diff --git a/.gitignore b/.gitignore index 9dcfcdcf874e3ed54257c36bb797b214413a90da..31c3b45765a10904abb1011847b48b33d09e5c4d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # Compiler output Unix IVAS_cod +IVAS_cod_fmtsw IVAS_dec IVAS_rend ISAR_post_rend @@ -16,6 +17,7 @@ build*/**/* # Compiler output VS2017 IVAS_cod.exe +IVAS_cod_fmtsw.exe IVAS_dec.exe IVAS_rend.exe ISAR_post_rend.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 21bb3e73845cba78065134b4ba197bc7fc1ecd00..9cb79ae4645011cc932e5180c8e2ef1d5477e292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,7 +174,7 @@ file(GLOB libDecSrcs "lib_dec/*.c") file(GLOB libDecHeaders "lib_dec/*.h") add_library(lib_dec ${libDecSrcs} ${libDecHeaders}) target_link_libraries(lib_dec lib_com lib_basop lib_rend lib_debug lib_isar) -target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_basop lib_enc lib_isar lib_util) +target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_basop lib_enc lib_isar) file(GLOB libUtilSrcs "lib_util/*.c") file(GLOB libUtilHeaders "lib_util/*.h") @@ -184,7 +184,7 @@ target_include_directories(lib_util PRIVATE lib_lc3plus lib_isar) if(NOT WMOPS) add_executable(ivas_lc3plus_unit_test ${CMAKE_SOURCE_DIR}/scripts/split_rendering/lc3plus_basop/ivas_lc3plus_unit_test.c) - target_link_libraries(ivas_lc3plus_unit_test lib_rend lib_dec lib_util lib_com lib_basop lib_debug lib_isar) + target_link_libraries(ivas_lc3plus_unit_test lib_rend lib_dec lib_com lib_basop lib_debug lib_isar) endif() file(GLOB libISARSrcs "lib_isar/*.c") diff --git a/LICENSE.md b/LICENSE.md index ca74eaf483b6772614a49c5025aa865a357e063e..21616d00deb55d678a5ed477119d38700456cab8 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index b931d122783a5b21781322d1b75a0e851b2bd2db..ef31eea686298eeea16af44df5c8347944440ce1 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_basop;..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_rend;..\lib_lc3plus;..\lib_util;.%(AdditionalIncludeDirectories) + ..\lib_basop;..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_lc3plus;.%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -109,7 +109,7 @@ Neither false false - ..\lib_basop;..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_rend;..\lib_lc3plus;..\lib_util;.%(AdditionalIncludeDirectories) + ..\lib_basop;..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_lc3plus;.%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) true @@ -209,11 +209,12 @@ - + + @@ -223,7 +224,6 @@ - diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index 170eada9ad30e017f4f3652be5ee6f08f2080937..59e2aa52d33a60e51eea8424e13518b64b9869b3 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -326,9 +326,6 @@ decoder_all_c - - decoder_ivas_c - decoder_ivas_c @@ -362,9 +359,6 @@ decoder_ivas_c - - decoder_ivas_c - decoder_ivas_c @@ -509,6 +503,12 @@ decoder_all_c + + decoder_ivas_c + + + decoder_ivas_c + diff --git a/Workspace_msvc/lib_isar.vcxproj b/Workspace_msvc/lib_isar.vcxproj index 0271901c88b4c9ad236ff5e34d925f4d7c107e4c..20c6363098f47d28ca0a42164bd532b2d263c17d 100644 --- a/Workspace_msvc/lib_isar.vcxproj +++ b/Workspace_msvc/lib_isar.vcxproj @@ -133,7 +133,6 @@ - diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index b76f3211cbbeb550c4df1977e072f6db0734bc9a..4dba9d23659cf7faacbeae481cc4f429fc0c8d7c 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -138,6 +138,7 @@ + diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 816f96619e0eee30a04a7a61f8afe62ce22faf09..84f3192389c79ffd54c5d2545677ed8e5642c20e 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/apps/decoder.c b/apps/decoder.c index 401a26761ce7244356038ff81f2ba9abd4994989..a5927d06e4adbe65cf9735f1e2a1420d00ba2a9a 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -124,7 +124,7 @@ typedef struct char *outputMdFilename; IVAS_DEC_COMPLEXITY_LEVEL complexityLevel; bool tsmEnabled; - IVAS_RENDER_FRAMESIZE renderFramesize; + IVAS_RENDER_NUM_SUBFR render_num_subframes; AcousticEnvironmentSequence aeSequence; bool dpidEnabled; uint16_t directivityPatternId[IVAS_MAX_NUM_OBJECTS]; @@ -142,9 +142,6 @@ typedef struct hrtfFileReader *hrtfReader; char *hrtfFileName; - IVAS_DEC_HRTF_TD_HANDLE *hHrtfTD; - - IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics; IVAS_BIN_RENDERER_TYPE binaural_renderer; IVAS_BIN_RENDERER_TYPE binaural_renderer_old; @@ -196,7 +193,7 @@ int main( Vector3PairFileReader *referenceVectorReader = NULL; RenderConfigReader *renderConfigReader = NULL; int16_t *pcmBuf = NULL; - IVAS_RENDER_FRAMESIZE asked_frame_size; + IVAS_RENDER_NUM_SUBFR asked_num_subframes; IVAS_DEC_HRTF_BINARY_WRAPPER hHrtfBinary; ObjectEditFileReader *objectEditFileReader = NULL; IVAS_ROOM_ACOUSTICS_CONFIG_DATA **pAE = NULL; @@ -207,8 +204,6 @@ int main( reset_mem( USE_BYTES ); #endif - hHrtfBinary.hHrtfTD = NULL; /* just to avoid compilation warning */ - hHrtfBinary.hHrtfStatistics = NULL; /* just to avoid compilation warning */ splitRendBits.bits_buf = splitRendBitsBuf; @@ -411,11 +406,10 @@ int main( * Configure the decoder *------------------------------------------------------------------------------------------*/ - asked_frame_size = arg.renderFramesize; + asked_num_subframes = arg.render_num_subframes; uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : IVAS_DEFAULT_AEID; - arg.enableHeadRotation = arg.enableHeadRotation || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM; - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.render_num_subframes, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.roomSize, arg.non_diegetic_pan_enabled, arg.non_diegetic_pan_gain_fx, arg.dpidEnabled, aeID, arg.objEditEnabled, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) { @@ -423,22 +417,10 @@ int main( goto cleanup; } - if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg.renderFramesize ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - - if ( arg.renderFramesize != asked_frame_size ) - { - fprintf( stderr, "\nChanged render framesize, only 20ms are allowed for decoding to EXT!\n" ); - } - /*------------------------------------------------------------------------------------------* * Configure Split rendering *------------------------------------------------------------------------------------------*/ - asked_frame_size = arg.renderFramesize; if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) @@ -446,12 +428,17 @@ int main( fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + } - if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg.renderFramesize ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + if ( ( error = IVAS_DEC_GetRenderNumSubfr( hIvasDec, &arg.render_num_subframes ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetRenderNumSubfr failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( !arg.renderConfigEnabled && ( arg.render_num_subframes != asked_num_subframes ) ) + { + fprintf( stderr, "\nChanged render framesize, only 20ms allowed!\n" ); } /*------------------------------------------------------------------------------------------* @@ -563,24 +550,24 @@ int main( if ( ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - if ( asked_frame_size != IVAS_RENDER_FRAMESIZE_20MS && + if ( asked_num_subframes != IVAS_RENDER_NUM_SUBFR_20MS && ( renderConfig.split_rend_config.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE || renderConfig.split_rend_config.dof == 0 ) ) { - arg.renderFramesize = asked_frame_size; + arg.render_num_subframes = asked_num_subframes; } else { - arg.renderFramesize = IVAS_RENDER_FRAMESIZE_20MS; + arg.render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; } - if ( ( error = IVAS_DEC_SetRenderFramesize( hIvasDec, arg.renderFramesize ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_SetRenderNumSubfr( hIvasDec, arg.render_num_subframes ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_SetRenderFramesize failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nIVAS_DEC_SetRenderNumSubfr failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - if ( arg.renderFramesize != asked_frame_size ) + if ( arg.render_num_subframes != asked_num_subframes ) { fprintf( stderr, "\nChanged render framesize, only 20ms are allowed for non-0dof split rendering!\n" ); } @@ -605,7 +592,7 @@ int main( /* ISAR frame size is set from command line, not renderer config file. * This will be ignored if output format is not split rendering. */ - renderConfig.split_rend_config.isar_frame_size_ms = (int16_t) arg.renderFramesize /* given in number of 5ms subframes */ * 5; + renderConfig.split_rend_config.isar_frame_size_ms = (int16_t) arg.render_num_subframes * 5; if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, renderConfig ) ) != IVAS_ERR_OK ) { @@ -730,19 +717,6 @@ cleanup: free( arg.aeSequence.pValidity ); } - if ( arg.hrtfReaderEnabled ) - { - destroy_td_hrtf( hHrtfBinary.hHrtfTD ); - destroy_hrtf_statistics( hHrtfBinary.hHrtfStatistics ); - } -#ifdef FIX_1990_SANITIZER_IN_REVERB_LOAD - // TODO: - /* This free differs from float version. - This is needed as HRTF statistics from ROM are currently converted from Word16 values to scaled Word32 values. */ - IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; - IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ); - destroy_hrtf_statistics( hHrtfStatistics ); -#endif IVAS_DEC_Close( &hIvasDec ); CustomLsReader_close( &hLsCustomReader ); hrtfFileReader_close( &hrtfReader ); @@ -924,8 +898,9 @@ static bool parseCmdlIVAS_dec( arg->inputFormat = IVAS_DEC_INPUT_FORMAT_G192; arg->non_diegetic_pan_enabled = false; arg->non_diegetic_pan_gain = 0.f; + arg->non_diegetic_pan_gain_fx = 0; arg->tsmEnabled = false; - arg->renderFramesize = IVAS_RENDER_FRAMESIZE_20MS; + arg->render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; arg->aeSequence.count = 0; arg->aeSequence.pID = NULL; arg->aeSequence.pValidity = NULL; @@ -1092,13 +1067,13 @@ static bool parseCmdlIVAS_dec( switch ( (int16_t) tmp ) { case 5: - arg->renderFramesize = IVAS_RENDER_FRAMESIZE_5MS; + arg->render_num_subframes = IVAS_RENDER_NUM_SUBFR_5MS; break; case 10: - arg->renderFramesize = IVAS_RENDER_FRAMESIZE_10MS; + arg->render_num_subframes = IVAS_RENDER_NUM_SUBFR_10MS; break; case 20: - arg->renderFramesize = IVAS_RENDER_FRAMESIZE_20MS; + arg->render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; break; default: fprintf( stderr, "Error: Invalid render frame size %d \n\n", tmp ); @@ -1738,9 +1713,13 @@ static ivas_error initOnFirstGoodFrame( if ( arg.rtpOutSR && srRtp != NULL ) { FILE *fParamsSR = NULL; - char srParamsFile[FILENAME_MAX], *ext = ".sr.txt"; - strncpy( srParamsFile, arg.outputWavFilename, FILENAME_MAX - sizeof( ext ) ); - strncat( srParamsFile, ext, sizeof( ext ) + 1 ); + char srParamsFile[FILENAME_MAX]; + const char *ext = ".sr.txt"; + + strncpy( srParamsFile, arg.outputWavFilename, FILENAME_MAX - strlen( ext ) - 1 ); + srParamsFile[FILENAME_MAX - strlen( ext ) - 1] = '\0'; + strncat( srParamsFile, ext, strlen( ext ) ); + srParamsFile[FILENAME_MAX - 1] = '\0'; /* Write the Split Rendering Params passed from SDP to srParamsFile */ fParamsSR = fopen( srParamsFile, "w" ); @@ -2008,6 +1987,7 @@ static ivas_error decodeG192( bool needNewFrame; int16_t nSamplesRendered, nSamplesRendered_loop, nSamplesToRender; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { -12582912, 0, 0, 0, 22 }, { -12582912, 0, 0, 0, 22 }, { -12582912, 0, 0, 0, 22 }, { -12582912, 0, 0, 0, 22 } }; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; SplitFileReadWrite *splitRendWriter = NULL; @@ -2148,21 +2128,19 @@ static ivas_error decodeG192( } } - int16_t num_subframes; - if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) + IVAS_RENDER_NUM_SUBFR num_subframes; + if ( ( error = IVAS_DEC_GetRenderNumSubfr( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); + fprintf( stderr, "\nIVAS_DEC_GetRenderNumSubfr failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( arg.enableHeadRotation || isSplitRend ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - if ( headRotReader == NULL ) { - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { Quaternions[i].w_fx = -12582912; Quaternions[i].x_fx = 0; @@ -2177,7 +2155,7 @@ static ivas_error decodeG192( } else { - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) { @@ -2187,7 +2165,7 @@ static ivas_error decodeG192( } } - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) { @@ -2199,13 +2177,12 @@ static ivas_error decodeG192( if ( arg.enableExternalOrientation ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableHeadRotation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableExternalOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t numFramesToTargetOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) { @@ -2213,7 +2190,7 @@ static ivas_error decodeG192( goto cleanup; } } - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK ) { @@ -2546,16 +2523,30 @@ static ivas_error decodeG192( } /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( arg.enableHeadRotation || isSplitRend ) { - IVAS_QUATERNION Quaternion; - if ( ( error = HeadRotationFileReading( headRotReader, &Quaternion, &Pos[0] ) ) != IVAS_ERR_OK ) + if ( headRotReader == NULL ) { - fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); - goto cleanup; + Quaternions[i].w_fx = -12582912; + Quaternions[i].x_fx = 0; + Quaternions[i].y_fx = 0; + Quaternions[i].z_fx = 0; + Quaternions[i].q_fact = 22; + Pos[i].x = 0.0f; + Pos[i].y = 0.0f; + Pos[i].z = 0.0f; + Pos[i].q_fact = 25; + } + else + { + if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[0], &Pos[0] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( headRotReader ) ); + goto cleanup; + } } - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[0], Pos[0], 0, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2787,6 +2778,7 @@ static ivas_error decodeVoIP( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; + IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { -12582912, 0, 0, 0, 22 }, { -12582912, 0, 0, 0, 22 }, { -12582912, 0, 0, 0, 22 }, { -12582912, 0, 0, 0, 22 } }; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; int16_t nOutSamples = 0; @@ -2979,21 +2971,19 @@ static ivas_error decodeVoIP( } } - int16_t num_subframes; - if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) + IVAS_RENDER_NUM_SUBFR num_subframes; + if ( ( error = IVAS_DEC_GetRenderNumSubfr( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); + fprintf( stderr, "\nIVAS_DEC_GetRenderNumSubfr failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } /* Head-tracking input simulation */ - if ( arg.enableHeadRotation ) + if ( arg.enableHeadRotation || isSplitRend ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - if ( headRotReader == NULL ) { - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { Quaternions[i].w_fx = -12582912; Quaternions[i].x_fx = 0; @@ -3008,7 +2998,7 @@ static ivas_error decodeVoIP( } else { - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) { @@ -3018,7 +3008,7 @@ static ivas_error decodeVoIP( } } - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) { @@ -3030,13 +3020,12 @@ static ivas_error decodeVoIP( if ( arg.enableExternalOrientation ) { - IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableHeadRotation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableExternalOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t numFramesToTargetOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK ) @@ -3046,7 +3035,7 @@ static ivas_error decodeVoIP( goto cleanup; } } - for ( i = 0; i < num_subframes; i++ ) + for ( i = 0; i < (int16_t) num_subframes; i++ ) { if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK ) { @@ -3756,12 +3745,6 @@ static ivas_error load_hrtf_from_file( /*------------------------------------------------------------------------------------------* * 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 ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) { return error; @@ -3783,13 +3766,15 @@ static ivas_error load_hrtf_from_file( 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_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) + + IVAS_DEC_HRTF_TD_HANDLE *hHrtfTD = NULL; + if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_TDrend_HRTF_binary( *hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -3798,7 +3783,7 @@ static ivas_error load_hrtf_from_file( } else { - destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + destroy_td_hrtf( hHrtfTD ); } } } @@ -3871,26 +3856,27 @@ static ivas_error load_hrtf_from_file( } } } - } - - if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle 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 ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); + fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - else + + if ( ( error = load_HrtfStatistics_from_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { - destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); + 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( hHrtfStatistics ); + } } } } @@ -3939,7 +3925,7 @@ static ivas_error restartDecoder( IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->render_num_subframes, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->roomSize, arg->non_diegetic_pan_enabled, arg->non_diegetic_pan_gain_fx, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) { @@ -3947,9 +3933,18 @@ static ivas_error restartDecoder( goto cleanup; } - if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) + if ( arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { - fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( ( error = IVAS_DEC_GetRenderNumSubfr( hIvasDec, &arg->render_num_subframes ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetRenderNumSubfr failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } @@ -3972,7 +3967,7 @@ static ivas_error restartDecoder( * This will be ignored if output format is not split rendering. */ if ( renderConfig != NULL ) { - renderConfig->split_rend_config.isar_frame_size_ms = (int16_t) arg->renderFramesize /* given in number of 5ms subframes */ * 5; + renderConfig->split_rend_config.isar_frame_size_ms = (int16_t) arg->render_num_subframes * 5; } if ( arg->renderConfigEnabled && renderConfig != NULL ) diff --git a/apps/encoder.c b/apps/encoder.c index 1599a9db555ba1a2daa2671ebd98c689751f02c4..9e10a9c5c6774d5398b591801feadf8e9282d4f7 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -829,10 +829,10 @@ int main( /* scene orientation */ if ( sceneOrientationFileReader ) { - PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++]; + IVAS_PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++]; IVAS_PIDATA_ORIENTATION *scene = &piDataTs->data.scene; - memset( piDataTs, 0, sizeof( PIDATA_TS ) ); + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); scene->size = sizeof( IVAS_PIDATA_ORIENTATION ); scene->piDataType = IVAS_PI_SCENE_ORIENTATION; @@ -846,10 +846,10 @@ int main( /* device orientation */ if ( deviceOrientationFileReader ) { - PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++]; + IVAS_PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++]; IVAS_PIDATA_ORIENTATION *device = &piDataTs->data.deviceUnCompensated; - memset( piDataTs, 0, sizeof( PIDATA_TS ) ); + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); device->size = sizeof( IVAS_PIDATA_ORIENTATION ); device->piDataType = IVAS_PI_DEVICE_ORIENTATION_COMPENSATED; @@ -2049,7 +2049,7 @@ static void usage_enc( void ) fprintf( stdout, " where 0 = adaptive, 3-100 = fixed in number of frames,\n" ); fprintf( stdout, " default is deactivated\n" ); fprintf( stdout, "-dtx : Activate DTX mode with a SID update rate of 8 frames\n" ); - fprintf( stdout, " Note: DTX is supported in EVS, stereo, ISM, SBA up to 80kbps and MASA up to 128kbps \n" ); + fprintf( stdout, " Note: DTX is supported on all bitrates for EVS, stereo, ISM, and MASA, and up to 80 kbps for SBA.\n" ); fprintf( stdout, "-rf p o : Activate channel-aware mode for WB and SWB signal at 13.2kbps, \n" ); fprintf( stdout, " where FEC indicator, p: LO or HI, and FEC offset, o: 2, 3, 5, or 7 in number of frames.\n" ); fprintf( stdout, " Alternatively p and o can be replaced by a rf configuration file with each line \n" ); diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 1b0b931367741edd3023b57f1b2941bec47f2646..12cc57349ebfe62d144ffb4d9320d9cf3b68d86f 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -938,10 +938,10 @@ int encoder_main( /* scene orientation */ if ( sceneOrientationFileReader ) { - PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; + IVAS_PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; IVAS_PIDATA_ORIENTATION *scene = &piDataTs->data.scene; - memset( piDataTs, 0, sizeof( PIDATA_TS ) ); + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); scene->size = sizeof( IVAS_PIDATA_ORIENTATION ); scene->piDataType = IVAS_PI_SCENE_ORIENTATION; @@ -955,10 +955,10 @@ int encoder_main( /* device orientation */ if ( deviceOrientationFileReader ) { - PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; + IVAS_PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; IVAS_PIDATA_ORIENTATION *device = &piDataTs->data.deviceUnCompensated; - memset( piDataTs, 0, sizeof( PIDATA_TS ) ); + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); device->size = sizeof( IVAS_PIDATA_ORIENTATION ); device->piDataType = IVAS_PI_DEVICE_ORIENTATION_COMPENSATED; @@ -2152,7 +2152,7 @@ static void usage_enc( void ) fprintf( stdout, " where 0 = adaptive, 3-100 = fixed in number of frames,\n" ); fprintf( stdout, " default is deactivated\n" ); fprintf( stdout, "-dtx : Activate DTX mode with a SID update rate of 8 frames\n" ); - fprintf( stdout, " Note: DTX is supported in EVS, stereo, ISM, SBA up to 80kbps and MASA up to 128kbps \n" ); + fprintf( stdout, " Note: DTX is supported on all bitrates for EVS, stereo, ISM, and MASA, and up to 80 kbps for SBA.\n" ); fprintf( stdout, "-rf p o : Activate channel-aware mode for WB and SWB signal at 13.2kbps, \n" ); fprintf( stdout, " where FEC indicator, p: LO or HI, and FEC offset, o: 2, 3, 5, or 7 in number of frames.\n" ); fprintf( stdout, " Alternatively p and o can be replaced by a rf configuration file with each line \n" ); diff --git a/apps/isar_post_rend.c b/apps/isar_post_rend.c index 6ccf204ceb221c7c11035b9f01fb93b9c191853e..c3fe556c8a02adc4ac7793d748f7b4a9a6e5391b 100644 --- a/apps/isar_post_rend.c +++ b/apps/isar_post_rend.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -106,15 +106,12 @@ typedef struct int32_t sampleRate; InputConfig inConfig; OutputConfig outConfig; - char inMetadataFilePaths[RENDERER_MAX_ISAR_MD_INPUTS][POST_REND_MAX_CLI_ARG_LENGTH]; - int16_t numInMetadataFiles; + char inMetadataFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; char headRotationFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; char splitRendBFIFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; - ISAR_POST_REND_COMPLEXITY_LEVEL complexityLevel; bool delayCompensationEnabled; bool quietModeEnabled; - bool sceneDescriptionInput; - IVAS_RENDER_FRAMESIZE render_framesize; + IVAS_RENDER_NUM_SUBFR render_num_subframes; } CmdlnArgs; typedef enum @@ -124,8 +121,6 @@ typedef enum CmdLnOptionId_outputFile, CmdLnOptionId_sampleRate, CmdLnOptionId_trajFile, - CmdLnOptionId_orientationTracking, - CmdLnOptionId_complexityLevel, CmdLnOptionId_noDelayCmp, CmdLnOptionId_quietModeEnabled, CmdLnOptionId_inputMetadata, @@ -133,6 +128,7 @@ typedef enum CmdLnOptionId_SplitRendBFIFile, CmdLnOptionId_framing, CmdLnOptionId_srParamsFile, + CmdLnOptionId_help, } CmdLnOptionId; static const CmdLnParser_Option cliOptions[] = { @@ -140,79 +136,91 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_inputFile, .match = "input_file", .matchShort = "i", - .description = "Path to the input file (WAV, raw PCM or scene description file)", + .placeholder = "", + .description = "Path to the input file (WAV or raw PCM file with BINAURAL_SPLIT_PCM input format\nor ISAR bitstream file with BINAURAL_SPLIT_CODED input format)", + .isMandatory = true, }, { .id = CmdLnOptionId_inputFormat, .match = "input_format", .matchShort = "if", - .description = "Audio format of input file (e.g. BINAURAL_SPLIT_PCM, use -l for a list)", - }, - { - .id = CmdLnOptionId_inputMetadata, - .match = "input_metadata", - .matchShort = "im", - .description = "Space-separated list of path to metadata files for BINAURAL_SPLIT_PCM input mode", + .placeholder = "", + .description = "Audio format of input file (BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM or RTPDUMP)", + .isMandatory = true, }, { .id = CmdLnOptionId_outputFile, .match = "output_file", .matchShort = "o", + .placeholder = "", .description = "Path to the output file", + .isMandatory = true, + }, + { + .id = CmdLnOptionId_inputMetadata, + .match = "input_metadata", + .matchShort = "im", + .placeholder = "", + .description = "Path to the input metadata file (mandatory for BINAURAL_SPLIT_PCM input format)", }, { .id = CmdLnOptionId_sampleRate, .match = "sample_rate", .matchShort = "fs", - .description = "Input sampling rate in kHz (16, 32, 48) - required only with raw PCM inputs", + .placeholder = "", + .description = "Input sampling rate in kHz (16, 32, 48) (mandatory for raw PCM input files)", }, { .id = CmdLnOptionId_trajFile, .match = "trajectory_file", .matchShort = "T", + .placeholder = "", .description = "Head rotation trajectory file for simulation of head tracking", }, { .id = CmdLnOptionId_SplitRendBFIFile, .match = "post_rend_bfi_file", .matchShort = "prbfi", - .description = "Split rendering option: bfi file", + .placeholder = "", + .description = "Split rendering BFI (Bad Frame Indicator) file", }, { .id = CmdLnOptionId_noDelayCmp, .match = "no_delay_compensation", .matchShort = "no_delay_cmp", - .description = "[flag] Turn off delay compensation", - }, - { - .id = CmdLnOptionId_complexityLevel, - .match = "complexity_level", - .matchShort = "level", - .description = "Complexity level, level = (1, 2, 3), will be defined after characterisation.", + .description = "Turn off delay compensation", }, { .id = CmdLnOptionId_quietModeEnabled, .match = "quiet", .matchShort = "q", - .description = "[flag] Limit printouts to terminal", + .description = "Quiet mode - limit printouts to terminal", }, { .id = CmdLnOptionId_listFormats, .match = "list", .matchShort = "l", - .description = "List supported audio formats", + .description = "List supported audio formats of input file", }, { .id = CmdLnOptionId_framing, .match = "framing", .matchShort = "fr", - .description = "Set Render audio framing.", + .placeholder = "", + .description = "Set audio rendering frame size in ms (5, 10, 20)", }, { .id = CmdLnOptionId_srParamsFile, .match = "sr_params", .matchShort = "s", - .description = "Path to the split rendering init params file", + .placeholder = "", + .description = "Path to the split rendering SDP init params file (mandatory for RTPDUMP input format)", + }, + { + .id = CmdLnOptionId_help, + .match = "help", + .matchShort = "h", + .description = "Show this help message and exit", }, }; @@ -293,26 +301,12 @@ static const CmdLnParser_Option *findOptionById( static bool parseInConfig( const char *inFormatStr, - InputConfig *inConfig, - bool *sceneDescriptionInput ) + InputConfig *inConfig ) { - char charBuf[FILENAME_MAX]; /* Initialize input config struct */ inConfig->numBinBuses = 0; - /* First check if input is being set to scene description file - this is not covered by parseAudioConfig(). */ - strncpy( charBuf, inFormatStr, sizeof( charBuf ) - 1 ); - charBuf[sizeof( charBuf ) - 1] = '\0'; - to_upper( charBuf ); - if ( strcmp( charBuf, "META" ) == 0 ) - { - *sceneDescriptionInput = true; - /* Parsing the file will be done later. At this point the actual file path - * may not be known as command line parameters are still being parsed. */ - return true; - } - /* Check for single-format inputs. The given string should map to a member of AUDIO_CONFIG enum. */ bool srRtp = false; IVAS_AUDIO_CONFIG audioConfig = parseAudioConfig( inFormatStr, &srRtp ); @@ -331,7 +325,7 @@ static bool parseInConfig( /* Default case covers formats that are defined in the AUDIO_CONFIG enum, * but cannot be used at input, e.g. BINAURAL */ const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_listFormats ); - fprintf( stderr, "Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); + fprintf( stderr, "Error: Unsupported input format: %s. To list valid formats, use option --%s.\n", inFormatStr, listOption->match ); return false; } } @@ -340,13 +334,13 @@ static bool parseInConfig( } -static bool parseRenderFramesize( +static bool parseRenderNumSubfr( char *value, - IVAS_RENDER_FRAMESIZE *render_framesize ) + IVAS_RENDER_NUM_SUBFR *render_num_subframes ) { int32_t tmp; - *render_framesize = IVAS_RENDER_FRAMESIZE_UNKNOWN; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_UNKNOWN; if ( !is_digits_only( value ) ) { return false; @@ -355,13 +349,13 @@ static bool parseRenderFramesize( switch ( (int16_t) tmp ) { case 5: - *render_framesize = IVAS_RENDER_FRAMESIZE_5MS; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_5MS; break; case 10: - *render_framesize = IVAS_RENDER_FRAMESIZE_10MS; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_10MS; break; case 20: - *render_framesize = IVAS_RENDER_FRAMESIZE_20MS; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; break; default: return false; @@ -405,50 +399,6 @@ static IVAS_AUDIO_CONFIG parseAudioConfig( } -static bool checkRequiredArgs( - CmdlnArgs args ) -{ - const CmdLnParser_Option *tmpOption; - - /* Check required arguments */ - bool missingRequiredArg = false; - if ( isEmptyString( args.inputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_inputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - - const bool singleInputSpecified = ( args.inConfig.numBinBuses != 0 ); - - if ( !args.sceneDescriptionInput && !singleInputSpecified ) - { - /* Neither scene description input nor single-type input was specified on command line */ - tmpOption = findOptionById( CmdLnOptionId_inputFormat ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( isEmptyString( args.outputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_outputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( args.sampleRate == 0 ) - { - tmpOption = findOptionById( CmdLnOptionId_sampleRate ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( missingRequiredArg ) - { - CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions ); - } - - return !missingRequiredArg; -} - - static CmdlnArgs defaultArgs( const char *executableName ) { @@ -461,28 +411,28 @@ static CmdlnArgs defaultArgs( args.sampleRate = 0; - args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID; + args.inConfig.numBinBuses = 0; + args.inConfig.binBuses[0].srRtp = false; + args.inConfig.binBuses[0].audioConfig = IVAS_AUDIO_CONFIG_INVALID; + args.inConfig.binBuses[0].inputChannelIndex = 0; + args.inConfig.binBuses[0].gain_dB = 0; - for ( int32_t i = 0; i < RENDERER_MAX_ISAR_MD_INPUTS; ++i ) - { - clearString( args.inMetadataFilePaths[i] ); - } - args.numInMetadataFiles = 0; + args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID; + clearString( args.inMetadataFilePath ); clearString( args.headRotationFilePath ); clearString( args.splitRendBFIFilePath ); args.delayCompensationEnabled = true; args.quietModeEnabled = false; - args.sceneDescriptionInput = false; - args.render_framesize = IVAS_RENDER_FRAMESIZE_20MS; + args.render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; return args; } -static void parseOption( +static int16_t parseOption( const int32_t optionId, char **optionValues, const int16_t numOptionValues, @@ -493,88 +443,155 @@ static void parseOption( switch ( optionId ) { case CmdLnOptionId_listFormats: - assert( numOptionValues == 0 ); printSupportedAudioConfigs(); exit( 0 ); case CmdLnOptionId_inputFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No input file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single input file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->inputFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_inputFormat: - assert( numOptionValues == 1 ); - if ( !parseInConfig( optionValues[0], &args->inConfig, &args->sceneDescriptionInput ) ) + if ( numOptionValues == 0 ) { - exit( -1 ); /* Error printout handled by failing function */ + fprintf( stderr, "Error: No input file format has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single input file format, but %d have been provided!\n", numOptionValues ); + return -1; + } + + if ( !parseInConfig( optionValues[0], &args->inConfig ) ) + { + /* Error printout handled by failing function */ + return -1; } break; case CmdLnOptionId_inputMetadata: - assert( numOptionValues <= RENDERER_MAX_ISAR_MD_INPUTS ); - for ( int16_t i = 0; i < numOptionValues; ++i ) + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No input metadata file for BINAURAL_SPLIT_PCM mode has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) { - strncpy( args->inMetadataFilePaths[i], optionValues[i], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); + fprintf( stderr, "Error: The program expects a single input metadata file, but %d have been provided!\n", numOptionValues ); + return -1; } - args->numInMetadataFiles = numOptionValues; + strncpy( args->inMetadataFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_outputFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No output file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single output file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->outputFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_sampleRate: - assert( numOptionValues == 1 ); args->sampleRate = (int32_t) ( strtol( optionValues[0], NULL, 10 ) * 1000 ); if ( args->sampleRate == 0 ) { - fprintf( stderr, "Invalid sampling rate specified\n" ); - exit( -1 ); + fprintf( stderr, "Error: Invalid sampling rate specified\n" ); + return -1; } break; case CmdLnOptionId_trajFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No head rotation trajectory file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single head rotation trajectory file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->headRotationFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_SplitRendBFIFile: - assert( numOptionValues == 1 ); - strncpy( args->splitRendBFIFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); - break; - case CmdLnOptionId_complexityLevel: - assert( numOptionValues == 1 ); - args->complexityLevel = (int32_t) ( strtol( optionValues[0], NULL, 10 ) ); - if ( args->complexityLevel < ISAR_POST_REND_COMPLEXITY_LEVEL_ONE || args->complexityLevel > ISAR_POST_REND_COMPLEXITY_LEVEL_THREE ) + if ( numOptionValues == 0 ) { - fprintf( stdout, "Invalid complexity level specified.\n" ); - exit( -1 ); + fprintf( stderr, "Error: No BFI file has been provided!\n" ); + return -1; } - else if ( args->complexityLevel == ISAR_POST_REND_COMPLEXITY_LEVEL_ONE || args->complexityLevel == ISAR_POST_REND_COMPLEXITY_LEVEL_TWO ) + else if ( numOptionValues > 1 ) { - fprintf( stdout, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" ); + fprintf( stderr, "Error: The program expects a single BFI file, but %d have been provided!\n", numOptionValues ); + return -1; } + strncpy( args->splitRendBFIFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; case CmdLnOptionId_noDelayCmp: - assert( numOptionValues == 0 ); + if ( numOptionValues != 0 ) + { + fprintf( stderr, "Error: Incorrect specification of the `-%s/--%s` command-line option!\n", cliOptions[optionId].matchShort, cliOptions[optionId].match ); + return -1; + } args->delayCompensationEnabled = false; break; case CmdLnOptionId_quietModeEnabled: - assert( numOptionValues == 0 ); + if ( numOptionValues != 0 ) + { + fprintf( stderr, "Error: Incorrect specification of the `-%s/--%s` command-line option!\n", cliOptions[optionId].matchShort, cliOptions[optionId].match ); + return -1; + } args->quietModeEnabled = true; break; case CmdLnOptionId_framing: - assert( numOptionValues == 1 ); - if ( !parseRenderFramesize( optionValues[0], &args->render_framesize ) ) + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: Incorrect audio rendering frame size!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) { - fprintf( stderr, "Unknown or invalid option for frame size: %s\n", optionValues[0] ); - exit( -1 ); + fprintf( stderr, "Error: The program expects a rendering frame size, but %d have been provided!\n", numOptionValues ); + return -1; + } + if ( !parseRenderNumSubfr( optionValues[0], &args->render_num_subframes ) ) + { + fprintf( stderr, "Error: Unknown or invalid option for audio rendring frame size: %s\n", optionValues[0] ); + return -1; } break; case CmdLnOptionId_srParamsFile: - assert( numOptionValues == 1 ); + if ( numOptionValues == 0 ) + { + fprintf( stderr, "Error: No path to the parameter initialization file has been provided!\n" ); + return -1; + } + else if ( numOptionValues > 1 ) + { + fprintf( stderr, "Error: The program expects a single parameter initialization file, but %d have been provided!\n", numOptionValues ); + return -1; + } strncpy( args->srParamsFilePath, optionValues[0], POST_REND_MAX_CLI_ARG_LENGTH - 1 ); break; + case CmdLnOptionId_help: + CmdLnParser_printUsage( args->executableName, cliOptions, numCliOptions ); + exit( 0 ); default: - assert( 0 && "This should be unreachable - all command line options should be explicitly handled." ); + fprintf( stderr, "Error: Incorrect or invalid command-line usage!\n" ); + return -1; break; } - return; + return 0; } @@ -589,11 +606,6 @@ static CmdlnArgs parseCmdlnArgs( exit( -1 ); /* Error printout handled by failing function */ } - if ( !checkRequiredArgs( args ) ) - { - exit( -1 ); /* Error printout handled by failing function */ - } - return args; } @@ -602,13 +614,12 @@ static void printSupportedAudioConfigs( void ) { uint16_t i; const char *supportedFormats[] = { - "BINAURAL (output only)", "BINAURAL_SPLIT_PCM", "BINAURAL_SPLIT_CODED", "RTPDUMP", }; - fprintf( stdout, "Supported audio formats:\n" ); + fprintf( stdout, "Supported audio formats:\n\n" ); for ( i = 0; i < sizeof( supportedFormats ) / sizeof( *supportedFormats ); i++ ) { fprintf( stdout, "%s\n", supportedFormats[i] ); @@ -876,7 +887,6 @@ int main( convert_backslash( args.inputFilePath ); convert_backslash( args.outputFilePath ); - convert_backslash( args.headRotationFilePath ); convert_backslash( args.srParamsFilePath ); /*------------------------------------------------------------------------------------------* @@ -885,6 +895,7 @@ int main( if ( !isEmptyString( args.headRotationFilePath ) ) { + convert_backslash( args.headRotationFilePath ); if ( RotationFileReader_open( args.headRotationFilePath, &headRotReader ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError opening file: %s\n", args.headRotationFilePath ); @@ -899,7 +910,11 @@ int main( if ( !isEmptyString( args.splitRendBFIFilePath ) ) { convert_backslash( args.splitRendBFIFilePath ); - SplitRendBFIFileReader_open( args.splitRendBFIFilePath, &splitRendBFIReader ); + if ( SplitRendBFIFileReader_open( args.splitRendBFIFilePath, &splitRendBFIReader ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError opening file: %s\n", args.splitRendBFIFilePath ); + goto cleanup; + } } int32_t inFileSampleRate = 0; @@ -908,7 +923,7 @@ int main( if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { error = split_rend_reader_open( &hSplitRendFileReadWrite, - args.inMetadataFilePaths[0], + args.inMetadataFilePath, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms, @@ -917,13 +932,21 @@ int main( &bitsBuffer.config.lc3plusHighRes ); if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend metadata file %s\n", args.inMetadataFilePaths[0] ); + if ( isEmptyString( args.inMetadataFilePath ) ) + { + const CmdLnParser_Option *listOption = findOptionById( CmdLnOptionId_inputMetadata ); + fprintf( stderr, "\nError: Split rendering metadata file not specified, use option -%s/--%s.\n", listOption->matchShort, listOption->match ); + } + else + { + fprintf( stderr, "\nError: Could not open split rendering metadata file %s!\n", args.inMetadataFilePath ); + } goto cleanup; } if ( AudioFileReader_open( &audioReader, audioFilePath ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError opening file: %s\n", audioFilePath ); + fprintf( stderr, "\nError: Could not open input file: %s!\n", audioFilePath ); goto cleanup; } } @@ -939,19 +962,19 @@ int main( &bitsBuffer.config.lc3plusHighRes ); if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend params file %s\n", args.srParamsFilePath ); + fprintf( stderr, "\nError: Could not open split rendering init params file %s!\n", args.srParamsFilePath ); goto cleanup; } if ( ( error = IVAS_RTP_READER_Init( &srRTP, args.inputFilePath, NULL, false, NULL ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "error in IVAS_RTP_READER_Init(): %d\n", error ); + fprintf( stderr, "\nError in IVAS_RTP_READER_Init(), error code: %d!\n", error ); goto cleanup; } audioReader = NULL; /* Force owerwrite of command line provided rendersize to align with codec frame size */ - args.render_framesize = bitsBuffer.config.isar_frame_size_ms / 5; + args.render_num_subframes = bitsBuffer.config.isar_frame_size_ms / 5; } /*if split renderer is running in post renderer mode*/ else if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) @@ -966,7 +989,7 @@ int main( &bitsBuffer.config.lc3plusHighRes ); if ( error != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend metadata file %s\n", args.inputFilePath ); + fprintf( stderr, "\nError reading input file %s, error code: %d!\n", args.inputFilePath, error ); goto cleanup; } audioReader = NULL; @@ -992,14 +1015,14 @@ int main( /* else if sampling rate given on command line, compare with wav file */ else if ( inFileSampleRate != args.sampleRate ) { - fprintf( stderr, "\nSampling rate mismatch: %d Hz requested, but %d Hz found in file %s\n", args.sampleRate, inFileSampleRate, args.inputFilePath ); + fprintf( stderr, "\nError: Sampling rate mismatch: %d Hz requested, but %d Hz found in file %s!\n", args.sampleRate, inFileSampleRate, args.inputFilePath ); goto cleanup; } break; case IVAS_ERR_SAMPLING_RATE_UNKNOWN: /* Returned when input is raw PCM */ if ( args.sampleRate == 0 ) { - fprintf( stderr, "\nSampling rate must be specified on command line when using raw PCM input\n" ); + fprintf( stderr, "\nError: Sampling rate must be specified on command line in case of raw PCM input!\n" ); goto cleanup; } break; @@ -1014,7 +1037,7 @@ int main( error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels ); if ( error != IVAS_ERR_OK && error != IVAS_ERR_NUM_CHANNELS_UNKNOWN ) { - fprintf( stderr, "\nAudioFileReader_getNumChannels failed: %s\n", ivas_error_to_string( error ) ); + fprintf( stderr, "\nError: AudioFileReader_getNumChannels() failed: %s\n", ivas_error_to_string( error ) ); goto cleanup; } } @@ -1023,9 +1046,9 @@ int main( * Open ISAR handle *------------------------------------------------------------------------------------------*/ - const int16_t frameSize_smpls = (int16_t) ( ( args.render_framesize ) * args.sampleRate * 5 / ( 1000 ) ); + const int16_t frameSize_smpls = (int16_t) ( ( args.render_num_subframes ) * args.sampleRate * 5 / ( 1000 ) ); args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_BINAURAL; - if ( ( error = ISAR_POST_REND_open( &hIsarPostRend, args.sampleRate, args.outConfig.audioConfig, true, 0, 0, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) + if ( ( error = ISAR_POST_REND_open( &hIsarPostRend, args.sampleRate, args.outConfig.audioConfig, true, 0, 0, (int16_t) args.render_num_subframes ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError opening renderer handle: %s\n", ivas_error_to_string( error ) ); goto cleanup; @@ -1242,34 +1265,45 @@ int main( /* Convert from int to float and from interleaved to packed */ convertInputBuffer( inpInt16Buffer, numSamplesRead, inBuffer.config.numSamplesPerChannel, num_in_channels, inFloatBuffer_fx ); *inBuffer.pq_fact = 0; - int16_t num_subframes, sf_idx; - num_subframes = (int16_t) args.render_framesize; + int16_t num_subframes; + num_subframes = (int16_t) args.render_num_subframes; /* Read from head rotation trajectory file if specified */ + IVAS_QUATERNION headRot[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; + IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; if ( headRotReader != NULL ) { - for ( sf_idx = 0; sf_idx < num_subframes; sf_idx++ ) + for ( i = 0; i < num_subframes; i++ ) { - IVAS_QUATERNION headRot; - IVAS_VECTOR3 Pos; - - IF( ( error = HeadRotationFileReading( headRotReader, &headRot, &Pos ) ) != IVAS_ERR_OK ) + if ( ( error = HeadRotationFileReading( headRotReader, &headRot[i], &Pos[i] ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in Head Rotation File Reading: %s\n", ivas_error_to_string( error ) ); goto cleanup; } - - if ( ( error = ISAR_POST_REND_SetHeadRotation( hIsarPostRend, headRot, Pos, DEFAULT_AXIS, sf_idx ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError setting Head Rotation: %s\n", ivas_error_to_string( error ) ); - goto cleanup; - } } } else { - fprintf( stderr, "\nHead Rotation should be enabled in post renderer\n" ); - goto cleanup; + for ( i = 0; i < num_subframes; i++ ) + { + headRot[i].w_fx = -12582912; + headRot[i].x_fx = 0; + headRot[i].y_fx = 0; + headRot[i].z_fx = 0; + headRot[i].q_fact = 22; + Pos[i].x_fx = 0; + Pos[i].y_fx = 0; + Pos[i].z_fx = 0; + } + } + + for ( i = 0; i < num_subframes; i++ ) + { + if ( ( error = ISAR_POST_REND_SetHeadRotation( hIsarPostRend, headRot[i], Pos[i], DEFAULT_AXIS, i ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError setting Head Rotation: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } } /* Read from split renderer bfi file if specified */ diff --git a/apps/renderer.c b/apps/renderer.c index 69e1935eb0c5727f32f24651dbcac15e44fa19c7..73203597c4ab47b940b6ae7a7b39f4c86693f5b6 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -87,16 +87,13 @@ static #define SEP_FOLDER '/' #endif -#ifndef _WIN32 -#define max( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) ) -#define min( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) -#endif - /*------------------------------------------------------------------------------------------* * Local structures *------------------------------------------------------------------------------------------*/ +typedef float IVAS_REND_LfePanMtx[RENDERER_MAX_INPUT_LFE_CHANNELS][RENDERER_MAX_OUTPUT_CHANNELS]; + typedef struct { uint32_t frameCounter; @@ -170,7 +167,6 @@ typedef struct int16_t numInMetadataFiles; char outMetadataFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char headRotationFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; - char splitRendBFIFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char referenceVectorFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char referenceRotationFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; char externalOrientationFilePath[RENDERER_MAX_CLI_ARG_LENGTH]; @@ -193,7 +189,7 @@ typedef struct bool lfeCustomRoutingEnabled; char inLfePanningMatrixFile[RENDERER_MAX_CLI_ARG_LENGTH]; int16_t syncMdDelay; - IVAS_RENDER_FRAMESIZE render_framesize; + IVAS_RENDER_NUM_SUBFR render_num_subframes; uint16_t directivityPatternId[RENDERER_MAX_ISM_INPUTS]; AcousticEnvironmentSequence aeSequence; IVAS_ROOM_SIZE_T reverbRoomSize; @@ -221,7 +217,6 @@ typedef enum CmdLnOptionId_listFormats, CmdLnOptionId_inputGain, CmdLnOptionId_outputMetadata, - CmdLnOptionId_SplitRendBFIFile, CmdLnOptionId_referenceVectorFile, CmdLnOptionId_exteriorOrientationFile, CmdLnOptionId_framing, @@ -236,96 +231,109 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_inputFile, .match = "input_file", .matchShort = "i", + .placeholder = "", .description = "Path to the input file (WAV, raw PCM or scene description file)", + .isMandatory = true, }, { .id = CmdLnOptionId_inputFormat, .match = "input_format", .matchShort = "if", + .placeholder = "", .description = "Audio format of input file (e.g. 5_1 or HOA3 or META,\nuse -l for a list)", + .isMandatory = true, }, { .id = CmdLnOptionId_inputMetadata, .match = "input_metadata", .matchShort = "im", + .placeholder = " [...]", .description = "Space-separated list of path to metadata files for ISM/MASA/OMASA/\nOSBA/BINAURAL_SPLIT_PCM inputs. \nFor OMASA, ISM files must be specified first.", }, { .id = CmdLnOptionId_outputFile, .match = "output_file", .matchShort = "o", + .placeholder = "", .description = "Path to the output file", + .isMandatory = true, }, { .id = CmdLnOptionId_outputFormat, .match = "output_format", .matchShort = "of", + .placeholder = "", .description = "Output format to render.\nAlternatively, can be a custom loudspeaker layout file", + .isMandatory = true, }, { .id = CmdLnOptionId_sampleRate, .match = "sample_rate", .matchShort = "fs", + .placeholder = "", .description = "Input sampling rate in kHz (16, 32, 48) - required only with raw\nPCM inputs", }, { .id = CmdLnOptionId_trajFile, .match = "trajectory_file", .matchShort = "T", + .placeholder = "", .description = "Head rotation trajectory file for simulation of head tracking\n(only for binaural outputs)", }, { .id = CmdLnOptionId_outputMetadata, .match = "output_metadata", .matchShort = "om", + .placeholder = "", .description = "coded metadata file for BINAURAL_SPLIT_PCM output mode", }, - { - .id = CmdLnOptionId_SplitRendBFIFile, - .match = "post_rend_bfi_file", - .matchShort = "prbfi", - .description = "Split rendering option: bfi file", - }, { .id = CmdLnOptionId_refRotFile, .match = "reference_rotation_file", .matchShort = "rf", + .placeholder = "", .description = "Reference rotation trajectory file for simulation of head tracking\n(only for binaural outputs)", }, { .id = CmdLnOptionId_customHrtfFile, .match = "custom_hrtf", .matchShort = "hrtf", + .placeholder = "", .description = "Custom HRTF file for binaural rendering\n(only for binaural outputs)", }, { .id = CmdLnOptionId_renderConfigFile, .match = "render_config_parameters", .matchShort = "render_config", + .placeholder = "", .description = "Binaural renderer configuration parameters in file\n(only for binaural outputs)", }, { .id = CmdLnOptionId_nonDiegeticPan, .match = "non_diegetic_panning", .matchShort = "non_diegetic_pan", + .placeholder = "", .description = "Panning mono non diegetic sound to stereo -90<= pan <= 90\nleft or l or 90->left, right or r or -90->right,\ncenter or c or 0 ->middle", }, { .id = CmdLnOptionId_orientationTracking, .match = "tracking_type", .matchShort = "otr", + .placeholder = "", .description = "Head orientation tracking type: 'none', 'ref', 'avg' or `ref_vec`\nor `ref_vec_lev` (only for binaural outputs)", }, { .id = CmdlnOptionId_lfePosition, .match = "lfe_position", .matchShort = "lp", + .placeholder = ",,", .description = "Output LFE position. Comma-delimited triplet of [gain, azimuth,\nelevation] where gain is linear (like --gain, -g) and azimuth,\nelevation are in degrees. If specified, overrides the default\nbehavior which attempts to map input to output LFE channel(s)", }, { .id = CmdlnOptionId_lfeMatrix, .match = "lfe_matrix", .matchShort = "lm", + .placeholder = "", .description = "LFE panning matrix. File (CSV table) containing a matrix of\ndimensions [ num_input_lfe x num_output_channels ] with elements\nspecifying linear routing gain (like --gain, -g). If specified,\noverrides the output LFE position option and the default\nbehavior which attempts to map input to output LFE channel(s)", }, { @@ -338,6 +346,7 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_complexityLevel, .match = "complexity_level", .matchShort = "level", + .placeholder = "", .description = "Complexity level, level = (1, 2, 3), will be defined after\ncharacterisation.", }, { @@ -350,6 +359,7 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_inputGain, .match = "gain", .matchShort = "g", + .placeholder = "", .description = "Input gain (linear, not in dB) to be applied to input audio file", }, { @@ -362,43 +372,50 @@ static const CmdLnParser_Option cliOptions[] = { .id = CmdLnOptionId_referenceVectorFile, .match = "reference_vector_file", .matchShort = "rvf", + .placeholder = "", .description = "Reference vector trajectory file for simulation of head tracking\n(only for binaural outputs)", }, { .id = CmdLnOptionId_exteriorOrientationFile, .match = "exterior_orientation_file", .matchShort = "exof", + .placeholder = "", .description = "External orientation trajectory file for simulation of external\norientations", }, { .id = CmdLnOptionId_framing, .match = "framing", .matchShort = "fr", - .description = "Set Render audio framing.", + .placeholder = "", + .description = "Set render audio framing in ms", }, { .id = CmdLnOptionId_syncMdDelay, .match = "sync_md_delay", .matchShort = "smd", + .placeholder = "", .description = "Metadata Synchronization Delay in ms, Default is 0. Quantized by\n5ms subframes for TDRenderer (13ms -> 10ms -> 2subframes)", }, { .id = CmdLnOptionId_directivityPatternId, .match = "ism_directivity_pattern_id", .matchShort = "dpid", + .placeholder = " [...]", .description = "Directivity pattern ID(s) = [ID1, ID2, ID3, ID4]. Space-separated\nlist of up to 4 numbers (unsigned integers) can be specified for\nBINAURAL and BINAURAL_ROOM_REVERB output.\nID1, ID2, ID3, ID4 specify the directivity pattern IDs used for\nISMs 1,2,3 and 4 respectively. \nThis option needs to be accompanied by a render_config file,\notherwise a default directivity pattern is used.", }, { .id = CmdLnOptionId_acousticEnvironmentId, .match = "acoustic_environment_id", .matchShort = "aeid", + .placeholder = "", .description = "Acoustic environment ID (number > 0) alternatively, it can be a text file where each line contains \"ID duration\" for BINAURAL_ROOM_REVERB output configuration.", }, { .id = CmdLnOptionId_roomSize, .match = "room_size", .matchShort = "rsz", - .description = "Selects default reverb based on a room size (S - small | M - medium | L - large)", + .placeholder = "", + .description = "Selects default reverb based on a room size (S - small |\nM - medium | L - large)", } }; @@ -658,8 +675,8 @@ static void setupWithSingleFormatInput( /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string contains "NULL" */ char charBuf[FILENAME_MAX]; - strncpy( charBuf, args.inMetadataFilePaths[i], min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1 ); - charBuf[min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1] = '\0'; + strncpy( charBuf, args.inMetadataFilePaths[i], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); + charBuf[RENDERER_MAX_CLI_ARG_LENGTH - 1] = '\0'; to_upper( charBuf ); if ( strncmp( charBuf, "NULL", 4 ) == 0 ) { @@ -761,7 +778,6 @@ int main( IVAS_CLDFB_FILTER_BANK_HANDLE cldfbAna[RENDERER_MAX_INPUT_CHANNELS]; IVAS_CLDFB_FILTER_BANK_HANDLE cldfbSyn[RENDERER_MAX_INPUT_CHANNELS]; int16_t cldfb_in_flag, CLDFBframeSize_smpls; - SplitRendBFIFileReader *splitRendBFIReader = NULL; Vector3PairFileReader *referenceVectorReader = NULL; hrtfFileReader *hrtfFileReader = NULL; IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend = NULL; @@ -891,11 +907,6 @@ int main( } } - if ( !isEmptyString( args.splitRendBFIFilePath ) ) - { - convert_backslash( args.splitRendBFIFilePath ); - SplitRendBFIFileReader_open( args.splitRendBFIFilePath, &splitRendBFIReader ); - } if ( !isEmptyString( args.externalOrientationFilePath ) ) { if ( RotationFileReader_open( args.externalOrientationFilePath, &externalOrientationFileReader ) != IVAS_ERR_OK ) @@ -990,12 +1001,12 @@ int main( goto cleanup; } - const int16_t frameSize_smpls = (int16_t) ( ( args.render_framesize ) * args.sampleRate * 5 / ( 1000 ) ); + const int16_t frameSize_smpls = (int16_t) ( ( args.render_num_subframes ) * args.sampleRate * BINAURAL_RENDERING_FRAME_SIZE_MS / ( 1000 ) ); Word32 nonDiegeticPanGain_fx = ( args.nonDiegeticPanGain == 1.0f ) ? ONE_IN_Q31 : ( args.nonDiegeticPanGain == -1.0f ) ? L_negate( ONE_IN_Q31 ) : (Word32) ( args.nonDiegeticPanGain * ( 1LL << Q31 ) ); - IF( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, !isEmptyString( args.customHrtfFilePath ), args.nonDiegeticPan, nonDiegeticPanGain_fx, args.Opt_Headrotation, args.Opt_ExternalOrientation, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) + IF( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, !isEmptyString( args.customHrtfFilePath ), args.nonDiegeticPan, nonDiegeticPanGain_fx, args.Opt_Headrotation, args.Opt_ExternalOrientation, (int16_t) args.render_num_subframes ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError opening renderer handle: %s\n", ivas_error_to_string( error ) ); goto cleanup; @@ -1100,7 +1111,7 @@ int main( fprintf( stderr, "\nIVAS_REND_GetHrtfStatisticsHandle failed\n\n" ); goto cleanup; } - if ( ( error = load_reverb_binary( *hHrtfStatistics, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_HrtfStatistics_from_binary( *hHrtfStatistics, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { @@ -1219,7 +1230,7 @@ int main( /* ISAR frame size is set from command line, not renderer config file. * This will be ignored if output format is not split rendering. */ - renderConfig.split_rend_config.isar_frame_size_ms = (int16_t) args.render_framesize /* given in number of 5ms subframes */ * 5; + renderConfig.split_rend_config.isar_frame_size_ms = (int16_t) args.render_num_subframes * BINAURAL_RENDERING_FRAME_SIZE_MS; if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK ) { @@ -1250,8 +1261,8 @@ int main( /* Set up output custom layout configuration */ if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - floatToFixed_arrL_app( args.outConfig.outSetupCustom.azimuth, args.outConfig.outSetupCustom.azimuth_fx, Q22, RENDERER_MAX_OUTPUT_CHANNELS ); - floatToFixed_arrL_app( args.outConfig.outSetupCustom.elevation, args.outConfig.outSetupCustom.elevation_fx, Q22, RENDERER_MAX_OUTPUT_CHANNELS ); + floatToFixed_arrL_app( args.outConfig.outSetupCustom.azimuth, args.outConfig.outSetupCustom.azimuth_fx, Q22, args.outConfig.outSetupCustom.num_spk ); + floatToFixed_arrL_app( args.outConfig.outSetupCustom.elevation, args.outConfig.outSetupCustom.elevation_fx, Q22, args.outConfig.outSetupCustom.num_spk ); if ( ( error = IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( hIvasRend, args.outConfig.outSetupCustom ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_REND_ConfigureCustomOutputLoudspeakerLayout(): %s\n", ivas_error_to_string( error ) ); @@ -1355,8 +1366,8 @@ int main( if ( args.inConfig.multiChannelBuses[i].audioConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) { - floatToFixed_arrL_app( args.inConfig.inSetupCustom.azimuth, args.inConfig.inSetupCustom.azimuth_fx, Q22, RENDERER_MAX_OUTPUT_CHANNELS ); - floatToFixed_arrL_app( args.inConfig.inSetupCustom.elevation, args.inConfig.inSetupCustom.elevation_fx, Q22, RENDERER_MAX_OUTPUT_CHANNELS ); + floatToFixed_arrL_app( args.inConfig.inSetupCustom.azimuth, args.inConfig.inSetupCustom.azimuth_fx, Q22, args.inConfig.inSetupCustom.num_spk ); + floatToFixed_arrL_app( args.inConfig.inSetupCustom.elevation, args.inConfig.inSetupCustom.elevation_fx, Q22, args.inConfig.inSetupCustom.num_spk ); if ( ( error = IVAS_REND_ConfigureCustomInputLoudspeakerLayout( hIvasRend, mcIds[i], args.inConfig.inSetupCustom ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_REND_ConfigureCustomInputLoudspeakerLayout(): %s\n", ivas_error_to_string( error ) ); @@ -1543,7 +1554,7 @@ int main( if ( ( error = split_rend_writer_open( &hSplitRendFileReadWrite, outFile, delayNumSamples_temp, delayTimeScale_temp, bitsBuffer.config.codec, bitsBuffer.config.poseCorrection, bitsBuffer.config.codec_frame_size_ms, bitsBuffer.config.isar_frame_size_ms, args.sampleRate, bitsBuffer.config.lc3plus_highres ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nCould not open split rend metadata file %s\n", outFile ); + fprintf( stderr, "\nError: Could not open split rend metadata file %s!\n", outFile ); goto cleanup; } } @@ -1647,7 +1658,7 @@ int main( { int16_t num_in_channels; num_in_channels = inBuffer.config.numChannels; - const bool isCurrentFrameMultipleOf20ms = frame % ( 4 / args.render_framesize ) == 0; + const bool isCurrentFrameMultipleOf20ms = frame % ( IVAS_RENDER_NUM_SUBFR_20MS / args.render_num_subframes ) == 0; if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && renderConfigReader != NULL && args.aeSequence.count > 0 && args.aeSequence.pValidity[args.aeSequence.selected] != 0 ) @@ -1711,7 +1722,7 @@ int main( } int16_t num_subframes, sf_idx; - num_subframes = (int16_t) args.render_framesize; + num_subframes = (int16_t) args.render_num_subframes; if ( isCurrentFrameMultipleOf20ms && !flushRendererLastFrame ) { @@ -2177,7 +2188,6 @@ cleanup: } split_rend_reader_writer_close( &hSplitRendFileReadWrite ); - SplitRendBFIFileReader_close( &splitRendBFIReader ); for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { @@ -2190,8 +2200,6 @@ cleanup: RotationFileReader_close( &externalOrientationFileReader ); RotationFileReader_close( &referenceRotReader ); Vector3PairFileReader_close( &referenceVectorReader ); - destroy_td_hrtf( hHrtfTD ); - destroy_hrtf_statistics( hHrtfStatistics ); IVAS_REND_Close( &hIvasRend ); IsmPositionProvider_close( positionProvider ); RenderConfigReader_close( &renderConfigReader ); @@ -2416,13 +2424,13 @@ static bool parseDiegeticPan( } -static bool parseRenderFramesize( +static bool parseRenderNumSubfr( char *value, - IVAS_RENDER_FRAMESIZE *render_framesize ) + IVAS_RENDER_NUM_SUBFR *render_num_subframes ) { int32_t tmp; - *render_framesize = IVAS_RENDER_FRAMESIZE_UNKNOWN; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_UNKNOWN; if ( !is_digits_only( value ) ) { return false; @@ -2431,13 +2439,13 @@ static bool parseRenderFramesize( switch ( (int16_t) tmp ) { case 5: - *render_framesize = IVAS_RENDER_FRAMESIZE_5MS; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_5MS; break; case 10: - *render_framesize = IVAS_RENDER_FRAMESIZE_10MS; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_10MS; break; case 20: - *render_framesize = IVAS_RENDER_FRAMESIZE_20MS; + *render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; break; default: return false; @@ -2696,53 +2704,6 @@ static bool parseReverbRoomSize( return true; } - -static bool checkRequiredArgs( - CmdlnArgs args ) -{ - const CmdLnParser_Option *tmpOption; - - /* Check required arguments */ - bool missingRequiredArg = false; - if ( isEmptyString( args.inputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_inputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - - const bool singleInputSpecified = args.inConfig.numAudioObjects != 0 || - args.inConfig.numAmbisonicsBuses != 0 || - args.inConfig.numMultiChannelBuses != 0 || - args.inConfig.numMasaBuses != 0; - - if ( !args.sceneDescriptionInput && !singleInputSpecified ) - { - /* Neither scene description input nor single-type input was specified on command line */ - tmpOption = findOptionById( CmdLnOptionId_inputFormat ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( isEmptyString( args.outputFilePath ) ) - { - tmpOption = findOptionById( CmdLnOptionId_outputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_INVALID ) - { - tmpOption = findOptionById( CmdLnOptionId_outputFormat ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; - } - if ( missingRequiredArg ) - { - CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions ); - } - - return !missingRequiredArg; -} - static CmdlnArgs defaultArgs( const char *executableName ) { @@ -2756,6 +2717,13 @@ static CmdlnArgs defaultArgs( args.inConfig.inSetupCustom.num_spk = 0; args.inConfig.inSetupCustom.num_lfe = 0; + for ( i = 0; i < RENDERER_MAX_INPUT_CHANNELS; i++ ) + { + args.inConfig.inSetupCustom.azimuth[i] = 0.f; + args.inConfig.inSetupCustom.azimuth_fx[i] = 0; + args.inConfig.inSetupCustom.elevation[i] = 0.f; + args.inConfig.inSetupCustom.elevation_fx[i] = 0; + } args.inConfig.numAudioObjects = 0; args.inConfig.numAmbisonicsBuses = 0; args.inConfig.numMultiChannelBuses = 0; @@ -2764,6 +2732,13 @@ static CmdlnArgs defaultArgs( args.outConfig.audioConfig = IVAS_AUDIO_CONFIG_INVALID; args.outConfig.outSetupCustom.num_spk = 0; args.outConfig.outSetupCustom.num_lfe = 0; + for ( i = 0; i < RENDERER_MAX_OUTPUT_CHANNELS; i++ ) + { + args.outConfig.outSetupCustom.azimuth[i] = 0.f; + args.outConfig.outSetupCustom.azimuth_fx[i] = 0; + args.outConfig.outSetupCustom.elevation[i] = 0.f; + args.outConfig.outSetupCustom.elevation_fx[i] = 0; + } for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { args.inConfig.ambisonicsBuses[i].audioConfig = IVAS_AUDIO_CONFIG_INVALID; @@ -2777,7 +2752,6 @@ static CmdlnArgs defaultArgs( clearString( args.headRotationFilePath ); clearString( args.outMetadataFilePath ); - clearString( args.splitRendBFIFilePath ); clearString( args.referenceVectorFilePath ); clearString( args.referenceRotationFilePath ); clearString( args.customHrtfFilePath ); @@ -2804,7 +2778,7 @@ static CmdlnArgs defaultArgs( args.lfeCustomRoutingEnabled = false; clearString( args.inLfePanningMatrixFile ); - args.render_framesize = IVAS_RENDER_FRAMESIZE_20MS; + args.render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; args.syncMdDelay = 0; for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { @@ -2822,7 +2796,7 @@ static CmdlnArgs defaultArgs( return args; } -static void parseOption( +static int16_t parseOption( const int32_t optionId, char **optionValues, const int16_t numOptionValues, @@ -2884,10 +2858,6 @@ static void parseOption( assert( numOptionValues == 1 ); strncpy( args->outMetadataFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); break; - case CmdLnOptionId_SplitRendBFIFile: - assert( numOptionValues == 1 ); - strncpy( args->splitRendBFIFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); - break; case CmdLnOptionId_referenceVectorFile: assert( numOptionValues == 1 ); strncpy( args->referenceVectorFilePath, optionValues[0], RENDERER_MAX_CLI_ARG_LENGTH - 1 ); @@ -2973,7 +2943,7 @@ static void parseOption( break; case CmdLnOptionId_framing: assert( numOptionValues == 1 ); - if ( !parseRenderFramesize( optionValues[0], &args->render_framesize ) ) + if ( !parseRenderNumSubfr( optionValues[0], &args->render_num_subframes ) ) { fprintf( stderr, "Unknown or invalid option for frame size: %s\n", optionValues[0] ); exit( -1 ); @@ -3012,7 +2982,7 @@ static void parseOption( break; } - return; + return 0; } static CmdlnArgs parseCmdlnArgs( @@ -3026,11 +2996,6 @@ static CmdlnArgs parseCmdlnArgs( exit( -1 ); /* Error printout handled by failing function */ } - if ( !checkRequiredArgs( args ) ) - { - exit( -1 ); /* Error printout handled by failing function */ - } - if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { args.Opt_Headrotation = 1; diff --git a/lib_basop/basop32.c b/lib_basop/basop32.c index eebc1684915ccba9a062a49f561a112f2208d36d..27b4992767c28495e79d03bfd466c620fc6e5d57 100644 --- a/lib_basop/basop32.c +++ b/lib_basop/basop32.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_basop/basop32.h b/lib_basop/basop32.h index 9bbf24f1c52e1c5159ad4ff22fa6720f3bfcd60a..7fe294167c38a962ea16d6b8dfbbdb14cb52384b 100644 --- a/lib_basop/basop32.h +++ b/lib_basop/basop32.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_basop/enh40.c b/lib_basop/enh40.c index 570f4b211ab675c8fd924a2b0d4786ddec25c679..57df99e5c706d64c70ceadb659e837d93f8e244c 100644 --- a/lib_basop/enh40.c +++ b/lib_basop/enh40.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_basop/enh40.h b/lib_basop/enh40.h index 9c3742f3ef23b24bced88e87e71b85a8ac83baca..8cfb0c6009194f2c88e2a6713d91f3440515ce1c 100644 --- a/lib_basop/enh40.h +++ b/lib_basop/enh40.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_basop/move.h b/lib_basop/move.h index fc4d4e18bdd53a1ba2d006ea049dae81a4c7772a..7f10031193e1add29631c97ce50536d6645966bb 100644 --- a/lib_basop/move.h +++ b/lib_basop/move.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_basop/stl.h b/lib_basop/stl.h index d2f82d6742545fc9ea402943a6f6eac2f4958fd0..6badc3bcfc758809a0063793ddef05fb68061813 100644 --- a/lib_basop/stl.h +++ b/lib_basop/stl.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_basop/typedef.h b/lib_basop/typedef.h index 6ff6832e61357970317e47348e32fe2cfe14d62f..9968d4c84cba87fc0435c0737579b64448365196 100644 --- a/lib_basop/typedef.h +++ b/lib_basop/typedef.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 87af1a8ebb95c0ef339d7724f96f7cff829d4b42..e35416e5ff223ad28cf3713e3fac1f745df2aee0 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -2,7 +2,6 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ - #include #include #include "options.h" @@ -11,7 +10,7 @@ #include "rom_com.h" #include "prot_fx.h" -#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) + void UnmapIndex( const Word16 PeriodicityIndex, /* Q0 */ const Word16 Bandwidth, /* Q0 */ diff --git a/lib_com/basop_com_lpc.c b/lib_com/basop_com_lpc.c index 589d957071248e229d8a920ca7a4fe8a0889e3be..398d753277625bc398c33e9a3719928979f2d4d5 100644 --- a/lib_com/basop_com_lpc.c +++ b/lib_com/basop_com_lpc.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/basop_lsf_tools.c b/lib_com/basop_lsf_tools.c index a982e0f41b3d2b48df2847babbb85a3e951900b6..db40e08ef75a14610eaf89a07882ea955e613deb 100644 --- a/lib_com/basop_lsf_tools.c +++ b/lib_com/basop_lsf_tools.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/basop_proto_func.h b/lib_com/basop_proto_func.h index 549cc7ac01af664f9618151aa9648aa9c46dee62..845d14a27604a2a08030620bbb5be4d82dabee20 100644 --- a/lib_com/basop_proto_func.h +++ b/lib_com/basop_proto_func.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/basop_settings.h b/lib_com/basop_settings.h index fa809240acb811e2ecf27b5e1439c1607c9d8e27..79544c078cfc742923c9c3c5e874f2f5debe3b9f 100644 --- a/lib_com/basop_settings.h +++ b/lib_com/basop_settings.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index 5478dd1fef105a2d78d96c80bf5d6acf4e71ef2c..7fa5e12bebe44c876bba1eccd8f891830e39eaf6 100644 --- a/lib_com/basop_tcx_utils.c +++ b/lib_com/basop_tcx_utils.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index fef47cf168cf0c6412f411d8974e31d7edb05d1c..551dbdeef64247b414cf3cb292d5671aed170575 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -988,7 +988,6 @@ Word32 div_w( Word32 L_num, Word32 L_den ) } -static Word32 div_w_newton( Word32 num, Word32 den ); /* Table of 256 precalculated estimates to be used by the "div_w_newton" function using the Newton/Raphson method. @@ -1283,7 +1282,7 @@ static Word32 L_dmult( Word32 L_var1, Word32 L_var2 ) * BASOP weights: 24 (incl. L_dmult) */ -static Word32 div_w_newton( Word32 num, Word32 den ) +Word32 div_w_newton( Word32 num, Word32 den ) { Word32 x0, x1, x2, x3, diff, result; @@ -2958,3 +2957,32 @@ cmplx CL_mult_32x16( cmplx input, cmplx_s coeff ) #endif return result; } + +Word64 Mpy_64_32( Word64 W_var1, Word32 L_var2 ) +{ + Word32 var1_l; + Word64 var_out; + var1_l = W_extract_l( W_var1 ); + var_out = W_mult0_32_32( L_and( var1_l, 1 ), L_var2 ); + var_out = W_mac_32_32( var_out, L_lshr( var1_l, 1 ), L_var2 ); + var_out = W_mac_32_32( W_shr( var_out, 31 ), W_extract_h( W_var1 ), L_var2 ); + return var_out; +} + +#ifndef FUNCTION_W_msu0_32_32 +Word64 W_msu0_32_32( Word64 L64_var1, Word32 L_var2, Word32 L_var3 ) +{ + /* no saturation */ + L64_var1 = W_sub_nosat( L64_var1, W_mult0_32_32( L_var2, L_var3 ) ); + return L64_var1; +} +#endif + +#ifndef FUNCTION_W_mac0_32_32 +Word64 W_mac0_32_32( Word64 L64_var1, Word32 L_var2, Word32 L_var3 ) +{ + /* no saturation */ + L64_var1 = W_add_nosat( L64_var1, W_mult0_32_32( L_var2, L_var3 ) ); + return L64_var1; +} +#endif diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index c0f6df8cd0235135dedd8acc4cc59514fda978c0..4265162488781d7effb4ca756968d6353e5f778c 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -328,6 +328,9 @@ Word16 BASOP_Util_Divide3232_Scale( Word32 x, /*!< i : Numerator*/ Word32 y, /*!< i : Denominator*/ Word16 *s ); /*!< o : Additional scalefactor difference*/ +Word32 div_w_newton( Word32 num, /*!< i : Numerator*/ + Word32 den ); /*!< i : Denominator*/ + Word32 BASOP_Util_Divide3232_Scale_newton( Word32 x, /*!< i : Numerator*/ Word32 y, /*!< i : Denominator*/ Word16 *s ); /*!< o : Additional scalefactor difference*/ @@ -906,4 +909,31 @@ cmplx CL_scale_t( cmplx x, Word16 y ); cmplx CL_dscale_t( cmplx x, Word16 y1, Word16 y2 ); cmplx CL_mult_32x16( cmplx input, cmplx_s coeff ); + +/*! + \brief 64-bit/32-bit multiplication with shift + + This multiplication is similar to Mpy_32_32 except for the fact that the first argument + and the return type are Word64. The function performs the following operation: + + z = ((int128_t)x (int128_t)y) >> 31 + + where: + - x is a 64-bit signed integer + - y is a 32-bit signed integer + - z is a 64-bit signed integer + + \param W_var1 64-bit signed integer argument + \param L_var2 32-bit signed integer argument + \return 64-bit signed integer representing the result of the multiplication with shift +*/ +Word64 Mpy_64_32( Word64 W_var1, Word32 L_var2 ); + +#ifndef FUNCTION_W_msu0_32_32 +Word64 W_msu0_32_32( Word64 L64_var1, Word32 L_var2, Word32 L_var3 ); +#endif +#ifndef FUNCTION_W_mac0_32_32 +Word64 W_mac0_32_32( Word64 L64_var1, Word32 L_var2, Word32 L_var3 ); +#endif + #endif /* __BASOP_UTIL_H__ */ diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 030c4746dbf96d2408be6aa6a214717cca631176..8f985c6ce3aab483a1616de0a45e73e92ad04d00 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/cldfb_evs_fx.c b/lib_com/cldfb_evs_fx.c index a471d8f91fb91d4bb2430d2ecd37dbda09ea86c6..a5f9da62a1941472a7aa615ad6b1820304a8f7ce 100644 --- a/lib_com/cldfb_evs_fx.c +++ b/lib_com/cldfb_evs_fx.c @@ -996,6 +996,9 @@ ivas_error openCldfb( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } + hs->flags = 0; + move16(); + hs->type = type; move16(); diff --git a/lib_com/cldfb_fx.c b/lib_com/cldfb_fx.c index 449e197ac1eff91d571d50377ba41e2a5ba469c2..f0c0d815810314a05676293396037a3e71db2ebb 100644 --- a/lib_com/cldfb_fx.c +++ b/lib_com/cldfb_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,7 +37,6 @@ #include #include #include "options.h" -#include #include "stat_dec.h" #include "prot_fx.h" #include "rom_com.h" @@ -596,6 +595,7 @@ void cldfbAnalysis_ts_fx_var_q( IF( NE_16( h_cldfb->Q_cldfb_state, *q_cldfb ) ) { Word16 norm_st = L_norm_arr( timeBuffer_fx, offset ); + norm_st = sub( norm_st, find_guarded_bits_fx( shr( h_cldfb->no_channels, 2 ) ) ); IF( GE_16( norm_st, sub( *q_cldfb, h_cldfb->Q_cldfb_state ) ) ) { scale_sig32( timeBuffer_fx, offset, sub( *q_cldfb, h_cldfb->Q_cldfb_state ) ); diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index f96fba710c9b17b78e3beb7cd3abd2dc2783605a..3ce3e518fe806c97ac7831f7f4bc966dcdeaf86e 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -180,12 +180,14 @@ IF( GT_16( element_mode, IVAS_SCE ) ) { return; } + /*---------------------------------------------------------------------* * Generate white noise vector *---------------------------------------------------------------------*/ /*for ( i=0; i 0, 0 => 0, 64 => 1, 128 => 2, 192 => 3, 256 => 4 */ +#define TC_SUBFR2IDX_16KHZ_fx(x) mac_r(1024L, (x), 512) /* -1 => 0, 0 => 0, 64 => 1, 128 => 2, 192 => 3, 256 => 4 */ -#define TC_SUBFR2IDX_fx(x) add(s_min(3, s_max(0, sub((x), 1))), TC_SUBFR2IDX_16KHZ_fx(x)) +#define TC_SUBFR2IDX_fx(x) add(s_min(3, s_max(0, sub((x), 1))), TC_SUBFR2IDX_16KHZ_fx(x)) #define L_IMPULSE 17 /* TC - length of one prototype impulse */ @@ -1484,10 +1281,10 @@ enum * TCQ constants *----------------------------------------------------------------------------------*/ -#define MAX_PULSES 560 -#define MAX_POS 320 -#define MAX_LEN MAX_PULSES -#define NUM_ENG_PACKED_WORDS 20 /* Storage for variable rate quantizer bits */ +#define MAX_PULSES 560 +#define MAX_POS 320 +#define MAX_LEN MAX_PULSES +#define NUM_ENG_PACKED_WORDS 20 /* Storage for variable rate quantizer bits */ #define NORMAL_HQ_CORE 0 /* Signal use of Normal HQ core */ #define LOW_RATE_HQ_CORE 1 /* Signal use of Low Rate MDCT core */ @@ -1540,7 +1337,6 @@ enum #define LPC_SHB_ORDER 10 #define LPC_WHTN_ORDER 4 /* Order of whitening filter for SHB excitation */ #define SHB_OVERLAP_LEN ( L_FRAME16k - L_SHB_LAHEAD ) / ( NUM_SHB_SUBFR - 1 ) -#define QUANT_DIST_INIT ( 10000000000.0f ) /* Quantiser search distance initialisation */ #define HIBND_ACB_L_FAC 5 / 2 /* SHB Interpolation Factor */ #define HIBND_ACB_L_FAC_Q1 ( 5 ) /* SHB Interpolation Factor Q1 */ #define NUM_HILBERTS 2 @@ -1555,8 +1351,7 @@ enum #define NUM_BITS_SHB_FrameGain 6 #define NUM_BITS_SHB_FrameGain_LBR_WB 4 -#define RECIP_ROOT_EIGHT 0.3535534f /* 1.0 / sqrt(8.0) - constant Gain Shape over TD BWE subframes */ -#define RECIP_ROOT_EIGHT_FX 11585 /* 1.0 / sqrt(8.0) - constant Gain Shape over TD BWE subframes */ +#define RECIP_ROOT_EIGHT_FX 11585 /* 1.0 / sqrt(8.0) - constant Gain Shape over TD BWE subframes */ #define LPC_SHB_ORDER_WB 6 #define LPC_WHTN_ORDER_WB 2 /* Order of whitening filter for WB excitation */ @@ -1575,88 +1370,65 @@ enum #define NUM_BITS_SHB_RES_GS 3 #define NUM_BITS_SHB_VF 3 #define NUM_BITS_SHB_SUBGAINS_RF 5 /* Number of bits for subframe gains for SWB in RF */ -#define SHB_GAIN_QLOW -1.0f /* SHB gain lowest scalar quantizer value */ -#define SHB_GAIN_QDELTA 0.15f /* SHB gain scalar quantizer stepsize */ -#define SHB_GAIN_QLOW_1k75 0.0f /* SHB gain lowest scalar quantizer value */ -#define SHB_GAIN_QDELTA_1k75 0.08f /* SHB gain scalar quantizer stepsize */ -#define SHB_GAIN_QLOW_1k75_FX 0 /* SHB gain lowest scalar quantizer value */ -#define SHB_GAIN_QDELTA_1k75_FX 10486 /* SHB gain scalar quantizer stepsize Q17 */ -#define SHB_GAIN_QDELTA_1k75_FX_15 2622 /* SHB gain scalar quantizer stepsize */ -#define SHB_GAIN_QLOW_FX -262144 /* Q18*/ /* SHB gain lowest scalar quantizer value */ -#define SHB_GAIN_QLOW_FX_16 -65536 /* SHB gain lowest scalar quantizer value */ -#define SHB_GAIN_QDELTA_FX_15 4915 /* SHB gain scalar quantizer step size */ -#define SHB_GAIN_QDELTA_FX_16 9830 -#define SHB_GAIN_QDELTA_FX 19661 /* 0.15 in Q17*/ +#define SHB_GAIN_QLOW_1k75_FX 0 /* SHB gain lowest scalar quantizer value */ +#define SHB_GAIN_QDELTA_1k75_FX 10486 /* SHB gain scalar quantizer stepsize, 0.08f Q17 */ +#define SHB_GAIN_QDELTA_1k75_FX_15 2622 /* SHB gain scalar quantizer stepsize, 0.08f */ +#define SHB_GAIN_QLOW_FX -262144 /* -SHB gain lowest scalar quantizer value, 1.0f in Q18 */ +#define SHB_GAIN_QLOW_FX_16 -65536 /* SHB gain lowest scalar quantizer value */ +#define SHB_GAIN_QDELTA_FX_15 4915 /* SHB gain scalar quantizer step size, 0.15f */ +#define SHB_GAIN_QDELTA_FX_16 9830 /* 0.15f in Q16 */ +#define SHB_GAIN_QDELTA_FX 19661 /* 0.15 in Q17 */ #define NUM_Q_LSF 5 /* Number of quantized LSFs */ #define MIRROR_POINT_BITS 2 /* Number of bits used to quantize mirror point */ #define MIRROR_POINT_Q_CB_SIZE 4 /* Size of codebook used to quantize mirror point */ -#define MAX_LSF 0.5f /* Maximum value of the LSFs */ -#define MAX_LSF_FX_2 8192 /* Maximum value of the LSFs */ -#define MAX_LSF_FX 16384 /* Maximum value of the LSFs */ -#define MAX_LSF_FX_BY_2 8192 /* Maximum value of the LSFs */ +#define MAX_LSF_FX_2 8192 /* Maximum value of the LSFs */ +#define MAX_LSF_FX 16384 /* Maximum value of the LSFs, 0.5f */ +#define MAX_LSF_FX_BY_2 8192 /* Maximum value of the LSFs */ #define NUM_MAP_LSF 5 /* Number of mapped LSFs */ #define NUM_LSF_GRIDS 4 /* Number of LSF grids */ #define NUM_LSF_GRID_BITS 2 /* Number of bits used for the LSF grids */ #define NUM_BITS_SHB_MSLVQ 20 /* Number of bits for the MSLVQ quantizer */ -#define VF_0th_PARAM 0.34f -#define VF_1st_PARAM 0.5f -#define VF_2nd_PARAM ( VF_1st_PARAM - VF_0th_PARAM ) -#define VF_0th_PARAM_FX 11141 /*.34*/ -#define VF_1st_PARAM_FX 16384 /*.5*/ -#define VF_2nd_PARAM_FX (VF_1st_PARAM_FX - VF_0th_PARAM_FX) - - -#define GAMMA0 0.65f /* Mean value of gamma1/gamma2 for formant PF */ -#define GAMMA_SHARP 0.15f /* Largest sharpening for gamma1/gamma2 (0.83/0.67)*/ -#define SWB_NOISE_MIX_FAC 0.15f /* Noise mixing adjustment factor for active PF */ -#define SWB_TILT_LOW 1.0f /* Lower threshold for PF tilt adaptation */ -#define SWB_TILT_HIGH 2.0f /* Higher threshold for PF tilt adaptation */ -#define SWB_TILT_DELTA ( 1.0f / ( SWB_TILT_HIGH - SWB_TILT_LOW ) ) /* Inclination between thresholds */ -#define GAMMA3_PLUS_WB 0.65f /* WB post-filter */ -#define GAMMA3_MINUS_WB 0.85f /* WB post-filter */ -#define AGC_FAC_WB 0.85f /* WB post-filter - gain adjustment factor */ -#define AGC_FAC1_WB ( 1.0f - AGC_FAC_WB ) /* WB post-filter - gain adjustment factor complement */ - -#define GAMMA0_FX 21299 /* Mean value of gamma1/gamma2 for formant PF */ -#define GAMMA_SHARP_FX 4915 /* Largest sharpening for gamma1/gamma2 (0.83/0.67)*/ -#define SWB_NOISE_MIX_FAC_FX 4915 /* 0.15f in Q15 */ -#define SWB_TILT_LOW_FX 4096 /* Q12 1.0f Lower threshold for PF tilt adaptation */ -#define SWB_TILT_HIGH_FX 8192 /* Q12 2.0f Higher threshold for PF tilt adaptation */ -#define SWB_TILT_DELTA_FX 32767 /* Q15 (1.0f/(SWB_TILT_HIGH-SWB_TILT_LOW)) Inclination between thresholds */ -#define HALF_POINT_FX (16384) -#define GAMMA3_PLUS_FX 6554 /* NB post-filter - tilt weighting factor when k1>0 */ -#define GAMMA3_MINUS_FX 29491 /* NB post-filter - tilt weighting factor when k1<0 */ -#define GAMMA3_PLUS_WB_FX 21299 /* WB post-filter */ -#define GAMMA3_MINUS_WB_FX 27853 /* WB post-filter */ -#define AGC_FAC_WB_FX 27853 /* WB post-filter - gain adjustment factor */ -#define AGC_FAC1_WB_FX (Word16)(32768L-AGC_FAC_WB_FX) /* WB post-filter - gain adjustment factor complement */ +#define VF_0th_PARAM_FX 11141 /*.34*/ +#define VF_1st_PARAM_FX 16384 /*.5*/ +#define VF_2nd_PARAM_FX (VF_1st_PARAM_FX - VF_0th_PARAM_FX) + +#define GAMMA0_FX 21299 /* Mean value of gamma1/gamma2 for formant PF, 0.65f */ +#define GAMMA_SHARP_FX 4915 /* Largest sharpening for gamma1/gamma2 (0.83/0.67=0.15f)*/ +#define SWB_NOISE_MIX_FAC_FX 4915 /* 0.15f in Q15 */ +#define SWB_TILT_LOW_FX 4096 /* Q12 1.0f Lower threshold for PF tilt adaptation */ +#define SWB_TILT_HIGH_FX 8192 /* Q12 2.0f Higher threshold for PF tilt adaptation */ +#define SWB_TILT_DELTA_FX 32767 /* Q15 (1.0f/(SWB_TILT_HIGH-SWB_TILT_LOW)) Inclination between thresholds */ +#define HALF_POINT_FX (16384) +#define GAMMA3_PLUS_FX 6554 /* NB post-filter - tilt weighting factor when k1>0 */ +#define GAMMA3_MINUS_FX 29491 /* NB post-filter - tilt weighting factor when k1<0 */ +#define GAMMA3_PLUS_WB_FX 21299 /* WB post-filter, 0.65f */ +#define GAMMA3_MINUS_WB_FX 27853 /* WB post-filter, 0.85f */ +#define AGC_FAC_WB_FX 27853 /* WB post-filter - gain adjustment factor, 0.85f */ +#define AGC_FAC1_WB_FX (Word16)(32768L-AGC_FAC_WB_FX) /* WB post-filter - gain adjustment factor complement */ #define MAX_LEN_MA_FILTER 20 /* maximum length of the MA filter for SHB TD envelope calculation */ #define TABLE_CUMSUM_MAX_N 320 /* maximum length of cumsum(i) and cumsum(i*i) tables */ #define NUM_BITS_FB_FRAMEGAIN_TBE 4 /* Number of bits for framegain for FB TBE */ -/* SWB TBE, FX only constants */ -#define NOISE_QFAC 6 -#define NOISE_QADJ (15-NOISE_QFAC) + + /* SWB TBE, FX only constants */ +#define NOISE_QFAC 6 +#define NOISE_QADJ (15-NOISE_QFAC) /*----------------------------------------------------------------------------------* * SWB BWE constants *----------------------------------------------------------------------------------*/ -#define INV_L_SUBFR16k 0.0125f -#define INV_L_SUBFR16k_FX 410 /*Q15 */ +#define INV_L_SUBFR16k_FX 410 /* 0.0125f in Q15 */ #define SWB_L_SUBFR 160 #define FB_L_SUBFR 240 #define SWB_FENV 14 -#define FB_GAIN_QLOW 0.0f -#define FB_GAIN_QDELTA 0.03125f -#define FB_GAIN_QLOW_FX 0 -#define FB_GAIN_QDELTA_FX 512 /*Q14 */ -#define FB_MAX_GAIN_VAR 0.5f +#define FB_GAIN_QLOW_FX 0 +#define FB_GAIN_QDELTA_FX 512 /* 0.03125f in Q14 */ #define NUM_BITS_FB_FRAMEGAIN 4 /* Number of bits for framegain for FB BWE */ @@ -1725,19 +1497,13 @@ enum #define NBITS_THRESH_BWE_HR 400 /* BWE HR number of bits threshold */ #define NBITS_HF_GAIN_BWE_HR 2 /* number of bits for HF (noncoded) energy estimation */ -#define BWE_HR_TRANS_EN_LIMIT1 0.1f /* HF (noncoded) energy equalization limit 1, transient frames */ -#define BWE_HR_TRANS_EN_LIMIT2 0.3f /* HF (noncoded) energy equalization limit 2, transient frames */ -#define BWE_HR_TRANS_EN_LIMIT3 0.5f /* HF (noncoded) energy equalization limit 3, transient frames */ -#define BWE_HR_NONTRANS_EN_LIMIT1 0.5f /* HF (noncoded) energy equalization limit 1, non-transient frames */ -#define BWE_HR_NONTRANS_EN_LIMIT2 1.2f /* HF (noncoded) energy equalization limit 2, non-transient frames */ -#define BWE_HR_NONTRANS_EN_LIMIT3 0.8f /* HF (noncoded) energy equalization limit 3, non-transient frames */ -#define BWE_HR_TRANS_EN_LIMIT1_FX_Q16 6554 -#define BWE_HR_TRANS_EN_LIMIT2_FX_Q16 19661 -#define BWE_HR_TRANS_EN_LIMIT3_FX_Q16 32767 -#define BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15 16384 /* 0.5 */ -#define BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14 19661 /* 1.2 */ -#define BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 16384 -#define BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15 26214 /* 0.8 */ +#define BWE_HR_TRANS_EN_LIMIT1_FX_Q16 6554 /* 0.1, HF (noncoded) energy equalization limit 1, transient frames */ +#define BWE_HR_TRANS_EN_LIMIT2_FX_Q16 19661 /* 0.3, HF (noncoded) energy equalization limit 2, transient frames */ +#define BWE_HR_TRANS_EN_LIMIT3_FX_Q16 32767 /* 0.5, HF (noncoded) energy equalization limit 3, transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15 16384 /* 0.5, HF (noncoded) energy equalization limit 1, non-transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14 19661 /* 1.2, HF (noncoded) energy equalization limit 2, non-transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 16384 /* 1.2, HF (noncoded) energy equalization limit 2, non-transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15 26214 /* 0.8, HF (noncoded) energy equalization limit 3, non-transient frames */ /*----------------------------------------------------------------------------------* * FD CNG @@ -1756,21 +1522,14 @@ enum #define FD_CNG_stages_37bits 6 #define FD_CNG_JOINT_stages_25bits 4 -#define OUTMAX_INV 0.000030517578125f /* 1/2^15 */ -#define OUTMAX_INV_FX 65536 /* 1/2^15 (Q31) */ #define ONE_BY_NS2A_8K_ST_DFT32MS_OVL_NS (Word16)(0x051E) -#define OUTMAX_INV_FX_16 (Word16)(0x0001) /* 1/2^15 */ -#define OUTMAX_SQ 1073741824.f /* 2^30 */ -#define OUTMAX_SQ_INV 0.00000000093132257461547852f /* 1/2^30 */ -#define DELTA ( 1e-20f ) -#define DELTA_FX ( 1 ) -#define DELTA_MANTISSA_W16 0x5e73 -#define DELTA_MANTISSA_W32 0x5e728433 -#define DELTA_EXPONENT (-66) +#define DELTA_FX ( 1 ) +#define DELTA_MANTISSA_W16 0x5e73 +#define DELTA_MANTISSA_W32 0x5e728433 +#define DELTA_EXPONENT (-66) -#define CLDFB_SCALING_FLT ( 1.5f ) -#define CLDFB_SCALING 24576/*1.5 Q14*/ /* Q 2.14 */ +#define CLDFB_SCALING 24576 /*1.5 Q14*/ /* Q 2.14 */ #define FFTLEN 640 #define FFTLEN2 ( FFTLEN / 2 ) @@ -1782,13 +1541,13 @@ enum #define NPARTCLDFB 10 #define NPART_SHAPING 62 -#define FDCNG_VQ_MAX_LEN FD_CNG_maxN_37bits -#define FDCNG_VQ_DCT_NSEGM 4 -#define FDCNG_VQ_DCT_MINTRUNC 8 -#define FDCNG_VQ_DCT_MAXTRUNC 18 -#define FDCNG_VQ_MAX_LEN_WB 21 +#define FDCNG_VQ_MAX_LEN FD_CNG_maxN_37bits +#define FDCNG_VQ_DCT_NSEGM 4 +#define FDCNG_VQ_DCT_MINTRUNC 8 +#define FDCNG_VQ_DCT_MAXTRUNC 18 +#define FDCNG_VQ_MAX_LEN_WB 21 -#define FDCNG_VQ_DCT_NPOST 8 +#define FDCNG_VQ_DCT_NPOST 8 typedef enum _DCTTYPE { @@ -1803,59 +1562,44 @@ typedef enum _DCTTYPE #define MSNUMSUBFR 6 #define MSBUFLEN 5 -#define NOISE_HEADROOM 5 /* headroom of noise in generate_masking_noise_fx */ - -#define MSALPHACORALPHA_FLT 0.7f -#define MSALPHACORMAX_FLT 0.3f -#define MSALPHAMAX_FLT 0.96f -#define MSALPHAHATMIN_FLT 0.05f /* It is used for all bands except the first one to get a stable bass */ -#define MSQEQINVMAX_FLT ( 1.f / 5.f ) -#define MSAV_FLT 2.12f -#define MSBETAMAX_FLT 0.8f -#define MSSNREXP_FLT ( -0.02f / 0.064f ) -#define MSALPHACORALPHA 22938/*0.7f Q15*/ -#define MSALPHACORALPHA2 9830/*0.3f Q15*/ -#define MSALPHACORMAX 9830/*0.3f Q15*/ -#define MSALPHAMAX 31457/*0.96f Q15*/ -#define MSALPHAHATMIN 107374184l/*0.05f Q31*/ -#define MSQEQINVMAX 6554/*1.f/5.f Q15*/ -#define MSAV 17367/*2.12f Q13*/ -#define MSAV_EXP 2 -#define MSBETAMAX 1717986944l/*0.8f Q31*/ -#define MSBETAMAX_SQRT 1920767767l/*0.894427191 Q31*/ /* sqrt(MSBETAMAX) */ -#define MSSNREXP -10240/*-0.02f/0.064f Q15*/ - -#define NB_LAST_BAND_SCALE_FLT 0.8f -#define SWB_13k2_LAST_BAND_SCALE_FLT 0.8f -#define NB_LAST_BAND_SCALE 26214/*0.8f Q15*/ -#define SWB_13k2_LAST_BAND_SCALE 26214/*0.8f Q15*/ - -#define CNG_LOG_SCALING 512.f /*2^9*/ +#define NOISE_HEADROOM 5 /* headroom of noise in generate_masking_noise_fx */ + +#define MSALPHACORALPHA 22938 /*0.7f Q15*/ +#define MSALPHACORALPHA2 9830 /*0.3f Q15*/ +#define MSALPHACORMAX 9830 /*0.3f Q15*/ +#define MSALPHAMAX 31457 /*0.96f Q15*/ +#define MSALPHAHATMIN 107374184l /*0.05f Q31*/ +#define MSQEQINVMAX 6554 /*1.f/5.f Q15*/ +#define MSAV 17367 /*2.12f Q13*/ +#define MSAV_EXP 2 +#define MSBETAMAX 1717986944l /*0.8f Q31*/ +#define MSBETAMAX_SQRT 1920767767l /*0.894427191 Q31*/ /* sqrt(MSBETAMAX) */ +#define MSSNREXP -10240 /*-0.02f/0.064f Q15*/ + +#define NB_LAST_BAND_SCALE 26214 /*0.8f Q15*/ +#define SWB_13k2_LAST_BAND_SCALE 26214 /*0.8f Q15*/ #define M_MAX 32 -#define NSTAGES_MAX 9 -#define MBEST_MAX 8 +#define NSTAGES_MAX 9 +#define MBEST_MAX 8 #define N_GAIN_MIN 4 #define N_GAIN_MAX 17 -#define numSlots_inv_EXP (-3) -#define PREEMPH_COMPENSATION_EXP 4 +#define PREEMPH_COMPENSATION_EXP 4 #define CHEAP_NORM_SIZE 161 -#define CLDFBscalingFactor_EXP (-15) -#define CLDFBinvScalingFactor_EXP ( 16) +#define CLDFBscalingFactor_EXP (-15) +#define CLDFBinvScalingFactor_EXP ( 16) -#define CNG_NORM_RECIPROCAL_RANGE_SHIFT 2 -#define CNG_RAND_GAUSS_SHIFT 2 +#define CNG_NORM_RECIPROCAL_RANGE_SHIFT 2 +#define CNG_RAND_GAUSS_SHIFT 2 #define CNA_MAX_BRATE ACELP_13k20 #define CNA_INIT_NBANDS 6 -#define GAIN_Q_OFFSET_EVS 60.f -#define GAIN_Q_OFFSET_EVS_FX_Q0 60 -#define GAIN_Q_OFFSET_IVAS 45.f -#define GAIN_Q_OFFSET_IVAS_FX_Q0 45 +#define GAIN_Q_OFFSET_EVS_FX_Q0 60 +#define GAIN_Q_OFFSET_IVAS_FX_Q0 45 /*----------------------------------------------------------------------------------* * Bass post-filter constants @@ -1868,30 +1612,20 @@ typedef enum _DCTTYPE * NB post-filter constants *----------------------------------------------------------------------------------*/ -#define THRESCRIT 0.5f /* NB post-filter - threshold LT pst switch off */ -#define AGC_FAC 0.9875f /* NB post-filter - gain adjustment factor */ -#define AGC_FAC1 ( 1.0f - AGC_FAC ) /* NB post-filter - gain adjustment factor complement */ #define LONG_H_ST 20 /* NB post-filter - impulse response length */ -#define POST_G1 0.75f /* NB post-filter - denominator weighting factor 12kbps */ -#define POST_G2 0.7f /* NB post-filter - numerator weighting factor 12kbps */ -#define GAMMA1_PST12K_FX 24576 /* denominator weighting factor 12K (0.75 in Q15) */ -#define GAMMA2_PST12K_FX 22938 /* numerator weighting factor 12K (0.7 in Q15) */ -#define POST_G1_FX GAMMA1_PST12K_FX /* 12 kbps default */ -#define POST_G2_FX GAMMA2_PST12K_FX /* 12 kbps default */ - -#define GAMMA1_PST 0.7f /* denominator weighting factor */ -#define GAMMA2_PST 0.55f /* numerator weighting factor */ -#define GAMMA3_PLUS 0.2f /* NB post-filter - tilt weighting factor when k1>0 */ -#define GAMMA3_MINUS 0.9f /* NB post-filter - tilt weighting factor when k1<0 */ -#define GAMMA1_PST12K_MIN_FX 21299 /* 0.65 in Q15 */ -#define GAMMA2_PST12K_MIN_FX 18022 /* 0.55 in Q15 */ -#define GAMMA1_PST12K_NOIS_FX 4915 /* 0.15 in Q15 */ -#define GAMMA2_PST12K_NOIS_FX 3277 /* 0.10 in Q15 */ +#define GAMMA1_PST12K_FX 24576 /* denominator weighting factor 12K (0.75 in Q15) */ +#define GAMMA2_PST12K_FX 22938 /* numerator weighting factor 12K (0.7 in Q15) */ +#define POST_G1_FX GAMMA1_PST12K_FX /* 12 kbps default */ +#define POST_G2_FX GAMMA2_PST12K_FX /* 12 kbps default */ + +#define GAMMA1_PST12K_MIN_FX 21299 /* 0.65 in Q15 */ +#define GAMMA2_PST12K_MIN_FX 18022 /* 0.55 in Q15 */ +#define GAMMA1_PST12K_NOIS_FX 4915 /* 0.15 in Q15 */ +#define GAMMA2_PST12K_NOIS_FX 3277 /* 0.10 in Q15 */ #define F_UP_PST 8 /* NB post-filter - resolution for fractionnal delay */ #define LH2_S 4 /* NB post-filter - length of INT16 interp. subfilters */ #define LH2_L 16 /* NB post-filter - length of long interp. subfilters */ -#define MIN_GPLT ( 1.0f / 1.5f ) /* NB post-filter - LT gain minimum */ #define LH_UP_S ( LH2_S / 2 ) #define LH_UP_L ( LH2_L / 2 ) #define LH2_L_P1 ( LH2_L + 1 ) @@ -1900,24 +1634,13 @@ typedef enum _DCTTYPE #define SIZ_Y_UP ( ( F_UP_PST - 1 ) * ( L_SUBFR + 1 ) ) #define SIZ_TAB_HUP_L ( ( F_UP_PST - 1 ) * LH2_L ) #define SIZ_TAB_HUP_S ( ( F_UP_PST - 1 ) * LH2_S ) -#define POST_G1_MIN 0.65f -#define POST_G2_MIN 0.55f -#define POST_G1_NOIS 0.15f -#define POST_G2_NOIS 0.10f -#define BG1 ( -0.01f ) -#define BG2 ( -0.05f ) -#define CG1 0.9f -#define CG2 1.45f -#define C_LP_NOISE ( 0.1f / 4.0f ) -#define K_LP_NOISE 15.0f -#define LP_NOISE_THR 25.0f -#define BG1_FX -328 /* -0.01 in Q15 */ -#define BG2_FX -1638 /* -0.05 in Q15 */ -#define CG1_FX 29491 /* 0.9 in Q15 */ -#define CG2_FX 47514L /* 1.45 in Q15 */ -#define C_LP_NOISE_FX 819 /* 0.1/4.0 in Q15 */ -#define CK_LP_NOISE_FX 6291456L /* 15.0 * 0.1/4 in Q8 * 65536 */ -#define LP_NOISE_THR_FX 6400 /* 25.0 in Q8 */ +#define BG1_FX -328 /* -0.01 in Q15 */ +#define BG2_FX -1638 /* -0.05 in Q15 */ +#define CG1_FX 29491 /* 0.9 in Q15 */ +#define CG2_FX 47514L /* 1.45 in Q15 */ +#define C_LP_NOISE_FX 819 /* 0.1/4.0 in Q15 */ +#define CK_LP_NOISE_FX 6291456L /* 15.0 * 0.1/4 in Q8 * 65536 */ +#define LP_NOISE_THR_FX 6400 /* 25.0 in Q8 */ /*----------------------------------------------------------------------------------* * Stability estimation @@ -1925,16 +1648,11 @@ typedef enum _DCTTYPE #define NB_BFI_THR 2 /* threshold for counter of last bad frames */ #define MAX_LT 40 -#define INV_MAX_LT ( 1.0f / MAX_LT ) -#define TH_0_MIN 2.5f -#define TH_1_MIN 1.875f -#define TH_2_MIN 1.5625f -#define TH_3_MIN 1.3125f -#define TH_0_MIN_FX 5120 /* 2.5f in Q11 */ -#define TH_1_MIN_FX 3840 /* 1.875f in Q11 */ -#define TH_2_MIN_FX 3200 /* 1.5625f in Q11 */ -#define TH_3_MIN_FX 2688 /* 1.3125f in Q11 */ +#define TH_0_MIN_FX 5120 /* 2.5f in Q11 */ +#define TH_1_MIN_FX 3840 /* 1.875f in Q11 */ +#define TH_2_MIN_FX 3200 /* 1.5625f in Q11 */ +#define TH_3_MIN_FX 2688 /* 1.3125f in Q11 */ /*----------------------------------------------------------------------------------* * Speech/music classifier constants @@ -1953,12 +1671,12 @@ typedef enum _DCTTYPE #define N_SMC_MIXTURES 6 /* number of mixtures */ #define N_PCA_COEF 12 /* number of PCA components */ #define HALF_N_PCA_COEF_LOG_P12_Q18 2890731 //Q18 of (0.5f * N_PCA_COEF *logf( PI2 )) -#define SMC_ST_MEAN_RSHIFT_FACT_FX 1 /* SMC_ST_MEAN_FACT equivalent right shift factor */ +#define SMC_ST_MEAN_RSHIFT_FACT_FX 1 /* SMC_ST_MEAN_FACT equivalent right shift factor */ #define M_LSP_SPMUS 6 /* number of LSPs used in speech/music classifier */ #define NB_BANDS_SPMUS 15 #define START_BAND_SPMUS 2 -#define N_OLD_BIN_E 42 /* == (L_FFT/2-2)/3 */ +#define N_OLD_BIN_E 42 /* == (L_FFT/2-2)/3 */ #define LOWEST_FBIN 3 /* lowest frequency bin for feature vector preparation */ #define HIGHEST_FBIN 70 /* highest frequency bin for feature vector preparation */ @@ -1967,18 +1685,14 @@ typedef enum _DCTTYPE #define BUF_LEN 60 #define L_OVR 8 -#define N_FEATURES_2 3 /* number of features */ +#define N_FEATURES_2 3 /* number of features */ #define ATT_NSEG 32 /* strong attack detection - number of time blocks */ #define TOD_NSPEC 80 /* number of spectral bins of the tonal detector */ #define TOD_NSPEC_INV_Q31 26843546 /* inverse of number of spectral bins of the tonal detector */ -#define TOD_THR_MASS 0.86f /* initial value for the adaptive threshold of the tonal detector */ -#define TOD_THR_MASS_FX_Q22 3607101 /* initial value for the adaptive threshold of the tonal detector */ -#define P2A_FACT 0.9f /* long-term averaging factor for peak-to-average ratio */ -#define P2A_FACT_FX_Q15 29491 /* long-term averaging factor for peak-to-average ratio */ -#define THR_P2A_HIGH 95.0f /* higher threshold to detect strongly peaky signals at low bitrates*/ -#define THR_P2A 80.0f /* lower threshold to detect strongly peaky signals at higher bitrates */ +#define TOD_THR_MASS_FX_Q22 3607101 /* initial value for the adaptive threshold of the tonal detector, 0.86f in Q22 */ +#define P2A_FACT_FX_Q15 29491 /* long-term averaging factor for peak-to-average ratio, 0.9f in Q15 */ #define THR_P2A_HIGH_FX 95 /* Q0, higher threshold to detect strongly peaky signals at low bitrates*/ #define THR_P2A_FX 80 /* Q0, lower threshold to detect strongly peaky signals at higher bitrates */ @@ -2028,11 +1742,8 @@ typedef enum _DCTTYPE #define MBANDS_GN 16 /* Number of band for gain coding in GSC */ #define MBANDS_GN_BITALLOC16k 20 /* Number of band for gain coding in GSC */ #define BAND1k2 3 -#define DSR_NB_PULSE ( 4.5f ) -#define DSR_NB_PULSE_Q18 ( 1179648 ) -#define MAX_EQ_LF 1.0f +#define DSR_NB_PULSE_Q18 ( 1179648 ) /* 4.5f*/ #define MBANDS_LOC ( MBANDS_GN - 1 ) -#define BIN_SIZE 25.0f #define SWNB_SUBFR 1 #define MIN_RATE_4SBFR ACELP_16k40 @@ -2067,16 +1778,14 @@ typedef enum _DCTTYPE #define HQ_GEN_FB 5 #define PREECHO_SMOOTH_LEN 20 -#define INV_PREECHO_SMOOTH_LENP1 ( 1 / ( PREECHO_SMOOTH_LEN + 1.0 ) ); -#define EPSILON 0.000000000000001f +//#define EPSILON 0.000000000000001f #define EPSILON_FX_SMALL 1 #define EPSILON_FIX (1) #define EPSILON_FX (Word32)1 #define EPSILON_FX_M 1208925819 #define EPSILON_FX_E -49 - #define MAX_SEGMENT_LENGTH 480 #define NUM_TIME_SWITCHING_BLOCKS 4 #define NUM_MAP_BANDS 20 @@ -2115,7 +1824,7 @@ typedef enum _DCTTYPE #define HVQ_PVQ_BUF_LEN ( HVQ_PVQ_COEFS * ( MAX_PVQ_BANDS - 1 ) + HQ_MAX_BAND_LEN ) /* 24*7+96 = 216 */ #define QBIT_MAX2 9 -#define Q_PVQ_OUT 10 +#define Q_PVQ_OUT 10 #define FLAGN_BITS 1 #define GAIN0_BITS 5 @@ -2137,15 +1846,12 @@ typedef enum _DCTTYPE #define HUFF_THR 10 #define NOSUPERPOSITION 40 -#define MAXVALUEOFFIRSTGAIN 2.5f -#define MINVALUEOFFIRSTGAIN -2.5f -#define MAXVALUEOFFIRSTGAIN_FX 20480 /*2.5f in Q13 */ -#define MINVALUEOFFIRSTGAIN_FX -20480 +#define MAXVALUEOFFIRSTGAIN_FX 20480 /* 2.5f in Q13 */ +#define MINVALUEOFFIRSTGAIN_FX -20480 /* -2.5f in Q13 */ #define NOOFGAINBITS1 6 #define AUDIODELAYBITS 6 -#define DELTAOFFIRSTGAIN (float) ( MAXVALUEOFFIRSTGAIN - MINVALUEOFFIRSTGAIN ) / (float) ( ( 1 << NOOFGAINBITS1 ) - 1 ) -#define DELTAOFFIRSTGAIN_FX 2601 /*Q15 */ +#define DELTAOFFIRSTGAIN_FX 2601 /*Q15 */ #define MAX_D1M_16k ( ( L_FRAME16k >> 1 ) - NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) - 16 ) #define MAX_D1M_12k8 ( ( L_FRAME16k >> 1 ) - NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) - 20 ) @@ -2157,30 +1863,23 @@ typedef enum _DCTTYPE #define ENV_ADJ_START 6 /* Number of consecutive bands for which the attenuation is maximum */ #define ENV_ADJ_INCL 5 /* Inclination for mapping between attenuation region width and attenuation limit */ -#define ENV_SMOOTH_FAC 0.1f /* Smoothing factor for envelope stability measure */ -#define ENV_SMOOTH_FAC_FX ((Word16)0x0CCD) +#define ENV_SMOOTH_FAC_FX ((Word16)0x0CCD) /* Smoothing factor for envelope stability measure, 0.1f */ #define L_STAB_TBL 10 /* Number of elements in stability transition table */ -#define LUMPED_ENV_SMOOTH_FAC_FX ((Word16)10089) /* Q19 (no typo error), 0.1/sqrt(27) */ -#define CMPLMNT_ENV_SMOOTH_FAC_FX ((Word16)29491) /* Q15 0.9 */ +#define LUMPED_ENV_SMOOTH_FAC_FX ((Word16)10089) /* Q19 (no typo error), 0.1/sqrt(27) */ +#define CMPLMNT_ENV_SMOOTH_FAC_FX ((Word16)29491) /* Q15 0.9 */ #define M_STAB_TBL_FX ( (Word16) 21068 ) /* Q13, 2.571756 */ #define D_STAB_TBL_FX ( (Word16) 845 ) /* Q13 0.1013138 */ #define HALF_D_STAB_TBL_FX ( (Word16) 422 ) /* Q13 0.1013138/2.0 */ #define NUM_ENV_STAB_PLC_STATES 2 /* Number of states of markov model */ -#define INV_NUM_ENV_STAB_PLC_STATES 16384 /* Q15 */ -#define INV_STAB_TRANS_FX 16497 /* Q14. Equal to 1.0f/(1-2*stab_trans_fx[L_STAB_TBL-1]) */ - -#define ENV_STAB_EST1 2.93f /* env_stab estimation coefficient 1 */ -#define ENV_STAB_EST2 (-2.20f) /* env_stab estimation coefficient 2 */ -#define ENV_STAB_EST3 0.741f /* env_stab estimation coefficient 3 */ -#define ENV_STAB_EST1_FX 12001 /* env_stab estimation coefficient 1 *//*Q-12*/ -#define ENV_STAB_EST2_FX (-9011) /* env_stab estimation coefficient 2 *//*Q-12*/ -#define ENV_STAB_EST3_FX 3035 /* env_stab estimation coefficient 3 *//*Q-12*/ -#define STAB_FAC_EST1 1.093f /* stab_fac HQ estimation coefficient 1 */ -#define STAB_FAC_EST2 (-5.84e-05f) /* stab_fac HQ estimation coefficient 2, including Q12 scaling */ -#define STAB_FAC_EST3 0.125f /* stab_fac HQ estimation coefficient 3 */ -#define STAB_FAC_EST1_FX ((Word32)0x45F3B646) /* stab_fac HQ estimation coefficient 1 */ -#define STAB_FAC_EST2_FX ((Word32)0xFFFF0B0D) /* stab_fac HQ estimation coefficient 2, including Q12 scaling */ -#define STAB_FAC_EST3_FX ((Word32)0x10000000) /* stab_fac HQ estimation coefficient 3 */ +#define INV_NUM_ENV_STAB_PLC_STATES 16384 /* Q15 */ +#define INV_STAB_TRANS_FX 16497 /* Q14. Equal to 1.0f/(1-2*stab_trans_fx[L_STAB_TBL-1]) */ + +#define ENV_STAB_EST1_FX 12001 /* env_stab estimation coefficient 1, 2.93f *//*Q-12*/ +#define ENV_STAB_EST2_FX (-9011) /* env_stab estimation coefficient 2, -2.20f *//*Q-12*/ +#define ENV_STAB_EST3_FX 3035 /* env_stab estimation coefficient 3, 0.741f *//*Q-12*/ +#define STAB_FAC_EST1_FX ((Word32)0x45F3B646) /* stab_fac HQ estimation coefficient 1, 1.093f */ +#define STAB_FAC_EST2_FX ((Word32)0xFFFF0B0D) /* stab_fac HQ estimation coefficient 2, (-5.84e-05f), including Q12 scaling */ +#define STAB_FAC_EST3_FX ((Word32)0x10000000) /* stab_fac HQ estimation coefficient 3, 0.125f */ #define ATT_LIM_HANGOVER 150 /* Number of hangover frames for disabling stability dependent attenuation */ #define DELTA_TH 5.0f /* Delta energy threshold for transient detection for envelope stability */ @@ -2213,8 +1912,6 @@ typedef enum _DCTTYPE #define HQ_GENERIC_EXC1 1 #define HQ_GENERIC_SP_EXC 2 -#define LF_EMP_FAC 1.2f - #define DIM_FB 3 #define HQ_FB_FENV SWB_FENV + DIM_FB #define N_CB_FB 32 @@ -2252,52 +1949,37 @@ typedef enum _DCTTYPE #define HVQ_NEW_BAND_BIT_THR 30 #define HVQ_NF_GROUPS 2 -#define HVQ_NF_WEIGHT1 0.9578f /* HVQ Classifier - Noise floor estimate weight 1 */ -#define HVQ_NF_WEIGHT2 0.6472f /* HVQ Classifier - Noise floor estimate weight 2 */ -#define HVQ_PE_WEIGHT1 0.42237f /* HVQ Classifier - Peak envelope estimate weight 1 */ -#define HVQ_PE_WEIGHT2 0.80285f /* HVQ Classifier - Peak envelope estimate weight 2 */ -#define HVQ_THR_POW 0.88f /* HVQ Classifier power factor for threshold calc */ #define HVQ_SHARP_THRES 9 /* HVQ Classifier - Sharpness threshold */ -#define HVQ_NF_WEIGHT1_FX 31385 /* Q15 0.9578 - HVQ Classifier - Noise floor estimate weight 1 */ -#define HVQ_NF_WEIGHT1B 1383 /* Q15, 1 - HVQ_NF_WEIGHT1_FX */ -#define HVQ_NF_WEIGHT2_FX 21207 /* Q15 0.6472 - HVQ Classifier - Noise floor estimate weight 2 */ -#define HVQ_NF_WEIGHT2B 11561 /* Q15 1 - HVQ_NF_WEIGHT2_FX */ -#define HVQ_PE_WEIGHT1_FX 13840 /* Q15 0.42237 - HVQ Classifier - Peak envelope estimate weight 1 */ -#define HVQ_PE_WEIGHT1B 18928 /* Q15, 1 - HVQ_PE_WEIGHT1_FX */ -#define HVQ_PE_WEIGHT2_FX 26308 /* Q15 0.80285 - HVQ Classifier - Peak envelope estimate weight 2 */ -#define HVQ_PE_WEIGHT2B 6460 /* Q15, 1 - HVQ_PE_WEIGHT2_FX */ -#define HVQ_SHARP_THRES_FX 576 /*9 in Q6 */ - -#define HVQ_PA_FAC 0.7071f /* HVQ Classifier peak allocation factor */ -#define HVQ_PA_FAC_FX 23170 /* Q15 0.7071 - HVQ Classifier peak allocation factor */ +#define HVQ_NF_WEIGHT1_FX 31385 /* Q15 0.9578 - HVQ Classifier - Noise floor estimate weight 1 */ +#define HVQ_NF_WEIGHT1B 1383 /* Q15, 1 - HVQ_NF_WEIGHT1_FX */ +#define HVQ_NF_WEIGHT2_FX 21207 /* Q15 0.6472 - HVQ Classifier - Noise floor estimate weight 2 */ +#define HVQ_NF_WEIGHT2B 11561 /* Q15 1 - HVQ_NF_WEIGHT2_FX */ +#define HVQ_PE_WEIGHT1_FX 13840 /* Q15 0.42237 - HVQ Classifier - Peak envelope estimate weight 1 */ +#define HVQ_PE_WEIGHT1B 18928 /* Q15, 1 - HVQ_PE_WEIGHT1_FX */ +#define HVQ_PE_WEIGHT2_FX 26308 /* Q15 0.80285 - HVQ Classifier - Peak envelope estimate weight 2 */ +#define HVQ_PE_WEIGHT2B 6460 /* Q15, 1 - HVQ_PE_WEIGHT2_FX */ +#define HVQ_SHARP_THRES_FX 576 /* 9 in Q6 */ + +#define HVQ_PA_FAC_FX 23170 /* Q15 0.7071 - HVQ Classifier peak allocation factor */ #define HVQ_PA_PEAKS_SHARP1 9 /* HVQ Classifier - Maximum number of peaks for band with high sharpness */ #define HVQ_PA_PEAKS_SHARP2 3 /* HVQ Classifier - Maximum number of peaks for band with medium sharpness */ #define HVQ_PA_PEAKS_SHARP3 2 /* HVQ Classifier - Maximum number of peaks for band with low sharpness */ -#define HVQ_PA_SHARP_THRES2 16.0f /* HVQ Classifier - Sharpness threshold for band with medium sharpness */ -#define HVQ_PA_SHARP_THRES3 12.0f /* HVQ Classifier - Sharpness threshold for band with low sharpness */ -#define HVQ_PA_SHARP_THRES2_FX 1024 /* Q6 16.0 - HVQ Classifier - Sharpness threshold for band with medium sharpness */ -#define HVQ_PA_SHARP_THRES3_FX 768 /* Q6 12.0 - HVQ Classifier - Sharpness threshold for band with low sharpness */ +#define HVQ_PA_SHARP_THRES2_FX 1024 /* Q6 16.0 - HVQ Classifier - Sharpness threshold for band with medium sharpness */ +#define HVQ_PA_SHARP_THRES3_FX 768 /* Q6 12.0 - HVQ Classifier - Sharpness threshold for band with low sharpness */ #define HVQ_BW 32 /* HVQ Classifier subband bandwidth */ #define HVQ_NSUB_32k 10 #define HVQ_NSUB_24k 7 /* HVQ Classifier number of subbands */ -#define HQ_CREST_THRESHOLD 7.0f /* HQ harmonic high band classifier, crest threshold */ -#define HQ_CREST_THRESHOLD_FX 1879048192 //7.0f in Q28 /* HQ harmonic high band classifier, crest threshold */ -#define HQ_CREST_MOD_THRESHOLD 2.128f /* HQ harmonic high band classifier, modified crest threshold */ -#define HQ_CREST_MOD_THRESHOLD_FX 1142461301 //2.128f in Q29 /* HQ harmonic high band classifier, modified crest threshold */ -#define HQ_CREST_FAC_SM 0.97f /* HQ harmonic high band classifier, smoothing factor */ -#define HQ_CREST_FAC_SM_FX 2083059139 //0.97f in Q31 /* HQ harmonic high band classifier, smoothing factor */ +#define HQ_CREST_THRESHOLD_FX 1879048192 /* HQ harmonic high band classifier, crest threshold, 7.0f in Q28 */ +#define HQ_CREST_MOD_THRESHOLD_FX 1142461301 /* HQ harmonic high band classifier, modified crest threshold, 2.128f in Q29 */ +#define HQ_CREST_FAC_SM_FX 2083059139 /* HQ harmonic high band classifier, smoothing factor, 0.97f in Q31 */ #define HVQ_BWE_NOISE_BANDS 2 /* Number of BWE noise bands */ -#define HVQ_BWE_WEIGHT1 0.95f -#define HVQ_BWE_WEIGHT2 0.2f -#define HVQ_NFPE_FACTOR 6.4f -#define HVQ_LB_NFPE_FACTOR 3.2f -#define HVQ_BWE_WEIGHT1_FX ((Word16)31130) /* 0.95 in Q15 */ -#define HVQ_BWE_WEIGHT2_FX ((Word16)6554) /* 0.2 in Q15 */ -#define HVQ_NFPE_FACTOR_CUBE_FX ((Word16)16777) /* 6.4^3 in Q6 */ -#define HVQ_LB_NFPE_FACTOR_CUBE_FX ((Word16)16777) /* 3.2^3 in Q9 */ +#define HVQ_BWE_WEIGHT1_FX ((Word16)31130) /* 0.95 in Q15 */ +#define HVQ_BWE_WEIGHT2_FX ((Word16)6554) /* 0.2 in Q15 */ +#define HVQ_NFPE_FACTOR_CUBE_FX ((Word16)16777) /* 6.4^3 in Q6 */ +#define HVQ_LB_NFPE_FACTOR_CUBE_FX ((Word16)16777) /* 3.2^3 in Q9 */ #define HVQ_VQ_DIM 5 /* HVQ peak VQ dimension */ #define HVQ_PVQ_GAIN_BITS 5 /* Number of bits to encode PVQ gains in HVQ */ @@ -2341,9 +2023,9 @@ enum QuantaMode #define KMAX 512 #define KMAX_NON_DIRECT 96 /* max K for non-direct indexing recursion rows */ #define ODD_DIV_SIZE 48 /* ind0=1/1 ind1 =1/3 ... ind47=1/95 */ -#define KMAX_FX 512 -#define KMAX_NON_DIRECT_FX 96 /* max K for non-direct indexing recursion rows is 1+KMAX_NON_DIRECT +1 */ -#define ODD_DIV_SIZE_FX 48 /* ind0=1/1 ind1 =1/3 ... ind47=1/95 */ +#define KMAX_FX 512 +#define KMAX_NON_DIRECT_FX 96 /* max K for non-direct indexing recursion rows is 1+KMAX_NON_DIRECT +1 */ +#define ODD_DIV_SIZE_FX 48 /* ind0=1/1 ind1 =1/3 ... ind47=1/95 */ /* TCQ */ #define TCQ_MAX_BAND_SIZE 120 /* Maxiumum supported band size for TCQ+USQ search */ @@ -2500,8 +2182,7 @@ enum QuantaMode #define MAX_PLOCS L_PROT48k / 4 + 1 /* maximum number of spectral peaks to be searched */ #define QUOT_LPR_LTR 4 #define LGW_MAX 9 /* maximum number frequency group widths */ -#define BETA_MUTE_FAC_INI_FLT 0.5f /* initial noise attenuation factor */ -#define BETA_MUTE_FAC_INI 16384 /* Q15, initial noise attenuation factor */ +#define BETA_MUTE_FAC_INI 16384 /* 0.5f in Q15, initial noise attenuation factor */ #define L_TRANA32k ( L_PROT32k / QUOT_LPR_LTR ) /* transient analysis frame length */ #define L_TRANA16k ( L_TRANA32k / 2 ) #define L_TRANA8k ( L_TRANA32k / 4 ) @@ -2517,16 +2198,11 @@ enum QuantaMode #define OFF_FRAMES_LIMIT 30 /* HQ phase ECU, burst length for muting to zero */ #define PH_ECU_MUTE_START 15 /* HQ phase ECU, burst length to start steep muting */ -#define SCALE_DOWN_3dB 0.7071f -#define MAX_TILT 0.f -#define ED_THRES 1.0f +//#define SCALE_DOWN_3dB 0.7071f -#define ED_THRES_12P 0.032209f -#define ED_THRES_50P 0.159063f -#define ED_THRES_90P 0.532669 -#define ED_THRES_12P_fx 66 -#define ED_THRES_50P_fx 326 -#define ED_THRES_90P_fx 1091 +#define ED_THRES_12P_fx 66 /* 0.032209f */ +#define ED_THRES_50P_fx 326 /* 0.159063f */ +#define ED_THRES_90P_fx 1091 /* 0.532669f */ #define MAXDELAY_FEC 224 @@ -2544,26 +2220,19 @@ enum QuantaMode #define GROUP_LENGTH 7 #define MAX_PEAKS_FROM_PITCH 10 #define LAST_HARMONIC_POS_TO_CHECK 128 /* 128 because we check harmonics only up to 3.2 kHz */ -#define ALLOWED_SIDE_LOBE_FLUCTUATION_FLT 3.0f /* 4.8 dB */ -#define ALLOWED_SIDE_LOBE_FLUCTUATION 24576/*3.0f Q13*/ /* 4.8 dB */ -#define ALLOWED_SIDE_LOBE_FLUCTUATION_EXP 2 -#define LEVEL_ABOVE_ENVELOPE_FLT 7.59f /* 8.8 dB */ -#define UNREACHABLE_THRESHOLD_FLT 16.0f /* 12 dB Increase of LEVEL_ABOVE_ENVELOPE_FLT so that the threshold is not reached */ -#define SMALL_THRESHOLD_FLT 1.10f /* 0.41 dB Increase of LEVEL_ABOVE_ENVELOPE_FLT for the peak detection at a definitive peak in the estimated spectrum */ -#define BIG_THRESHOLD_FLT 1.5f /* 1.76 dB Increase of LEVEL_ABOVE_ENVELOPE_FLT for the peak detection at a probable peak in the estimated spectrum */ -#define LEVEL_ABOVE_ENVELOPE 7.59f /* 8.8 dB */ -#define UNREACHABLE_THRESHOLD 16384/*16.0f Q10*/ /* 12 dB Increase of LEVEL_ABOVE_ENVELOPE so that the threshold is not reached */ -#define SMALL_THRESHOLD 1126/*1.10f Q10*/ /* 0.41 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a definitive peak in the estimated spectrum */ -#define BIG_THRESHOLD 1536/*1.5f Q10*/ /* 1.76 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a probable peak in the estimated spectrum */ - -#define kSmallerLagsTargetBitsThreshold 150 -#define kCtxHmOlRSThr_FLT 2.6f -#define kLtpHmGainThr_FLT 0.46f /* Use the LTP pitch lag in the harmonic model? */ -#define kLtpHmGainThr 0x3AE1 /* 0.46f */ -#define kCtxHmOlRSThr 0x5333 /* 2.6f (2Q13) */ - -#define kTcxHmSnrOffsetGc 8/*0.03125f Q8*/ -#define kTcxHmSnrOffsetVc 0 +#define ALLOWED_SIDE_LOBE_FLUCTUATION 24576 /*3.0f Q13*/ /* 4.8 dB */ +#define ALLOWED_SIDE_LOBE_FLUCTUATION_EXP 2 +#define LEVEL_ABOVE_ENVELOPE 7.59f /* 8.8 dB */ +#define UNREACHABLE_THRESHOLD 16384 /* 16.0f Q10*/ /* 12 dB Increase of LEVEL_ABOVE_ENVELOPE so that the threshold is not reached */ +#define SMALL_THRESHOLD 1126 /* 1.10f Q10*/ /* 0.41 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a definitive peak in the estimated spectrum */ +#define BIG_THRESHOLD 1536 /* 1.5f Q10*/ /* 1.76 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a probable peak in the estimated spectrum */ + +#define kSmallerLagsTargetBitsThreshold 150 +#define kLtpHmGainThr 0x3AE1 /* 0.46f, Use the LTP pitch lag in the harmonic model? */ +#define kCtxHmOlRSThr 0x5333 /* 2.6f (2Q13) */ + +#define kTcxHmSnrOffsetGc 8 /* 0.03125f Q8 */ +#define kTcxHmSnrOffsetVc 0 #define kTcxHmNumGainBits 2 /* Number of bits for the gain index */ #define kTcxHmParabolaHalfWidth 4 /* Parabola half width */ @@ -2670,13 +2339,9 @@ enum #define CUTFREE_ABS_RANGE 6 #define CUTFREE_REL_RANGE 0.25 -#define VBR_ADR_MAX_TARGET 6.15f /* max target ADR for VBR. This rate is used in the closed loop rate control */ +#define PPP_LAG_THRLD_Q6 180*64 #define PPP_LAG_THRLD 180 /* max lag allowed for PPP coding */ - -#define PPP_LAG_THRLD_Q6 180*64 -#define PPP_LAG_THRLD 180 -#define SNR_THLD_FX_Q8 17152 /* Threshold is upscaled to Q8 to compared with st->vadsnr*/ - +#define SNR_THLD_FX_Q8 17152 /* Threshold is upscaled to Q8 to compared with st->vadsnr*/ #define MAXLAG_WI ( PPP_LAG_THRLD / 2 + 12 ) /* Maximum lag used in waveform interpolation */ #define MAX_LAG_PIT ( PPP_LAG_THRLD + 21 ) /* Max possible pitch lag after adding delta lag */ @@ -2687,21 +2352,21 @@ enum #define Q_SCALE 7 -#define CONST_1_16_Q14 19005 /* 1.16*16384 */ -#define CONST_1_37_Q14 22446 /* 1.37*16384 */ -#define SCALE_DOWN_ERAS_Q15 26214 /* 0.8*32768 */ -#define SHAPE1_COEF_QF 15 /* shape1 num and den coeffcient Q format */ -#define SHAPE2_COEF_QF 15 /* shape2 num and den coeffcient Q format */ -#define SHAPE3_COEF_QF 15 /* shape3 num and den coeffcient Q format */ -#define BP1_COEF_WB_QF 14 /* wb num and den coeffcient Q format */ -#define BP1_COEF_NB_QF_ORDER7 13 /* nb num and den coeffcient Q format */ +#define CONST_1_16_Q14 19005 /* 1.16*16384 */ +#define CONST_1_37_Q14 22446 /* 1.37*16384 */ +#define SCALE_DOWN_ERAS_Q15 26214 /* 0.8*32768 */ +#define SHAPE1_COEF_QF 15 /* shape1 num and den coeffcient Q format */ +#define SHAPE2_COEF_QF 15 /* shape2 num and den coeffcient Q format */ +#define SHAPE3_COEF_QF 15 /* shape3 num and den coeffcient Q format */ +#define BP1_COEF_WB_QF 14 /* wb num and den coeffcient Q format */ +#define BP1_COEF_NB_QF_ORDER7 13 /* nb num and den coeffcient Q format */ /*----------------------------------------------------------------------------------* * JBM *----------------------------------------------------------------------------------*/ -#define MAX_JBM_SLOTS 100 /* every primary copy and partial copy stored in JBM needs one slot */ -#define MAX_AU_SIZE ( ( MAX_BITS_PER_FRAME + 7 ) / 8 ) /* max frame size in bytes */ +#define MAX_JBM_SLOTS 100 /* every primary copy and partial copy stored in JBM needs one slot */ +#define MAX_AU_SIZE ( ( MAX_BITS_PER_FRAME + 7 ) / 8 ) /* max frame size in bytes */ #define ACTIVE 4 #define BACKGROUND 1 @@ -2715,97 +2380,97 @@ enum /*------------------------------------------------------------------------------------* FEC_clas_estim constants *-------------------------------------------------------------------------------------*/ + #define Q_MAX 12 -#define LG10 24660 /* 10*log10(2) in Q13 */ +#define LG10 24660 /* 10*log10(2) in Q13 */ #define L_Q_MEM 5 #define GE_SHIFT 6 #define LSF_1_OVER_256SQ 5000 #define LSF_1_OVER_256SQSQ 763 -#define G_CODE_MIN_TC_Q15 655 /*0.02 Q15*/ +#define G_CODE_MIN_TC_Q15 655 /*0.02 Q15*/ #define G_CODE_MAX_TC_Q0 5 -#define G_PITCH_MIN_Q14 0 /* SQ of gains: pitch gain lower limit (0.0 in Q13) */ -#define G_PITCH_MAX_MINUS_MIN_Q13 9994 /* SQ of gains: pitch gain upper limit (1.22-0 in Q13) */ +#define G_PITCH_MIN_Q14 0 /* SQ of gains: pitch gain lower limit (0.0 in Q13) */ +#define G_PITCH_MAX_MINUS_MIN_Q13 9994 /* SQ of gains: pitch gain upper limit (1.22-0 in Q13) */ /* higher ACELP constants */ -#define G_AVQ_MIN_32kbps_Q15 2621 /* lower limit for gain Q in higher-rate ACELP contribtuion @32kbps (0.08 in Q15) */ -#define G_AVQ_MIN_Q15 26214 /* lower limit for gain Q in higher-rate ACELP contribtuion (0.8 in Q15) */ -#define G_AVQ_MAX_Q0 96 /* upper limit for gain Q in higher-rate ACELP contribtuion */ - -#define LG10_G_AVQ_MIN_32kbps_Q14 (-17972) /* log10(0.08) lower limit for gain Q in higher-rate ACELP contribtuion @32kbps (0.08 in Q15) */ -#define LG10_G_AVQ_MIN_Q14 (-1588) /* log10(0.8) lower limit for gain Q in higher-rate ACELP contribtuion (0.8 in Q15) */ -#define LG10_G_AVQ_MAX_Q13 16239 /* log10(96) upper limit for gain Q in higher-rate ACELP contribtuion */ -#define LG10_G_CODE_MIN_TC192_Q14 (-3635) /* log10(0.6) */ -#define LG10_G_CODE_MAX_TC192_Q13 13212 /* log10(41) */ -#define LG10_G_CODE_MAX_Q13 5726 /* log10(5) SQ of gains: code gain upper limit */ -#define LG10_G_CODE_MIN_Q14 (-27836) /* log10(0.02) SQ of gains: code gain lower limit */ -#define LG10_G_CODE_MIN_TC_Q14 LG10_G_CODE_MIN_Q14 /* log10(0.02) Q15*/ -#define LG10_G_CODE_MAX_TC_Q13 LG10_G_CODE_MAX_Q13 - -#define LN_2_Q31 (1488521848 ) +#define G_AVQ_MIN_32kbps_Q15 2621 /* lower limit for gain Q in higher-rate ACELP contribtuion @32kbps (0.08 in Q15) */ +#define G_AVQ_MIN_Q15 26214 /* lower limit for gain Q in higher-rate ACELP contribtuion (0.8 in Q15) */ +#define G_AVQ_MAX_Q0 96 /* upper limit for gain Q in higher-rate ACELP contribtuion */ + +#define LG10_G_AVQ_MIN_32kbps_Q14 (-17972) /* log10(0.08) lower limit for gain Q in higher-rate ACELP contribtuion @32kbps (0.08 in Q15) */ +#define LG10_G_AVQ_MIN_Q14 (-1588) /* log10(0.8) lower limit for gain Q in higher-rate ACELP contribtuion (0.8 in Q15) */ +#define LG10_G_AVQ_MAX_Q13 16239 /* log10(96) upper limit for gain Q in higher-rate ACELP contribtuion */ +#define LG10_G_CODE_MIN_TC192_Q14 (-3635) /* log10(0.6) */ +#define LG10_G_CODE_MAX_TC192_Q13 13212 /* log10(41) */ +#define LG10_G_CODE_MAX_Q13 5726 /* log10(5) SQ of gains: code gain upper limit */ +#define LG10_G_CODE_MIN_Q14 (-27836) /* log10(0.02) SQ of gains: code gain lower limit */ +#define LG10_G_CODE_MIN_TC_Q14 LG10_G_CODE_MIN_Q14 /* log10(0.02) Q15*/ +#define LG10_G_CODE_MAX_TC_Q13 LG10_G_CODE_MAX_Q13 + +#define LN_2_Q31 (1488521848 ) /* AVQ (RE8) related consatnts */ -#define QR 32768 -#define Q_AVQ_OUT 6 /* AVQ_output scaling currently Q9, but may change */ -#define Q_AVQ_OUT_DEC 10 +#define QR 32768 +#define Q_AVQ_OUT 6 /* AVQ_output scaling currently Q9, but may change */ +#define Q_AVQ_OUT_DEC 10 -#define PIT_DECODE_2XL_SUBFR (2*L_SUBFR) -#define PIT_FR1_8b_MINUS_PIT_MIN_X2 ((PIT_FR1_8b-PIT_MIN)*2) +#define PIT_DECODE_2XL_SUBFR (2*L_SUBFR) +#define PIT_FR1_8b_MINUS_PIT_MIN_X2 ((PIT_FR1_8b-PIT_MIN)*2) #define PIT_FR1_8b_MINUS_PIT_FR1_8b_MINUS_PIT_MIN_X2 (PIT_FR1_8b-PIT_FR1_8b_MINUS_PIT_MIN_X2) -#define PIT_FR2_9b_MINUS_PIT_MIN_X4 ((PIT_FR2_9b-PIT_MIN)*4) -#define PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2) -#define PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) -#define PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2 ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2) -#define PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2 ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2 ) -#define PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 ) - -#define PIT_DECODE_1 ((PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) -#define PIT_DECODE_2 ((PIT_FR2_9b-PIT_MIN)*4) -#define PIT_DECODE_3 (PIT_FR1_9b - ((PIT_FR2_9b-PIT_MIN)*4) - ((PIT_FR1_9b-PIT_FR2_9b)*2)) -#define PIT_DECODE_7 (PIT_FR1_EXTEND_9b - (PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4) - (PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2)) -#define PIT_DECODE_8 (PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2)) -#define PIT_DECODE_9 (( (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 + (PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)) -#define PIT_DECODE_10 (PIT_FR1_DOUBLEEXTEND_9b - ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) - ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)) - -#define BIN4_FX 800 -#define TH_COR_FX 19661 /* Q15 Minimum correlation for per bin processing */ -#define TH_D_FX 800 /* 50 (Q4) Difference limit between nearest harmonic and a frequency bin */ -#define TH_PIT_FX 128 /* (Fs / (2.0f * TH_D)) Maximum pitch for per bin processing */ - -#define GUESS_TBL_SZ 256 -#define INT_FS_FX 12800 /* internal sampling frequency */ -#define INT_FS_16k_FX 16000 /* CELP core internal sampling frequency @16kHz */ - -#define WB_LIMIT_LSF_FX 16256 -#define Fs_2 16384 /* lsf max value (Use in reorder_fx.c) */ -#define Fs_2_16k 20480 /* lsf max value (Use in reorder_fx.c) */ - -#define LG10 24660 /* 10*log10(2) in Q13 */ -#define TEN_MULT_LOG10_2_IN_Q29 1616142464 /* (10 * log10(2)) = 3.0103 (in Q29) */ -#define LG10_s3_0 16440 /* 10*log10(2)/1.55 = 1.00343331 in Q14 */ -#define LOG2_10 27213 /* log base 2 of 10 in Q12 */ -#define LOG2_10_Q29 1783446566 /* log base 2 of 10 in Q12 */ -#define LOG10_2_Q31 646456993 /* inverse log base 10 of 2 in Q31 */ -#define INV_LOG2_10 9864 /* 1/log2(10), Q15*/ -#define MU_MA_FX 10923 /* original prediction factor for the AMR WB tables (Q15) */ - -#define E_MIN_FXQ15 115 /* Q15*/ -#define E_MIN_FXQ31 7516193 /* 0.0035d in Q31*/ - -#define MAX_DYNAMIC_FX (82*128) -#define MIN_DYNAMIC_FX (50*128) -#define DYNAMIC_RANGE_FX (MAX_DYNAMIC_FX-MIN_DYNAMIC_FX) -#define MAX_GSC_NF_BITS 3 -//#define GSC_NF_STEPS (1 << MAX_GSC_NF_BITS) -#define GSF_NF_DELTA_FX (DYNAMIC_RANGE_FX/GSC_NF_STEPS) +#define PIT_FR2_9b_MINUS_PIT_MIN_X4 ((PIT_FR2_9b-PIT_MIN)*4) +#define PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2) +#define PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) +#define PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2 ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2) +#define PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2 ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2 ) +#define PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 ) + +#define PIT_DECODE_1 ((PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) +#define PIT_DECODE_2 ((PIT_FR2_9b-PIT_MIN)*4) +#define PIT_DECODE_3 (PIT_FR1_9b - ((PIT_FR2_9b-PIT_MIN)*4) - ((PIT_FR1_9b-PIT_FR2_9b)*2)) +#define PIT_DECODE_7 (PIT_FR1_EXTEND_9b - (PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4) - (PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2)) +#define PIT_DECODE_8 (PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2)) +#define PIT_DECODE_9 (( (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 + (PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)) +#define PIT_DECODE_10 (PIT_FR1_DOUBLEEXTEND_9b - ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) - ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)) + +#define BIN4_FX 800 +#define TH_COR_FX 19661 /* Q15 Minimum correlation for per bin processing */ +#define TH_D_FX 800 /* 50 (Q4) Difference limit between nearest harmonic and a frequency bin */ +#define TH_PIT_FX 128 /* (Fs / (2.0f * TH_D)) Maximum pitch for per bin processing */ + +#define GUESS_TBL_SZ 256 +#define INT_FS_FX 12800 /* internal sampling frequency */ +#define INT_FS_16k_FX 16000 /* CELP core internal sampling frequency @16kHz */ + +#define WB_LIMIT_LSF_FX 16256 +#define Fs_2 16384 /* lsf max value (Use in reorder_fx.c) */ +#define Fs_2_16k 20480 /* lsf max value (Use in reorder_fx.c) */ + +#define LG10 24660 /* 10*log10(2) in Q13 */ +#define TEN_MULT_LOG10_2_IN_Q29 1616142464 /* (10 * log10(2)) = 3.0103 (in Q29) */ +#define LG10_s3_0 16440 /* 10*log10(2)/1.55 = 1.00343331 in Q14 */ +#define LOG2_10 27213 /* log base 2 of 10 in Q12 */ +#define LOG2_10_Q29 1783446566 /* log base 2 of 10 in Q12 */ +#define LOG10_2_Q31 646456993 /* inverse log base 10 of 2 in Q31 */ +#define INV_LOG2_10 9864 /* 1/log2(10), Q15*/ +#define MU_MA_FX 10923 /* original prediction factor for the AMR WB tables (Q15) */ + +#define E_MIN_FXQ15 115 /* Q15*/ +#define E_MIN_FXQ31 7516193 /* 0.0035d in Q31*/ + +#define MAX_DYNAMIC_FX (82*128) +#define MIN_DYNAMIC_FX (50*128) +#define DYNAMIC_RANGE_FX (MAX_DYNAMIC_FX-MIN_DYNAMIC_FX) +#define MAX_GSC_NF_BITS 3 +#define GSF_NF_DELTA_FX (DYNAMIC_RANGE_FX/GSC_NF_STEPS) /*----------------------------------------------------------------------------------* * AVQ constants *----------------------------------------------------------------------------------*/ -#define MIN_GLOB_GAIN_BWE_HR_FX 24576 /* Q13 */ -#define MAX_GLOB_GAIN_BWE_HR_FX 32000 /* Q6 */ +#define MIN_GLOB_GAIN_BWE_HR_FX 24576 /* Q13 */ +#define MAX_GLOB_GAIN_BWE_HR_FX 32000 /* Q6 */ #define LG10_MIN_GLOB_GAIN_BWE_HR_Q14 7817 #define LG10_MAX_GLOB_GAIN_BWE_HR_Q13 22110 @@ -2814,186 +2479,187 @@ enum * LD music post-filter constants *----------------------------------------------------------------------------------*/ -#define BIN_16kdct_fx (6400/DCT_L_POST) -#define E_MIN_Q15 14680 /* 0.0035 -> Q22 */ +#define BIN_16kdct_fx (6400/DCT_L_POST) +#define E_MIN_Q15 14680 /* 0.0035 -> Q22 */ -#define QSCALE 7 -#define MODE2_E_MIN 4/*0.03f Q0*/ /* 0.03f in QSCALE */ -#define MODE2_E_MIN_Q15 983/*0.03f Q15*/ /* 0.03f in Q15*/ +#define QSCALE 7 +#define MODE2_E_MIN 4 /*0.03f Q0*/ /* 0.03f in QSCALE */ +#define MODE2_E_MIN_Q15 983 /*0.03f Q15*/ /* 0.03f in Q15*/ /* long term pst parameters : */ -#define L2_LH2_L 4 /* log2(LH2_L) */ -#define MIN_GPLT_FX 21845 /* LT gain minimum 1/1.5 (Q15) */ +#define L2_LH2_L 4 /* log2(LH2_L) */ +#define MIN_GPLT_FX 21845 /* LT gain minimum 1/1.5 (Q15) */ -#define AGC_FAC_FX 32358 /* gain adjustment factor 0.9875 (Q15) */ -#define AGC_FAC1_FX (Word16)(32768L - AGC_FAC_FX) +#define AGC_FAC_FX 32358 /* gain adjustment factor 0.9875 (Q15) */ +#define AGC_FAC1_FX (Word16)(32768L - AGC_FAC_FX) -#define DOWNMIX_12k8_FX 1850 +#define DOWNMIX_12k8_FX 1850 /*----------------------------------------------------------------------------------* * HQ Constants *----------------------------------------------------------------------------------*/ -#define INV2POWHALF 23170 /* Q15, sqrt(2)/2 */ -#define EPSILLON_FX (Word16) 1 -#define MAX_SFM_LEN_FX 96 -#define MAX_P_ATT_FX (Word16) 40 /* Maximum number of pulses for gain attenuation factor */ -#define MAX_PHG_FX (Word16) 10 /* Q0, Maximum number of pulses for which to apply pulse height dependent gain */ -#define PHG_START_FX (Word16) 3277 /* Q15, 0.1f */ -#define PHG_DELTA_FX (Word16) 2621 /* Q15, ((PHG_END-PHG_START)/MAX_PHG) */ -#define ENV_ADJ_START_FX (Word16) 6 /* Q0, Number of consecutive bands for which the attenuation is maximum */ -#define ENV_ADJ_INV_INCL_FX (Word16) 6554 /* Q15, 1/5.0f, Inverse inclination for mapping between attenuation region width and attenuation limit */ - -#define INV_HVQ_THRES_BIN_24k 9362 /* 1/224 in Q21 */ -#define INV_HVQ_THRES_BIN_32k 6554 /* 1/320 in Q21 */ -#define INV_BANDS_PER_SUBFRAMES 14564 /* 1/9 in Q17 */ -#define NUM_SUBFRAMES 4 -#define BANDS_PER_SUBFRAMES 9 -#define ENERGY_TH_NUM_SUBFRAMES 1638400L /* 400 in Q12 */ -#define INV_SFM_N_ENV_STAB 19418 /* 1/27 in Q19 */ -#define ENERGY_TH_FX 819200L /* 100 in Q13 */ -#define ENERGY_LT_BETA_FX 30474 /* 0.93 in Q15 - Smoothing factor for long-term energy measure */ -#define ENERGY_LT_BETA_1_FX 2294 /* 0.07 i Q15 - (1 - ENERGY_LT_BETA_FX) */ -#define INV_DELTA_TH 13107 /* 1/5 in Q16 - Inverse Delta energy threshold for transient detection for envelope stability */ - -#define ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX ((Word16) 410) /* Q15, 1/80 = 0.0125 */ -#define ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX ((Word16) 345) /* Q15, 1/95 = 0.010526315 */ - -#define INV_PREECHO_SMOOTH_LENP1_FX 1560 /*(32768 / (PREECHO_SMOOTH_LEN + 1.0));*/ - -#define INV_HVQ_BW 1024 /* Q15 1/32 */ - -#define ACELP_48k_BITS 960 /* Q0 - ACELP_48k / 50 */ +#define INV2POWHALF 23170 /* Q15, sqrt(2)/2 */ +#define EPSILLON_FX (Word16) 1 +#define MAX_SFM_LEN_FX 96 +#define MAX_P_ATT_FX (Word16) 40 /* Maximum number of pulses for gain attenuation factor */ +#define MAX_PHG_FX (Word16) 10 /* Q0, Maximum number of pulses for which to apply pulse height dependent gain */ +#define PHG_START_FX (Word16) 3277 /* Q15, 0.1f */ +#define PHG_DELTA_FX (Word16) 2621 /* Q15, ((PHG_END-PHG_START)/MAX_PHG) */ +#define ENV_ADJ_START_FX (Word16) 6 /* Q0, Number of consecutive bands for which the attenuation is maximum */ +#define ENV_ADJ_INV_INCL_FX (Word16) 6554 /* Q15, 1/5.0f, Inverse inclination for mapping between attenuation region width and attenuation limit */ + +#define INV_HVQ_THRES_BIN_24k 9362 /* 1/224 in Q21 */ +#define INV_HVQ_THRES_BIN_32k 6554 /* 1/320 in Q21 */ +#define INV_BANDS_PER_SUBFRAMES 14564 /* 1/9 in Q17 */ +#define NUM_SUBFRAMES 4 +#define BANDS_PER_SUBFRAMES 9 +#define ENERGY_TH_NUM_SUBFRAMES 1638400L /* 400 in Q12 */ +#define INV_SFM_N_ENV_STAB 19418 /* 1/27 in Q19 */ +#define ENERGY_TH_FX 819200L /* 100 in Q13 */ +#define ENERGY_LT_BETA_FX 30474 /* 0.93 in Q15 - Smoothing factor for long-term energy measure */ +#define ENERGY_LT_BETA_1_FX 2294 /* 0.07 i Q15 - (1 - ENERGY_LT_BETA_FX) */ +#define INV_DELTA_TH 13107 /* 1/5 in Q16 - Inverse Delta energy threshold for transient detection for envelope stability */ + +#define ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX ((Word16) 410) /* Q15, 1/80 = 0.0125 */ +#define ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX ((Word16) 345) /* Q15, 1/95 = 0.010526315 */ + +#define INV_PREECHO_SMOOTH_LENP1_FX 1560 /*(32768 / (PREECHO_SMOOTH_LEN + 1.0));*/ + +#define INV_HVQ_BW 1024 /* Q15 1/32 */ + +#define ACELP_48k_BITS 960 /* Q0 - ACELP_48k / 50 */ /*----------------------------------------------------------------------------------* * ISF quantizer constants *----------------------------------------------------------------------------------*/ - /*qlpc_avq, lsf_msvq_ma*/ -#define W_MODE0 0x1333 /*60.0f/FREQ_DIV in 0Q15*/ -#define W_MODE1 0x14CD /*65.0f/FREQ_DIV in 0Q15*/ -#define W_MODE2 0x147B /*64.0f/FREQ_DIV in 0Q15*/ -#define W_MODE_ELSE 0x1429 /*60.0f/FREQ_DIV in 0Q15*/ -/* qmc_cng_common.h */ -/* codec side */ -#define SCALE_TABLE_SHIFT_FACTOR (31-23) - -/* parameter_bitmapping.h */ -#define NPARAMS_MAX 10 + +#define W_MODE0 0x1333 /*60.0f/FREQ_DIV in 0Q15*/ +#define W_MODE1 0x14CD /*65.0f/FREQ_DIV in 0Q15*/ +#define W_MODE2 0x147B /*64.0f/FREQ_DIV in 0Q15*/ +#define W_MODE_ELSE 0x1429 /*60.0f/FREQ_DIV in 0Q15*/ +#define SCALE_TABLE_SHIFT_FACTOR (31-23) + +#define NPARAMS_MAX 10 /* Flags for CLDFB intialization */ /* Flag indicating that the states should be kept. */ -#define CLDFB_FLAG_KEEP_STATES 8 +#define CLDFB_FLAG_KEEP_STATES 8 /* Flag indicating 2.5 ms setup */ -#define CLDFB_FLAG_2_5MS_SETUP 128 +#define CLDFB_FLAG_2_5MS_SETUP 128 + typedef enum SIGNAL_CLASSIFER_MODE { CLASSIFIER_ACELP, CLASSIFIER_TCX } SIGNAL_CLASSIFIER_MODE; -#define CNT0P1 1717986918 /* 0.1*2^34 */ -#define CNT0P001 1099511627 /* 0.001*2^40 */ -#define CNT0P0001 1759218604 /* 0.0001*2^44 */ +#define CNT0P1 1717986918 /* 0.1*2^34 */ +#define CNT0P001 1099511627 /* 0.001*2^40 */ +#define CNT0P0001 1759218604 /* 0.0001*2^44 */ -#define CNT0P05 1717986918 /* 0.05*2^35 */ +#define CNT0P05 1717986918 /* 0.05*2^35 */ -#define CNT1DIV28 1227133513 /* (1/28)*2^35 */ -#define CNT1DIV14 1227133513 /* (1/14)*2^34 */ -#define CNT1DIV8 1073741824 /* (1/8)*2^33 */ +#define CNT1DIV28 1227133513 /* (1/28)*2^35 */ +#define CNT1DIV14 1227133513 /* (1/14)*2^34 */ +#define CNT1DIV8 1073741824 /* (1/8)*2^33 */ + +#define SP_CENTER_Q 10 +#define ITD_STABLE_RATE_Q 15 +#define SPEC_AMP_Q 14 +#define SFM_Q 15 +#define TONA_Q 14 +#define lt_bg_highf_eng_Q 16 -#define SP_CENTER_Q 10 -#define ITD_STABLE_RATE_Q 15 -#define SPEC_AMP_Q 14 -#define SFM_Q 15 -#define TONA_Q 14 -#define lt_bg_highf_eng_Q 16 /*----------------------------------------------------------------------------------* * TEC/TFA *----------------------------------------------------------------------------------*/ -#define DELAY_TEMP_ENV_BUFF_TEC 9 -#define EXT_DELAY_HI_TEMP_ENV 2 - - - /************************************************************************/ - /* CLDFB */ - /************************************************************************/ -#define SCALE_MODULATION ( 1 ) - -#define SCALE_GAIN_ANA_10 ( 4 ) -#define SCALE_GAIN_ANA_16 ( 3 ) -#define SCALE_GAIN_ANA_20 ( 3 ) -#define SCALE_GAIN_ANA_32 ( 2 ) -#define SCALE_GAIN_ANA_30 ( 2 ) -#define SCALE_GAIN_ANA_40 ( 2 ) -#define SCALE_GAIN_ANA_60 ( 1 ) - -#define SCALE_GAIN_SYN (-6 ) - -#define SCALE_CLDFB_ANA_10 ( SCALE_MODULATION + SCALE_GAIN_ANA_10 ) -#define SCALE_CLDFB_ANA_16 ( SCALE_MODULATION + SCALE_GAIN_ANA_16 ) -#define SCALE_CLDFB_ANA_20 ( SCALE_MODULATION + SCALE_GAIN_ANA_20 ) -#define SCALE_CLDFB_ANA_32 ( SCALE_MODULATION + SCALE_GAIN_ANA_32 ) -#define SCALE_CLDFB_ANA_40 ( SCALE_MODULATION + SCALE_GAIN_ANA_40 ) -#define SCALE_CLDFB_ANA_60 ( SCALE_MODULATION + SCALE_GAIN_ANA_60 ) -#define SCALE_CLDFB_ANA_30 ( SCALE_MODULATION + SCALE_GAIN_ANA_30 ) - -#define SCALE_CLDFB_SYN_10 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_16 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_20 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_32 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_40 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_60 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_30 ( SCALE_MODULATION + SCALE_GAIN_SYN ) - -/************************************************************************/ -/* FFT */ -/************************************************************************/ -#define SCALEFACTORN2 ( 3) -#define SCALEFACTOR2 ( 2) -#define SCALEFACTOR3 ( 3) -#define SCALEFACTOR4 ( 3) -#define SCALEFACTOR5 ( 4) -#define SCALEFACTOR8 ( 4) -#define SCALEFACTOR10 ( 5) -#define SCALEFACTOR12 ( 5) -#define SCALEFACTOR15 ( 5) -#define SCALEFACTOR16_5 ( 5) -#define SCALEFACTOR20_5 ( 5) -#define SCALEFACTOR24 ( 6) -#define SCALEFACTOR30 ( 6) -#define SCALEFACTOR30_1 ( 5) -#define SCALEFACTOR30_2 ( 1) -#define SCALEFACTOR32 ( 6) -#define SCALEFACTOR32_1 ( 5) -#define SCALEFACTOR32_2 ( 1) -#define SCALEFACTOR40 ( 7) -#define SCALEFACTOR60 ( 7) -#define SCALEFACTOR64 ( 7) -#define SCALEFACTOR80 ( 8) -#define SCALEFACTOR100 (10) -#define SCALEFACTOR120 ( 8) -#define SCALEFACTOR128 ( 8) -#define SCALEFACTOR160 ( 8) -#define SCALEFACTOR192 (10) -#define SCALEFACTOR200 (10) -#define SCALEFACTOR240 ( 9) -#define SCALEFACTOR256 ( 9) -#define SCALEFACTOR320 (10) -#define SCALEFACTOR400 (10) -#define SCALEFACTOR480 (11) -#define SCALEFACTOR600 (10) - -#define BASOP_CFFT_MAX_LENGTH 600 +#define DELAY_TEMP_ENV_BUFF_TEC 9 +#define EXT_DELAY_HI_TEMP_ENV 2 + + +/*----------------------------------------------------------------------------------* + * CLDFB + *----------------------------------------------------------------------------------*/ + +#define SCALE_MODULATION ( 1 ) + +#define SCALE_GAIN_ANA_10 ( 4 ) +#define SCALE_GAIN_ANA_16 ( 3 ) +#define SCALE_GAIN_ANA_20 ( 3 ) +#define SCALE_GAIN_ANA_32 ( 2 ) +#define SCALE_GAIN_ANA_30 ( 2 ) +#define SCALE_GAIN_ANA_40 ( 2 ) +#define SCALE_GAIN_ANA_60 ( 1 ) + +#define SCALE_GAIN_SYN (-6 ) + +#define SCALE_CLDFB_ANA_10 ( SCALE_MODULATION + SCALE_GAIN_ANA_10 ) +#define SCALE_CLDFB_ANA_16 ( SCALE_MODULATION + SCALE_GAIN_ANA_16 ) +#define SCALE_CLDFB_ANA_20 ( SCALE_MODULATION + SCALE_GAIN_ANA_20 ) +#define SCALE_CLDFB_ANA_32 ( SCALE_MODULATION + SCALE_GAIN_ANA_32 ) +#define SCALE_CLDFB_ANA_40 ( SCALE_MODULATION + SCALE_GAIN_ANA_40 ) +#define SCALE_CLDFB_ANA_60 ( SCALE_MODULATION + SCALE_GAIN_ANA_60 ) +#define SCALE_CLDFB_ANA_30 ( SCALE_MODULATION + SCALE_GAIN_ANA_30 ) + +#define SCALE_CLDFB_SYN_10 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_16 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_20 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_32 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_40 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_60 ( SCALE_MODULATION + SCALE_GAIN_SYN ) +#define SCALE_CLDFB_SYN_30 ( SCALE_MODULATION + SCALE_GAIN_SYN ) + + +/*----------------------------------------------------------------------------------* + * FFT + *----------------------------------------------------------------------------------*/ + +#define SCALEFACTORN2 ( 3) +#define SCALEFACTOR2 ( 2) +#define SCALEFACTOR3 ( 3) +#define SCALEFACTOR4 ( 3) +#define SCALEFACTOR5 ( 4) +#define SCALEFACTOR8 ( 4) +#define SCALEFACTOR10 ( 5) +#define SCALEFACTOR12 ( 5) +#define SCALEFACTOR15 ( 5) +#define SCALEFACTOR16_5 ( 5) +#define SCALEFACTOR20_5 ( 5) +#define SCALEFACTOR24 ( 6) +#define SCALEFACTOR30 ( 6) +#define SCALEFACTOR30_1 ( 5) +#define SCALEFACTOR30_2 ( 1) +#define SCALEFACTOR32 ( 6) +#define SCALEFACTOR32_1 ( 5) +#define SCALEFACTOR32_2 ( 1) +#define SCALEFACTOR40 ( 7) +#define SCALEFACTOR60 ( 7) +#define SCALEFACTOR64 ( 7) +#define SCALEFACTOR80 ( 8) +#define SCALEFACTOR100 (10) +#define SCALEFACTOR120 ( 8) +#define SCALEFACTOR128 ( 8) +#define SCALEFACTOR160 ( 8) +#define SCALEFACTOR192 (10) +#define SCALEFACTOR200 (10) +#define SCALEFACTOR240 ( 9) +#define SCALEFACTOR256 ( 9) +#define SCALEFACTOR320 (10) +#define SCALEFACTOR400 (10) +#define SCALEFACTOR480 (11) +#define SCALEFACTOR600 (10) + +#define BASOP_CFFT_MAX_LENGTH 600 /*----------------------------------------------------------------------------------* * BASOP ROM Tables *----------------------------------------------------------------------------------*/ -#define LD_INT_TAB_LEN 120 -#define INV_TABLE_SIZE 256 -#define SQRT_TABLE_SIZE 256 +#define INV_TABLE_SIZE 256 +#define SQRT_TABLE_SIZE 256 /*----------------------------------------------------------------------------------* @@ -3048,67 +2714,36 @@ enum VOIP_RTPDUMP }; -//EVS macros -#define LT_UV_THR_FX (100*64) /* in Q6 */ -#define INV_MAX_LT_FX (Word16)((1.0f/MAX_LT)*32768) -#define EVS_PI 3.14159265358979323846264338327950288f -#define EVS_PI_FX 25736 /* pi in Q13 */ -#define EVS_2PI_FX 51472 /* 2 * pi in Q13 */ -#define EVS_PI_FX_Q27 421657428 /* pi in Q28 */ -#define EVS_2PI_FX_Q27 843314856 /* 2 * pi in Q28 */ -#define EVS_PI_BY_2_FX (Word16)(0x3244) // Q13 -//#define EVS_PI_FX (Word16)(0x6488) -#define EVS_PI_FX16 (Word16)(0x6488) -#define PI2_FX 1686629713 //Q28 +/*----------------------------------------------------------------------------------* + * EVS macros + *----------------------------------------------------------------------------------*/ -#define LG10 24660 /* 10*log10(2) in Q13 */ +#define LT_UV_THR_FX (100*64) /* in Q6 */ +#define INV_MAX_LT_FX (Word16)((1.0f/MAX_LT)*32768) +#define LG10 24660 /* 10*log10(2) in Q13 */ -#define EVS_LW_MIN (Word32)0x80000000 -#define EVS_LW_MAX (Word32)0x7fffffff +#define EVS_LW_MIN (Word32)0x80000000 +#define EVS_LW_MAX (Word32)0x7fffffff -#define EVS_SW_MAX (Word16)0x7fff /* largest Ram */ +#define EVS_SW_MAX (Word16)0x7fff /* largest Ram */ -#define SYNC_GOOD_FRAME (UWord16) 0x6B21 /* synchronization word of a "good" frame */ -#define SYNC_BAD_FRAME (UWord16) 0x6B20 /* synchronization word of a "bad" frame */ -#define G192_BIN0 (UWord16) 0x007F /* binary "0" according to ITU-T G.192 */ -#define G192_BIN1 (UWord16) 0x0081 /* binary "1" according to ITU-T G.192 */ -#define DEGREE_180 (Word32)(180.0 *ONE_IN_Q22) -#define DEGREE_360 (Word32)(360.0 *ONE_IN_Q22) extern const Word16 Idx2Freq_Tbl[]; - #define chk_fs(fs) /* 'x' is converted to Q6, 'Freq_Tbl'/1000 in Q9 */ /* only works for 'fs' = [8000,12800,16000,25600,32000,48000] (unpredictable otherwise) */ /* 15625 is 1000000.0f/Q6 but we use the calculated value to avoid float point code */ -#define NS2SA_FX2(fs,x) (chk_fs(fs) mult((&Idx2Freq_Tbl[-2])[L_and(L_shr(fs,8),7)], (Word16)((x)/15625))) - -#define L_FRAME_12k8 256 /* Frame size at 12k8Hz: 20ms = 256 samples */ -#define L_FRAME_16k 320 /* Frame size at 16kHz: 20ms = 320 samples */ -#define L_NEXT_MAX_12k8 112 /* maximum encoder lookahead at 12k8Hz */ -#define L_PAST_MAX_12k8 144 /* maximum encoder past samples at 12k8Hz */ -#define L_DIV 256 /* 20ms frame size (ACELP or short TCX frame) */ -#define L_DIV_MAX 320 - +#define NS2SA_FX2(fs,x) (chk_fs(fs) mult(Idx2Freq_Tbl[L_and(L_shr(fs,8),7)-2], (Word16)((x)/15625))) -//tbs_vase.c -#define PRED_GAIN_E 8 +#define L_FRAME_12k8 256 /* Frame size at 12k8Hz: 20ms = 256 samples */ +#define L_FRAME_16k 320 /* Frame size at 16kHz: 20ms = 320 samples */ +#define L_NEXT_MAX_12k8 112 /* maximum encoder lookahead at 12k8Hz */ +#define L_PAST_MAX_12k8 144 /* maximum encoder past samples at 12k8Hz */ +#define L_DIV 256 /* 20ms frame size (ACELP or short TCX frame) */ +#define L_DIV_MAX 320 -#define FS_48K_IN_NS_Q31 103079 -#define FS_32K_IN_NS_Q31 68719 -#define FS_16K_IN_NS_Q31 34360 +#define PRED_GAIN_E 8 -#define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ -#define ONE_BY_TEN_Q15 3277 /* 1/10.f in Q15 */ -#define THREE_Q21 6291456 -#define SIX_Q21 12582912 - -typedef enum -{ - MCT_CHAN_MODE_REGULAR, - MCT_CHAN_MODE_LFE, - MCT_CHAN_MODE_IGNORE -} MCT_CHAN_MODE; /* clang-format on */ #endif /* CNST_H */ diff --git a/lib_com/codec_tcx_common_fx.c b/lib_com/codec_tcx_common_fx.c index d7f30d90530f1c56374aa10938d729f3af82652f..8517668e5779027a75dcbb2329246cc0f5f8425e 100644 --- a/lib_com/codec_tcx_common_fx.c +++ b/lib_com/codec_tcx_common_fx.c @@ -4,7 +4,6 @@ #include #include -#include #include "options.h" #include "prot_fx.h" #include "basop_util.h" diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index d6190dffd1d56c33c87a4e3cb4afdc1049de3732..aac5939fce0fbd9da95f550c749ffe8ff5d6fb36 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -153,7 +153,6 @@ typedef struct } IVAS_QUATERNION; - typedef struct { float x, y, z; @@ -174,12 +173,12 @@ typedef enum typedef enum { - IVAS_RENDER_FRAMESIZE_UNKNOWN = 0, - IVAS_RENDER_FRAMESIZE_5MS = 1, - IVAS_RENDER_FRAMESIZE_10MS = 2, - IVAS_RENDER_FRAMESIZE_20MS = 4 + IVAS_RENDER_NUM_SUBFR_UNKNOWN = 0, + IVAS_RENDER_NUM_SUBFR_5MS = 1, + IVAS_RENDER_NUM_SUBFR_10MS = 2, + IVAS_RENDER_NUM_SUBFR_20MS = 4 -} IVAS_RENDER_FRAMESIZE; +} IVAS_RENDER_NUM_SUBFR; typedef enum { @@ -187,6 +186,7 @@ typedef enum IVAS_ROOM_SIZE_SMALL, IVAS_ROOM_SIZE_MEDIUM, IVAS_ROOM_SIZE_LARGE + } IVAS_ROOM_SIZE_T; typedef struct ivas_masa_metadata_frame_struct *IVAS_MASA_METADATA_HANDLE; @@ -197,6 +197,7 @@ typedef struct ivas_hrtf_crend_structure *IVAS_DEC_HRTF_CREND_HANDLE; typedef struct ivas_hrtf_fastconv_struct *IVAS_DEC_HRTF_FASTCONV_HANDLE; typedef struct ivas_hrtf_parambin_struct *IVAS_DEC_HRTF_PARAMBIN_HANDLE; typedef struct ivas_hrtf_statistics_struct *IVAS_DEC_HRTF_STATISTICS_HANDLE; + typedef struct ivas_cldfb_filter_bank_struct *IVAS_CLDFB_FILTER_BANK_HANDLE; typedef struct ivas_LS_setup_custom *IVAS_LSSETUP_CUSTOM_HANDLE; @@ -241,6 +242,7 @@ typedef enum _ivas_binaural_renderer_type } IVAS_BIN_RENDERER_TYPE; + /*----------------------------------------------------------------------------------* * Split rendering API constants, structures, and enums *----------------------------------------------------------------------------------*/ @@ -318,16 +320,6 @@ typedef struct _ISAR_SPLIT_REND_CONFIG * Renderer API structures and enums *----------------------------------------------------------------------------------*/ -#ifdef DEBUGGING -typedef enum -{ - IVAS_RENDER_TYPE_OVERRIDE_NONE, - IVAS_RENDER_TYPE_OVERRIDE_CREND, - IVAS_RENDER_TYPE_OVERRIDE_FASTCONV - -} IVAS_RENDER_TYPE_OVERRIDE; - -#endif typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG { UWord16 aeID; /* Acoustic environment ID */ @@ -376,4 +368,466 @@ typedef struct } IVAS_REND_AudioBuffer; + +/*----------------------------------------------------------------------------------* + * RTP API structures and enums + *----------------------------------------------------------------------------------*/ + +/* IVAS PI Data Types */ +typedef enum +{ + /* Forward direction PI types */ + IVAS_PI_SCENE_ORIENTATION, /* orientation of audio scene in unit quaternions */ + IVAS_PI_DEVICE_ORIENTATION_COMPENSATED, /* orientation of device in unit quaternions (compensated) */ + IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED, /* orientation of device in unit quaternions (un-compensated) */ + IVAS_PI_ACOUSTIC_ENVIRONMENT, /* describe the acoustic environment */ + IVAS_PI_AUDIO_DESCRIPTION, /* audio content description (voice/music/ambiance) */ + IVAS_PI_ISM_NUM, /* Number of objects */ + IVAS_PI_ISM_ID, /* id of each object */ + IVAS_PI_ISM_GAIN, /* gain of each object */ + IVAS_PI_ISM_ORIENTATION, /* orientation of each object */ + IVAS_PI_ISM_POSITION, /* position of each object */ + IVAS_PI_ISM_POSITION_COMPACT, /* position of each object in compact representation */ + IVAS_PI_ISM_DISTANCE_ATTENUATION, /* distance attenuation for each object */ + IVAS_PI_ISM_DIRECTIVITY, /* directivity of each object */ + IVAS_PI_DIEGETIC_TYPE, /* digetic audio indication */ + IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION, /* audio suppression indication */ + IVAS_PI_AUDIO_FOCUS_INDICATION, /* audio focus indication (direction in Quaternions and/or level) */ + + /* Reverse direction PI types */ + IVAS_PI_PLAYBACK_DEVICE_ORIENTATION, /* orientation of the playback device in quaternions */ + IVAS_PI_HEAD_ORIENTATION, /* head orientation of the listener in Quaternions */ + IVAS_PI_LISTENER_POSITION, /* position of the listener in 3D space */ + IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_REQUEST, /* receiver’s preference with respect to audio suppression */ + IVAS_PI_AUDIO_FOCUS_REQUEST, /* direction of interest for the listener in Quaternions and/or audio focus level */ + IVAS_PI_PI_LATENCY, /* round-trip latency for PI frames */ + IVAS_PI_R_ISM_ID, /* id of an object for editing */ + IVAS_PI_R_ISM_GAIN, /* editing request for gain factor for received object */ + IVAS_PI_R_ISM_ORIENTATION, /* editing request for orientation for received object */ + IVAS_PI_R_ISM_POSITION, /* editing request for position for received object */ + IVAS_PI_R_ISM_POSITION_COMPACT, /* editing request for position for received object in a compact representation*/ + IVAS_PI_R_ISM_DIRECTION, /* editing request for direction for received object */ + IVAS_PI_RESERVED27, /* reserved */ + IVAS_PI_RESERVED28, /* reserved */ + IVAS_PI_RESERVED29, /* reserved */ + IVAS_PI_RESERVED30, /* reserved */ + IVAS_PI_NO_DATA = 31, /* Indicates an empty PI data frame */ + IVAS_PI_MAX_ID /* Max number of PI data IDs supprted */ + +} IVAS_PI_TYPE; + +/* orientation data corresponding to any of the following pi data types :- + * - IVAS_PI_SCENE_ORIENTATION + * - IVAS_PI_DEVICE_ORIENTATION_COMPENSATED + * - IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED + * - IVAS_PI_PLAYBACK_DEVICE_ORIENTATION + * - IVAS_PI_HEAD_ORIENTATION + * - IVAS_PI_R_ISM_ORIENTATION + * + * piDataType is used to identify the correct pi data type contained here + */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_SCENE_ORIENTATION) */ + uint32_t piDataType; /* one of supported orientation data types */ + IVAS_QUATERNION orientation; /* orientation data expressed as quartenions */ + +} IVAS_PIDATA_ORIENTATION; + +/* Acoustic environment corresponding to IVAS_PI_ACOUSTIC_ENVIRONMENT + * + * acoustic environment ID + * late reverb parameters + * - RT60 – indicating the time that it takes for the reflections to reduce 60 dB in energy level, per frequency band + * - DSR – diffuse to source signal energy ratio, per frequency band + * - Pre-delay – delay at which the computation of DSR values was performed + * early reflections + * - 3D rectangular virtual room dimensions + * - Broadband energy absorption coefficient per wall surface + */ +typedef enum +{ + IVAS_PI_AE_LOW, /* center frequency 25 Hz */ + IVAS_PI_AE_MID, /* center frequency 250 Hz */ + IVAS_PI_AE_HIGH, /* center frequency 2.5 kHz */ + IVAS_PI_AE_NUM_BANDS /* number of ae bands */ + +} IVAS_PI_AE_BANDS; + +typedef enum +{ + IVAS_PI_AE_LOW_FREQ = 25, + IVAS_PI_AE_MID_FREQ = 250, + IVAS_PI_AE_HIGH_FREQ = 2500 + +} IVAS_PI_AE_BANDS_FREQ; + +typedef enum +{ + IVAS_PI_AE_FRONT, + IVAS_PI_AE_BACK, + IVAS_PI_AE_LEFT, + IVAS_PI_AE_RIGHT, + IVAS_PI_AE_CEILING, + IVAS_PI_AE_FLOOR, + IVAS_PI_AE_NUM_SURFACE + +} IVAS_PI_AE_SURFACE; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ACOUSTIC_ENV) */ + uint32_t piDataType; /* IVAS_PI_ACOUSTIC_ENVIRONMENT */ + bool availLateReverb; /* AE contains only late reverb parameters */ + bool availEarlyReflections; /* AE containing late reverb and simplified early reflections */ + uint8_t aeid; /* seven-bit acoustic environment identifier */ + + /* only valid if availLateReverb==true or availEarlyReflections==true */ + float rt60[IVAS_PI_AE_NUM_BANDS]; /* time for the reflections to reduce 60 dB per band in seconds */ + float dsr[IVAS_PI_AE_NUM_BANDS]; /* diffuse to source signal energy ratio per band in dB */ + Word32 rt60_fx[IVAS_PI_AE_NUM_BANDS]; /* Q26: time for the reflections to reduce 60 dB per band in seconds */ + Word32 dsr_fx[IVAS_PI_AE_NUM_BANDS]; /* Q30: diffuse to source signal energy ratio per band in dB */ + + /* only valid if availEarlyReflections==true */ + IVAS_VECTOR3 roomDimensions; /* room dimensions in meters length (x), width (y), height (z) */ + float absorbCoeffs[IVAS_PI_AE_NUM_SURFACE]; /* absorption coefficients for all surfaces */ + Word32 absorbCoeffs_fx[IVAS_PI_AE_NUM_SURFACE]; /* Q30: absorption coefficients for all surfaces */ + +} IVAS_PIDATA_ACOUSTIC_ENV; + +/* Audio Description corresponding to IVAS_PI_AUDIO_DESCRIPTION + * Describe the following audio decriptors per object/type :- + * - audio content type is speech/music/ambiance + * - if audio rendering is editable + * - if stereo audio is binaural + * + * number of valid entries decide on basis of audio format:- + * - Stereo/SBA/MASA = 1 entry + * - MultiChannel = 2 entries (1 for center channel + 1 for all other channels) + * - ISM = Number of Object entries ( 1 per object ) + * - OMASA/OSBA = 1 + Num Discrete Coded Objects + * + */ +typedef struct +{ + bool speech; /* audio has voice/speech */ + bool music; /* audio has music */ + bool ambiance; /* audio has background ambiance */ + bool editable; /* rendering audio metadata is editable */ + bool binaural; /* stereo stream is binaural */ + +} IVAS_AUDIO_ID; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_AUDIO_DESC) */ + uint32_t piDataType; /* IVAS_PI_AUDIO_DESCRIPTION */ + uint32_t nValidEntries; /* Number of valid audio IDs */ + IVAS_AUDIO_ID audioId[1 + IVAS_MAX_NUM_OBJECTS]; /* audio id as per format */ + +} IVAS_PIDATA_AUDIO_DESC; + +/* ISM specific PI data related to PI types : - + * + * - IVAS_PI_ISM_NUM + * - IVAS_PI_ISM_ID + * - IVAS_PI_ISM_GAIN + * - IVAS_PI_ISM_ORIENTATION + * - IVAS_PI_ISM_POSITION + * - IVAS_PI_ISM_DISTANCE_ATTENUATION + * - IVAS_PI_ISM_DIRECTIVITY + */ + +/* Number of ISMs */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_NUM) */ + uint32_t piDataType; /* IVAS_PI_ISM_NUM */ + uint32_t numObjects; /* Number of ISM */ +} IVAS_PIDATA_ISM_NUM; + +/* ISM ID */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_ID) */ + uint32_t piDataType; /* IVAS_PI_ISM_ID */ + uint16_t numObjects; /* number of objects */ + uint8_t id[IVAS_MAX_NUM_OBJECTS]; /* 8-bit ISM id of object */ + +} IVAS_PIDATA_ISM_ID; + +/* ISM gain */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_GAIN) */ + uint32_t piDataType; /* IVAS_PI_ISM_GAIN */ + uint16_t numObjects; /* number of objects */ + int8_t dB[IVAS_MAX_NUM_OBJECTS]; /* ISM gain in dB per object [-96, +3] */ + +} IVAS_PIDATA_ISM_GAIN; + +/* ISM orientation */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_ORIENTATION) */ + uint32_t piDataType; /* IVAS_PI_ISM_ORIENTATION */ + uint16_t numObjects; /* number of objects */ + IVAS_QUATERNION orientation[IVAS_MAX_NUM_OBJECTS]; /* Orientation of audio objects in ISM(s) */ + +} IVAS_PIDATA_ISM_ORIENTATION; + +/* ISM position */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_POSITION) */ + uint32_t piDataType; /* IVAS_PI_ISM_POSITION */ + uint16_t numObjects; /* number of objects */ + IVAS_VECTOR3 position[IVAS_MAX_NUM_OBJECTS]; /* Position of audio objects in ISM(s) */ +} IVAS_PIDATA_ISM_POSITION; + +/* ISM distance attenuation comprising of following gains per ISM + * - reference distance + * - maximum distance + * - roll-off factor + */ +typedef struct +{ + float ref_dist; /* reference distance in meters */ + float max_dist; /* maximum distance in meters */ + float roll; /* roll-off factor values */ + +} IVAS_DIST_ATTEN; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_ATTENUATION) */ + uint32_t piDataType; /* IVAS_PI_ISM_DISTANCE_ATTENUATION */ + uint16_t numObjects; /* number of objects */ + IVAS_DIST_ATTEN distAtten[IVAS_MAX_NUM_OBJECTS]; /* Distance attenuation of audio objects */ + +} IVAS_PIDATA_ISM_ATTENUATION; + +/* ISM Directivity comprising of following per ISM :- + * - inner cone angle determines the size of the main cone directed to the front of the object + * - outer cone angle determines the size of the outer (back) cone + * - outer attenuation gain determines the attenuation outside the outer cone + */ +typedef struct +{ + uint16_t innerConeAngle; /* inner cone angle in degrees (0 - 360) */ + uint16_t outerConeAngle; /* outer cone angle in degrees (0 - 360) */ + float outerAttenuationdB; /* attenuation outside the outer cone in dB */ + +} IVAS_ISM_DIRECTIVITY; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_DIRECTIVITY) */ + uint32_t piDataType; /* IVAS_PI_ISM_DIRECTIVITY */ + uint16_t numObjects; /* number of objects */ + IVAS_ISM_DIRECTIVITY directivity[IVAS_MAX_NUM_OBJECTS]; /* Directivity of audio objects */ + +} IVAS_PIDATA_ISM_DIRECTIVITY; + +/* Diegetic and non-diegetic indication flag as per audio format + * + * number of valid entries decided on basis of audio format:- + * - Stereo/SBA/MASA/MultiChannel = 1 entry + * - ISM = Number of Object entries ( 1 per object ) + * - OMASA/OSBA = 1 (last) + Num Discrete Coded Objects + */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_DIEGETIC) */ + uint32_t piDataType; /* IVAS_PI_DIEGETIC_TYPE */ + bool isDiegetic[1 + IVAS_MAX_NUM_OBJECTS]; /* diegetic indication as per audio format */ + +} IVAS_PIDATA_DIEGETIC; + +/* Audio focus direction indicates a direction of interest. + * The audio focus level indicates the amount of suppression applied to the + * directions other than the audio focus direction. + */ +typedef enum +{ + IVAS_FLVL_NO_AUDIO_FOCUS = 0, /* Apply no audio focus */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_1, /* Audio focus level 1 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_2, /* Audio focus level 2 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_3, /* Audio focus level 3 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_4, /* Audio focus level 4 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_5, /* Audio focus level 5 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_6, /* Audio focus level 6 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_7, /* Audio focus level 7 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_8, /* Audio focus level 8 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_9, /* Audio focus level 9 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_10, /* Audio focus level 10 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_11, /* Audio focus level 11 */ + IVAS_FLVL_FOCUS_LEVEL_LEVEL_12, /* Audio focus level 12 */ + IVAS_FLVL_MAX_AUDIO_FOCUS, /* Apply max audio focus */ + IVAS_FLVL_DEFAULT_AUDIO_FOCUS, /* Default audio focus */ + IVAS_FLVL_NO_PREFERENCE, /* No preference / No indication */ + +} IVAS_FLVL; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_AUDIO_FOCUS) */ + uint32_t piDataType; /* IVAS_PI_AUDIO_FOCUS_INDCATION or IVAS_PI_AUDIO_FOCUS_REQUEST */ + bool availDirection; /* audio focus contains direction */ + bool availLevel; /* audio focus contains level */ + IVAS_QUATERNION direction; /* direction data expressed as quarternions */ + IVAS_FLVL flvl; /* audio focus level */ + +} IVAS_PIDATA_AUDIO_FOCUS; + +/* Position data corresponding to any of the following pi data types :- + * - IVAS_PI_LISTENER_POSITION + * - IVAS_PI_R_ISM_POSITION + * + * piDataType is used to identify the correct pi data type contained here + */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_POSITION) */ + uint32_t piDataType; /* one of supported position data types */ + IVAS_VECTOR3 position; /* Position data */ +} IVAS_PIDATA_POSITION; + +/* Dynamic Audio Suppression describes receiver’s preference with respect to the + * type of audio content that should be enhanced and the amount of suppression to + * be applied to the background noise + */ +typedef enum +{ + IVAS_SLI_MIN_SUPPRESSION = 0, /* Apply min suppression */ + IVAS_SLI_SUPPRESSION_LEVEL_1, /* Suppression level 1 */ + IVAS_SLI_SUPPRESSION_LEVEL_2, /* Suppression level 2 */ + IVAS_SLI_SUPPRESSION_LEVEL_3, /* Suppression level 3 */ + IVAS_SLI_SUPPRESSION_LEVEL_4, /* Suppression level 4 */ + IVAS_SLI_SUPPRESSION_LEVEL_5, /* Suppression level 5 */ + IVAS_SLI_SUPPRESSION_LEVEL_6, /* Suppression level 6 */ + IVAS_SLI_SUPPRESSION_LEVEL_7, /* Suppression level 7 */ + IVAS_SLI_SUPPRESSION_LEVEL_8, /* Suppression level 8 */ + IVAS_SLI_SUPPRESSION_LEVEL_9, /* Suppression level 9 */ + IVAS_SLI_SUPPRESSION_LEVEL_10, /* Suppression level 10 */ + IVAS_SLI_SUPPRESSION_LEVEL_11, /* Suppression level 11 */ + IVAS_SLI_MAX_SUPPRESSION, /* Apply max suppression */ + IVAS_SLI_NO_SUPPRESSION, /* Apply no suppression */ + IVAS_SLI_DEFAULT_SUPPRESSION, /* Apply default suppression */ + IVAS_SLI_NO_PREFERENCE, /* No preference / No indication */ + +} IVAS_SLI; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_DYNAMIC_SUPPRESSION) */ + uint32_t piDataType; /* IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_REQUEST or IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION */ + bool speech; /* receiver's preference is voice/speech */ + bool music; /* receiver's preference is music */ + bool ambiance; /* receiver's preference is background ambiance */ + IVAS_SLI sli; /* suppression level indicator [0, 15] */ + +} IVAS_PIDATA_DYNAMIC_SUPPRESSION; + +/* Reverse PI latency calculated as the elapsed time between the sent reverse PI data + * and received forward PI data. It is based on the receiving device experiencing the + * result of its sent data by receiving the corresponding data in forward direction as + * forward PI data + */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_REVERSE_PI_LATENCY) */ + uint32_t piDataType; /* IVAS_PI_PI_LATENCY */ + IVAS_PI_TYPE type; /* Reverse PI used for computation of Latency */ + int32_t latency; /* Latency as 27-bit int on RTP Clock @ 16KHz */ + +} IVAS_PIDATA_REVERSE_PI_LATENCY; + +/* ISM specific PI data editing requests */ + +/* ISM ID in editing requests */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_ID) */ + uint32_t piDataType; /* IVAS_PI_R_ISM_ID */ + uint8_t id; /* 8-bit ISM id of object to edit */ + +} IVAS_PIDATA_ISM_EDIT_ID; + +/* Editing request for ISM gain */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_GAIN) */ + uint32_t piDataType; /* IVAS_PI_R_ISM_GAIN */ + int8_t dB; /* Preferred ISM gain in dB [-96, +3] */ + +} IVAS_PIDATA_ISM_EDIT_GAIN; + +/* Editing request for ISM orientation */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_ORIENTATION) */ + uint32_t piDataType; /* IVAS_PI_R_ISM_ORIENTATION */ + IVAS_QUATERNION orientation; /* orientation editing request for received ISM */ + +} IVAS_PIDATA_ISM_EDIT_ORIENTATION; + +/* Editing request for ISM direction */ +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_DIRECTION) */ + uint32_t piDataType; /* IVAS_PI_R_ISM_DIRECTION */ + float azimuth; /* azimuth angle in degrees [-180, 180] */ + float elevation; /* elevation angle in degrees [-90°, 90°] */ + +} IVAS_PIDATA_ISM_EDIT_DIRECTION; + +typedef struct +{ + size_t size; /* sizeof(IVAS_PIDATA_NO_DATA) */ + uint32_t piDataType; /* IVAS_PI_NO_DATA */ + +} IVAS_PIDATA_NO_DATA; + +typedef union +{ + IVAS_PIDATA_ORIENTATION scene; + IVAS_PIDATA_ORIENTATION deviceCompensated; + IVAS_PIDATA_ORIENTATION deviceUnCompensated; + IVAS_PIDATA_ACOUSTIC_ENV acousticEnv; + IVAS_PIDATA_AUDIO_DESC audioDesc; + IVAS_PIDATA_ISM_NUM ismNum; + IVAS_PIDATA_ISM_ID ismId; + IVAS_PIDATA_ISM_GAIN ismGain; + IVAS_PIDATA_ISM_ORIENTATION ismOrientation; + IVAS_PIDATA_ISM_POSITION ismPosition; + IVAS_PIDATA_ISM_POSITION ismPositionCompact; + IVAS_PIDATA_ISM_ATTENUATION ismAttenuation; + IVAS_PIDATA_ISM_DIRECTIVITY ismDirectivity; + IVAS_PIDATA_DIEGETIC digeticIndicator; + IVAS_PIDATA_DYNAMIC_SUPPRESSION dynSuppressionIndication; + IVAS_PIDATA_AUDIO_FOCUS focusIndication; + IVAS_PIDATA_ORIENTATION playbackOrientation; + IVAS_PIDATA_ORIENTATION headOrientation; + IVAS_PIDATA_POSITION listnerPosition; + IVAS_PIDATA_DYNAMIC_SUPPRESSION dynSuppressionRequest; + IVAS_PIDATA_AUDIO_FOCUS focusRequest; + IVAS_PIDATA_REVERSE_PI_LATENCY piLatency; + IVAS_PIDATA_ISM_EDIT_ID ismEditId; + IVAS_PIDATA_ISM_EDIT_GAIN ismEditGain; + IVAS_PIDATA_ISM_EDIT_ORIENTATION ismEditOrientation; + IVAS_PIDATA_POSITION ismEditPosition; + IVAS_PIDATA_POSITION ismEditPositionCompact; + IVAS_PIDATA_ISM_EDIT_DIRECTION ismEditDirection; + IVAS_PIDATA_NO_DATA noPiData; + +} IVAS_PIDATA; + +typedef struct +{ + IVAS_PIDATA data; + uint32_t timestamp; + +} IVAS_PIDATA_TS; + #endif /* COMMON_API_TYPES_H */ diff --git a/lib_com/core_com_config_fx.c b/lib_com/core_com_config_fx.c index 90fc306b700bd445d4b24666223dab9c1c9015ec..cb9723487826c1f5d416afa83084bec6400607b9 100644 --- a/lib_com/core_com_config_fx.c +++ b/lib_com/core_com_config_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -997,8 +997,11 @@ void init_tcx_cfg_ivas_fx( IF( hTcxCfg->fIsTNSAllowed ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); +#else InitTnsConfigs_ivas_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); - +#endif SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) ); } @@ -1253,7 +1256,11 @@ void init_tcx_cfg_fx( IF( hTcxCfg->fIsTNSAllowed ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); +#else InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); +#endif SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) ); } diff --git a/lib_com/deemph_fx.c b/lib_com/deemph_fx.c index 8442897c574169fd2c7b38b565f53d394d54f4c6..e141f9a67e599fdce79f29ffa220862d1f0d3ee5 100644 --- a/lib_com/deemph_fx.c +++ b/lib_com/deemph_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/delay_comp_fx.c b/lib_com/delay_comp_fx.c index fd5330aed8f08c9a7103bb5b0e967f11135e4ced..6d82271baa656411bcb691b87776fda3c3713bbc 100644 --- a/lib_com/delay_comp_fx.c +++ b/lib_com/delay_comp_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/disclaimer.c b/lib_com/disclaimer.c index ce456fb496f45c0cebb1127e13bad31a0295099e..00bc46b473f777e125d375333149e95487886326 100644 --- a/lib_com/disclaimer.c +++ b/lib_com/disclaimer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/enr_1_az_fx.c b/lib_com/enr_1_az_fx.c index bb2f9ea1904d264d3b2d2800300fc16f3cf760c8..108e25c3a87fdbf149ab19f5a8d46ac8c3bc8d93 100644 --- a/lib_com/enr_1_az_fx.c +++ b/lib_com/enr_1_az_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/env_adj_fx.c b/lib_com/env_adj_fx.c index 0926ee07171bc950bcb4e0795d240ec7f57c0969..0cf2906d544eb1211ad248a29e67e3e24b8b9700 100644 --- a/lib_com/env_adj_fx.c +++ b/lib_com/env_adj_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/env_stab_fx.c b/lib_com/env_stab_fx.c index 29908b1261bc42d298c05f01cc1f629d9a468c43..33c3435dbea4a0ee8af2e8a158b79814c348581a 100644 --- a/lib_com/env_stab_fx.c +++ b/lib_com/env_stab_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,7 +37,6 @@ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" diff --git a/lib_com/env_stab_trans_fx.c b/lib_com/env_stab_trans_fx.c index 5cdc93ff74d5349d83030601ddf8ef77c2ec4d19..63b35b0d56cde4d412c91bf3d70aeb6bfde56c97 100644 --- a/lib_com/env_stab_trans_fx.c +++ b/lib_com/env_stab_trans_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,11 +36,11 @@ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" #include "wmc_auto.h" + /*--------------------------------------------------------------------------* * env_stab_transient_detect() * diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 4ad2a85a190be22cc7d6ecf511fe6334f9bd7341..95e527da0e813e09f3196ef785d0bd7a47095a0a 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -29,99 +29,20 @@ /* INPUT OUTPUT ARGUMENTS */ /*-----------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) tolt_code : tilt of the code Q15 */ -/*=======================================================================*/ -Word16 est_tilt_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -) -{ - Word16 i, tmp, exp, ener1, exp1, ener2, exp2; - Word32 L_tmp; - Word16 tilt_code; - - ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) ); - exp1 = sub( exp1, add( Q_exc, Q_exc ) ); - L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - ener1 = mult( ener1, tmp ); - exp1 = sub( sub( exp1, exp ), 10 ); /* 10 -> gain_pit Q14 to Q9 */ - - ener2 = extract_h( Dot_product12( code, code, L_SUBFR, &exp2 ) ); - - exp = norm_l( gain_code ); - tmp = extract_h( L_shl( gain_code, exp ) ); - tmp = mult( tmp, tmp ); /* energy of innovative code excitation */ - ener2 = mult( ener2, tmp ); - exp2 = sub( exp2, add( exp, exp ) ); - - i = sub( exp1, exp2 ); - BASOP_SATURATE_WARNING_OFF_EVS - ener1 = shr_sat( ener1, sub( 1, s_min( i, 0 ) ) ); - ener2 = shr_sat( ener2, add( s_max( 0, i ), 1 ) ); - BASOP_SATURATE_WARNING_ON_EVS - tmp = sub( ener1, ener2 ); - ener1 = add( add( ener1, ener2 ), 1 ); - - /* find voice factor (1=voiced, -1=unvoiced) */ - exp = div_s( abs_s( tmp ), ener1 ); - if ( tmp < 0 ) - { - exp = negate( exp ); - } - *voice_fac = exp; - move16(); - - /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ - - /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ - - return tilt_code; -} - -/*======================================================================*/ -/* FUNCTION : est_tilt_ivas_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Estimate spectral tilt based on the relative E of adaptive */ -/* and innovative excitations */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) exc : adaptive excitation vector Q0 */ -/* _ (Word16) gain_pit : adaptive gain Q14 */ -/* _ (Word16 *) code : algebraic exctitation vector Q12 */ -/* _ (Word32) gain_code : algebraic code gain Q16 */ -/* _ (Word16) Q_exc : Scaling factor of excitation Q0 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) voice_fac : voicing factor Q15 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ /* o : tilt of the code Q15 */ -Word16 est_tilt_ivas_fx( +Word16 est_tilt_fx( const Word16 *exc, /* i : adaptive excitation vector Qx */ const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ + const Word16 *code, /* i : algebraic excitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ - const Word16 L_subfr, /* i : Sub frame length */ - const Word16 flag_tilt /* i : flag for special tilt */ + const Word16 L_subfr /* i : Sub frame length */ ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; @@ -161,25 +82,7 @@ Word16 est_tilt_ivas_fx( *voice_fac = exp; move16(); - IF( flag_tilt == 0 ) - { - /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ - - /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ - } - ELSE IF( EQ_16( flag_tilt, 1 ) ) - { - /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ - // tilt_code = (float)(0.25f + (*voice_fac + 1.0f) * 0.125f); - tilt_code = mac_r( 12288L /*0.375.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */ - } - ELSE - { - /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ - // tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f); - tilt_code = mac_r( 13763L /*0.42.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4588 /*0.14.Q15*/ ); /*Q15 */ - } + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ return tilt_code; } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 1a85899d30a2d907a195fc137833e71bed7a4e10..ac6d781a4d7ad3ff08299fa2b1a036ff480086fc 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -58,7 +58,9 @@ ivas_error createFdCngCom_fx( * *-------------------------------------------------------------------*/ -void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) +void initFdCngCom( + HANDLE_FD_CNG_COM hFdCngCom, + Word16 scale ) { /* Calculate CLDFB scaling factor */ /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ @@ -172,112 +174,6 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) return; } - -void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) -{ - /* Calculate CLDFB scaling factor */ - /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ - /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ - assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); - /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ - hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 ); - move16(); - /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ - hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor ); - move16(); - - /* Initialize the overlap-add */ - set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); - hFdCngCom->olapBufferAna = NULL; - set16_fx( hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); - - set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN ); - hFdCngCom->olapBufferSynth2 = NULL; - - /* Initialize the comfort noise generation */ - set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); - set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN ); - set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1 ); - - /* Initialize quantizer */ - set32_fx( hFdCngCom->sidNoiseEst, 0, NPART ); - set16_fx( &hFdCngCom->sidNoiseEstExp, 0, 1 ); - set16_fx( hFdCngCom->A_cng, 0, M + 1 ); - hFdCngCom->A_cng[0] = 4096 /*1.f Q12*/; /* 3Q12 */ - move16(); - - /* Set some counters and flags */ - hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ - move16(); - hFdCngCom->active_frame_counter = 0; - move16(); - hFdCngCom->frame_type_previous = ACTIVE_FRAME; - move16(); - hFdCngCom->flag_noisy_speech = 0; - move16(); - hFdCngCom->likelihood_noisy_speech = 0; - move16(); - hFdCngCom->numCoreBands = 0; - move16(); - hFdCngCom->stopBand = 0; - move16(); - hFdCngCom->startBand = 0; - move16(); - hFdCngCom->stopFFTbin = 0; - move16(); - hFdCngCom->frameSize = 0; - move16(); - hFdCngCom->fftlen = 0; - move16(); - hFdCngCom->seed = 0; - move16(); - // hFdCngCom->seed2 = 1; - // move16(); - // hFdCngCom->seed3 = 2; - // move16(); - hFdCngCom->CngBitrate = -1; - move16(); - - /* Initialize noise estimation algorithm */ - set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); - mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) ); - mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) ); - set32_fx( hFdCngCom->msPeriodogSum, 0, 2 ); - hFdCngCom->msPeriodogSum_exp[0] = 0; - move16(); - hFdCngCom->msPeriodogSum_exp[1] = 0; - move16(); - set32_fx( hFdCngCom->msPsdSum, 0, 2 ); - set16_fx( hFdCngCom->msSlope, 0, 2 ); - set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); - hFdCngCom->msQeqInvAv_exp[0] = 0; - move16(); - hFdCngCom->msQeqInvAv_exp[1] = 0; - move16(); - hFdCngCom->msFrCnt_init_counter = 0; - move16(); - hFdCngCom->msFrCnt_init_thresh = 1; - move16(); - hFdCngCom->init_old = 0; - move16(); - hFdCngCom->offsetflag = 0; - move16(); - hFdCngCom->msFrCnt = MSSUBFRLEN; - move16(); - hFdCngCom->msMinBufferPtr = 0; - move16(); - hFdCngCom->msAlphaCor[0] = 644245120l /*0.3f Q31*/; - move16(); - hFdCngCom->msAlphaCor[1] = 644245120l /*0.3f Q31*/; - move16(); - set16_fx( hFdCngCom->psize, 0, NPART ); - /* Initialize exponents */ - hFdCngCom->exp_cldfb_periodog = 0; - move16(); - - return; -} - /*------------------------------------------------------------------- * deleteFdCngCom() * diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c index 230dd7ac59f6cff002e6b472a4aab281f04083f8..0be5e21942545a7cfa66763f400cdb289d20e4de 100644 --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 461e1c7b62b2d1d9a5dde466bab12a301a6b86ab..651820c6a9342b61eb646933afe889e8e51717a4 100644 --- a/lib_com/fft_fx.c +++ b/lib_com/fft_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,7 +37,6 @@ #include #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" diff --git a/lib_com/fill_spectrum_fx.c b/lib_com/fill_spectrum_fx.c index 6bf0af3035ae5e95d4fbe7dc67be8d6b5d30236e..e41eca0af2046898dae1c160b152c3d5e6850b3f 100644 --- a/lib_com/fill_spectrum_fx.c +++ b/lib_com/fill_spectrum_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/findpulse_fx.c b/lib_com/findpulse_fx.c index f30990c1eca577968540dfd1edb3cd7d7fcbae6e..e95daaa698e655b54c9bbe633fc79ddd16b61a8a 100644 --- a/lib_com/findpulse_fx.c +++ b/lib_com/findpulse_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include #include "options.h" -#include #include "prot_fx.h" #include "cnst.h" #include "wmc_auto.h" diff --git a/lib_com/frame_ener_fx.c b/lib_com/frame_ener_fx.c index d63d7e79f9c285aefd267278798ce2d0d1c6cf5f..6e7a6f2a2b199b7990edbe53bc6196368e0f63bf 100644 --- a/lib_com/frame_ener_fx.c +++ b/lib_com/frame_ener_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "wmc_auto.h" diff --git a/lib_com/get_gain_fx.c b/lib_com/get_gain_fx.c index 7db540b1902e9f52e37b0ab86aab7da18db861ea..7cf27be0b28700db5352e49015143c173bad6da4 100644 --- a/lib_com/get_gain_fx.c +++ b/lib_com/get_gain_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 8e29f34bdcf70cef927ad0cc76e2aad4fd2f8452..3f4edb7ff2223823998130b64c1e5889d6aa6b72 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ ====================================================================================*/ #include -#include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ @@ -44,13 +43,14 @@ #include "wmc_auto.h" /*-------------------------------------------------------------------* - * Local constants + * Local function prototypes *-------------------------------------------------------------------*/ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const Word16 *dic_fx, const Word16 index_fx, const Word16 vec_en_fx ); + /*========================================================================*/ -/* FUNCTION : void Comp_and_apply_gain_enc_fx */ +/* FUNCTION : void Comp_and_apply_gain_fx */ /*------------------------------------------------------------------------*/ /* PURPOSE : Compute and apply the quantized per band gain */ /*------------------------------------------------------------------------*/ @@ -70,12 +70,19 @@ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const /* _ None */ /*========================================================================*/ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX +Word16 Comp_and_apply_gain_fx( +#else void Comp_and_apply_gain_fx( +#endif Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + const Word16 Flag_adj_q_exc, /* i : Flag allowing Q_exc adjustment */ +#endif Word16 Qexc_diff, Word16 Q_exc ) { @@ -83,6 +90,11 @@ void Comp_and_apply_gain_fx( Word16 StartBin, NB_Qbins; Word16 y_gain; Word16 L16, frac, exp1, tmp_exp; +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + Word16 Q_adapt; + Word16 Q_exc_diffQ[L_FRAME16k]; + Word32 exc_diffQ32[L_FRAME16k]; +#endif Word32 L32; /* Recreate excitation for local synthesis and decoder */ @@ -92,6 +104,7 @@ void Comp_and_apply_gain_fx( move16(); tmp_exp = add( 14, sub( Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/ + FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { StartBin = add( StartBin, NB_Qbins ); @@ -115,6 +128,7 @@ void Comp_and_apply_gain_fx( * y_gain = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) *-----------------------------------------------------------------*/ + L16 = sub( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */ L32 = L_mult( L16, 27213 ); /* 3.321928 in Q13 -> Q26 */ L32 = L_shr( L32, 10 ); /* From Q26 to Q16 */ @@ -125,25 +139,65 @@ void Comp_and_apply_gain_fx( Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) ); - - FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + IF( Flag_adj_q_exc != 0 ) { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ - exc_diffQ[i] = round_fx_sat( L_shl_sat( L32, tmp_exp ) ); /*Q_exc */ - move16(); + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) + { + exc_diffQ32[i] = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ + move32(); + Q_exc_diffQ[i] = Q_exc; + if ( exc_diffQ[i] ) + { + Q_exc_diffQ[i] = sub( Q_exc_diffQ[i], tmp_exp ); + move16(); + } + } + } + ELSE +#endif + { + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) + { + L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ + exc_diffQ[i] = round_fx_sat( L_shl_sat( L32, tmp_exp ) ); /*Q_exc */ + move16(); + } } } } - +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + Q_adapt = Q_exc; + move16(); + test(); + IF( EQ_16( ReUseGain, 0 ) && Flag_adj_q_exc != 0 ) + { + Word16 total_bins = add( StartBin, NB_Qbins ); + move16(); + FOR( i = 0; i < total_bins; i++ ) + { + Q_adapt = s_min( Q_adapt, add( Q_exc_diffQ[i], norm_l( exc_diffQ32[i] ) ) ); + move16(); + } + FOR( i = 0; i < total_bins; i++ ) + { + exc_diffQ[i] = round_fx( L_shl( exc_diffQ32[i], sub( Q_adapt, Q_exc_diffQ[i] ) ) ); /*Q_exc*/ + } + } + return Q_adapt; +#else return; +#endif } +#ifndef FIX_2338_HARM_GSC_GAIN_COMP + void Comp_and_apply_gain_ivas_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ + Word16 exc_diffQ[], /* i/o: Quantized excitation */ + Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ Word16 Qexc_diff, Word16 *Q_exc ) { @@ -193,6 +247,7 @@ void Comp_and_apply_gain_ivas_fx( * y_gain = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) *-----------------------------------------------------------------*/ + L16 = sub_sat( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */ L32 = L_mult( L16, 27213 ); /* 3.321928 in Q13 -> Q26 */ L32 = L_shr( L32, 10 ); /* From Q26 to Q16 */ @@ -235,6 +290,7 @@ void Comp_and_apply_gain_ivas_fx( return; } +#endif /*========================================================================*/ @@ -255,36 +311,44 @@ void Comp_and_apply_gain_ivas_fx( /* _ (Word32*) etmp14 : Energy band 14 Q_exc_diff*2+1 */ /* _ (Word32*) etmp15 : Energy band 15 Q_exc_diff*2+1 */ /*------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*========================================================================*/ -static Word16 Comp_band_log_ener( /* o : Band gain Q12 */ - const Word16 *pt_fx, /* i : Dct input Q_sc */ - const Word16 Len, /* i : Lenght en energy accumulation */ - const Word16 Q_sc, /* i : scaling of input */ - const Word16 E_sc /* i : Additional scaling factor for energy */ +/* o : Band gain Q12 */ +static Word16 Comp_band_log_ener( + const Word16 *pt_fx, /* i : Dct input Q_sc */ + const Word16 Len, /* i : Lenght en energy accumulation */ + const Word16 Q_sc, /* i : scaling of input */ + const Word16 E_sc /* i : Additional scaling factor for energy */ ) { Word32 L_tmp; Word16 e_tmp, f_tmp, tmp16, ener_exp; + L_tmp = Calc_Energy_Autoscaled( pt_fx, Q_sc, Len, &ener_exp ); e_tmp = norm_l( L_tmp ); f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); e_tmp = sub( sub( add( 30, E_sc ), e_tmp ), ener_exp ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 19728 ); /* Q16 */ /*log10(2) in Q17 */ tmp16 = round_fx( L_shl( L_tmp, 12 - 2 ) ); /* Q12 -1 is to compensate Q17 */ + return tmp16; } + void Ener_per_band_comp_fx( const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ const Word16 Q_exc, /* i : frame length */ const Word16 Mband, /* i : Max band */ - const Word16 Eflag /* i : flag of highest band */ +#ifdef FIX_1904_HARM_GSC_ENC + const Word16 Eflag, /* i : flag of highest band */ + const Word16 L_frame /* i : frame length */ +#else + const Word16 Eflag /* i : flag of highest band */ +#endif ) { const Word16 *pt_fx; @@ -312,9 +376,19 @@ void Ener_per_band_comp_fx( pt_fx += 32; } +#ifdef FIX_1904_HARM_GSC_ENC + IF( EQ_16( L_frame, L_FRAME16k ) ) + { + y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ + move16(); + y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/ + move16(); + } +#endif + return; } - +#ifndef FIX_1904_HARM_GSC_ENC void Ener_per_band_comp_ivas_fx( const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */ @@ -360,16 +434,18 @@ void Ener_per_band_comp_ivas_fx( return; } +#endif /*-------------------------------------------------------------------* - * gsc_gainQ() + * GSC_gain_adj() + * * - * Quantization of the energy per band *-------------------------------------------------------------------*/ static void GSC_gain_adj( const Word16 coder_type, /* i : Coder type */ + const Word16 Mbands_gn, /* i : Number of band */ const Word32 core_brate, /* i : Bit rate */ const Word16 mean_g, /* i : Average gain Q12 */ Word16 *old_y_gain, /* i/o: Previous frame dequantized vector */ @@ -379,10 +455,15 @@ static void GSC_gain_adj( { /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ Word16 Gain_off, i; + Word16 Fac_div; + + Fac_div = 102; + move16(); - IF( coder_type != INACTIVE ) + test(); + IF( coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) ) { - FOR( i = 0; i < MBANDS_GN; i++ ) + FOR( i = 0; i < Mbands_gn; i++ ) { old_y_gain[i] = y_gain_tmp[i]; move16(); @@ -392,9 +473,18 @@ static void GSC_gain_adj( } ELSE { - Gain_off = 0; + Gain_off = 0; /* For higher bitrate, thus for L_frame == L_FRAME16k as well */ move16(); - IF( LE_32( core_brate, ACELP_7k20 ) ) + + test(); + IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) /* IVAS LR mode only */ + { + Gain_off = 18432; + move16(); /* 9 -> Q11 */ + Fac_div = 205; /* Q15 -> Q16 to compensate for Gain_off being Q11 instead of Q12 */ + move16(); + } + ELSE IF( LE_32( core_brate, ACELP_7k20 ) ) { Gain_off = 32767; move16(); /* 8 -> Q12 */ @@ -421,12 +511,16 @@ static void GSC_gain_adj( } /*mimic ACELP decay of energy for low rates*/ +#ifndef FIX_2406_FIX_GAIN_ON_INACTIVE FOR( i = 0; i < MBANDS_GN; i++ ) +#else + FOR( i = 0; i < Mbands_gn; i++ ) +#endif { old_y_gain[i] = y_gain_tmp[i]; move16(); /*y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn));*/ - y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 102 /* 20/MBANDS_GN in Q15 */ ) ) ) ); + y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, Fac_div /* 20/MBANDS_GN in Q15 */ ) ) ) ); move16(); } } @@ -435,795 +529,174 @@ static void GSC_gain_adj( } -/*-------------------------------------------------------------------* - * GSC_gain_adj_ivas_fx() - * - * Quantization of the energy per band - *-------------------------------------------------------------------*/ +/*==========================================================================*/ +/* FUNCTION : Word16 gsc_gaindec_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Generic signal frequency band decoding and application */ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16) pvq_bits_fx : core used Q0 */ +/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) core_fx : core used Q0 */ +/* _ (Word16) bwidth_fx : input signal bandwidth Q0 */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) y_gainQ_fx : quantized gain per band */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) old_y_gain_fx : AR gain quantizer for low rate */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ (Word16) : average frequency gain */ +/*==========================================================================*/ -static void GSC_gain_adj_ivas_fx( - const Word16 coder_type, /* i : Coder type */ - const Word16 Mbands_gn, /* i : Number of band */ - const Word32 core_brate, /* i : Bit rate */ - const Word16 mean_g, /* i : Average gain Q12 */ - Word16 *old_y_gain, /* i/o: Previous frame dequantized vector */ - const Word16 *y_gain_tmp, /* i : Dequantized gains */ - Word16 *y_gainQ /* i/o: Output gains Q12 */ +/*! r: average frequency gain */ +Word16 gsc_gaindec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 y_gainQ_fx[], /* o : quantized gain per band Q12 */ + const Word32 core_brate_fx, /* i : core used */ + Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth_fx /* i : input signal bandwidth */ ) { - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - Word16 Gain_off, i; + Word16 idx_g_fx, i; + Word16 mean_4g_fx; + Word16 Mbands_gn = MBANDS_GN; + move16(); + Word16 y_gain_tmp3_fx[MBANDS_GN]; - test(); - IF( ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - FOR( i = 0; i < Mbands_gn; i++ ) - { - old_y_gain[i] = y_gain_tmp[i]; - move16(); - y_gainQ[i] = add( y_gain_tmp[i], mean_g ); - move16(); - } + Mbands_gn = MBANDS_GN16k; + move16(); } - ELSE + + test(); + test(); + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { - Gain_off = 0; - move16(); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - test(); - IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) - { - Gain_off = 18432; - move16(); /* 9 -> Q11 */ - } - IF( LE_32( core_brate, ACELP_7k20 ) ) - { - Gain_off = 16384; - move16(); /* 8 -> Q11 */ - } - ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) - { - Gain_off = 13517; - move16(); /* 6.6f -> Q11 */ - } - ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) - { - Gain_off = 9830; - move16(); /*4.8f-> Q11 */ - } - ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); + + IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { - Gain_off = 7168; - move16(); /* 3.5f -> Q11 */ + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); + + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); + VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); } - ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) + ELSE { - Gain_off = 6144; - move16(); /* 3.0f -> Q11 dB */ - } + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - /*mimic ACELP decay of energy for low rates*/ - FOR( i = 0; i < Mbands_gn; i++ ) - { - old_y_gain[i] = y_gain_tmp[i]; - move16(); - y_gainQ[i] = add( y_gain_tmp[i], sub( mean_g, i_mult2( i, mult_r( Gain_off, 205 /* 20/MBANDS_GN in Q16 */ ) ) ) ); - move16(); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); + VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); } - } - - return; -} - - -/*-------------------------------------------------------------------* - * GSC_gain_DQ() - * - * Form the final vector after gain quantization/Dequantization - * Common to both encoder and decoder - *-------------------------------------------------------------------*/ - -static void GSC_gain_DQ_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word16 coder_type, /* i : Coder type */ - const Word16 Mbands_gn, /* i : Number of band */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 mean_g, /* i : Average gain Q12 */ - const Word16 *Gain_in, /* i : Unquantized gain vector Q12 */ - Word16 *Gain_out /* o : Level adjusted unquantized gain vector Q12 */ -) -{ - Word16 Gain_off; - Word16 i; - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - Gain_off = 0; - move16(); - - test(); - IF( coder_type == INACTIVE || EQ_16( coder_type, UNVOICED ) ) - { test(); - IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) + IF( LE_32( core_brate_fx, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) { - Gain_off = 1843; // 9/20 in Q12 + /* Some energy is needed in high band for stat_noise_uv_enc + to be functional in inactive speech */ + y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); /*Q12*/ move16(); - } - ELSE IF( LE_32( core_brate, ACELP_7k20 ) ) - { - Gain_off = 1638; // 8/20 in Q12; /* 0 dB */ + y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); /*Q12*/ move16(); - } - ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) - { - Gain_off = 1351; // 6.6f/20 in Q12 /* ~-3.3 dB */ + y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); /*Q12*/ move16(); - } - ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) - { - Gain_off = 983; // 4.8f/20 in Q12 /* ~-2.4 dB */ + y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); /*Q12*/ move16(); - } - ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) - { - Gain_off = 717; // 3.5f/20 in Q12 /* ~-2.4 dB */ + y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); /*Q12*/ move16(); - } - ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) - { - Gain_off = 614; // 3.0f/20 in Q12 /* ~-2.4 dB */ + y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); /*Q12*/ move16(); } - } - - test(); - IF( coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) ) - { - FOR( i = 0; i < Mbands_gn; i++ ) + ELSE { - Gain_out[i] = add( Gain_in[i], mean_g ); // Q12 - move16(); + set16_fx( y_gainQ_fx + 10, 0, MBANDS_GN - 10 ); } } ELSE { - /*mimic ACELP decay of energy for low rates*/ - test(); - IF( element_mode == EVS_MONO && EQ_16( enc_dec, DEC ) ) + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + + VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); + + IF( LT_32( core_brate_fx, ACELP_9k60 ) ) { - /* This is to keep EVS mono bit-exact with the standard (there might be a small desynchronization between encoder and decoder but there is no real quality or interop. issue) */ - FOR( i = 0; i < Mbands_gn; i++ ) + /*--------------------------------------------------------------------------------------* + * UQ of the first 8 bands and half of the last 8 bands + *--------------------------------------------------------------------------------------*/ + + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + + VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); + + IF( !( coder_type == INACTIVE && st_fx->tdm_LRTD_flag == 0 && EQ_16( st_fx->idchan, 1 ) ) || GT_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { - Gain_out[i] = add( Gain_out[i], sub( mean_g, mult( Gain_off, div_s( i, Mbands_gn ) ) ) ); // Q12 + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); + + /*----------------------------------------------------------------------* + * Interpolation of the last 4 Q bands to create bands 8-16 + * And scaling + *----------------------------------------------------------------------*/ + + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + + VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); + + Copy( y_gainQ_fx + 8, y_gain_tmp3_fx, 4 ); + set16_fx( y_gainQ_fx + 12, 0, 4 ); + + fft_rel_fx( y_gainQ_fx + 8, 4, 2 ); + + y_gainQ_fx[15] = y_gainQ_fx[11]; + move16(); + y_gainQ_fx[11] = 0; + move16(); + + ifft_rel_fx( y_gainQ_fx + 8, 8, 3 ); + + FOR( i = 8; i < 16; i++ ) + { + y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ + move16(); + } + + /*----------------------------------------------------------------------* + * Copy the true Q values in the specific bands + *----------------------------------------------------------------------*/ + + y_gainQ_fx[8] = y_gain_tmp3_fx[0]; /*Q12*/ + move16(); + y_gainQ_fx[10] = y_gain_tmp3_fx[1]; /*Q12*/ move16(); - // Gain_out[i] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ); + y_gainQ_fx[12] = y_gain_tmp3_fx[2]; /*Q12*/ + move16(); + y_gainQ_fx[14] = y_gain_tmp3_fx[3]; /*Q12*/ + move16(); + } + ELSE + { + set16_fx( y_gainQ_fx + 3, 0, MBANDS_GN16k - 3 ); } } ELSE { - FOR( i = 0; i < Mbands_gn; i++ ) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Gain_out[i] = add( Gain_in[i], sub( mean_g, mult( Gain_off, div_s( i, Mbands_gn ) ) ) ); // Q12 - move16(); - // Gain_out[i] = Gain_in[i] + mean_g - ( i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ) ); - } - } - } + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); - return; -} - - -/*-------------------------------------------------------------------* - * gsc_gainQ() - * - * Quantization of the energy per band - *-------------------------------------------------------------------*/ - -Word16 gsc_gainQ_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 y_gain4[], - /* i : Energy per band */ // Q12 - Word16 y_gainQ[], - /* o : quantized energy per band */ // Q12 - const Word32 core_brate, /* i : Core rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 L_frame, /* i : frame length */ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word32 core_brate_inp /* i : true core bitrate */ -) -{ - Word16 y_gain_tmp[MBANDS_GN16k]; - Word16 y_gain_tmp2[MBANDS_GN16k]; - Word16 i, idx_g = 0; - move16(); - Word16 mean_4g_fx[1], ftmp1_fx; - Word16 Mbands_gn = MBANDS_GN; - move16(); - Word16 y_gain_tmp3[MBANDS_GN]; - Word32 L_tmp; - - if ( EQ_16( L_frame, L_FRAME16k ) ) - { - Mbands_gn = MBANDS_GN16k; - move16(); - } - - mean_4g_fx[0] = 0; - move32(); - - test(); - test(); - IF( ( EQ_16( coder_type, AUDIO ) || coder_type == INACTIVE ) && bwidth == NB ) - { - L_tmp = 0; - move32(); - FOR( i = 0; i < 10; i++ ) - { - L_tmp = L_add( L_tmp, y_gain4[i] ); - } - L_tmp = L_sub( Mpy_32_16_1( L_tmp, 3277 /* (1/10.0f) in Q15 */ ), 2457 /* 0.6f in Q12 */ ); // Q12 - ftmp1_fx = extract_l( L_tmp ); - FOR( i = 0; i < Mbands_gn; i++ ) - { - IF( LT_16( y_gain4[i], ftmp1_fx ) ) - { - y_gain_tmp2[i] = ftmp1_fx; /*Q12*/ - } - ELSE - { - y_gain_tmp2[i] = y_gain4[i]; /*Q12*/ - } - move16(); - } - - /* Quantized mean gain without clipping */ - L_tmp = 0; - move32(); - FOR( i = 0; i < 10; i++ ) - { - L_tmp = L_add( L_tmp, y_gain4[i] ); - } - L_tmp = Mpy_32_16_1( L_tmp, 3277 /* (1/10.0f) in Q15 */ ); // Q12 - mean_4g_fx[0] = extract_l( L_tmp ); // Q12 - move16(); - idx_g = vquant_fx( mean_4g_fx, Gain_meanNB_fx, mean_4g_fx, Gain_mean_dicNB_fx, 1, 64 ); - push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); - - FOR( i = 0; i < Mbands_gn; i++ ) - { - y_gain_tmp[i] = sub( y_gain_tmp2[i], mean_4g_fx[0] ); // Q12 - move16(); - } - - if ( LT_16( y_gain_tmp[9], -1229 /* -0.3f in Q12 */ ) ) - { - y_gain_tmp[9] = -1229; /* -0.3f in Q12 */ - move16(); - } - - set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 ); - idx_g = vquant_fx( y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - - IF( LT_32( core_brate, ACELP_9k60 ) ) - { - idx_g = vquant_fx( y_gain_tmp + 3, Mean_dic_NB_fx + 3, y_gain_tmp + 3, Gain_dic2_NB_fx, 3, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - - idx_g = vquant_fx( y_gain_tmp + 6, Mean_dic_NB_fx + 6, y_gain_tmp + 6, Gain_dic3_NB_fx, 4, 16 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); - } - ELSE - { - idx_g = vquant_fx( y_gain_tmp + 3, Mean_dic_NB_fx + 3, y_gain_tmp + 3, Gain_dic2_NBHR_fx, 3, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - - idx_g = vquant_fx( y_gain_tmp + 6, Mean_dic_NB_fx + 6, y_gain_tmp + 6, Gain_dic3_NBHR_fx, 4, 128 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 ); - } - - test(); - IF( LE_32( core_brate, ACELP_9k60 ) && coder_type == INACTIVE ) - { - /* Some energy is needed in high band for stat_noise_uv_enc() to be functional in inactive speech */ - y_gain_tmp[10] = mean_fx( y_gain_tmp + 6, 3 ); /*Q12*/ - move16(); - y_gain_tmp[11] = mean_fx( y_gain_tmp + 7, 3 ); /*Q12*/ - move16(); - y_gain_tmp[12] = mean_fx( y_gain_tmp + 8, 3 ); /*Q12*/ - move16(); - y_gain_tmp[13] = mean_fx( y_gain_tmp + 9, 3 ); /*Q12*/ - move16(); - y_gain_tmp[14] = mean_fx( y_gain_tmp + 10, 3 ); /*Q12*/ - move16(); - y_gain_tmp[15] = mean_fx( y_gain_tmp + 11, 3 ); /*Q12*/ - move16(); - } - ELSE - { - set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 ); - } - } - ELSE - { - L_tmp = 0; - move32(); - FOR( i = 0; i < 16; i++ ) - { - L_tmp = L_add( L_tmp, y_gain4[i] ); - } - L_tmp = Mpy_32_16_1( L_tmp, 2048 /* (1/16.f) in Q15 */ ); // Q12 - ftmp1_fx = extract_l( L_tmp ); - FOR( i = 0; i < Mbands_gn; i++ ) - { - IF( LT_16( y_gain4[i], sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) ) - { - y_gain_tmp2[i] = sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ); - } - ELSE IF( GT_16( y_gain4[i], add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) ) - { - y_gain_tmp2[i] = add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ); - } - ELSE - { - y_gain_tmp2[i] = y_gain4[i]; - } - move16(); - } - - L_tmp = 0; - move32(); - FOR( i = 0; i < 16; i++ ) - { - L_tmp = L_add( L_tmp, y_gain_tmp2[i] ); - } - L_tmp = Mpy_32_16_1( L_tmp, 2048 /* (1/16.f) in Q15 */ ); // Q12 - mean_4g_fx[0] = extract_l( L_tmp ); // Q12 - move16(); - idx_g = vquant_fx( mean_4g_fx, mean_m_fx, mean_4g_fx, mean_gain_dic_fx, 1, 64 ); - push_indice( hBstr, IND_MEAN_GAIN2, idx_g, 6 ); - - /* Subtraction of the average gain */ - FOR( i = 0; i < Mbands_gn; i++ ) - { - y_gain_tmp[i] = sub( y_gain_tmp2[i], mean_4g_fx[0] ); // Q12 - move16(); - } - - IF( LT_32( core_brate, ACELP_9k60 ) ) - { - /* prediction and quantization of the average gain */ - - /*--------------------------------------------------------------------------------------* - * Quantization of the first 8 bands - * Keep only 4 bands out of the last 8 bands - *--------------------------------------------------------------------------------------*/ - - Copy( y_gain_tmp, y_gain_tmp2, 8 ); - - y_gain_tmp2[8] = y_gain_tmp[8]; - move16(); - y_gain_tmp2[9] = y_gain_tmp[10]; - move16(); - y_gain_tmp2[10] = y_gain_tmp[12]; - move16(); - y_gain_tmp2[11] = y_gain_tmp[14]; - move16(); - - idx_g = 0; - move16(); - idx_g = vquant_fx( y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - - test(); - test(); - test(); - IF( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && EQ_16( idchan, 1 ) ) || GT_32( core_brate_inp, GSC_LRES_GAINQ_LIMIT ) ) - { - idx_g = vquant_fx( y_gain_tmp2 + 3, YGain_mean_LR_fx + 3, y_gain_tmp2 + 3, YGain_dic2_LR_fx, 4, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - - /*----------------------------------------------------------------------* - * Vector quantization of the first 8 bands + quantization of the 4 bands out of the last 8 - * Interpolation of the last 4 bands Q to create bands 8-16 - *----------------------------------------------------------------------*/ - - idx_g = vquant_fx( y_gain_tmp2 + 7, YGain_mean_LR_fx + 7, y_gain_tmp2 + 7, YGain_dic3_LR_fx, 5, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - - set16_fx( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 ); - - /* Update to quantized vector */ - Copy( y_gain_tmp2, y_gain_tmp, 8 ); - - Copy( y_gain_tmp2 + 8, y_gain_tmp3, 4 ); - set16_fx( y_gain_tmp + 8, 0, 8 ); - fft_rel_fx( y_gain_tmp2 + 8, 4, 2 ); - - Copy( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 ); - y_gain_tmp[15] = y_gain_tmp2[11]; - move16(); - ifft_rel_fx( y_gain_tmp + 8, 8, 3 ); - - FOR( i = 8; i < 16; i++ ) - { - y_gain_tmp[i] = shl( mult( y_gain_tmp[i], 23101 /* 1.41 in Q14 */ ), 1 ); /*Q12*/ - move16(); - } - - y_gain_tmp[8] = y_gain_tmp3[0]; - move16(); - y_gain_tmp[10] = y_gain_tmp3[1]; - move16(); - y_gain_tmp[12] = y_gain_tmp3[2]; - move16(); - y_gain_tmp[14] = y_gain_tmp3[3]; - move16(); - } - ELSE - { - Copy( y_gain_tmp2, y_gain_tmp, 3 ); - set16_fx( y_gain_tmp + 3, 0, MBANDS_GN16k - 3 ); - } - } - ELSE - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - idx_g = vquant_fx( y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - - idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16_fx + 4, y_gain_tmp + 4, YG_dicMR_2_fx, 4, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - - idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16_fx + 8, y_gain_tmp + 8, YG_dicMR_3_fx, 4, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - - idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16_fx + 12, y_gain_tmp + 12, YG_dicMR_4_fx, 4, 16 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); - } - ELSE - { - idx_g = vquant_fx( y_gain_tmp, YG_mean16HR_fx, y_gain_tmp, YG_dicHR_1_fx, 4, 128 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 ); - - idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16HR_fx + 4, y_gain_tmp + 4, YG_dicHR_2_fx, 4, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - - idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16HR_fx + 8, y_gain_tmp + 8, YG_dicHR_3_fx, 4, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - - idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16HR_16kHz_fx, y_gain_tmp + 12, YG_dicHR_4_16kHz_fx, 4, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - - idx_g = vquant_fx( y_gain_tmp + 16, YG_meanL2G_16kHz_fx, y_gain_tmp + 16, YG_dicL2G_16kHz_fx, 2, 8 ); - push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 ); - } - } - } - - GSC_gain_DQ_fx( element_mode, ENC, coder_type, Mbands_gn, core_brate, mean_4g_fx[0], y_gain_tmp, y_gainQ ); - - return mean_4g_fx[0]; -} - - -/*==========================================================================*/ -/* FUNCTION : Word16 gsc_gaindec_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Generic signal frequency band decoding and application */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pvq_bits_fx : core used Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) core_fx : core used Q0 */ -/* _ (Word16) bwidth_fx : input signal bandwidth Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) y_gainQ_fx : quantized gain per band */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) old_y_gain_fx : AR gain quantizer for low rate */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) : average frequency gain */ -/*==========================================================================*/ - -Word16 gsc_gaindec_fx( /* o : average frequency gain */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ -) -{ - Word16 idx_g_fx, i; - Word16 mean_4g_fx; - Word16 y_gain_tmp3_fx[MBANDS_GN]; - - test(); - test(); - IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) - { - idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); - VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - - idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); - VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); - - IF( LT_32( core_brate_fx, ACELP_9k60 ) ) - { - idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 5 ) ); - VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 4 ) ); - VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); - } - ELSE - { - idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); - VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 7 ) ); - VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); - } - test(); - IF( LE_32( core_brate_fx, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) - { - /* Some energy is needed in high band for stat_noise_uv_enc - to be functional in inactive speech */ - y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); - move16(); - y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); - move16(); - y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); - move16(); - y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); - move16(); - y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); - move16(); - y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); - move16(); - } - ELSE - { - set16_fx( y_gainQ_fx + 10, 0, MBANDS_GN - 10 ); - } - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - - VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); - - IF( LE_32( core_brate_fx, ACELP_9k60 ) ) - { - /*--------------------------------------------------------------------------------------* - * UQ of the first 8 bands and half of the last 8 bands - *--------------------------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); - - /*----------------------------------------------------------------------* - * Interpolation of the last 4 Q bands to create bands 8-16 - * And scaling - *----------------------------------------------------------------------*/ - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - - VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); - - Copy( y_gainQ_fx + 8, y_gain_tmp3_fx, 4 ); - set16_fx( y_gainQ_fx + 12, 0, 4 ); - - fft_rel_fx( y_gainQ_fx + 8, 4, 2 ); - - y_gainQ_fx[15] = y_gainQ_fx[11]; - move16(); - y_gainQ_fx[11] = 0; - move16(); - ifft_rel_fx( y_gainQ_fx + 8, 8, 3 ); - FOR( i = 8; i < 16; i++ ) - { - y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ - move16(); - } - /*----------------------------------------------------------------------* - * Copy the true Q values in the specific bands - *----------------------------------------------------------------------*/ - y_gainQ_fx[8] = y_gain_tmp3_fx[0]; - move16(); - y_gainQ_fx[10] = y_gain_tmp3_fx[1]; - move16(); - y_gainQ_fx[12] = y_gain_tmp3_fx[2]; - move16(); - y_gainQ_fx[14] = y_gain_tmp3_fx[3]; - move16(); - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); - VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16_fx + 12, YG_dicMR_4_fx, idx_g_fx, 4 ); - } - } - - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj( coder_type, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx ); - - return mean_4g_fx; -} - - -/*==========================================================================*/ -/* FUNCTION : Word16 gsc_gaindec_ivas_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Generic signal frequency band decoding and application */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pvq_bits_fx : core used Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) core_fx : core used Q0 */ -/* _ (Word16) bwidth_fx : input signal bandwidth Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) y_gainQ_fx : quantized gain per band */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) old_y_gain_fx : AR gain quantizer for low rate */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) : average frequency gain */ -/*==========================================================================*/ - -Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band Q12 */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ -) -{ - Word16 idx_g_fx, i; - Word16 mean_4g_fx; - Word16 Mbands_gn = MBANDS_GN; - move16(); - Word16 y_gain_tmp3_fx[MBANDS_GN]; - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Mbands_gn = MBANDS_GN16k; - move16(); - } - - test(); - test(); - IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx( y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); - - IF( LT_32( core_brate_fx, ACELP_9k60 ) ) - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); - VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NB_fx, idx_g_fx, 4 ); - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx( y_gainQ_fx + 3, Mean_dic_NB_fx + 3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); - VDQ_vec_fx( y_gainQ_fx + 6, Mean_dic_NB_fx + 6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); - } - test(); - IF( LE_32( core_brate_fx, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) - { - /* Some energy is needed in high band for stat_noise_uv_enc - to be functional in inactive speech */ - y_gainQ_fx[10] = mean_fx( y_gainQ_fx + 6, 3 ); /*Q12*/ - move16(); - y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); /*Q12*/ - move16(); - y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); /*Q12*/ - move16(); - y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); /*Q12*/ - move16(); - y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); /*Q12*/ - move16(); - y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); /*Q12*/ - move16(); - } - ELSE - { - set16_fx( y_gainQ_fx + 10, 0, MBANDS_GN - 10 ); - } - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - - VDQ_vec_fx( &mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); - - IF( LT_32( core_brate_fx, ACELP_9k60 ) ) - { - /*--------------------------------------------------------------------------------------* - * UQ of the first 8 bands and half of the last 8 bands - *--------------------------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx + 3, YGain_mean_LR_fx + 3, YGain_dic2_LR_fx, idx_g_fx, 4 ); - - /*----------------------------------------------------------------------* - * Interpolation of the last 4 Q bands to create bands 8-16 - * And scaling - *----------------------------------------------------------------------*/ - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - - VDQ_vec_fx( y_gainQ_fx + 7, YGain_mean_LR_fx + 7, YGain_dic3_LR_fx, idx_g_fx, 5 ); - - Copy( y_gainQ_fx + 8, y_gain_tmp3_fx, 4 ); - set16_fx( y_gainQ_fx + 12, 0, 4 ); - - fft_rel_fx( y_gainQ_fx + 8, 4, 2 ); - - y_gainQ_fx[15] = y_gainQ_fx[11]; - move16(); - y_gainQ_fx[11] = 0; - move16(); - ifft_rel_fx( y_gainQ_fx + 8, 8, 3 ); - FOR( i = 8; i < 16; i++ ) - { - y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ - move16(); - } - /*----------------------------------------------------------------------* - * Copy the true Q values in the specific bands - *----------------------------------------------------------------------*/ - y_gainQ_fx[8] = y_gain_tmp3_fx[0]; /*Q12*/ - move16(); - y_gainQ_fx[10] = y_gain_tmp3_fx[1]; /*Q12*/ - move16(); - y_gainQ_fx[12] = y_gain_tmp3_fx[2]; /*Q12*/ - move16(); - y_gainQ_fx[14] = y_gain_tmp3_fx[3]; /*Q12*/ - move16(); - } - ELSE - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 ); idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4 ); @@ -1251,8 +724,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc } } - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj_ivas_fx( coder_type, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx ); + GSC_gain_adj( coder_type, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx ); return mean_4g_fx; } @@ -1264,32 +736,40 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc * Quantization of the energy per band *-------------------------------------------------------------------*/ -Word16 gsc_gainQ_fx( /*Q12*/ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 y_gain4[], /* i : Energy per band Q12 */ - Word16 y_gainQ[], /* o : quantized energy per band Q12 */ - const Word32 core_brate, /* i : Core rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth /* i : input signal bandwidth */ +Word16 gsc_gainQ_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 idchan, /* i : channel ID */ + const Word16 y_gain4[], /* i : Energy per band Q12*/ + Word16 y_gainQ[], /* o : quantized energy per band Q12*/ + const Word32 core_brate, /* i : Core rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 L_frame, /* i : frame length */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word32 core_brate_inp /* i : true core bitrate */ ) { - Word16 y_gain_tmp[MBANDS_GN], y_gain_tmp2[MBANDS_GN]; + Word16 y_gain_tmp[MBANDS_GN16k], y_gain_tmp2[MBANDS_GN16k]; Word16 i, idx_g = 0; move16(); Word16 mean_4g[1] = { 0 }, tmp16, tmp1, tmp2; move16(); Word16 Mbands_gn = MBANDS_GN; - Word16 y_gain_tmp3[MBANDS_GN]; + Word16 y_gain_tmp3[MBANDS_GN16k]; Word16 cnt; Word32 L_tmp; mean_4g[0] = 0; + if ( EQ_16( L_frame, L_FRAME16k ) ) + { + Mbands_gn = MBANDS_GN16k; + move16(); + } test(); test(); IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && ( bwidth == NB ) ) { - /*ftmp1 = mean(y_gain4, 10)-0.6f;*/ L_tmp = L_deposit_l( 0 ); FOR( cnt = 0; cnt < 10; cnt++ ) @@ -1373,7 +853,6 @@ Word16 gsc_gainQ_fx( /*Q12*/ ELSE { /*ftmp1 = mean(y_gain4, 16);*/ - L_tmp = 0; move32(); FOR( cnt = 0; cnt < 16; cnt++ ) @@ -1382,7 +861,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ } tmp16 = round_fx( L_tmp ); - tmp1 = sub( tmp16, 4915 ); + tmp1 = sub( tmp16, 4915 ); /* 0.6 Q12 */ tmp2 = add( tmp16, 4915 ); L_tmp = 0; move32(); @@ -1438,54 +917,89 @@ Word16 gsc_gainQ_fx( /*Q12*/ idx_g = vquant_fx( y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx( y_gain_tmp2 + 3, YGain_mean_LR_fx + 3, y_gain_tmp2 + 3, YGain_dic2_LR_fx, 4, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx( y_gain_tmp2 + 7, YGain_mean_LR_fx + 7, y_gain_tmp2 + 7, YGain_dic3_LR_fx, 5, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - set16_fx( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 ); - /* Update to quantized vector */ - Copy( y_gain_tmp2, y_gain_tmp, 8 ); + test(); + test(); + test(); + IF( !( coder_type == INACTIVE && tdm_LRTD_flag == 0 && EQ_16( idchan, 1 ) ) || GT_32( core_brate_inp, GSC_LRES_GAINQ_LIMIT ) ) + { + idx_g = vquant_fx( y_gain_tmp2 + 3, YGain_mean_LR_fx + 3, y_gain_tmp2 + 3, YGain_dic2_LR_fx, 4, 32 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); + idx_g = vquant_fx( y_gain_tmp2 + 7, YGain_mean_LR_fx + 7, y_gain_tmp2 + 7, YGain_dic3_LR_fx, 5, 32 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); + set16_fx( y_gain_tmp2 + 12, 0, MBANDS_GN - 12 ); - Copy( y_gain_tmp2 + 8, y_gain_tmp3, 4 ); - set16_fx( y_gain_tmp + 8, 0, 8 ); - fft_rel_fx( y_gain_tmp2 + 8, 4, 2 ); + /* Update to quantized vector */ + Copy( y_gain_tmp2, y_gain_tmp, 8 ); - Copy( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 ); - y_gain_tmp[15] = y_gain_tmp2[11]; - move16(); - ifft_rel_fx( y_gain_tmp + 8, 8, 3 ); + Copy( y_gain_tmp2 + 8, y_gain_tmp3, 4 ); + set16_fx( y_gain_tmp + 8, 0, 8 ); + fft_rel_fx( y_gain_tmp2 + 8, 4, 2 ); - FOR( i = 8; i < 16; i++ ) - { - y_gain_tmp[i] = shl( mult_r( y_gain_tmp[i], 23101 ), 1 ); + Copy( y_gain_tmp2 + 8, y_gain_tmp + 8, 3 ); + y_gain_tmp[15] = y_gain_tmp2[11]; move16(); - } + ifft_rel_fx( y_gain_tmp + 8, 8, 3 ); - y_gain_tmp[8] = y_gain_tmp3[0]; - move16(); - y_gain_tmp[10] = y_gain_tmp3[1]; - move16(); - y_gain_tmp[12] = y_gain_tmp3[2]; - move16(); - y_gain_tmp[14] = y_gain_tmp3[3]; - move16(); + FOR( i = 8; i < 16; i++ ) + { + y_gain_tmp[i] = shl( mult_r( y_gain_tmp[i], 23101 ), 1 ); + move16(); + } + + y_gain_tmp[8] = y_gain_tmp3[0]; + move16(); + y_gain_tmp[10] = y_gain_tmp3[1]; + move16(); + y_gain_tmp[12] = y_gain_tmp3[2]; + move16(); + y_gain_tmp[14] = y_gain_tmp3[3]; + move16(); + } + ELSE + { + Copy( y_gain_tmp2, y_gain_tmp, 3 ); + set16_fx( y_gain_tmp + 3, 0, MBANDS_GN16k - 3 ); + } } ELSE { - idx_g = vquant_fx( y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); - idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16_fx + 4, y_gain_tmp + 4, YG_dicMR_2_fx, 4, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16_fx + 8, y_gain_tmp + 8, YG_dicMR_3_fx, 4, 32 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16_fx + 12, y_gain_tmp + 12, YG_dicMR_4_fx, 4, 16 ); - push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); + IF( EQ_16( L_frame, L_FRAME ) ) + { + idx_g = vquant_fx( y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); + + idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16_fx + 4, y_gain_tmp + 4, YG_dicMR_2_fx, 4, 32 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); + + idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16_fx + 8, y_gain_tmp + 8, YG_dicMR_3_fx, 4, 32 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 5 ); + + idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16_fx + 12, y_gain_tmp + 12, YG_dicMR_4_fx, 4, 16 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 4 ); + } + ELSE + { + idx_g = vquant_fx( y_gain_tmp, YG_mean16HR_fx, y_gain_tmp, YG_dicHR_1_fx, 4, 128 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 7 ); + + idx_g = vquant_fx( y_gain_tmp + 4, YG_mean16HR_fx + 4, y_gain_tmp + 4, YG_dicHR_2_fx, 4, 64 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); + + idx_g = vquant_fx( y_gain_tmp + 8, YG_mean16HR_fx + 8, y_gain_tmp + 8, YG_dicHR_3_fx, 4, 64 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); + + idx_g = vquant_fx( y_gain_tmp + 12, YG_mean16HR_16kHz_fx, y_gain_tmp + 12, YG_dicHR_4_16kHz_fx, 4, 64 ); + push_indice( hBstr, IND_Y_GAIN_TMP, idx_g, 6 ); + + idx_g = vquant_fx( y_gain_tmp + 16, YG_meanL2G_16kHz_fx, y_gain_tmp + 16, YG_dicL2G_16kHz_fx, 2, 8 ); + push_indice( hBstr, IND_Y_GAIN_HF, idx_g, 3 ); + } } } /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj( coder_type, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ ); + GSC_gain_adj( coder_type, Mbands_gn, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ ); return mean_4g[0]; /*Q12*/ } @@ -1498,11 +1012,11 @@ Word16 gsc_gainQ_fx( /*Q12*/ *-------------------------------------------------------------------*/ static Word16 VDQ_vec_fx( - Word16 *Qvec_out_fx, /* o: Quanitzed vector */ - const Word16 *mean_dic_fx, /* i: average codebook */ - const Word16 *dic_fx, /* i: codebook */ - const Word16 index_fx, /* i: index of codebook*/ - const Word16 vec_en_fx /* i: vector length */ + Word16 *Qvec_out_fx, /* o : Quanitzed vector */ + const Word16 *mean_dic_fx, /* i : average codebook */ + const Word16 *dic_fx, /* i : codebook */ + const Word16 index_fx, /* i : index of codebook */ + const Word16 vec_en_fx /* i : vector length */ ) { Word16 i, j; diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 0829a934dcef39340f470260e9066e54aecbed4f..a8d2aa6823f103230af4c50772b1ca28b17379b4 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -77,7 +77,11 @@ void Inac_switch_ematch_fx( test(); IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 ) { +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); +#else Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); +#endif /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) @@ -91,7 +95,11 @@ void Inac_switch_ematch_fx( /* Find spectrum and energy per band for GC and VC frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); +#else Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); +#endif /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) @@ -104,7 +112,12 @@ void Inac_switch_ematch_fx( { /* Find spectrum and energy per band for inactive frames */ edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode ); + +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); +#else Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); +#endif /* More agressive smoothing in the first 50 frames */ pt_exc = dct_exc_tmp; diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 8489cd66de0015dd76d4f18bb75c3861a077fb21..800a9c3beed883f5941fc88fb5d25eeeb44bf516 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -636,7 +636,7 @@ static void envelop_modify_fx( return; } - +#ifndef FIX_1904_HARM_GSC_ENC void highband_exc_dct_in_fx( const Word32 core_brate, /* i : core bitrate */ const Word16 *mfreq_bindiv, /* i : bin per bands tables */ @@ -751,11 +751,11 @@ void highband_exc_dct_in_fx( test(); IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) ) { - set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */ + set16_fx( noisepb, 13107, last_bin ); /*0.4 in Q15 */ } ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) ) { - set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k ); + set16_fx( noisepb, 13107 /*0.4f*/, last_bin ); } ELSE { @@ -772,7 +772,7 @@ void highband_exc_dct_in_fx( test(); IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) { - set16_fx( noisepb, 3277, MBANDS_GN ); + set16_fx( noisepb, 3277, last_bin ); } test(); IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) @@ -801,12 +801,19 @@ void highband_exc_dct_in_fx( test(); IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); +#else Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 ); +#endif } ELSE { +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); +#else Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); - +#endif IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) { FOR( i = L_FRAME - 16; i < L_FRAME; i++ ) @@ -1010,8 +1017,14 @@ void highband_exc_dct_in_fx( return; } +#endif + +#ifdef FIX_1904_HARM_GSC_ENC +void highband_exc_dct_in_fx( +#else void highband_exc_dct_in_ivas_fx( +#endif const Word32 core_brate, /* i : core bitrate */ const Word16 *mfreq_bindiv, /* i : bin per bands tables */ Word16 last_bin, /* i : last bin of bit allocation */ @@ -1056,6 +1069,9 @@ void highband_exc_dct_in_ivas_fx( Word16 frac, exp, tmp1; Word16 tmp2; Word16 *end, Q_hb_exc; +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + Word16 Flag_adj_q_exc, old_Q_exc; +#endif FOR( j = 10; j < MBANDS_GN; j++ ) { @@ -1125,11 +1141,11 @@ void highband_exc_dct_in_ivas_fx( test(); IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) ) { - set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */ + set16_fx( noisepb, 13107, last_bin ); /*0.4 in Q15 */ } ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) ) { - set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k ); + set16_fx( noisepb, 13107 /*0.4f*/, last_bin ); } ELSE { @@ -1146,7 +1162,7 @@ void highband_exc_dct_in_ivas_fx( IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) { - set16_fx( noisepb, 3277, MBANDS_GN ); + set16_fx( noisepb, 3277, last_bin ); } test(); @@ -1168,19 +1184,29 @@ void highband_exc_dct_in_ivas_fx( { Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ ); } + /*--------------------------------------------------------------------------------------* * Quantize average gain * Subtract Q averaged gain * VQ of remaining gain per band *--------------------------------------------------------------------------------------*/ + test(); IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) { +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); +#else Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); +#endif } ELSE { +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); +#else Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); +#endif test(); IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) @@ -1195,9 +1221,11 @@ void highband_exc_dct_in_ivas_fx( } } } + /*--------------------------------------------------------------------------------------* * Check potential energy excitation overshoot *--------------------------------------------------------------------------------------*/ + IF( bfi ) { test(); @@ -1315,7 +1343,7 @@ void highband_exc_dct_in_ivas_fx( move16(); } } - +#if !defined FIX_2338_HARM_GSC_GAIN_COMP && !defined FIX_2380_HARM_GSC_GAIN_COMP_FX IF( EQ_16( element_mode, EVS_MONO ) ) { Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); @@ -1355,6 +1383,33 @@ void highband_exc_dct_in_ivas_fx( Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); } } +#elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX + Flag_adj_q_exc = 0; + move16(); + IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep all EVS BE */ + { + Flag_adj_q_exc = 1; + move16(); + } + old_Q_exc = *Q_exc; + move16(); + *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Flag_adj_q_exc, Qexc_diffQ, *Q_exc ); + Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, old_Q_exc ) ); + + IF( exc_wo_nf != NULL ) + { + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Flag_adj_q_exc, Qexc_diffQ, *Q_exc ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); + } +#else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */ + Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); + + IF( exc_wo_nf != NULL ) + { + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); + } +#endif /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c index bee644b0ea037de41c76d610beedf781a460c730..c496a377708fea392fee16a1283e421473e2563c 100644 --- a/lib_com/gs_preech_fx.c +++ b/lib_com/gs_preech_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include #include "options.h" -#include #include "cnst.h" #include "rom_com.h" #include "prot_fx.h" @@ -57,7 +56,12 @@ void pre_echo_att_fx( const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, const Word16 last_coder_type, /* i : Last coding mode Q0*/ - const Word16 L_frame /* i : Frame length Q0*/ +#ifdef FIX_1904_HARM_GSC_ENC + const Word16 L_frame, /* i : Frame length Q0*/ + const Word16 element_mode /* i : Current IVAS element mode*/ +#else + const Word16 L_frame /* i : Frame length Q0*/ +#endif ) { Word32 etmp_fx; @@ -69,6 +73,9 @@ void pre_echo_att_fx( Word16 tmp, n1, n2, exp, frac1, frac2; Word32 etmp1_fx; Word16 att_len; +#ifdef FIX_1904_HARM_GSC_ENC + Word16 etmp_e, tmp_e; +#endif test(); IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */ @@ -108,33 +115,53 @@ void pre_echo_att_fx( IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 ) { /* Find the average energy before the attack */ - L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */ - L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */ - tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */ - L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */ - etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */ - - etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */ - /* Find the correction factor and apply it before the attack */ - /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ - /* = isqrt(etmp/(*Last_frame_ener)) */ - etmp_fx = L_max( etmp_fx, 1 ); - *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 ); - move32(); - n1 = norm_l( etmp_fx ); - n2 = norm_l( *Last_frame_ener_fx ); - - n1 = sub( n1, 1 ); - exp = sub( n1, n2 ); - - frac1 = round_fx( L_shl( etmp_fx, n1 ) ); - frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); - L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */ - L_tmp = L_shr( L_tmp, exp ); /* add exponent */ - - L_tmp = Isqrt( L_tmp ); - ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */ + { + etmp_fx = sum32_fx( finc_fx, attack_pos_fx ); + etmp_e = sub( 31, add( shl( Q_new, 1 ), 1 ) ); + etmp_fx = L_add( etmp_fx, L_shr( 21474836 /*0.01 in Q31*/, etmp_e ) ); /* etmp = etmp + 0.01; (exp = etmp_e) */ + etmp_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( etmp_fx, L_mult0( attack_pos_fx, ATT_SEG_LEN ), &tmp_e ) ); + tmp_e = add( tmp_e, sub( etmp_e, 31 ) ); + etmp_e = tmp_e; + move16(); + /* Find the correction factor and apply it before the attack */ + tmp = BASOP_Util_Divide3232_Scale( *Last_frame_ener_fx, etmp_fx, &tmp_e ); /* numerator Q = 2 * Q_new + 1; denominator Q = 31 - tmp_e */ + tmp_e = add( tmp_e, sub( sub( 31, etmp_e ), add( shl( Q_new, 1 ), 1 ) ) ); /* tmp_e = tmp_e + (31 - tmp_e) - (2 * Q_new + 1) */ + tmp = Sqrt16( tmp, &tmp_e ); + ratio_fx = shr_sat( tmp, sub( 2, tmp_e ) ); /* Q13 */ + } + ELSE +#endif + { + L_tmp = sum32_fx( finc_fx, attack_pos_fx ); /*Q1 */ + L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */ + tmp = round_fx( Isqrt( L_tmp1 ) ); /*Q15 */ + L_tmp = L_shr( L_tmp, 2 ); /*Q1 ; ATT_SEG_LEN=4 */ + etmp_fx = Mult_32_16( L_tmp, tmp ); /*Q1 */ + + etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */ + /* Find the correction factor and apply it before the attack */ + /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ + /* = isqrt(etmp/(*Last_frame_ener)) */ + etmp_fx = L_max( etmp_fx, 1 ); + *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 ); + move32(); + n1 = norm_l( etmp_fx ); + n2 = norm_l( *Last_frame_ener_fx ); + + n1 = sub( n1, 1 ); + exp = sub( n1, n2 ); + + frac1 = round_fx( L_shl( etmp_fx, n1 ) ); + frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) ); + L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */ + L_tmp = L_shr( L_tmp, exp ); /* add exponent */ + + L_tmp = Isqrt( L_tmp ); + ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */ + } /* Pre-echo atttenuation should never increase the energy */ ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) @@ -153,16 +180,31 @@ void pre_echo_att_fx( * In normal cases, just compute the energy of the frame *-------------------------------------------------------*/ - etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */ - etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ - *Last_frame_ener_fx = etmp_fx; - move32(); /*2*Q_new+1*/ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */ + { + Word16 exp_etmp = sub( 15, Q_new ); + etmp_fx = sum2_16_exp_fx( exc_fx, L_frame, &exp_etmp, 7 ); /* Q = 31-exp_etmp */ + etmp_fx = L_shr( etmp_fx, 8 ); /*31-exp_etmp//INV_L_FRAME = 1/256*/ + IF( EQ_16( L_frame, L_FRAME16k ) ) + { + etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*31 - exp_etmp*/ + } + *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/ + } + ELSE +#endif + { + etmp_fx = sum2_fx( exc_fx, L_frame ); /*2*Q_new+1 */ + etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ + *Last_frame_ener_fx = etmp_fx; + move32(); /*2*Q_new+1*/ + } } return; } - - +#ifndef FIX_1904_HARM_GSC_ENC void pre_echo_att_ivas_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ @@ -267,3 +309,4 @@ void pre_echo_att_ivas_fx( return; } +#endif diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c index 382755b8eb5415c8f0d74d0ee229e54cfb0acc25..1622a7b1e900e0a25aea5e5a3658249d09182d98 100644 --- a/lib_com/hp50_fx.c +++ b/lib_com/hp50_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ ====================================================================================*/ #include -#include #include "options.h" #include "prot_fx.h" #include "wmc_auto.h" diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index e4c671a74c7b65877dd9facc121b2c9dcd644d4a..40df76cae17dd491ce44a34c6e4462d19e055368 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index 78f60d4659b3eb2e3d64e98c2904dd75eccfc1ee..1331b31a172c7d0a914341f5288751c76e1ece2d 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -209,171 +209,6 @@ void mdct_spectrum_denorm_fx( } -void mdct_spectrum_denorm_ivas_fx( - const Word32 inp_vector[], /* i : Q0 : */ - Word32 L_y2[], /* i/o : Qs : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word32 L_band_energy[], /* i : Qbe : band energy */ - const Word16 npulses[], /* i : Q0 : number of coded spectrum */ - const Word16 bands, /* i : Q0 : number of subbands */ - const Word16 ld_slope_fx, /* i : Q15 : */ - const Word16 pd_thresh_fx /* i : Q15 : */ -) -{ - Word16 i, k; - Word32 L_Eyy; - Word32 L_tmp, L_temp; - Word16 temp_fx, temp_lo_fx, temp_hi_fx; - Word32 L_inp_tmp[L_FRAME48k]; - Word16 exp_norm; - Word16 exp_safe; - Word16 exp_normn, exp_normd; - - Word16 pd_fx; - Word16 Qpd; - - Word16 div_pd_fx; - Word16 Qdivpd; - Word32 L_div_pd; - - Word16 frac, exp; - - Word16 gain_tweak_fx; - Word16 Qtweak; - - Word16 exp_shift; - - Word16 QEyy; - Word16 pow_fx; - Word16 Qpow; - Word16 Qdiv; - Word16 Qgamma; - Word16 gamma_fx; - - Word16 cond_fx; - - exp_safe = 4; /* safe bit for overflow */ - move16(); - - FOR( k = 0; k < bands; k++ ) - { - L_tmp = L_deposit_l( 0 ); - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - L_inp_tmp[i] = L_mult( extract_l( inp_vector[i] ), extract_l( inp_vector[i] ) ); - move32(); /* Q0+Q0+1 */ - L_tmp = L_or( L_tmp, L_inp_tmp[i] ); - } - exp_norm = norm_l( L_tmp ); - exp_norm = sub( exp_norm, exp_safe ); - - L_Eyy = L_deposit_l( 0 ); - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - /*Eyy += (float) inp_vector[i] * inp_vector[i]; */ - L_Eyy = L_add( L_Eyy, L_shl( L_inp_tmp[i], exp_norm ) ); /* Q1+exp_norm */ - } - QEyy = add( 1, exp_norm ); - - IF( L_Eyy > 0x0L ) - { - /* Set gamma to be pulse gain which results in perfect quantized subband energy */ - /*gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); */ - - /* Pow part (pow(2.0f, band_energy) ) */ - L_temp = L_shr( L_band_energy[k], sub( SWB_BWE_LR_Qbe, 16 ) ); - temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); - Qpow = sub( 14, temp_hi_fx ); - pow_fx = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qpow */ - - /* Div part ( pow (2.0f, band_energy[i])/Eyy ) */ - exp_normn = norm_s( pow_fx ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_l( L_Eyy ); - temp_fx = div_s( shl( pow_fx, exp_normn ), extract_h( L_shl( L_Eyy, exp_normd ) ) ); /* ((Qpow + exp_norm) - (QEyy + exp_normd)) + 31 */ - Qdiv = add( sub( add( Qpow, exp_normn ), add( QEyy, exp_normd ) ), 31 ); - - exp_norm = norm_s( temp_fx ); - temp_fx = shl( temp_fx, exp_norm ); /* Qdiv + exp_norm */ - Qdiv = add( Qdiv, exp_norm ); - - /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */ - Qgamma = add( Qdiv, 16 ); - IF( s_and( Qdiv, 1 ) == 0 ) /* Qdiv % 2 == 0 */ - { - L_temp = Sqrt_l( L_shr( L_deposit_h( temp_fx ), 1 ), &exp_norm ); - L_temp = L_shr( L_temp, exp_norm ); - Qgamma = sub( shr( Qgamma, 1 ), 1 ); - gamma_fx = round_fx( L_temp ); - } - ELSE - { - L_temp = Sqrt_l( L_deposit_h( temp_fx ), &exp_norm ); - L_temp = L_shr( L_temp, exp_norm ); - Qgamma = shr( Qgamma, 1 ); - gamma_fx = round_fx( L_temp ); - } - - /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ - /*pd = (float) npulses[k] / band_width[k]; */ - exp_normn = norm_s( npulses[k] ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_s( band_width[k] ); - pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_normn + exp_normd) */ - Qpd = add( sub( exp_normn, exp_normd ), 15 ); - - cond_fx = sub( shl_sat( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); /* Q15 */ - move16(); /* allow overflow happen. */ - IF( cond_fx < 0 ) - { - /*gain_tweak = (float) pow (2.0f, (ld_slope * log2_f (pd / pd_thresh))); */ - /* Div part */ - exp_normn = norm_s( pd_fx ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_s( pd_thresh_fx ); - div_pd_fx = div_s( shl( pd_fx, exp_normn ), shl( pd_thresh_fx, exp_normd ) ); /* Qpd+exp_normn - (15 + exp_normd) + 15 */ - Qdivpd = add( sub( add( Qpd, exp_normn ), add( 15, exp_normd ) ), 15 ); - - /* Log2 part */ - exp_norm = norm_s( div_pd_fx ); - L_div_pd = L_deposit_h( shl( div_pd_fx, exp_norm ) ); /* Qdivpd + exp_norm + 16 */ - Qdivpd = add( add( Qdivpd, exp_norm ), 16 ); - - frac = Log2_norm_lc( L_div_pd ); - exp = sub( 30, Qdivpd ); - L_tmp = L_Comp( exp, frac ); /* Q16 */ - - /* Mult part */ - L_tmp = Mpy_32_16_1( L_tmp, ld_slope_fx ); - - /* Pow part */ - temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - Qtweak = sub( 14, temp_hi_fx ); - gain_tweak_fx = extract_l( Pow2( 14, temp_lo_fx ) ); - - /*gamma *= gain_tweak; */ - L_tmp = L_mult( gamma_fx, gain_tweak_fx ); /* Qgamma+Qtweak+1 */ - exp_norm = norm_l( L_tmp ); - gamma_fx = round_fx_sat( L_shl( L_tmp, exp_norm ) ); - Qgamma = sub( add( add( Qgamma, Qtweak ), exp_norm ), 15 ); /*Qgamma+Qtweak+1+exp_norm-16; */ - } - - exp_shift = sub( SWB_BWE_LR_Qs - 1, Qgamma ); - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - /*y2[i] = gamma * inp_vector[i]; */ - L_tmp = L_mult( gamma_fx, extract_l( inp_vector[i] ) ); /* Qgamma+0+1=Qgamma+1 */ - L_y2[i] = L_shl( L_tmp, exp_shift ); /* SWB_BWE_LR_Qs */ - move32(); - } - } - } - - return; -} - /*==========================================================================*/ /* FUNCTION : void hq2_core_configure_fx() */ /*--------------------------------------------------------------------------*/ diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index 76efad10e991b289bd73e343153f8440468cc7b5..c3b373d51d2efde69fa8044f047776fdf0eea8d1 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,7 +34,7 @@ #include "options.h" #include "prot_fx.h" #include "oper_32b.h" -#include "move.h" +#include "stl.h" /*--------------------------------------------------------------------------* * hq2_noise_inject() diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index efdbea428063fe26224390f7fd1128fdd72ce812..cc5f483eadb9af737c0a99fb6d02eb3111bfb0c8 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/hvq_pvq_bitalloc_fx.c b/lib_com/hvq_pvq_bitalloc_fx.c index ea51afe8889a7ada88e3d207702a3f4d529b9ba0..905749d47d8ca12ecf270991ac0cab4a2082c75b 100644 --- a/lib_com/hvq_pvq_bitalloc_fx.c +++ b/lib_com/hvq_pvq_bitalloc_fx.c @@ -40,6 +40,9 @@ Word16 hvq_pvq_bitalloc_fx( UWord16 lsb; Word16 num_sfm; + *n_sel_bands = 0; + move16(); + IF( EQ_16( bwidth_fx, FB ) ) { num_sfm = SFM_N_HARM_FB; @@ -107,8 +110,6 @@ Word16 hvq_pvq_bitalloc_fx( return 0; } - *n_sel_bands = 0; - move16(); envSum = 0; move16(); E_max = L_deposit_l( 0 ); diff --git a/lib_com/ifft_rel_fx.c b/lib_com/ifft_rel_fx.c index 450e9195ec0f2bb96c63443a1e1c61d35ef32c2e..933925b11bfdb9619a511f76569ad3f436504639 100644 --- a/lib_com/ifft_rel_fx.c +++ b/lib_com/ifft_rel_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -139,7 +139,10 @@ void ifft_rel_fx( /*Can be acheived with a shr */ step = idiv1616( N_MAX_SAS, n2 ); move16(); - + IF( LT_16( n8, 2 ) ) + { + continue; + } s = sincos_t_fx + step; /*Q15 */ c = s + 64; /*Q15 */ s3 = sincos_t_fx + i_mult2( step, 3 ); /*Q15 */ diff --git a/lib_com/int_lsp_fx.c b/lib_com/int_lsp_fx.c index 08ab6ba85458ce3160f9acf2d05af088bff5434e..ab84c76bbf51544f5b24366b9afb61c883e970c9 100644 --- a/lib_com/int_lsp_fx.c +++ b/lib_com/int_lsp_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -43,13 +43,13 @@ void int_lsp_fx( - const Word16 L_frame, /* i : length of the frame */ + const Word16 L_frame, /* i : length of the frame */ const Word16 lsp_old[], /* i : Q15 LSPs from past frame */ const Word16 lsp_new[], /* i : Q15 LSPs from present frame */ Word16 *Aq, /* o : Q12 LP coefficients in both subframes */ - const Word16 m, /* i : order of LP filter */ + const Word16 m, /* i : order of LP filter */ const Word16 *int_coeffs, /* i : Q15 interpolation coefficients */ - const Word16 Opt_AMR_WB /* i : Q0 flag indicating AMR-WB IO mode */ + const Word16 Opt_AMR_WB /* i : Q0 flag indicating AMR-WB IO mode */ ) { Word16 lsp[M], fnew, fold; @@ -118,81 +118,6 @@ void int_lsp4_fx( Word32 L_tmp; const Word16 *pt_int_coeffs; - IF( EQ_16( L_frame, L_FRAME ) ) - { - IF( EQ_16( relax_prev_lsf_interp, 1 ) ) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_12k8_fx; /*Q15*/ - } - ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) - { - pt_int_coeffs = interpol_frac_mid_FEC_fx; /*Q15*/ - } - ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_12k8_fx; /*Q15*/ - } - ELSE - { - pt_int_coeffs = interpol_frac_mid_fx; /*Q15*/ - } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( EQ_16( relax_prev_lsf_interp, 1 ) ) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_16k_fx; /*Q15*/ - } - ELSE IF( EQ_16( relax_prev_lsf_interp, 2 ) ) - { - pt_int_coeffs = interpol_frac_mid_16k_FEC_fx; /*Q15*/ - } - ELSE IF( EQ_16( relax_prev_lsf_interp, -1 ) ) - { - pt_int_coeffs = interpol_frac_mid_relaxprev_pred_16k_fx; /*Q15*/ - } - ELSE - { - pt_int_coeffs = interpol_frac_mid_16k_fx; /*Q15*/ - } - } - k = sub( shr( L_frame, 6 ), 1 ); - FOR( j = 0; j < k; j++ ) - { - FOR( i = 0; i < m; i++ ) - { - L_tmp = L_mult( lsp_old[i], *pt_int_coeffs ); /*Q31 */ - L_tmp = L_mac( L_tmp, lsp_mid[i], *( pt_int_coeffs + 1 ) ); /*Q31 */ - lsp[i] = mac_r( L_tmp, lsp_new[i], *( pt_int_coeffs + 2 ) ); - move16(); - } - pt_int_coeffs += 3; - - E_LPC_f_lsp_a_conversion( lsp, Aq, m ); - Aq += add( m, 1 ); - } - - /* Last subframe */ - E_LPC_f_lsp_a_conversion( lsp_new, Aq, m ); - - return; -} - -void int_lsp4_ivas_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame Q15*/ - const Word16 lsp_mid[], /* i : LSPs from mid-frame Q15*/ - const Word16 lsp_new[], /* i : LSPs from present frame Q15*/ - Word16 *Aq, /* o : LP coefficients in both subframes Q12*/ - const Word16 m, /* i : order of LP filter */ - Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ -) -{ - Word16 lsp[M16k]; - Word16 i, j, k; - Word32 L_tmp; - const Word16 *pt_int_coeffs; - IF( EQ_16( L_frame, L_FRAME ) ) { IF( EQ_16( relax_prev_lsf_interp, 1 ) ) @@ -209,7 +134,6 @@ void int_lsp4_ivas_fx( } ELSE IF( EQ_16( relax_prev_lsf_interp, -2 ) ) { - // This condition not present in int_lsp4_fx pt_int_coeffs = interpol_frac2_mid_fx; /*Q15*/ } ELSE diff --git a/lib_com/interleave_spectrum_fx.c b/lib_com/interleave_spectrum_fx.c index c12623f0d09809ae6b0f70993e1f099f84bdae3a..8847b9f5b2cf36b5a39aa2f690132efe209f9b34 100644 --- a/lib_com/interleave_spectrum_fx.c +++ b/lib_com/interleave_spectrum_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/interpol_fx.c b/lib_com/interpol_fx.c index 5a78eb9bb15cd5a89d48836171606a702c904dd5..78c277a216afe4e35bfa54626d7f70a573a5174c 100644 --- a/lib_com/interpol_fx.c +++ b/lib_com/interpol_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c index 5ab82ee6dc158e877fd24f908e16cd20545f4f5c..0d623b3f636ed0c9eb52fa6a41780ddc7adee1f3 100644 --- a/lib_com/isf_dec_amr_wb_fx.c +++ b/lib_com/isf_dec_amr_wb_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c index 3f6e181efb2154cf8fc2ce949321b0959c1dab90..35a4f1581b85ce82e86f16747181dd57c410e9c8 100644 --- a/lib_com/ivas_agc_com_fx.c +++ b/lib_com/ivas_agc_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,13 +32,13 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" -#include #include "wmc_auto.h" #include "prot_fx.h" #include "rom_com.h" + + /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_arith_fx.c b/lib_com/ivas_arith_fx.c index c708976dac8552562abb21fd47637ec18a9eb61f..aa261f69daab8bf32323b2299d212927b82d3afb 100644 --- a/lib_com/ivas_arith_fx.c +++ b/lib_com/ivas_arith_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_avq_pos_reorder_com_fx.c b/lib_com/ivas_avq_pos_reorder_com_fx.c index 25f8be3ad2ae64b4b05bc88bfc19b22043377621..5d05618e1b5eaa0b2fd5469f3e5b78df1c12b240 100644 --- a/lib_com/ivas_avq_pos_reorder_com_fx.c +++ b/lib_com/ivas_avq_pos_reorder_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 7f16a8b365187a2d07687249b7ff9d08d5142493..f2cf7ca5cc7ccee588152d5a094359d082ce7bd0 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -186,12 +186,12 @@ typedef enum #define IVAS_NUM_SUPPORTED_FS 3 /* number of supported sampling-rates in IVAS */ #define CLDFB_SLOT_NS 1250000L /* 1.25ms: CLDFB slot length */ -#define MAX_JBM_SUBFRAMES_5MS 8 -#define DEFAULT_JBM_SUBFRAMES_5MS 4 -#define JBM_CLDFB_SLOTS_IN_SUBFRAME 4 +#define DEFAULT_JBM_SUBFRAMES_5MS 4 /* == IVAS_MAX_PARAM_SPATIAL_SUBFRAMES */ +#define MAX_JBM_SUBFRAMES_5MS ( DEFAULT_JBM_SUBFRAMES_5MS * 2 ) +#define JBM_CLDFB_SLOTS_IN_SUBFRAME 4 /* == IVAS_MAX_PARAM_SPATIAL_SUBFRAMES */ #define JBM_CLDFB_SLOTS_IN_SUBFRAME_LOG2 2 /* To be used for shift operation instead of division */ -#define MAX_JBM_CLDFB_TIMESLOTS 32 -#define DEFAULT_JBM_CLDFB_TIMESLOTS 16 +#define DEFAULT_JBM_CLDFB_TIMESLOTS CLDFB_NO_COL_MAX +#define MAX_JBM_CLDFB_TIMESLOTS ( DEFAULT_JBM_CLDFB_TIMESLOTS * 2 ) #define MAX_JBM_L_FRAME48k ( IVAS_MAX_FRAME_SIZE * 2 ) /* 1920: max. time-scaled frame buffer length (per channel) in samples */ #define MAX_JBM_L_FRAME_NS 40000000L /* 40 ms: time-scaled frame size in ns, proportional to MAX_JBM_L_FRAME48k */ #define MAX_SPAR_INTERNAL_CHANNELS IVAS_SPAR_MAX_CH @@ -561,7 +561,7 @@ typedef enum #define STEREO_DFT_ITD_FS 32000 #define STEREO_DFT_ITD_MAX 160 /*samples @ 32000*/ #define STEREO_DFT_ITD_MAX_ANA 200 -#define STEREO_DFT_ITD_MIN max( STEREO_DFT_ITD_MAX - 256 + 1, 1 ) /*STEREO_DFT_ITD_MAX-pow(2,STEREO_DFT_ITD_NBITS-1)+1*/ +#define STEREO_DFT_ITD_MIN 1 /* == max( STEREO_DFT_ITD_MAX - pow(2,STEREO_DFT_ITD_NBITS-1) + 1, 1 )*/ #define STEREO_DFT_ITD_NBITS 9 /* 1 bit for sign, the rest for the absolute value*/ #define STEREO_DFT_ITD_MODE_NBITS 1 @@ -643,9 +643,6 @@ typedef enum #define SBA_DIRAC_NRG_SMOOTH_LONG 10 #define SBA_DIRAC_NRG_SMOOTH_SHORT 3 -#define SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ((Word16)0x2667) -#define SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX ((Word32)0x5B6DB6DB) - /* PLC for DFT Stereo residual */ #define STEREO_DFT_RES_N_PEAKS_MAX 15 /*Maximum number of peaks within residual signal in each frame (res_cod_band_max == 6 in 48kHz)*/ @@ -816,7 +813,6 @@ enum fea_names #define STEREO_BITS_ICBWE_DFT ( STEREO_ICBWE_SPBITS_DFT + STEREO_ICBWE_GSBITS_DFT + STEREO_ICBWE_REFBITS ) #define MAX_DELAYREGLEN 12 /* max regression length */ -#define INV_MAX_DELAYREGLEN 0.083333333333333f /* (1/MAX_DELAYREGLEN) */ #define INV_MAX_DELAYREGLEN_FX_Q15 2731 /* (1/MAX_DELAYREGLEN) in Q15 */ #define MAX_INTERPOLATE 11 #define ADDED_MEM_DS 40 @@ -1264,7 +1260,7 @@ enum #define MASA_BIT_REDUCT_PARAM 10 #define MASA_MAXIMUM_TWO_DIR_BANDS 24 #define NBITS_HR_COH 4 -#define OMASA_TDREND_MATCHING_GAIN_FX 26026 +#define OMASA_TDREND_MATCHING_GAIN_FX 26026 #define OMASA_GAIN_EDIT_THR_Q12 246 /* OMASA gain change threshold, 0.06f in Q12 */ #define OMASA_AZI_EDIT_THR_Q22 ONE_IN_Q22 /* OMASA-DISC azimuth change threshold, 1.0f in Q22 */ @@ -1273,8 +1269,7 @@ enum #define MASA_INV_ANGLE_AT_EQUATOR_DEG_Q30 1453366656l /* 1.353553128183453f in Q30 */ #define MASA_JBM_RINGBUFFER_FRAMES 3 -#define TOLERANCE_360_Q22 1510033326 /* 360 in Q22 + 0.02 in Q22*/ -#define MINUS_TOLERANCE_360_Q22 -1510033326 /* - (360 in Q22 + 0.02 in Q22) */ + typedef enum { MASA_STEREO_NOT_DEFINED, @@ -1357,6 +1352,13 @@ typedef enum #define MCT_NUM_BLOCK_DATA_BITS 4 +typedef enum +{ + MCT_CHAN_MODE_REGULAR, + MCT_CHAN_MODE_LFE, + MCT_CHAN_MODE_IGNORE +} MCT_CHAN_MODE; + /*----------------------------------------------------------------------------------* * MC Param-Upmix Mode Constants @@ -1534,6 +1536,10 @@ typedef enum #define VBAP_NUM_SEARCH_SECTORS 4 +#define DEGREE_90_Q_22 377487360 +#define DEGREE_180_Q_22 754974720 +#define DEGREE_360_Q_22 1509949440 + /*----------------------------------------------------------------------------------* * Binaural Rendering Constants @@ -1591,8 +1597,8 @@ typedef enum #define ONE_BY_360_Q15 ( 91 ) /* Q15 */ #define ONE_BY_180_Q31 ( 11930465 ) /* Q31 */ -#define RESAMPLE_FACTOR_16_48_FX ( 5461 ) // Q14 -#define RESAMPLE_FACTOR_32_48_FX ( 10922 ) // Q14 +#define RESAMPLE_FACTOR_16_48_FX ( 5461 ) // Q14 +#define RESAMPLE_FACTOR_32_48_FX ( 10922 ) // Q14 /* ----- Enums - TD Renderer ----- */ @@ -1837,6 +1843,144 @@ typedef enum } STEREO_DMX_EVS_PRC; + +/*----------------------------------------------------------------------------------* + * Q values + *----------------------------------------------------------------------------------*/ + +#define Q1 1 +#define Q2 2 +#define Q3 3 +#define Q4 4 +#define Q5 5 +#define Q6 6 +#define Q7 7 +#define Q8 8 +#define Q9 9 +#define Q10 10 +#define Q11 11 +#define Q12 12 +#define Q13 13 +#define Q14 14 +#define Q15 15 +#define Q16 16 +#define Q17 17 +#define Q18 18 +#define Q19 19 +#define Q20 20 +#define Q21 21 +#define Q22 22 +#define Q23 23 +#define Q24 24 +#define Q25 25 +#define Q26 26 +#define Q27 27 +#define Q28 28 +#define Q29 29 +#define Q30 30 +#define Q31 31 +#define Q32 32 +#define Q33 33 +#define Q34 34 +#define Q35 35 +#define Q36 36 +#define Q37 37 +#define Q38 38 +#define Q39 39 +#define Q40 40 +#define Q41 41 +#define Q42 42 +#define Q43 43 +#define Q44 44 +#define Q45 45 +#define Q46 46 +#define Q47 47 +#define Q48 48 +#define Q49 49 +#define Q50 50 +#define Q51 51 +#define Q52 52 +#define Q53 53 +#define Q54 54 +#define Q55 55 +#define Q56 56 +#define Q57 57 +#define Q58 58 +#define Q59 59 +#define Q60 60 +#define Q61 61 +#define Q62 62 +#define Q63 63 + +/*----------------------------------------------------------------------------------* + * One (1) in Q + *----------------------------------------------------------------------------------*/ + +#define ONE_IN_Q1 2 +#define ONE_IN_Q2 4 +#define ONE_IN_Q3 8 +#define ONE_IN_Q4 16 +#define ONE_IN_Q5 32 +#define ONE_IN_Q6 64 +#define ONE_IN_Q7 128 +#define ONE_IN_Q8 256 +#define ONE_IN_Q9 512 +#define ONE_IN_Q10 1024 +#define ONE_IN_Q11 2048 +#define ONE_IN_Q12 4096 +#define ONE_IN_Q13 8192 +#define ONE_IN_Q14 16384 +#define ONE_IN_Q15 32768 +#define ONE_IN_Q16 65536 +#define ONE_IN_Q17 131072 +#define ONE_IN_Q18 262144 +#define ONE_IN_Q19 524288 +#define ONE_IN_Q20 1048576 +#define ONE_IN_Q21 2097152 +#define ONE_IN_Q22 4194304 +#define ONE_IN_Q23 8388608 +#define ONE_IN_Q24 16777216 +#define ONE_IN_Q25 33554432 +#define ONE_IN_Q26 67108864 +#define ONE_IN_Q27 134217728 +#define ONE_IN_Q28 268435456 +#define ONE_IN_Q29 536870912 +#define ONE_IN_Q30 1073741824 +#define ONE_IN_Q31 0x7fffffff +#define ONE_IN_Q45 (Word64)0x200000000000 +#define ONE_IN_Q62 (Word64)0x4000000000000000 + +#define MAX_WORD16 32767 + +/*----------------------------------------------------------------------------------* + * General constants + *----------------------------------------------------------------------------------*/ + +#define L_SUBFRAME_48k 240 +#define L_SUBFRAME_32k 160 +#define L_SUBFRAME_16k 80 +#define L_SUBFRAME_8k 40 + +#define Q31_BY_SUB_FRAME_240 8985287 /* 1/239 in Q31 */ +#define Q31_BY_SUB_FRAME_160 13506186 /* 1/159 in Q31 */ +#define Q31_BY_SUB_FRAME_80 27183337 /* 1/79 in Q31 */ +#define Q31_BY_SUB_FRAME_40 55063683 /* 1/39 in Q31 */ + +#define EVS_PI_FX 25736 /* pi in Q13 */ +#define EVS_2PI_FX 51472 /* 2 * pi in Q13 */ +#define EVS_PI_FX_Q27 421657428 /* pi in Q28 */ +#define EVS_2PI_FX_Q27 843314856 /* 2 * pi in Q28 */ +#define EVS_PI_BY_2_FX (Word16)(0x3244)/* Q13 */ + + +#define FS_48K_IN_NS_Q31 103079 +#define FS_32K_IN_NS_Q31 68719 +#define FS_16K_IN_NS_Q31 34360 + +#define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ +#define ONE_BY_TEN_Q15 3277 /* 1/10.f in Q15 */ +#define THREE_Q21 6291456 + #endif /* clang-format on */ /* IVAS_CNST_H */ diff --git a/lib_com/ivas_cov_smooth_fx.c b/lib_com/ivas_cov_smooth_fx.c index 9a8de3c1f055c1e3a119181c3c404a3a903242a7..c81de63477e3f2399f2ad222f2753e89d43dab1a 100644 --- a/lib_com/ivas_cov_smooth_fx.c +++ b/lib_com/ivas_cov_smooth_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,7 @@ #include #include "options.h" -#include "cnst.h" +#include "ivas_cnst.h" #include "wmc_auto.h" #include "prot_fx.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_dirac_com_fx.c b/lib_com/ivas_dirac_com_fx.c index cba992070911995e986aa23a6637d2802d189c5f..cf256b3681fa7f3f4b1b245a1ac1532b9519babf 100644 --- a/lib_com/ivas_dirac_com_fx.c +++ b/lib_com/ivas_dirac_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,11 +33,9 @@ #include #include #include "options.h" -#include #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "prot_fx.h" -#include "cnst.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_entropy_coder_common_fx.c b/lib_com/ivas_entropy_coder_common_fx.c index f52d59859e7833964f125b0837b23a7d18c91dce..0ea623d294e90e12c4a6860ef9bac28ad7ce479f 100644 --- a/lib_com/ivas_entropy_coder_common_fx.c +++ b/lib_com/ivas_entropy_coder_common_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include "options.h" #include "ivas_rom_com.h" -#include "math.h" #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h index 1b69f35efad13bedbc81bbb43ea04dbfca30a4fa..3e965151e154406e658655cfc9494cbd62968347 100644 --- a/lib_com/ivas_error.h +++ b/lib_com/ivas_error.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_error_utils.h b/lib_com/ivas_error_utils.h index 0c3d5ce042d74d7b9ea0c4be32729f5c161889de..791bc458dfd9dbc9fba9986bed8c8c08631f0371 100644 --- a/lib_com/ivas_error_utils.h +++ b/lib_com/ivas_error_utils.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_fb_mixer_fx.c b/lib_com/ivas_fb_mixer_fx.c index c860b354e27a271e5a6384bde2e3e15f9512408e..3f1cb29e59419e072a55f2454f9200b21810036c 100644 --- a/lib_com/ivas_fb_mixer_fx.c +++ b/lib_com/ivas_fb_mixer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,10 +32,8 @@ #include #include -#include #include "options.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_filters_fx.c b/lib_com/ivas_filters_fx.c index 02e7b272a4beb7759335c88421067918f710763f..5f1b1423b93703d585690fa03dd2bec6fb3543a0 100644 --- a/lib_com/ivas_filters_fx.c +++ b/lib_com/ivas_filters_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,13 +38,6 @@ #include "ivas_rom_com.h" #include "ivas_prot_fx.h" -/*------------------------------------------------------------------------------------------* - * Local functions declaration - *------------------------------------------------------------------------------------------*/ - -static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 *pIn_Out_e ); - - /*-----------------------------------------------------------------------------------------* * Function ivas_filters_init() * @@ -71,27 +64,21 @@ void ivas_filters_init_fx( FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->num_e[IVAS_FILTER_STAGE_0][i] = 1; filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN]; - filter_state->den_e[IVAS_FILTER_STAGE_0][i] = 1; move32(); move32(); + filter_state->num_shr[IVAS_FILTER_STAGE_0][i] = Q30 - Q31; + filter_state->den_shr[IVAS_FILTER_STAGE_0][i] = Q30 - Q31; move16(); move16(); } - filter_state->state_fx[0][0] = 0; - filter_state->state_e[0][0] = 0; - filter_state->state_fx[0][1] = 0; - filter_state->state_e[0][1] = 0; - filter_state->state_fx[0][2] = 0; - filter_state->state_e[0][2] = 0; - move32(); - move32(); - move32(); - move16(); - move16(); - move16(); + filter_state->state_fx[IVAS_FILTER_STAGE_0][0] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_0][1] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_0][2] = 0; + move64(); + move64(); + move64(); } ELSE { @@ -100,121 +87,110 @@ void ivas_filters_init_fx( FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { - filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->num_e[IVAS_FILTER_STAGE_0][i] = filt_coeff_e[i]; filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN]; - filter_state->den_e[IVAS_FILTER_STAGE_0][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN]; filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN * 2]; - filter_state->num_e[IVAS_FILTER_STAGE_1][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN * 2]; filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN * 3]; - filter_state->den_e[IVAS_FILTER_STAGE_1][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN * 3]; move32(); move32(); move32(); move32(); + filter_state->num_shr[IVAS_FILTER_STAGE_0][i] = sub( sub( 31, filt_coeff_e[i + 0 * IVAS_BIQUAD_FILT_LEN] ), Q31 ); + filter_state->den_shr[IVAS_FILTER_STAGE_0][i] = sub( sub( 31, filt_coeff_e[i + 1 * IVAS_BIQUAD_FILT_LEN] ), Q31 ); + filter_state->num_shr[IVAS_FILTER_STAGE_1][i] = sub( sub( 31, filt_coeff_e[i + 2 * IVAS_BIQUAD_FILT_LEN] ), Q31 ); + filter_state->den_shr[IVAS_FILTER_STAGE_1][i] = sub( sub( 31, filt_coeff_e[i + 3 * IVAS_BIQUAD_FILT_LEN] ), Q31 ); move16(); move16(); move16(); move16(); } - filter_state->state_fx[0][0] = 0; - filter_state->state_e[0][0] = 0; - filter_state->state_fx[0][1] = 0; - filter_state->state_e[0][1] = 0; - filter_state->state_fx[0][2] = 0; - filter_state->state_e[0][2] = 0; - filter_state->state_fx[1][0] = 0; - filter_state->state_e[1][0] = 0; - filter_state->state_fx[1][1] = 0; - filter_state->state_e[1][1] = 0; - filter_state->state_fx[1][2] = 0; - filter_state->state_e[1][2] = 0; - move32(); - move32(); - move32(); - move32(); - move32(); - move32(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + filter_state->state_fx[IVAS_FILTER_STAGE_0][0] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_0][1] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_0][2] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_1][0] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_1][1] = 0; + filter_state->state_fx[IVAS_FILTER_STAGE_1][2] = 0; + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); } return; } +static Word64 ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, const Word16 stage, const Word64 in ); + +/*-----------------------------------------------------------------------------------------* + * Function ivas_iir_2_filter_fx() + * + * Process call for filtering a sample + *-----------------------------------------------------------------------------------------*/ + +static Word64 ivas_iir_2_filter_fx( + ivas_filters_process_state_t *filter_state, + const Word16 stage, + const Word64 in ) +{ + Word64 tmp_prod, tmp, out; + Word16 j; + + tmp_prod = W_shr( Mpy_64_32( in, filter_state->num_fx[stage][0] ), filter_state->num_shr[stage][0] ); + out = W_add( filter_state->state_fx[stage][0], tmp_prod ); + + FOR( j = 1; j < filter_state->filt_len; j++ ) + { + tmp_prod = W_shr( Mpy_64_32( in, filter_state->num_fx[stage][j] ), filter_state->num_shr[stage][j] ); + tmp = W_add( filter_state->state_fx[stage][j], tmp_prod ); + tmp_prod = W_shr( Mpy_64_32( out, filter_state->den_fx[stage][j] ), filter_state->den_shr[stage][j] ); + filter_state->state_fx[stage][j - 1] = W_sub( tmp, tmp_prod ); + move64(); + } + + return out; +} /*-----------------------------------------------------------------------------------------* - * Function ivas_filter_process() + * Function ivas_filter_process_fx32() * - * Process call for selecting the type filter + * Process call for filtering a signal *-----------------------------------------------------------------------------------------*/ -void ivas_filter_process_fx( +void ivas_filter_process_fx32( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i/o: signal subject to filtering Q(q_factor) */ - const Word16 length, /* i : filter order */ - Word16 q_factor ) + Word32 *pIn_Out_fx, /* i/o: signal subject to filtering */ + const Word16 length ) /* i : number of samples to filter */ { - Word16 pIn_Out_e[L_FRAME_MAX]; + Word64 in, out; Word16 i; SWITCH( filter_state->order ) { case IVAS_FILTER_ORDER_1: - set_val_Word16( pIn_Out_e, sub( Q31, q_factor ), length ); - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, pIn_Out_e ); - /* Scale pIn_Out_fx back to input Q */ FOR( i = 0; i < length; i++ ) { - pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); // Q(31-pIn_Out_e[i]) -> Q(q_factor) + in = W_deposit32_h( pIn_Out_fx[i] ); + + out = ivas_iir_2_filter_fx( filter_state, IVAS_FILTER_STAGE_0, in ); + + pIn_Out_fx[i] = W_extract_h( out ); move32(); } BREAK; case IVAS_FILTER_ORDER_4: - set_val_Word16( pIn_Out_e, sub( Q31, q_factor ), length ); - /* biquad-1 */ - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, pIn_Out_e ); - /* biquad-2 */ - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_1, pIn_Out_e ); - /* Scale pIn_Out_fx back to input Q */ FOR( i = 0; i < length; i++ ) { - pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); // Q(31-pIn_Out_e[i]) -> Q(q_factor) - move32(); - } - BREAK; - default: - BREAK; - } - - return; -} + in = W_deposit32_h( pIn_Out_fx[i] ); + out = ivas_iir_2_filter_fx( filter_state, IVAS_FILTER_STAGE_0, in ); + out = ivas_iir_2_filter_fx( filter_state, IVAS_FILTER_STAGE_1, out ); -void ivas_filter_process_exp_fx( - ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i/o: signal subject to filtering (exp[i] : pIn_out_e[i]) */ - const Word16 length, /* i : filter order */ - Word16 *pIn_Out_e ) -{ - SWITCH( filter_state->order ) - { - case IVAS_FILTER_ORDER_1: - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, pIn_Out_e ); - /* Scale pIn_Out_fx back to input Q */ - BREAK; - case IVAS_FILTER_ORDER_4: - /* biquad-1 */ - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, pIn_Out_e ); - /* biquad-2 */ - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_1, pIn_Out_e ); - /* Scale pIn_Out_fx back to input Q */ + pIn_Out_fx[i] = W_extract_h( out ); + move32(); + } BREAK; default: BREAK; @@ -223,64 +199,50 @@ void ivas_filter_process_exp_fx( return; } - /*-----------------------------------------------------------------------------------------* - * Function ivas_iir_2_filter() + * Function ivas_filter_process_fx64() * * Process call for filtering a signal *-----------------------------------------------------------------------------------------*/ -static void ivas_iir_2_filter_fx( - ivas_filters_process_state_t *filter_state, - Word32 *pIn_Out_fx, // Q(31-*pIn_Out_e) - const Word16 length, - const Word16 stage, - Word16 *pIn_Out_e ) -{ - Word16 i, j; - - Word32 *pIn_fx = pIn_Out_fx; - Word32 *pOut_fx = pIn_Out_fx; - Word32 tmp_pIn_buf_i_fx; - Word16 tmp_pIn_buf_i_e; +void ivas_filter_process_fx64( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + Word64 *pIn_Out_fx, /* i/o: signal subject to filtering */ + const Word16 length ) /* i : number of samples to filter */ - Word32 L_tmp_prod, L_tmp; - Word16 L_prod_e, L_tmp_e; +{ + Word64 in, out; + Word16 i; - FOR( i = 0; i < length; i++ ) + SWITCH( filter_state->order ) { - tmp_pIn_buf_i_fx = pIn_fx[i]; - move32(); - tmp_pIn_buf_i_e = pIn_Out_e[i]; - move16(); - - L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); // Q31 -(pIn_Out_e[i]+ filter_state->num_e[stage][0]) - L_prod_e = add( pIn_Out_e[i], filter_state->num_e[stage][0] ); - - pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pIn_Out_e[i] ); // Q31 - pIn_Out_e[i] - move32(); + case IVAS_FILTER_ORDER_1: + FOR( i = 0; i < length; i++ ) + { + in = pIn_Out_fx[i]; + move64(); - FOR( j = 1; j < filter_state->filt_len; j++ ) - { - L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); // Q31-L_prod_e - L_prod_e = add( filter_state->num_e[stage][j], tmp_pIn_buf_i_e ); + out = ivas_iir_2_filter_fx( filter_state, IVAS_FILTER_STAGE_0, in ); - L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); // Q31 - L_tmp_e + pIn_Out_fx[i] = out; + move64(); + } + BREAK; + case IVAS_FILTER_ORDER_4: + FOR( i = 0; i < length; i++ ) + { + in = pIn_Out_fx[i]; + move64(); - L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); // Q31 - ( pIn_Out_e[i]+filter_state->den_e[stage][j] ) - L_prod_e = add( pIn_Out_e[i], filter_state->den_e[stage][j] ); + out = ivas_iir_2_filter_fx( filter_state, IVAS_FILTER_STAGE_0, in ); + out = ivas_iir_2_filter_fx( filter_state, IVAS_FILTER_STAGE_1, out ); - filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); // Q31 - filter_state->state_e[stage][j - 1] - move32(); - /*In case when exponent is less than -31 the value is very small and negligible hence resetting it to zero to avoid exponent overflow*/ - IF( LT_16( filter_state->state_e[stage][j - 1], -31 ) ) - { - filter_state->state_fx[stage][j - 1] = 0; - move32(); - filter_state->state_e[stage][j - 1] = 0; - move16(); + pIn_Out_fx[i] = out; + move64(); } - } + BREAK; + default: + BREAK; } return; diff --git a/lib_com/ivas_ism_com_fx.c b/lib_com/ivas_ism_com_fx.c index ea276c944920f227648b8d0fccf79076571f0806..840949990c2b2f6bc0f7d32473e1ddcbaf9d5710 100644 --- a/lib_com/ivas_ism_com_fx.c +++ b/lib_com/ivas_ism_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,9 +32,7 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_stat_com.h" #include "ivas_rom_com.h" diff --git a/lib_com/ivas_lfe_com_fx.c b/lib_com/ivas_lfe_com_fx.c index d515cc5fbc77ce306b43d6d8607a430a74c3f5b7..8047af53ffdadaa5bccd8d628cafd75ee6c9c145 100644 --- a/lib_com/ivas_lfe_com_fx.c +++ b/lib_com/ivas_lfe_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,13 +31,11 @@ *******************************************************************************************************/ #include -#include "math.h" #include "options.h" #include "ivas_stat_com.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" -#include "cnst.h" +#include "ivas_cnst.h" #include #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_limiter_fx.c b/lib_com/ivas_limiter_fx.c index a293b629c189f7cedfff46ed6caf5e6b4213873d..0ef37acdf183f0003e78b6adc89735ffbfb83ce7 100644 --- a/lib_com/ivas_limiter_fx.c +++ b/lib_com/ivas_limiter_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,15 +32,17 @@ #include #include "options.h" -#include #include "prot_fx.h" -#include "ivas_prot_rend_fx.h" -#include "ivas_rom_rend.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #include #include "ivas_prot_fx.h" + +/*-----------------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------------*/ + #define RELEASE_CNST_20MS ( 85899345 ) // Q30 #define RELEASE_CNST_2_20MS ( 21474836 ) // Q30 #define RELEASE_CNST_10MS ( 42949672 ) // Q30 @@ -52,6 +54,7 @@ #define ATTACK_CNST_16k ( 2027355264 ) // Q31 #define ATTACK_CNST_8k ( 1913946752 ) // Q31 + /*-------------------------------------------------------------------* * detect_strong_saturations() * diff --git a/lib_com/ivas_masa_com_fx.c b/lib_com/ivas_masa_com_fx.c index 9c706bc74a1dc6bfdeefea66b3835ef25fe0f2bd..eb08f15bb858955b336bdbfea9db609efaf6e9d0 100644 --- a/lib_com/ivas_masa_com_fx.c +++ b/lib_com/ivas_masa_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include #include "options.h" -#include #include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" diff --git a/lib_com/ivas_mc_com_fx.c b/lib_com/ivas_mc_com_fx.c index 8201037a1a5f89eb53acb0e81787b0a87f68da5c..ffb5265541bcf1335433b8f494f2a71e624455c5 100644 --- a/lib_com/ivas_mc_com_fx.c +++ b/lib_com/ivas_mc_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include #include "options.h" -#include #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_mc_param_com_fx.c b/lib_com/ivas_mc_param_com_fx.c index e3827c5685d146777de8975f73bd52b7b5791873..01f8614cdd06d0ee8694db3f10159726a6a1d528 100644 --- a/lib_com/ivas_mc_param_com_fx.c +++ b/lib_com/ivas_mc_param_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include -#include #include "options.h" #include "ivas_cnst.h" #include "prot_fx.h" diff --git a/lib_com/ivas_mcmasa_com_fx.c b/lib_com/ivas_mcmasa_com_fx.c index 23a3800fb792ba9eeee06ef4cd26001a9b54d5e6..b611b1290aa14eef36fd09e95e27a4e9ea8b3e98 100644 --- a/lib_com/ivas_mcmasa_com_fx.c +++ b/lib_com/ivas_mcmasa_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_mct_com_fx.c b/lib_com/ivas_mct_com_fx.c index 81a56df146d9ba7378dbcadacb6aeb39b98f28b0..bcfada29e48fc0ef926997cc6f40b06b6ed40ef1 100644 --- a/lib_com/ivas_mct_com_fx.c +++ b/lib_com/ivas_mct_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_mdct_core_com_fx.c b/lib_com/ivas_mdct_core_com_fx.c index fe313eecdd7c3be915f9d9aa73c37081e79b61ac..ec623fbf1512b3914acf31aa8606c4fa9a15c1aa 100644 --- a/lib_com/ivas_mdct_core_com_fx.c +++ b/lib_com/ivas_mdct_core_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index 960b823ae605a2c890c6b77a3e305039fe0af208..fde3edaddd34d6fd40aa67a67ff0d726193d3b5e 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_mdft_imdft_fx.c b/lib_com/ivas_mdft_imdft_fx.c index 1d07ab13356e8b5b418e841bd302a6dd002df1dd..49d1cbbf11c01d8bd02dd538abad93162ee0fab9 100644 --- a/lib_com/ivas_mdft_imdft_fx.c +++ b/lib_com/ivas_mdft_imdft_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -29,19 +29,20 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ -#include +#include #include #include "options.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include #include "wmc_auto.h" -#include -#include +#ifdef DEBUGGING #include "debug.h" +#endif #include "ivas_prot_fx.h" + /*-----------------------------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------------------------*/ @@ -52,6 +53,7 @@ #define IVAS_ONE_BY_240_Q37 572662306 #define IVAS_ONE_BY_160_Q37 858993459 #define IVAS_ONE_BY_80_Q37 1717986918 + /*-----------------------------------------------------------------------------------------* * Function ivas_get_mdft_twid_factors() * diff --git a/lib_com/ivas_omasa_com_fx.c b/lib_com/ivas_omasa_com_fx.c index 1c1d4bf6cb6ca87def78b29f60c793547d2f3e4d..e5986879b9525a064a1fbf6225d475feaf3e7c74 100644 --- a/lib_com/ivas_omasa_com_fx.c +++ b/lib_com/ivas_omasa_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,7 +37,7 @@ #include "prot_fx.h" #include "ivas_rom_com.h" #include "rom_com.h" -#include + /*--------------------------------------------------------------- * Local constants diff --git a/lib_com/ivas_osba_com_fx.c b/lib_com/ivas_osba_com_fx.c index 79ce8443ace24e625bd32134f6817c56bd34b78c..5527f53898e41e5fbc4f8f70638a81df90912404 100644 --- a/lib_com/ivas_osba_com_fx.c +++ b/lib_com/ivas_osba_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include "options.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" -#include "prot_fx.h" -#include "ivas_rom_com.h" #ifdef DEBUGGING #include "debug.h" #endif diff --git a/lib_com/ivas_pca_tools_fx.c b/lib_com/ivas_pca_tools_fx.c index e0d42e4040cd90a6dc4f59c0d193d7c2d6d1022a..4669b86a36742dc5e4850cd869503be72e2b9867 100644 --- a/lib_com/ivas_pca_tools_fx.c +++ b/lib_com/ivas_pca_tools_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include "options.h" #include "ivas_cnst.h" -#include #include #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -1376,7 +1375,7 @@ void pca_enc_s3_fx( q_ang_2surv_fx( ph1_fx, n1, ph1_q_fx, ind1 ); - tmp = add( add( mult( q_fx[1], q_fx[1] ), mult( q_fx[2], q_fx[2] ) ), mult( q_fx[3], q_fx[3] ) ); // Q15 + Q15 - Q15 -> Q15 + tmp = mac_r( L_mac( L_mult( q_fx[1], q_fx[1] ), q_fx[2], q_fx[2] ), q_fx[3], q_fx[3] ); // Q15 + Q15 - Q15 -> Q15 r_e = 0; move16(); r_fx = Sqrt16( tmp, &r_e ); @@ -1430,8 +1429,7 @@ void pca_enc_s3_fx( q_ang_2surv_fx( ph2_fx, n2[i], ph2_q_fx + 2 * i, ind2 + 2 * i ); } - r_fx = Sqrt16( add( mult( q_fx[2], q_fx[2] ), mult( q_fx[3], q_fx[3] ) ), &r_e ); - + r_fx = Sqrt16( mac_r( L_mult( q_fx[2], q_fx[2] ), q_fx[3], q_fx[3] ), &r_e ); v_fx = BASOP_Util_Divide1616_Scale( q_fx[2], r_fx, &v_e ); v_e = add( v_e, sub( 0, r_e ) ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index def4c806b0c503d9d922a5721a416b32e19b959d..d87207a908def528694a9b3dc597f32dd6e43f2a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -622,12 +622,6 @@ void ivas_dirac_dec_set_md_map_fx( const Word16 nCldfbTs /* i : number of CLDFB time slots */ ); -void ivas_jbm_dec_get_adapted_subframes_fx( - const Word16 nCldfbTs, /* i : number of time slots in the current frame */ - Word16 *subframe_nbslots, /* i/o: subframe grid */ - Word16 *nb_subframes /* i/o: number of subframes in the frame */ -); - /*! r: number of bits read */ Word16 read_GR0( const UWord16 *bit_stream, /* i : bitstream to be read */ @@ -1039,7 +1033,7 @@ void ivas_ism_render_sf_fx( const Word16 n_samples_to_render /* i : output frame length per channel */ ); -void ivas_omasa_separate_object_render_jbm_fx( +void ivas_omasa_separate_object_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 nSamplesRendered, /* i : number of samples rendered */ Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal */ @@ -1363,13 +1357,12 @@ void stereo_tcx_init_dec_fx( const Word16 last_element_mode /* i : element mode of previous frame */ ); -void stereo_icBWE_enc_ivas_fx( +void stereo_icBWE_enc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 shb_speech_ref_fx[], /* i : SHB speech ref channel */ - const Word16 shb_speech_ref_e, /* i : SHB speech ref channel */ - Word32 shb_speech_nonref_fx[], /* i/o: SHB speech non-ref channel */ + const Word16 shb_speech_ref_fx16[], /* i : SHB speech ref channel Q0*/ + Word16 shb_speech_nonref_fx_16[], /* i/o: SHB speech non-ref channel shb_speech_nonref_e*/ Word16 shb_speech_nonref_e, /* i/o: SHB speech non-ref channel */ - const Word32 *voice_factors_fx /* i : voicing factors Q31 */ + const Word16 *voice_factors_fx /* i : voicing factors Q15 */ ); void initMdctStereoDecData_fx( @@ -1576,8 +1569,7 @@ void decoder_tcx_imdct_fx( void ivas_sba_dirac_stereo_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 mcmasa /* i : McMASA flag */ + const Word16 output_frame /* i : output frame length per channel */ ); ivas_error ivas_osba_render_sf_fx( @@ -1595,10 +1587,15 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length */ const Word16 hq_core_type, /* i : HQ core type */ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ +#else Word16 output[], Word16 *Q_output +#endif ); +#ifndef HARMONIZE_TBE void ivas_HQ_FEC_Mem_update_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 *t_audio_q_fx, /*Q12*/ @@ -1614,7 +1611,7 @@ void ivas_HQ_FEC_Mem_update_fx( Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ Word16 output_frame ); - +#endif /* o : Consumed bits Q0 */ Word16 ivas_hq_classifier_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -1864,6 +1861,7 @@ void stereoFdCngCoherence_fx( Word16 fft_exp ); +#ifndef HARMONIZE_TBE void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -1884,6 +1882,7 @@ void GenShapedWBExcitation_ivas_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ @@ -1891,11 +1890,15 @@ void GenShapedWBExcitation_ivas_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); - +#endif /* o : Q_syn_hb*/ Word16 ivas_wb_bwe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + #endif Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ @@ -1990,15 +1993,6 @@ ivas_error stereo_memory_dec_fx( const Word16 nchan_transport /* i : number of transport channels */ ); -void initFdCngDec_ivas_fx( - DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale -); - -void ivas_initFdCngCom_fx( - HANDLE_FD_CNG_COM hFdCngCom, Word16 scale -); - Word16 set_ACELP_flag_IVAS( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ @@ -2067,24 +2061,46 @@ UWord32 ivas_syn_output_fx( Word16 *synth_out /* o : integer 16 bits synthesis signal */ ); +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER +void ivas_buffer_interleaved_to_deinterleaved_fx( + Word32 *audio_in, /* i : interleaved audio buffer */ + Word32 *audio_out[], /* o : pointers to each channel of deinterleaved audio buffer */ + const Word16 n_channels, /* i : number of channels */ + const Word16 frame_length /* i : frame length (one channel) */ +); +#else void ivas_buffer_interleaved_to_deinterleaved_fx( Word32 *audio, /* i/o: audio buffer */ const Word16 n_channels, /* i : number of channels */ const Word16 frame_length, /* i : frame length (one channel) */ const Word16 n_samp_full /* i : full frame length (one channel) */ ); +#endif +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER +void ivas_buffer_deinterleaved_to_interleaved_fx( + Word32 *audio_in[], /* i : pointers to each channel of deinterleaved audio buffer */ + Word32 *audio_out, /* o : interleaved audio buffer */ + const Word16 n_channels, /* i : number of channels */ + const Word16 frame_length /* i : frame length (one channel) */ +); +#else void ivas_buffer_deinterleaved_to_interleaved_fx( Word32 *audio[], /* i : deinterleaved audio buffer */ const Word16 n_channels, /* i : number of channels */ const Word16 frame_length, /* i : frame length (one channel) */ Word32 *audio_out /* o : interleaved audio buffer */ ); +#endif void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11 */ +#else Word16 *signal_out, /* o : synthesis @internal_Fs, Q0 */ +#endif Word16 *signal_outFB, /* o : synthesis @output_Fs, Q0 */ Word16 pitch_buf[], /* o : floating pitch for each subframe, Q6 */ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ @@ -2455,7 +2471,7 @@ void ivas_fb_mixer_cross_fading_fx( const Word16 cf_offset ); -ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( +ivas_error ivas_omasa_dirac_td_binaural_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of samples requested */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ @@ -2492,7 +2508,7 @@ void ivas_sba_get_spar_hoa_md_flag_fx( Word16 *spar_hoa_dirac2spar_md_flag ); -void ivas_omasa_dirac_rend_jbm_fx( +void ivas_omasa_dirac_rend_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of samples requested */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ @@ -2977,17 +2993,6 @@ void stereo_icBWE_preproc_fx( Word16 shb_speech_nonref[], /* o : SHB speech non-ref channel */ Word16 q_shb_speech_nonref /* i : Q SHB speech non-ref channel */ ); - -void core_switching_pre_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ - const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ - const Word16 *old_inp_16k, /* i : old input signal @16kHz */ - const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ - const Word16 active_cnt, /* i : active frame counter */ - const Word16 last_element_mode /* i : last_element_mode */ -); - Word16 ivas_acelp_tcx20_switching_fx( Encoder_State *st, /* i/o: encoder state structure */ Word16 *inp_fx, /* i : new input signal */ @@ -3004,7 +3009,7 @@ Word16 ivas_acelp_tcx20_switching_fx( const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); -void encod_gen_2sbfr( +void encod_gen_2sbfr_fx( Encoder_State *st, /* i/o: state structure */ const Word16 speech[], /* i : input speech */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ @@ -3018,8 +3023,8 @@ void encod_gen_2sbfr( Word16 *bwe_exc, /* o : excitation for SWB TBE */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : pitch values for primary channel */ - Word16 Q_new, - Word16 shift + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ ); void acelp_fast_fx( @@ -3802,20 +3807,17 @@ void ivas_lfe_enc_fx( BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ); -void ivas_filter_process_fx( +void ivas_filter_process_fx32( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ Word32 *pIn_Out_fx, /* i : signal subject to filtering */ - const Word16 length, /* i : filter order */ - Word16 q_factor + const Word16 length /* i : number of samples to filter */ ); -void ivas_filter_process_exp_fx( +void ivas_filter_process_fx64( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i/o: signal subject to filtering (exp[i] : pIn_out_e[i]) */ - const Word16 length, /* i : filter order */ - Word16 *pIn_Out_e + Word64 *pIn_Out_fx, /* i : signal subject to filtering */ + const Word16 length /* i : number of samples to filter */ ); - ivas_error ivas_osba_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); @@ -3841,7 +3843,7 @@ ivas_error ivas_osba_data_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); -ivas_error ivas_osba_dirac_td_binaural_jbm_fx( +ivas_error ivas_osba_dirac_td_binaural_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ @@ -4268,8 +4270,7 @@ void ivas_ism_coh_estim_dtx_enc_fx( void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ const Word16 sce_id_dtx, /* i : SCE DTX ID */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *Q_cngNoiseLevel + const Word16 nchan_transport /* i : number of transport channels */ ); ivas_error stereo_dft_enc_create_fx( @@ -4484,7 +4485,7 @@ ivas_error signaling_enc_secondary_fx( const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag */ ); -void tdm_low_rate_enc( +void tdm_low_rate_enc_fx( Encoder_State *st, /* i/o: State structure */ const Word16 Aq[], /* i : 12k8 Lp coefficient */ const Word16 *res, /* i : residual signal Q_new*/ @@ -4495,8 +4496,8 @@ void tdm_low_rate_enc( Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ const Word16 attack_flag, /* i : attack flag */ const Word16 *lsf_new, /* i : current frame ISF vector x2.56 */ - Word16 *tmp_noise, /* o : long-term noise energy Q8 */ - Word16 Q_new + Word16 *tmp_noise, /* o : long-term noise energy Q8 */ + const Word16 Q_new /* i : Scaling factor */ ); void tdm_low_rate_dec_fx( @@ -5849,7 +5850,7 @@ ivas_error ivas_mct_enc_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ); -ivas_error ivas_compute_core_buffers_fx( +void ivas_compute_core_buffers_fx( Encoder_State *st, /* i/o: encoder state structure */ Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame */ Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz */ @@ -5863,17 +5864,11 @@ ivas_error ivas_compute_core_buffers_fx( Word32 epsP[M + 1], /* i/o: LP prediction errors */ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ - Word16 Q_old_inp_16k, + const Word16 Q_old_inp_16k, Word16 Q_r[2], Word16 *Q_new ); -ivas_error ivas_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 *data, /* i : input signal Q0 */ - const Word16 n_samples /* i : number of input samples */ -); - void reset_metadata_spatial_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -5924,6 +5919,24 @@ void modify_Rmat_q_fx( * General IVAS prototypes *----------------------------------------------------------------------------------*/ +ivas_error ivas_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 *data, /* i : input signal Q0 */ + const Word16 n_samples /* i : number of input samples */ +); + +ivas_error ivas_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of samples wanted */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ + Word16 *data /* o : output synthesis signal */ +); + void copy_encoder_config_ivas_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ @@ -5942,67 +5955,63 @@ void ivas_mct_enc_close_fx( MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ); -ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ - const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - const Word16 n, /* i : channel number Q0*/ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1*/ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ - Word16 *relE_fx, /* o : frame relative energy Q8*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ - Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ - Word16 *epsP_fx_q, - Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ - Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ - Word16 *attack_flag, /* o : flag signaling attack Q0*/ - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ - Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ - Word16 *q_old_wsp, - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ - Word16 *loc_harm, /* o : harmonicity flag Q0*/ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ - const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ - Word16 fr_bands_LR_fx_q[CPE_CHANNELS], - const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ - Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ - Word16 lf_E_LR_fx_q, - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ - Word16 band_energies_LR_fx_q, - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ - const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ - const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ - Word16 *Q_new -#ifdef DEBUG_MODE_INFO - , - const Word16 ch_idx -#endif -); - -ivas_error pre_proc_ivas_fx( +void pre_proc_front_ivas_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* o : Q factor of LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, /* o : Q factor of weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands fr_bands_LR_fx_q*/ + Word16 fr_bands_LR_fx_q[CPE_CHANNELS], /* i : Q factors of energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels lf_E_LR_fx_q*/ + const Word16 lf_E_LR_fx_q, /* i : Q factor of per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN band_energies_LR_fx_q*/ + const Word16 band_energies_LR_fx_q, /* o : Q factors of energy in critical bands without minimum noise floor */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ + Word16 *Q_new /* i/o : Q factor of speech buffers */ +); + +void pre_proc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 last_element_mode, /* i : last element mode Q0*/ const Word32 element_brate, /* i : element bitrate Q0*/ @@ -6021,17 +6030,17 @@ ivas_error pre_proc_ivas_fx( Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ - Word16 e_old_wsp, + const Word16 e_old_wsp, /* i : Q value of weighted input signal buffer */ const Word16 loc_harm, /* i : harmonicity flag Q0*/ const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ - Word16 e_enerBuffer, - Word16 fft_buff_fx[2 * L_FFT], /* Qx */ - Word16 cor_map_sum_fx, /* Q8 */ - Word16 *Q_new + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer e_enerBuffer */ + const Word16 e_enerBuffer, /* i : Q value of energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 cor_map_sum_fx, /* i : speech/music clasif. parameter Q8*/ + Word16 *Q_new /* i/o: Q factor of speech buffers */ ); void ivas_initialize_handles_enc_fx( @@ -6129,21 +6138,9 @@ Word16 is_DTXrate( /*----------------------------------------------------------------------------------* - * JBM prototypes + * Internal rendering prototypes *----------------------------------------------------------------------------------*/ -ivas_error ivas_jbm_dec_tc_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); - -ivas_error ivas_jbm_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 nSamplesAsked, /* i : number of samples wanted */ - UWord16 *nSamplesRendered, /* o : number of samples rendered */ - UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - Word16 *data /* o : output synthesis signal */ -); - ivas_error ivas_jbm_dec_flush_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 tc_granularity_new, /* i : new renderer granularity */ @@ -6156,7 +6153,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( Word16 *data /* o : output synthesis signal */ ); -void ivas_jbm_dec_feed_tc_to_renderer_fx( +void ivas_dec_feed_tc_to_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ Word16 *nSamplesResidual /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ @@ -6170,80 +6167,80 @@ ivas_error ivas_jbm_dec_set_discard_samples_fx( Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ ); -void ivas_jbm_dec_get_adapted_linear_interpolator_fx( +void ivas_dec_get_adapted_linear_interpolator_fx( const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ const Word16 interp_length, /* i : length of the interpolator to be created */ Word16 *interpolator_fx /* o : the interpolator */ ); -void ivas_jbm_dec_get_adapted_subframes( +void ivas_dec_get_adapted_subframes_fx( const Word16 nCldfbTs, /* i : number of time slots in the current frame */ Word16 *subframe_nbslots, /* i/o: subframe grid */ Word16 *nb_subframes /* i/o: number of subframes in the frame */ ); -void ivas_jbm_dec_get_md_map( +void ivas_dec_get_md_map_fx( const Word16 default_len, /* i : default frame length in metadata slots */ const Word16 len, /* i : length of the modfied frames in metadata slots */ const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ + const Word16 offset, /* i : current read offset into the MD buffer */ const Word16 buf_len, /* i : length of the metadata buffer */ Word16 *map /* o : metadata index map */ ); -Word16 ivas_jbm_dec_get_num_tc_channels_fx( +Word16 ivas_dec_get_num_tc_channels_fx( Decoder_Struct *st_ivas /* i : IVAS decoder handle */ ); -void ivas_jbm_dec_get_md_map_even_spacing( +void ivas_dec_get_md_map_even_spacing_fx( const Word16 len, /* i : length of the modfied frames in metadata slots */ const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ + const Word16 offset, /* i : current read offset into the MD buffer */ const Word16 buf_len, /* i : length of the metadata buffer */ Word16 *map /* o : metadata index map */ ); -TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode_fx( +TC_BUFFER_MODE ivas_dec_get_tc_buffer_mode_fx( Decoder_Struct *st_ivas /* i : IVAS decoder handle */ ); -Word16 ivas_jbm_dec_get_render_granularity_fx( +Word16 ivas_dec_get_render_granularity_fx( const RENDERER_TYPE renderer_type, /* i : renderer type */ const RENDERER_TYPE renderer_type_sec, /* i : secondary renderer type */ const Word32 output_Fs /* i : sampling rate */ ); -ivas_error ivas_jbm_dec_tc_buffer_open_fx( +ivas_error ivas_dec_tc_buffer_open_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ - const Word16 nchan_transport_jbm, /* i : number of real transport channels */ + const Word16 nchan_transport_rend, /* i : number of TCs for rendering */ const Word16 nchan_transport_internal, /* i : number of totally buffered channels */ const Word16 nchan_full, /* i : number of channels to fully store */ const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ); -ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( +ivas_error ivas_dec_tc_buffer_reconfigure_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ - const Word16 nchan_transport_jbm, /* i : new number of real transport channels */ + const Word16 nchan_transport_rend, /* i : new number of TCs for rendering */ const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */ const Word16 nchan_full, /* i : new number of channels to fully store */ const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */ ); -void ivas_jbm_dec_tc_buffer_close_fx( +void ivas_dec_tc_buffer_close_fx( DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */ ); -void ivas_jbm_dec_td_renderers_adapt_subframes( +void ivas_dec_td_renderers_adapt_subframes_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -ivas_error ivas_jbm_dec_metadata_open( +ivas_error ivas_jbm_dec_masa_metadata_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void ivas_jbm_masa_sf_to_sf_map( +void ivas_jbm_masa_sf_to_sf_map_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -6405,7 +6402,7 @@ UWord16 get_indice_st( void stereo_mdct_core_enc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples Q0*/ + Word16 new_samples[CPE_CHANNELS][L_INP], /* i : new samples Qnew-1*/ Word16 old_wsp[CPE_CHANNELS][L_WSP], /* i : 12.8kHz weighted speech (for LTP Qx*/ Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k] /* o : floating pitch for each subframe Q6*/ ); @@ -6804,18 +6801,12 @@ void ivas_filters_init_fx( const Word16 order ); -void ivas_filter_process_fx( - ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ - Word32 *pIn_Out_fx, /* i/o: signal subject to filtering Q(q_factor) */ - const Word16 length, /* i : filter order */ - Word16 q_factor -); /*----------------------------------------------------------------------------------* * OSBA prototypes *----------------------------------------------------------------------------------*/ -ivas_error ivas_osba_enc_reconfig( +ivas_error ivas_osba_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -6832,11 +6823,11 @@ void ivas_set_surplus_brate_dec( Word32 *ism_total_brate /* i : ISM total bitrate */ ); -ivas_error ivas_omasa_separate_object_renderer_open( +ivas_error ivas_omasa_separate_object_renderer_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void ivas_omasa_separate_object_renderer_close( +void ivas_omasa_separate_object_renderer_close_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); diff --git a/lib_com/ivas_qmetadata_com_fx.c b/lib_com/ivas_qmetadata_com_fx.c index 906277f54294d732a576187b64c798e8e375c836..93c3bd806f4cb58668a58882e92fc47173745258 100644 --- a/lib_com/ivas_qmetadata_com_fx.c +++ b/lib_com/ivas_qmetadata_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,12 +32,10 @@ #include #include -#include #include "options.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "prot_fx.h" -#include "cnst.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_qspherical_com_fx.c b/lib_com/ivas_qspherical_com_fx.c index 7d7c159b365ed4e89520a51b472381c25d7b7c8a..2a0e7797c27c0c282680a748e86a4624ac910a38 100644 --- a/lib_com/ivas_qspherical_com_fx.c +++ b/lib_com/ivas_qspherical_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,11 +33,9 @@ #include #include #include "options.h" -#include #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "prot_fx.h" -#include "cnst.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 092bc8df5385e897d625a28fe8b28d19c91f298b..6081e450affc3b2e778d31e2a3e89cbf9c2d220d 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "stat_com.h" #include "ivas_stat_com.h" diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 3878adfeae4a4cbd7c1bf04ff490a8f859a1704a..4ef543df7eac85d5479913267c65404b9e25d60b 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include "options.h" #include -#include "cnst.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" diff --git a/lib_com/ivas_rotation_com_fx.c b/lib_com/ivas_rotation_com_fx.c index d399c6a660e352ebd6ad625d8d13753c88d432a0..5fc6261a955b8f0fbee67a48d693230994521342 100644 --- a/lib_com/ivas_rotation_com_fx.c +++ b/lib_com/ivas_rotation_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,8 +34,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #ifdef DEBUGGING @@ -46,11 +44,19 @@ #include "enh64.h" +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define DEGREE_180 ( Word32 )( 180.0 * ONE_IN_Q22 ) +#define DEGREE_360 ( Word32 )( 360.0 * ONE_IN_Q22 ) + /*------------------------------------------------------------------------- * Euler2Quat() * * Calculate corresponding Quaternion from Euler angles in radians *------------------------------------------------------------------------*/ + void Euler2Quat_fx( const Word32 yaw, /* i : yaw (x) Q22 */ const Word32 pitch, /* i : pitch (y) Q22 */ @@ -107,7 +113,7 @@ void Copy_Quat_fx( /*------------------------------------------------------------------------- - * Scale_Quat_fx() + * modify_Quat_q_fx() * * Quaternion q factor modification *------------------------------------------------------------------------*/ @@ -118,10 +124,18 @@ void modify_Quat_q_fx( Word16 q_new /* i : quaternion describing the rotation */ ) { +#ifdef FIX_BASOP_2361_OTR + Word16 shift = sub( q_new, in_quat->q_fact ); + out_quat->w_fx = L_shl_sat( in_quat->w_fx, shift ); // q_new + out_quat->x_fx = L_shl_sat( in_quat->x_fx, shift ); // q_new + out_quat->y_fx = L_shl_sat( in_quat->y_fx, shift ); // q_new + out_quat->z_fx = L_shl_sat( in_quat->z_fx, shift ); // q_new +#else out_quat->w_fx = L_shl_sat( in_quat->w_fx, sub( q_new, in_quat->q_fact ) ); // q_new out_quat->x_fx = L_shl_sat( in_quat->x_fx, sub( q_new, in_quat->q_fact ) ); // q_new out_quat->y_fx = L_shl_sat( in_quat->y_fx, sub( q_new, in_quat->q_fact ) ); // q_new out_quat->z_fx = L_shl_sat( in_quat->z_fx, sub( q_new, in_quat->q_fact ) ); // q_new +#endif out_quat->q_fact = q_new; return; } @@ -141,12 +155,19 @@ void modify_Rmat_q_fx( ) { Word16 j, k; +#ifdef FIX_BASOP_2361_OTR + Word16 shift = sub( q_new, q_cur ); +#endif FOR( j = 0; j < 3; j++ ) { FOR( k = 0; k < 3; k++ ) { +#ifdef FIX_BASOP_2361_OTR + Rmat_out[j][k] = L_shl( Rmat_in[j][k], shift ); +#else Rmat_out[j][k] = L_shl( Rmat_in[j][k], sub( q_new, q_cur ) ); +#endif move32(); } } @@ -194,7 +215,7 @@ void Quat2EulerDegree_fx( Word32 tmp8 = W_extract_l( W_shr( W_mult0_32_32( quat.w_fx, quat.y_fx ), Q22 ) ); // Q22 Word32 tmp9 = W_extract_l( W_shr( W_mult0_32_32( quat.z_fx, quat.x_fx ), Q22 ) ); // Q22 p_fx = L_shl( L_sub( tmp8, tmp9 ), 1 ); - p_fx = max( L_negate( ONE_IN_Q22 ), min( ONE_IN_Q22, p_fx ) ); // Q22 + p_fx = L_max( L_negate( ONE_IN_Q22 ), L_min( ONE_IN_Q22, p_fx ) ); // Q22 Word32 p_fx_sq = W_extract_l( W_shr( W_mult0_32_32( p_fx, p_fx ), Q22 ) ); Word16 res_exp = 0; diff --git a/lib_com/ivas_sba_config_fx.c b/lib_com/ivas_sba_config_fx.c index 4caa22da2a0b258d80f3dcc3068db56af2c80911..2658644cccfbd82d4c43785bdb980684baebae4b 100644 --- a/lib_com/ivas_sba_config_fx.c +++ b/lib_com/ivas_sba_config_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,11 +32,8 @@ #include #include -#include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_stat_com.h" #include "ivas_rom_com.h" diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index 48be0cfd083000e5f134b7d50633a61a12d5ab67..652b095c10d9b7541808914c6b338ca3b84cd1d5 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,15 +32,15 @@ #include #include "options.h" -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" #include "rom_com.h" #include "ivas_rom_com.h" -#include #include #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*------------------------------------------------------------------- * sns_compute_scf_fx() * diff --git a/lib_com/ivas_spar_com_fx.c b/lib_com/ivas_spar_com_fx.c index afb639ef00c92528308d8e5ceabf7085007fd8c4..4733e4fa086c6a370344255238982d9180b38088 100644 --- a/lib_com/ivas_spar_com_fx.c +++ b/lib_com/ivas_spar_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,14 +31,12 @@ *******************************************************************************************************/ #include -#include "math.h" #include "options.h" #include "basop_util.h" #include "ivas_stat_com.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" -#include "cnst.h" +#include "ivas_cnst.h" #include #include "wmc_auto.h" #include "basop_util.h" @@ -3845,7 +3843,8 @@ void ivas_get_spar_md_from_dirac_enc_fx( Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word16 q_ppMixer_mat = 0; - Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; + Word32 en_ratio_fac_fx; + Word16 diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; Word16 active_w; move16(); move16(); @@ -3864,11 +3863,11 @@ void ivas_get_spar_md_from_dirac_enc_fx( foa_ch = FOA_CHANNELS; move16(); diff_norm_order1_fx = 3; - move32(); + move16(); diff_norm_order2_fx = 5; - move32(); + move16(); diff_norm_order3_fx = 7; - move32(); + move16(); FOR( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) { @@ -3900,7 +3899,7 @@ void ivas_get_spar_md_from_dirac_enc_fx( P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[s_min( diff_norm_order1_fx, s_max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[1] = 0; @@ -3911,7 +3910,7 @@ void ivas_get_spar_md_from_dirac_enc_fx( P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[s_min( diff_norm_order2_fx, s_max( 0, ( s_min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[2] = 0; @@ -3921,7 +3920,7 @@ void ivas_get_spar_md_from_dirac_enc_fx( P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[s_min( diff_norm_order3_fx, s_max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 move32(); len = s_max( 0, sub( foa_ch, ndm ) ); FOR( i = 0; i < len; i++ ) // i < max( 0, ( foa_ch - ndm ) ) @@ -4293,7 +4292,8 @@ void ivas_get_spar_md_from_dirac_fx( Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word16 q_ppMixer_mat = 0; - Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; + Word32 en_ratio_fac_fx; + Word16 diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; Word16 active_w; move16(); move16(); @@ -4312,11 +4312,11 @@ void ivas_get_spar_md_from_dirac_fx( foa_ch = FOA_CHANNELS; move16(); diff_norm_order1_fx = 3; - move32(); + move16(); diff_norm_order2_fx = 5; - move32(); + move16(); diff_norm_order3_fx = 7; - move32(); + move16(); FOR( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) { @@ -4348,7 +4348,7 @@ void ivas_get_spar_md_from_dirac_fx( P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[s_min( diff_norm_order1_fx, s_max( 0, sub( foa_ch, ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[1] = 0; @@ -4359,7 +4359,7 @@ void ivas_get_spar_md_from_dirac_fx( P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[s_min( diff_norm_order2_fx, s_max( 0, ( s_min( num_ch, hoa2_ch ) - ndm ) ) )] ); // 2*q_P_re - 31 move32(); P_norm_fx[2] = 0; @@ -4369,7 +4369,7 @@ void ivas_get_spar_md_from_dirac_fx( P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ) ); // 2*q_P_re - 31 move32(); } - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[s_min( diff_norm_order3_fx, s_max( 0, ( num_ch - ndm ) ) )] ); // 2*q_P_re - 31 move32(); len = s_max( 0, sub( foa_ch, ndm ) ); FOR( i = 0; i < len; i++ ) // i < max( 0, ( foa_ch - ndm ) ) diff --git a/lib_com/ivas_spar_com_quant_util_fx.c b/lib_com/ivas_spar_com_quant_util_fx.c index 8e84e4e374273d2b97988a01283fac18405d859d..50820e240f241b69348a9e1d683e943dc218b542 100644 --- a/lib_com/ivas_spar_com_quant_util_fx.c +++ b/lib_com/ivas_spar_com_quant_util_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include "math.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include @@ -347,11 +346,11 @@ void ivas_map_prior_coeffs_quant( { ivas_quant_strat_t qs = pSpar_md_cfg->quant_strat[qsi]; ivas_quant_strat_t prev_qs = pSpar_md_cfg->quant_strat[pSpar_md_cfg->prev_quant_idx]; - Word32 one_by_q_lvl_PR_fx = one_by_q_level[max( ( prev_qs.PR.q_levels[0] - 1 ), 1 )]; /*q31*/ + Word32 one_by_q_lvl_PR_fx = one_by_q_level[s_max( ( prev_qs.PR.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_C_fx = one_by_q_level[max( ( prev_qs.C.q_levels[0] - 1 ), 1 )]; /*q31*/ + Word32 one_by_q_lvl_C_fx = one_by_q_level[s_max( ( prev_qs.C.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_P_r_fx = one_by_q_level[max( ( prev_qs.P_r.q_levels[0] - 1 ), 1 )]; /*q31*/ + Word32 one_by_q_lvl_P_r_fx = one_by_q_level[s_max( ( prev_qs.P_r.q_levels[0] - 1 ), 1 )]; /*q31*/ move32(); FOR( i = 0; i < nB; i++ ) { diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 65a081c9c9884c49cda797f81a9889a55959c056..d3737fa1924f76dc7eee101a09fc2c51a8fba7e7 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include #include "options.h" #include "typedef.h" -#include "cnst.h" #include "ivas_cnst.h" @@ -656,10 +655,9 @@ typedef struct ivas_filters_process_state_t Word16 filt_len; Word32 num_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; Word32 den_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - Word32 state_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - Word16 num_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - Word16 den_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - Word16 state_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word64 state_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word16 num_shr[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word16 den_shr[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; } ivas_filters_process_state_t; diff --git a/lib_com/ivas_stereo_dft_com_fx.c b/lib_com/ivas_stereo_dft_com_fx.c index 6d63bc6d1565160d0a3a3edb4f84b812077e882e..c85ccf53f0b1160264330c4e42698402baa57996 100644 --- a/lib_com/ivas_stereo_dft_com_fx.c +++ b/lib_com/ivas_stereo_dft_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "prot_fx.h" -#include "cnst.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c index 958781473910ff0f164ad50b9eb076fd3e0796e3..7d528f5b92207df25c3cc90272dd68e3eca57680 100644 --- a/lib_com/ivas_stereo_eclvq_com_fx.c +++ b/lib_com/ivas_stereo_eclvq_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,13 +32,13 @@ #include #include "options.h" -#include #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include #include "prot_fx.h" #include "wmc_auto.h" + /*--------------------------------------------------------------- * ECSQ_init_instance_fx() * diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index 11f16d0a5fde3f8b3f14e48230b90860028650ce..705c1756d66f540acf9149f56233e2443dc81a47 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,16 +32,14 @@ #include #include -#include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_prot_fx.h" + /*--------------------------------------------------------------- * interpTargetChannel_fx() * diff --git a/lib_com/ivas_stereo_mdct_bands_com_fx.c b/lib_com/ivas_stereo_mdct_bands_com_fx.c index 43f2f16c7efc13d125717975cc63064027644d3d..09c9d94c2864b945083f67246737565163ffeea8 100644 --- a/lib_com/ivas_stereo_mdct_bands_com_fx.c +++ b/lib_com/ivas_stereo_mdct_bands_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_stereo_mdct_stereo_com_fx.c b/lib_com/ivas_stereo_mdct_stereo_com_fx.c index 0a773169d07313155482bed27f0613b1cccb7a40..02d141da2a5d4230507ab7a689789e366e16e52a 100644 --- a/lib_com/ivas_stereo_mdct_stereo_com_fx.c +++ b/lib_com/ivas_stereo_mdct_stereo_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_stereo_psychlpc_com_fx.c b/lib_com/ivas_stereo_psychlpc_com_fx.c index df514089560c440dde31ff103bf87fd0b1ff740f..3a130b8cbacc3e3c2070785ccf34bde94ba4d8af 100644 --- a/lib_com/ivas_stereo_psychlpc_com_fx.c +++ b/lib_com/ivas_stereo_psychlpc_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/ivas_stereo_td_bit_alloc_fx.c b/lib_com/ivas_stereo_td_bit_alloc_fx.c index fe18e7bad6caea89ed7c019b09a57943b5499eeb..45dfb3110223d8c83886c107cec362b670a38c91 100644 --- a/lib_com/ivas_stereo_td_bit_alloc_fx.c +++ b/lib_com/ivas_stereo_td_bit_alloc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include "cnst.h" #include "stat_enc.h" #include "rom_com.h" #include "ivas_rom_com.h" diff --git a/lib_com/ivas_tools_fx.c b/lib_com/ivas_tools_fx.c index bc080f2f832a86c95ef4ee01a7b709ee6492da90..fae273974686300a3f790b5aec60bb9435b39a8b 100644 --- a/lib_com/ivas_tools_fx.c +++ b/lib_com/ivas_tools_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,12 +33,16 @@ #include #include #include "options.h" -#include #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_rom_com.h" #include "ivas_prot_fx.h" + +/*-----------------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------------*/ + #define ANGLE_90_DEG_Q22 377487360 #define ANGLE_180_DEG_Q22 754974720 #define ANGLE_360_DEG_Q22 1509949440 @@ -156,6 +160,38 @@ UWord32 ivas_syn_output_fx( * Convert an interleaved buffer of audio channels to deinterleaved one *-------------------------------------------------------------------*/ +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER +void ivas_buffer_interleaved_to_deinterleaved_fx( + Word32 *audio_in, /* i : interleaved audio buffer */ + Word32 *audio_out[], /* o : pointers to each channel of deinterleaved audio buffer */ + const Word16 n_channels, /* i : number of channels */ + const Word16 frame_length /* i : frame length (one channel) */ +) +{ + Word16 ch, s; + Word32 buffer[MAX_TRANSPORT_CHANNELS][MAX_JBM_L_FRAME48k]; /* temp buffer needed when "*audio_in" and "*audio_out[]" point to the same memory */ + + FOR( ch = 0; ch < n_channels; ch++ ) + { + FOR( s = 0; s < frame_length; s++ ) + { + buffer[ch][s] = audio_in[s * n_channels + ch]; + move32(); + } + } + + FOR( ch = 0; ch < n_channels; ch++ ) + { + FOR( s = 0; s < frame_length; s++ ) + { + audio_out[ch][s] = buffer[ch][s]; + move32(); + } + } + + return; +} +#else void ivas_buffer_interleaved_to_deinterleaved_fx( Word32 *audio, /* i/o: audio buffer */ const Word16 n_channels, /* i : number of channels */ @@ -185,6 +221,7 @@ void ivas_buffer_interleaved_to_deinterleaved_fx( return; } +#endif /*-------------------------------------------------------------------* @@ -193,6 +230,38 @@ void ivas_buffer_interleaved_to_deinterleaved_fx( * Convert a deinterleaved buffer of audio channels to interleaved one *-------------------------------------------------------------------*/ +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER +void ivas_buffer_deinterleaved_to_interleaved_fx( + Word32 *audio_in[], /* i : pointers to each channel of deinterleaved audio buffer */ + Word32 *audio_out, /* o : interleaved audio buffer */ + const Word16 n_channels, /* i : number of channels */ + const Word16 frame_length /* i : frame length (one channel) */ +) +{ + Word16 ch, s; + Word32 buffer[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; /* temp buffer needed when "*audio_in[]" and "*audio_out" point to the same memory */ + + FOR( ch = 0; ch < n_channels; ch++ ) + { + FOR( s = 0; s < frame_length; s++ ) + { + buffer[ch][s] = audio_in[ch][s]; + move32(); + } + } + + FOR( ch = 0; ch < n_channels; ch++ ) + { + FOR( s = 0; s < frame_length; s++ ) + { + audio_out[s * n_channels + ch] = buffer[ch][s]; + move32(); + } + } + + return; +} +#else void ivas_buffer_deinterleaved_to_interleaved_fx( Word32 *audio[], /* i/o: deinterleaved audio buffer */ const Word16 n_channels, /* i : number of channels */ @@ -220,6 +289,7 @@ void ivas_buffer_deinterleaved_to_interleaved_fx( return; } +#endif /*-------------------------------------------------------------------* @@ -601,7 +671,7 @@ void v_mult_mat_fx( pt_y++; } - MVR2R_WORD32( tmp_y, y, Nc ); /*Qx - guardbits*/ + Copy32( tmp_y, y, Nc ); /*Qx - guardbits*/ } diff --git a/lib_com/ivas_transient_det_fx.c b/lib_com/ivas_transient_det_fx.c index 39dee9314d95f5acf0175589995418fc9918d52f..ea3acdb9e5a981e966b0a2d3f5c83948603d57ff 100644 --- a/lib_com/ivas_transient_det_fx.c +++ b/lib_com/ivas_transient_det_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,19 +32,19 @@ #include #include "options.h" -#include "math.h" #include "wmc_auto.h" #include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" #include "ivas_stat_com.h" + /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ #define IVAS_TDET_PARM_ENV_EPS ( 1e-5f ) -#define IVAS_TDET_PARM_ENV_EPS_fx 21474 // Q31 +#define IVAS_TDET_PARM_ENV_EPS_fx ( ( (Word64) 21474 ) << 12 ) // Q11+32 #define IVAS_TDET_DUCK_MULT_FAC ( 590558003 ) // Q29 #define IVAS_TDET_PARM_TRANS_THR ( 107374182 ) // Q30 @@ -381,8 +381,6 @@ void ivas_td_decorr_get_ducking_gains_fx( const Word16 tdet_flag /*Q0*/ ) { Word16 i; - Word32 e_fast_fx[L_FRAME48k], e_slow_fx[L_FRAME48k]; - Word16 e_fast_e[L_FRAME48k], e_slow_e[L_FRAME48k]; Word32 in_duck_gain = hTranDet->in_duck_gain; /*Q30*/ move32(); Word32 out_duck_gain = hTranDet->out_duck_gain; /*Q30*/ @@ -394,37 +392,46 @@ void ivas_td_decorr_get_ducking_gains_fx( Word32 duck_mult_fac = hTranDet->duck_mult_fac; /*Q29*/ move32(); - Copy32( pIn_pcm, e_fast_fx, frame_len ); /*Q11*/ + Word64 e_fast_fx[L_FRAME48k], e_slow_fx[L_FRAME48k]; + Word32 fast_fx, slow_fx; + Word16 fast_e, slow_e; - set16_fx( e_fast_e, 31 - Q11, L_FRAME48k ); + FOR( i = 0; i < frame_len; i++ ) + { + e_fast_fx[i] = W_deposit32_h( pIn_pcm[i] ); /*Q43*/ + move64(); + } /* env hpf */ - ivas_filter_process_exp_fx( &hTranDet->env_hpf, e_fast_fx, frame_len, e_fast_e ); - + ivas_filter_process_fx64( &hTranDet->env_hpf, e_fast_fx, frame_len ); /*Q43*/ FOR( i = 0; i < frame_len; i++ ) { - // e_fast_fx[i] = L_add( L_abs( e_fast_fx[i] ), L_shr( IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff ) ); /*Q14*/ - e_fast_fx[i] = BASOP_Util_Add_Mant32Exp( L_abs( e_fast_fx[i] ), e_fast_e[i], IVAS_TDET_PARM_ENV_EPS_fx, 0, &e_fast_e[i] ); - move32(); + e_fast_fx[i] = W_add( W_abs( e_fast_fx[i] ), IVAS_TDET_PARM_ENV_EPS_fx ); + move64(); e_slow_fx[i] = e_fast_fx[i]; - move32(); - e_slow_e[i] = e_fast_e[i]; - move16(); + move64(); } /* env fast*/ - ivas_filter_process_exp_fx( &hTranDet->env_fast, e_fast_fx, frame_len, e_fast_e ); + ivas_filter_process_fx64( &hTranDet->env_fast, e_fast_fx, frame_len ); /*Q43*/ /* env slow */ - ivas_filter_process_exp_fx( &hTranDet->env_slow, e_slow_fx, frame_len, e_slow_e ); + ivas_filter_process_fx64( &hTranDet->env_slow, e_slow_fx, frame_len ); /*Q43*/ IF( tdet_flag ) { FOR( i = 0; i < frame_len; i++ ) { - in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_slow_e[i], e_fast_fx[i], e_fast_e[i], duck_mult_fac ); /*Q30*/ - pIn_duck_gains[i] = in_duck_gain; /*Q30*/ + fast_e = W_norm( e_fast_fx[i] ); + fast_fx = W_extract_h( W_shl( e_fast_fx[i], fast_e ) ); /*Q43 + fast_e - 32 = Q11 + fast_e*/ + fast_e = sub( 20, fast_e ); /*exp: 31 - (Q11 + fast_e) = 20 - fast_e*/ + slow_e = W_norm( e_slow_fx[i] ); + slow_fx = W_extract_h( W_shl( e_slow_fx[i], slow_e ) ); /*Q43 + fast_e - 32 = Q11 + slow_e*/ + slow_e = sub( 20, slow_e ); /*exp: 31 - (Q11 + slow_e) = 20 - slow_e*/ + + in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, slow_fx, slow_e, fast_fx, fast_e, duck_mult_fac ); /*Q30*/ + pIn_duck_gains[i] = in_duck_gain; /*Q30*/ move32(); } hTranDet->in_duck_gain = in_duck_gain; /*Q30*/ @@ -434,11 +441,18 @@ void ivas_td_decorr_get_ducking_gains_fx( { FOR( i = 0; i < frame_len; i++ ) { - in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_slow_e[i], e_fast_fx[i], e_fast_e[i], duck_mult_fac ); /*Q30*/ - pIn_duck_gains[i] = in_duck_gain; /*Q30*/ - move32(); - out_duck_gain = ivas_calc_duck_gain_fx( out_duck_gain, out_duck_coeff, e_fast_fx[i], e_fast_e[i], e_slow_fx[i], e_slow_e[i], duck_mult_fac ); /*Q30*/ - pOut_duck_gains[i] = out_duck_gain; /*Q30*/ + fast_e = W_norm( e_fast_fx[i] ); + fast_fx = W_extract_h( W_shl( e_fast_fx[i], fast_e ) ); /*Q43 + fast_e - 32 = Q11 + fast_e*/ + fast_e = sub( 20, fast_e ); /*exp: 31 - (Q11 + fast_e) = 20 - fast_e*/ + slow_e = W_norm( e_slow_fx[i] ); + slow_fx = W_extract_h( W_shl( e_slow_fx[i], slow_e ) ); /*Q43 + fast_e - 32 = Q11 + slow_e*/ + slow_e = sub( 20, slow_e ); /*exp: 31 - (Q11 + slow_e) = 20 - slow_e*/ + + in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, slow_fx, slow_e, fast_fx, fast_e, duck_mult_fac ); /*Q30*/ + pIn_duck_gains[i] = in_duck_gain; /*Q30*/ + move32(); + out_duck_gain = ivas_calc_duck_gain_fx( out_duck_gain, out_duck_coeff, fast_fx, fast_e, slow_fx, slow_e, duck_mult_fac ); /*Q30*/ + pOut_duck_gains[i] = out_duck_gain; /*Q30*/ move32(); } hTranDet->in_duck_gain = in_duck_gain; /*Q30*/ diff --git a/lib_com/lag_wind_fx.c b/lib_com/lag_wind_fx.c index 3685cb834bc4ccf47e38ba6b5662c9919fc3158e..a83b90b9be26cf4ab7fc2486e73be09a577e14de 100644 --- a/lib_com/lag_wind_fx.c +++ b/lib_com/lag_wind_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/lerp_fx.c b/lib_com/lerp_fx.c index 632593c6f10283a4c907e77b595b9f68ef8b094b..2015a074cb9a9f7e44701d29a8cbef995b55dd19 100644 --- a/lib_com/lerp_fx.c +++ b/lib_com/lerp_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/log2.c b/lib_com/log2.c index 70e6b93c00dd2b1203eee6c8e9801c05d3a0aadb..6f398df1e66c198ca82f8208c0e496ce788fabd6 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -58,15 +58,17 @@ Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val Word16 i, a; Word16 y; - if ( L_x <= 0 ) - L_x = L_deposit_h( 0x4000 ); - + if ( L_x > 0 ) /* There are many cases in the code where L_x == 0 */ + assert( L_x >= 0x40000000 ); /* If assert fail, means input is not normalized as it should be */ + L_x = L_max( L_x, 0x40000000 ); L_x = L_shr( L_x, 9 ); a = extract_l( L_x ); /* Extract b10-b24 of fraction */ a = lshr( a, 1 ); i = mac_r( L_x, -32 * 2 - 1, 16384 ); /* Extract b25-b31 minus 32 */ + assert( ( i >= 0 ) && ( i < (Word16) ( sizeof( L_table_Log2_norm_lc ) / sizeof( L_table_Log2_norm_lc[0] ) ) ) && ( i < (Word16) ( sizeof( table_diff_Log2_norm_lc ) / sizeof( table_diff_Log2_norm_lc[0] ) ) ) ); + y = mac_r( L_table_Log2_norm_lc[i], table_diff_Log2_norm_lc[i], a ); /* table[i] << 16 - diff*a*2 */ return y; @@ -75,6 +77,7 @@ Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val Word32 log10_fx( Word32 Linput ) /*o : Q23, i: 2Q13*/ { Word16 n1, frac, p1, p2, q1; + Word16 idx; Word32 Ltemp1, Ltemp2; Word32 L_tmp; @@ -89,10 +92,16 @@ Word32 log10_fx( Word32 Linput ) /*o : Q23, i: 2Q13*/ Ltemp2 = L_mult( extract_h( Ltemp1 ), 0x40 ); frac = extract_l( Ltemp2 ); - p1 = log2_tab[sub( extract_h( Ltemp2 ), 0x20 )]; + idx = sub( extract_h( Ltemp2 ), 0x20 ); + assert( idx >= 0 && idx < (Word16) ( sizeof( log2_tab ) / sizeof( log2_tab[0] ) ) ); + p1 = log2_tab[idx]; move16(); - p2 = log2_tab[sub( extract_h( Ltemp2 ), 0x1F )]; + + idx = sub( extract_h( Ltemp2 ), 0x1F ); + assert( idx >= 0 && idx < (Word16) ( sizeof( log2_tab ) / sizeof( log2_tab[0] ) ) ); + p2 = log2_tab[idx]; move16(); + Ltemp2 = L_mult( n1, 0x200 ); n1 = extract_l( Ltemp2 ); diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 833ff03fb572f67dff94fca968c9136a5baec042..4b096ac35a52c814559eca58cea6e97a66976fe3 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,7 @@ #include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "cnst.h" /* Common constants */ -#include + /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ diff --git a/lib_com/longarith.c b/lib_com/longarith.c index a922c2b4a0afe55f50a81cc7c5d65ff43c74fcf5..193c358cb5808f579aa0237862c8b88408cb2ab1 100644 --- a/lib_com/longarith.c +++ b/lib_com/longarith.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index bb4cec6c21ea2cd1ef3a766595019c800d514b75..5b3b8a1c0b990019220f3b27a10a45a8ad7faedc 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index e4dbd7e2a9530e465ca94197dd625124167ee4ae..c1638a26948fbcd99d94666bdf1e153c29d409dc 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -2963,90 +2963,6 @@ void lsf_syn_mem_backup_fx( } -/*-------------------------------------------------------------------* - * lsf_syn_mem_backup_fx() - * - * - *--------------------------------------------------------------------*/ - -void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code Q15 */ - Word32 *gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *next_force_sf_bck_fx, /* o: */ - Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *streaklimit, /* Q15 */ - Word16 *pstreaklen ) -{ - Word16 i; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - *clip_var = st_fx->clip_var_fx[0]; - move16(); - - FOR( i = 0; i < M; i++ ) - { - mem_AR[i] = st_fx->mem_AR_fx[i]; // Q2.56 - move16(); - mem_MA[i] = st_fx->mem_MA_fx[i]; // Q2.56 - move16(); - lsp_new_bck[i] = lsp_new[i]; // Q15 - move16(); - lsp_mid_bck[i] = lsp_mid[i]; // Q15 - move16(); - } - - *streaklimit = st_fx->streaklimit_fx; // Q15 - move16(); - *pstreaklen = st_fx->pstreaklen; - move16(); - - FOR( i = 0; i < L_FFT; i++ ) - { - Bin_E[i] = st_fx->Bin_E_fx[i]; // Q_new + Q_SCALE - 2 - move32(); - } - - FOR( i = 0; i < ( L_FFT / 2 ); i++ ) - { - Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; // Q_new + Q_SCALE - 2 - move32(); - } - - /* back-up memories */ - FOR( i = 0; i < M; i++ ) - { - mem_syn_bck[i] = hLPDmem->mem_syn[i]; // Q( st_fx->hLPDmem->q_mem_syn ) - move16(); - } - - *mem_w0_bck = hLPDmem->mem_w0; // Q( st_fx->hLPDmem->q_mem_syn ) - move16(); - - - *btilt_code_fx = hLPDmem->tilt_code; // Q15 - move16(); - *gc_threshold_fx = hLPDmem->gc_threshold; // Q16 - move16(); - Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); - *next_force_sf_bck_fx = st_fx->next_force_safety_net; - move16(); - - - return; -} - void lsf_update_memory( Word16 narrowband, /* i : narrowband flag */ const Word16 qlsf[], /* i : quantized lsf coefficients */ @@ -3190,83 +3106,6 @@ void lsf_syn_mem_restore_fx( return; } -void lsf_syn_mem_restore_ivas_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: Q15 */ - Word32 gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 streaklimit, /* i:LSF quantizer Q15 */ - Word16 pstreaklen /* i:LSF quantizer */ -) -{ - Word16 i; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - /* restore lsf memories */ - st_fx->clip_var_fx[0] = clip_var; - move16(); - - FOR( i = 0; i < M; i++ ) - { - st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 - move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 - move16(); - lsp_new[i] = lsp_new_bck[i]; // Q15 - move16(); - lsp_mid[i] = lsp_mid_bck[i]; // Q15 - move16(); - } - - st_fx->streaklimit_fx = streaklimit; // Q15 - move16(); - st_fx->pstreaklen = pstreaklen; - move16(); - - FOR( i = 0; i < L_FFT; i++ ) - { - st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 - move16(); - } - - FOR( i = 0; i < ( L_FFT / 2 ); i++ ) - { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 - move32(); - } - - /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; // Q( st_fx->hLPDmem->q_mem_syn ) - move16(); - - FOR( i = 0; i < M; i++ ) - { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; // Q( st_fx->hLPDmem->q_mem_syn ) - move16(); - } - - move16(); - hLPDmem->tilt_code = btilt_code_fx; // Q15 - move32(); - hLPDmem->gc_threshold = gc_threshold_fx; // Q16 - Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); - st_fx->next_force_safety_net = next_force_sf_bck_fx; - move16(); - - return; -} /* Returns: codebook index */ Word16 tcxlpc_get_cdk( diff --git a/lib_com/mime.h b/lib_com/mime.h index 7d21f6aac0c182941a2df91c96dc617ff4234b8e..803e54cb0f96738d813f1e5975b4a28a43bbe5ba 100644 --- a/lib_com/mime.h +++ b/lib_com/mime.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 7977bc49b5c66b7871c2010652b25b8d61a0a0fe..97f4ef4135ba2434827ea79755800456d90043c7 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ #include -#include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "prot_fx.h" @@ -169,7 +168,6 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q { autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); - t1 = L_Comp( r_fx_h[1], r_fx_l[1] ); /* R[1] in Q31 */ t2 = L_abs( t1 ); /* abs R[1] */ t0 = L_deposit_l( 0 ); @@ -182,12 +180,10 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q t0 = L_negate( t0 ); /* R[1]/R[0] */ } - mu_preemph_fx = extract_h( t0 ); /*r_fx[1] / r_fx[0]; */ mem_preemph_fx = signal_ana_fx[mem_len_ana + lg - LEN_WIN_SSS - 1]; move16(); - PREEMPH_FX( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); - + preemph_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); /* Autocorrelations */ autocorr_fx( signal_ana_fx + mem_len_ana + lg - LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r, @@ -450,7 +446,6 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { autocorr_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); - t1 = L_Comp( r_fx_h[1], r_fx_l[1] ); /* R[1] in Q31 */ t2 = L_abs( t1 ); /* abs R[1] */ t0 = L_deposit_l( 0 ); @@ -463,12 +458,10 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ t0 = L_negate( t0 ); /* R[1]/R[0] */ } - mu_preemph_fx = extract_h( t0 ); /*r_fx[1] / r_fx[0]; */ mem_preemph_fx = signal_ana_fx[mem_len_ana + lg - LEN_WIN_SSS - 1]; move16(); - PREEMPH_FX( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); - + preemph_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx ); /* Autocorrelations */ autocorr_fx( signal_ana_fx + sub( add( mem_len_ana, lg ), LEN_WIN_SSS ), M, r_fx_h, r_fx_l, &Q_r, diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index bbca861591070cc59549d592ad221314cc7ebfd9..956f87251ad66b0f988ddb344df30c2a8a6a52a4 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c index 39d57299e7dad568f0bf2d5c65e1f454d250f127..03b80f7ded5afa86d2613cc93a55e9f030d636f7 100644 --- a/lib_com/nelp_fx.c +++ b/lib_com/nelp_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/options.h b/lib_com/options.h index 355f7dc1babe3cc8ff0364d064bcf6cdb2c8b791..61a3c10ccfc2662a6854e6d6fc182f24dde9d839 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -81,22 +81,33 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ -#define FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK /* Eri: Issue 1999: Range check on float values of distance attenuation, while the float values are not propagated to this function. The test is not correct, but configurable distance attenuation is not used in Characterization.*/ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define FIX_1435_MOVE_STEREO_PANNING /* VA: issue 1435: do the EVS stereo panning in the renderer */ - +#define FIX_1904_HARM_GSC_ENC /* VA: #1904 Harmonization of EVS and IVAS GSC code */ +#define FIX_2388_INITTNSCONFIGURATION /* FhG: issue 2388 : harmonizing InitTnsConfiguration() function */ +#define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ +#define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ +#define FIX_2405_HARM_SMC_INIT /* VA, basop 2405, harmonisation of SMC init */ +#define FIX_2280_REDUCTION_UNNECESSARY_SCALING /* VA: reduction of unnecessary scaling */ +#define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE /* VA: reduction of unnecessary scaling, non-BE part */ +#define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ +#define FIX_2404_HARM_SIGNAL_CLAS /* VA: basop-2404, harmonize signal_clas and signa_ivas_clas */ +#define HARMONIZE_ACELP_ENC /* VA: basop issue 2400: Remove duplicated main ACELP encoder function */ +#define FIX_2392_MSAN_DESTROY_DEC /* VA: basop issue 2392: fix MSAN in ivas_destroy_dec_fx() */ /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_1454_FIX_STEREO_TO_FOA_JBM /* VA: issue 1454: fix buggy stereo to FOA in JBM */ -#define FIX_2015_PREMPH_SAT_ALT_PART2 /* VA: Add missing scaling factor to be passed to AVQ_cod() */ -#define FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH /* VA: Fix Issue 2253 where the encoder and decoder could get out of sync */ - - +#define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT /* Dolby: Issue 2250: random vector generation in GenShapedSHBExcitation() */ +#define FIX_2338_HARM_GSC_GAIN_COMP /* VA: basop issue 2338: harmonization of band gain computation for both EVS and IVAS */ +#define FIX_BASOP_2361_OTR /* FhG: Basop issue 2361: Orientation tracking tests for equivalent rotations fail */ +#define FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER /* FhG/VA: basop issue 2396: keep TC channel pointers in one constant place during decoding and rendering */ +#define FIX_2408_FD_BWE_UPDATE /* VA: basop issue 2408: bug-fix in the FD BWE memory updates in wb_pre_proc_ivas_fx() */ +#define FIX_2380_HARM_GSC_GAIN_COMP_FX /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */ +#define FIX_2406_FIX_GAIN_ON_INACTIVE /* VA: basop issue 2406: gain between 6.4 and 8kHz was too weak during inactive content with Fs=16kHz */ +#define FIX_2407_FIX_RESIDU_IVAS /* VA: basop 2407, Implementation issue in residu_ivas + unnecessary complexity */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_com/parameter_bitmaping_fx.c b/lib_com/parameter_bitmaping_fx.c index 92387209012c8cd2dfd7a6bacdb30ab3903715ad..4225879e6b20e56584e35c4bc40240cfc0112337 100644 --- a/lib_com/parameter_bitmaping_fx.c +++ b/lib_com/parameter_bitmaping_fx.c @@ -25,24 +25,6 @@ static Word16 PutIntoBitstream_fx( return value; } -static Word16 PutIntoBitstream_ivas_fx( - const Word16 **pStream, - TEncodeValue EncodeValue, - Word16 index, - BSTR_ENC_HANDLE hBstr, - const Word16 nBits ) -{ - Word16 value; - Word16 codedValue; - - move16(); - value = *( *pStream )++; - codedValue = EncodeValue( value, index ); - - push_next_indice( hBstr, codedValue, nBits ); - - return value; -} static Word16 FixedWidthEncoding( Word16 value, Word16 index ) { @@ -252,6 +234,8 @@ void SetParameters_fx( } } } + + return; } @@ -266,13 +250,11 @@ void WriteToBitstream_fx( Word16 index; Word16 iParam, nParams; - assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) ); nParams = paramsBitMap->nParams; FOR( index = 0; index < nArrayLength; index++ ) { - FOR( iParam = 0; iParam < nParams; iParam++ ) { ParamBitMap const *param; @@ -321,75 +303,11 @@ void WriteToBitstream_fx( } } } -} -void WriteToBitstream_ivas_fx( - ParamsBitMap const *paramsBitMap, - const Word16 nArrayLength, - const Word16 **pStream, - Word16 *pnSize, - BSTR_ENC_HANDLE hBstr, - Word16 *pnBits ) -{ - Word16 index; - Word16 iParam, nParams; - - - assert( ( paramsBitMap != NULL ) && ( nArrayLength > 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( hBstr != NULL ) && ( pnBits != NULL ) ); - nParams = paramsBitMap->nParams; - move16(); - - FOR( index = 0; index < nArrayLength; index++ ) - { - FOR( iParam = 0; iParam < nParams; iParam++ ) - { - ParamBitMap const *param; - Word16 nBits; - /* If a function for encoding/decoding value is defined than it should take care of 0 */ - Word16 fShiftValue; - TEncodeValue EncodeValue; - Word16 value; - - move16(); - param = ¶msBitMap->params[iParam]; - - move16(); - nBits = param->nBits; - IF( param->nBits == 0 ) - { -#define WMC_TOOL_SKIP - nBits = param->GetNumberOfBits( **pStream, index ); -#undef WMC_TOOL_SKIP - } - - fShiftValue = s_and( param->fZeroAllowed == 0, param->EncodeValue == NULL ); - - EncodeValue = param->EncodeValue; - if ( param->EncodeValue == NULL ) - { - move16(); - EncodeValue = &FixedWidthEncoding; - } - value = PutIntoBitstream_ivas_fx( pStream, EncodeValue, index, hBstr, nBits ); - IF( fShiftValue ) - { - value = add( value, 1 ); - } - - move16(); - *pnSize = add( *pnSize, 1 ); - move16(); - *pnBits = add( *pnBits, nBits ); - - test(); - IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) ) - { - WriteToBitstream_ivas_fx( param->pSubParamBitMap, value, pStream, pnSize, hBstr, pnBits ); - } - } - } + return; } + /** Get nBits long value from bitstream into *pStream. */ static Word16 GetFromBitstream( Decoder_State *st, @@ -457,6 +375,9 @@ void ReadFromBitstream_fx( } } } + move16(); *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) ); + + return; } diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c index 2f44e1081feb6c81b81d336b92bfe37b088fb00d..12a35b39371dd7e1eb8a155d802b21215ef544ab 100644 --- a/lib_com/ppp_fx.c +++ b/lib_com/ppp_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index cc7e544e896b9b7487ac1e7c6dbcd3fdf1079d3e..b04456870275c50cc5f02f259d093d6f1c991319 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -58,9 +58,8 @@ void pred_lt4_ivas_fx( FOR( i = 0; i < nb_coef; i++ ) { /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/ - s64 = W_mac_32_32( s64, L_deposit_l( *x1-- ), ( *c1 ) ); /* Q_exc + Q32 */ - s64 = W_mac_32_32( s64, L_deposit_l( *x2++ ), ( *c2 ) ); /* Q_exc + Q32 */ - + s64 = W_mac_32_16( s64, ( *c1 ), *x1-- ); /* Q_exc + Q32 */ + s64 = W_mac_32_16( s64, ( *c2 ), *x2++ ); /* Q_exc + Q32 */ c1 += up_sample; c2 += up_sample; } diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index 9631c68596fe1934049cd1badd965b0801156e87..46c8ccc36b531cab8b599c1b576afde3c3b97a33 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -8,11 +8,44 @@ #include "wmc_auto.h" /*-------------------------------------------------------------* - * preemph_copy_fx() + * preemph_fx() * * Preemphasis: filtering through 1 - mu z^-1 *-------------------------------------------------------------*/ +void preemph_fx( + Word16 x[], /* i/o: input/output signal Qx */ + const Word16 mu, /* i : preemphasis coefficient Q15 */ + const Word16 lg, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ +) +{ + Word16 i, temp; + + temp = x[lg - 1]; /* Qx */ + move16(); + + FOR( i = lg - 1; i > 0; i-- ) + { + x[i] = msu_r_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx */ + move16(); + } + + x[0] = msu_r_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx */ + move16(); + + *mem = temp; /* Qx */ + move16(); + + return; +} + +/*-------------------------------------------------------------* + * preemph_copy_fx() + * + * Preemphasis + copy: filtering through 1 - mu z^-1 + *-------------------------------------------------------------*/ + void preemph_copy_fx( const Word16 x[], /* i : input signal Qx */ Word16 y[], /* o : output signal Qx */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index bf24d493e29618fcce60ee39e5fcd9933a62dbb0..4dc1a1b1eadbdf44bb0ef2242219f853c1011b74 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,13 +33,6 @@ #ifndef PROT_FX2_H #define PROT_FX2_H -/*----------------------------------------------------------------------------------* - * Prototypes of RAM counting tool macros - *----------------------------------------------------------------------------------*/ - -#define MVR2R_WORD32( x, y, n ) Copy32( x, y, n ) -#define MVR2R_WORD16( x, y, n ) Copy( x, y, n ) - #include #include #include @@ -59,36 +52,19 @@ #include "complex_basop.h" -#define TCX_IMDCT_SCALE 15 -#define TCX_IMDCT_HEADROOM 1 - - /*----------------------------------------------------------------------------------* * Prototypes of global macros *----------------------------------------------------------------------------------*/ -#ifndef min -#define min( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) -#endif - -#ifndef max -#define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) -#endif - -#ifndef ABSVAL -#define ABSVAL( a ) ( ( a ) >= 0 ? ( a ) : ( -( a ) ) ) -#endif - -#ifndef SQR -#define SQR( a ) ( ( a ) * ( a ) ) -#endif - #ifndef SWAP #define SWAP( a, b ) \ { \ tempr = ( a ); \ ( a ) = ( b ); \ ( b ) = tempr; \ + move32(); \ + move32(); \ + move32(); \ } #endif @@ -99,6 +75,9 @@ u__p = x; \ x = y; \ y = u__p; \ + move32(); \ + move32(); \ + move32(); \ } #endif @@ -927,27 +906,6 @@ void lsf_syn_mem_restore_fx( Word16 pstreaklen /* i:LSF quantizer */ ); -void lsf_syn_mem_restore_ivas_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 btilt_code_fx, /* i: Q15 */ - Word32 gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 streaklimit, /* i:LSF quantizer Q15 */ - Word16 pstreaklen /* i:LSF quantizer */ -); - void lsf_update_memory( Word16 narrowband, /* i : narrowband flag */ const Word16 qisf[], /* i : quantized xSF coefficients */ @@ -1546,28 +1504,8 @@ Word16 gsc_gaindec_fx( const Word16 bwidth_fx /* i : i signal bandwidth */ ); -/*! r: average frequency gain */ -Word16 gsc_gaindec_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ -); - Word16 gsc_gainQ_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 y_gain4[], /* i : Energy per band Q13 */ - Word16 y_gainQ[], /* o : quantized energy per band Q13 */ - const Word32 core_brate, /* i : Core rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth /* i : signal bandwidth */ -); - -Word16 gsc_gainQ_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 element_mode, /* i : element mode */ const Word16 idchan, /* i : channel ID */ const Word16 y_gain4[], /* i : Energy per band Q12 */ Word16 y_gainQ[], /* o : quantized energy per band Q12 */ @@ -1669,16 +1607,6 @@ void int_lsp4_fx( Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ ); -void int_lsp4_ivas_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame Q15*/ - const Word16 lsp_mid[], /* i : LSPs from mid-frame Q15*/ - const Word16 lsp_new[], /* i : LSPs from present frame Q15*/ - Word16 *Aq, /* o : LP coefficients in both subframes Q12*/ - const Word16 m, /* i : order of LP filter */ - Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ -); - void de_interleave_spectrum_fx( Word32 *coefs, /* i/o: i and output coefficients Q? */ const Word16 length /* i : length of spectrum Q0 */ @@ -1758,7 +1686,13 @@ void Ener_per_band_comp_fx( Word16 y_gain4[], /* o : Energy per band to quantize Q12 */ const Word16 Q_exc_diff, const Word16 Mband, /* i : Max band */ - const Word16 Eflag ); +#ifdef FIX_1904_HARM_GSC_ENC + const Word16 Eflag, + const Word16 L_frame /* i : frame length */ +#else + const Word16 Eflag +#endif +); void Ener_per_band_comp_ivas_fx( const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ @@ -1769,15 +1703,23 @@ void Ener_per_band_comp_ivas_fx( const Word16 L_frame /* i : frame length */ ); +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX +Word16 Comp_and_apply_gain_fx( +#else void Comp_and_apply_gain_fx( +#endif Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + const Word16 Flag_adj_q_exc, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ +#endif Word16 Qexc_diff, Word16 Q_exc ); +#ifndef FIX_2338_HARM_GSC_GAIN_COMP void Comp_and_apply_gain_ivas_fx( Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ @@ -1786,16 +1728,21 @@ void Comp_and_apply_gain_ivas_fx( const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ Word16 Qexc_diff, Word16 *Q_exc ); - +#endif void pre_echo_att_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, const Word16 last_coder_type, /* i : Last coding mode Q0*/ - const Word16 L_frame /* i : Frame length Q0*/ +#ifdef FIX_1904_HARM_GSC_ENC + const Word16 L_frame /* i : Frame length Q0*/, + const Word16 element_mode /* i : Current IVAS element mode*/ +#else + const Word16 L_frame /* i : Frame length Q0*/ +#endif ); - +#ifndef FIX_1904_HARM_GSC_ENC void pre_echo_att_ivas_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ @@ -1804,6 +1751,7 @@ void pre_echo_att_ivas_fx( const Word16 last_coder_type, /* i : Last coding mode Q0*/ const Word16 L_frame /* i : Frame length Q0*/ ); +#endif void tcx_get_windows_mode1( const Word16 left_mode, /* i: overlap mode of left window half */ @@ -2265,19 +2213,6 @@ void mdct_spectrum_denorm_fx( const Word16 pd_thresh_fx /* i : Q15 : */ ); -void mdct_spectrum_denorm_ivas_fx( - const Word32 inp_vector[], /* i : Q0 : */ - Word32 L_y2[], /* i/o : Qs : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word32 L_band_energy[], /* i : Qbe : band energy */ - const Word16 npulses[], /* i : Q0 : number of coded spectrum */ - const Word16 bands, /* i : Q0 : numbers of subbands */ - const Word16 ld_slope_fx, /* i : Q15 : */ - const Word16 pd_thresh_fx /* i : Q15 : */ -); - void hq2_core_configure_fx( const Word16 frame_length, /* Q0 */ const Word16 num_bits, /* Q0 */ @@ -2686,9 +2621,12 @@ void lag_wind_32( Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ); -// preemp_fx.c -#define PREEMPH_FX( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) -#define PREEMPH_32FX( signal, signal_out, mu, L, mem ) preemph_copy_32fx2( ( signal ), ( signal_out ), ( mu ), ( L ), ( mem ) ) +void preemph_fx( + Word16 x[], /* i/o: input/output signal Qx */ + const Word16 mu, /* i : preemphasis coefficient Q15 */ + const Word16 lg, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ +); void preemph_copy_fx( const Word16 x[], /* i : i signal Qx */ @@ -2898,16 +2836,7 @@ Word16 tbe_celp_exc_offset( const Word16 L_frame /* i : frame lenght */ ); -void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ -); - -void tbe_celp_exc_ivas( +void tbe_celp_exc_fx( const Word16 element_mode, /* i : element mode */ const Word16 idchan, /* i : channel ID */ const Word16 L_frame_fx, /* i : Frame lenght */ @@ -2935,11 +2864,12 @@ void Calc_rc0_h( Word16 *rc0 /* o : 1st parcor */ ); +#ifndef HARMONIZE_TBE void Calc_rc0_h_ivas_enc_fx( Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ); - +#endif void PostShortTerm_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -2974,11 +2904,11 @@ void PostShortTerm_ivas_dec_fx( ); void flip_spectrum_and_decimby4_fx( - const Word16 i[], /* i : i spectrum */ + const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory */ - Word16 mem2[], /* i/o : memory */ + Word16 mem1[], /* i/o: memory */ + Word16 mem2[], /* i/o: memory */ const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */ ); @@ -2992,67 +2922,90 @@ void GenShapedWBExcitation_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ Word16 *state_lpc_syn, /* i/o : memory */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor */ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o : random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor */ const Word16 signal_type, const Word16 igf_flag ); +#ifdef HARMONIZE_TBE +void GenShapedWBExcitation_ivas_fx( + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o: memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o: memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o: memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag /* i : IGF flag */ +); + +#endif void GenWBSynth_fx( - const Word16 *input_synspeech, /* i : i synthesized speech */ + const Word16 *input_synspeech, /* i : i synthesized speech */ Word16 *shb_syn_speech_16k, /* o : output highband compnent */ Word16 *state_lsyn_filt_shb1, /* i/o: memory */ Word16 *state_lsyn_filt_shb2 /* i/o: memory */ ); void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ Word16 *tbe_demph, /* i/o: de-emphasis memory */ Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: i shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: i res gain shape, Q14 */ + Word16 *lpc_shb_sf, /* i : LP coefficients */ + const Word32 shb_ener_sf_32, /* i : i shb ener, Q31 */ + Word16 *shb_res_gshape, /* i : i res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ Word16 fb_state_lpc_syn[], /* i/o: memory */ Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi ); void GenShapedSHBExcitation_ivas_enc_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc_fb */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc_fb */ Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ Word16 *tbe_demph, /* i/o: de-emphasis memory */ Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *lpc_shb_sf, /* i : LP coefficients */ + const Word32 shb_ener_sf_32, /* i : input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i : input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ @@ -3164,41 +3117,31 @@ void ScaleShapedSHB_fx32( Word16 *Q_new ); void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o : synthesized shb signal */ - Word16 *overlap, /* i/o : buffer for overlap-add */ - const Word16 *subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16 *win, /* i : window */ - const Word16 *subwin, /* i : subframes window */ - const Word16 Q_bwe_exc, - Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ - Word16 *Qx, /* o : newly computed Q factor for synSHB */ - Word16 prev_Qx, /* i : prev_Qx for memory scaling */ - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal */ + Word16 *overlap, /* i/o: buffer for overlap-add */ + const Word16 *subgain, /* i : subframe gain */ + const Word32 frame_gain, /* i : frame gain */ + const Word16 *win, /* i : window */ + const Word16 *subwin, /* i : subframes window */ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ); void non_linearity_fx( - const Word16 i[], /* i : i signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : i length */ - Word32 *prev_scale, /* i/o: memory Q30 */ - Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ -); - -void non_linearity_ivas_fx( - const Word16 i[], /* i : i signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : i length */ - Word32 *prev_scale, /* i/o: memory Q30 */ - Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ + const Word16 element_mode, /* i : element mode */ + const Word16 i[], /* i : i signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : i length */ + Word32 *prev_scale, /* i/o: memory Q30 */ + const Word16 Q_inp, /* i : scaling of input */ + const Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ); void interp_code_5over2_fx( @@ -3634,6 +3577,7 @@ Word32 DTFS_getEngy_band_wb_fx( Word16 lband, Word16 hband ); +#ifndef FIX_2388_INITTNSCONFIGURATION void InitTnsConfiguration( const Word16 bwidth, const Word16 frameLength, @@ -3642,8 +3586,13 @@ void InitTnsConfiguration( const Word32 total_brate, const Word16 element_mode, const Word16 is_mct ); +#endif +#ifdef FIX_2388_INITTNSCONFIGURATION +void InitTnsConfiguration_fx( +#else void InitTnsConfiguration_ivas_fx( +#endif const Word16 bwidth, const Word16 frameLength, STnsConfig *pTnsConfig, @@ -3834,13 +3783,6 @@ void nelp_encoder_fx( Word16 *qIn1, Word16 reduce_gains ); -void nelp_encoder_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state */ - Word16 *in_fx, /* i : residual signal */ - Word16 *exc_fx, /* o : NELP quantized excitation signal */ - Word16 *qIn1, - Word16 reduce_gains ); - void swb_bwe_enc_lr_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 L_m_core[], /* i : lowband synthesis */ @@ -3866,31 +3808,6 @@ void swb_bwe_enc_lr_fx( Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ ); -void swb_bwe_enc_lr_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ -); - void isf_enc_amr_wb_fx( Encoder_State *st, /* i/o: state structure */ Word16 *isf_new, /* i/o: quantized ISF vector */ @@ -4024,44 +3941,17 @@ void CNG_exc_fx( ); void cng_params_postupd_fx( - const Word16 ho_circ_ptr, /* i : pointer for CNG averaging buffers Q0 */ - Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ - const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ - const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ - const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ - Word32 ho_env_circ[] /* i/o: Envelope buffer */ -); - -void cng_params_postupd_ivas_fx( const Word16 ho_circ_ptr, /* i : pointer for CNG averaging buffers Q0 */ Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ Word32 ho_env_circ[], /* i/o: Envelope buffer */ - const Word16 element_mode, /* i : Element mode */ - const Word16 bwidth /* i : Audio bandwidth */ + const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ ); void cng_params_upd_fx( - const Word16 lsp_new[], /* i : LSP parameters Q15 */ - const Word16 exc2[], /* i : current enhanced excitation Q_exc */ - const Word16 L_frame, /* i : frame length Q0 */ - Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ - Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ - Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ - Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ - const Word16 Q_exc, /* i : Q value of excitation */ - const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ - Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ - Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ - Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ - Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ - const Word32 last_active_brate /* i : Last active bit rate Q0 */ -); - -void cng_params_upd_ivas_fx( const Word16 lsp_new[], /* i : LSP aprameters Q15 */ const Word16 exc2[], /* i : current enhanced excitation Q_exc */ const Word16 L_frame, /* i : frame length Q0 */ @@ -4077,8 +3967,8 @@ void cng_params_upd_ivas_fx( Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ const Word32 last_active_brate, /* i : Last active bit rate Q0 */ - const Word16 element_mode, /* i : Element mode */ - const Word16 bwidth /* i : Audio bandwidth */ + const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ ); Word16 get_cng_mode( @@ -4347,6 +4237,7 @@ void tcx_noise_filling_with_shift( const Word16 element_mode /* i : IVAS element mode */ ); +#ifndef FIX_2388_INITTNSCONFIGURATION void InitTnsConfigs( const Word16 bwidth, const Word16 L_frame, @@ -4355,15 +4246,21 @@ void InitTnsConfigs( const Word32 total_brate, const Word16 element_mode, const Word16 is_mct ); +#endif -void InitTnsConfigs_ivas_fx( - const Word16 bwidth, - const Word16 L_frame, - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ); +#ifdef FIX_2388_INITTNSCONFIGURATION +void InitTnsConfigs_fx +#else +void InitTnsConfigs_ivas_fx +#endif + ( + const Word16 bwidth, + const Word16 L_frame, + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, + const Word32 total_brate, + const Word16 element_mode, + const Word16 is_mct ); void SetAllowTnsOnWhite( STnsConfig tnsConfig[2][2], @@ -4826,19 +4723,8 @@ Word16 est_tilt_fx( const Word16 *code, /* i : algebraic exctitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -); - -/* o : tilt of the code Q15 */ -Word16 est_tilt_ivas_fx( - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic excitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ - const Word16 L_subfr, /* i : Sub frame length */ - const Word16 flag_tilt /* i : flag for special tilt */ + const Word16 L_subfr /* i : Sub frame length */ ); /* o : tilt of the code */ @@ -5034,6 +4920,7 @@ void freq_dnw_scaling_fx( const Word16 L_frame /* i : frame length */ ); +#ifndef FIX_1904_HARM_GSC_ENC void highband_exc_dct_in_fx( const Word32 core_brate, /* i : core bitrate */ const Word16 *mfreq_bindiv, /* i : bin per bands tables */ @@ -5065,7 +4952,6 @@ void highband_exc_dct_in_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); - void highband_exc_dct_in_ivas_fx( const Word32 core_brate, /* i : core bitrate */ const Word16 *mfreq_bindiv, /* i : bin per bands tables */ @@ -5097,6 +4983,39 @@ void highband_exc_dct_in_ivas_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); +#else +void highband_exc_dct_in_fx( + const Word32 core_brate, /* i : core bitrate */ + const Word16 *mfreq_bindiv, /* i : bin per bands tables */ + Word16 last_bin, /* i : last bin of bit allocation */ + Word16 Diff_len, /* i : number of bin before cut-off frequency */ + Word16 noise_lev, /* i : pulses dynamic */ + Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ + Word16 *exc_diffQ, /* i : frequency coefficients of per band */ + Word16 *seed_tcx, /* i : Seed for noise */ + Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ + Word16 nb_subfr, /* i : Number of subframe considered */ + Word16 *exc_dct_in, /* o : dct of residual signal */ + Word16 last_coder_type, /* i : coding type of last frame */ + Word16 *bitallocation_band, /* i : bit allocation flag of each band */ + const Word16 *lsf_new, /* i : LSFs at the end of the frame */ + Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ + Word16 *last_ener, /* i : frequency energy of last frame */ + Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ + Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ + Word16 bfi, /* i : bad frame indicator */ + const Word16 coder_type, /* i : coder type */ + Word16 bwidth, + Word16 *exc_wo_nf, /* o : temporal excitation (in f domain) without noisefill */ + Word16 Qexc_diffQ, + Word16 *Q_exc, + const Word16 GSC_noisy_speech, + Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy */ + const Word16 L_frame, /* i : frame length */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ +); +#endif void lsf_dec_bfi( const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ @@ -5335,14 +5254,6 @@ Word32 sign_l( const Word32 x /* i : input value of x */ ); -void ivas_updt_dec_common_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis */ - const Word16 Qpostd /* i : Synthesis Q value */ -); - /* Random generator with Gaussian distribution with mean 0 and std 1 */ Word32 rand_gauss( Word16 *seed ); @@ -5907,6 +5818,7 @@ void swb_tbe_dec_fx( Word16 *Q_synth, Word16 *pitch_buf ); +#ifndef HARMONIZE_TBE void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ @@ -5919,8 +5831,9 @@ void ivas_dequantizeSHBparams_fx_9_1( Word16 *Q_shb_res_gshape, /* o : Q14 */ Word16 *Q_mixFactors, /* o : Q15 */ Word16 *MSFlag ); - +#endif void fb_tbe_dec_fx( +#ifndef HARMONIZE_TBE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, @@ -5928,9 +5841,13 @@ void fb_tbe_dec_fx( Word16 hb_synth_exp ); void fb_tbe_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, +#ifdef HARMONIZE_TBE + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ +#endif Word32 *hb_synth, /* o : high-band synthesis */ Word16 hb_synth_exp, Word16 *fb_synth_ref, @@ -6157,14 +6074,6 @@ void swb_CNG_dec_fx( const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); -void swb_CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ -); - void td_cng_dec_init_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ); @@ -6181,7 +6090,6 @@ void concealment_init_x( void concealment_init_ivas_fx( const Word16 L_frameTCX, T_PLCInfo_HANDLE hPlcInfo ); - void concealment_update_x( const Word16 bfi, const Word16 core, @@ -6482,18 +6390,7 @@ void hf_synth_reset_fx( void hf_synth_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate Q0*/ - const Word16 output_frame, /* i : output frame length Q0*/ - const Word16 *Aq, /* i : quantized Az Q12*/ - const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ - Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ - Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2 /* i : synthesis scaling */ -); - -void hf_synth_ivas_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word16 element_mode, /* i : element mode Q0*/ const Word32 core_brate, /* i : core bitrate Q0*/ const Word16 output_frame, /* i : output frame length Q0*/ const Word16 *Aq, /* i : quantized Az Q12*/ @@ -6561,20 +6458,6 @@ void formant_post_filt_fx( const Word16 off_flag /* i : off flag */ ); -void Filt_mu_fx( - Word16 *sig_in, /* i : signal (beginning at sample -1) */ - Word16 *sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr /* i : the length of subframe */ -); - -void Filt_mu_ivas_fx( - Word16 *sig_in, /* i : signal (beginning at sample -1) */ - Word16 *sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr, /* i : the length of subframe */ - const Word16 extl ); - void scale_st_fx( const Word16 *sig_in, /* i : postfilter i signal */ Word16 *sig_out, /* i/o: postfilter o signal */ @@ -6761,17 +6644,6 @@ void gain_dec_tc_fx( Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ ); -void gain_dec_tc_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : pitch gain */ - Word32 *gain_code_fx, /* o : Quantized codeebook gain */ - Word16 *gain_inov_fx, /* o : unscaled innovation gain */ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ -); - void gain_dec_mless_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 L_frame_fx, /* i : length of the frame */ @@ -6801,15 +6673,7 @@ void gain_dec_lbr_fx( ); void lp_gain_updt_fx( - const Word16 i_subfr, /* i : subframe number Q0 */ - const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ - const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ - Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ - Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ - const Word16 L_frame /* i : length of the frame */ -); - -void lp_gain_updt_ivas_fx( + const Word16 element_mode, /* i : element mode */ const Word16 i_subfr, /* i : subframe number Q0 */ const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ @@ -7068,20 +6932,6 @@ void inov_decode_fx( const Word16 L_subfr /* i : subframe length Q0 */ ); -void inov_decode_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate Q0 */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ - const Word16 L_frame, /* i : length of the frame Q0 */ - const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation Q12 */ - const Word16 L_subfr /* i : subframe length Q0 */ -); - void dec_acelp_4t64_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 nbbits, /* i : number of bits per codebook */ @@ -7133,12 +6983,6 @@ ivas_error acelp_core_switch_dec_bfi_fx( const Word16 coder_type /* i : coder type */ ); -ivas_error acelp_core_switch_dec_bfi_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ -); - void pred_lt4( const Word16 excI[], /* in : excitation buffer Q_exc*/ Word16 excO[], /* out: excitation buffer Q_exc*/ @@ -7730,35 +7574,34 @@ void hq_configure_bfi_fx( void bandwidth_switching_detect_fx( Decoder_State *st_fx /* i/o: encoder state structure */ ); - -void bandwidth_switching_detect_ivas_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ -); - void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ - Decoder_State *st_fx /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 *old_syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ ); ivas_error core_switching_pre_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length Q0*/ -); + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 last_element_mode, /* i : last_element_mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 Q_old_synthFB, + Word16 *Q_olapBufferSynth, + Word16 *Q_olapBufferSynth2 ); ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth Qsynth*/ - const Word16 output_frame, /* i : frame length Q0*/ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ - const Word16 last_element_mode, /* i : element mode of previous frame Q0*/ - Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ -); - -ivas_error core_switching_post_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#else + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ + Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#endif const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -7801,16 +7644,12 @@ void updt_IO_switch_dec_fx( Decoder_State *st_fx /* o : Decoder static variables structure */ ); -void updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : synthesis signal Qpost */ - const Word16 Qpost ); - void updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16 *synth, /* i : decoded synthesis */ + const Word16 *synth16, /* i : decoded synthesis Qpostd */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ); @@ -8765,12 +8604,6 @@ Word16 dlpc_avq_fx( Word32 sr_core ); Word16 decode_lpc_avq_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 numlpc, /* i : Number of sets of lpc */ - Word16 *param_lpc /* o : lpc parameters */ -); - -Word16 decode_lpc_avq_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 numlpc, /* i : Number of sets of lpc */ Word16 *param_lpc, /* o : lpc parameters */ @@ -9263,12 +9096,6 @@ void bpf_pitch_coherence_ivas_fx( const Word32 pitch_buf[] /* i : pitch for each subframe [0,1,2,3] */ ); -/* fft_rel.c */ - -#define SIZE_256 256 -#define NUM_STAGE_256 7 -#define SIZE2_256 ( SIZE_256 / 2 ) - void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ Word32 **realBuffer_fx, /* o : real value buffer Qx - 5*/ @@ -9484,14 +9311,6 @@ void stereo_dft_dec_open( const Word16 nchan_transport /* i : number of transport channels */ ); -void ivas_bw_switching_pre_proc_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 nchan_out, /* i : number of output channels */ - Word32 *old_syn_12k8_16k_fx, - Word16 Q, - Word16 Q_audio ); - UWord32 mvl2s_r( const Word32 x[], /* i : input vector */ const Word16 q, @@ -10299,11 +10118,11 @@ void ivas_swb_tbe_dec_fx( STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ - Word16 *pitch_buf_fx, /* i : Q6 */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); Word16 swb_bwe_dec_fx32( @@ -10316,10 +10135,18 @@ Word16 swb_bwe_dec_fx32( ); ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs */ - Word16 synth_fx16[], /* o : synthesis */ - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ + Decoder_State *st, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else + Word16 output_fx[], /* o : synthesis @internal Fs */ +#endif + Word16 synth_fx16[], /* o : synthesis */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ +#else + Word16 save_hb_synth_fx16[], /* o : HB synthesis */ +#endif Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ Word16 *voice_factors_fx, /* o : voicing factors */ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ @@ -10347,17 +10174,6 @@ void wtda_fx32( const Word16 L /* i : length */ ); -ivas_error core_switching_pre_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 output_frame, /* i : frame length */ - const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ - const Word16 nchan_out, /* i : number of output channels */ - const Word16 last_element_mode, /* i : last_element_mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth, - Word16 *Q_olapBufferSynth2 ); - void hp20_fx_32( Word32 signal_fx[], const Word16 lg, @@ -10464,26 +10280,15 @@ void Copy_Scale_sig32( ); void swb_pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ - Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ - Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */ - Word16 *Q_shb_spch, + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *new_swb_speech, /* o : original input signal at 32kHz - Q0 */ + Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz - Q0*/ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ - Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ + Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers*/ CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); -void core_encode_update_ivas_fx( - Encoder_State *st /* i/o: Encoder state structure */ -); - -void updt_enc_common_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 Q_new /* i : CUrrent frame scaling */ -); - /* o : Q(2x - 31 - gb) */ Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector, Qx */ @@ -10618,26 +10423,6 @@ Word16 ari_decode_14bits_sign_ivas( Word16 *res, Tastat *s ); -void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code Q15 */ - Word32 *gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *next_force_sf_bck_fx, /* o: */ - Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *streaklimit, /* Q15 */ - Word16 *pstreaklen ); - ivas_error config_acelp1_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 total_brate, /* i : total bitrate */ @@ -10722,12 +10507,6 @@ void writeTCXparam_fx( const Word16 target_bitsTCX10[2], const Word16 pre_past_flag ); -void calculate_hangover_attenuation_gain_ivas_fx( - Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -); - void init_coder_ace_plus_ivas_fx( Encoder_State *st, /* i : Encoder state */ const Word32 last_total_brate, /* i : last total bitrate */ @@ -10827,20 +10606,6 @@ Word16 msvq_stage1_dct_recalc_candidates_fdcng_wb_fx( Word16 *dist_ptr_e /* i/o: exp for updated MSE vector for stage1 */ ); -void FEC_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ - const Word16 *synth, /* i : pointer to synthesized speech for E computation Q_Synth*/ - const Word16 coder_type, /* i : type of coder Q0*/ - Word16 clas, /* i : signal clas for current frame Q0*/ - const Word16 *fpit, /* i : close loop fractional pitch buffer Q6*/ - const Word16 *res, /* i : LP residual signal frame Qx*/ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse Q0*/ - const Word16 L_frame, /* i : Frame length Q0*/ - const Word32 total_brate, /* i : total codec bitrate Q0*/ - const Word16 Q_synth /* i : input scaling */ -); - ivas_error IGF_Reconfig_fx( IGF_ENC_INSTANCE_HANDLE *hIGFEnc, /* i/o: instance handle of IGF Encoder */ const Word16 igf, /* i : IGF on/off */ @@ -10851,13 +10616,6 @@ ivas_error IGF_Reconfig_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -void core_switching_post_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz */ - Word16 *old_inp_16k_fx, /* i : old input signal @16kHz */ - Word16 A_fx[], /* i : unquant. LP filter coefs. */ - Word16 Q_new ); - void residu_ivas_fx( const Word16 *a, /* i : LP filter coefficients Q31-a_exp*/ const Word16 a_exp, @@ -10875,14 +10633,6 @@ void WriteToBitstream_fx( BSTR_ENC_HANDLE hBstr, Word16 *pnBits ); -void WriteToBitstream_ivas_fx( - ParamsBitMap const *paramsBitMap, - const Word16 nArrayLength, - const Word16 **pStream, - Word16 *pnSize, - BSTR_ENC_HANDLE hBstr, - Word16 *pnBits ); - /*===========================================================================================*/ /*----------------------------------------------------------------------------------* @@ -11130,7 +10880,11 @@ ivas_error init_encoder_fx( const Word32 element_brate /* i : element bitrate */ ); +#ifdef HARMONIZE_ACELP_ENC +ivas_error acelp_core_enc_fx( +#else ivas_error acelp_core_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 inp[], /* i : input signal of the current frame Q_new*/ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ @@ -11143,12 +10897,20 @@ ivas_error acelp_core_enc_ivas_fx( Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ - Word16 *q_old_syn_12k8_16, - Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits, /* o : number of unused bits Q0*/ - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ +#ifndef HARMONIZE_ACELP_ENC + Word16 *q_old_syn_12k8_16, /* o : Q factor of old_syn_12k8_16k[] */ +#endif + Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ + Word16 *unbits, /* o : number of unused bits Q0*/ + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ - Word16 Q_new ); +#ifdef HARMONIZE_ACELP_ENC + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift need to obtain 12 bits vectors */ +#else + const Word16 Q_new +#endif +); void flip_and_downmix_generic_fx32( Word32 input[], /* i : input spectrum Qx*/ @@ -11189,20 +10951,6 @@ void bands_and_bit_alloc_ivas_fx( const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ ); -void ivas_find_wsp_fx( - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 L_subfr, /* i : length of subframe Q0*/ - const Word16 nb_subfr, /* i : number of subframes Q0*/ - const Word16 *A_fx, /* i : A(z) filter coefficients Q12 */ - Word16 *Aw_fx, /* o : weighted A(z) filter coefficients Q12 */ - const Word16 *speech_fx, /* i : pointer to the denoised speech frame Q_new */ - const Word16 tilt_fact, /* i : tilt factor Q15 */ - Word16 *wsp_fx, /* o : poitnter to the weighted speech frame Q_new */ - Word16 *mem_wsp_fx, /* i/o: W(Z) denominator memory Q_new */ - const Word16 gamma, /* i : weighting factor Q15 */ - const Word16 L_look /* i : look-ahead Q0*/ -); - Word16 RCcontextMapping_encode2_estimate_bandWise_start_fx( Word16 *x, /* Q0 */ const Word16 nt, /* Q0 */ @@ -11258,7 +11006,8 @@ void UnmapIndex_fx( Word32 *Lag /* Q0 */ ); -#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) +//#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) +#define GET_ADJ2( T, L, F ) ( sub( shl( L, F ), T ) ) Word32 tcx_hm_render_fx( const Word32 lag, /* i: pitch lag Q0 */ diff --git a/lib_com/reordvct_fx.c b/lib_com/reordvct_fx.c index 62eb2f352665c97f24322207fc2092e4ac2e5c64..e89e9ed3817916883af0f99172debd4d115959e3 100644 --- a/lib_com/reordvct_fx.c +++ b/lib_com/reordvct_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 60c0c3356f5d827efb551da6df2ab08a57a3ff26..7008b4cf056f516200c39068350c2204141d1c0b 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -24,6 +24,7 @@ void residu_ivas_fx( const Word16 l /* i : size of filtering */ ) { +#ifndef FIX_2407_FIX_RESIDU_IVAS Word32 s; Word16 i, j; @@ -38,7 +39,23 @@ void residu_ivas_fx( y[i] = s; move32(); } +#else + Word64 s64; + Word16 i, j, scaling; + + scaling = sub( Q15, a_exp ); + FOR( i = 0; i < l; i++ ) + { + s64 = W_mult_32_16( x[i], a[0] ); + FOR( j = 1; j <= m; j++ ) + { + s64 = W_mac_32_16( s64, x[i - j], a[j] ); + } + y[i] = W_shl_sat_l( s64, scaling ); + move32(); + } +#endif return; } diff --git a/lib_com/rom_basop_util.c b/lib_com/rom_basop_util.c index eb79cc02648c67df6dbd075f3da2a9704142e2f8..321658f7a927a8edbf7f58dbb894dad0f9a5269f 100644 --- a/lib_com/rom_basop_util.c +++ b/lib_com/rom_basop_util.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/rom_basop_util.h b/lib_com/rom_basop_util.h index 63b55fe59b013b680023ac62f9706f119d26cbeb..ffbc7292acd5ff5038e8cd5cecc199274cb7e9d8 100644 --- a/lib_com/rom_basop_util.h +++ b/lib_com/rom_basop_util.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 1ba9251d304ce6969f3889bdd8c55089bee933df..a61ee76afeba95bcb1b93347b81311a7e45e897f 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index f1fdf7f78d581ff201922df2be5d9f0464f3f811..eff398b330db5b5ab4b9b32bfb8f5537257b8a34 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c index 52ba436de439de14d69c2f354877fac9f50390cb..9047c7ea4a40903db214b7ed79988d908a241c66 100644 --- a/lib_com/scale_mem_fx.c +++ b/lib_com/scale_mem_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 2a37faef604e3c4189d8c939b9a99be895941167..a85d6c7c013d62a4da41d8f93132dce64e52df2e 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index ad87695e831dd5092ddb9456261828e46ca5ec72..33c5545ce37b4036d4da03314b713530fd1d6377 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -158,7 +158,7 @@ void stat_noise_uv_mod_fx( { exctilt = calc_tilt_fx( &Exc2_local[i_subfr], En_shift, L_SUBFR ); /*Q15 */ exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ - PREEMPH_FX( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); + preemph_fx( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); } } @@ -458,7 +458,7 @@ void stat_noise_uv_mod_ivas_fx( { exctilt = calc_tilt_fx( &Exc2_local[i_subfr], En_shift, L_SUBFR ); /*Q15 */ exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ - PREEMPH_FX( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); + preemph_fx( &Exc2_local[i_subfr], exctilt, L_SUBFR, exc_pe ); } } @@ -614,7 +614,7 @@ void stat_noise_uv_mod_ivas_fx( mult( sub( 32767, beta ), lspnew_s[i] ) ); } - int_lsp4_ivas_fx( L_FRAME, oldlsp_mix, midlsp_mix, newlsp_mix, Aq, M, 0 ); + int_lsp4_fx( L_FRAME, oldlsp_mix, midlsp_mix, newlsp_mix, Aq, M, 0 ); Copy( lspnew_s, lspold_s, M ); } ELSE /* (unvoiced_vad != 0) */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index cc8b22db64fdf8b46a65290c72a58d61667a3615..a413064d2eb6b709c9b037ba1c4f004186060303 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 1326b31a98eac391da7fa04154e79c9759448955..4baf7f9a2e33c153d8da706de9389ded6ebc48d7 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index e63dc471ebd194f07d9a62648460c6ad02d96846..8f5f19d13763f2c67f45eaaf9cc77ad6a61e3147 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -8,30 +8,29 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" #include "basop_util.h" -#include "ivas_prot_fx.h" /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -#define POW_EXC16k_WHTND 1.14e11f /* power of random excitation, length 320 samples, uniform distribution */ -#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // Q31 +#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // 1.14e11f in Q31 power of random excitation, length 320 samples, uniform distribution #define POW_EXC16k_WHTND_FX_INV_SQRT_IN_Q49 1667313793 // Q49 #define POW_EXC16k_WHTND_FX 178125000 // Q-6 -#define THR_ENV_ERROR_PLOSIVE 200.0f /* threshold for envelope error used in plosive detection */ #define THR_ENV_ERROR_PLOSIVE_FX 200 /* threshold for envelope error used in plosive detection Q0 */ + /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ -static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[] ); +static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[], Word16 element_mode ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); -static void Calc_st_filt_tbe( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +static void Calc_st_filt_tbe_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); -void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); +static void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); + /*-------------------------------------------------------------------* * swb_tbe_reset() @@ -160,85 +159,8 @@ Word16 tbe_celp_exc_offset( * * Compute tbe bwe celp excitation *-------------------------------------------------------------------*/ -void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch Q0 */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch Q1 */ - Word16 *error_fx, /* i/o: Error Q5 */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ -) -{ - Word16 offset_fx, tmp_fx, i; - IF( EQ_16( L_frame_fx, L_FRAME ) ) - { - /*offset = T0 * HIBND_ACB_L_FAC + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) - 2 * HIBND_ACB_L_FAC; - for (i=0; i 0 ) - { - tmp_fx = shr( *error_fx, 5 ); /*Q0*/ - } - ELSE - { - tmp_fx = negate( shr( abs_s( *error_fx ), 5 ) ); /*Q0*/ - } - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx]; // Qx - move16(); - } - tmp_fx = extract_l( L_mult( T0_frac_fx, 1 ) ); /*Q3; 0.25 in Q2*/ - tmp_fx = add( shl( T0_fx, 3 ), tmp_fx ); /*Q3*/ - tmp_fx = extract_l( L_mult( tmp_fx, 5 ) ); /*Q5, 2.5 in Q1*/ - tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*Q5*/ - *error_fx = add( *error_fx, tmp_fx ); /*Q5*/ - move16(); - } - ELSE - { - /* offset = T0*2.5 + (int) ((float) T0_frac * 0.25f*2.5 + 2*2.5 + 0.5f) - 2*2.5; - case above*/ - /* offset = T0*2 + (int) ((float) T0_frac * 0.25f*2 + 2*2 + 0.5f) - 2*2; - case here*/ - - /*(int) ((float) T0_frac * 0.25f*2 + 2*2 + 0.5f)*/ - offset_fx = tbe_celp_exc_offset( T0_fx, T0_frac_fx, L_frame_fx ); - IF( *error_fx > 0 ) - { - tmp_fx = shr( *error_fx, 5 ); /*Q0*/ - } - ELSE - { - tmp_fx = negate( shr( abs_s( *error_fx ), 5 ) ); /*Q0*/ - } - - FOR( i = 0; i < L_SUBFR * 2; i++ ) - { - bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx]; // Qx - move16(); - } - - /* error += (float) offset - (float) T0 * 2 - 0.5f * (float) T0_frac;*/ - tmp_fx = extract_l( L_mult( T0_frac_fx, 2 ) ); /*Q3; 0.5 in Q2*/ - tmp_fx = add( shl( T0_fx, 4 ), tmp_fx ); /* now tmp_fx = "T0_fx*2+ 0.5f*T0_frac_fx" in Q3*/ - tmp_fx = shl( tmp_fx, 2 ); /*now above tmp_fx in Q5*/ - tmp_fx = sub( shl( offset_fx, 5 ), tmp_fx ); /*move offset_fx to Q5, tmp_fx in Q5, ans tmp_fx in Q5*/ - *error_fx = add( *error_fx, tmp_fx ); /*error_fx in Q5*/ - move16(); - } -} - -/*-------------------------------------------------------------------* - * swb_tbe_celp_exc_ivas() - * - * Compute tbe bwe celp excitation - *-------------------------------------------------------------------*/ -void tbe_celp_exc_ivas( +void tbe_celp_exc_fx( const Word16 element_mode, /* i : element mode */ const Word16 idchan, /* i : channel ID */ const Word16 L_frame_fx, /* i : Frame lenght */ @@ -321,6 +243,8 @@ void tbe_celp_exc_ivas( *error_fx = add( *error_fx, tmp_fx ); /*error_fx in Q5*/ move16(); } + + return; } /*===========================================================================*/ @@ -349,6 +273,14 @@ void tbe_celp_exc_ivas( /* RETURN ARGUMENTS : */ /* _ None */ /*---------------------------------------------------------------------------*/ + +static const Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, + -26319, -17530, -6393, 6393, 17530, 26319, + 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ +static const Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, + -19519, -27683, -32137, -32137, -27683, + -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ + void flip_and_downmix_generic_fx( Word16 input[], /* i : input spectrum Qx*/ Word16 output[], /* o : output spectrum Qx*/ @@ -371,21 +303,11 @@ void flip_and_downmix_generic_fx( /*Word16 s_tmp[L_FRAME32k];*/ /*Word16 factor;*/ Word16 period; - Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, - -26319, -17530, -6393, 6393, 17530, 26319, - 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ - Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, - -19519, -27683, -32137, -32137, -27683, - -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ - Word16 *local_negsin_table, *local_cos_table; Word32 L_tmp; /* 1850 Hz downmix */ period = 17; move16(); - local_negsin_table = local_negsin_table17; - local_cos_table = local_cos_table17; - FOR( i = 0; i < length; i = i + 2 ) { @@ -467,9 +389,9 @@ void flip_and_downmix_generic_fx( { WHILE( ( j < period ) && ( i < length ) ) { - L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = round_fx( L_tmp ); /*Qx */ + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table17[j] ); /*//Qx+16 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table17[j] ); /*Qx+16 */ + output[i] = round_fx( L_tmp ); /*Qx */ move16(); i++; j++; @@ -511,21 +433,11 @@ void flip_and_downmix_generic_fx32( /*Word16 s_tmp[L_FRAME32k];*/ /*Word16 factor;*/ Word16 period; - Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, - -26319, -17530, -6393, 6393, 17530, 26319, - 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ - Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, - -19519, -27683, -32137, -32137, -27683, - -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ - Word16 *local_negsin_table, *local_cos_table; Word32 L_tmp; /* 1850 Hz downmix */ period = 17; move16(); - local_negsin_table = local_negsin_table17; - local_cos_table = local_cos_table17; - FOR( i = 0; i < length; i = i + 2 ) { @@ -597,9 +509,9 @@ void flip_and_downmix_generic_fx32( WHILE( ( j < period ) && ( i < length ) ) { test(); - L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = L_tmp; /*Qx */ + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table17[j] ); /*//Qx+16 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table17[j] ); /*Qx+16 */ + output[i] = L_tmp; /*Qx */ move32(); i++; j++; @@ -807,9 +719,15 @@ void Calc_rc0_h( *rc0 = negate( *rc0 ); move16(); } + + return; } +#ifdef HARMONIZE_TBE +static void Calc_rc0_h_ivas_enc_fx( +#else void Calc_rc0_h_ivas_enc_fx( +#endif Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ) @@ -868,7 +786,7 @@ void Calc_rc0_h_ivas_enc_fx( } } -static void Calc_st_filt_tbe( +static void Calc_st_filt_tbe_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -906,6 +824,8 @@ static void Calc_st_filt_tbe( move16(); } } + + return; } static void Calc_st_filt_tbe_ivas_enc_fx( @@ -946,8 +866,11 @@ static void Calc_st_filt_tbe_ivas_enc_fx( move16(); } } + + return; } +#ifndef HARMONIZE_TBE static void Calc_st_filt_tbe_ivas_dec_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ @@ -986,8 +909,10 @@ static void Calc_st_filt_tbe_ivas_dec_fx( move16(); } } -} + return; +} +#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : output signal */ @@ -1190,7 +1115,7 @@ void PostShortTerm_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ @@ -1310,7 +1235,11 @@ void PostShortTerm_ivas_dec_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ +#ifdef HARMONIZE_TBE + Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#else Calc_st_filt_tbe_ivas_dec_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#endif /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ @@ -1327,6 +1256,13 @@ void PostShortTerm_ivas_dec_fx( return; } + +/*-------------------------------------------------------------------* + * flip_spectrum_and_decimby4() + * + * + *-------------------------------------------------------------------*/ + void flip_spectrum_and_decimby4_fx( const Word16 input[], /* i : input spectrum Q_inp */ Word16 output[], /* o : output spectrum Q_inp */ @@ -1406,21 +1342,23 @@ void flip_spectrum_and_decimby4_fx( /*==========================================================================*/ void GenShapedWBExcitation_ivas_fx( - Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32 *mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag, /* i : unvoiced flag */ - const Word16 igf_flag ) + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o: memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o: memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o: memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag /* i : IGF flag */ +) { Word16 i, j, k; Word16 wht_fil_mem[LPC_WHTN_ORDER_WB]; @@ -1478,7 +1416,7 @@ void GenShapedWBExcitation_ivas_fx( IF( uv_flag ) { - create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed, element_mode ); IF( LT_16( Q_bwe_exc, 5 ) ) { @@ -1554,7 +1492,7 @@ void GenShapedWBExcitation_ivas_fx( move32(); /* Q_bwe_exc+16 */ } - create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed, element_mode ); /* Ensure pow22 is greater than zero when computing normalization */ Lmax = 0; @@ -1661,6 +1599,7 @@ void GenShapedWBExcitation_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q(Q_bwe_exc) */ Word16 *state_lpc_syn, /* i/o : memory Q(Q_bwe_exc) */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q(Q_bwe_exc) */ const Word16 Q_bwe_exc, /* i : Q for memories */ Word16 bwe_seed[], /* i/o : random number generator seed */ @@ -1727,7 +1666,7 @@ void GenShapedWBExcitation_fx( IF( uv_flag ) { - create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed, element_mode ); IF( LT_16( Q_bwe_exc, 5 ) ) { FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1802,7 +1741,7 @@ void GenShapedWBExcitation_fx( move32(); /* Q_bwe_exc+16 */ } - create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed, element_mode ); /* Ensure pow22 is greater than zero when computing normalization */ Lmax = 0; @@ -2074,6 +2013,7 @@ void GenShapedSHBExcitation_fx( Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ Word16 voice_factors[], /* i : voicing factor*/ @@ -2293,8 +2233,8 @@ void GenShapedSHBExcitation_fx( { /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); L_tmp = L_deposit_l( 0 ); tmp = add( *Q_bwe_exc, 1 ); @@ -2392,9 +2332,7 @@ prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; move16(); *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); move16(); -deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); -/* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ -/* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ +deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); // Q_bwe_exc-NOISE_QADJ { IF( EQ_16( coder_type, UNVOICED ) ) { @@ -2409,9 +2347,7 @@ deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); move16(); /* exc16kWhtnd: Q_bwe_exc */ } - PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); - /* i/o: exc16kWhtnd (Q_bwe_exc) */ - /* i/o: tbe_premph (Q_bwe_exc) */ + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc } ELSE { @@ -2491,9 +2427,7 @@ deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); temp = div_s( temp, temp2 ); /* Q15 */ temp = mult_r( PREEMPH_FAC, temp ); - PREEMPH_FX( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); - /* exc16kWhtnd: Q_bwe_exc; - tbe_premph: Q_bwe_exc*/ + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc } } } @@ -2978,8 +2912,8 @@ void GenShapedSHBExcitation_ivas_enc_fx( ELSE { /* create a random excitation - Reuse exc16k memory */ - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); // Q5 - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); // Q5 + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); // Q5 + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); // Q5 L_tmp = L_deposit_l( 0 ); tmp = add( *Q_bwe_exc, 1 ); @@ -3366,8 +3300,8 @@ void GenShapedSHBExcitation_ivas_enc_fx( move16(); } } - // preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); - PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc + + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc } ELSE { @@ -3392,9 +3326,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( Scale_sig( exc16kWhtnd, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); // Q_bwe_exc - PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc - /* i/o: exc16kWhtnd (Q_bwe_exc) */ - /* i/o: tbe_premph (Q_bwe_exc) */ + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc } ELSE { @@ -3475,9 +3407,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( temp = div_s( temp, temp2 ); /* Q15 */ temp = mult_r( PREEMPH_FAC, temp ); - PREEMPH_FX( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc - /* exc16kWhtnd: Q_bwe_exc; - tbe_premph: Q_bwe_exc*/ + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc } } } @@ -4006,8 +3936,8 @@ void GenShapedSHBExcitation_ivas_dec_fx( /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; move16(); - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); // Q5 - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); // Q5 + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); // Q5 + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); // Q5 L_tmp = L_deposit_l( 0 ); tmp = add( *Q_bwe_exc, 1 ); @@ -4393,8 +4323,8 @@ void GenShapedSHBExcitation_ivas_dec_fx( move16(); } } - // preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph); - PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); + + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); } ELSE { @@ -4414,9 +4344,7 @@ void GenShapedSHBExcitation_ivas_dec_fx( exc16kWhtnd[k] = mult_r_sat( White_exc16k[k], scale ); move16(); } - PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); - /* i/o: exc16kWhtnd (Q_exc16kWhtnd) */ - /* i/o: tbe_premph (Q_exc16kWhtnd) */ + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_exc16kWhtnd } ELSE { @@ -4496,9 +4424,7 @@ void GenShapedSHBExcitation_ivas_dec_fx( temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ temp = div_s( temp, temp2 ); /* Q15 */ temp = mult_r( PREEMPH_FAC, temp ); - PREEMPH_FX( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); - /* exc16kWhtnd: Q_exc16kWhtnd; - tbe_premph: Q_exc16kWhtnd*/ + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_exc16kWhtnd } } } @@ -4966,7 +4892,6 @@ void ScaleShapedSHB_fx( } } - Q_gFr_norm = norm_l( frame_gain ); if ( frame_gain == 0 ) { @@ -5204,19 +5129,19 @@ void ScaleShapedSHB_fx32( *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16 *overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ - const Word16 *subgain, /* i : subframe gain Q15*/ - const Word32 frame_gain, /* i : frame gain Q18 */ - const Word16 *win, /* i : window Q15*/ - const Word16 *subwin, /* i : subframes window Q15*/ - const Word16 Q_bwe_exc, - Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ - Word16 *Qx, /* o : newly computed Q factor for synSHB */ - Word16 prev_Qx, /* i : prev_Qx for memory scaling */ - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal Q_bwe_exc/Qx*/ + Word16 *overlap, /* i/o: buffer for overlap-add Q_bwe_exc/Qx*/ + const Word16 *subgain, /* i : subframe gain Q15*/ + const Word32 frame_gain, /* i : frame gain Q18*/ + const Word16 *win, /* i : window Q15*/ + const Word16 *subwin, /* i : subframes window Q15*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ) { const Word16 *skip; @@ -5226,6 +5151,7 @@ void ScaleShapedWB_fx( Word16 sum_gain; Word32 L_tmp; Word16 max_val, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; + /* Init */ set32_fx( mod_syn, 0, L_FRAME16k + L_SHB_LAHEAD ); @@ -5323,7 +5249,6 @@ void ScaleShapedWB_fx( } } - max_val = 0; move16(); FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) @@ -5425,6 +5350,7 @@ void ScaleShapedWB_fx( return; } + /*-------------------------------------------------------------------* * non_linearity() * @@ -5433,7 +5359,7 @@ void ScaleShapedWB_fx( static Word32 non_linearity_scaled_copy( const Word16 input[], - Word16 j, + const Word16 j, const Word16 length, Word32 output[], Word32 prev_scale, @@ -5443,7 +5369,6 @@ static Word32 non_linearity_scaled_copy( Word16 i; Word32 L_tmp; - IF( en_abs ) { FOR( i = 0; i < j; i++ ) @@ -5495,6 +5420,7 @@ static Word32 non_linearity_scaled_copy( move32(); } } + return prev_scale; } @@ -5502,12 +5428,12 @@ static Word32 non_linearity_scaled_copy( /*-------------------------------------------------------------------* * non_linearity() * - * Apply a non linearity to the SHB excitation + * Apply a non linearity to the SHB excitation in IVAS formats * -------------------------------------------------------------------*/ static Word32 non_linearity_scaled_copy_ivas( const Word16 input[], - Word16 j, + const Word16 j, const Word16 length, Word32 output[], Word32 prev_scale, @@ -5517,7 +5443,6 @@ static Word32 non_linearity_scaled_copy_ivas( Word16 i; Word32 L_tmp; - IF( en_abs ) { FOR( i = 0; i < j; i++ ) @@ -5605,6 +5530,7 @@ static Word32 non_linearity_scaled_copy_ivas( move32(); } } + return prev_scale; } @@ -5631,15 +5557,15 @@ static Word32 non_linearity_scaled_copy_ivas( /*==========================================================================*/ void non_linearity_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32 *pPrevScale, /* i/o: memory Q30 */ - Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ - + const Word16 element_mode, /* i : element mode */ + const Word16 input[], /* i : input signal Q_inp */ + Word32 output[], /* o : output signal 2*Q_inp */ + const Word16 length, /* i : input length */ + Word32 *pPrevScale, /* i/o: memory Q30 */ + const Word16 Q_inp, /* i : scaling of input */ + const Word16 coder_type, /* i : Coder Type */ + Word16 *voice_factors, /* i : Voice Factors */ + const Word16 L_frame /* i : ACELP frame length */ ) { Word16 i, j; @@ -5661,23 +5587,24 @@ void non_linearity_fx( Word16 nframes; Word32 prev_scale; Word16 length_half; + Word16 sc_factor; + Word32 prev_scale_factor; IF( EQ_16( L_frame, L_FRAME16k ) ) { - nframes = 5; + nframes = NB_SUBFR16k; move16(); ths = 17817; move16(); /* 0.87*5 in Q12 */ } ELSE { - nframes = 4; + nframes = NB_SUBFR; move16(); ths = 15400; move16(); /* 0.94*4 in Q12 */ } - FOR( i = 0; i < nframes; i++ ) { v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */ @@ -5694,7 +5621,6 @@ void non_linearity_fx( prev_scale = *pPrevScale; move32(); - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ FOR( i = j = 0; i < length_half; i++ ) @@ -5708,8 +5634,7 @@ void non_linearity_fx( max_val = s_max( max_val, tmp ); } - - IF( GT_16( max_val, shl( 1, Q_inp ) ) ) + IF( GT_16( max_val, shl_sat( 1, Q_inp ) ) ) { exp = norm_s( max_val ); tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ @@ -5721,251 +5646,19 @@ void non_linearity_fx( move32(); /* Q31; 0.67 in Q31 */ } - test(); - IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ) ) - { - scale_step = 16384; - move16(); /* Q14 */ - prev_scale = L_shr( scale, 1 ); /* Q30 */ - } - ELSE - { - - /* Computing log2(scale) */ - IF( j == 0 ) - { - scale_step = 32767; - move16(); - } - ELSE - { - e_tmp = norm_l( scale ); - f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub( -1, e_tmp ); - L_tmp = Mpy_32_16( e_tmp, f_tmp, MAX_16 ); /* Q16 */ - - /* Computing log2(prev_scale) */ - e_tmp = norm_l( prev_scale ); - f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate( e_tmp ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, MAX_16 ); /* Q16 */ - - /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ - L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ - - /* Computing 1/j */ - exp = norm_s( j ); - tmp = div_s( shl( 1, sub( 14, exp ) ), j ); /* Q(29-exp) */ - - /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - tmp = extract_l( Pow2( 14, frac ) ); - scale_step = shl_sat( tmp, exp ); /* Q14 */ - } - } - - prev_scale = non_linearity_scaled_copy( input, j, length_half, output, prev_scale, scale_step, en_abs ); - - max_val = 0; - move16(); - j = shr( length, 1 ); - FOR( i = length_half; i < length; i++ ) - { - tmp = abs_s( input[i] ); - if ( GT_16( tmp, max_val ) ) - { - j = i; - move16(); - } - max_val = s_max( max_val, tmp ); - } - - IF( GT_16( max_val, shl( 1, Q_inp ) ) ) + IF( element_mode == EVS_MONO ) { - exp = norm_s( max_val ); - tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ - scale = L_shl_sat( L_mult( 21955 /* 0.67 in Q15 */, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ + prev_scale_factor = Mult_32_16( prev_scale, 32 ); } ELSE { - scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ + sc_factor = s_max( sub( 13, norm_s( add( j, 1 ) ) ), 0 ); /* Adapt the scaling factor allowed depending of max position */ + sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ + prev_scale_factor = L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ); /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ } test(); - IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ) ) - { - scale_step = 16384; - move16(); /*Q14 */ - prev_scale = L_shr( scale, 1 ); /*Q30 */ - } - ELSE - { - /*scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / prev_scale)); */ - /* Computing log2(scale) */ - IF( EQ_16( j, length_half ) ) - { - scale_step = 32767; - move16(); /*Q14 */ - } - ELSE - { - e_tmp = norm_l( scale ); - f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub( -e_tmp, 1 ); - L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ - - /* Computing log2(prev_scale) */ - e_tmp = norm_l( prev_scale ); - f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate( e_tmp ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ - - /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ - L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ - - /* Computing 1/(j - length/2) */ - tmp = sub( j, length_half ); - exp = norm_s( tmp ); - tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* Q(29-exp) */ - - /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - tmp = extract_l( Pow2( 14, frac ) ); - scale_step = shl_sat( tmp, exp ); /*Q14 */ - } - } - - prev_scale = non_linearity_scaled_copy( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); - - *pPrevScale = prev_scale; - move32(); - - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : void non_linearity_ivas_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Apply a non linearity to the SHB excitation */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 input[] i : input signal Q_inp */ -/* Word16 length i : input length */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word32 output[] o : output signal 2*Q_inp */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word32 *prev_scale i/o: memory Q30 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ - -void non_linearity_ivas_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32 *pPrevScale, /* i/o: memory Q30 */ - Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ - -) -{ - Word16 i, j; - Word16 max_val = 0; - move16(); - Word32 scale; - Word16 scale_step; - Word16 exp, tmp; - Word16 e_tmp, f_tmp; - Word16 frac; - Word32 L_tmp; - Word32 L_tmp1; - - Word16 en_abs = 0; - Word16 v_fac = 0; - move16(); - move16(); - Word16 ths; - Word16 nframes; - Word32 prev_scale; - Word16 length_half; - Word16 sc_factor; - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - nframes = 5; - move16(); - ths = 17817; - move16(); /* 0.87*5 in Q12 */ - } - ELSE - { - nframes = 4; - move16(); - ths = 15400; - move16(); /* 0.94*4 in Q12 */ - } - - - FOR( i = 0; i < nframes; i++ ) - { - v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */ - } - - test(); - if ( EQ_16( coder_type, VOICED ) && GT_16( v_fac, ths ) ) - { - en_abs = 1; - move16(); - } - - length_half = shr( length, 1 ); - prev_scale = *pPrevScale; - move32(); - - - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ - - FOR( i = j = 0; i < length_half; i++ ) - { - tmp = abs_s( input[i] ); - if ( GT_16( tmp, max_val ) ) - { - j = i; - move16(); - } - max_val = s_max( max_val, tmp ); - } - - - IF( GT_16( max_val, shl_sat( 1, Q_inp ) ) ) - { - exp = norm_s( max_val ); - tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ - scale = L_shl( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ - } - ELSE - { - scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ - } - - sc_factor = s_max( sub( 13, norm_s( add( j, 1 ) ) ), 0 ); /* Adapt the scaling factor allowed depending of max position */ - sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ - test(); - IF( prev_scale <= 0 || GT_32( L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ), scale /*Q31*/ ) ) /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ + IF( prev_scale <= 0 || ( GT_32( prev_scale_factor, scale /*Q31*/ ) ) ) { scale_step = 16384; move16(); /* Q14 */ @@ -5973,7 +5666,6 @@ void non_linearity_ivas_fx( } ELSE { - /* Computing log2(scale) */ IF( j == 0 ) { @@ -6010,7 +5702,14 @@ void non_linearity_ivas_fx( } } - prev_scale = non_linearity_scaled_copy_ivas( input, j, length_half, output, prev_scale, scale_step, en_abs ); + IF( element_mode == EVS_MONO ) + { + prev_scale = non_linearity_scaled_copy( input, j, length_half, output, prev_scale, scale_step, en_abs ); + } + ELSE + { + prev_scale = non_linearity_scaled_copy_ivas( input, j, length_half, output, prev_scale, scale_step, en_abs ); + } max_val = 0; move16(); @@ -6038,12 +5737,19 @@ void non_linearity_ivas_fx( move32(); /* Q31; 0.67 in Q31 */ } - /* if ( element_mode > EVS_MONO ) */ /* element mode is not needed because the function is duplicated for IVAS */ - sc_factor = s_max( sub( 12, norm_s( add( sub( j, length_half ), 1 ) ) ), 0 ); /* allowed intra frame jump is smaller */ - sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ + IF( element_mode == EVS_MONO ) + { + prev_scale_factor = Mult_32_16( prev_scale, 32 ); + } + ELSE + { + sc_factor = s_max( sub( 12, norm_s( add( sub( j, length_half ), 1 ) ) ), 0 ); /* allowed intra frame jump is smaller */ + sc_factor = s_max( sc_factor, 1 ); /* Note: The sc_factor is the log2 of the sc_factor in the float code to simplify condition below */ + prev_scale_factor = L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ); /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ + } test(); - IF( prev_scale <= 0 || GT_32( L_shr( prev_scale, sub( sc_factor, 1 ) /*Q30 -> Q31*/ ), scale /*Q31*/ ) ) /* Since the sc_factor is the log2 of sc_factor in float, we apply it using L_shr */ + IF( prev_scale <= 0 || ( GT_32( prev_scale_factor, scale /*Q31*/ ) ) ) { scale_step = 16384; move16(); /*Q14 */ @@ -6087,7 +5793,14 @@ void non_linearity_ivas_fx( } } - prev_scale = non_linearity_scaled_copy_ivas( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); + IF( element_mode == EVS_MONO ) + { + prev_scale = non_linearity_scaled_copy( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); + } + ELSE + { + prev_scale = non_linearity_scaled_copy_ivas( input + length_half, sub( j, length_half ), sub( length, length_half ), output + length_half, prev_scale, scale_step, en_abs ); + } *pPrevScale = prev_scale; move32(); @@ -6109,25 +5822,71 @@ void non_linearity_ivas_fx( void create_random_vector_fx( Word16 output[], /* o : output random vector Q5*/ const Word16 length, /* i : length of random vector */ - Word16 seed[] /* i/o: start seed */ + Word16 seed[], /* i/o: start seed */ + Word16 element_mode /* i : element mode */ ) { Word16 i, j, k; Word16 scale1, scale2; Word32 L_tmp; + /* + Note: the constant 2144047674 is 0.0078f in Q38 from the float reference. + It should read 0.0078125f, which is 1/128.Since 0.0078f is nor exactly + depictable in fixed point, rounding has to be performed to get the same + j and k values for any input (e.g. if Random() returns 5000) + */ + +#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT + if ( element_mode != EVS_MONO ) + { + j = shr( abs_s( Random( &seed[0] ) ), 7 ); /* Random( &seed[0] * 0.0078125f ) */ + } + else + { + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ + j = extract_l( L_shr( L_tmp, 23 ) ); + } +#else L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ j = extract_l( L_shr( L_tmp, 23 ) ); +#endif j = s_and( j, 0xff ); +#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT + if ( element_mode != EVS_MONO ) + { + k = shr( abs_s( Random( &seed[1] ) ), 7 ); /* Random( &seed[0] * 0.0078125f ) */ + } + else + { + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + k = extract_l( L_shr( L_tmp, 23 ) ); + } +#else L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ k = extract_l( L_shr( L_tmp, 23 ) ); +#endif + k = s_and( k, 0xff ); WHILE( EQ_16( k, j ) ) { +#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT + if ( element_mode != EVS_MONO ) + { + k = shr( abs_s( Random( &seed[1] ) ), 7 ); + } + else + { + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + k = extract_l( L_shr( L_tmp, 23 ) ); + } +#else L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ k = extract_l( L_shr( L_tmp, 23 ) ); +#endif + k = s_and( k, 0xff ); } @@ -6261,6 +6020,7 @@ void interp_code_5over2_fx( Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ move16(); + return; } @@ -6488,7 +6248,6 @@ void elliptic_bpf_48k_generic_fx( } /*IsUpsampled3*/ - memory_fx2[0][0] = input_fx[L_FRAME48k - 4]; memory_fx2[0][1] = input_fx[L_FRAME48k - 3]; memory_fx2[0][2] = input_fx[L_FRAME48k - 2]; @@ -6536,7 +6295,6 @@ void elliptic_bpf_48k_generic_fx( } } - Q_temp = norm_l( L_tmpMax ); Q_temp = sub( Q_temp, 4 ); Scale_sig32( L_tmp2, 960, Q_temp ); @@ -6598,7 +6356,6 @@ void elliptic_bpf_48k_generic_fx( } } - memory_fx2[2][0] = L_tmp2[L_FRAME48k - 4]; memory_fx2[2][1] = L_tmp2[L_FRAME48k - 3]; memory_fx2[2][2] = L_tmp2[L_FRAME48k - 2]; @@ -6636,6 +6393,8 @@ void elliptic_bpf_48k_generic_fx( return; } + + /*-------------------------------------------------------------------* * synthesise_fb_high_band() * @@ -6692,20 +6451,12 @@ void synthesise_fb_high_band_fx( IF( EQ_16( L_frame, L_FRAME16k ) ) { /* for 16kHz ACELP core */ - elliptic_bpf_48k_generic_fx( - element_mode, - 1, // IsUpsampled3 - excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_3_fx - - ); + elliptic_bpf_48k_generic_fx( element_mode, 1, /* IsUpsampled3 */ excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_3_fx ); } ELSE { /* for 12.8kHz ACELP core */ - elliptic_bpf_48k_generic_fx( - element_mode, - 1, // IsUpsampled3 - excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_1_fx ); + elliptic_bpf_48k_generic_fx( element_mode, 1, /* IsUpsampled3 */ excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_1_fx ); } /* temp1 = sum2_f( tmp, L_FRAME48k ) + 0.001f */ temp1 = sum2_fx_mod( tmp, L_FRAME48k ); @@ -6788,15 +6539,18 @@ void synthesise_fb_high_band_fx( move16(); } } + return; } + /*-------------------------------------------------------------------* * Estimate_mix_factors_fx() * * * * Estimate mix factors for SHB excitation generation * *-------------------------------------------------------------------*/ -void Estimate_mix_factors_fx( + +static void Estimate_mix_factors_fx( const Word16 *shb_res, /* i : SHB LP residual in Q = Q_shb */ const Word16 Q_shb, const Word16 *exc16kWhtnd, /* i : SHB transformed low band excitation Q_bwe_exc */ @@ -6860,7 +6614,6 @@ void Estimate_mix_factors_fx( /* (Q_bwe_exc) */ } - length = L_FRAME16k; move16(); temp_p1_p2 = Dot_product( temp_numer1, temp_numer2, length ); /* 2*(Q_bwe_exc)+1 */ @@ -6936,6 +6689,7 @@ void Estimate_mix_factors_fx( return; } + /*======================================================================================*/ /* FUNCTION : prep_tbe_exc_fx() */ /*--------------------------------------------------------------------------------------*/ @@ -6985,7 +6739,6 @@ void prep_tbe_exc_fx( const Word16 idchan, /* i : channel ID */ const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ - ) { Word16 i; diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 4eb334205f5230fce05a392f84970bacb68586f5..29febbbfc0ba569368b8fa6ace26bdcf9756765a 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -401,9 +401,14 @@ void predict_signal( x0--; } - win = &inter4_2tcx2[frac][0]; /* Q15 */ - if ( EQ_16( frac_max, 6 ) ) + IF( EQ_16( frac_max, 6 ) ) + { win = &inter6_2tcx2[frac][0]; /* Q15 */ + } + ELSE + { + win = &inter4_2tcx2[frac][0]; /* Q15 */ + } FOR( j = 0; j < L_subfr; j++ ) { diff --git a/lib_com/tcx_mdct_window_fx.c b/lib_com/tcx_mdct_window_fx.c index 942eb15fabd5de8f0445e030f008693663ab6b77..dd3ad48feedb75dd5440e59510b8e76c4966b882 100644 --- a/lib_com/tcx_mdct_window_fx.c +++ b/lib_com/tcx_mdct_window_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,7 +37,6 @@ #include #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index f73fb5971b38de11530493d3bdd92d6df7fdd6ea..44c034a20ac0c3ea1e8572bbdf63954cb4c9dbf4 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1973,6 +1973,7 @@ void tcx_noise_filling_with_shift( *--------------------------------------------------------------*/ +#ifndef FIX_2388_INITTNSCONFIGURATION void InitTnsConfigs( const Word16 bwidth, /*Q0*/ const Word16 L_frame, /*Q0*/ @@ -1989,22 +1990,37 @@ void InitTnsConfigs( InitTnsConfiguration( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); InitTnsConfiguration( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); } - -void InitTnsConfigs_ivas_fx( - const Word16 bwidth, /*Q0*/ - const Word16 L_frame, /*Q0*/ - STnsConfig tnsConfig[2][2], - const Word16 igfStopFreq, /*Q0*/ - const Word32 total_brate, /*Q0*/ - const Word16 element_mode, /*Q0*/ - const Word16 MCT_flag /*Q0*/ ) +#endif + +#ifdef FIX_2388_INITTNSCONFIGURATION +void InitTnsConfigs_fx +#else +void InitTnsConfigs_ivas_fx +#endif + ( + const Word16 bwidth, /*Q0*/ + const Word16 L_frame, /*Q0*/ + STnsConfig tnsConfig[2][2], + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { IF( GT_32( total_brate, ACELP_32k ) ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfiguration_fx( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); +#else InitTnsConfiguration_ivas_fx( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); +#endif } +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfiguration_fx( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); + InitTnsConfiguration_fx( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); +#else InitTnsConfiguration_ivas_fx( bwidth, L_frame, &tnsConfig[1][0], igfStopFreq, total_brate, element_mode, MCT_flag ); InitTnsConfiguration_ivas_fx( bwidth, add( L_frame, shr( L_frame, 2 ) ), &tnsConfig[1][1], igfStopFreq, total_brate, element_mode, MCT_flag ); +#endif } void SetTnsConfig( diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c old mode 100755 new mode 100644 index 600b2e6fe9b03a725b1673a09f2db93a39e903a7..8c79d885f2a9c45228e992c246f30e746444df00 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -72,6 +72,7 @@ static void ITF_GetFilterParameters_fx( Word32 rxx[], const Word16 maxOrder, Wor /* Interface functions */ /********************************/ +#ifndef FIX_2388_INITTNSCONFIGURATION /** Init TNS configuration. * Fills STnsConfig structure with sensible content. * @param nSampleRate Sampling rate of the input. @@ -196,15 +197,21 @@ void InitTnsConfiguration( } return; /*TNS_NO_ERROR;*/ } - -void InitTnsConfiguration_ivas_fx( - const Word16 bwidth, /*Q0*/ - const Word16 frameLength, /*Q0*/ - STnsConfig *pTnsConfig, - const Word16 igfStopFreq, /*Q0*/ - const Word32 total_brate, /*Q0*/ - const Word16 element_mode, /*Q0*/ - const Word16 is_mct /*Q0*/ ) +#endif /* FIX_2388_INITTNSCONFIGURATION */ + +#ifdef FIX_2388_INITTNSCONFIGURATION +void InitTnsConfiguration_fx +#else +void InitTnsConfiguration_ivas_fx +#endif /* FIX_2388_INITTNSCONFIGURATION */ + ( + const Word16 bwidth, /*Q0*/ + const Word16 frameLength, /*Q0*/ + STnsConfig *pTnsConfig, + const Word16 igfStopFreq, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 is_mct /*Q0*/ ) { Word16 iFilter = 0; move16(); @@ -235,7 +242,11 @@ void InitTnsConfiguration_ivas_fx( IF( LE_32( total_brate, ACELP_32k ) ) { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ +#ifdef FIX_2388_INITTNSCONFIGURATION + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParametersIGF32kHz_LowBR ) / sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ +#else + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ +#endif pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } ELSE @@ -243,7 +254,11 @@ void InitTnsConfiguration_ivas_fx( test(); IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) { - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ +#ifdef FIX_2388_INITTNSCONFIGURATION + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters48kHz_grouped ) / sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ +#else + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters48kHz_grouped ), sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ +#endif move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } @@ -259,7 +274,11 @@ void InitTnsConfiguration_ivas_fx( test(); IF( GT_16( element_mode, IVAS_SCE ) && GE_32( total_brate, L_tmp ) ) { - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ +#ifdef FIX_2388_INITTNSCONFIGURATION + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters32kHz_Stereo ) / sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ +#else + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz_Stereo ), sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ +#endif move16(); IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { @@ -274,7 +293,11 @@ void InitTnsConfiguration_ivas_fx( { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ +#ifdef FIX_2388_INITTNSCONFIGURATION + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters32kHz ) / sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ +#else + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ +#endif pTnsConfig->pTnsParameters = tnsParameters32kHz; @@ -289,13 +312,21 @@ void InitTnsConfiguration_ivas_fx( IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); +#ifdef FIX_2388_INITTNSCONFIGURATION + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters16kHz_grouped ) / sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ +#else pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ +#endif pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } ELSE { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ +#ifdef FIX_2388_INITTNSCONFIGURATION + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters16kHz ) / sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ +#else + pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ +#endif pTnsConfig->pTnsParameters = tnsParameters16kHz; } } diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 66dde5a95db1fc1f5adb9e0e40115fb8f1e157f3..cd5ad9667d9fd56c238f1809e5e46a7978e5d686 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -39,7 +39,6 @@ #include #include "options.h" #include "stl.h" -#include #include "cnst.h" #include "prot_fx.h" #include "basop_util.h" diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index 4e259e0cc5076d1d74b4a16d3ed1410fdad505f4..c84cd9efad4c495df32efee54db2a27c02a2faa0 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -76,14 +76,13 @@ void direct_transform_fx( move32(); } - iseg_fx = &in32_r16_fx[-segment_length4]; /*Q*/ - oseg_fx = out32_fx; /*Q*/ + oseg_fx = out32_fx; /*Q*/ wh_fx = &win_fx[segment_length4]; /*Q15*/ wl_fx = wh_fx - 1; /*Q15*/ shift = extract_l( L_mult0( 3, segment_length4 ) ); /*Q0*/ - sh_fx = &iseg_fx[shift]; /*Q*/ + sh_fx = &in32_r16_fx[segment_length2]; /*Q*/ sl_fx2 = sh_fx - 1; /*Q*/ @@ -94,7 +93,7 @@ void direct_transform_fx( move32(); } - sl_fx2 = &iseg_fx[( segment_length2 - 1 )]; /*Q*/ + sl_fx2 = &in32_r16_fx[( segment_length4 - 1 )]; /*Q*/ FOR( i = segment_length4; i < segment_length2; i++ ) { @@ -107,7 +106,7 @@ void direct_transform_fx( edct_fx( dctin32_fx, oseg_fx, segment_length2, &Qs[0] ); Qmin = s_min( Qs[0], Qmin ); - iseg_fx += segment_length2; + iseg_fx = &in32_r16_fx[segment_length4]; oseg_fx += segment_length2; FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) diff --git a/lib_com/trans_inv_fx.c b/lib_com/trans_inv_fx.c index 8bf63fccac0734f9e46e5332ae9ba842825e42ea..34d424f26e0bcdebff96c44bcc3584ff2f2f725c 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -1032,7 +1032,7 @@ void Inverse_Transform( } } - out_segment = out_alias - segment_length_div4; + out_segment = out_alias; in_segment = in_mdct_modif; /*Q*/ tmp = *Q; @@ -1051,7 +1051,7 @@ void Inverse_Transform( FOR( ta = segment_length_div4; ta < segment_length_div2; ta++ ) { - out_segment[ta] = L_shr( alias[ta], tmp ); /*q_out*/ + *out_segment++ = L_shr( alias[ta], tmp ); /*q_out*/ move32(); } /* This previous loop fills the output buffer from [0..seg_len_div4-1] */ @@ -1059,13 +1059,13 @@ void Inverse_Transform( win2 = &win[segment_length_div2]; /*Q15*/ FOR( ta = segment_length_div2; ta < segment_length; ta++ ) { - out_segment[ta] = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); /*q_out*/ + *out_segment++ = L_shr( Mult_32_16( alias[ta], *--win2 ), tmp ); /*q_out*/ move32(); } /* This previous loop fills the output buffer from [seg_len_div4..seg_len-seg_len_div4-1] */ - out_segment += segment_length_div2; /*q_out*/ - in_segment += segment_length_div2; /*Q*/ + out_segment = &out_alias[segment_length_div4]; /*q_out*/ + in_segment += segment_length_div2; /*Q*/ FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS - 1; seg++ ) { diff --git a/lib_debug/debug.c b/lib_debug/debug.c index f9b0e34c3d44bbbfc4c40ae16464fc3dfa83caac..59ca6252eee2afbbfdd03ee7c96f23e10d99f7b4 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_debug/debug.h b/lib_debug/debug.h index c79ff60465cf7fc043aff2930846e853c02edde2..5d905d0e467e61ac787397982da38c6a3a0e9880 100644 --- a/lib_debug/debug.h +++ b/lib_debug/debug.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -70,6 +70,9 @@ char *fname( char *dir, char *file, const int16_t n, const int16_t id, const int #define FORCE_DIR_MAX_LENGTH 255 /* maximum length of the directory for modes/parameters enforcement */ #endif +#define MAX16B_FLT 32767.0f +#define MIN16B_FLT ( -32768.0f ) + /*------------------------------------------------------------------------------------------* * Read/write I/O tool *------------------------------------------------------------------------------------------*/ diff --git a/lib_debug/sba_debug.c b/lib_debug/sba_debug.c index c05ae96ef6279111db026a5dadff58fa2ce72045..5f7e846ae1bd166a5354b72507356e9a570f0bb2 100644 --- a/lib_debug/sba_debug.c +++ b/lib_debug/sba_debug.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,6 +38,7 @@ #include "options.h" #include "ivas_cnst.h" #include "sba_debug.h" +#include "debug.h" #include #include "wmc_auto.h" #ifdef DEBUG_SBA diff --git a/lib_debug/sba_debug.h b/lib_debug/sba_debug.h index 2be427d524e82f92deec2ab9e8c0964374474dab..850e7ab67460da4f0aace38de4956e4772be23ff 100644 --- a/lib_debug/sba_debug.h +++ b/lib_debug/sba_debug.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_debug/snr.c b/lib_debug/snr.c index cf15a2907b50dec0580121c2773f91191c8b4afc..743a632a609ae7e4b3170cd43e0dec193aa6e207 100644 --- a/lib_debug/snr.c +++ b/lib_debug/snr.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index 5afd9de166568531c15df05978d588430d1cad77..5a14edc319a07ee916125b725776c9d9ad8bb65a 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -820,7 +820,6 @@ static void *mem_alloc_block( size_t size, const char *size_str ); void reset_mem( Counting_Size cnt_size ) { - int16_t something; size_t tmp_size; /* initialize list of stack records */ @@ -840,7 +839,13 @@ void reset_mem( Counting_Size cnt_size ) max_num_calls = MAX_NUM_RECORDS; /* initialize stack pointers */ +#if defined( __GNUC__ ) || defined( __clang__ ) + /* GCC/Clang: use builtin (works for many targets) */ + ptr_base_stack = __builtin_frame_address( 0 ); +#else + int16_t something; ptr_base_stack = &something; +#endif ptr_max_stack = ptr_base_stack; ptr_current_stack = ptr_base_stack; @@ -945,10 +950,14 @@ void reset_mem( Counting_Size cnt_size ) void reset_stack( void ) { - int16_t something; - /* initialize/reset stack pointers */ +#if defined( __GNUC__ ) || defined( __clang__ ) + /* GCC/Clang: use builtin (works for many targets) */ + ptr_base_stack = __builtin_frame_address( 0 ); +#else + int16_t something; ptr_base_stack = &something; +#endif ptr_max_stack = ptr_base_stack; ptr_current_stack = ptr_base_stack; @@ -963,10 +972,15 @@ void reset_stack( void ) int push_stack( const char *filename, const char *fctname ) { - int16_t something; int32_t current_stack_size; +#if defined( __GNUC__ ) || defined( __clang__ ) + /* GCC/Clang: use builtin (works for many targets) */ + ptr_current_stack = __builtin_frame_address( 0 ); +#else + int16_t something; ptr_current_stack = &something; +#endif (void) *filename; /* to avoid compilation warning */ diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index 60269751b1da0ff3c090390a467677449519fc6d..9b6ac8434f6235b4fd38a4c91d051cfdcf0748c9 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -614,6 +614,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( move16(); s = 0; move16(); + /* Main Loop through the 2-tuples */ FOR( k = 0; k < lastnz; k += 2 ) { @@ -701,9 +702,9 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( c = add( 12, esc_nb ); } - s = (UWord16) L_shl( s, 4 ); /*Shift old 4 bits*/ - s = (UWord16) L_add( s, c ); /*replace last 4 bits*/ - t = (UWord16) L_and( s, 0xFF ); + s = shl( s_and( s, 0x0F ), 4 ); /*Shift old 4 bits*/ + s = add( s, c ); /*replace last 4 bits*/ + t = s_and( s, 0xFF ); } /* Decode signs */ diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 43d1e26276cd38025a1f819bc580aa761ea3ec8d..641f6005913ec14383212465558f765c5cd7975c 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -399,285 +399,6 @@ void HQ_FEC_processing_fx( return; } -void ivas_HQ_FEC_Mem_update_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /*Q12*/ - Word32 *normq_fx, /*Q14*/ - Word16 *ynrm, - Word16 *Num_bands_p, - Word16 is_transient, - Word16 hqswb_clas, - Word16 c_switching_flag, - Word16 nb_sfm, - Word16 num_Sb, - Word16 *mean_en_high_fx, /*Q5*/ - Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ - Word16 output_frame ) -{ - Word16 Min_ind; - Word32 Min_value; - Word16 Max_ind; - Word16 stat_mode_curr; - - Word16 i, j, k; - Word16 offset; - Word16 exp, exp1, exp2, tmp_fx; - Word32 *norm_values_fx; // Q12 - Word32 L_tmp, tmp_energy_fx = 0 /*Q8*/, Max_coeff_fx /*Q12*/; - Word32 en_high_fx[MAX_SB_NB]; // Q12 - HQ_NBFEC_HANDLE hHQ_nbfec; - HQ_DEC_HANDLE hHQ_core; - hHQ_nbfec = st_fx->hHQ_nbfec; - hHQ_core = st_fx->hHQ_core; - move32(); // for tmp_energy_fx - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - - IF( is_transient ) - { - set16_fx( hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM ); - set16_fx( hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM ); - } - ELSE - { - FOR( j = 0; j < HQ_FEC_SIGN_SFM; j++ ) - { - hHQ_nbfec->prev_sign_switch[j] = hHQ_nbfec->prev_sign_switch_2[j]; - move16(); - hHQ_nbfec->prev_sign_switch_2[j] = 0; - move16(); - - FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) - { - test(); - test(); - test(); - IF( ( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE] > 0 && t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE] < 0 ) || ( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE] < 0 && t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE] > 0 ) ) - { - hHQ_nbfec->prev_sign_switch[j] = add( hHQ_nbfec->prev_sign_switch[j], 1 ); - move16(); - hHQ_nbfec->prev_sign_switch_2[j] = add( hHQ_nbfec->prev_sign_switch_2[j], 1 ); - move16(); - } - } - } - } - /* if LR MDCT core is used, recalculate norms from decoded MDCT spectrum (using code from hq_hr_enc_fx()) */ - test(); - IF( ( EQ_16( hqswb_clas, HQ_HVQ ) ) || ( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) ) - { - /* First group */ - logqnorm_fx( t_audio_q_fx, 12, ynrm, 32, WID_G1, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); - j = ynrm[0]; - move16(); - offset = WID_G1; - move16(); - - FOR( i = 1; i < SFM_G1; i++ ) - { - logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G1, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); - offset = add( offset, WID_G1 ); - } - - /* Second group */ - FOR( i = SFM_G1; i < SFM_G1 + 2; i++ ) - { - logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G2, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); - offset = add( offset, WID_G2 ); - } - } - - /* Memory update for the LGF log2 Norm */ - FOR( i = 0; i < nb_sfm; i++ ) - { - normq_fx[i] = dicn_fx[ynrm[i]]; - move32(); - } - k = 0; - move16(); - FOR( i = 0; i < num_Sb; i++ ) - { - norm_values_fx = &hHQ_nbfec->ynrm_values_fx[i][0]; - Copy32( norm_values_fx, &norm_values_fx[1], MAX_PGF - 1 ); - - L_tmp = L_deposit_l( 0 ); - FOR( j = 0; j < Num_bands_p[i]; j++ ) - { - L_tmp = L_add( L_tmp, L_shr( normq_fx[k], 3 ) ); /*11*/ - k = add( k, 1 ); - } - tmp_fx = shl_sat( inv_tbl_fx[Num_bands_p[i]], 1 ); /*16*/ - norm_values_fx[0] = Mult_32_16( L_tmp, tmp_fx ); /*11 + 16 - 15*/ - move32(); - tmp_energy_fx = L_add( tmp_energy_fx, L_shr( L_tmp, 3 ) ); /*8*/ - } - test(); - test(); - IF( ( c_switching_flag ) || ( ( st_fx->last_core == ACELP_CORE ) && ( EQ_16( st_fx->core, HQ_CORE ) ) ) ) - { - FOR( i = 0; i < MAX_SB_NB; i++ ) - { - FOR( j = 1; j < MAX_PGF; j++ ) - { - hHQ_nbfec->ynrm_values_fx[i][j] = hHQ_nbfec->ynrm_values_fx[i][0]; - move32(); - } - } - } - set16_fx( hHQ_nbfec->Norm_gain_fx, 32767, SFM_N_NB ); /*15*/ - /* st->energy_MA_Curr[1]=Energy of the current frame */ - tmp_fx = inv_tbl_fx[nb_sfm]; - move16(); /*15*/ - L_tmp = Mult_32_16( tmp_energy_fx, tmp_fx ); /*8 + 15 - 15*/ - - hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl( L_tmp, 16 - 8 ) ); - move16(); - /* Moving Average */ - hHQ_nbfec->energy_MA_Curr_fx[0] = s_max( 1, add( mult_r( 26214, hHQ_nbfec->energy_MA_Curr_fx[0] ), mult_r( 6554, hHQ_nbfec->energy_MA_Curr_fx[1] ) ) ); - move16(); - - /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ - hHQ_nbfec->diff_energy_fx = abs_s( sub( hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0] ) ); - move16(); - exp1 = sub( norm_l( hHQ_nbfec->diff_energy_fx ), 1 ); - exp2 = norm_l( hHQ_nbfec->energy_MA_Curr_fx[0] ); - hHQ_nbfec->diff_energy_fx = div_s( extract_h( L_shl( hHQ_nbfec->diff_energy_fx, exp1 ) ), extract_h( L_shl( hHQ_nbfec->energy_MA_Curr_fx[0], exp2 ) ) ); - move16(); - exp = add( 15, sub( exp1, exp2 ) ); - hHQ_nbfec->diff_energy_fx = shl( hHQ_nbfec->diff_energy_fx, sub( 11, exp ) ); /*11*/ - move16(); - - /* Classify the stationary mode : 12% */ - IF( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_12P_fx ) ) - { - stat_mode_curr = 1; - move16(); - } - ELSE - { - stat_mode_curr = 0; - move16(); - } - - /* Apply Hysteresis to prevent frequent mode changing */ - if ( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) - { - hHQ_nbfec->stat_mode_out = stat_mode_curr; - move16(); - } - - hHQ_nbfec->stat_mode_old = stat_mode_curr; - move16(); - - /* Find max. band index (Minimum value means maximum energy) */ - Min_ind = 0; - move16(); - Min_value = L_deposit_l( 100 ); - FOR( i = 0; i < num_Sb; i++ ) - { - IF( GT_32( Min_value, ynrm[i] ) ) - { - Min_value = ynrm[i]; - move16(); - Min_ind = i; - move16(); - } - } - - /* Find max. coeff in band 0 */ - Max_ind = 0; - move16(); - IF( Min_ind == 0 ) - { - Max_coeff_fx = L_deposit_l( 0 ); - FOR( i = 0; i < 8; i++ ) - { - L_tmp = L_abs( t_audio_q_fx[i] ); // Q12 - IF( LT_32( Max_coeff_fx, L_tmp ) ) - { - Max_coeff_fx = L_add( L_tmp, 0 ); - Max_ind = i; - move16(); - } - } - } - - /* Find energy difference from band 16 */ - k = 1; - move16(); - - FOR( i = k; i < num_Sb; i++ ) - { - en_high_fx[i] = L_deposit_l( 0 ); - FOR( j = 0; j < 2; j++ ) - { - /*en_high[i] += 0.5f*st->ynrm_values[i][j+1];*/ - en_high_fx[i] = L_add( en_high_fx[i], L_shr( hHQ_nbfec->ynrm_values_fx[i][j + 1], 1 ) ); /*Q12*/ - move32(); - } - } - - *mean_en_high_fx = 0; - move16(); - FOR( i = k; i < num_Sb; i++ ) - { - /* *mean_en_high += (float)(en_high[i]/st->ynrm_values[i][0]);*/ - exp1 = sub( norm_l( en_high_fx[i] ), 1 ); - exp2 = norm_l( hHQ_nbfec->ynrm_values_fx[i][0] ); - tmp_fx = div_s( extract_h( L_shl( en_high_fx[i], exp1 ) ), extract_h( L_shl( hHQ_nbfec->ynrm_values_fx[i][0], exp2 ) ) ); - exp = add( 15, sub( exp1, exp2 ) ); - *mean_en_high_fx = add_sat( *mean_en_high_fx, shr_sat( tmp_fx, sub( exp, 5 ) ) ); - move16(); - } - *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[sub( num_Sb, k )] ); - move16(); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( LT_16( Min_ind, 5 ) ) && ( LT_16( abs_s( sub( Min_ind, hHQ_nbfec->old_Min_ind ) ), 2 ) ) && ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_90P_fx ) ) && ( !st_fx->bfi ) && ( !st_fx->prev_bfi ) && ( !st_fx->prev_old_bfi ) && ( !is_transient ) && ( !hHQ_core->old_is_transient[1] ) && ( EQ_16( hHQ_nbfec->prev_last_core, HQ_CORE ) ) && ( EQ_16( st_fx->last_core, HQ_CORE ) ) ) - { - hHQ_nbfec->phase_mat_flag = 1; - move16(); - test(); - if ( ( Min_ind == 0 ) && ( LT_16( Max_ind, 3 ) ) ) - { - hHQ_nbfec->phase_mat_flag = 0; - move16(); - } - } - ELSE - { - hHQ_nbfec->phase_mat_flag = 0; - move16(); - } - - hHQ_nbfec->old_Min_ind = Min_ind; - move16(); - - FOR( i = 0; i < L_FRAME8k; i++ ) - { - hHQ_nbfec->old_coeffs_fx[i] = t_audio_q_fx[i]; - move32(); - } - } - - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; - move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; - move16(); - hHQ_core->old_is_transient[0] = is_transient; - move16(); - - return; -} - void HQ_FEC_Mem_update_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 *t_audio_q_fx, /*Q12*/ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 958b8064dd6e701622ce10fa131cf5c17c18d638..07ebbcdb8e08342731d71ab89eaa2e290d67748e 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ ====================================================================================*/ #include #include -#include #include "options.h" #include "cnst.h" #include "rom_com.h" @@ -53,10 +52,18 @@ *-------------------------------------------------------------------*/ ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ - Word16 synth_fx16[], /* o : synthesis Q_syn2*/ - Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else + Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ +#endif + Word16 synth_fx16[], /* o : synthesis Q_syn2*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ +#else + Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ +#endif Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ @@ -75,7 +82,6 @@ ivas_error acelp_core_dec_fx( const Word16 read_sid_info /* i : read SID info flag */ ) { - Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/; Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ Word16 output_frame; /* frame length at output sampling freq. */ @@ -207,7 +213,11 @@ ivas_error acelp_core_dec_fx( Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ } - set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + set32_fx( output_fx32, 0, st->L_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ +#else + set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ +#endif set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ /* CN generation done in DFT domain */ @@ -969,7 +979,7 @@ ivas_error acelp_core_dec_fx( tmpF_fx = *old_exc_s_fx; st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */ move16(); - PREEMPH_FX( old_exc_s_fx, st->preemph_fac, st->L_frame, &tmpF_fx ); + preemph_fx( old_exc_s_fx, st->preemph_fac, st->L_frame, &tmpF_fx ); Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M ); Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); /* Q0 -> Q_syn */ Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 0 ); @@ -1036,7 +1046,7 @@ ivas_error acelp_core_dec_fx( test(); IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) { - int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } /*---------------------------------------------------------------* @@ -1897,6 +1907,7 @@ ivas_error acelp_core_dec_fx( st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); } + Word32 synth_fx[L_FRAME48k]; Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); syn_32_fx = syn_tmp_32_fx + L_SUBFR; @@ -2009,7 +2020,11 @@ ivas_error acelp_core_dec_fx( } } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( save_hb_synth_fx32 != NULL ) +#else IF( save_hb_synth_fx16 != NULL ) +#endif { /* save and then zero-out lowband */ max_real = 0; @@ -2050,7 +2065,13 @@ ivas_error acelp_core_dec_fx( } } - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx32, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); +#else + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*tmp buffer for save_hb_synth_fx[] */, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); + + Copy_Scale_sig_32_16( synth_fx, save_hb_synth_fx16, output_frame, 0 ); // Q0 +#endif /* restore lowband */ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -2104,7 +2125,7 @@ ivas_error acelp_core_dec_fx( } /* save synthesis - needed in case of core switching */ - Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 + Copy_Scale_sig_32_16( synth_fx, st->previoussynth_fx, output_frame, 0 ); // Q0 } ELSE { @@ -2193,11 +2214,16 @@ ivas_error acelp_core_dec_fx( /* Copy output signal */ Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_16_32_no_sat( psyn_fx, output_fx32, st->L_frame, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 +#else IF( st->element_mode > EVS_MONO ) { Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ } +#endif + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 st->Q_syn2 = 0; move16(); } @@ -2218,16 +2244,7 @@ ivas_error acelp_core_dec_fx( IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); - } - ELSE - { - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 - hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); - Copy_Scale_sig_16_32_DEPREC( synth_fx16, synth_fx, output_frame, 0 ); - } + hf_synth_fx( st->hBWE_zero, st->element_mode, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); } ELSE { @@ -2278,12 +2295,12 @@ ivas_error acelp_core_dec_fx( { IF( EQ_16( st->element_mode, EVS_MONO ) ) { - non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); } ELSE { Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), st->hBWE_TD->q_old_bwe_exc_extended_fx ) ) ); /* Q(q_old_bwe_exc_extended_fx) -> Q(2 * Q_exc) */ - non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); exp = sub( L_norm_arr( bwe_exc_extended_fx + L_FRAME32k, NL_BUFF_OFFSET ), 16 ); Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, exp ); /* Q(2 * Q_exc) -> Q(q_old_bwe_exc_extended_fx) */ st->hBWE_TD->q_old_bwe_exc_extended_fx = add( shl( st->Q_exc, 1 ), exp ); @@ -2310,17 +2327,8 @@ ivas_error acelp_core_dec_fx( IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, - st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); - } - ELSE - { - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, - st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, - st->hFdCngDec->hFdCngCom->CngBandwidth ); - } + cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); /* Set 16k LSP flag for CNG buffer */ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; @@ -2332,15 +2340,6 @@ ivas_error acelp_core_dec_fx( } } - IF( NE_16( st->element_mode, EVS_MONO ) ) - { - IF( save_hb_synth_fx16 ) - { - Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0 - } - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 - } - pop_wmops(); return error; } diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 2df489cc115889a8c470e271a0024175d44b0235..dd477874f1de42f56209d021d5f2a4edca6a9cde 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -360,6 +360,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( { Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ + Word32 syn32[L_FRAME16k]; /* synthesis signal buffer */ Word16 lsf_new[M]; /* LSFs at the end of the frame */ Word16 lsp_new[M]; /* LSPs at the end of the frame */ Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ @@ -378,16 +379,15 @@ ivas_error acelp_core_switch_dec_bfi_fx( Word32 tmp8; Word16 voice_factors[NB_SUBFR16k]; Word16 pitch_buf[NB_SUBFR16k]; - Word16 Q_exc; + Word16 Q_exc, Qtmp; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI]; Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; Word16 i; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128 * 3]; + Word32 synth32[L_FRAME48k]; MUSIC_POSTFILT_HANDLE hMusicPF; BPF_DEC_HANDLE hBPF; ivas_error error; - + Word16 Prev_Q_syn_r; hMusicPF = st_fx->hMusicPF; hBPF = st_fx->hBPF; error = IVAS_ERR_OK; @@ -404,6 +404,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ + Q_exc = st_fx->Q_exc; move16(); st_fx->bpf_off = 1; @@ -426,7 +427,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( exc2 = old_exc2 + L_EXC_MEM; IF( st_fx->hBWE_TD != NULL ) { - Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); // Q_exc + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); bwe_exc = old_bwe_exc + PIT16k_MAX * 2; } ELSE @@ -515,8 +516,14 @@ ivas_error acelp_core_switch_dec_bfi_fx( * Synthesis *-----------------------------------------------------------------*/ + Prev_Q_syn_r = st_fx->Q_syn; + move16(); Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn + } Copy( st_fx->mem_syn2_fx, tmp1, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp1, 1, Q_exc, st_fx->Q_syn ); @@ -527,6 +534,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( /*------------------------------------------------------------------* * Perform fixed deemphasis through 1/(1 - g*z^-1) *-----------------------------------------------------------------*/ + tmp1[0] = st_fx->mem_deemph_fx; move16(); /*if in acelp_core_dec_fx deemph_fx is used*/ /*tmp1 = shr(st_fx->mem_deemph_fx, sub(st_fx->Q_syn,1)); if in acelp_core_dec_fx Deemph2 is used*/ @@ -565,285 +573,68 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( tmp6, hBPF->vibrato_hist, L_TRACK_HIST ); hBPF->psf_att_fx = tmp7; move16(); - /*----------------------------------------------------------------* - * Resamping to the output sampling frequency - *----------------------------------------------------------------*/ - /* CLDFB analysis of the synthesis at internal sampling rate */ - IF( NE_32( ( error = cldfb_save_memory( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) - { - return error; - } - cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); - cldfb_restore_memory( st_fx->cldfbAna ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* CLDFB synthesis of the combined signal */ - IF( NE_32( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) - { - return error; - } - cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, - negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); - - /* output to Q0 */ - Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0 - - cldfb_restore_memory( st_fx->cldfbSyn ); - - return error; -} - -ivas_error acelp_core_switch_dec_bfi_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ -) -{ - Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ - Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ - Word32 syn32[L_FRAME16k]; /* synthesis signal buffer */ - Word16 lsf_new[M]; /* LSFs at the end of the frame */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ - Word16 old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ - Word16 tmp_noise; /* Long term temporary noise energy */ - Word16 FEC_pitch; /* FEC pitch */ - Word16 old_bwe_exc[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ - Word16 *bwe_exc; /* Excitation for SWB TBE */ - Word16 tmp1[NBPSF_PIT_MAX]; - Word16 tmp2[M]; - Word16 tmp3; - Word16 tmp4[L_TRACK_HIST]; - Word16 tmp5[L_TRACK_HIST]; - Word16 tmp6[L_TRACK_HIST]; - Word16 tmp7; - Word32 tmp8; - Word16 voice_factors[NB_SUBFR16k]; - Word16 pitch_buf[NB_SUBFR16k]; - Word16 Q_exc, Qtmp; - Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; - Word16 i; - Word32 synth32[L_FRAME48k]; - MUSIC_POSTFILT_HANDLE hMusicPF; - BPF_DEC_HANDLE hBPF; - ivas_error error; - Word16 Prev_Q_syn_r; - hMusicPF = st_fx->hMusicPF; - hBPF = st_fx->hBPF; - error = IVAS_ERR_OK; - move32(); - - FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH_BFI; i++ ) - { - set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); - realBuffer[i] = realBufferTmp[i]; - imagBuffer[i] = imagBufferTmp[i]; - } /*----------------------------------------------------------------* - * Initialization - *----------------------------------------------------------------*/ - Q_exc = st_fx->Q_exc; - move16(); - st_fx->bpf_off = 1; - move16(); - st_fx->clas_dec = st_fx->last_good; - move16(); - tmp_noise = 0; - move16(); - - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc - exc = old_exc + L_EXC_MEM_DEC; - IF( st_fx->hWIDec != NULL ) - { - Copy( st_fx->hWIDec->old_exc2_fx, old_exc2, L_EXC_MEM ); - } - ELSE - { - set16_fx( old_exc2, 0, L_EXC_MEM ); - } - exc2 = old_exc2 + L_EXC_MEM; - IF( st_fx->hBWE_TD != NULL ) - { - Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); - bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - } - ELSE - { - bwe_exc = NULL; - } - - st_fx->GSC_noisy_speech = 0; - move16(); - st_fx->relax_prev_lsf_interp = 0; - move16(); - - /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) - { - st_fx->nelp_mode_dec = 1; - move16(); - } - - Copy( st_fx->mem_AR_fx, tmp1, M ); - Copy( st_fx->mem_MA_fx, tmp2, M ); - - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); - - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new ); - - Copy( tmp1, st_fx->mem_AR_fx, M ); - Copy( tmp2, st_fx->mem_MA_fx, M ); - - /*----------------------------------------------------------------* - * Excitation decoding + * Resamping to the output sampling frequency *----------------------------------------------------------------*/ - IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - Word16 gain_buf[NB_SUBFR16k]; - Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; - move16(); - /* SC-VBR */ - decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); - FEC_pitch = pitch_buf[3]; - move16(); - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type ); - st_fx->Q_exc = Q_exc; - move16(); - } - ELSE - { - tmp1[0] = st_fx->bfi_pitch_fx; - move16(); - tmp1[1] = st_fx->bfi_pitch_frame; - move16(); - tmp1[2] = st_fx->lp_gainp_fx; - move16(); - tmp1[3] = st_fx->lp_gainc_fx; - move16(); - tmp1[4] = st_fx->upd_cnt; - move16(); - tmp1[5] = st_fx->seed; - move16(); + CLDFB_SCALE_FACTOR scaleFactor; + Word32 workBuffer[128 * 3]; - /* calculation of excitation signal */ - FEC_exc_estim_fx( st_fx, st_fx->L_frame, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &Q_exc, &tmp_noise ); - Rescale_exc( NULL, exc, bwe_exc, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32) 0, - &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame, st_fx->last_coder_type ); + IF( NE_32( ( error = cldfb_save_memory( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) + { + return error; + } + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + cldfb_restore_memory( st_fx->cldfbAna ); - st_fx->seed = tmp1[5]; - move16(); - st_fx->bfi_pitch_fx = tmp1[0]; - move16(); - st_fx->bfi_pitch_frame = tmp1[1]; - move16(); - st_fx->lp_gainp_fx = tmp1[2]; - move16(); - st_fx->lp_gainc_fx = tmp1[3]; - move16(); - st_fx->upd_cnt = tmp1[4]; + scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); - } - - /*------------------------------------------------------------------* - * Synthesis - *-----------------------------------------------------------------*/ - Prev_Q_syn_r = st_fx->Q_syn; - move16(); - Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); - Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn - Copy( st_fx->mem_syn2_fx, tmp1, M ); - syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp1, 1, Q_exc, st_fx->Q_syn ); - tmp8 = st_fx->enr_old_fx; - move32(); - frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp8, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + /* CLDFB synthesis of the combined signal */ + IF( NE_32( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) + { + return error; + } + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - tmp1[0] = st_fx->mem_deemph_fx; - move16(); /*if in acelp_core_dec_fx deemph_fx is used*/ - /*tmp1 = shr(st_fx->mem_deemph_fx, sub(st_fx->Q_syn,1)); if in acelp_core_dec_fx Deemph2 is used*/ + /* output to Q0 */ + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0 - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - deemph_fx( syn, PREEMPH_FAC, L_FRAME, &tmp1[0] ); /*Q0*/ + cldfb_restore_memory( st_fx->cldfbSyn ); } ELSE { - deemph_fx( syn, PREEMPH_FAC_16k, L_FRAME16k, &tmp1[0] ); /*Q0*/ - } - - /*----------------------------------------------------------------* - * Bass post-filter - *----------------------------------------------------------------*/ - - st_fx->bpf_off = 1; - move16(); - Copy( hBPF->pst_old_syn_fx, tmp1, NBPSF_PIT_MAX ); - - tmp3 = st_fx->stab_fac_smooth_fx; - move16(); - Copy( hBPF->mem_mean_pit_fx, tmp4, L_TRACK_HIST ); - Copy( hBPF->Track_on_hist, tmp5, L_TRACK_HIST ); - Copy( hBPF->vibrato_hist, tmp6, L_TRACK_HIST ); - tmp7 = hBPF->psf_att_fx; - move16(); + /* CLDFB analysis of the synthesis at internal sampling rate */ + Qtmp = sub( 11, st_fx->Q_syn ); + Copy_Scale_sig_16_32_no_sat( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) + { + return error; + } + cldfbAnalysis_ivas_fx( syn32, realBuffer, imagBuffer, shr( st_fx->L_frame, 1 ), st_fx->cldfbAna ); + cldfb_restore_memory_ivas_fx( st_fx->cldfbAna ); - bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn, st_fx->L_frame, pitch_buf, - st_fx->bpf_off, st_fx->stab_fac_fx, &tmp3, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/ ); + /* CLDFB synthesis of the combined signal */ + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) + { + return error; + } - Copy( tmp1, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); - Copy( tmp4, hBPF->mem_mean_pit_fx, L_TRACK_HIST ); - Copy( tmp5, hBPF->Track_on_hist, L_TRACK_HIST ); - Copy( tmp6, hBPF->vibrato_hist, L_TRACK_HIST ); - hBPF->psf_att_fx = tmp7; - move16(); - /*----------------------------------------------------------------* - * Resamping to the output sampling frequency - *----------------------------------------------------------------*/ - /* CLDFB analysis of the synthesis at internal sampling rate */ - Qtmp = sub( 11, st_fx->Q_syn ); - Copy_Scale_sig_16_32_no_sat( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) - { - return error; - } - /*cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer);*/ - cldfbAnalysis_ivas_fx( syn32, realBuffer, imagBuffer, shr( st_fx->L_frame, 1 ), st_fx->cldfbAna ); - cldfb_restore_memory_ivas_fx( st_fx->cldfbAna ); + Word16 out_len = extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ); + cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, out_len, -1, 0, st_fx->cldfbSyn ); - /* CLDFB synthesis of the combined signal */ - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) - { - return error; + Copy_Scale_sig_32_16( synth32, synth_out, out_len, -4 ); + cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); } - /*cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ - Word16 out_len = extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ); - cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, out_len, -1, 0, st_fx->cldfbSyn ); - Copy_Scale_sig_32_16( synth32, synth_out, out_len, -4 ); - - - // Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); - - cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); return error; } + /*-------------------------------------------------------------------* * decod_gen_voic_core_switch() * @@ -854,8 +645,8 @@ static void decod_gen_voic_core_switch_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 *Aq, /* i : LP filter coefficient Q_12 */ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ + const Word16 *Aq, /* i : LP filter coefficient Q_12 */ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ const Word32 core_brate, /* i : switching frame bit-rate */ Word16 *Q_exc ) { @@ -873,7 +664,6 @@ static void decod_gen_voic_core_switch_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; - /*----------------------------------------------------------------------* * initializations *----------------------------------------------------------------------*/ @@ -902,6 +692,7 @@ static void decod_gen_voic_core_switch_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector. *--------------------------------------------------------------*/ + IF( st_fx->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); @@ -910,6 +701,7 @@ static void decod_gen_voic_core_switch_fx( { pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } + /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ @@ -936,11 +728,7 @@ static void decod_gen_voic_core_switch_fx( gain_dec_mless_fx( st_fx, L_frame, GENERIC, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); } - /* _ (Word16*) gain_pit : quantized pitch gain (Q14) */ - /* _ (Word32*) gain_code : quantized codebook gain (Q16) */ - /* _ (Word16*) gain_inov : gain of the innovation (used for normalization) (Q12) */ - /* _ (Word32*) norm_gain_code : norm. gain of the codebook excitation (Q16) */ - st_fx->tilt_code_fx = est_tilt_fx( exc, gain_pit, code, gain_code, &voice_fac, *Q_exc ); /*Q15*/ + st_fx->tilt_code_fx = est_tilt_fx( exc, gain_pit, code, gain_code, &voice_fac, *Q_exc, L_SUBFR ); /*Q15*/ move16(); /*----------------------------------------------------------------------* @@ -977,6 +765,7 @@ static void decod_gen_voic_core_switch_fx( /*-----------------------------------------------------------------* * long term prediction on the 2nd sub frame *-----------------------------------------------------------------*/ + IF( st_fx->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index d7dcf5b0315eb9da72405cfd072d546c53d8887d..3806f8c2a920021b5ce46b0a7d6d7d62c7539b25 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -172,7 +172,7 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ - IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ), IVAS_ERR_OK ) ) { return error; } @@ -993,7 +993,7 @@ ivas_error amr_wb_dec_fx( st_fx->last_flag_cna = flag_cna; move16(); - updt_dec_common_fx( st_fx, -1, -1, NULL, 0 ); + updt_dec_common_fx( st_fx, -1, -1, NULL, NULL, 0 ); /*----------------------------------------------------------------* * Overlap of ACELP synthesis with old MDCT memory diff --git a/lib_dec/ari_hm_dec_fx.c b/lib_dec/ari_hm_dec_fx.c index ecbf0b6b7fe405df68c12f6e652b08311718f549..f2b1a011021a6c53d1d0e368b2ce14179ce8064f 100644 --- a/lib_dec/ari_hm_dec_fx.c +++ b/lib_dec/ari_hm_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 2fb37132f61825efa05bfac97b3e57e2a0080dbc..d2558f47c1f1bc9a5ff1b5dca78acb5763eeff17 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -1041,7 +1041,7 @@ Word16 res_bpf_adapt_ivas_fx( bpf_error_ratio = ONE_IN_Q14; // Q13 move16(); } - bpf_error_ratio = add( mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), mult( ( MAX_16 - STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ) ); + bpf_error_ratio = mac_r( L_mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), ( MAX_16 - STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ); hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio; move16(); diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 0006bacbbd2e6354d3e976b80a362a608103ee88..56d2bd29c3e33ac9724922d7936ab0c301c0c909 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -9,9 +9,6 @@ #include "prot_fx.h" #include "ivas_cnst.h" -/*Temporary location to be move in prot* when merge is done*/ -void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); -void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); /*-----------------------------------------------------------------* * Local function prototypes @@ -19,7 +16,6 @@ void E_LPC_f_lsp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ); static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); -static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); /*-----------------------------------------------------------------* * CNG_dec_fx() @@ -723,7 +719,7 @@ void swb_CNG_dec_fx( { st_fx->last_vad_fx = 1; move16(); - st_fx->hTdCngDec->burst_cnt_fx = add( st_fx->hTdCngDec->burst_cnt_fx, 1 ); + st_fx->hTdCngDec->burst_cnt_fx = add_sat( st_fx->hTdCngDec->burst_cnt_fx, 1 ); move16(); if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) ) { @@ -735,43 +731,6 @@ void swb_CNG_dec_fx( return; } -void swb_CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ -) -{ - test(); - IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* SHB SID decoding and CNG */ - test(); - IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) ) - { - shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); - } - st_fx->last_vad_fx = 0; - move16(); - st_fx->hTdCngDec->burst_cnt_fx = 0; - move16(); - } - ELSE - { - st_fx->last_vad_fx = 1; - move16(); - st_fx->hTdCngDec->burst_cnt_fx = add_sat( st_fx->hTdCngDec->burst_cnt_fx, 1 ); // saturation reached? - move16(); - if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) ) - { - st_fx->hTdCngDec->burst_cnt_fx = 0; - move16(); - } - } - - return; -} /*---------------------------------------------------------------------* * shb_CNG_decod() @@ -780,7 +739,7 @@ void swb_CNG_dec_ivas_fx( *---------------------------------------------------------------------*/ static void shb_CNG_decod_fx( - Decoder_State *st_fx, /* i/o: State structure */ + Decoder_State *st, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ @@ -788,7 +747,7 @@ static void shb_CNG_decod_fx( ) { Word16 i; - Word16 idx_ener_fx; + Word16 idx_ener; TD_CNG_DEC_HANDLE hTdCngDec; Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; @@ -799,410 +758,237 @@ static void shb_CNG_decod_fx( Word32 wb_ener_fx; Word16 wb_ener16_fx; Word32 L_gain_fx; - Word16 gain_fx; + Word32 gain_fx; Word16 shb_syn16k_fx[L_FRAME16k]; - Word16 tmp; - Word16 step_fx; + Word32 tmp; + Word32 step_fx; Word16 interp_fx; - Word16 ener_fx; + Word32 ener_fx; Word16 exp, exp1; Word16 fra; Word32 L_tmp; - Word16 tmp2; - Word16 allow_cn_step_fx = 0; - move16(); + Word16 tmp_16, tmp_16_2, step_fx16, gain_fx16, ener_fx16; + Word16 allow_cn_step_fx; Word16 q; TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - hTdCngDec = st_fx->hTdCngDec; + hBWE_TD = st->hBWE_TD; + hTdCngDec = st->hTdCngDec; + allow_cn_step_fx = 0; + move16(); - IF( st_fx->bfi == 0 ) + IF( st->bfi == 0 ) { test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { - idx_ener_fx = get_next_indice_fx( st_fx, 4 ); + idx_ener = get_next_indice_fx( st, 4 ); - if ( !idx_ener_fx ) + IF( idx_ener == 0 ) { - idx_ener_fx = -15; + idx_ener = -15; move16(); } - IF( st_fx->element_mode == EVS_MONO ) + + /* de-quantization of SHB CNG parameters */ + IF( st->element_mode == EVS_MONO ) { - /* de-quantization of SHB CNG parameters */ - L_tmp = L_mult( idx_ener_fx, 27400 ); /*Q14 */ + L_tmp = L_mult( idx_ener, 27400 ); /*Q14 */ hTdCngDec->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 295924 ), 6 ) ); /*Q8 */ move16(); } ELSE { + hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 8807 ), 36991 ); // Q11 + move32(); } } } /* SHB spectrum estimation */ - - interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 ); interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp2 = mult( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ); /*Q14*/ - tmp = mult( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ); /*Q14*/ - shb_lspCNG_fx[i] = add( tmp2, tmp ); - move16(); /*Q14*/ - } - IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) + IF( st->element_mode == EVS_MONO ) { - if ( LT_16( hTdCngDec->shb_dtx_count_fx, 1000 ) ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 ); - move16(); + tmp_16_2 = mult( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ); /*Q14*/ + tmp_16 = mult( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ); /*Q14*/ + shb_lspCNG_fx[i] = add( tmp_16_2, tmp_16 ); + move16(); /*Q14*/ } } - E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ - E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - - Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ - - /* SHB energy estimation */ - wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ - FOR( i = 0; i < L_FRAME32k; i++ ) - { - wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ - } - exp = norm_l( wb_ener_fx ); - fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); - exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); - wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ - if ( !st_fx->first_CNG ) - { - hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; - move16(); /*Q8 */ - } - if ( GT_16( abs_s( sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ) ), 3072 ) ) - { - allow_cn_step_fx = 1; - move16(); - } - - IF( EQ_16( allow_cn_step_fx, 1 ) ) - { - hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; - move16(); /*Q8 */ - } ELSE { - tmp = sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ); /*Q8 */ - tmp = mult_r( tmp, 29491 ); /*Q8 */ - hTdCngDec->wb_cng_ener_fx = add( hTdCngDec->wb_cng_ener_fx, tmp ); /*Q8 */ - move16(); - } - test(); - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && ( st_fx->bfi == 0 ) ) - { - hTdCngDec->last_wb_cng_ener_fx = hTdCngDec->wb_cng_ener_fx; - move16(); - - if ( !st_fx->first_CNG ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hTdCngDec->shb_cng_ener_fx = hTdCngDec->last_shb_cng_ener_fx; + shb_lspCNG_fx[i] = add( mult_r( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 move16(); } } - gain_fx = sub( hTdCngDec->wb_cng_ener_fx, hTdCngDec->last_wb_cng_ener_fx ); /* Q8 */ - if ( GT_16( gain_fx, 15 ) ) - { - gain_fx = 15; - move16(); - } - step_fx = sub( add( gain_fx, hTdCngDec->last_shb_cng_ener_fx ), hTdCngDec->shb_cng_ener_fx ); /*Q8 */ - test(); - IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st_fx->last_core_brate, SID_2k40 ) ) - { - hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, step_fx ); /* Q8 */ - move16(); - } - ELSE + IF( LE_16( hTdCngDec->shb_dtx_count_fx, 1000 ) ) { - hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, mult( 8192, step_fx ) ); /*Q8 */ + hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 ); move16(); } - /* generate white noise excitation */ - FOR( i = 0; i < L_FRAME16k; i++ ) - { - excTmp_fx[i] = shr_r( Random( &hTdCngDec->swb_cng_seed ), 8 ); - move16(); /*Q-8*/ - } - - /* synthesis filtering */ - Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 ); + E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ + E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - /* synthesis signal gain shaping */ - L_tmp = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) + IF( st->element_mode != EVS_MONO ) { - L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ + Copy_Scale_sig( shb_lpcCNG_fx, hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ } - q = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, q ); - q = sub( q, 32 ); - ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ - IF( EQ_16( st_fx->last_vad_fx, 1 ) ) + Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ + + /* SHB energy estimation */ + IF( st->element_mode == EVS_MONO ) { - hTdCngDec->trans_cnt_fx = 0; - move16(); - test(); - IF( GT_16( hTdCngDec->burst_cnt_fx, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) + wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ + FOR( i = 0; i < L_FRAME32k; i++ ) { - hTdCngDec->trans_cnt_fx = 5; + wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ + } + exp = norm_l( wb_ener_fx ); + fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); + exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); + wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); + wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ + if ( !st->first_CNG ) + { + hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; + move16(); /*Q8 */ + } + if ( GT_16( abs_s( sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ) ), 3072 ) ) + { + allow_cn_step_fx = 1; move16(); } - } - ener_fx = hTdCngDec->shb_cng_ener_fx; - move16(); /*Q8 */ - IF( hTdCngDec->trans_cnt_fx > 0 ) - { - i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ - ener_fx = add_sat( hTdCngDec->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( hTdCngDec->last_shb_ener_fx, hTdCngDec->shb_cng_ener_fx ) ) ); /*Q8 */ - hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); - move16(); - } - - tmp = mult( 3277, ener_fx ); /*Q8 */ - L_tmp = L_mult( 27213, tmp ); /*Q22, 27213=3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ - L_tmp = L_add( L_tmp, 10 << 16 ); - if ( L_tmp < 0 ) - { - L_tmp = 0; - move32(); - } - fra = L_Extract_lc( L_tmp, &exp ); - L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */ - L_tmp = L_shr( L_tmp, 10 ); - if ( !L_tmp ) - { - L_tmp = 1; /*Q5 */ - } - exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /*Q31*/ - tmp = extract_h( L_tmp ); /*Q15*/ - exp = sub( exp, 16 ); - exp1 = norm_s( ener_excSHB_fx ); - fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ - - IF( GT_16( fra, tmp ) ) - { - fra = shr( fra, 1 ); /*Q15*/ - exp1 = sub( exp1, 1 ); - } - tmp = div_s( fra, tmp ); /*Q15*/ - - L_tmp = L_deposit_h( tmp ); /*Q31 */ - tmp = sub( add( 5, exp ), add( q, exp1 ) ); - L_gain_fx = Isqrt_lc( L_tmp, &tmp ); /*Q31-Qtmp */ - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - shb_syn16k_fx[i] = extract_l( L_shr( Mpy_32_16_1( L_gain_fx, excSHB_fx[i] ), sub( 5, tmp ) ) ); /*Q3 = 31-Qtmp-8-15-5+Qtmp */ - move16(); - } - - test(); - IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) - { - /* rescale the Hilbert memories to Q0 */ - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) + IF( EQ_16( allow_cn_step_fx, 1 ) ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */ - move32(); + hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; + move16(); /*Q8 */ } - - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) + ELSE { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */ + tmp_16 = sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ); /*Q8 */ + tmp_16 = mult_r( tmp_16, 29491 ); /*Q8 */ + hTdCngDec->wb_cng_ener_fx = add( hTdCngDec->wb_cng_ener_fx, tmp_16 ); /*Q8 */ move16(); } - } - GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - - IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); - } - - ResetSHBbuffer_Dec_fx( st_fx->hBWE_TD, st_fx->extl ); - return; -} - -static void shb_CNG_decod_ivas_fx( - Decoder_State *st, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ - const Word16 Qsyn ) -{ - Word16 i; - Word16 idx_ener; - TD_CNG_DEC_HANDLE hTdCngDec; - Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; - Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; - Word16 excTmp_fx[L_FRAME16k]; - Word16 excSHB_fx[L_FRAME16k]; - Word16 tmp_lsp[LPC_SHB_ORDER]; - Word16 ener_excSHB_fx; - Word32 wb_ener_fx; - Word16 wb_ener16_fx; - Word32 L_gain_fx; - Word32 gain_fx; - Word16 shb_syn16k_fx[L_FRAME16k]; - Word32 tmp; - Word32 step_fx; - Word16 interp_fx; - Word32 ener_fx; - Word16 exp, exp1; - Word16 fra; - Word32 L_tmp; - Word16 allow_cn_step_fx; - Word16 q; - TD_BWE_DEC_HANDLE hBWE_TD; - - hBWE_TD = st->hBWE_TD; - hTdCngDec = st->hTdCngDec; - allow_cn_step_fx = 0; - move16(); - - IF( st->bfi == 0 ) - { test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && ( st->bfi == 0 ) ) { - idx_ener = get_next_indice_fx( st, 4 ); + hTdCngDec->last_wb_cng_ener_fx = hTdCngDec->wb_cng_ener_fx; + move16(); - IF( idx_ener == 0 ) + if ( !st->first_CNG ) { - idx_ener = -15; + hTdCngDec->shb_cng_ener_fx = hTdCngDec->last_shb_cng_ener_fx; move16(); } - - /* de-quantization of SHB CNG parameters */ - IF( st->element_mode == EVS_MONO ) - { - hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 6850 ), 36991 ); // Q11 - move32(); - } - ELSE - { - hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 8807 ), 36991 ); // Q11 - move32(); - } } - } - /* SHB spectrum estimation */ - interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 ); - interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ + gain_fx16 = sub( hTdCngDec->wb_cng_ener_fx, hTdCngDec->last_wb_cng_ener_fx ); /* Q8 */ + if ( GT_16( gain_fx16, 15 ) ) + { + gain_fx16 = 15; + move16(); + } + step_fx16 = sub( add( gain_fx16, hTdCngDec->last_shb_cng_ener_fx ), hTdCngDec->shb_cng_ener_fx ); /*Q8 */ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - shb_lspCNG_fx[i] = add( mult_r( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 - move16(); + test(); + IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) + { + hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, step_fx16 ); /* Q8 */ + move16(); + } + ELSE + { + hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, mult( 8192, step_fx16 ) ); /*Q8 */ + move16(); + } } - - IF( LE_16( hTdCngDec->shb_dtx_count_fx, 1000 ) ) + ELSE { - hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 ); - move16(); - } + wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ + } + } + exp = norm_l( wb_ener_fx ); + fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); + exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); + wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); + wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ + Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */ + if ( EQ_16( st->first_CNG, 0 ) ) + { + hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; + move32(); /*Q11 */ + } + if ( GT_32( L_abs( L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ + { + allow_cn_step_fx = 1; + move16(); + } - E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ - E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); + IF( EQ_16( allow_cn_step_fx, 1 ) ) + { + hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; + move32(); /*Q11 */ + } + ELSE + { + tmp = L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ + tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ + hTdCngDec->wb_cng_ener_fx_32 = L_add( hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ + move32(); + } - Copy_Scale_sig( shb_lpcCNG_fx, hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ + test(); + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) + { + hTdCngDec->last_wb_cng_ener_fx_32 = hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ + move32(); - Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ + if ( !st->first_CNG ) + { + hTdCngDec->shb_cng_ener_fx_32 = hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ + move32(); + } + } - /* SHB energy estimation */ - wb_ener_fx = L_deposit_l( 1 ); /*Q1 */ - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - FOR( i = 0; i < L_FRAME32k; i++ ) + gain_fx = L_sub( hTdCngDec->wb_cng_ener_fx_32, hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ + if ( GT_32( gain_fx, 30720 ) ) { - wb_ener_fx = L_add( wb_ener_fx, Mpy_32_16_1( L_mult0( synth_fx[i], synth_fx[i] ), 51 ) ); /* 2*Qsyn */ + gain_fx = 30720; + move32(); } - } - exp = norm_l( wb_ener_fx ); - fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); - exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); - wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ - Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */ - if ( EQ_16( st->first_CNG, 0 ) ) - { - hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; - move32(); /*Q11 */ - } - if ( GT_32( L_abs( L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ - { - allow_cn_step_fx = 1; - move16(); - } + step_fx = L_sub( L_add( gain_fx, hTdCngDec->last_shb_cng_ener_fx_32 ), hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ - IF( EQ_16( allow_cn_step_fx, 1 ) ) - { - hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; - move32(); /*Q11 */ - } - ELSE - { - tmp = L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ - tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ - hTdCngDec->wb_cng_ener_fx_32 = L_add( hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ - move32(); - } - test(); - test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) - { - hTdCngDec->last_wb_cng_ener_fx_32 = hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ - move32(); - - if ( !st->first_CNG ) + test(); + IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) { - hTdCngDec->shb_cng_ener_fx_32 = hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ + hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ + move32(); + } + ELSE + { + hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ move32(); } } - gain_fx = L_sub( hTdCngDec->wb_cng_ener_fx_32, hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ - if ( GT_32( gain_fx, 30720 ) ) - { - gain_fx = 30720; - move32(); - } - step_fx = L_sub( L_add( gain_fx, hTdCngDec->last_shb_cng_ener_fx_32 ), hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ - test(); - IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) - { - hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ - move32(); - } - ELSE - { - hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ - move32(); - } /* generate white noise excitation */ FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -1213,7 +999,6 @@ static void shb_CNG_decod_ivas_fx( /* synthesis filtering */ Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 ); - /* synthesis signal gain shaping */ L_tmp = 0; move32(); @@ -1238,56 +1023,105 @@ static void shb_CNG_decod_ivas_fx( } } - ener_fx = hTdCngDec->shb_cng_ener_fx_32; - move32(); /*Q11 */ - IF( GT_16( st->hTdCngDec->trans_cnt_fx, 0 ) ) + IF( st->element_mode == EVS_MONO ) { - i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ - ener_fx = L_add( hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( hTdCngDec->last_shb_ener_fx_32, hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ - hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); - move16(); - } + ener_fx16 = hTdCngDec->shb_cng_ener_fx; + move16(); /*Q8 */ + IF( hTdCngDec->trans_cnt_fx > 0 ) + { + i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ + ener_fx16 = add_sat( hTdCngDec->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( hTdCngDec->last_shb_ener_fx, hTdCngDec->shb_cng_ener_fx ) ) ); /*Q8 */ + hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); + move16(); + } - tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ - IF( GT_32( tmp, 32767 ) ) - abort(); - Word16 tmp_16; - tmp_16 = (Word16) tmp; - move16(); - L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ - L_tmp = L_add( L_tmp, L_shl( 10, 16 ) ); - if ( ( L_tmp < 0 ) ) - { - L_tmp = 0; - move32(); - } - fra = L_Extract_lc( L_tmp, &exp ); - L_tmp = L_shr( Pow2( exp, fra ), 5 ); /*Q5 */ - if ( !L_tmp ) - { - L_tmp = 1; - move32(); /*Q5 */ + tmp_16 = mult( 3277, ener_fx16 ); /*Q8 */ + L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ + L_tmp = L_add( L_tmp, 10 << 16 ); + if ( L_tmp < 0 ) + { + L_tmp = 0; + move32(); + } + fra = L_Extract_lc( L_tmp, &exp ); + L_tmp = L_shl_sat( Pow2( exp, fra ), 5 ); /*Q5 */ + L_tmp = L_shr( L_tmp, 10 ); + if ( !L_tmp ) + { + L_tmp = 1; /*Q5 */ + } + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /*Q31*/ + tmp_16 = extract_h( L_tmp ); /*Q15*/ + exp = sub( exp, 16 ); + exp1 = norm_s( ener_excSHB_fx ); + fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ + + IF( GT_16( fra, tmp_16 ) ) + { + fra = shr( fra, 1 ); /*Q15*/ + exp1 = sub( exp1, 1 ); + } + tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ + + L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ + tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); + L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ } - exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /*Q31*/ - tmp_16 = extract_h( L_tmp ); /*Q15*/ - exp = sub( exp, 16 ); - exp1 = norm_s( ener_excSHB_fx ); - fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ - - IF( GT_16( fra, tmp_16 ) ) + ELSE { - fra = shr( fra, 1 ); /*Q15*/ - exp1 = sub( exp1, 1 ); + ener_fx = hTdCngDec->shb_cng_ener_fx_32; + move32(); /*Q11 */ + IF( GT_16( st->hTdCngDec->trans_cnt_fx, 0 ) ) + { + i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ + ener_fx = L_add( hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( hTdCngDec->last_shb_ener_fx_32, hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ + hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); + move16(); + } + + tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ + IF( GT_32( tmp, 32767 ) ) + abort(); + tmp_16 = (Word16) tmp; + move16(); + L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ + L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ + L_tmp = L_add( L_tmp, L_shl( 10, 16 ) ); + if ( L_tmp < 0 ) + { + L_tmp = 0; + move32(); + } + fra = L_Extract_lc( L_tmp, &exp ); + L_tmp = L_shr( Pow2( exp, fra ), 5 ); /*Q5 */ + if ( !L_tmp ) + { + L_tmp = 1; + move32(); /*Q5 */ + } + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /*Q31*/ + tmp_16 = extract_h( L_tmp ); /*Q15*/ + exp = sub( exp, 16 ); + exp1 = norm_s( ener_excSHB_fx ); + fra = shl( ener_excSHB_fx, exp1 ); /*Q15*/ + + IF( GT_16( fra, tmp_16 ) ) + { + fra = shr( fra, 1 ); /*Q15*/ + exp1 = sub( exp1, 1 ); + } + tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ + + L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ + tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); + L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ + hTdCngDec->shb_cng_gain_fx_32 = ener_fx; + move32(); } - tmp_16 = div_s( fra, tmp_16 ); /*Q15*/ - L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ - tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); - L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ - hTdCngDec->shb_cng_gain_fx_32 = ener_fx; - move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { shb_syn16k_fx[i] = extract_l( L_shr( Mpy_32_16_1( L_gain_fx, excSHB_fx[i] ), sub( 5, tmp_16 ) ) ); /*Q3 = 31-Qtmp-8-15-5+Qtmp */ @@ -1317,7 +1151,17 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } - Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */ + IF( st->element_mode != EVS_MONO ) + { + IF( EQ_32( st->output_Fs, 32000 ) ) + { + Scale_sig( shb_synth_fx, L_FRAME32k, -3 ); /* Qx - 3 */ + } + ELSE + { + Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */ + } + } ResetSHBbuffer_Dec_fx( st->hBWE_TD, st->extl ); diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 22fed24cb2640ca07b98af6f1d0d7e2741e9924e..678d0b3d7ccc621dd3ecc0bbea2006fe0b507cea 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -240,7 +240,11 @@ void open_decoder_LPD_fx( IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); +#else InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); +#endif } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ if ( st->tcxonly == 0 ) @@ -1978,7 +1982,7 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL && ( st->ini_frame == 0 || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) ) { - concealment_init_ivas_fx( st->hTcxDec->L_frameTCX, st->hPlcInfo ); + concealment_init_x( st->hTcxDec->L_frameTCX, st->hPlcInfo ); } } ELSE diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index b22a48b43cf685fa4255336d593e0698cfaa7ba9..3a9148b7661f45f9584b5d5729caac9f4eba3f27 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -133,7 +133,11 @@ void mode_switch_decoder_LPD_fx( IF( ( st->hTcxCfg->fIsTNSAllowed != 0 ) && st->hIGFDec != NULL ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0 /* 0 should be replaced with MCT_flag*/ ); +#else InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, 0 /* 0 should be replaced with MCT_flag*/ ); +#endif } } } @@ -377,7 +381,11 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hTcxCfg->fIsTNSAllowed && st->hIGFDec != NULL && st->hTcxCfg != NULL ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); +#else InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); +#endif SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, (Word8) EQ_16( st->element_mode, IVAS_CPE_MDCT ) ); } diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 8bab0d0615082173235cbc1d82893dd6957d809d..ee7fdb5a82efad09496b3aa8d2bf7c8c908c8f67 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -12,128 +12,13 @@ /*---------------------------------------------------------------------* - * bandwidth_switching_detect_fx() - * - * + * Local prototypes *---------------------------------------------------------------------*/ static void smoothTransitionDtxToTcx_fx( Word16 synth[], const Word16 output_frame, const Word16 delay_comp ); -static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output ); - -void bandwidth_switching_detect_fx( - Decoder_State *st_fx /* i/o: encoder state structure */ -) -{ - test(); - test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */ - st_fx->prev_bws_cnt = 0; - st_fx->bws_cnt = 0; - st_fx->bws_cnt1 = 0; - move16(); - move16(); - move16(); - - return; - } - /* update band-width switching counter */ - test(); - test(); - test(); - IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) - { - st_fx->bws_cnt1 = 0; - move16(); - } - ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) - { - st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); /* Q0 */ - move16(); - } - ELSE IF( st_fx->bws_cnt1 > 0 ) - { - IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 ); /* Q0 */ - move16(); - } - ELSE - { - st_fx->bws_cnt = 0; - move16(); - } - - IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - st_fx->bws_cnt1 = 0; - move16(); - } - ELSE - { - IF( EQ_16( st_fx->bwidth, SWB ) ) - { - st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); /* Q0 */ - move16(); - } - ELSE - { - st_fx->bws_cnt1 = 0; - move16(); - } - } - } - /* update band-width switching counter */ - test(); - test(); - test(); - IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) - { - st_fx->bws_cnt = 0; - move16(); - } - ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) ) - { - st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); /* Q0 */ - move16(); - } - ELSE IF( st_fx->bws_cnt > 0 ) - { - IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 ); /* Q0 */ - move16(); - } - ELSE - { - st_fx->bws_cnt1 = 0; - move16(); - } - - IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - st_fx->bws_cnt = 0; - move16(); - } - ELSE - { - IF( EQ_16( st_fx->bwidth, WB ) ) - { - st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); - move16(); - } - ELSE - { - st_fx->bws_cnt = 0; - move16(); - } - } - } +static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output ); - return; -} /*---------------------------------------------------------------------* * Calc_freq_ener_fx() @@ -167,6 +52,7 @@ static Word32 Calc_freq_ener_fx( return enerLL_fx; } + /*---------------------------------------------------------------------* * bw_switching_pre_proc_fx() * @@ -174,8 +60,10 @@ static Word32 Calc_freq_ener_fx( *---------------------------------------------------------------------*/ void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ - Decoder_State *st_fx /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 *old_syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ ) { Word16 i; @@ -184,1002 +72,106 @@ void bw_switching_pre_proc_fx( IF( st_fx->element_mode > EVS_MONO ) { - } - - test(); - test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) ) - { - /*----------------------------------------------------------------------* - * Calculate tilt of the ACELP core synthesis - *----------------------------------------------------------------------*/ - - st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3 ) ); /* Q11 */ - move16(); - /*-------------------------------------------------------------------------------* - * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis - *-------------------------------------------------------------------------------*/ - - edct_16fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); - - L_tmp = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME / 2; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, syn_dct_fx[i], syn_dct_fx[i] ); /* (2 * Q_syn2) */ - } - L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ - st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ - move32(); - L_tmp = L_deposit_l( 0 ); - FOR( ; i < L_FRAME; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, syn_dct_fx[i], syn_dct_fx[i] ); - } - L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ - st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ - move32(); - } - ELSE - { - IF( st_fx->hHQ_core->old_is_transient[0] ) - { - L_tmp = L_deposit_l( 0 ); - FOR( i = 0; i < 32; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ - } - L_tmp = L_shr( L_tmp, 5 ); /* 2 * Q_syn2 */ - st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ - move32(); - L_tmp = L_deposit_l( 0 ); - FOR( ; i < 64; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ - } - L_tmp = L_shr( L_tmp, 5 ); /* 2 * Q_syn2 */ - st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ - move32(); - } - ELSE + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->core == ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) && st_fx->hBWE_FD != NULL && !( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) { - L_tmp = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME / 2; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ - } - L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ - st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ - move32(); - L_tmp = L_deposit_l( 0 ); - FOR( ; i < L_FRAME; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ - } - L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ - st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ - move32(); + /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ + Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; + Word32 old_syn_12k8_16k_tmp_32fx[L_FRAME16k]; + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_32fx, st_fx->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) + Copy_Scale_sig_32_16( old_syn_12k8_16k_tmp_32fx, old_syn_12k8_16k_tmp_16fx, st_fx->L_frame, sub( -1, Q11 ) ); + st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st_fx->L_frame ), sub( Q11, 8 ) ) ); // Q24+(Q11-8) - 16 + move16(); } - } - - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( st_fx->last_bwidth == 0 && LE_16( st_fx->extl, SWB_CNG ) ) - { - st_fx->prev_ener_shb_fx = 0; - move16(); - set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); - } - ELSE IF( ( ( st_fx->core == ACELP_CORE && ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st_fx->core, st_fx->last_core ) && NE_16( st_fx->extl, st_fx->last_extl ) ) ) && GE_16( st_fx->last_bwidth, SWB ) ) - { - st_fx->attenu_fx = 3277; /* Q15 */ - move16(); - } - - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && !( EQ_16( st_fx->last_extl, WB_TBE ) || EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && GT_32( st_fx->core_brate, ACELP_8k00 ) ) ) - { - st_fx->prev_fractive = 0; - move16(); - } - return; -} - - -/*---------------------------------------------------------------------* - * core_switching_pre_dec_fx() - * - * Preprocessing/preparation for ACELP/HQ core switching - *---------------------------------------------------------------------*/ -ivas_error core_switching_pre_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length Q0*/ -) -{ - Word16 oldLenClasBuff, newLenClasBuff, i; - BPF_DEC_HANDLE hBPF; - TD_BWE_DEC_HANDLE hBWE_TD; - FD_BWE_DEC_HANDLE hBWE_FD; - HQ_DEC_HANDLE hHQ_core; - TCX_DEC_HANDLE hTcxDec; - ivas_error error; - - hBWE_TD = st_fx->hBWE_TD; - hBWE_FD = st_fx->hBWE_FD; - hHQ_core = st_fx->hHQ_core; - hBPF = st_fx->hBPF; - hTcxDec = st_fx->hTcxDec; - - error = IVAS_ERR_OK; - move32(); - test(); - test(); - test(); - /* Codec switching */ - IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && st_fx->element_mode > EVS_MONO ) ) - { - st_fx->mem_deemph_fx = st_fx->syn[M]; /* Q_syn */ - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); /* Q0 */ - Scale_sig( &( st_fx->mem_deemph_fx ), 1, st_fx->Q_syn ); /* Brings mem_deemph to Qsyn */ - - Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ - - st_fx->bpf_off = 1; - move16(); - Scale_sig( st_fx->hPFstat->mem_pf_in, L_SUBFR, st_fx->Q_syn ); /* Post_filter mem */ /* st_fx->Q_syn*/ - Scale_sig( st_fx->hPFstat->mem_res2, DECMEM_RES2, st_fx->Q_syn ); /* NB post_filter mem */ /* st_fx->Q_syn */ - Scale_sig( st_fx->hPFstat->mem_stp, L_SUBFR, st_fx->Q_syn ); /* Post_filter mem */ /* st_fx->Q_syn */ - IF( hBPF != NULL ) - { - set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ - hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st_fx->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ - hBPF->pst_mem_deemp_err_fx = 0; - move16(); - move16(); - } - move16(); - st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); /* 2 * lp_noise_q - 16 */ - - /* reset old HB synthesis buffer */ - IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) - { - st_fx->old_bwe_delay = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); /* Q0 */ - } - ELSE - { - st_fx->old_bwe_delay = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); /* Q0 */ - } - move16(); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); - - /* reset upd_cnt */ - st_fx->upd_cnt = MAX_UPD_CNT; - move16(); - st_fx->igf = 0; - move16(); - - - test(); - IF( hBWE_TD != NULL && NE_16( st_fx->last_core, ACELP_CORE ) ) - { - hBWE_TD->prev_hb_synth_fx_exp = 31; - move16(); - /* reset BWE memories */ - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* Q_exc */ - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - } - - test(); - IF( GE_32( st_fx->output_Fs, 16000 ) && st_fx->hBWE_zero != NULL ) - { - hf_synth_reset_fx( st_fx->hBWE_zero ); - } - IF( st_fx->hBWE_FD != NULL ) - { - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - } - IF( st_fx->hHQ_core != NULL ) - { - set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - - IF( GT_32( st_fx->output_Fs, 16000 ) ) - { - set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); - } - - /* pre-echo */ - hHQ_core->pastpre = 0; - move16(); - } - /* reset the GSC pre echo energy threshold in case of switching */ - IF( st_fx->hGSCDec != NULL ) - { - st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; - } - move32(); - - test(); - IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) - { - IF( st_fx->element_mode == EVS_MONO ) - { - st_fx->last_core = HQ_CORE; - move16(); - Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /* st_fx->q_prev_synth_buffer_fx */ - } - IF( hHQ_core != NULL ) - { - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - - set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - hHQ_core->prev_frm_hfe2 = 0; - move16(); - hHQ_core->prev_stab_hfe2 = 0; - move16(); - } - } - - IF( st_fx->prev_bfi != 0 ) - { - Word16 delay_comp; - - /*switch off Hq Voicing as it was not uodated in MODE2*/ - IF( hHQ_core != NULL ) - { - hHQ_core->oldHqVoicing = 0; - hHQ_core->HqVoicing = 0; - move16(); - move16(); - } - - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); - - test(); - test(); - IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) ) - { - - Word16 no_col; - Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128 * 3]; - - FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) - { - set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); - realBuffer[i] = realBufferTmp[i]; - move32(); - imagBuffer[i] = imagBufferTmp[i]; - move32(); - } - - no_col = s_min( st_fx->cldfbAna->no_col, idiv1616( sub( add( delay_comp, st_fx->cldfbAna->no_channels ), 1 ), st_fx->cldfbAna->no_channels ) ); /* Q0 */ - - /* CLDFB analysis of the synthesis at internal sampling rate */ - IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) - { - return error; - } - cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer ); - cldfb_restore_memory( st_fx->cldfbAna ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* CLDFB synthesis of the combined signal */ - IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) - { - return error; - } - cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer ); - cldfb_restore_memory( st_fx->cldfbSyn ); - } - - test(); - test(); - IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) ) - { - lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( st_fx->output_frame_fx, 1 ), shr( st_fx->last_L_frame, 1 ) ); - /*Set to zero the remaining part*/ - set16_fx( hHQ_core->fer_samples_fx + delay_comp + shr( st_fx->output_frame_fx, 1 ), 0, shr( st_fx->output_frame_fx, 1 ) - delay_comp ); - } - } - - st_fx->use_acelp_preq = 0; - move16(); - st_fx->reset_mem_AR = 0; - move16(); - } - - /*FEC*/ - IF( LE_16( st_fx->L_frame, L_FRAME16k ) ) - { - test(); - IF( LE_16( st_fx->last_L_frame, L_FRAME16k ) && NE_16( st_fx->core, HQ_CORE ) ) - { - IF( NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) - { - IF( GT_16( st_fx->L_frame, st_fx->last_L_frame ) ) - { - oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->last_L_frame, getInvFrameLen( st_fx->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - } - ELSE - { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - newLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->L_frame, getInvFrameLen( st_fx->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); - } - lerp( &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); - } - } - ELSE - { - set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - } - } - - /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores - within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ - test(); - test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) - { - st_fx->last_ppp_mode_dec = 0; - move16(); - st_fx->last_nelp_mode_dec = 0; - move16(); - } - - test(); - test(); - test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) ) - { - st_fx->act_count = 3; - move16(); - st_fx->uv_count = 0; - move16(); - } - - test(); - test(); - IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) ) - { - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - st_fx->hPFstat->reset = 1; - move16(); - } - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); /* Q2.56 */ - Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi1_fx, M ); /* Q2.56 */ - Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi0_fx, M ); /* Q2.56*/ - Copy( TRWB2_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); /* Q2.56 */ - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_16k ); - } - ELSE - { - Copy( TRWB_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ /* Q2.56 */ - Copy( TRWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); /* Q2.56 */ - Copy( TRWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); /* Q2.56 */ - Copy( TRWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); /* Q2.56 */ - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - } - - - set16_fx( st_fx->agc_mem_fx, 0, 2 ); - st_fx->mem_deemph_fx = 0; - move16(); - IF( !st_fx->last_con_tcx ) - { - set16_fx( st_fx->mem_syn2_fx, 0, M ); - } - set16_fx( st_fx->mem_syn1_fx, 0, M ); - IF( hBWE_TD != NULL ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move16(); - } - /* Reset ACELP parameters */ - set16_fx( st_fx->mem_MA_fx, 0, M ); - IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) - { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); /* Q2.56 */ - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); /* Q2.56 */ - } - st_fx->tilt_code_fx = 0; - move16(); - st_fx->gc_threshold_fx = 0; - move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); /* Q16 */ - move32(); - set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 ); - st_fx->dm_fx.prev_state = 0; - move16(); - - st_fx->last_coder_type = GENERIC; - move16(); - - frame_ener_fx( output_frame, UNVOICED_CLAS, st_fx->previoussynth_fx, -1, &st_fx->enr_old_fx, 1, 0, 0, 0 ); - st_fx->lp_gainp_fx = 0; - move16(); - - /* the sqrt below needs to be changed to use basop Sqrt16 */ - /*st_fx->lp_gainc_fx = (float)sqrt( st_fx->lp_ener_fx ); */ - IF( st_fx->lp_ener_fx != 0 ) - { - Word32 L_tmp; - Word16 tmp, exp; - exp = norm_l( st_fx->lp_ener_fx ); /* In Q6 */ - tmp = extract_h( L_shl( st_fx->lp_ener_fx, exp ) ); - exp = sub( exp, 30 - 6 ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - - st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ - move16(); - } - - - st_fx->last_voice_factor_fx = 0; - move16(); - st_fx->Last_GSC_noisy_speech_flag = 0; - move16(); - - /* reset CLDFB memories */ - cldfb_reset_memory( st_fx->cldfbAna ); - cldfb_reset_memory( st_fx->cldfbBPF ); - cldfb_reset_memory( st_fx->cldfbSyn ); - - /* reset TBE memories */ - test(); - test(); - - IF( !st_fx->last_con_tcx && !( ( EQ_16( st_fx->last_core, HQ_CORE ) ) && st_fx->element_mode > EVS_MONO ) ) - { - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); - } - ELSE IF( LT_16( st_fx->L_frame, L_FRAME16k ) ) - { - /* resample from 16kHz to 12.8kHZ */ - synth_mem_updt2( st_fx->L_frame, L_FRAME16k, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); - } - - IF( hBWE_TD != NULL ) - { - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - } - - test(); - IF( GE_32( st_fx->output_Fs, 16000L ) && st_fx->hBWE_zero != NULL ) - { - hf_synth_reset_fx( st_fx->hBWE_zero ); - } - IF( hBWE_FD != NULL ) - { - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); - } - } - - test(); - test(); - test(); - test(); - test(); - IF( hHQ_core != NULL && EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) || ( st_fx->element_mode != EVS_MONO && NE_16( st_fx->last_core, HQ_CORE ) ) ) ) - { - set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - - set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - hHQ_core->prev_frm_hfe2 = 0; - hHQ_core->prev_stab_hfe2 = 0; - move16(); - move16(); - IF( GT_32( st_fx->output_Fs, 16000 ) ) - { - set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); - } - - if ( st_fx->element_mode != EVS_MONO ) - { - } - else - { - set16_fx( hHQ_core->old_out_fx, 0, output_frame ); - hHQ_core->Q_old_wtda_LB = 15; - hHQ_core->Q_old_wtda = 15; - move16(); - } - } - - test(); - /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - IF( hHQ_core != NULL ) - { - hHQ_core->pastpre = sub( hHQ_core->pastpre, 1 ); /* Q0 */ - move16(); - IF( hHQ_core->pastpre <= 0 ) - { - reset_preecho_dec_fx( hHQ_core ); - } - } - IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - st_fx->VAD = 0; - move16(); - st_fx->m_frame_type = ZERO_FRAME; - move16(); - } - ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) - { - st_fx->VAD = 0; - move16(); - st_fx->m_frame_type = SID_FRAME; - move16(); - } - ELSE - { - st_fx->VAD = 1; - move16(); - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - } - - /*switch on CNA on active frames*/ - IF( st_fx->element_mode == EVS_MONO ) /* for IVAS modes, st->flag_cna is set earlier */ - { - test(); - test(); - test(); - test(); - test(); - test(); - IF( NE_16( st_fx->core, AMR_WB_CORE ) && st_fx->VAD && LE_32( st_fx->total_brate, CNA_MAX_BRATE ) ) - { - st_fx->flag_cna = 1; - move16(); - } - ELSE IF( EQ_16( st_fx->core, AMR_WB_CORE ) && st_fx->VAD && LE_32( st_fx->total_brate, ACELP_8k85 ) ) - { - st_fx->flag_cna = 1; - move16(); - } - ELSE IF( st_fx->VAD || ( EQ_16( st_fx->cng_type, FD_CNG ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) - { - st_fx->flag_cna = 0; - move16(); - } - } - if ( EQ_16( st_fx->core, AMR_WB_CORE ) ) - { - st_fx->cng_type = LP_CNG; - move16(); - } - - test(); - test(); - test(); - test(); - IF( st_fx->hFdCngDec && ( ( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) || - ( NE_16( st_fx->hFdCngDec->hFdCngCom->frameSize, st_fx->L_frame ) ) || - st_fx->ini_frame == 0 || NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) ) - { - - IF( NE_16( st_fx->core, AMR_WB_CORE ) ) - { - Word32 tmp; - - tmp = st_fx->total_brate; - move32(); - test(); - if ( EQ_16( st_fx->rf_flag, 1 ) && EQ_32( st_fx->total_brate, ACELP_13k20 ) ) - { - tmp = ACELP_9k60; - move32(); - } - configureFdCngDec_fx( st_fx->hFdCngDec, st_fx->bwidth, tmp, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode ); - } - ELSE - { - configureFdCngDec_fx( st_fx->hFdCngDec, 1, ACELP_8k00, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode ); - - if ( st_fx->VAD ) - { - st_fx->hFdCngDec->hFdCngCom->CngBitrate = st_fx->total_brate; - move32(); - } - } - - test(); - test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && LE_16( st_fx->L_frame, L_FRAME16k ) && LE_16( st_fx->last_L_frame, L_FRAME16k ) ) - { - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - } - - lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st_fx->L_frame, 1 ), shl( st_fx->last_L_frame, 1 ) ); - test(); - IF( LE_32( st_fx->total_brate, SID_2k40 ) && LE_32( st_fx->last_total_brate, SID_2k40 ) ) - { - lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st_fx->L_frame, 1 ), shl( st_fx->last_L_frame, 1 ) ); - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - FOR( i = 0; i < shl( st_fx->L_frame, 1 ); i++ ) - { - st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i], 20480 /* Q15*/ ); /* q_olapBuffer */ - move16(); - } - } - ELSE - { - FOR( i = 0; i < shl( st_fx->L_frame, 1 ); i++ ) - { - st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( shl( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i], 1 ), 26214 /* Q14*/ ); /* q_olapBuffer */ - move16(); - } - } - } - } - } - - return error; -} - -/*---------------------------------------------------------------------* - * core_switching_post_dec() - * - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - -ivas_error core_switching_post_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - const Word16 output_frame, /* i : frame length Q0*/ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ - const Word16 last_element_mode, /* i : element mode of previous frame Q0*/ - Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ -) -{ - Word16 i, delay_comp, delta; - Word16 tmpF, tmp, Fs_kHz, shift, *ptmp1, *ptmp2; - Word32 L_tmp; - Word16 synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP]; - Word16 mem_synth[NS2SA( 16000, DELAY_CLDFB_NS ) + 2]; - Word16 Qtmp; - Word16 Qsubfr; - TD_BWE_DEC_HANDLE hBWE_TD; - FD_BWE_DEC_HANDLE hBWE_FD; - HQ_DEC_HANDLE hHQ_core; - ivas_error error; - - (void) ( last_element_mode ); - hBWE_TD = st_fx->hBWE_TD; - hBWE_FD = st_fx->hBWE_FD; - hHQ_core = st_fx->hHQ_core; - error = IVAS_ERR_OK; - move32(); - - /* Rescale synthesis in Q0 to avoid multiple rescaling after */ - tmp = Find_Max_Norm16( synth, output_frame ); - Scale_sig( synth, output_frame, tmp ); - *Qsynth = add( *Qsynth, tmp ); - move16(); - - test(); - test(); - test(); - IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx ) - { - if ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) - { - return error; - } /*the output at Q0*/ - } - - /* set multiplication factor according to the sampling rate */ - tmp = extract_l( L_shr( st_fx->output_Fs, 13 ) ); /* Q0 */ - Fs_kHz = shl( add( tmp, 1 ), 3 ); /* Q0 */ - - delta = 1; - move16(); - if ( GE_16( output_frame, L_FRAME16k ) ) - { - delta = shr( Fs_kHz, 3 ); /* Q0 */ - } - - /* set delay compensation between HQ synthesis and ACELP synthesis */ - delay_comp = i_mult2( delta, HQ_DELAY_COMP ); /* Q0 */ - - IF( EQ_16( st_fx->core, HQ_CORE ) ) - { - st_fx->use_acelp_preq = 0; - move16(); - /* rescaling to the min exp of the 2 */ - /* Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/ - - hBWE_FD->mem_deemph_old_syn_fx = 0; - move16(); - - test(); - test(); - test(); - IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) - { - if ( ( error = acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr ) ) != IVAS_ERR_OK ) - { - return error; - } - } - test(); - test(); - IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) - { - Copy( st_fx->delay_buf_out_fx, synth_subfr_out, delay_comp ); /* hHQ_core->Q_old_postdec */ - Qsubfr = hHQ_core->Q_old_postdec; - move16(); - } - - /* delay HQ synthesis to synchronize with ACELP synthesis */ - /* rescaling to the min exp of the 2 */ - Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec ); - Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */ - *Qsynth = Qtmp; - move16(); - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); /* Qtmp */ - hHQ_core->Q_old_postdec = Qtmp; - move16(); - delay_signal_fx( synth, output_frame, st_fx->delay_buf_out_fx, delay_comp ); /* Qsynth, Q0 */ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) - { - /* mem_over_hp_fx : Qsubfr */ - core_switching_OLA_fx( mem_synth, st_fx->last_L_frame, st_fx->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st_fx->bwidth, Qsynth, &Qsubfr ); - } - ELSE IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) /* HQ | ACELP | TRANSITION with ACELP frame lost */ - { - /* Overlapp between old->out (stocked in st_fx->fer_samples)and good HQ frame on L/2 */ - ptmp1 = &synth[delay_comp]; /* Qsynth */ - shift = i_mult2( Fs_kHz, 10 ); - tmp = i_mult2( delta, shr( N16_CORE_SW, 1 ) ); - - Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); /* Qsynth */ - ptmp2 = &hHQ_core->fer_samples_fx[tmp]; - tmp = div_s( 1, shift ); /*Q15*/ - tmpF = 0; - move16(); - - FOR( i = 0; i < shift; i++ ) - { - L_tmp = L_mult( ( *ptmp1 ), tmpF ); /*Qsynth + 16*/ - *ptmp1 = round_fx_sat( L_mac_sat( L_tmp, add_sat( sub( 24576, tmpF ), 8192 ), ( *ptmp2 ) ) ); /*Qsynth*/ - ptmp1++; - ptmp2++; - tmpF = add( tmpF, tmp ); - } - } - ELSE IF( ( !core_switching_flag && EQ_16( st_fx->core, HQ_CORE ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* ACELP | TRANSITION | HQ with TRANSITION lost */ - || ( core_switching_flag && st_fx->prev_bfi && NE_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) ) ) - { - /* Overlapp between CELP estimation (BFI) and good HQ frame on L/2 */ - shift = i_mult2( Fs_kHz, 10 ); - tmp = div_s( 1, shift ); /*Q15*/ - tmpF = 0; - move16(); - ptmp1 = synth; - Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); /* Qsynth */ - ptmp2 = hHQ_core->fer_samples_fx; - FOR( i = 0; i < shift; i++ ) - { - L_tmp = L_mult( ( *ptmp1 ), tmpF ); /*Qsynth + 16*/ - *ptmp1 = round_fx_sat( L_mac_sat( L_tmp, add_sat( sub( 24576, tmpF ), 8192 ), ( *ptmp2 ) ) ); /*Qsynth*/ - move16(); - tmpF = add( tmpF, tmp ); - ptmp1++; - ptmp2++; - } - } - - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - IF( !( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_32( st_fx->core_brate, HQ_32k ) ) ) - { - set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - } - Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate( *Qsynth ) ); /*scaling of st_fx->previoussynth_fx set at Q0*/ - - /*Set post-filtering flag to zero*/ - st_fx->hPFstat->on = 0; - move16(); - } - ELSE - { - IF( EQ_16( st_fx->last_core, HQ_CORE ) ) /* MDCT to ACELP transition */ - { - Qtmp = s_min( s_min( *Qsynth, hHQ_core->Q_old_postdec ), hHQ_core->Q_old_wtda ); - - Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qsynth */ - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); /* Qtmp */ - Scale_sig( hHQ_core->old_out_fx, L_FRAME48k, sub( Qtmp, hHQ_core->Q_old_wtda ) ); /* Qtmp */ - *Qsynth = Qtmp; - move16(); - hHQ_core->Q_old_postdec = Qtmp; - move16(); - hHQ_core->Q_old_wtda = Qtmp; - move16(); - - Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame Q0*/ - - tmp = i_mult2( delta, N_ZERO_8 ); - shift = i_mult2( Fs_kHz, 3 ); - test(); - IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) - { - Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[tmp], shift, *Qsynth ); /* Qsynth */ - } - - ptmp2 = &hHQ_core->old_out_fx[tmp]; - tmp = div_s( 1, shift ); - ptmp1 = &synth[delay_comp]; - tmpF = 0; - move16(); - FOR( i = 0; i < shift; i++ ) - { - *ptmp1 = add( mult_r( tmpF, *ptmp1 ), mult_r( sub( 32767, tmpF ), *ptmp2++ ) ); /* Q0 */ - move16(); - ptmp1++; - tmpF = add( tmpF, tmp ); - } - } - - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - hHQ_core->oldHqVoicing = 0; - move16(); - - set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - hHQ_core->prev_frm_hfe2 = 0; - move16(); - hHQ_core->prev_stab_hfe2 = 0; - move16(); - } - /* reset SWB BWE buffers */ - test(); - test(); - test(); - IF( st_fx->bws_cnt == 0 || ( st_fx->bws_cnt > 0 && NE_16( st_fx->coder_type, INACTIVE ) && NE_16( st_fx->coder_type, AUDIO ) ) ) - { - st_fx->attenu_fx = 3277; /* Q15 */ - move16(); + return; } test(); test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) || - ( ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_extl, SWB_TBE ) ) && st_fx->extl < 0 && NE_16( st_fx->core, HQ_CORE ) ) || ( st_fx->last_core == ACELP_CORE && st_fx->core == ACELP_CORE && ( ( NE_16( st_fx->prev_coder_type, INACTIVE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) || ( NE_16( st_fx->prev_coder_type, AUDIO ) && EQ_16( st_fx->coder_type, AUDIO ) ) ) && st_fx->bws_cnt > 0 ) ) + IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) ) { - set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); - hBWE_FD->old_wtda_swb_fx_exp = 0; + /*----------------------------------------------------------------------* + * Calculate tilt of the ACELP core synthesis + *----------------------------------------------------------------------*/ + + st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3 ) ); /* Q11 */ move16(); - if ( NE_16( st_fx->last_extl, WB_BWE ) ) + + /*-------------------------------------------------------------------------------* + * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis + *-------------------------------------------------------------------------------*/ + + edct_16fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); + + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME / 2; i++ ) { - hBWE_FD->prev_mode = NORMAL; - move16(); + L_tmp = L_mac0_sat( L_tmp, syn_dct_fx[i], syn_dct_fx[i] ); /* (2 * Q_syn2) */ } - - hBWE_FD->prev_Energy_fx = 0; - move16(); - hBWE_FD->prev_L_swb_norm = 8; - move16(); - hBWE_FD->prev_frica_flag = 0; - move16(); - set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); - hBWE_FD->prev_td_energy_fx = 0; - move16(); - hBWE_FD->prev_weight_fx = 6554; - move16(); /*0.2 in Q15*/ - hBWE_FD->prev_fb_ener_adjust_fx = 0; - move16(); + L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ + st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ + move32(); + L_tmp = L_deposit_l( 0 ); + FOR( ; i < L_FRAME; i++ ) + { + L_tmp = L_mac0_sat( L_tmp, syn_dct_fx[i], syn_dct_fx[i] ); + } + L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ + st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ + move32(); } - - /* reset WB BWE buffers */ - test(); - IF( NE_16( st_fx->last_extl, WB_BWE ) && EQ_16( st_fx->extl, WB_BWE ) ) + ELSE { - set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); - - test(); - IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) + IF( st_fx->hHQ_core->old_is_transient[0] ) { - hBWE_FD->prev_mode = NORMAL; - move16(); + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < 32; i++ ) + { + L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ + } + L_tmp = L_shr( L_tmp, 5 ); /* 2 * Q_syn2 */ + st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ + move32(); + L_tmp = L_deposit_l( 0 ); + FOR( ; i < 64; i++ ) + { + L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ + } + L_tmp = L_shr( L_tmp, 5 ); /* 2 * Q_syn2 */ + st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ + move32(); + } + ELSE + { + L_tmp = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME / 2; i++ ) + { + L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ + } + L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ + st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ + move32(); + L_tmp = L_deposit_l( 0 ); + FOR( ; i < L_FRAME; i++ ) + { + L_tmp = L_mac0_sat( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i] ); /* 2 * Q_syn2 */ + } + L_tmp = L_shr( L_tmp, 7 ); /* 2 * Q_syn2 */ + st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */ + move32(); } - hBWE_FD->prev_Energy_wb_fx = 0; - move16(); - hBWE_FD->prev_L_swb_norm = 8; - move16(); - set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); - hBWE_FD->prev_flag = 0; - move16(); } - /* reset SWB TBE buffers */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); test(); test(); test(); @@ -1187,79 +179,52 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - test(); - test(); - IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) && - ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) || - ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) ) + IF( st_fx->last_bwidth == 0 && LE_16( st_fx->extl, SWB_CNG ) ) { - swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - - set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); - - IF( EQ_16( output_frame, L_FRAME16k ) ) - { - /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ - set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - } - set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); - set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); + st_fx->prev_ener_shb_fx = 0; + move16(); + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); } - ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && - ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || - NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_flag, st_fx->rf_flag_last ) ) ) + ELSE IF( ( ( st_fx->core == ACELP_CORE && ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st_fx->core, st_fx->last_core ) && NE_16( st_fx->extl, st_fx->last_extl ) ) ) && GE_16( st_fx->last_bwidth, SWB ) ) { - set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->gain_prec_swb_fx = 16384; - move16(); /*Q14 = 1 */ + st_fx->attenu_fx = 3277; /* Q15 */ + move16(); } - /* Interp_3_2 CNG buffers reset */ test(); test(); test(); - IF( st_fx->hTdCngDec != NULL && EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) ) - { - set16_fx( st_fx->hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); - } - - /* reset FB TBE buffers */ test(); test(); - IF( EQ_16( st_fx->extl, FB_TBE ) && ( NE_16( st_fx->last_extl, FB_TBE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) ) + IF( EQ_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && !( EQ_16( st_fx->last_extl, WB_TBE ) || EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && GT_32( st_fx->core_brate, ACELP_8k00 ) ) ) { - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; + st_fx->prev_fractive = 0; move16(); - fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } - /* reset WB TBE buffers */ - test(); - IF( NE_16( st_fx->last_extl, WB_TBE ) && EQ_16( st_fx->extl, WB_TBE ) ) - { - wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); + return; +} - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); - set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); - } - return error; -} +/*---------------------------------------------------------------------* + * core_switching_post_dec() + * + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ -ivas_error core_switching_post_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ - Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ +ivas_error core_switching_post_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth, /* i/o: output synthesis Qsynth*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ +#else + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ +#endif +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#else + Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ +#endif const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -1302,8 +267,7 @@ ivas_error core_switching_post_dec_ivas_fx( test(); IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx ) { - /*needed to be converted to fixed curretnly using evs implementation not in line*/ - if ( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) + IF( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; } /*the output at Q0*/ @@ -1315,14 +279,14 @@ ivas_error core_switching_post_dec_ivas_fx( delta = 1; move16(); - IF( GE_16( output_frame, L_FRAME16k ) ) + if ( GE_16( output_frame, L_FRAME16k ) ) { delta = shr( Fs_kHz, 3 ); } /* set delay compensation between HQ synthesis and ACELP synthesis */ delay_comp = i_mult2( delta, HQ_DELAY_COMP ); /* Q0 */ - /*needed to add more condition in if*/ + test(); test(); test(); @@ -1339,10 +303,7 @@ ivas_error core_switching_post_dec_ivas_fx( { st_fx->use_acelp_preq = 0; move16(); - /* rescaling to the min exp of the 2 */ - /* Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/ + IF( st_fx->hBWE_FD != NULL ) { hBWE_FD->mem_deemph_old_syn_fx = 0; @@ -1372,27 +333,31 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); } } + /* delay HQ synthesis to synchronize with ACELP synthesis */ /* rescaling to the min exp of the 2 */ - Word16 NonZero = 1; - move16(); - FOR( i = 0; i < delay_comp; i++ ) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - IF( st_fx->delay_buf_out_fx[i] != 0 ) + Word16 NonZero = 1; + move16(); + FOR( i = 0; i < delay_comp; i++ ) + { + IF( st_fx->delay_buf_out_fx[i] != 0 ) + { + NonZero = 0; + move16(); + break; + } + } + test(); + IF( hHQ_core->Q_old_postdec >= 0 || EQ_16( NonZero, 1 ) ) { - NonZero = 0; + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /* Q0 */ + hHQ_core->Q_old_postdec = 0; move16(); - break; } - } - test(); - IF( hHQ_core->Q_old_postdec >= 0 || EQ_16( NonZero, 1 ) ) - { - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /* Q0 */ - hHQ_core->Q_old_postdec = 0; move16(); } - move16(); Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec ); Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */ *Qsynth = Qtmp; @@ -1481,7 +446,11 @@ ivas_error core_switching_post_dec_ivas_fx( test(); IF( ( ( NE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_core_brate, FRAME_NO_DATA ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) && NE_16( st_fx->element_mode, IVAS_CPE_TD ) ) || EQ_16( nchan_out, 1 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_fx->idchan, 1 ) && ( EQ_16( nchan_out, 1 ) || EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) ) { - Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 ); /* Q10 */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Scale_sig32( output_fx, L_FRAME48k, Q10 - Q11 ); /* Q10 */ +#else + Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 ); /* Q10 */ +#endif core_switch_lb_upsamp_fx( st_fx, output_fx ); } @@ -1539,7 +508,11 @@ ivas_error core_switching_post_dec_ivas_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ +#else Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ +#endif move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -1557,7 +530,6 @@ ivas_error core_switching_post_dec_ivas_fx( } ELSE IF( st_fx->element_mode != EVS_MONO ) { - /*needed to be filled with ivas specific code*/ /* Reset memories of CLDFBs */ IF( st_fx->cldfbAna != NULL ) { @@ -1589,7 +561,11 @@ ivas_error core_switching_post_dec_ivas_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ +#else Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ +#endif move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -1605,6 +581,7 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); } } + IF( st_fx->hBWE_TD != NULL ) { hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); @@ -1650,10 +627,18 @@ ivas_error core_switching_post_dec_ivas_fx( hHQ_core->Q_old_wtda = Qtmp; move16(); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word16 output_mem_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; + IF( output_mem_fx32 != NULL ) + { + Copy_Scale_sig_32_16( output_mem_fx32, output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Qtmp, Q11 ) ); // Qtmp + } +#else IF( output_mem_fx != NULL ) { Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */ } +#endif *Qsynth = Qtmp; move16(); @@ -1723,6 +708,15 @@ ivas_error core_switching_post_dec_ivas_fx( hHQ_core->oldHqVoicing = 0; move16(); } + + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2 = 0; + move16(); + hHQ_core->prev_stab_hfe2 = 0; + move16(); + } } } ELSE @@ -1834,7 +828,6 @@ ivas_error core_switching_post_dec_ivas_fx( test(); test(); test(); - IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) && ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) || ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) ) @@ -1910,6 +903,7 @@ ivas_error core_switching_post_dec_ivas_fx( return error; } + /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * @@ -1993,9 +987,17 @@ void core_switching_hq_prepare_dec_fx( /* reset state of old_out if switching */ set16_fx( st_fx->hHQ_core->old_out_fx, 0, output_frame ); + return; } + +/*---------------------------------------------------------------------* + * core_switch_lb_upsamp() + * + * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz) + *---------------------------------------------------------------------*/ + static void core_switch_lb_upsamp_fx( Decoder_State *st, /* i/o: Decoder state */ Word32 *output /* i/o: LB synth/upsampled LB synth Q10*/ @@ -2071,17 +1073,36 @@ static void core_switch_lb_upsamp_fx( no_col = s_min( no_col, temp ); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( st->hTcxDec->L_frameTCX, imult1616( no_col, st->cldfbSyn->no_channels ) ), Q11 - Q10 ); /* Q11 */ +#else Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( L_FRAME48k, imult1616( no_col, st->cldfbSyn->no_channels ) ), 4 - 10 ); /* Q4 */ +#endif /* save synthesis - needed in case of core switching */ IF( st->hTcxDec != NULL ) { - Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -4 ); /* Q0 */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ +#else + Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ +#endif } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Scale_sig32( output, imult1616( no_col, st->cldfbSyn->no_channels ), Q11 - Q4 ); /* Q11 */ +#endif + return; } + +/*---------------------------------------------------------------------* + * smoothTransitionDtxToTcx() + * + * apply smoothing to the transition part for inactive to active transitions in DTX + *---------------------------------------------------------------------*/ + #define TRANSITION_SMOOTHING_LEN_16k 15 #define TRANSITION_SMOOTHING_LEN_32k 31 #define TRANSITION_SMOOTHING_LEN_48k 47 @@ -2165,22 +1186,36 @@ static void smoothTransitionDtxToTcx_fx( * * Preprocessing/preparation for ACELP/HQ core switching *---------------------------------------------------------------------*/ -ivas_error core_switching_pre_dec_ivas_fx( + +ivas_error core_switching_pre_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 output_frame, /* i : frame length */ const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ - Word16 Q_old_synthFB, + const Word16 Q_old_synthFB, Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 ) { Word32 tmp_fx; /*Q-12*/ Word16 i, oldLenClasBuff, newLenClasBuff; ivas_error error; - Word16 exp = 25; + Word16 tmp, exp = Q25; + Word32 L_tmp; move16(); + BPF_DEC_HANDLE hBPF; + TD_BWE_DEC_HANDLE hBWE_TD; + FD_BWE_DEC_HANDLE hBWE_FD; + HQ_DEC_HANDLE hHQ_core; + TCX_DEC_HANDLE hTcxDec; + + hBWE_TD = st->hBWE_TD; + hBWE_FD = st->hBWE_FD; + hHQ_core = st->hHQ_core; + hBPF = st->hBPF; + hTcxDec = st->hTcxDec; + error = IVAS_ERR_OK; move32(); @@ -2190,9 +1225,9 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) ) { - st->mem_deemph_fx = st->syn[M]; + st->mem_deemph_fx = st->syn[M]; /* Q_syn */ move16(); - set16_fx( st->agc_mem_fx, 0, 2 ); + set16_fx( st->agc_mem_fx, 0, 2 ); /* Q0 */ Scale_sig( &( st->mem_deemph_fx ), 1, st->Q_syn ); /* Brings mem_deemph to Qsyn */ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ @@ -2204,12 +1239,12 @@ ivas_error core_switching_pre_dec_ivas_fx( Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ - set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ } - IF( st->hBPF != NULL ) + IF( hBPF != NULL ) { - st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ - st->hBPF->pst_mem_deemp_err_fx = 0; + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ + hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ + hBPF->pst_mem_deemp_err_fx = 0; move16(); move16(); } @@ -2219,23 +1254,23 @@ ivas_error core_switching_pre_dec_ivas_fx( /* reset old HB synthesis buffer */ IF( EQ_16( st->last_L_frame, L_FRAME ) ) { - st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + st->old_bwe_delay = NS2SA_FX2( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } ELSE { - st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + st->old_bwe_delay = NS2SA_FX2( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } move16(); set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); test(); - IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) + IF( hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) { - st->hBWE_TD->prev_hb_synth_fx_exp = 31; + hBWE_TD->prev_hb_synth_fx_exp = Q31; move16(); /* reset BWE memories */ - set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* Q_exc */ + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } @@ -2247,35 +1282,36 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); test(); - IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) + IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); + IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } - IF( st->hBWE_FD != NULL ) + IF( hBWE_FD != NULL ) { - set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - st->hHQ_core->last_max_pos_pulse = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); IF( GT_32( st->output_Fs, 16000 ) ) { - set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } /* pre-echo */ - st->hHQ_core->pastpre = 0; + hHQ_core->pastpre = 0; move16(); } @@ -2294,20 +1330,19 @@ ivas_error core_switching_pre_dec_ivas_fx( st->last_core = HQ_CORE; move16(); - Copy32( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - // Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0 + Copy( hTcxDec->FBTCXdelayBuf, st->prev_synth_buffer_fx, NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /* st->q_prev_synth_buffer_fx */ } - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); - st->hHQ_core->last_max_pos_pulse = 0; + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st->hHQ_core->prev_frm_hfe2 = 0; - st->hHQ_core->prev_stab_hfe2 = 0; + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); move16(); } @@ -2318,66 +1353,114 @@ ivas_error core_switching_pre_dec_ivas_fx( Word16 delay_comp; /*switch off Hq Voicing as it was not updated in MODE2*/ - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - st->hHQ_core->oldHqVoicing = 0; - st->hHQ_core->HqVoicing = 0; + hHQ_core->oldHqVoicing = 0; + hHQ_core->HqVoicing = 0; move16(); move16(); } - delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - /*TODO To be tested:control not entering the block*/ - test(); - test(); - IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + test(); + test(); + IF( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && EQ_16( st->core, HQ_CORE ) ) + { + Word16 no_col; + Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; + Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + CLDFB_SCALE_FACTOR scaleFactor; + Word32 workBuffer[128 * 3]; + + FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) + { + set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer[i] = realBufferTmp[i]; + move32(); + imagBuffer[i] = imagBufferTmp[i]; + move32(); + } + + no_col = s_min( st->cldfbAna->no_col, idiv1616( sub( add( delay_comp, st->cldfbAna->no_channels ), 1 ), st->cldfbAna->no_channels ) ); /* Q0 */ + + /* CLDFB analysis of the synthesis at internal sampling rate */ + IF( ( error = cldfb_save_memory( st->cldfbAna ) ) != IVAS_ERR_OK ) + { + return error; + } + cldfbAnalysis_fx( st->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer ); + cldfb_restore_memory( st->cldfbAna ); + + scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); + + /* CLDFB synthesis of the combined signal */ + IF( ( error = cldfb_save_memory( st->cldfbSyn ) ) != IVAS_ERR_OK ) + { + return error; + } + cldfbSynthesis_fx( st->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer ); + cldfb_restore_memory( st->cldfbSyn ); + } + } + ELSE { - /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ - assert( 0 ); - Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH]; - Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; - Word32 syn_Overl_fx[320]; - Word32 fer_samples_fx[960]; - Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 ); - Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 ); + /*TODO To be tested:control not entering the block*/ + test(); + test(); + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + { + /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ + assert( 0 ); + Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH]; + Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + Word32 syn_Overl_fx[320]; + Word32 fer_samples_fx[960]; + Copy_Scale_sig_16_32_DEPREC( hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 ); + Copy_Scale_sig_16_32_DEPREC( hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 ); - FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) - { - set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); - realBuffer_fx[i] = realBufferTmp_fx[i]; - imagBuffer_fx[i] = imagBufferTmp_fx[i]; - } + FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) + { + set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer_fx[i] = realBufferTmp_fx[i]; + imagBuffer_fx[i] = imagBufferTmp_fx[i]; + } - /* CLDFB analysis of the synthesis at internal sampling rate */ - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) ) - { - return error; - } + /* CLDFB analysis of the synthesis at internal sampling rate */ + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) ) + { + return error; + } - cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna ); - cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ + cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna ); + cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ - /* CLDFB synthesis of the combined signal */ - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) ) - { - return error; - } + /* CLDFB synthesis of the combined signal */ + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) ) + { + return error; + } - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, 0, 0, st->cldfbSyn ); - cldfb_restore_memory_ivas_fx( st->cldfbSyn ); - Copy_Scale_sig_32_16( syn_Overl_fx, st->hTcxDec->syn_Overl, 320, 15 ); - Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 ); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, 0, 0, st->cldfbSyn ); + cldfb_restore_memory_ivas_fx( st->cldfbSyn ); + Copy_Scale_sig_32_16( syn_Overl_fx, hTcxDec->syn_Overl, 320, 15 ); + Copy_Scale_sig_32_16( fer_samples_fx, hHQ_core->fer_samples_fx, 960, 9 ); + } } test(); test(); IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { - lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); + lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); /*Set to zero the remaining part*/ - set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); + set16_fx( hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); } } @@ -2395,17 +1478,35 @@ ivas_error core_switching_pre_dec_ivas_fx( { IF( NE_16( st->L_frame, st->last_L_frame ) ) { - IF( GT_16( st->L_frame, st->last_L_frame ) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); + IF( GT_16( st->L_frame, st->last_L_frame ) ) + { + oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + } + ELSE + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + newLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); + } } ELSE { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); + IF( GT_16( st->L_frame, st->last_L_frame ) ) + { + oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + } + ELSE + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); + } } lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } @@ -2413,6 +1514,8 @@ ivas_error core_switching_pre_dec_ivas_fx( ELSE { set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); + st->classifier_Q_mem_syn = 0; + move16(); } } @@ -2490,10 +1593,11 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) { /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ - set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); - set16_fx( st->agc_mem_fx, 0, 2 ); } + + set16_fx( st->agc_mem_fx, 0, 2 ); st->mem_deemph_fx = 0; move16(); IF( !st->last_con_tcx ) @@ -2501,9 +1605,9 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->mem_syn2_fx, 0, M ); } set16_fx( st->mem_syn1_fx, 0, M ); - if ( st->hBWE_TD != NULL ) + if ( hBWE_TD != NULL ) { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } @@ -2512,11 +1616,11 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* Q2.56 */ } ELSE { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* Q2.56 */ } st->tilt_code_fx = 0; @@ -2532,13 +1636,38 @@ ivas_error core_switching_pre_dec_ivas_fx( st->last_coder_type = GENERIC; move16(); - fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ - st->lp_gainp_fx = 0; - move16(); - st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ - move16(); - st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ - move16(); + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + frame_ener_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); + st->lp_gainp_fx = 0; + move16(); + + IF( st->lp_ener_fx != 0 ) + { + exp = norm_l( st->lp_ener_fx ); /* In Q6 */ + tmp = extract_h( L_shl( st->lp_ener_fx, exp ) ); + exp = sub( exp, 30 - 6 ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + + st->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ + move16(); + } + } + ELSE + { + Word32 previoussynth_fx_32[L_FRAME48k]; + Copy_Scale_sig_16_32_no_sat( st->previoussynth_fx, previoussynth_fx_32, output_frame, 0 ); + fer_energy_fx( output_frame, UNVOICED_CLAS, previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q0*/ + st->lp_gainp_fx = 0; + move16(); + st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ + move16(); + st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ + move16(); + } st->last_voice_factor_fx = 0; st->Last_GSC_noisy_speech_flag = 0; @@ -2546,9 +1675,18 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); /* reset CLDFB memories */ - cldfb_reset_memory_fx( st->cldfbAna ); - cldfb_reset_memory_fx( st->cldfbBPF ); - cldfb_reset_memory_fx( st->cldfbSyn ); + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + cldfb_reset_memory( st->cldfbAna ); + cldfb_reset_memory( st->cldfbBPF ); + cldfb_reset_memory( st->cldfbSyn ); + } + ELSE + { + cldfb_reset_memory_fx( st->cldfbAna ); + cldfb_reset_memory_fx( st->cldfbBPF ); + cldfb_reset_memory_fx( st->cldfbSyn ); + } /* reset TBE memories */ test(); @@ -2563,21 +1701,22 @@ ivas_error core_switching_pre_dec_ivas_fx( synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); } - IF( st->hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { - set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } test(); - IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) + IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); + IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } - IF( st->hBWE_FD != NULL ) + IF( hBWE_FD != NULL ) { - set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); } } @@ -2586,11 +1725,11 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { - IF( st->hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); - set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } st->tilt_code_fx = 0; @@ -2604,7 +1743,9 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->last_coder_type = GENERIC; move16(); - fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ + Word32 previoussynth_fx_32[L_FRAME48k]; + Copy_Scale_sig_16_32_no_sat( st->previoussynth_fx, previoussynth_fx_32, output_frame, 0 ); + fer_energy_fx( output_frame, UNVOICED_CLAS, previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q0*/ st->lp_gainp_fx = 0; move16(); @@ -2619,15 +1760,15 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); test(); - IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) + IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } - IF( st->hBWE_FD != NULL ) + IF( hBWE_FD != NULL ) { - set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } test(); @@ -2638,17 +1779,11 @@ ivas_error core_switching_pre_dec_ivas_fx( /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ Word16 offset; offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Word32 *old_synthFB_fx; - IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) ); - } - Copy_Scale_sig_16_32_no_sat( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10 - Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); + Word32 old_synthFB_fx[L_FRAME_PLUS * 2]; + Copy_Scale_sig_16_32_no_sat( hTcxDec->old_synthFB_fx, old_synthFB_fx, hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10 + Copy32( old_synthFB_fx + hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); st->cldfbAna->Q_cldfb_state = Q10; move16(); - IF( old_synthFB_fx ) - free( old_synthFB_fx ); } } @@ -2658,22 +1793,22 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) { - set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); - st->hHQ_core->last_max_pos_pulse = 0; + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st->hHQ_core->prev_frm_hfe2 = 0; - st->hHQ_core->prev_stab_hfe2 = 0; + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); move16(); IF( GT_32( st->output_Fs, 16000 ) ) { - set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } IF( st->element_mode != EVS_MONO ) @@ -2681,48 +1816,53 @@ ivas_error core_switching_pre_dec_ivas_fx( /* Estimate mem_env_delta to reinit env_stab */ tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/ - st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ + hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ move16(); test(); IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) { - set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); - set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); - set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); + set16_fx( hHQ_core->old_out_fx, 0, output_frame ); + set32_fx( hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); + set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); } - st->hHQ_core->no_att_hangover = 0; + hHQ_core->no_att_hangover = 0; move16(); - st->hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/ move32(); - set16_fx( st->hHQ_core->old_is_transient, 0, 3 ); - set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 ); - st->hHQ_core->prev_R = 0; + set16_fx( hHQ_core->old_is_transient, 0, 3 ); + set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); + hHQ_core->prev_R = 0; move16(); - set16_fx( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); - st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; - st->hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + set16_fx( hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ move16(); move16(); - set16_fx( st->hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); + set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); } ELSE { - set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); - set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); + set16_fx( hHQ_core->old_out_fx, 0, output_frame ); + set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); + hHQ_core->Q_old_wtda_LB = Q15; + move16(); + hHQ_core->Q_old_wtda = Q15; + move16(); } } /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 ); + hHQ_core->pastpre = sub( hHQ_core->pastpre, 1 ); move16(); - IF( st->hHQ_core->pastpre < 0 ) + IF( hHQ_core->pastpre < 0 ) { - reset_preecho_dec_fx( st->hHQ_core ); + reset_preecho_dec_fx( hHQ_core ); } } + test(); IF( st->core_brate == FRAME_NO_DATA ) { @@ -2740,10 +1880,8 @@ ivas_error core_switching_pre_dec_ivas_fx( st->m_frame_type = ACTIVE_FRAME; } - move16(); - move16(); /*switch on CNA on active frames*/ - IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ + IF( st->element_mode == EVS_MONO ) /* for IVAS modes, st->flag_cna is set earlier */ { test(); test(); @@ -2779,10 +1917,18 @@ ivas_error core_switching_pre_dec_ivas_fx( /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ IF( NE_16( st->core, AMR_WB_CORE ) ) { + L_tmp = st->total_brate; + move32(); test(); - IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) + if ( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) + { + L_tmp = ACELP_9k60; + move32(); + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, ACELP_9k60, st->L_frame, st->last_L_frame, st->element_mode ); + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, L_tmp, st->L_frame, st->last_L_frame, st->element_mode ); } ELSE { @@ -2791,7 +1937,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } ELSE { - configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); + configureFdCngDec_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); if ( st->VAD ) { @@ -2799,6 +1945,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move32(); } } + test(); test(); IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) ) @@ -2809,27 +1956,56 @@ ivas_error core_switching_pre_dec_ivas_fx( lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame ); } - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 ); - - test(); - IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth ); - - IF( EQ_16( st->L_frame, L_FRAME ) ) + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); + test(); + IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { - FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); + + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); - move32(); + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[i], 20480 /* Q15*/ ); /* q_olapBuffer */ + move16(); + } + } + ELSE + { + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[i], 1 ), 26214 /* Q14*/ ); /* q_olapBuffer */ + move16(); + } } } - ELSE + } + ELSE + { + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 ); + + test(); + IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { - FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth ); + + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); - move32(); + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); + move32(); + } + } + ELSE + { + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); + move32(); + } } } } @@ -2838,12 +2014,7 @@ ivas_error core_switching_pre_dec_ivas_fx( return error; } -/*---------------------------------------------------------------------* - * core_switching_hq_prepare_dec() - * - * Preprocessing in the first HQ frame after ACELP frame - * Modify bit allocation for HQ core by removing ACELP subframe budget - *---------------------------------------------------------------------*/ + /*---------------------------------------------------------------------* * bandwidth_switching_detect() @@ -2851,7 +2022,7 @@ ivas_error core_switching_pre_dec_ivas_fx( * Classification for band-width switching *---------------------------------------------------------------------*/ -void bandwidth_switching_detect_ivas_fx( +void bandwidth_switching_detect_fx( Decoder_State *st_fx /* i/o: encoder state structure */ ) { @@ -2966,191 +2137,3 @@ void bandwidth_switching_detect_ivas_fx( return; } - - -/*---------------------------------------------------------------------* - * bw_switching_pre_proc() - * - * Band-width switching pre-processing - *---------------------------------------------------------------------*/ -void ivas_bw_switching_pre_proc_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 nchan_out /* i : number of output channels */, - Word32 *old_syn_12k8_16k_fx, - Word16 Q, - Word16 Q_audio ) -{ - Word16 i; - Word32 syn_dct_fx[L_FRAME]; - - - IF( st->element_mode > EVS_MONO ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) - { - /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ - Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; - Copy_Scale_sig_32_16( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_16fx, st->L_frame, sub( -1, Q ) ); - st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16 - move16(); - } - - return; - } - - - test(); - test(); - IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) - { - /*----------------------------------------------------------------------* - * Calculate tilt of the ACELP core synthesis - *----------------------------------------------------------------------*/ - - st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame ); - move16(); - /*-------------------------------------------------------------------------------* - * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis - *-------------------------------------------------------------------------------*/ - edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q ); - Word64 W_tmp = 0; - move64(); - Word32 tmp; - Word16 shift; - FOR( i = 0; i < L_FRAME / 2; i++ ) - { - W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) ); - } - shift = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, shift ); - tmp = W_extract_h( W_tmp ); - tmp = L_shr( tmp, 8 ); - - tmp = getSqrtWord32( tmp ); - st->enerLL_fx = tmp; - move32(); - st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); - move16(); - W_tmp = 0; - move64(); - FOR( ; i < L_FRAME; i++ ) - { - W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) ); - } - shift = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, shift ); - tmp = W_extract_h( W_tmp ); // Q = Q + shift - 32 - tmp = L_shr( tmp, 7 ); // divide by 128 - tmp = getSqrtWord32( tmp ); - st->enerLH_fx = tmp; - move32(); - st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); - move16(); - } - ELSE - { - IF( st->hHQ_core->old_is_transient[0] ) - { - Word32 tmp, L_tmp = 0; - move32(); - FOR( i = 0; i < 32; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i] ); - } - tmp = L_shr( L_tmp, 5 ); // divide by 32 - tmp = getSqrtWord32( tmp ); - st->enerLL_fx = tmp; - move32(); - st->enerLL_fx_Q = Q_audio; - move16(); - - L_tmp = 0; - move32(); - FOR( ; i < 64; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i] ); - } - - tmp = L_shr( L_tmp, 5 ); // divide by 32 - tmp = getSqrtWord32( tmp ); - st->enerLH_fx = tmp; - move32(); - st->enerLH_fx_Q = Q_audio; - move16(); - } - ELSE - { - Word32 tmp, L_tmp = 0; - move32(); - FOR( i = 0; i < L_FRAME / 2; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i] ); - } - tmp = L_shr( L_tmp, 5 ); // divide by 32 - tmp = getSqrtWord32( tmp ); - st->enerLL_fx = tmp; - move32(); - st->enerLL_fx_Q = Q_audio; - move16(); - - L_tmp = 0; - move32(); - FOR( ; i < L_FRAME; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i] ); - } - tmp = L_shr( L_tmp, 5 ); // divide by 32 - tmp = getSqrtWord32( tmp ); - st->enerLL_fx = tmp; - move32(); - st->enerLL_fx_Q = Q_audio; - move16(); - } - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) - { - st->prev_ener_shb_fx = 0; - move16(); - IF( st->hBWE_FD != NULL ) - { - set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); - } - } - ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) - { - st->attenu_fx = 3277; // 0.1f in Q15 - move16(); - } - - test(); - test(); - test(); - test(); - test(); - if ( EQ_16( st->last_core, HQ_CORE ) || ( ( st->last_core == ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) - { - st->prev_fractive = 0; - move16(); - } - - return; -} diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 9515aefe898464d21f318f419e654ab748d92957..00ff81afedaba35ac89a81a7cc2ebca47e030fe1 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -556,7 +556,7 @@ void decoder_LPD_fx( move16(); } - int_lsp4_ivas_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); + int_lsp4_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); } ELSE { @@ -930,16 +930,14 @@ void decoder_LPD_fx( E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); E_LPC_a_lsp_conversion( A, lsptmp, &xspnew_uw[0], M ); Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 1 ); - cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, - st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, - Qexc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); + + cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + Qexc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, EVS_MONO, -1 ); } ELSE { - cng_params_upd_fx( &lsp[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, - st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, - &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, - st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); + cng_params_upd_fx( &lsp[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, EVS_MONO, -1 ); } /* Set 16k LSP flag for CNG buffer */ diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 0d867fd6f0708fc01193345fa209e6302c4eabc9..ac137b37c99be1174fcc91f5a549d265eeeff808 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -353,7 +353,7 @@ void decoder_acelp_fx( IF( st->igf != 0 ) { - tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); + tbe_celp_exc_fx( EVS_MONO, 0, st->L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, 0 ); } pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); // Q6 diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 94d4486b1692b4bb9c0d9d76ae127ae2d526748a..1eccbfeab0344714846a2e1d48fb2330596446d6 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -479,7 +479,7 @@ Word16 dec_acelp_tcx_frame_fx( test(); IF( st->core == ACELP_CORE && st->igf != 0 && st->con_tcx == 0 ) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors, st->L_frame ); + non_linearity_fx( EVS_MONO, ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors, st->L_frame ); /* update the old BWE exe memory */ Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); } diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index c65162afcdb24dac8a49a954240e671cfc1272eb..af6c706f707b26fa9080b21007ba168478c7c1cc 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -84,6 +84,7 @@ void decod_amr_wb_fx( *--------------------------------------------------------------*/ lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_FRAME, lp_flag, exc_fx ); + /*--------------------------------------------------------------* * Innovation decoding *--------------------------------------------------------------*/ @@ -98,9 +99,9 @@ void decod_amr_wb_fx( gain_dec_amr_wb_fx( st_fx, st_fx->core_brate, &gain_pit_fx, &L_gain_code_fx, hAmrwb_IO->past_qua_en_fx, &gain_inov_fx, code_fx, &L_norm_gain_code_fx ); /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); + lp_gain_updt_fx( EVS_MONO, i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, 0, diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index f7640abe7f632fc12eede8fbd214f933d651677c..e1a3917df5d5f1e1885f1db2cc5c36e825e02ab5 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -164,6 +164,7 @@ ivas_error decod_gen_voic_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ + IF( st_fx->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); @@ -173,13 +174,14 @@ ivas_error decod_gen_voic_fx( pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } - // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); - tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); + tbe_celp_exc_fx( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ + lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx ); + /*-----------------------------------------------------------------* * Transform-domain contribution decoding (active frames) *-----------------------------------------------------------------*/ @@ -215,12 +217,14 @@ ivas_error decod_gen_voic_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15 + + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ + test(); IF( !st_fx->inactive_coder_type_flag && st_fx->coder_type == INACTIVE ) { @@ -228,14 +232,7 @@ ivas_error decod_gen_voic_fx( } /* update LP filtered gains for the case of frame erasures */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); - } - ELSE - { - lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); - } + lp_gain_updt_fx( st_fx->element_mode, i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation @@ -368,7 +365,6 @@ ivas_error decod_gen_voic_fx( } /* FEC fast recovery */ - IF( do_WI_fx ) { /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 85f83ca61a68c8f4dda8181f9c6093b4fbf1cd28..5e02f9913af51236c2fd65bef4eb000879738288 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ #include #include "options.h" /* Compilation switches */ -#include #include "cnst.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ @@ -198,7 +197,8 @@ void transf_cdbk_dec_fx( st_fx->last_code_preq = code_preQ[L_SUBFR - 1]; // q_Code_preQ move16(); - PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); + /*--------------------------------------------------------------* * Compute normalized prequantizer excitation gain for FEC * diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 645444e7da153aae1e206c04a23616839199f2c9..83818d1c9aae785f8534622fa770f1b6dc283cc1 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -202,12 +202,11 @@ void dec_pit_exc_fx( gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx ); move16(); } ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */ { - /*inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);*/ inov_decode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); /*--------------------------------------------------------------* @@ -217,7 +216,7 @@ void dec_pit_exc_fx( gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx ); move16(); } ELSE @@ -250,6 +249,7 @@ void dec_pit_exc_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); @@ -418,7 +418,7 @@ void dec_pit_exc_fx( move16(); pt_gain++; - lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); + lp_gain_updt_fx( st_fx->element_mode, i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); } } diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index bb24978b22dbfac33cece7743f571b7b12242d9a..1a568cbf9a109fabc600841fc3ed3afab2f9aad7 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -35,7 +35,7 @@ static void modify_pst_param_fx( const Word16 lp_noise, Word16 *g1, Word16 *g2, static void Dec_formant_postfilt_fx( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); -static void calc_st_filt_ivas_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero, const Word16 extl ); +static void Filt_mu_fx( Word16 *sig_in, Word16 *sig_out, Word16 parcor0, Word16 L_subfr ); /*-------------------------------------------------------------------------- @@ -72,11 +72,13 @@ void Init_post_filter_fx( return; } + /*-------------------------------------------------------------------------- * NB_post_filt: * * Main routine to perform post filtering on NB synthesis *--------------------------------------------------------------------------*/ + void nb_post_filt_fx( const Word16 L_frame, /* i : frame length */ PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ @@ -132,7 +134,6 @@ void nb_post_filt_fx( move16(); } - /* run the post filter */ p_Aq = Aq; // Q12 move16(); @@ -148,10 +149,10 @@ void nb_post_filt_fx( j = add( j, 1 ); } - return; } + /*---------------------------------------------------------------------------- * Dec_postfilt() * @@ -175,15 +176,16 @@ void nb_post_filt_fx( * 1. search around 1st subframe delay (3 integer values) * 2. search around best integer with fract. delays (1/8) *----------------------------------------------------------------------------*/ + static void Dec_postfilt_fx( PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ const Word16 t0, /* i : pitch delay given by coder Q0 */ const Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q0 */ - const Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ + const Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output Q15*/ const Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ const Word16 gamma2, /* i : short term postfilt. num. weighting factor Q15*/ - const Word16 Gain_factor, /* i : Gain Factor (Q15) */ + const Word16 Gain_factor, /* i : Gain Factor (Q15) */ const Word16 disable_hpf ) { /* Local variables and arrays */ @@ -191,14 +193,11 @@ static void Dec_postfilt_fx( Word16 apond2[LONG_H_ST]; // Q12 Word16 sig_ltp[L_SUBFR + 1]; /* H0 output signal */ Word16 res2[SIZ_RES2]; // Q0 - Word16 *sig_ltp_ptr; Word16 *res2_ptr; Word16 *ptr_mem_stp; - Word16 parcor0; // Q15 - /* Init pointers and restore memories */ res2_ptr = res2 + DECMEM_RES2; ptr_mem_stp = hPFstat->mem_stp + L_SYN_MEM - 1; @@ -244,10 +243,10 @@ static void Dec_postfilt_fx( /* Update for next subframe */ Copy( &res2[L_SUBFR], hPFstat->mem_res2, DECMEM_RES2 ); - return; } + /*-------------------------------------------------------------------------- * formant_post_filt_fx: * @@ -445,7 +444,7 @@ static void Dec_formant_postfilt_fx( } /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt_ivas_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero, -1 ); + calc_st_filt_local_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero ); /* 1/A(gamma1) filtering, mem_stp is updated */ resynth[0] = *( hPFstat->mem_stp + sub( L_SYN_MEM, 1 ) ); @@ -463,7 +462,8 @@ static void Dec_formant_postfilt_fx( } /* Tilt filtering */ - Filt_mu_ivas_fx( resynth, sig_out, parcor0, L_SUBFR, -1 ); + Filt_mu_fx( resynth, sig_out, parcor0, L_SUBFR ); + IF( scale_down ) { Scale_sig( sig_out, L_SUBFR, 1 ); @@ -472,10 +472,10 @@ static void Dec_formant_postfilt_fx( /* Gain control */ scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR ); - return; } + /*------------------------------------------------------------------------------------ * modify_pst_param() * @@ -494,7 +494,6 @@ static void modify_pst_param_fx( Word16 lp_noiseQ12; Word32 L_tmp; - test(); IF( NE_16( coder_type, INACTIVE ) && LT_16( lp_noise, LP_NOISE_THR_FX ) ) { @@ -534,20 +533,21 @@ static void modify_pst_param_fx( *gain_factor = extract_h( L_shl( L_tmp, 7 ) ); /* Q24=>Q31=>Q15 */ - return; } + /*---------------------------------------------------------------------------- * pst_ltp_fx * * Perform harmonic postfilter *----------------------------------------------------------------------------*/ + static void pst_ltp_fx( Word16 t0, /* i : pitch delay given by coder Q0 */ Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) Qx */ - Word16 *ptr_sig_pst0, /* o : harmonic postfilter o Qx */ - Word16 gain_factor /* i : Gain Factor (Q15) */ + Word16 *ptr_sig_pst0, /* o : harmonic postfilter o Qx */ + Word16 gain_factor /* i : Gain Factor (Q15) */ ) { Word32 L_temp; @@ -570,7 +570,6 @@ static void pst_ltp_fx( Word16 off_yup; Word16 nb_sh_sig; - /* i signal justified on 13 bits */ ptr_sig = ptr_sig_in - DECMEM_RES2; // Qx nb_sh_sig = getScaleFactor16( ptr_sig, DECMEM_RES2 + L_SUBFR ); @@ -587,7 +586,6 @@ static void pst_ltp_fx( /* Sub optimal delay search */ search_del_fx( t0, ptr_sig_cadr, <pdel, &phase, &num_gltp, &den_gltp, &sh_num, &sh_den, y_up, &off_yup ); - IF( num_gltp == 0 ) { Copy( ptr_sig_in, ptr_sig_pst0, L_SUBFR ); @@ -603,7 +601,6 @@ static void pst_ltp_fx( /* Filtering with long filter */ compute_ltp_l_fx( ptr_sig_cadr, ltpdel, phase, ptr_sig_pst0, &num2_gltp, &den2_gltp, &sh_num2, &sh_den2 ); - IF( EQ_16( select_ltp_fx( num_gltp, den_gltp, sh_num, sh_den, num2_gltp, den2_gltp, sh_num2, sh_den2 ), 1 ) ) { /* select short filter */ @@ -672,15 +669,19 @@ static void pst_ltp_fx( /** filtering by H0(z) = harmonic filter **/ filt_plt_fx( ptr_sig_in, ptr_y_up, ptr_sig_pst0, gain_plt ); } + + return; } + /*---------------------------------------------------------------------------- * search_del_fx: * * Computes best (shortest) integer LTP delay + fine search *---------------------------------------------------------------------------*/ + static void search_del_fx( - Word16 t0, /* i : pitch delay given by coder Q0 */ + Word16 t0, /* i : pitch delay given by coder Q0 */ Word16 *ptr_sig_in, /* i : i signal (with delay line) */ Word16 *ltpdel, /* o : delay = *ltpdel - *phase / f_up */ Word16 *phase, /* o : phase */ @@ -715,7 +716,6 @@ static void search_del_fx( Word16 i_max, lambda, phi, phi_max, ioff; Word16 temp; - /*------------------------------------- * Computes energy of current signal *-------------------------------------*/ @@ -747,6 +747,7 @@ static void search_del_fx( * Selects best of 3 integer delays * Maximum of 3 numerators around t0 *-------------------------------------*/ + lambda = sub( t0, 1 ); ptr_sig_past = ptr_sig_in - lambda; L_num_int = L_deposit_l( -1 ); @@ -947,7 +948,6 @@ static void search_del_fx( ptr_L_den1 = L_den1; ptr_y_up = y_up; - /* if den_max = 0 : will be selected and declared unvoiced */ /* if num!=0 & den=0 : will be selected and declared unvoiced */ /* degenerated seldom cases, switch off LT is OK */ @@ -1025,6 +1025,7 @@ static void search_del_fx( /*--------------------------------------------------- * test if normalized crit0[iopt] > THRESHCRIT *--------------------------------------------------*/ + test(); IF( num_max == 0 || LE_16( den_max, 1 ) ) { @@ -1093,30 +1094,28 @@ static void search_del_fx( move16(); } - return; } + /*---------------------------------------------------------------------------- * filt_plt_fx: * * Perform long term postfilter *----------------------------------------------------------------------------*/ + static void filt_plt_fx( Word16 *s_in, /* i : i signal with past Qx */ Word16 *s_ltp, /* i : filtered signal with gain 1 Qx*/ Word16 *s_out, /* o : signal Qx */ - Word16 gain_plt /* i : filter gain Q15 */ + Word16 gain_plt /* i : filter gain Q15 */ ) { - /* Local variables */ Word32 L_acc; - Word16 n; Word16 gain_plt_1; - gain_plt_1 = sub( 32767, gain_plt ); // Q15 gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ @@ -1128,7 +1127,6 @@ static void filt_plt_fx( move16(); /* no overflow */ } - return; } @@ -1139,6 +1137,7 @@ static void filt_plt_fx( * compute delayed signal, num & den of gain for fractional delay * with long interpolation filter *----------------------------------------------------------------------------*/ + static void compute_ltp_l_fx( Word16 *s_in, /* i/o: signal with past */ Word16 ltpdel, /* i : delay factor */ @@ -1214,10 +1213,10 @@ static void compute_ltp_l_fx( move16(); move16(); - return; } + /*---------------------------------------------------------------------------- * select_ltp_fx: * @@ -1225,23 +1224,22 @@ static void compute_ltp_l_fx( * with gain1 = num1 * 2** sh_num1 / den1 * 2** sh_den1 * and gain2 = num2 * 2** sh_num2 / den2 * 2** sh_den2 *----------------------------------------------------------------------------*/ -static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain */ - Word16 num1, /* i : numerator of gain1 Q(sh_num1) */ - Word16 den1, /* i : denominator of gain1 Q(sh_den1) */ - Word16 sh_num1, /* i : just. factor for num1 */ - Word16 sh_den1, /* i : just. factor for den1 */ - Word16 num2, /* i : numerator of gain2 Q(sh_num2) */ - Word16 den2, /* i : denominator of gain2 Q(sh_den2) */ - Word16 sh_num2, /* i : just. factor for num2 */ - Word16 sh_den2 /* i : just. factor for den2 */ +/* o : 1 = 1st gain, 2 = 2nd gain */ +static Word16 select_ltp_fx( + Word16 num1, /* i : numerator of gain1 Q(sh_num1) */ + Word16 den1, /* i : denominator of gain1 Q(sh_den1) */ + Word16 sh_num1, /* i : just. factor for num1 */ + Word16 sh_den1, /* i : just. factor for den1 */ + Word16 num2, /* i : numerator of gain2 Q(sh_num2) */ + Word16 den2, /* i : denominator of gain2 Q(sh_den2) */ + Word16 sh_num2, /* i : just. factor for num2 */ + Word16 sh_den2 /* i : just. factor for den2 */ ) { Word32 L_temp1, L_temp2; Word32 L_temp; - Word16 temp1, temp2; - IF( den2 == 0 ) { return 1; @@ -1283,6 +1281,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain return temp1; } + /*---------------------------------------------------------------------------- * calc_st_filt_local_fx * @@ -1290,22 +1289,20 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain * controls gain : computation of energy impulse response as * SUMn (abs (h[n])) and computes parcor0 *---------------------------------------------------------------------------- */ + static void calc_st_filt_local_fx( Word16 *apond2, /* i : coefficients of numerator Q12 */ - Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15*/ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx */ - Word16 *mem_zero /* i : All zero memory */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx */ + Word16 *mem_zero /* i : All zero memory */ ) { Word32 L_g0; - Word16 h[LONG_H_ST]; - Word16 g0, temp; Word16 i; - temp = sub( 2, norm_s( apond2[0] ) ); /* compute i.r. of composed filter apond2 / apond1 */ @@ -1333,71 +1330,18 @@ static void calc_st_filt_local_fx( } } - return; } -static void calc_st_filt_ivas_fx( - Word16 *apond2, /* i : coefficients of numerator Q12 */ - Word16 *apond1, /* i : coefficients of denominator Q12 */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15 */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx*/ - Word16 *mem_zero, /* i : All zero memory */ - const Word16 extl /* i : extension layer info */ -) -{ - Word32 L_g0; - - Word16 h[LONG_H_ST]; // Q12 - - Word16 g0, temp; - Word16 i; - - - temp = sub( 2, norm_s( apond2[0] ) ); - /* compute i.r. of composed filter apond2 / apond1 */ - IF( EQ_16( extl, SWB_TBE ) ) - { - E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, LPC_SHB_ORDER ); - } - ELSE - { - E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); - } - - /* compute 1st parcor */ - Calc_rc0_h( h, parcor0 ); - - /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 - FOR( i = 1; i < LONG_H_ST; i++ ) - { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); // Q12 - } - g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 - - /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ - { - temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ - FOR( i = 0; i < L_SUBFR; i++ ) - { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); // Qx - move16(); - } - } - - - return; -} /*---------------------------------------------------------------------------- * filt_mu * * tilt filtering with : (1 + mu z-1) * (1/1-|mu|) * computes y[n] = (1/1-|mu|) (x[n]+mu*x[n-1]) *---------------------------------------------------------------------------*/ -void Filt_mu_fx( + +static void Filt_mu_fx( Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : signal with tilt */ Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ @@ -1405,14 +1349,11 @@ void Filt_mu_fx( ) { Word32 L_acc, L_temp, L_fact; - Word16 *ptrs; - Word16 n; Word16 mu, mu2, ga, temp; Word16 fact, sh_fact; - IF( parcor0 > 0 ) { mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 @@ -1458,105 +1399,17 @@ void Filt_mu_fx( BASOP_SATURATE_WARNING_ON_EVS; } - return; } -void Filt_mu_ivas_fx( - Word16 *sig_in, /* i : signal (beginning at sample -1) */ - Word16 *sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) Q15 */ - Word16 L_subfr, /* i : the length of subframe */ - const Word16 extl ) -{ - Word32 L_acc, L_temp, L_fact; - - Word16 *ptrs; - - Word16 n; - Word16 mu, mu2, ga, temp; - Word16 fact, sh_fact; - IF( EQ_16( extl, SWB_TBE ) ) - { - IF( parcor0 > 0 ) - { - mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); // Q15 - /* GAMMA3_PLUS_FX < 0.5 */ - sh_fact = 14; - move16(); /* sh_fact */ - fact = (Word16) 0x4000; - move16(); /* Q(sh_fact) */ - L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ - } - ELSE - { - mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); // Q15 - /* GAMMA3_MINUS_FX < 0.9375 */ - sh_fact = 11; - move16(); /* sh_fact */ - fact = (Word16) 0x0800; - move16(); /* Q(sh_fact) */ - L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ - } - } - ELSE - { - IF( parcor0 > 0 ) - { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 - /* GAMMA3_PLUS_FX < 0.5 */ - sh_fact = 14; - move16(); /* sh_fact */ - fact = (Word16) 0x4000; - move16(); /* Q(sh_fact) */ - L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ - } - ELSE - { - mu = mult_r( parcor0, GAMMA3_MINUS_FX ); // Q15 - /* GAMMA3_MINUS_FX < 0.9375 */ - sh_fact = 11; - move16(); /* sh_fact */ - fact = (Word16) 0x0800; - move16(); /* Q(sh_fact) */ - L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ - } - } - - temp = sub( 1, abs_s( mu ) ); - BASOP_SATURATE_WARNING_OFF_EVS; - mu2 = add_sat( 32767, temp ); /* Q15 (1 - |mu|) */ - BASOP_SATURATE_WARNING_ON_EVS; - ga = div_s( fact, mu2 ); /* Q(sh_fact) / (1 - |mu|) */ - - ptrs = sig_in; /* points on sig_in(-1) */ - - sh_fact = sub( sh_fact, 16 ); /* to remove the saturate(), should shl by 16 before rounding */ - - FOR( n = 0; n < L_subfr; n++ ) - { - L_acc = L_mult0( mu, *ptrs++ ); - L_temp = L_mac( L_acc, 16384, *ptrs ); /* sig_in(n) * 2**15 */ - - L_temp = Madd_32_16( L_fact, L_temp, ga ); - L_temp = L_shr( L_temp, sh_fact ); /* mult. temp x ga */ - - BASOP_SATURATE_WARNING_OFF_EVS; - /*sig_out[n] = saturate(L_temp); move16();*/ - sig_out[n] = round_fx_sat( L_temp ); - BASOP_SATURATE_WARNING_ON_EVS; - } - - - return; -} /*---------------------------------------------------------------------------- * scale_st_fx() * * control of the subframe gain * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out *---------------------------------------------------------------------------*/ + void scale_st_fx( const Word16 *sig_in, /* i : postfilter i signal Qx */ Word16 *sig_out, /* i/o: postfilter o signal Qx */ @@ -1564,12 +1417,11 @@ void scale_st_fx( Word16 L_subfr ) { Word32 L_acc, L_temp; - Word16 i; Word16 scal_in, scal_out; Word16 s_g_in, s_g_out, temp, sh_g0, g0; Word16 gain = 0; - + move16(); /* compute i gain */ L_acc = L_deposit_l( 0 ); @@ -1648,10 +1500,10 @@ void scale_st_fx( *gain_prec = gain; move16(); - return; } + /*---------------------------------------------------------------------------- * blend_subfr2_fx() * @@ -1671,6 +1523,7 @@ void blend_subfr2_fx( move16(); move16(); move16(); + FOR( i = 0; i < L_SUBFR / 2; i++ ) { sigOut[i] = mac_r_sat( L_mult_sat( fac1, sigIn1[i] ), fac2, sigIn2[i] ); // Qx diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index 6b6748b803ff1933f7b06c897de86590e86258e7..41a2e9842cd2657b9f28f019e4a75462e9e93f22 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -52,7 +52,7 @@ void getLPCparam_fx( { IF( st->lpcQuantization == 0 ) { - decode_lpc_avq_ivas_fx( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode ); + decode_lpc_avq_fx( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode ); } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) { @@ -1003,7 +1003,7 @@ void dec_prm_fx( { IF( st->lpcQuantization == 0 ) { - decode_lpc_avq_fx( st, st->numlpc, param_lpc ); + decode_lpc_avq_fx( st, st->numlpc, param_lpc, 0, EVS_MONO, 0 ); move16(); } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f9377d53f0c13846986a9bdc12fea6940b908d60..8482ef78b9c4ad53e51af924cd1bfcd8edce0db6 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -9,7 +9,6 @@ #include "options.h" #include "basop_util.h" #include "stl.h" -#include "math.h" #include "ivas_prot_fx.h" #include "rom_com.h" #include "ivas_rom_com.h" @@ -1076,6 +1075,8 @@ void decoder_tcx_fx( Word16 predictionGain; /* not counted */ predictionGain = 0; move16(); + Q_A_itf = 15; + move16(); FOR( j = startLine; j < endLine; j++ ) { @@ -4022,6 +4023,7 @@ void decoder_tcx_ivas_fx( move16(); fUseTns = 0; /* flag that is set if TNS data is present */ move16(); + prm_sqQ = NULL; set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); @@ -4043,8 +4045,8 @@ void decoder_tcx_ivas_fx( decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx, fUseTns, &tnsData, bfi, frame_cnt, 0, NULL ); - Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 - Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( st->Q_syn, 14 ) ); // Scaling xn_buf_fx to Q_syn + Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 + Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, -( Q14 - 2 ) ); // Scaling xn_buf_fx to Q(-2) x_e = sub( 31, 11 ); IF( st->igf != 0 ) @@ -5645,7 +5647,7 @@ void decoder_tcx_imdct_fx( generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x + x_fx[ind] = L_shl( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x } } diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index b00b445d791133d719b9027e7956584ccc86388f..20d5f4b22bfec94ffa76a46023927e9d4511f8bc 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -87,6 +87,7 @@ void decod_tran_fx( move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10 + /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ @@ -118,9 +119,11 @@ void decod_tran_fx( transition_dec_fx( st_fx, 0, L_frame_fx, i_subfr, tc_subfr_fx, &Jopt_flag, exc_fx, &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch_fx, &position, bwe_exc_fx, &st_fx->Q_exc ); + /*-----------------------------------------------------------------* * Transform domain contribution decoding - active frames *-----------------------------------------------------------------*/ + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { gain_code_fx = 0; @@ -142,14 +145,7 @@ void decod_tran_fx( IF( Jopt_flag == 0 ) { /* 2/3-bit decoding */ - IF( st_fx->element_mode == EVS_MONO ) - { - gain_dec_tc_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - ELSE - { - gain_dec_tc_ivas_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } + gain_dec_tc_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } ELSE { @@ -165,24 +161,15 @@ void decod_tran_fx( } /* update LP filtered gains for the case of frame erasures */ - IF( st_fx->element_mode == EVS_MONO ) - { - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); - move16(); - } - ELSE - { - lp_gain_updt_ivas_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + lp_gain_updt_fx( st_fx->element_mode, i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); - move16(); - } + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); + move16(); /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ + test(); test(); test(); @@ -219,6 +206,7 @@ void decod_tran_fx( /*-----------------------------------------------------------------* * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { IF( ( st_fx->element_mode == EVS_MONO ) ) @@ -244,6 +232,7 @@ void decod_tran_fx( /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ + Word16 tmp_idx_2; tmp_idx_2 = 0; move16(); diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index b5c10232c4034725f0ef48a73c45102630738d31..83e5666b4f44ad691d655fdaa355ce364695ff40 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -5,6 +5,8 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ + + static void gain_dec_gacelp_uv_fx( Word16 index, /* i : Quantization index vector Q0 */ Word16 *code, /* i : algebraic code excitation Q9 */ @@ -90,19 +92,18 @@ void decod_unvoiced_fx( * Innovation decoding *--------------------------------------------------------------*/ - // inov_decode(st, st->core_brate, 0, L_FRAME, 1, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR); inov_decode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); /*-------------------------------------------------------* * Generate Gaussian excitation * *-------------------------------------------------------*/ - // gaus_L2_dec_flt(code2, st->tilt_code, p_Aq, FORMANT_SHARPENING_G1_FLT, &(st->seed_acelp)); gaus_L2_dec( code2_fx, st_fx->tilt_code_fx, p_Aq_fx, FORMANT_SHARPENING_G1, &( st_fx->seed_acelp ) ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + Word16 tmp_idx_1; tmp_idx_1 = 0; move16(); @@ -115,18 +116,11 @@ void decod_unvoiced_fx( gain_dec_gacelp_uv_fx( index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &( st_fx->past_gpit ), &norm_gain_code_fx, &gain_inov_fx ); - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR ); move16(); /* update LP filtered gains for the case of frame erasures */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); - } - ELSE - { - lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); - } + lp_gain_updt_fx( st_fx->element_mode, i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); /*-------------------------------------------------------* * - Find the total excitation. * diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 1bd406e7a78568ba835ccb8a98d87b0a998fddfd..055f1325f884406f175cbf35e8ecc5d54ef82375 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -76,10 +76,17 @@ void decision_matrix_dec_fx( move16(); tmp16 = get_next_indice_fx( st, 1 ); // Q0 +#ifdef FIX_2252_TD_CNG_STARTS_SID + IF( EQ_16( tmp16, 1 ) ) +#else if ( EQ_16( tmp16, 1 ) ) +#endif { st->L_frame = L_FRAME16k; move16(); + st->nb_subfr = NB_SUBFR16k; + move16(); + st->bwidth = s_max( st->bwidth, WB ); } } ELSE diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index 97b41d98ba05840ab02db7f9be0a44e2a443cb68..9080fd5aa2693b1a960bedf79275a55cd42b6be2 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -146,145 +146,6 @@ static Word16 pack4bits_fx( } Word16 decode_lpc_avq_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 numlpc, /* i : Number of sets of lpc */ - Word16 *param_lpc /* o : lpc parameters */ -) -{ - Word16 k, j; - Word16 nb, qn1, qn2, avqBits, q_type; - Word16 start_bit_pos; - move16(); - move16(); - move16(); - j = 0; - start_bit_pos = st->next_bit_pos; - - FOR( k = 0; k < numlpc; k++ ) - { - /* Decode quantizer type */ - - IF( k == 0 ) - { - move16(); - move16(); - q_type = 0; - nb = 0; - } - ELSE - { - move16(); - nb = 1; - q_type = get_next_indice_fx( st, nb ); - move16(); - param_lpc[j] = q_type; - j = add( j, 1 ); - } - /* Decode quantization indices */ - - IF( q_type == 0 ) - { - /* Absolute quantizer with 1st stage stochastic codebook */ - { - move16(); - param_lpc[j] = get_next_indice_fx( st, 8 ); - } - j = add( j, 1 ); - } - /* - * 2nd stage decoding is skipped if: - * - we are in low bitrate mode and no joint SNS coding is used - * - OR the side-SNS-is-zero flag is set for joint SNS - */ - { - /* 2 bits to specify Q2,Q3,Q4,ext */ - qn1 = add( 2, get_next_indice_fx( st, 2 ) ); - qn2 = add( 2, get_next_indice_fx( st, 2 ) ); - - /* Unary code */ - /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ - - IF( GT_16( qn1, 4 ) ) - { - nb = unary_decode_fx( st, &qn1 ); - - if ( EQ_16( nb, 1 ) ) - { - qn1 = add( qn1, 5 ); - } - if ( EQ_16( nb, 2 ) ) - { - qn1 = add( qn1, 4 ); - } - if ( EQ_16( nb, 3 ) ) - { - move16(); - qn1 = 0; - } - if ( GT_16( nb, 3 ) ) - { - qn1 = add( qn1, 3 ); - } - } - - IF( GT_16( qn2, 4 ) ) - { - nb = unary_decode_fx( st, &qn2 ); - - if ( EQ_16( nb, 1 ) ) - { - qn2 = add( qn2, 5 ); - } - if ( EQ_16( nb, 2 ) ) - { - qn2 = add( qn2, 4 ); - } - if ( EQ_16( nb, 3 ) ) - { - move16(); - qn2 = 0; - } - if ( GT_16( nb, 3 ) ) - { - qn2 = add( qn2, 3 ); - } - } - - /* check for potential bit errors */ - test(); - IF( ( GT_16( qn1, NB_SPHERE ) ) || ( GT_16( qn2, NB_SPHERE ) ) ) - { - qn1 = 0; - move16(); - qn2 = 0; - move16(); - st->BER_detect = 1; - move16(); - } - - move16(); - param_lpc[j] = qn1; - j = add( j, 1 ); - move16(); - param_lpc[j] = qn2; - j = add( j, 1 ); - - /* Decode Split-by-2 algebraic VQ */ - avqBits = shl( qn1, 2 ); - - pack4bits_fx( avqBits, st, ¶m_lpc[j] ); - j = add( j, qn1 ); - - avqBits = shl( qn2, 2 ); - pack4bits_fx( avqBits, st, ¶m_lpc[j] ); - j = add( j, qn2 ); - } - } - - return sub( st->next_bit_pos, start_bit_pos ); -} - -Word16 decode_lpc_avq_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 numlpc, /* i : Number of sets of lpc */ Word16 *param_lpc, /* o : lpc parameters */ @@ -324,6 +185,7 @@ Word16 decode_lpc_avq_ivas_fx( param_lpc[j] = q_type; j = add( j, 1 ); } + test(); IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && k == 0 ) { @@ -338,6 +200,7 @@ Word16 decode_lpc_avq_ivas_fx( j = add( j, 1 ); move16(); } + /* Decode quantization indices */ IF( q_type == 0 ) @@ -362,6 +225,7 @@ Word16 decode_lpc_avq_ivas_fx( } j = add( j, 1 ); } + /* * 2nd stage decoding is skipped if: * - we are in low bitrate mode and no joint SNS coding is used diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index a358cbe8ad5929f44104d7a45e7e9b53bb57dc5a..07b2deddc3d6b0309a992cb26e82a6784253f8e7 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -315,7 +315,7 @@ ivas_error evs_dec_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ) != IVAS_ERR_OK ) { return error; } @@ -346,7 +346,7 @@ ivas_error evs_dec_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) + if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, NULL, NULL, 0, output_frame, core_switching_flag, 0, 1, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) { return error; } @@ -355,7 +355,7 @@ ivas_error evs_dec_fx( * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ - bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); + bw_switching_pre_proc_fx( st_fx, -1, 1, old_syn_12k8_16k_fx ); /*---------------------------------------------------------------------* * WB TBE decoding @@ -408,7 +408,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { +#ifdef HARMONIZE_TBE + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); +#else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); +#endif } } ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) || @@ -843,7 +847,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { +#ifdef HARMONIZE_TBE + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); +#else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); +#endif } } Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ @@ -1374,7 +1382,8 @@ ivas_error evs_dec_fx( st_fx->bfi = 1; move16(); } - updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd ); + + updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, NULL, Qpostd ); } ELSE { @@ -1383,7 +1392,8 @@ ivas_error evs_dec_fx( st_fx->bfi = 0; move16(); } - updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd ); + + updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, NULL, Qpostd ); } pop_wmops(); diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 2c62fd65340c904f09cf44af0e344f72e34496fa..471600ca384bdf57eb243d35a22f4ea120904fde 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -3,17 +3,15 @@ ====================================================================================*/ -#include "basop32.h" +#include +#include +#include "options.h" +#include "stl.h" #include "cnst.h" -#include "enh1632.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" -#include "move.h" #include "wmc_auto.h" -#include #include "typedef.h" -#include -#include "options.h" #include "rom_com.h" #include "stat_dec.h" #include "prot_fx.h" @@ -21,7 +19,6 @@ #include "basop_util.h" #include "rom_basop_util.h" #include "ivas_rom_dec.h" -#include "ivas_prot_fx.h" #ifdef DEBUGGING #include "debug.h" #endif @@ -81,16 +78,17 @@ ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) return error; } -void initFdCngDec_ivas_fx( +void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale /*Q15*/ ) + const Word16 scale /* i : Q factor */ +) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; hFdCngDec = st->hFdCngDec; - ivas_initFdCngCom_fx( hFdCngDec->hFdCngCom, scale ); + initFdCngCom( hFdCngDec->hFdCngCom, scale ); set16_fx( hFdCngDec->olapBufferAna, 0, FFTLEN ); hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); @@ -125,6 +123,7 @@ void initFdCngDec_ivas_fx( set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msPsd_fx, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msNoiseFloor_32fx, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); @@ -150,6 +149,7 @@ void initFdCngDec_ivas_fx( move16(); set16_fx( hFdCngDec->msLogPeriodog, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msLogNoiseEst, 0, NPART_SHAPING ); set32_fx( hFdCngDec->msLogNoiseEst_32fx, 0, NPART_SHAPING ); set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); @@ -196,97 +196,10 @@ void initFdCngDec_ivas_fx( move16(); Copy( st->lsp_old_fx, st->lspCNG_fx, M ); /*Q15*/ hFdCngDec->hFdCngCom->sid_frame_counter = 0; - return; -} - -void initFdCngDec_fx( - DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - const Word16 scale /*Q15*/ ) -{ - /* Initialize common */ - HANDLE_FD_CNG_DEC hFdCngDec; - - hFdCngDec = st->hFdCngDec; - - initFdCngCom( hFdCngDec->hFdCngCom, scale ); - set16_fx( hFdCngDec->olapBufferAna, 0, 320 ); - hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; - move16(); - set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); - hFdCngDec->hFdCngCom->olapBufferSynth2 = hFdCngDec->olapBufferSynth2; - move16(); - - /* Set some counters and flags */ - - hFdCngDec->flag_dtx_mode = 0; - move16(); - hFdCngDec->lp_noise = -167772160l /*-20.f Q23*/; /* format: Q8.24 */ - move32(); - hFdCngDec->lp_speech = 209715200l /* 25.f Q23*/; /* format: Q8.24 */ - move32(); - - /* Initialization of the noise estimation algorithm */ - - set32_fx( hFdCngDec->bandNoiseShape, 0, FFTLEN2 ); - set16_fx( &hFdCngDec->bandNoiseShape_exp, 0, 1 ); - - set32_fx( hFdCngDec->partNoiseShape, 0, NPART ); - set16_fx( &hFdCngDec->partNoiseShape_exp, 0, 1 ); - - set32_fx( hFdCngDec->msPeriodog, 0, NPART_SHAPING ); - set16_fx( &hFdCngDec->msPeriodog_exp, 0, 1 ); - - set32_fx( hFdCngDec->msAlpha, 0, NPART_SHAPING ); - - set32_fx( hFdCngDec->msBminWin, 0, NPART_SHAPING ); - - set32_fx( hFdCngDec->msBminSubWin, 0, NPART_SHAPING ); - - set16_fx( hFdCngDec->msPsd, 0, NPART_SHAPING ); - set32_fx( hFdCngDec->msPsd_fx, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msNoiseFloor, 0, NPART_SHAPING ); - - set32_fx( hFdCngDec->msNoiseEst, 0, NPART_SHAPING ); - set16_fx( &hFdCngDec->msNoiseEst_exp, 0, 1 ); - - set32_fx( hFdCngDec->msMinBuf, 2147483647l /*1.0 Q31*/, MSNUMSUBFR * NPART_SHAPING ); - - set32_fx( hFdCngDec->msCurrentMin, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); - - set32_fx( hFdCngDec->msCurrentMinOut, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); - - set32_fx( hFdCngDec->msCurrentMinSubWindow, 2147483647l /*1.0 Q31*/, NPART_SHAPING ); - - set16_fx( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); - - set16_fx( hFdCngDec->msPsdFirstMoment, 0, NPART_SHAPING ); - - set32_fx( hFdCngDec->msPsdSecondMoment, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msPeriodogBuf, 0, MSBUFLEN * NPART_SHAPING ); - - hFdCngDec->msPeriodogBufPtr = 0; - move16(); - - set16_fx( hFdCngDec->msLogPeriodog, 0, NPART_SHAPING ); - set16_fx( hFdCngDec->msLogNoiseEst, 0, NPART_SHAPING ); - - set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); - hFdCngDec->nFFTpart_shaping = 0; - move16(); - set32_fx( hFdCngDec->msPeriodog_ST_fx, 0, NPART_SHAPING ); - hFdCngDec->msPeriodog_ST_exp = 0; - move16(); - hFdCngDec->hFdCngCom->fftBuffer_exp = 0; - move16(); - hFdCngDec->hFdCngCom->periodog_exp = 0; - move16(); - set32_fx( hFdCngDec->smoothed_psd_fx, 0, L_FRAME16k ); - hFdCngDec->smoothed_psd_exp = 0; - move16(); return; } + /* configureFdCngDec_fx @@ -1182,7 +1095,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ + cngNoiseLevel[j] = L_shl_r( Mpy_32_16_r( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ move32(); } } @@ -1793,7 +1706,7 @@ void perform_noise_estimation_dec_ivas_fx( FOR( p = 0; p < npart; p++ ) { temp = L_shl( msPeriodog[p], q_shift ); - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ + msNoiseEst[p] = Madd_32_16( Mpy_32_16_r( msNoiseEst[p], sub( MAX_16, alpha ) ), temp, alpha ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); } } @@ -1871,7 +1784,7 @@ void perform_noise_estimation_dec_ivas_fx( L_tmp = L_shr( msPeriodog[p], sub( sub( 31, hFdCngDec->hFdCngCom->periodog_exp ), 4 ) ); IF( LT_32( L_tmp, msNoiseEst[p] ) ) { - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); /*temp_q_msNoiseEst[p]*/ + msNoiseEst[p] = Madd_32_16( Mpy_32_16_r( msNoiseEst[p], wght ), L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ); /*temp_q_msNoiseEst[p]*/ move32(); temp_q_msNoiseEst[p] = sub( add( hFdCngDec->msNoiseEst_exp, scale ), 15 ); move16(); @@ -1894,7 +1807,7 @@ void perform_noise_estimation_dec_ivas_fx( L_tmp = L_shr_sat( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_ST_exp ) ); /*Q31 - hFdCngDec->msPeriodog_ST_exp*/ IF( LT_32( L_tmp, msNoiseEst[p] ) ) { - msNoiseEst[p] = Madd_32_16( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ + msNoiseEst[p] = Madd_32_16( Mpy_32_16_r( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), L_tmp, ONE_IN_Q15 - CNA_ACT_DN_FACT_Q15 ); /*Q31 - hFdCngDec->msNoiseEst_exp*/ move32(); } } @@ -5072,7 +4985,7 @@ void generate_masking_noise_lb_dirac_fx( n_samples_start = add( n_samples_start, hFdCngCom->frameSize ); } - /* move generated noise to the 5ms subframe starts in the tc buffer according to the output sampling frequency to avoid + /* move generated noise to the 5ms subframe starts in the TC buffer according to the output sampling frequency to avoid overwriting it with the synthesis in case of shared tc and synth channel memory, i.e. non-TSM mode */ slot_size_cng = shr( hFdCngCom->frameSize, 4 /* DEFAULT_JBM_CLDFB_TIMESLOTS */ ); /* move start indices forward to the end of the last subframe */ diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 0848104afa84f0eb798d41eb438c02502ccc57de..551e04205f4030c9b5c74c55883e0f286a580299 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -113,8 +113,10 @@ void gain_dec_tc_fx( /*----------------------------------------------------------------* * find number of bits for gain dequantization *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; + + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / L_SUBFR )]; move16(); + /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ @@ -132,7 +134,6 @@ void gain_dec_tc_fx( *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ - /* Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ @@ -147,6 +148,7 @@ void gain_dec_tc_fx( * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ @@ -154,24 +156,38 @@ void gain_dec_tc_fx( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp_gcode0 = sub( exp_gcode0, 14 ); + /*------------------------------------------------------------------------------------------* * Select the gain quantization table and dequantize the gain *------------------------------------------------------------------------------------------*/ - /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); - move16(); - + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - IF( GT_16( nBits, 3 ) ) + IF( st_fx->element_mode == EVS_MONO ) { - wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); - wgain_code = shl_sat( wgain_code, add( expg, 13 ) ); /* wgain_code in Q13*/ + IF( GT_16( nBits, 3 ) ) + { + wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); + wgain_code = shl_sat( wgain_code, add( expg, 13 ) ); /* wgain_code in Q13*/ + } + ELSE /* nBits == 3 */ + { + wgain_code = tbl_gain_code_tc_fx[index]; /*Q13*/ + move16(); + } } - ELSE /* nBits == 3 */ + ELSE { - wgain_code = tbl_gain_code_tc_fx[index]; /*Q13*/ - move16(); + IF( GT_16( nBits, 3 ) ) + { + wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); + wgain_code = shl( wgain_code, add( expg, 12 ) ); /* wgain_code in Q12*/ + } + ELSE /* nBits == 3 */ + { + wgain_code = shr( tbl_gain_code_tc_fx[index], 1 ); // Q12 + move16(); + } } /*-----------------------------------------------------------------* @@ -179,139 +195,16 @@ void gain_dec_tc_fx( *-----------------------------------------------------------------*/ /* *gain_code *= gcode0;*/ - L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); /*Q16*/ - move32(); - - /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub( norm_s( *gain_inov_fx ), 1 ); - expg = s_max( expg, 0 ); - - tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ - move32(); - - return; -} - -/*======================================================================================*/ -/* FUNCTION : void gain_dec_tc_ivas_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Decoding of pitch and codebook gains and updating long term energies */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word32 core_brate_fx i : core bitrate */ -/* Word16 *code_fx i : algebraic code excitation */ -/* Word16 L_frame_fx i : length of the frame */ -/* Word16 i_subfr_fx i : subframe number */ -/* Word16 tc_subfr_fx i : TC subframe index */ -/* Word16 Es_pred_fx i : predicted scaled innov. energy Q8 */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 *gain_pit_fx o : pitch gain Q14 */ -/* Word32 *gain_code_fx o : Quantized codeebook gain Q16 */ -/* Word16 *gain_inov_fx o : unscaled innovation gain Q12 */ -/* Word32 *norm_gain_code_fx o : norm. gain of the codebook excit. Q16 */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*======================================================================================*/ - -void gain_dec_tc_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : pitch gain */ - Word32 *gain_code_fx, /* o : Quantized codeebook gain */ - Word16 *gain_inov_fx, /* o : unscaled innovation gain */ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ -) -{ - Word16 index, nBits; - Word16 gcode0_fx; - Word16 Ei_fx; - Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac; - Word32 L_tmp, L_tmp1; - Word16 wgain_code = 0; - move16(); - *gain_pit_fx = 0; - move16(); - - /*----------------------------------------------------------------* - * find number of bits for gain dequantization - *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; - move16(); - /*-----------------------------------------------------------------* - * calculate the predicted gain code - *-----------------------------------------------------------------*/ - - /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - expg*/ - expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - expg2 = expg; - move16(); - L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ - - *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); - move16(); /* gain_inov in Q12 */ - - - /* Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ - e_tmp = sub( expg2, add( 1, e_tmp ) ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ - /* gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub( Es_pred_fx, Ei_fx ); /* Q8 */ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - /*------------------------------------------------------------------------------------------* - * Select the gain quantization table and dequantize the gain - *------------------------------------------------------------------------------------------*/ - - /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - - - IF( GT_16( nBits, 3 ) ) + IF( st_fx->element_mode == EVS_MONO ) { - wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); - wgain_code = shl( wgain_code, add( expg, 12 ) ); /* wgain_code in Q12*/ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q13*Q0 -> Q14 */ + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); /*Q16*/ } - ELSE /* nBits == 3 */ + ELSE { - wgain_code = shr( tbl_gain_code_tc_fx[index], 1 ); // Q12 - move16(); + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q12*Q0 -> Q13 */ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 3 ) ); /* Q13 -> Q16 */ } - - /*-----------------------------------------------------------------* - * decode normalized codebook gain - *-----------------------------------------------------------------*/ - - /* *gain_code *= gcode0;*/ - L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q12*Q0 -> Q13 */ - *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 3 ) ); /* Q13 -> Q16 */ move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ @@ -353,8 +246,9 @@ void gain_dec_tc_ivas_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*======================================================================================*/ + void gain_dec_mless_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 L_frame_fx, /* i : length of the frame */ const Word16 coder_type, /* i : coding type */ const Word16 i_subfr_fx, /* i : subframe number */ @@ -431,6 +325,7 @@ void gain_dec_mless_fx( * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ @@ -528,6 +423,7 @@ void gain_dec_mless_fx( L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ Ei_fx = round_fx( L_shl( L_tmp1, 11 ) ); /* Q8 */ } + /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ @@ -540,6 +436,7 @@ void gain_dec_mless_fx( * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ + L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ @@ -650,6 +547,7 @@ void gain_dec_lbr_fx( * calculate prediction of gcode * search for the best codeword *-----------------------------------------------------------------*/ + test(); IF( i_subfr == 0 ) { @@ -698,7 +596,6 @@ void gain_dec_lbr_fx( gcode0_fx = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ - /*-----------------------------------------------------------------* * gcode0 = pow(10.0, gcode0/20) * = pow(2, 3.321928*gcode0/20) @@ -775,6 +672,7 @@ void gain_dec_lbr_fx( * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ + L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ @@ -848,6 +746,7 @@ void gain_dec_lbr_fx( * gcode0 = pow(10.0, dotp(b, aux, n_pred) * = pow(2, 3.321928*dotp(b, aux, n_pred) *-----------------------------------------------------------------*/ + L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ @@ -879,7 +778,6 @@ void gain_dec_lbr_fx( n_pred = 8; move16(); - cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ IF( EQ_16( nBits, 7 ) ) @@ -984,126 +882,13 @@ void gain_dec_lbr_fx( /* _ (Word16 *) lp_gainp : LP-filtered pitch gain(FEC) Q14 */ /* _ (Word16 *) lp_gainc : LP-filtered code gain (FEC) Q3 */ /*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*=======================================================================*/ - void lp_gain_updt_fx( - const Word16 i_subfr, /* i : subframe number Q0 */ - const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ - const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ - Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ - Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ - const Word16 L_frame /* i : length of the frame */ -) -{ - Word16 tmp; - - tmp = extract_h( L_shl_sat( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ - IF( EQ_16( L_frame, L_FRAME ) ) - { - IF( EQ_16( i_subfr, 0 ) ) - { - *lp_gainp = mult( 3277, gain_pit ); - move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ - *lp_gainc = mult_r( 3277, tmp ); - move16(); /* (15+3)-15 -> Q3*/ - } - ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) - { - *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); - move16(); /*Q14 (0.2 in Q15 = 6554)*/ - *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); - move16(); /*Q3*/ - } - ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - *lp_gainp = add( *lp_gainp, mult( 9830, gain_pit ) ); - move16(); /*Q14 (0.3 in Q15 = 9830)*/ - *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 9830, tmp ); - move16(); /*Q3*/ - } - ELSE /* i_subfr == 3*L_SUBFR */ - { - *lp_gainp = add( *lp_gainp, mult( 13107, gain_pit ) ); - move16(); /*Q14 (0.4 in Q15 = 13107)*/ - *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 13107, tmp ); - move16(); /*Q3*/ - } - } - ELSE - { - IF( i_subfr == 0 ) - { - *lp_gainp = mult( 2185, gain_pit ); - move16(); /*(1.0/15.0) in Q15 = 2185 , (15+14)-15 -> Q14*/ - *lp_gainc = mult_r( 2185, tmp ); - move16(); /* (15+3)-15 -> Q3*/ - } - ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) - { - *lp_gainp = add( *lp_gainp, mult( 4369, gain_pit ) ); - move16(); /*Q14 (2.0/15.0 in Q15 = 4369)*/ - *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 4369, tmp ); - move16(); /*Q3*/ - } - ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); - move16(); /*Q14 (3.0/15.0 in Q15 = 6554)*/ - *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); - move16(); /*Q3*/ - } - ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) - { - *lp_gainp = add( *lp_gainp, mult( 8738, gain_pit ) ); - move16(); /*Q14 (4.0/15.0 in Q15 = 8738)*/ - *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 8738, tmp ); - move16(); /*Q3*/ - } - ELSE /* i_subfr == 4*L_SUBFR */ - { - *lp_gainp = add( *lp_gainp, mult( 10923, gain_pit ) ); - move16(); /*Q14 (5.0/15.0 in Q15 = 10923)*/ - *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 10923, tmp ); - move16(); /*Q3*/ - } - } - return; -} - -/*====================================================================== */ -/* FUNCTION : lp_gain_updt_ivas_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Update of LP pitch and code gains (FEC) */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) i_subfr : subframe number Q0 */ -/* _ (Word16) gain_pit : Decoded gain pitch Q14 */ -/* _ (Word32) norm_gain_code : Normalised gain code Q16 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) T0 : close loop integer pitch */ -/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ -/* _ (Word16 ) pitch : pitch value Q6 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/* _ (Word16 *) lp_gainp : LP-filtered pitch gain(FEC) Q14 */ -/* _ (Word16 *) lp_gainc : LP-filtered code gain (FEC) Q3 */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - - -void lp_gain_updt_ivas_fx( + const Word16 element_mode, /* i : element mode */ const Word16 i_subfr, /* i : subframe number Q0 */ const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ @@ -1117,7 +902,8 @@ void lp_gain_updt_ivas_fx( tmp = extract_h( L_shl_sat( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ /* To handle extremely low values */ test(); - if ( norm_gain_code != 0 && tmp == 0 ) + test(); + if ( element_mode != EVS_MONO && norm_gain_code != 0 && tmp == 0 ) { tmp = 1; move16(); @@ -1195,7 +981,8 @@ void lp_gain_updt_ivas_fx( /* To handle extremely low values */ test(); - if ( tmp != 0 && *lp_gainc == 0 ) + test(); + if ( element_mode != EVS_MONO && tmp != 0 && *lp_gainc == 0 ) { *lp_gainc = 1; move16(); @@ -1245,6 +1032,7 @@ Word32 gain_dec_gaus_fx( L_enr_q = L_mult( index, stepSize ); /* Q0 * QstepSize_Exp -> QstepSize_Exp+1 */ L_enr_q = L_shl( L_enr_q, sub( 24 - 1, stepSize_Exp ) ); /* QstepSize_Exp+1 -> Q24 */ L_enr_q = L_add( L_enr_q, L_shl( L_deposit_h( lowBound ), 8 ) ); /* Q24 */ + /*------------------------------------------------------------* * gain = pow(10.0, enr/20) * = pow(2, 3.321928*enr/20) @@ -1384,7 +1172,7 @@ void gain_dec_SQ_fx( *---------------------------------------------------------------------*/ void gain_dec_amr_wb_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ const Word32 core_brate, /* i : core bitrate */ Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ @@ -1402,7 +1190,6 @@ void gain_dec_amr_wb_fx( Word32 L_tmp; Word16 expg, exp_gcode0, fracg; - /**gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );*/ L_tmp = Dot_product12( code, code, L_SUBFR, &expg ); /*Q31 - expg*/ @@ -1415,6 +1202,7 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Select the gain quantization table *-----------------------------------------------------------------*/ + nbits = 7; move16(); t_qua_gain = t_qua_gain7b_fx; @@ -1451,6 +1239,7 @@ void gain_dec_amr_wb_fx( * = pow(2, 3.321928*gcode0/20) * = pow(2, 0.166096*gcode0) *-----------------------------------------------------------------*/ + L_tmp = L_mult( gcode0, 21771 ); /* *0.166096 in Q17 -> Q27 */ L_tmp = L_shr( L_tmp, 9 + 2 ); /* From Q27 to Q16 */ L_Extract( L_tmp, &exp_gcode0, &fracg ); /* Extract exponent of gcode0 */ @@ -1473,6 +1262,7 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Decode code gain *-----------------------------------------------------------------*/ + qua_en = t_qua_gain[( index2 + 1 )]; move16(); @@ -1496,12 +1286,14 @@ void gain_dec_amr_wb_fx( past_qua_en[i] = past_qua_en[i - 1]; move16(); } + /*past_qua_en[0] = (float)(20.0*log10(qua_en));*/ /*----------------------------------------------------------* * past_qua_en[0] = 20*log10(t_qua_gain[indice*2+1]) * = 6.0206*log2(t_qua_gain[indice*2+1]) * = 6.0206*(log2(t_qua_gain[indice*2+1]Q11 -11) *----------------------------------------------------------*/ + tmp = norm_l( qua_en ); fracg = Log2_norm_lc( L_shl( qua_en, tmp ) ); expg = sub( 30, tmp ); @@ -1515,6 +1307,7 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Normalized code gain *-----------------------------------------------------------------*/ + /**norm_gain_code = *gain_code / *gain_inov;*/ expg = sub( norm_s( *gain_inov ), 1 ); expg = s_max( expg, 0 ); diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index d49ecb5b7a90acfa8ff9ef6503a90004bfe22adc..0d38c40bcae3b2bb344d92d0a21cb4c379361fca 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -87,14 +87,7 @@ void gaus_dec_fx( move32(); /* update LP filtered gains for the case of frame erasures */ - IF( st_fx->element_mode == EVS_MONO ) - { - lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ - } - ELSE - { - lp_gain_updt_ivas_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ - } + lp_gain_updt_fx( st_fx->element_mode, i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ /*------------------------------------------------------------------------------------------* * Updates diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 5564dc1b8176c177c0076abf7362b40c43a02a26..a314bb232a5fe452b27616d7cf343ee1edbd92f1 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -241,6 +241,7 @@ void decod_audio_fx( nbits = 4; /* Q0 */ move16(); } + test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { @@ -276,6 +277,7 @@ void decod_audio_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -283,11 +285,13 @@ void decod_audio_fx( * Decode adaptive (pitch) excitation contribution * Reset unvaluable part of the adaptive (pitch) excitation contribution *--------------------------------------------------------------------------------------*/ + IF( GT_16( pit_band_idx, BAND1k2 ) ) { /*---------------------------------------------------------------* * Decode adaptive (pitch) excitation contribution *---------------------------------------------------------------*/ + test(); test(); test(); @@ -351,6 +355,7 @@ void decod_audio_fx( /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); /*---------------------------------------------------------------* @@ -469,7 +474,6 @@ void decod_audio_fx( } } - Word16 Q_exc_old = st_fx->Q_exc; move16(); gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc ); @@ -486,17 +490,23 @@ void decod_audio_fx( Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); /* Q_exc_old */ } } + /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); + /*----------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame, 0 ); +#else pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame ); +#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -530,6 +540,7 @@ void decod_audio_fx( return; } + /*==========================================================================*/ /* FUNCTION : void gsc_dec_fx () */ /*--------------------------------------------------------------------------*/ @@ -595,6 +606,7 @@ void gsc_dec_fx( /*--------------------------------------------------------------------------------------* * Initialization *--------------------------------------------------------------------------------------*/ + bit = bits_used; move16(); @@ -655,14 +667,7 @@ void gsc_dec_fx( i--; } - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ - } - ELSE - { - mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ - } + mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ move16(); @@ -849,10 +854,17 @@ void gsc_dec_fx( * Estimate noise level *--------------------------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, + &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, + hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, + st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); +#else highband_exc_dct_in_ivas_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); +#endif exc_dct_in[0] = 0; move16(); @@ -860,6 +872,7 @@ void gsc_dec_fx( return; } + /*-------------------------------------------------------------------* * GSC_dec_init() * @@ -891,5 +904,6 @@ void GSC_dec_init_fx( hGSCDec->Last_frame_ener_fx = MAX_32; move32(); + return; } diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 87e8b1fd7b813b8716bb15d9306a870631495ebf..153b760804e41756ed7400e9d6731de8e8332579 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -20,8 +20,7 @@ *---------------------------------------------------------------------*/ static void filt_6k_7k_scale_fx( Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp ); -static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn ); -static void hf_synthesis_ivas_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn ); +static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word16 element_mode, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn ); static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, Word16 HF_corr_gain, Word16 til, Word16 voice_factors, const Word16 exc[], const Word16 Q_exc, const Word16 Q_out, Word16 qhf ); static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor ); static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const Word16 *lsf, const Word16 voicing_fac, const Word16 clas, Word16 *voicing_flag, Word16 *start_band_old, Word32 *OptCrit_old ); @@ -80,14 +79,15 @@ void hf_synth_reset_fx( void hf_synth_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word16 element_mode, /* i : element mode Q0*/ const Word32 core_brate, /* i : core bitrate Q0*/ const Word16 output_frame, /* i : output frame length Q0*/ const Word16 *Aq, /* i : quantized Az Q12*/ const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2 /* i : synthesis scaling */ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2 /* i : synthesis scaling */ ) { const Word16 *p_Aq; @@ -99,8 +99,7 @@ void hf_synth_fx( p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { - hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2 ); - + hf_synthesis_fx( hBWE_zero, element_mode, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[i_subfr * output_subfr / L_SUBFR], Q_syn2 ); p_Aq += ( M + 1 ); /* Q12 */ } @@ -120,6 +119,7 @@ void hf_synth_fx( static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, + const Word16 element_mode, /* i : element mode Q0*/ const Word32 core_brate, /* i : core bitrate Q0*/ const Word16 output_subfr, /* i : output sub-frame length Q0*/ const Word16 Aq[], /* i : quantized Az Q12*/ @@ -135,6 +135,9 @@ static void hf_synthesis_fx( Word16 HF_exc[L_SUBFR16k]; Word16 tmp, ener, exp1, exp2, scale; Word32 L_tmp; + Word16 Q_tmp, Q_ener, sft; + Word32 ONE, P_ONE; + Word64 prod; Word16 Ap[M16k + 1]; /*-----------------------------------------------------------------* @@ -157,280 +160,148 @@ static void hf_synthesis_fx( /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); tmp = round_fx( L_tmp ); /* Q15 */ - /* tmp = (float)(sqrt(ener/tmp)) */ - /* scale is -1 if tmp > ener */ - scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ - tmp = shl( tmp, scale ); /* Q15 + scale*/ - exp1 = sub( exp1, scale ); - - tmp = div_s( tmp, ener ); /* Q15 */ - exp1 = sub( exp1, exp2 ); - - L_tmp = L_deposit_h( tmp ); /* Q31 */ - - L_tmp = Isqrt_lc( L_tmp, &exp1 ); - scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ - - exp2 = sub( hBWE_zero->memExp1, exp1 ); - hBWE_zero->memExp1 = exp1; - move16(); - - /*-----------------------------------------------------------------* - * calculate energy scaling factor to respect tilt of synth12k8 - * (tilt: 1=voiced, -1=unvoiced) - *-----------------------------------------------------------------*/ - hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); - /* i: mem_hp400 in Q_syn */ - /* i: synth in Q_syn */ - /* o: synth in Q_syn-3 */ - L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ - FOR( i = 1; i < L_SUBFR; i++ ) + IF( element_mode == EVS_MONO ) { - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */ - } - tmp = norm_l( L_tmp ); - ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ - /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ + /* tmp = (float)(sqrt(ener/tmp)) */ + /* scale is -1 if tmp > ener */ + scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ + tmp = shl( tmp, scale ); /* Q15 + scale*/ + exp1 = sub( exp1, scale ); - L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ - FOR( i = 2; i < L_SUBFR; i++ ) - { - L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */ - } - tmp = extract_h( L_shl( L_tmp, tmp ) ); /* tmp = r[1] */ - /*tmp in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0 */ - /*we use the same normalization factor for both ener and tmp, */ - /*if the headroom in "tmp" is less than "ener", tmp can saturate */ - /*but this is ok since below we apply some thresholds to tmp */ - - tmp = s_max( 0, tmp ); - if ( tmp > 0 ) - { tmp = div_s( tmp, ener ); /* Q15 */ - } + exp1 = sub( exp1, exp2 ); - /*-----------------------------------------------------------------* - * modify energy of white noise according to synthesis tilt - *-----------------------------------------------------------------*/ - /* tmp = 1.0 - fac */ - tmp = add_sat( 1, sub( 32767 /* 1 in Q15 */, tmp ) ); - test(); - if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) ) - { - /* emphasize HF noise in CNG */ - /*fac *= 2.0f;*/ - tmp = add_sat( tmp, tmp ); /* Q15 */ - } - tmp = s_max( tmp, 3277 ); /* 0.1 in Q15 */ + L_tmp = L_deposit_h( tmp ); /* Q31 */ - /*scale *= fac;*/ - tmp = mult_r( scale, tmp ); - /*-----------------------------------------------------------------* - * modify HF excitation according to both calculated scaling factors - * high pass filtering (0.94ms of delay) - *-----------------------------------------------------------------*/ - - filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx, tmp, exp2 ); - /* i: input HF_exc is scaled in float, here scaling is done inside this filter */ - /* i: mem_hf in Q-2 */ - /* o: HF_exc in Q0 */ + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ - /*-----------------------------------------------------------------* - * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ - /*weight_a( Aq, Ap, 0.6f, M );*/ - weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M ); - /* o: Ap in Q14 */ + hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); - Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 ); - /* i: Ap in Q14 */ - /* i: HF_exc in Q0 */ - /* o: HF_syn in Q0 */ - /* i/o: mem_syn_hf in Q0 */ + L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ + FOR( i = 1; i < L_SUBFR; i++ ) + { + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i] ); /* 2*(Q_syn-3)+1 */ + } + tmp = norm_l( L_tmp ); + ener = extract_h( L_shl( L_tmp, tmp ) ); /* ener = r[0] */ + /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - Scale_sig( HF_syn, L_SUBFR16k, ( add( Q_syn, exp1 ) ) ); /* bring HF_syn to (Q_syn+exp1) */ + L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ + FOR( i = 2; i < L_SUBFR; i++ ) + { + L_tmp = L_mac_sat( L_tmp, synth[i], synth[i - 1] ); /* 2*(Q_syn-3)+1 */ + } + tmp = extract_h( L_shl( L_tmp, tmp ) ); /* tmp = r[1] */ + /*tmp in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0 */ + /*we use the same normalization factor for both ener and tmp, */ + /*if the headroom in "tmp" is less than "ener", tmp can saturate */ + /*but this is ok since below we apply some thresholds to tmp */ + tmp = s_max( 0, tmp ); + if ( tmp > 0 ) + { + tmp = div_s( tmp, ener ); /* Q15 */ + } - /*-----------------------------------------------------------------* - * add filtered HF noise to speech synthesis - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * modify energy of white noise according to synthesis tilt + *-----------------------------------------------------------------*/ - /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ - delay_signal_fx( HF_syn, L_SUBFR16k, hBWE_zero->delay_syn_hf_fx, NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15 ); + /* tmp = 1.0 - fac */ + tmp = add_sat( 1, sub( 32767 /* 1 in Q15 */, tmp ) ); + test(); + if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) ) + { + /* emphasize HF noise in CNG */ + /*fac *= 2.0f;*/ + tmp = add_sat( tmp, tmp ); /* Q15 */ + } + tmp = s_max( tmp, 3277 ); /* 0.1 in Q15 */ - /* interpolate the HF synthesis */ - IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ - { - s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), - sub( Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), - 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ - Scale_sig( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN, s ); /* Qx + s */ - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, hBWE_zero->mem_hp_interp_fx ); - Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ - Scale_sig( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN, -s ); /* Qx */ - Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ - Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); - } - ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ - { - s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ - Scale_sig( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */ - Interpolate_allpass_steep_fx( HF_syn, hBWE_zero->mem_hp_interp_fx, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Q_syn + exp1 */ - Scale_sig( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ - Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ - } - ELSE /* 16kHz sampled output */ - { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ + /*scale *= fac;*/ + tmp = mult_r( scale, tmp ); } - Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); - - return; -} - -void hf_synth_ivas_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ - const Word32 core_brate, /* i : core bitrate Q0*/ - const Word16 output_frame, /* i : output frame length Q0*/ - const Word16 *Aq, /* i : quantized Az Q12*/ - const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ - Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ - Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2 /* i : synthesis scaling */ -) -{ - const Word16 *p_Aq; - Word16 i_subfr, output_subfr; - - output_subfr = shr( output_frame, 2 ); - - p_Aq = Aq; /* Q12 */ - FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + ELSE { - hf_synthesis_ivas_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[i_subfr * output_subfr / L_SUBFR], Q_syn2 ); - - p_Aq += ( M + 1 ); /* Q12 */ - } - - return; -} - -static void hf_synthesis_ivas_fx( - ZERO_BWE_DEC_HANDLE hBWE_zero, - const Word32 core_brate, /* i : core bitrate Q0*/ - const Word16 output_subfr, /* i : output sub-frame length Q0*/ - const Word16 Aq[], /* i : quantized Az Q12*/ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ - const Word16 Q_syn /* i : synthesis scaling */ -) -{ - Word16 i, s; - Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_FRAME48k / NB_SUBFR]; - Word16 HF_exc[L_SUBFR16k]; - Word16 exp1, exp2, scale, tmp, ener, Q_tmp, Q_ener, sft; - Word32 L_tmp, ONE, P_ONE; - Word16 Ap[M16k + 1]; - Word64 prod; + exp1 = add( exp1, 6 ); /* tmp exponent */ - /*-----------------------------------------------------------------* - * generate white noise vector - *-----------------------------------------------------------------*/ + ener = shr( ener, 1 ); /* to avoid the assertion in div_s() further*/ + exp2 = add( exp2, 1 ); - Random_Fill( &hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3 ); /* 3 = Shift Right by 3 */ + tmp = div_s( ener, tmp ); + exp1 = sub( exp2, exp1 ); - /* o: HF_exc in Q(-3) */ + scale = Sqrt16( tmp, &exp1 ); /* scale exponent = exp1 */ - /*-----------------------------------------------------------------* - * calculate energy scaling factor so that white noise would have the - * same energy as exc12k8 - *-----------------------------------------------------------------*/ - - /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); - exp2 = sub( exp2, add( Q_exc, Q_exc ) ); // ener exponent + /*-----------------------------------------------------------------* + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ - /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ - L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); - tmp = round_fx( L_tmp ); - exp1 = add( exp1, 6 ); /* tmp exponent */ + hp400_12k8_ivas_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); - ener = shr( ener, 1 ); /* to avoid the assertion in div_s() further*/ - exp2 = add( exp2, 1 ); - - tmp = div_s( ener, tmp ); - exp1 = sub( exp2, exp1 ); - - scale = Sqrt16( tmp, &exp1 ); /* scale exponent = exp1 */ + /* i: mem_hp400 in Q_syn */ + /* i: synth in Q_syn */ + /* o: synth in Q_syn-3 */ + prod = W_mac0_16_16( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3) */ + FOR( i = 1; i < L_SUBFR; i++ ) + { + prod = W_mac0_16_16( prod, synth[i], synth[i] ); /* 2*(Q_syn-3) */ + } + sft = W_norm( prod ); + ener = extract_h( W_extract_h( W_shl( prod, sft ) ) ); + Q_ener = sub( add( shl( sub( Q_syn, 3 ), 1 ), sft ), 48 ); - /*-----------------------------------------------------------------* - * calculate energy scaling factor to respect tilt of synth12k8 - * (tilt: 1=voiced, -1=unvoiced) - *-----------------------------------------------------------------*/ + prod = W_mac0_16_16( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3) */ + FOR( i = 2; i < L_SUBFR; i++ ) + { + prod = W_mac0_16_16( prod, synth[i], synth[i - 1] ); /* 2*(Q_syn-3) */ + } + sft = sub( W_norm( prod ), 1 ); + tmp = extract_h( W_extract_h( W_shl( prod, sft ) ) ); + Q_tmp = sub( add( shl( sub( Q_syn, 3 ), 1 ), sft ), 48 ); - hp400_12k8_ivas_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); + tmp = s_max( 0, tmp ); + IF( tmp > 0 ) + { + tmp = div_s( tmp, ener ); + Q_tmp = add( 15, sub( Q_tmp, Q_ener ) ); + } - /* i: mem_hp400 in Q_syn */ - /* i: synth in Q_syn */ - /* o: synth in Q_syn-3 */ - prod = W_mac0_16_16( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3) */ - FOR( i = 1; i < L_SUBFR; i++ ) - { - prod = W_mac0_16_16( prod, synth[i], synth[i] ); /* 2*(Q_syn-3) */ - } - sft = W_norm( prod ); - ener = extract_h( W_extract_h( W_shl( prod, sft ) ) ); - Q_ener = sub( add( shl( sub( Q_syn, 3 ), 1 ), sft ), 48 ); + /*-----------------------------------------------------------------* + * modify energy of white noise according to synthesis tilt + *-----------------------------------------------------------------*/ + /* tmp = 1.0 - fac */ + ONE = L_shl( 1, Q_tmp ); + P_ONE = L_shl( 3277 /* 0.1 in Q15 */, sub( Q_tmp, 15 ) ); + L_tmp = L_msu0( ONE, tmp, 1 ); + test(); + if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) ) + { + /* emphasize HF noise in CNG */ + /*fac *= 2.0f;*/ + L_tmp = L_add( L_tmp, L_tmp ); + } + L_tmp = L_max( L_tmp, P_ONE ); + L_tmp = L_min( L_tmp, ONE ); - prod = W_mac0_16_16( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3) */ - FOR( i = 2; i < L_SUBFR; i++ ) - { - prod = W_mac0_16_16( prod, synth[i], synth[i - 1] ); /* 2*(Q_syn-3) */ - } - sft = sub( W_norm( prod ), 1 ); - tmp = extract_h( W_extract_h( W_shl( prod, sft ) ) ); - Q_tmp = sub( add( shl( sub( Q_syn, 3 ), 1 ), sft ), 48 ); + sft = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, sft ); - tmp = s_max( 0, tmp ); - IF( tmp > 0 ) - { - tmp = div_s( tmp, ener ); - Q_tmp = add( 15, sub( Q_tmp, Q_ener ) ); - } + tmp = round_fx( L_tmp ); + Q_tmp = sub( add( Q_tmp, sft ), 16 ); - /*-----------------------------------------------------------------* - * modify energy of white noise according to synthesis tilt - *-----------------------------------------------------------------*/ - /* tmp = 1.0 - fac */ - ONE = L_shl( 1, Q_tmp ); - P_ONE = L_shl( 3277 /* 0.1 in Q15 */, sub( Q_tmp, 15 ) ); - L_tmp = L_msu0( ONE, tmp, 1 ); - test(); - if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) ) - { - /* emphasize HF noise in CNG */ - /*fac *= 2.0f;*/ - L_tmp = L_add( L_tmp, L_tmp ); + /*scale *= fac;*/ + tmp = mult_r( scale, tmp ); /* Q = (15 - exp1) + Q_tmp - 15 */ + Q_tmp = sub( Q_tmp, exp1 ); } - L_tmp = L_max( L_tmp, P_ONE ); - L_tmp = L_min( L_tmp, ONE ); - sft = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, sft ); - - tmp = round_fx( L_tmp ); - Q_tmp = sub( add( Q_tmp, sft ), 16 ); - - /*scale *= fac;*/ - tmp = mult_r( scale, tmp ); /* Q = (15 - exp1) + Q_tmp - 15 */ - Q_tmp = sub( Q_tmp, exp1 ); /*-----------------------------------------------------------------* * modify HF excitation according to both calculated scaling factors * high pass filtering (0.94ms of delay) @@ -441,21 +312,17 @@ static void hf_synthesis_ivas_fx( move16(); filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx, tmp, exp2 ); - /* i: HF_exc in Q(-3) */ - /* o: HF_exc in ((-3) + Q_tmp - 17) */ - /* o: hBWE_zero->mem_hf_fx in Q(HF_exc)-2 */ + /* i: input HF_exc is scaled in float, here scaling is done inside this filter */ + /* i: mem_hf in Q-2 */ + /* o: HF_exc in Q0 */ /*-----------------------------------------------------------------* * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz *-----------------------------------------------------------------*/ - /*weight_a( Aq, Ap, 0.6f, M );*/ weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M ); - /* o: Ap in Q14 */ Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 ); - /* o: HF_syn in same Q as HF_exc */ - /* o: mem_syn_hf_fx same Q as HF_syn */ Scale_sig( HF_syn, L_SUBFR16k, ( add( Q_syn, exp1 ) ) ); /* bring HF_syn to (Q_syn+exp1) */ @@ -494,11 +361,13 @@ static void hf_synthesis_ivas_fx( { Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } + Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); return; } + /*-------------------------------------------------------------------* * filt_6k_7k: * @@ -508,6 +377,7 @@ static void hf_synthesis_ivas_fx( * dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB * (gain=4.0) *-------------------------------------------------------------------*/ + static void filt_6k_7k_scale_fx( Word16 signal[], /* i/o: signal Qx*/ Word16 lg, /* i : length of input Q0*/ @@ -539,9 +409,13 @@ static void filt_6k_7k_scale_fx( signal[i] = round_fx_sat( L_tmp ); /* Q0 */ move16(); } + Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */ + + return; } + /*-------------------------------------------------------------------* * hf_synth_amr_wb_init() * @@ -578,7 +452,7 @@ void hf_synth_amr_wb_init_fx( move16(); hAmrwb_IO->OptCrit_old_fx = 32768; move32(); /*1.0f in Q15*/ - ; + return; } @@ -589,6 +463,7 @@ void hf_synth_amr_wb_init_fx( * reset of HF synthesis filters * - needed in switching scenarios *-------------------------------------------------------------------*/ + void hf_synth_amr_wb_reset_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ @@ -634,6 +509,7 @@ void hf_synth_amr_wb_reset_fx( return; } + /*-------------------------------------------------------------------* * hf_synth_amr_wb() * @@ -641,8 +517,8 @@ void hf_synth_amr_wb_reset_fx( *-------------------------------------------------------------------*/ void hf_synth_amr_wb_fx( - AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ - ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ + AMRWB_IO_DEC_HANDLE hAmrwb_IO, /* i/o: AMR-WB IO data handle */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* o : zero BWE decoder handle */ const Word32 core_brate, /* i : core bitrate Q0*/ const Word16 output_frame, /* i : output frame length Q0*/ const Word16 *Aq, /* i : quantized Az : Q12*/ @@ -883,7 +759,6 @@ void hf_synth_amr_wb_fx( tmp = sub( 18022 /* 1.1f in Q14 */, tmp ); /*Q14 */ fmerit_w = round_fx( L_shl( L_mult( fmerit_w, tmp ), 1 ) ); /*Q: 14+14+1+1-16 = 14 */ - L_tmp = L_deposit_l( fmerit_w ); /*Q14 */ L_tmp = Isqrt( L_tmp ); /*Q(31-7) */ tmp = round_fx( L_tmp ); /*Q8 */ @@ -1201,6 +1076,8 @@ void hf_synth_amr_wb_fx( return; } + + static void hf_synthesis_amr_wb_fx( const Word32 core_brate, /* i : core bitrate : Q0*/ const Word16 output_subfr, /* i : output sub-frame length : Q0*/ @@ -1226,6 +1103,7 @@ static void hf_synthesis_amr_wb_fx( Word32 L_tmp; Word16 q1, q2, q3, shift; Word16 *pt1, *pt2, flag; + IF( EQ_32( core_brate, ACELP_23k85 ) ) { ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_SUBFR ); @@ -1361,6 +1239,7 @@ static void hf_synthesis_amr_wb_fx( return; } + static Word16 EnhanceClass_fx( const Word16 qq_fx, /* Qx */ const Word16 pp_fx, /* Qx */ @@ -1423,10 +1302,12 @@ static Word16 EnhanceClass_fx( *unvoicing_flag = 0; move16(); } + test(); return ( *unvoicing_flag && GT_16( qq_fx, pp_fx ) ); } + static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, /* i : core bitrate Q0*/ @@ -1450,7 +1331,6 @@ static void envelope_fx( const Word16 *pt2, *pt3; Word16 Aq[M + 1]; - /* Aq has dynamic scaling go back to Q12 to make sure there's no overflow while calculating qx,qy*/ shift = sub( norm_s( Aq_dyn_scal[0] ), 2 ); @@ -1644,7 +1524,6 @@ static void envelope_fx( } qy = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ - L_tmp = L_mult( qx, qx ); /* Q21 + 2q1 */ L_tmp = L_mac( L_tmp, qy, qy ); /* Q21 + 2q1 */ qq = round_fx( Isqrt( L_shr( L_tmp, add( 11, shl( q1, 1 ) ) ) ) ); /*Q10*/ @@ -1711,16 +1590,17 @@ static void envelope_fx( rr = s_min( est_level1, est_level2 ); } - q1 = norm_s( pp ); tmp = div_s( shl( 1, sub( 14, q1 ) ), pp ); /*Q(29-q1-10) */ L_tmp = L_mult( rr, tmp ); /*Q(30-q1-10+10) */ *sub_gain = s_min( 20480 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ move16(); + return; } + /*---------------------------------------------------------------------* * AdaptiveStartBand_fx() * diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 6be36bd1ac5cd96048cfda606148eb5f02ac6e29..dcc99bbdc980ea25aa9fe8066a50ef78303a1313 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -468,8 +468,13 @@ void ivas_hq_core_dec_fx( const Word16 output_frame, /* i : output frame length Q0*/ const Word16 hq_core_type, /* i : HQ core type Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ - Word16 output[], /* Q_ouput */ - Word16 *Q_output ) +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ +#else + Word16 output[], /* Q_ouput */ + Word16 *Q_output +#endif +) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; Word16 i, j, flag_uv, num_Sb, nb_sfm; @@ -484,15 +489,13 @@ void ivas_hq_core_dec_fx( Word32 normq_fx[NB_SFM]; Word16 mean_en_high_fx; Word16 SWB_fenv_fx[SWB_FENV + DIM_FB]; - const Word16 *sfmsize, *sfm_start, *sfm_end; Word16 gapsynth_fx[L_FRAME48k]; Word16 tmp, tmp_loop; Word32 L_tmp; UWord16 lsb; Word16 L_spec; - HQ_NBFEC_HANDLE hHQ_nbfec; HQ_DEC_HANDLE hHQ_core; - hHQ_nbfec = st_fx->hHQ_nbfec; + hHQ_core = st_fx->hHQ_core; TCX_DEC_HANDLE hTcxDec; @@ -506,7 +509,19 @@ void ivas_hq_core_dec_fx( Word16 mdctWindowLength; Word16 mdctWindowLengthFB; Word16 tmp_e; +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 tmp_out[L_FRAME48k]; +#else + Word16 output[L_FRAME16k]; + Word16 Q_output; + + Q_output = 0; + move16(); + *Q_synth = 0; + move16(); + st_fx->Q_syn_factor = 0; + move16(); +#endif /*-------------------------------------------------------------------------- * Initializations @@ -519,11 +534,10 @@ void ivas_hq_core_dec_fx( set16_fx( wtda_audio_16, 0, 2 * L_FRAME48k ); mean_en_high_fx = 0; move16(); - Q_audio = 12; + Q_audio = Q12; move16(); - Q_G_audio = 12; + Q_G_audio = Q12; move16(); - sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; move16(); move16(); @@ -565,14 +579,7 @@ void ivas_hq_core_dec_fx( } ELSE { - core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - if ( GT_16( num_bits, HQ_48k / 50 ) ) - { - num_bits = (Word16) ( HQ_48k / 50 ); - move16(); - } + /* this cannot happen in IVAS */ } } IF( hq_recovery_flag ) @@ -625,11 +632,6 @@ void ivas_hq_core_dec_fx( } } - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); - } - /*-------------------------------------------------------------------------- * transform-domain decoding *--------------------------------------------------------------------------*/ @@ -645,11 +647,6 @@ void ivas_hq_core_dec_fx( &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); } - ELSE - { - HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, hHQ_nbfec->ynrm_values_fx, hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, - output_frame, sfm_start, sfm_end ); - } hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); @@ -675,16 +672,10 @@ void ivas_hq_core_dec_fx( { IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { - IF( EQ_16( st_fx->prev_bfi, 1 ) ) - { - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - } + /* this cannot happen in IVAS */ - /* HQ low rate decoder */ - hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); + is_transient = 0; + move16(); hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; @@ -730,9 +721,11 @@ void ivas_hq_core_dec_fx( } } } - ivas_HQ_FEC_Mem_update_fx( st_fx, t_audio_q, normq_fx, ynrm, num_bands_p, is_transient, hqswb_clas, - core_switching_flag, nb_sfm, num_Sb, &mean_en_high_fx, hq_core_type, output_frame ); + + HQ_FEC_Mem_update_fx( st_fx, t_audio_q, normq_fx, ynrm, num_bands_p, is_transient, hqswb_clas, + core_switching_flag, nb_sfm, num_Sb, &mean_en_high_fx, hq_core_type, output_frame ); } + /*-------------------------------------------------------------------------- * Attenuate HFs in case of band-width switching (from higher BW to lower BW) *--------------------------------------------------------------------------*/ @@ -910,47 +903,14 @@ void ivas_hq_core_dec_fx( move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Q_output = Q_audio; +#else *Q_output = Q_audio; +#endif move16(); } - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - test(); - IF( EQ_16( st_fx->bfi, 0 ) && st_fx->prev_bfi == 0 ) - { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 31 - exp_old_out - Q_old_wtda */ - } - ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) - { - set16_fx( hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); - } - - test(); - test(); - test(); - test(); - IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && EQ_16( hHQ_core->old_is_transient[2], 0 ) && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) ) - { - time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); - } - ELSE - { - window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - hHQ_nbfec->phase_mat_next = 0; - move16(); - } - - test(); - test(); - IF( ( EQ_16( st_fx->bfi, 0 ) && EQ_16( st_fx->prev_bfi, 0 ) ) || !( GE_16( output_frame, L_FRAME16k ) ) ) - { - preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, - &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); - } - } - ELSE { test(); IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) @@ -973,7 +933,11 @@ void ivas_hq_core_dec_fx( IF( st_fx->element_mode > EVS_MONO ) { /* LB synthesis for potential switch to ACELP */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + window_ola_fx( wtda_audio_LB, output, &Q_output, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, L_FRAME16k, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); +#else window_ola_fx( wtda_audio_LB, output, Q_output, hHQ_core->old_out_LB_fx, &hHQ_core->Q_old_wtda_LB, L_FRAME16k, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); +#endif } test(); test(); @@ -986,28 +950,6 @@ void ivas_hq_core_dec_fx( } } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) ) - { - st_fx->hPlcInfo->recovery_gain = shl_sat( st_fx->hPlcInfo->recovery_gain, *Q_synth ); /* Q15 */ - move16(); - IF( st_fx->hTonalMDCTConc->q_lastPcmOut != 0 ) - { - Scale_sig( st_fx->hTonalMDCTConc->secondLastPcmOut, shr( st_fx->hPlcInfo->L_frameTCX, 1 ), negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); - Scale_sig( st_fx->hTonalMDCTConc->lastPcmOut, st_fx->hPlcInfo->L_frameTCX, negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); - st_fx->hTonalMDCTConc->q_lastPcmOut = 0; - move16(); - } - waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth, 0, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi ); - } - IF( GE_16( output_frame, L_FRAME16k ) ) { IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) ) @@ -1034,13 +976,6 @@ void ivas_hq_core_dec_fx( move16(); } - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* Q_old_auOut */ - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ - } - /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ { @@ -1064,12 +999,21 @@ void ivas_hq_core_dec_fx( Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } + /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig( output, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame, negate( Q_output ) ); /* Q0 */ + + Copy_Scale_sig_16_32_DEPREC( output, output_32_fx, L_FRAME16k, sub( Q11, Q_output ) ); // Q11 + st_fx->Q_syn_factor = s_min( 0, s_min( *Q_synth, Q_output ) ); +#else IF( st_fx->element_mode > EVS_MONO ) { Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } +#endif + return; } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 0d342ba2dca4b8d6c76ba11a26494c5d88a9d067..30a7d4f4ae9ca4fc66f9917ef120cb2bf155e698 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -166,7 +166,8 @@ void ivas_hq_hr_dec_fx( Word16 csw_flag1, csw_flag2; HQ_DEC_HANDLE hHQ_core = st_fx->hHQ_core; - + hq_generic_offset = 0; + move16(); move16(); move16(); @@ -434,7 +435,8 @@ void hq_hr_dec_fx( move16(); HQ_DEC_HANDLE hHQ_core = st_fx->hHQ_core; - + hq_generic_offset = 0; + move16(); move16(); Q_audio = 0; /* to avoid compilation warnings */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index b08a0cb64c9e472df4c0282f4a76a5e98382106d..fba40748cd832d65b1b32a2a3ea0aac9ee6229a1 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -14,7 +14,7 @@ #include "stat_dec.h" #include "basop_util.h" #define MID 57 /* (.89*1<<6)*/ -#include "ivas_prot_fx.h" + /**********************************************************************/ /* get scalefactor of an Word32 array with condition @@ -1838,11 +1838,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); + width = sub( hGrid->swb_offset[s_min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[s_min( sfb + tb, stop_sfb )] ); - tmp = dS[min( sfb + tb, stop_sfb - 1 )]; - tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; + tmp = dS[s_min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[s_min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -2507,11 +2507,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); + width = sub( hGrid->swb_offset[s_min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[s_min( sfb + tb, stop_sfb )] ); - tmp = dS[min( sfb + tb, stop_sfb - 1 )]; - tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; + tmp = dS[s_min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[s_min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index ec2c0ce0bf2a289c6f395fd43c5d54feeff6ce7d..b8a5fe6de63c1dd49f8d29605942b44899021687 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -91,12 +91,23 @@ ivas_error init_decoder_fx( move16(); st_fx->ini_frame = 0; move16(); - st_fx->bwidth = NB; - move16(); - st_fx->last_bwidth = NB; - move16(); + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->bwidth = NB; + move16(); + st_fx->last_bwidth = NB; + move16(); + } + ELSE + { + st_fx->bwidth = WB; + move16(); + st_fx->last_bwidth = WB; + move16(); + } st_fx->extl_brate = 0; move16(); + st_fx->coder_type = GENERIC; /* low-rate mode flag */ move16(); st_fx->last_coder_type = GENERIC; @@ -425,7 +436,6 @@ ivas_error init_decoder_fx( set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); set32_fx( st_fx->delay_buf_out32_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set32_fx( st_fx->previoussynth_fx_32, 0, L_FRAME48k ); IF( st_fx->element_mode == EVS_MONO ) { @@ -928,7 +938,7 @@ ivas_error init_decoder_fx( } /* Init FD-CNG */ - initFdCngDec_ivas_fx( st_fx, st_fx->cldfbSyn->scale ); + initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); } ELSE { diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 4d44e5b5b421cffb7f2d5faa669a5fbfd39ad139..21e70e083045a138a72ac4a8a909e9654abe63c4 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -191,188 +191,3 @@ void inov_decode_fx( cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); return; } - -/*======================================================================*/ -/* FUNCTION : inov_decode_ivas_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Decode the algebraic innovation and do pitch sharpening */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/* _ (Word16) i_subfr : length of the frame Q0 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) L_subfr : subframe length */ -/* _ (Word16) sharpFlag : formant sharpening flag */ -/* _ (Word16) tc_subfr : TC subframe index */ -/* _ (Word16 *) p_Aq : LP filter coefficients Q12 */ -/* _ (Word16) tilt_code : tilt of the excitation of previous subframe Q15*/ -/* _ (Word16) pt_pitch : current subframe fractional pitch Q6 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *[]) code : subframe length Q12 */ -/* _ (Word16 []) index_buf_4T : subframe length */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void inov_decode_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate Q0 */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ - const Word16 L_frame, /* i : length of the frame Q0 */ - const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation Q12 */ - const Word16 L_subfr /* i : subframe length Q0 */ -) -{ - Word16 nBits; - Word16 g1, g2; - - IF( EQ_16( L_frame, L_FRAME ) ) - { - g1 = FORMANT_SHARPENING_G1; - move16(); - g2 = FORMANT_SHARPENING_G2; - move16(); - } - ELSE - { - g1 = FORMANT_SHARPENING_G1_16k; - move16(); - g2 = FORMANT_SHARPENING_G2_16k; - move16(); - } - - IF( !Opt_AMR_WB ) - { - IF( st_fx->acelp_cfg.fcb_mode ) - { - Word16 i; - Word16 indexing_indices[8], wordcnt, bitcnt; - PulseConfig config; - test(); - test(); - test(); - IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0 ) - { - IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) - { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 - move16(); - - IF( EQ_16( nBits, 8 ) ) - { - dec_acelp_1t64_fx( st_fx, code, L_subfr ); - } - ELSE - { - dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); - } - } - ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( ( st_fx->idchan == 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) - { - IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) - { - dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); - } - ELSE - { - dec_acelp_fast_fx( st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR ); - } - } - ELSE - { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 - move16(); - bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 - move16(); - - FOR( i = 0; i < wordcnt; i++ ) - { - indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); // Q0 - move16(); - } - IF( bitcnt ) - { - indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); // Q0 - move16(); - } - config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; - D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); - } - } - ELSE - { - set16_fx( code, 0, L_SUBFR ); - } - } - ELSE - { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 - move16(); - - IF( EQ_16( nBits, 7 ) ) - { - dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); - } - ELSE IF( EQ_16( nBits, 12 ) ) - { - dec_acelp_2t32_fx( st_fx, code ); - } - ELSE - { - dec_acelp_4t64_fx( st_fx, nBits, code, Opt_AMR_WB ); - } - } - } - ELSE - { - IF( EQ_32( core_brate, ACELP_6k60 ) ) - { - dec_acelp_2t32_fx( st_fx, code ); - } - ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) - { - dec_acelp_4t64_fx( st_fx, 20, code, Opt_AMR_WB ); - } - ELSE IF( EQ_32( core_brate, ACELP_12k65 ) ) - { - dec_acelp_4t64_fx( st_fx, 36, code, Opt_AMR_WB ); - } - ELSE IF( EQ_32( core_brate, ACELP_14k25 ) ) - { - dec_acelp_4t64_fx( st_fx, 44, code, Opt_AMR_WB ); - } - ELSE IF( EQ_32( core_brate, ACELP_15k85 ) ) - { - dec_acelp_4t64_fx( st_fx, 52, code, Opt_AMR_WB ); - } - ELSE IF( EQ_32( core_brate, ACELP_18k25 ) ) - { - dec_acelp_4t64_fx( st_fx, 64, code, Opt_AMR_WB ); - } - ELSE IF( EQ_32( core_brate, ACELP_19k85 ) ) - { - dec_acelp_4t64_fx( st_fx, 72, code, Opt_AMR_WB ); - } - ELSE - { - dec_acelp_4t64_fx( st_fx, 88, code, Opt_AMR_WB ); - } - } - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - return; -} diff --git a/lib_dec/ivas_agc_dec_fx.c b/lib_dec/ivas_agc_dec_fx.c index a196a1abdd8a157e472fdcf21913f8367fd42e63..c091579e49590469de74283c12003cf0f948e3fa 100644 --- a/lib_dec/ivas_agc_dec_fx.c +++ b/lib_dec/ivas_agc_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,12 +31,10 @@ *******************************************************************************************************/ #include -#include #include #include "options.h" #include "prot_fx.h" #include "ivas_prot_fx.h" -#include "rom_com.h" #include "wmc_auto.h" diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index c4014731a21f82fd02dc5f469edac7462837eaad..0b7e13a808921b9ee0de8d6a139cfc5a0d35a488 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,14 +33,12 @@ #include #include "options.h" #include -#include -#include "cnst.h" +#include "ivas_cnst.h" #include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* @@ -72,19 +70,13 @@ ivas_error ivas_core_dec_fx( Word16 tmp_buffer_fx[L_FRAME48k]; Word16 tmp16, tmp16_2, j; Word16 Q_white_exc; - - set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); - Word16 tmps, incr; Word16 flag_bwe_bws, flaf_swb_tbe; Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL }; - Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q15 Word16 core_switching_flag[CPE_CHANNELS]; - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q6 - Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; - + Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; Word16 unbits[CPE_CHANNELS]; Word16 sid_bw[CPE_CHANNELS]; FRAME_MODE frameMode[CPE_CHANNELS]; @@ -101,16 +93,13 @@ ivas_error ivas_core_dec_fx( ivas_error error; Word32 L_tmp; Word16 Q_synth; +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; +#endif Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; Word16 e_sig[CPE_CHANNELS]; - e_sig[0] = e_sig[1] = 15; - move16(); - move16(); - Word16 tdm_lsfQ_PCh_fx[M]; Word32 conceal_eof_gain32; @@ -118,6 +107,11 @@ ivas_error ivas_core_dec_fx( move32(); push_wmops( "ivas_core_dec" ); + set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); + e_sig[0] = e_sig[1] = Q15; + move16(); + move16(); + /*------------------------------------------------------------------* * General initialization *-----------------------------------------------------------------*/ @@ -290,6 +284,9 @@ ivas_error ivas_core_dec_fx( } set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + set32_fx( output_32_fx[n], 0, L_FRAME48k ); +#endif set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ @@ -441,7 +438,7 @@ ivas_error ivas_core_dec_fx( * Detect bandwidth switching *---------------------------------------------------------------------*/ - bandwidth_switching_detect_ivas_fx( st ); + bandwidth_switching_detect_fx( st ); /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching @@ -454,9 +451,7 @@ ivas_error ivas_core_dec_fx( move16(); move16(); - Copy_Scale_sig_16_32_DEPREC( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); // Q0 - - IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) { return error; } @@ -475,12 +470,13 @@ ivas_error ivas_core_dec_fx( * HQ core decoding *---------------------------------------------------------------------*/ +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE set16_fx( output_16_fx[n], 0, L_FRAME48k ); /* this is needed for instances like L_norm_arr( p_output_fx[i], L_FRAME48k ) */ - +#endif IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ - Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; IF( save_hb_synth_32_fx ) @@ -491,7 +487,7 @@ ivas_error ivas_core_dec_fx( { save_hb_synth_16_fx = NULL; } - +#endif IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q11 - Q10 ); // Q11 @@ -531,13 +527,19 @@ ivas_error ivas_core_dec_fx( st->Q_syn_factor = 0; move16(); - IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( NE_32( ( error = acelp_core_dec_fx( st, output_32_fx[n], synth_16_fx[n], save_hb_synth_32_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#else + IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#endif { return error; } +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); // Q0 +#endif IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q10 - Q11 ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) , Q10 */ @@ -560,16 +562,16 @@ ivas_error ivas_core_dec_fx( IF( save_hb_synth_32_fx ) { +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Copy_Scale_sig_16_32_DEPREC( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); // Q11 +#else + Scale_sig32( save_hb_synth_32_fx, output_frame, Q11 ); // Q0 -> Q11 +#endif hSCE->q_save_hb_synth_fx = Q11; move16(); } - - Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) } - Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); // Q0 - test(); test(); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -605,9 +607,13 @@ ivas_error ivas_core_dec_fx( move32(); } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + stereo_tcx_core_dec_fx( st, frameMode[n], output_32_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); +#else stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, sub( Q11, st->Q_syn_factor ) ); // Q11 +#endif IF( st->hTcxDec ) { @@ -625,6 +631,11 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); + + Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor +#else Word16 Q_output; Q_output = 0; @@ -640,6 +651,7 @@ ivas_error ivas_core_dec_fx( st->Q_syn_factor = s_min( 0, s_min( Q_synth, Q_output ) ); Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor Scale_sig( output_16_fx[n], L_FRAME48k, sub( st->Q_syn_factor, Q_output ) ); // st->Q_syn_factor +#endif } /*---------------------------------------------------------------------* @@ -819,6 +831,7 @@ ivas_error ivas_core_dec_fx( /*core_switching_post_dec*/ Q_synth = add( sub( 15, e_sig[0] ), st->Q_syn_factor ); +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING /*------------------fix-to-fix-end-----------------------*/ Word16 output_mem_16_fx[L_FRAME48k]; @@ -839,7 +852,7 @@ ivas_error ivas_core_dec_fx( /*size of synth is choosen as delay comp to start with*/ /*-------------------cldfb-start-------------------------*/ - +#endif IF( st->cldfbSyn != NULL ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q4 - Q11 ); // Q4 @@ -847,11 +860,6 @@ ivas_error ivas_core_dec_fx( move16(); } - Word16 q_audio, old_syn_fx; - old_syn_fx = Q11; - move16(); - q_audio = Q12; - move16(); test(); test(); test(); @@ -903,7 +911,11 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_fx, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#else + IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -933,7 +945,7 @@ ivas_error ivas_core_dec_fx( * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ - ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); + bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n] ); IF( st->hHQ_core == NULL ) { @@ -944,7 +956,14 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE + Scale_sig32( output_32_fx[n], output_frame, ( Q4 - Q11 ) ); // Q4 + Scale_sig32( output_32_fx[n], output_frame, ( Q11 - Q4 ) ); // Q11 +#endif +#else Scale_sig32( output_32_fx[n], L_FRAME48k, ( Q11 - Q4 ) ); // Q11 +#endif /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -985,8 +1004,18 @@ ivas_error ivas_core_dec_fx( * WB BWE decoding *---------------------------------------------------------------------*/ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE + Word16 Q_hb_synth_fx, Q_synth_fx; + Word16 Q_syn_hb; + + Q_hb_synth_fx = 0; + move16(); + Q_synth_fx = Q_synth; + move16(); +#else Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; Word16 Q_syn_hb, sf; +#endif flaf_swb_tbe = 0; move16(); @@ -1004,6 +1033,7 @@ ivas_error ivas_core_dec_fx( move16(); } +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE sf = getScaleFactor32( output_32_fx[n], L_FRAME48k ); Q_input = 0; @@ -1018,7 +1048,8 @@ ivas_error ivas_core_dec_fx( move16(); Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, sub( Q_input, Q11 ) ); // Q_input - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 +#endif + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 test(); test(); test(); @@ -1028,7 +1059,11 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ +#ifdef HARMONIZE_TBE + wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); +#else ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); +#endif } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) { @@ -1037,7 +1072,11 @@ ivas_error ivas_core_dec_fx( ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) { /* WB BWE decoder */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_32_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); +#else Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); +#endif } /* Memories Re-Scaling */ @@ -1045,7 +1084,9 @@ ivas_error ivas_core_dec_fx( { Copy_Scale_sig_16_32_no_sat( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 } - Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE + Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 +#endif Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], synth_32_fx[n], output_frame, sub( Q11, Q_synth_fx ) ); // Q11 IF( hBWE_FD != NULL ) @@ -1092,7 +1133,11 @@ ivas_error ivas_core_dec_fx( /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { +#ifdef HARMONIZE_TBE + fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); +#else fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); +#endif } } ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || flag_bwe_bws ) @@ -1151,22 +1196,31 @@ ivas_error ivas_core_dec_fx( IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) { /* SHB CNG decoder */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], output_frame, -( Q11 ) ); // Q0 + Copy_Scale_sig_32_16( synth_32_fx[n], synth_16_fx[n], output_frame, -( Q11 + Q2 ) ); // Q0 + Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 + Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 + + swb_CNG_dec_fx( st, synth_16_fx[n], hb_synth_16_fx[n], sid_bw[n], -Q2 ); +#else Word16 synth_fxl[960]; /* Q-2 */ Word16 q; q = 2; move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], output_frame, -( Q11 ) ); // Q0 Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); // Q0 Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 - swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); + swb_CNG_dec_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); +#endif test(); IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { - Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], output_frame, ( Q11 ) ); // Q11 } Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ) ); // Q0 @@ -1181,15 +1235,11 @@ ivas_error ivas_core_dec_fx( IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) { Word16 q; - q = 11; + q = Q11; move16(); - if ( hCPE->hStereoDft != NULL ) - { - hCPE->hStereoDft->td_gain_fx[0] = 1; - move32(); - } stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q, Q_white_exc ); + test(); test(); test(); @@ -1488,7 +1538,7 @@ ivas_error ivas_core_dec_fx( save_synthesis_hq_fec_fx( st, NULL, output_fx_loc, output_frame, 0, hCPE ); /* Updates */ - ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); + updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, NULL, output_32_fx[n], Q11 ); Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); // Q0 diff --git a/lib_dec/ivas_corecoder_dec_reconfig_fx.c b/lib_dec/ivas_corecoder_dec_reconfig_fx.c index 288cd9a0373fe7247a3cb4c3f8dbc5ea3c6df7ef..6e6ac9d3545b46c15e39f4baf6d60a8ce62f7ce3 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig_fx.c +++ b/lib_dec/ivas_corecoder_dec_reconfig_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 7a134d59bed246fc942c44990d849f1ae34fed71..45007974483505fb416b1075b6e00456be83df21 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,14 +33,11 @@ #include #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include /*--------------------------------------------------------------------------* diff --git a/lib_dec/ivas_dec_fx.c b/lib_dec/ivas_dec_fx.c new file mode 100644 index 0000000000000000000000000000000000000000..bd3eab3e4feb8c9131b76321da996b6d835e91f4 --- /dev/null +++ b/lib_dec/ivas_dec_fx.c @@ -0,0 +1,1565 @@ +/****************************************************************************************************** + + (C) 2022-2026 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 +#include "options.h" +#include "ivas_cnst.h" +#include "prot_fx.h" +#include "ivas_prot_fx.h" +#include "ivas_prot_rend_fx.h" +#include "ivas_rom_com.h" +#include "wmc_auto.h" +#ifdef DEBUGGING +#include "debug.h" +#endif + + +/*--------------------------------------------------------------------------* + * ivas_dec() + * + * Principal IVAS decoder routine, decoding of metadata and transport channels + *--------------------------------------------------------------------------*/ + +ivas_error ivas_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 ch, n, output_frame, nchan_out, i, s; + Decoder_State *st; /* used for bitstream handling */ + Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* buffer for output synthesis */ + Word16 nchan_remapped; + Word16 nb_bits_metadata[MAX_SCE + 1]; + Word32 output_Fs, ivas_total_brate; + AUDIO_CONFIG output_config; + ivas_error error; + Word16 num_md_sub_frames; + Word32 ism_total_brate; + + push_wmops( "ivas_dec" ); + /*----------------------------------------------------------------* + * Initialization of local vars after struct has been set + *----------------------------------------------------------------*/ + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); + nchan_out = st_ivas->hTcBuffer->nchan_transport_rend; + move16(); + output_config = st_ivas->hDecoderConfig->output_config; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); + + output_frame = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) /* output_Fs / FRAMES_PER_SEC */; + + /* set pointers to transport channels audio */ + FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ ) + { + p_output_fx[n] = st_ivas->p_output_fx[n]; + IF( p_output_fx[n] != NULL ) + { + set32_fx( p_output_fx[n], 0, L_FRAME48k ); + } + } + + /*----------------------------------------------------------------* + * Decoding + pre-rendering + *----------------------------------------------------------------*/ + + test(); + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + + { + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + move32(); + IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* HP filtering */ + FOR( n = 0; n < s_min( nchan_out, st_ivas->nchan_transport ); n++ ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* Metadata decoding and configuration */ + test(); + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) + { + ivas_ism_dtx_dec_fx( st_ivas, nb_bits_metadata ); + + IF( ( error = ivas_sce_dec_fx( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &p_output_fx[st_ivas->hISMDTX.sce_id_dtx], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK ) + { + return error; + } + + ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport ); + + ivas_param_ism_dec_dequant_md_fx( st_ivas ); + } + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + ivas_param_ism_dec_dequant_md_fx( st_ivas ); + } + ELSE /* ISM_MODE_DISC */ + { + IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + FOR( n = 0; n < st_ivas->nchan_transport; n++ ) + { + /* for DTX frames, dominant object has already been decoded before */ + test(); + test(); + IF( !( ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) && EQ_16( n, st_ivas->hISMDTX.sce_id_dtx ) ) ) + { + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[n], output_frame, nb_bits_metadata[n] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* HP filtering */ + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + { + ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame ); + + Scale_sig32( p_output_fx[0], output_frame, Q11 - Q8 ); + } + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) ) + { + /* loudness correction */ + ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, st_ivas->nchan_transport, output_frame ); /*returns Q-1*/ + + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q + } + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) + { + set16_fx( nb_bits_metadata, 0, MAX_SCE ); + + /* read parameters from the bitstream */ + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->hQMetaData != NULL ) + { + // st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( st_ivas->nSCE > 0 ) + { + st = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st = st_ivas->hCPE[0]->hCoreCoder[0]; + } + + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + test(); + IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[0]->brate_surplus = 0; + move32(); + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + move32(); + } + + /* core-decoding of transport channels */ + IF( EQ_16( st_ivas->nSCE, 1 ) ) + { + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* TCs remapping */ + nchan_remapped = st_ivas->nchan_transport; + move16(); + + test(); + test(); + test(); + test(); + test(); + IF( st_ivas->sba_dirac_stereo_flag ) + { + nchan_remapped = nchan_out; + move16(); + + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) + { + FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 + } + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); + nchan_out = nchan_transport; + move16(); + + ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx ), ( p_output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); + + IF( st_ivas->hSpar->hPCA != NULL ) + { + ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output_fx ); + } + + ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); + } + + ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame ); + } + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) + { + nchan_remapped = 1; /* Only one channel transported */ + move16(); + } + + /* HP filtering */ + FOR( n = 0; n < nchan_remapped; n++ ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + nchan_remapped = ivas_sba_remapTCs_fx( p_output_fx, st_ivas, output_frame ); + + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 Q_p_output = MAX_16, temp_min; + move16(); + Word16 nchan_transport; + + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); + nchan_out = nchan_transport; + move16(); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + temp_min = L_norm_arr( p_output_fx[ch], output_frame ); + Q_p_output = s_min( Q_p_output, temp_min ); + } + Q_p_output = sub( Q_p_output, 2 ); + if ( GT_16( Q_p_output, 20 ) ) + { + Q_p_output = 20; + move16(); + } + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); // Q(11+Q_p_output) + } + + ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output ); + FOR( Word16 c = 0; c < nchan_transport; c++ ) + { + Scale_sig32( p_output_fx[c], output_frame, 11 ); // Q11 + } + } + ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) + { + Word16 size = st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); + if ( EQ_16( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, 3 ) ) + size = add( size, 1 ); + + FOR( i = 0; i < size; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 + } + + ivas_spar_dec_agc_pca_fx( st_ivas, p_output_fx, output_frame ); + } + } + + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) + { + Word16 q_shift = 0; + move16(); + + ivas_masa_prerender_fx( st_ivas, p_output_fx, &q_shift, output_frame, nchan_remapped ); + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, negate( q_shift ) ); + } + + test(); + /* external output */ + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) + { + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) + { + set_zero_fx( p_output_fx[add( st_ivas->nchan_transport, n )], output_frame ); + } + + ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, output_frame ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + /* loudness correction */ + ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, nchan_remapped, output_frame ); + + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q + } + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + { + Word16 nchan_ism, nchan_transport_ism; + Word16 dirac_bs_md_write_idx; + + set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); + + /* Set the number of objects for the parametric rendering */ + dirac_bs_md_write_idx = 0; + move16(); + IF( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->numIsmDirections = 0; + move16(); + test(); + if ( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism; + move16(); + } + + dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ + move16(); + } + + /* MASA metadata decoding */ + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); + + st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); + + IF( NE_32( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + FOR( n = 0; n < nchan_transport_ism; n++ ) + { + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* decode MASA channels */ + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) + { + Copy32( p_output_fx[0], p_output_fx[1], output_frame ); /* Copy mono signal to stereo output channels */ + } + + FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + + Word16 output_q = Q11; + move16(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + { + ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame ); + + output_q = Q8; + move16(); + } + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + { + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + ivas_omasa_rearrange_channels_fx( p_output_fx, nchan_transport_ism, output_frame ); + } + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + /* Convert separate object to MASA, combine with the original MASA, and output combined MASA + empty objects. */ + ivas_omasa_combine_separate_ism_with_masa_fx( st_ivas, p_output_fx, &output_q, st_ivas->nchan_ism, output_frame ); + } + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + /* Extract objects from MASA, output MASA + all objects (i.e., extracted and separated objects) */ + ivas_omasa_render_objects_from_mix_fx( st_ivas, p_output_fx, st_ivas->nchan_ism, output_frame, &output_q ); + } + } + + IF( NE_16( output_q, Q11 ) ) + { + FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ ) + { + Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); // Q11 + } + st_ivas->hCPE[0]->q_output_mem_fx[0] = output_q; + st_ivas->hCPE[0]->q_output_mem_fx[1] = output_q; + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + Word16 nchan_ism, sba_ch_idx; + + set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); + nchan_ism = st_ivas->nchan_ism; + move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + /* set ISM parameters and decode ISM metadata in OSBA format */ + IF( NE_32( ( error = ivas_osba_ism_metadata_dec_fx( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) + { + return error; + } + sba_ch_idx = st_ivas->nchan_ism; + move16(); + } + ELSE + { + nb_bits_metadata[1] = add( nb_bits_metadata[1], NO_BITS_MASA_ISM_NO_OBJ ); + sba_ch_idx = 0; + move16(); + move16(); + } + + /* SBA metadata decoding */ + IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) ) + { + return error; + } + + test(); + IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + move32(); + } + + /* core-decoding of transport channels */ + IF( EQ_16( st_ivas->nSCE, 1 ) ) + { + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, add( nb_bits_metadata[0], nb_bits_metadata[1] ) ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + IF( st_ivas->sba_dirac_stereo_flag ) + { + FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); // Q14 + } + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); + nchan_out = nchan_transport; + move16(); + ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); + + IF( st_ivas->hSpar->hPCA != NULL ) + { + ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &p_output_fx[sba_ch_idx] ); + } + + ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); + + ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame ); + } + + /* HP filtering */ + FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + + nchan_remapped = ivas_sba_remapTCs_fx( &p_output_fx[sba_ch_idx], st_ivas, output_frame ); + + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 nchan_transport; + // num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); + nchan_out = nchan_transport; + move16(); + Word16 Q_p_output; + Word16 min_norm = 31; + move16(); + + FOR( ch = 0; ch < nchan_transport; ++ch ) + { + Word16 norm = L_norm_arr( p_output_fx[sba_ch_idx + ch], output_frame ); // Normalize per channel + min_norm = s_min( norm, min_norm ); + } + + Q_p_output = s_max( 3, sub( min_norm, 1 ) ); + + Q_p_output = s_min( Q_p_output, 19 ); // to restrict Q-factor of p_ouptut to Q30 + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, Q_p_output ); // Q_p_output + Q11 + } + Q_p_output = add( Q11, Q_p_output ); + hSpar->hMdDec->Q_mixer_mat = 31; + move16(); + + ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) ); + FOR( Word16 c = 0; c < nchan_transport; c++ ) + { + Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11 + } + } + ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 ) + { + Word16 size = add( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, sba_ch_idx ); + if ( EQ_16( size, 3 ) ) + { + size = add( size, 1 ); + } + + FOR( i = sba_ch_idx; i < size; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14 + } + + ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame ); + } + + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + /* loudness correction */ + ivas_dirac_dec_binaural_sba_gain_fx( &p_output_fx[sba_ch_idx], nchan_remapped, output_frame ); /*returns Q-1*/ + + FOR( i = 0; i < nchan_remapped; i++ ) + { + Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame ); + + Scale_sig32( p_output_fx[0], output_frame, Q11 - Q8 ); // Q11 + + /* add W */ + FOR( n = 0; n < nchan_out; n++ ) + { + v_add_32( p_output_fx[n], p_output_fx[n + s_max( nchan_out, nchan_ism )], p_output_fx[n], output_frame ); + } + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) + { + IF( st_ivas->nSCE > 0 ) + { + st = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st = st_ivas->hCPE[0]->hCoreCoder[0]; + } + + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + /* LFE channel decoder */ + ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); + + Scale_sig32( p_output_fx[LFE_CHANNEL], output_frame, Q11 - Q9 ); // Q11 + + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* HP filtering */ + FOR( n = 0; n < st_ivas->nchan_transport; n++ ) + { + IF( NE_16( n, LFE_CHANNEL ) ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + } + + test(); + test(); + test(); + IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) + { + ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); + } + } + + test(); + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) + { + IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) + { + s = Q16 - Q11; + move16(); + s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) ); + FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) + { + Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s) + } + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); + FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) + { + Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11 + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hOutSetup.ambisonics_order, 0 ); + } + } + } + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + /* LFE channel decoder */ + ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); + + Scale_sig32( p_output_fx[LFE_CHANNEL], output_frame, Q11 - Q9 ); // Q11 + + ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); + + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* HP filtering */ + FOR( n = 0; n < st_ivas->nchan_transport; n++ ) + { + IF( NE_16( n, LFE_CHANNEL ) ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + } + + /* Rendering */ + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + { + /* Compensate loudness for not doing full upmix */ + FOR( n = 4; n < 8; n++ ) + { + Scale_sig32( p_output_fx[n], output_frame, 1 ); + } + + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + { + s = Q16 - Q11; + move16(); + Word16 nchan_transport; + nchan_transport = audioCfg2channels( IVAS_AUDIO_CONFIG_5_1_2 ); + s = sub( s, find_guarded_bits_fx( nchan_transport ) ); + FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i ) + { + Scale_sig32( p_output_fx[i], output_frame, s ); + } + + ivas_ls_setup_conversion_fx( st_ivas, nchan_transport, output_frame, p_output_fx, p_output_fx ); + + FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i ) + { + Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); + } + } + } + } + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + /* read Parametric MC parameters from the bitstream */ + ivas_param_mc_dec_read_BS_fx( ivas_total_brate, st, st_ivas->hParamMC, &nb_bits_metadata[0] ); + + IF( EQ_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* HP filtering */ + FOR( n = 0; n < st_ivas->nchan_transport; n++ ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + + /* Rendering */ + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + { + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); + } + } + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + IF( st_ivas->hOutSetup.separateChannelEnabled ) + { + st = st_ivas->hCPE[0]->hCoreCoder[0]; /* Metadata is always with CPE in the case of separated channel */ + } + + /* read McMASA parameters from the bitstream */ + IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( st_ivas->hOutSetup.separateChannelEnabled ) + { + /* Decode the transport audio signals */ + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */ + n = LFE_CHANNEL - 1; + move16(); + + /* Decode the separated channel to output[n] to be combined with the synthesized channels */ + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */ + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + { + ivas_lfe_synth_with_filters_fx( st_ivas->hMasa->hMasaLfeSynth, p_output_fx, output_frame, n, LFE_CHANNEL ); + } + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 ) + { + /* Delay the separated channel to sync with the DirAC rendering */ + delay_signal32_fx( p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); + } + } + ELSE + { + IF( EQ_16( st_ivas->nSCE, 1 ) ) + { + IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) + { + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + + IF( st_ivas->sba_dirac_stereo_flag != 0 ) /* use the flag to trigger the DFT upmix */ + { + ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame ); + } + + /* HP filtering */ + FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + { + hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); + } + + IF( EQ_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) + { + ivas_mono_stereo_downmix_mcmasa_fx( st_ivas, p_output_fx, output_frame ); + } + } + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + IF( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */ + { + st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); + IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + move32(); + } + ELSE + { + st_ivas->last_active_ivas_total_brate = ivas_total_brate; + move32(); + } + } + + test(); + test(); + if ( LT_16( st_ivas->ini_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */ + { + st_ivas->ini_frame = add( st_ivas->ini_frame, 1 ); + move16(); + } + + test(); + test(); + if ( LT_16( st_ivas->ini_active_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */ + { + st_ivas->ini_active_frame = add( st_ivas->ini_active_frame, 1 ); + move16(); + } + + st_ivas->last_ivas_format = st_ivas->ivas_format; + move32(); + pop_wmops(); + + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_num_tc_channels() + * + * Get the number of transport channels provided to the renderer + *--------------------------------------------------------------------------*/ + +Word16 ivas_dec_get_num_tc_channels_fx( + Decoder_Struct *st_ivas /* i : IVAS decoder handle */ +) +{ + Word16 num_tc; + Word32 ivas_total_brate; + AUDIO_CONFIG output_config; + + IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) + { + num_tc = st_ivas->hDecoderConfig->nchan_out; + move16(); + } + ELSE + { + num_tc = st_ivas->nchan_transport; + move16(); + } + output_config = st_ivas->hDecoderConfig->output_config; + move16(); + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); + + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + { + num_tc = 1; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) + { + num_tc = 1; + move16(); + } + ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) + { + if ( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + { + num_tc = 1; + move16(); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + IF( st_ivas->sba_dirac_stereo_flag ) + { + num_tc = CPE_CHANNELS; + move16(); + } + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && st_ivas->hCPE[0] != NULL && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) + { + num_tc = 1; /* Only one channel transported */ + move16(); + } + + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->nchan_transport, 2 ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) + { + num_tc = CPE_CHANNELS; + move16(); + } + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) + { + if ( EQ_16( num_tc, 3 ) ) + { + num_tc = add( num_tc, 1 ); + } + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + { + IF( NE_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + { + test(); + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + num_tc = add( num_tc, 1 ); + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + num_tc = add( num_tc, st_ivas->nchan_ism ); + } + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + if ( st_ivas->sba_dirac_stereo_flag ) + { + num_tc = CPE_CHANNELS; + move16(); + } + + if ( EQ_16( num_tc, 3 ) ) + { + num_tc = add( num_tc, 1 ); + } + if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + num_tc = add( num_tc, st_ivas->nchan_ism ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) + { + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) ) + { + num_tc = 1; + move16(); + } + ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + { + num_tc = 2; + move16(); + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + /* do all static dmx already in the TC decoder if less channels than transported... */ + test(); + test(); + test(); + test(); + test(); + IF( NE_16( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + if ( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) + { + num_tc = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + } + } + ELSE IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) + { + num_tc = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + } + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + if ( st_ivas->hOutSetup.separateChannelEnabled ) + { + num_tc = add( num_tc, 1 ); + } + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) ) + { + /* LFE is synthesized in TD with the TCs*/ + num_tc = add( num_tc, 1 ); + } + } + } + + return num_tc; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_tc_buffer_mode() + * + * + *--------------------------------------------------------------------------*/ + +TC_BUFFER_MODE ivas_dec_get_tc_buffer_mode_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + TC_BUFFER_MODE buffer_mode; + + buffer_mode = TC_BUFFER_MODE_BUFFER; + move16(); + + SWITCH( st_ivas->renderer_type ) + { + /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */ + case RENDERER_DISABLE: + case RENDERER_MCMASA_MONO_STEREO: + case RENDERER_OSBA_STEREO: + case RENDERER_MONO_DOWNMIX: + buffer_mode = TC_BUFFER_MODE_BUFFER; + move16(); + BREAK; + case RENDERER_NON_DIEGETIC_DOWNMIX: + case RENDERER_TD_PANNING: + case RENDERER_BINAURAL_OBJECTS_TD: + case RENDERER_BINAURAL_FASTCONV: + case RENDERER_BINAURAL_FASTCONV_ROOM: + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + case RENDERER_STEREO_PARAMETRIC: + case RENDERER_DIRAC: + case RENDERER_PARAM_ISM: + case RENDERER_BINAURAL_MIXER_CONV: + case RENDERER_BINAURAL_MIXER_CONV_ROOM: + case RENDERER_OMASA_OBJECT_EXT: + case RENDERER_OMASA_MIX_EXT: + case RENDERER_OSBA_AMBI: + case RENDERER_OSBA_LS: + buffer_mode = TC_BUFFER_MODE_RENDERER; + move16(); + BREAK; + case RENDERER_MC_PARAMMC: + IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + { + buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */ + move16(); + } + ELSE + { + buffer_mode = TC_BUFFER_MODE_RENDERER; + move16(); + } + BREAK; + case RENDERER_MC: + if ( NE_16( ivas_dec_get_num_tc_channels_fx( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) ) + { + buffer_mode = TC_BUFFER_MODE_RENDERER; + move16(); + } + BREAK; + case RENDERER_SBA_LINEAR_ENC: + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( ( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), ( add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) ) + { + buffer_mode = TC_BUFFER_MODE_BUFFER; + move16(); + } + ELSE + { + buffer_mode = TC_BUFFER_MODE_RENDERER; + move16(); + } + BREAK; + case RENDERER_SBA_LINEAR_DEC: + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + { + buffer_mode = TC_BUFFER_MODE_BUFFER; + move16(); + } + ELSE + { + buffer_mode = TC_BUFFER_MODE_RENDERER; + move16(); + } + BREAK; + } + + return buffer_mode; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_tc_audio_allocate() + * + * allocate and initialize TC audio buffer + *--------------------------------------------------------------------------*/ + +static ivas_error ivas_dec_tc_audio_allocate_fx( + DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: TC buffer handle */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 Opt_tsm /* i : TSM option flag */ +) +{ + Word16 nsamp_to_allocate; + Word16 ch_idx, n_samp_full, n_samp_residual, offset; + + IF( Opt_tsm ) + { + n_samp_full = NS2SA_FX2( output_Fs, MAX_JBM_L_FRAME_NS ); + n_samp_full = s_max( n_samp_full, L_FRAME48k ); /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': ensure minimal length */ + n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); + } + ELSE + { + n_samp_full = extract_l( Mpy_32_32( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + n_samp_residual = 0; + move16(); + } + + nsamp_to_allocate = imult1616( s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ), n_samp_full ); + + IF( Opt_tsm ) + { + /* note: this is stack memory buffer for TC decoded and also time-scale modified audio signals */ + IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TC Buffer\n" ) ); + } + set_zero_fx( hTcBuffer->tc_buffer_fx, nsamp_to_allocate ); + + offset = 0; + move16(); + FOR( ch_idx = 0; ch_idx < s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); ch_idx++ ) + { + hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; + offset = add( offset, n_samp_full ); + } + FOR( ; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) + { + hTcBuffer->tc_fx[ch_idx] = NULL; + } + + /* memory buffer for TC audio samples not rendered in the previous frame */ + FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) + { + IF( ( hTcBuffer->tc_buffer_old_fx[ch_idx] = (Word32 *) malloc( n_samp_residual * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TC Buffer\n" ) ); + } + set_zero_fx( hTcBuffer->tc_buffer_old_fx[ch_idx], n_samp_residual ); + } + FOR( ; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) + { + hTcBuffer->tc_buffer_old_fx[ch_idx] = NULL; + } + } + else + { + hTcBuffer->tc_buffer_fx = NULL; + + FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) + { + hTcBuffer->tc_fx[ch_idx] = NULL; + } + + FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) + { + hTcBuffer->tc_buffer_old_fx[ch_idx] = NULL; + } + } + + hTcBuffer->tc_buffer2_fx = NULL; + + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_tc_buffer_open() + * + * Open and initialize transport channel buffer handle + *--------------------------------------------------------------------------*/ + +ivas_error ivas_dec_tc_buffer_open_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ + const Word16 nchan_transport_rend, /* i : number of TCs for rendering */ + const Word16 nchan_transport_internal, /* i : number of totally buffered channels */ + const Word16 nchan_full, /* i : number of channels to fully store */ + const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ +) +{ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + Word16 nMaxSlotsPerSubframe; + ivas_error error; + Word16 tmp, tmp_e; + + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + IF( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TC Buffer\n" ) ); + } + + hTcBuffer->tc_buffer_mode = tc_buffer_mode; + move16(); + hTcBuffer->nchan_transport_rend = nchan_transport_rend; + move16(); + hTcBuffer->nchan_transport_internal = nchan_transport_internal; + move16(); + hTcBuffer->nchan_buffer_full = nchan_full; + move16(); + hTcBuffer->n_samples_granularity = n_samples_granularity; + move16(); + hTcBuffer->n_samples_available = 0; + move16(); + hTcBuffer->n_samples_buffered = 0; + move16(); + hTcBuffer->n_samples_rendered = 0; + move16(); + hTcBuffer->slots_rendered = 0; + move16(); + hTcBuffer->subframes_rendered = 0; + move16(); + hTcBuffer->n_samples_discard = 0; + move16(); + hTcBuffer->n_samples_flushed = 0; + move16(); + hTcBuffer->nb_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + + /* nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity; */ + tmp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + tmp = BASOP_Util_Divide1616_Scale( tmp, hTcBuffer->n_samples_granularity, &tmp_e ); + nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ + + hTcBuffer->num_slots = mult0( nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + move16(); + + set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + + IF( ( error = ivas_dec_tc_audio_allocate_fx( hTcBuffer, st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->Opt_tsm ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hTcBuffer = hTcBuffer; + + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_jbm_dec_tc_audio_deallocate() + * + * deallocate TC audio buffer + *--------------------------------------------------------------------------*/ + +static void ivas_jbm_dec_tc_audio_deallocate_fx( + DECODER_TC_BUFFER_HANDLE hTcBuffer /* i/o: JBM TSM buffer handle */ +) +{ + Word16 ch_idx; + + IF( hTcBuffer != NULL ) + { + IF( hTcBuffer->tc_buffer_fx != NULL ) + { + FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) + { + hTcBuffer->tc_fx[ch_idx] = NULL; + } + + free( hTcBuffer->tc_buffer_fx ); + hTcBuffer->tc_buffer_fx = NULL; + } + + FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) + { + IF( hTcBuffer->tc_buffer_old_fx[ch_idx] != NULL ) + { + free( hTcBuffer->tc_buffer_old_fx[ch_idx] ); + hTcBuffer->tc_buffer_old_fx[ch_idx] = NULL; + } + } + + IF( hTcBuffer->tc_buffer2_fx != NULL ) + { + free( hTcBuffer->tc_buffer2_fx ); + hTcBuffer->tc_buffer2_fx = NULL; + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_tc_buffer_close() + * + * Close transport channel buffer handle + *--------------------------------------------------------------------------*/ + +void ivas_dec_tc_buffer_close_fx( + DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */ +) +{ + IF( *phTcBuffer != NULL ) + { + ivas_jbm_dec_tc_audio_deallocate_fx( *phTcBuffer ); + + free( *phTcBuffer ); + *phTcBuffer = NULL; + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_tc_buffer_reconfigure() + * + * Reconfigure transport channel buffer handle + *--------------------------------------------------------------------------*/ + +ivas_error ivas_dec_tc_buffer_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ + const Word16 nchan_transport_rend, /* i : new number of TCs for rendering */ + const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */ + const Word16 nchan_full, /* i : new number of channels to fully store */ + const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */ +) +{ + Word16 ch_idx, num_tc_buffer_mem, n_samples_still_available; + Word32 tc_buffer_mem[MAX_INTERN_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES - 1]; + ivas_error error; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + + hTcBuffer = st_ivas->hTcBuffer; + move16(); + + num_tc_buffer_mem = 0; + move16(); + n_samples_still_available = 0; + move16(); + + IF( st_ivas->hDecoderConfig->Opt_tsm ) + { + /* save samples of the TC buffer from the previous frame */ + num_tc_buffer_mem = s_min( hTcBuffer->nchan_transport_internal, nchan_transport_internal ); + n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); + + /* what is remaining from last frame needs always be smaller than the new granularity */ + assert( n_samples_still_available < n_samples_granularity ); + + FOR( ch_idx = 0; ch_idx < num_tc_buffer_mem; ch_idx++ ) + { + Copy32( hTcBuffer->tc_buffer_old_fx[ch_idx] + hTcBuffer->n_samples_flushed, tc_buffer_mem[ch_idx], n_samples_still_available ); + } + } + + /* if granularity changes, adapt subframe_nb_slots */ + IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) ) + { + Word16 nMaxSlotsPerSubframeNew; + Word16 tmp, tmp_e; + + /* nMaxSlotsPerSubframeNew = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / n_samples_granularity; */ + tmp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + tmp = BASOP_Util_Divide1616_Scale( tmp, n_samples_granularity, &tmp_e ); + nMaxSlotsPerSubframeNew = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ + + /* if samples were flushed, take that into account here */ + test(); + IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 ) + { + hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = idiv1616( hTcBuffer->n_samples_flushed, n_samples_granularity ); + hTcBuffer->n_samples_flushed = 0; + move16(); + move16(); + } + ELSE + { + hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = nMaxSlotsPerSubframeNew; + move16(); + } + } + + hTcBuffer->tc_buffer_mode = tc_buffer_mode; + move16(); + hTcBuffer->nchan_transport_rend = nchan_transport_rend; + move16(); + hTcBuffer->nchan_transport_internal = nchan_transport_internal; + move16(); + hTcBuffer->nchan_buffer_full = nchan_full; + move16(); + hTcBuffer->n_samples_granularity = n_samples_granularity; + move16(); + + /* reallocate TC audio buffers */ + + ivas_jbm_dec_tc_audio_deallocate_fx( hTcBuffer ); + + IF( ( error = ivas_dec_tc_audio_allocate_fx( hTcBuffer, st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->Opt_tsm ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* propagate samples of the TC buffer from the previous frame */ + FOR( ch_idx = 0; ch_idx < num_tc_buffer_mem; ch_idx++ ) + { + Copy32( tc_buffer_mem[ch_idx], hTcBuffer->tc_buffer_old_fx[ch_idx], n_samples_still_available ); + } + + return IVAS_ERR_OK; +} diff --git a/lib_dec/ivas_dec_render_fx.c b/lib_dec/ivas_dec_render_fx.c new file mode 100644 index 0000000000000000000000000000000000000000..93e30218b0d6b1b3ea1b1ec41b93f9d34b2e6eba --- /dev/null +++ b/lib_dec/ivas_dec_render_fx.c @@ -0,0 +1,2364 @@ +/****************************************************************************************************** + + (C) 2022-2026 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 +#include "options.h" +#include "ivas_cnst.h" +#include "prot_fx.h" +#include "ivas_prot_fx.h" +#include "ivas_prot_rend_fx.h" +#include "ivas_rom_com.h" +#include "wmc_auto.h" +#ifdef DEBUGGING +#include "debug.h" +#endif + + +/*-----------------------------------------------------------------------* + * Local function prototypes + *-----------------------------------------------------------------------*/ + +static void ivas_dec_tc_buffer_playout_fx( Decoder_Struct *st_ivas, const UWord16 nSamplesAsked, UWord16 *nSamplesRendered, Word32 *output_fx[] ); + +static void ivas_jbm_dec_copy_masa_meta_to_buffer_fx( Decoder_Struct *st_ivas ); + +static void ivas_jbm_masa_sf_to_slot_map_fx( Decoder_Struct *st_ivas, const Word16 nCldfbTs ); + +static Word16 ceil_fx16( + const Word16 inp, + const Word16 Q ) +{ + Word16 ret = shr( inp, Q ); + + IF( ( s_and( inp, sub( shl( 1, Q ), 1 ) ) ) > 0 ) + { + ret = add( ret, 1 ); + } + + return ret; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_feed_tc_to_renderer() + * + * Feed decoded transport channels to the IVAS renderer routine + * + digest TC channels in ParamISM and ParamMC + *--------------------------------------------------------------------------*/ + +void ivas_dec_feed_tc_to_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ + Word16 *nSamplesResidual /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ +) +{ + Word32 tmp_buf_fx[MAX_JBM_L_FRAME48k]; + Word32 *p_data_fx[FOA_CHANNELS + MAX_NUM_OBJECTS]; +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER + Word16 n, n_render_timeslots, n_ch_cldfb, ch; +#else + Word16 n, n_render_timeslots, n_ch_cldfb; + Word16 ch, offset, len_offset; +#endif + DECODER_TC_BUFFER_HANDLE hTcBuffer; + + hTcBuffer = st_ivas->hTcBuffer; + n_ch_cldfb = sub( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); + move16(); + + hTcBuffer->q_tc_fx = Q11; + move16(); + + IF( st_ivas->hDecoderConfig->Opt_tsm ) + { + Word16 n_samples_still_available; + Word16 n_ch_full_copy, n_ch_res_copy; + + n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); + hTcBuffer->n_samples_buffered = add( add( n_samples_still_available, nSamplesForRendering ), hTcBuffer->n_samples_discard ); + hTcBuffer->n_samples_available = i_mult( hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity ) ); + *nSamplesResidual = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available ); + move16(); + move16(); + move16(); + n_ch_full_copy = s_min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); + n_ch_res_copy = sub( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); + +#ifndef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER + /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': + in case of 'length(hTcBuffer->tc[]) < length(p_output_f[])', reset of TC buffer + pointers is needed after ivas_buffer_interleaved_to_deinterleaved() */ + len_offset = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ); + IF( LT_16( len_offset, L_FRAME48k ) ) + { + offset = 0; + move16(); + FOR( ch = 0; ch < s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); ch++ ) + { + hTcBuffer->tc_fx[ch] = &hTcBuffer->tc_buffer_fx[offset]; + st_ivas->p_output_fx[ch] = hTcBuffer->tc_fx[ch]; + offset = add( offset, len_offset ); + } + } + +#endif + FOR( ch = 0; ch < n_ch_full_copy; ch++ ) + { + Copy32( hTcBuffer->tc_fx[ch], tmp_buf_fx, nSamplesForRendering ); + set_zero_fx( hTcBuffer->tc_fx[ch], hTcBuffer->n_samples_discard ); + Copy32( hTcBuffer->tc_buffer_old_fx[ch], hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available ); + Copy32( tmp_buf_fx, hTcBuffer->tc_fx[ch] + n_samples_still_available + hTcBuffer->n_samples_discard, nSamplesForRendering - *nSamplesResidual ); + Copy32( tmp_buf_fx + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old_fx[ch], *nSamplesResidual ); + } + + IF( n_ch_res_copy > 0 ) + { + FOR( ; ch < hTcBuffer->nchan_transport_rend; ch++ ) + { + p_data_fx[ch] = hTcBuffer->tc_fx[ch]; + Copy32( hTcBuffer->tc_fx[ch], tmp_buf_fx, nSamplesForRendering ); + Copy32( hTcBuffer->tc_buffer_old_fx[ch], p_data_fx[ch], n_samples_still_available ); + Copy32( tmp_buf_fx, p_data_fx[ch] + n_samples_still_available, sub( nSamplesForRendering, *nSamplesResidual ) ); + Copy32( tmp_buf_fx + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old_fx[ch], *nSamplesResidual ); + } + } + + n_render_timeslots = idiv1616( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity ); + } + ELSE + { + FOR( n = 0; n < n_ch_cldfb; n++ ) + { + p_data_fx[n] = &st_ivas->p_output_fx[n][0]; + move16(); + } + + ch = s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); + FOR( n = 0; n < ch; n++ ) + { + hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; /* note: buffers needed in the TD decorellator */ + move16(); + } + + hTcBuffer->n_samples_buffered = nSamplesForRendering; + hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered; + *nSamplesResidual = 0; + move16(); + move16(); + move16(); + + n_render_timeslots = DEFAULT_JBM_CLDFB_TIMESLOTS; + move16(); + } + + /* CLDFB analysis for ParamMC/ParamISM */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) ) + { + ivas_param_ism_dec_digest_tc_fx( st_ivas, n_render_timeslots, p_data_fx, Q11 ); + } + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) && EQ_32( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_RENDERER ) ) + { + ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, p_data_fx, Q11 ); + } + + hTcBuffer->n_samples_rendered = 0; + move16(); + hTcBuffer->subframes_rendered = 0; + move16(); + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_render() + * + * Principal IVAS internal rendering routine + *--------------------------------------------------------------------------*/ + +ivas_error ivas_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of samples wanted */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ + Word16 *data /* o : output synthesis signal Q0*/ +) +{ + Word16 n, nchan_out; + Word16 nchan_transport_rend; + Word16 nchan_remapped; + Word32 output_Fs; + AUDIO_CONFIG output_config; + Word16 nSamplesAskedLocal; + ivas_error error; + Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; + Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS]; + Word16 subframe_len, gd_bits, exp, nchan_in, i, j, ch; + const Word16 output_q_factor = Q11; + move16(); + Word16 nchan_out_syn_output; + + push_wmops( "ivas_dec_render" ); + /*----------------------------------------------------------------* + * Initialization of local vars after struct has been set + *----------------------------------------------------------------*/ + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); + nchan_out = st_ivas->hDecoderConfig->nchan_out; + move16(); + nchan_transport_rend = st_ivas->hTcBuffer->nchan_transport_rend; + move16(); + output_config = st_ivas->hDecoderConfig->output_config; + move32(); + nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard ); + move16(); + + FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + { + p_output_fx[n] = st_ivas->p_output_fx[n]; + } + + IF( !st_ivas->hDecoderConfig->Opt_tsm ) + { + FOR( n = 0; n < MAX_INTERN_CHANNELS; n++ ) + { + st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; + } + } + + FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) + { + p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered]; + } + + /*----------------------------------------------------------------* + * Update combined orientation access index + *----------------------------------------------------------------*/ + + IF( st_ivas->hCombinedOrientationData != NULL ) + { + /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */ + st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard ); + move16(); + + ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); + } + + /*----------------------------------------------------------------* + * Rendering + *----------------------------------------------------------------*/ + + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + move16(); + + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) + { + assert( 0 ); + } + ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) + { + ivas_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) || EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + { + /* Rendering */ + IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) + { + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) + { + ivas_apply_non_diegetic_panning_fx( p_tc_fx[0], p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + ivas_stereo2sba_fx( p_tc_fx, p_output_fx, *nSamplesRendered ); + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* Rendering */ + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); + + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + /* Convert CICP19 -> Ambisonics */ + ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); + } + } + } + ELSE /* ISM_MODE_DISC */ + { + test(); + test(); + /* Loudspeaker or Ambisonics rendering */ + IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ + ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_fx, *nSamplesRendered ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) + { + ivas_apply_non_diegetic_panning_fx( p_tc_fx[0], p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered ); + } +#ifdef DEBUGGING + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) +#else + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) +#endif + { + /* Convert to Ambisonics */ + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) + { + FOR( j = 0; j < HOA3_CHANNELS; j++ ) + { + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + move32(); + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 + move32(); + } + } + + ivas_ism2sba_sf_fx( p_tc_fx, p_output_fx, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order ); + + Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) ); + FOR( j = 0; j < sba_num_chans; j++ ) + { + scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11 + } + + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) + { + FOR( j = 0; j < 16; j++ ) + { + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 + move32(); + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30 + move32(); + } + } + } + + /* Binaural rendering */ + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) + { + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + IF( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); + gd_bits = find_guarded_bits_fx( subframe_len ); + exp = 13; + move16(); + nchan_in = 12; + move16(); + nchan_out = 2; + move16(); + exp = sub( exp, gd_bits ); + *st_ivas->hCrendWrapper->p_io_qfactor = exp; + move16(); + FOR( i = 0; i < nchan_in; i++ ) + { + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 + } + + IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + FOR( i = 0; i < nchan_out; i++ ) + { + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 + } + } + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) + { + nchan_remapped = nchan_transport_rend; + move16(); + + test(); + test(); + /* Loudspeakers, Ambisonics or Binaural rendering */ + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) + { + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) + { + ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); + } + } + ELSE + { + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + { + nchan_remapped = st_ivas->nchan_transport; + move16(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) + { + IF( NE_32( ( error = ivas_omasa_dirac_td_binaural_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) + { + ivas_omasa_dirac_rend_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) + { + ivas_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); + ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, *nSamplesRendered ); + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + nchan_remapped = nchan_transport_rend; + move16(); + + /* Loudspeakers, Ambisonics or Binaural rendering */ + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) + { + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + hSpar->hMdDec->Q_mixer_mat = 30; + move16(); + + IF( NE_32( ( error = ivas_osba_dirac_td_binaural_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ) + { + test(); + /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/ + IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) ) + { + Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered ); + Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered ); + p_tc_fx[1] = p_output_fx[2]; + p_tc_fx[2] = p_output_fx[3]; + } + + /* render objects */ + ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_fx, *nSamplesRendered ); + + /* add already rendered SBA part */ + ivas_osba_stereo_add_channels_fx( p_tc_fx, p_output_fx, st_ivas->hSbaIsmData->gain_bed_fx, nchan_out, st_ivas->nchan_ism, st_ivas->ism_mode, *nSamplesRendered ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/ + { + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism] ) ), IVAS_ERR_OK ) ) + { + return error; + } + + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) + { + Copy32( p_tc_fx[n], p_output_fx[n], *nSamplesRendered ); + } + } + ELSE + { + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + + FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) + { + scale_sig32( p_output_fx[n], *nSamplesRendered, 1 ); + } + } + ELSE + { + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + { + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) + { + Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered ); + } + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) + { + set32_fx( p_output_fx[n], 0, *nSamplesRendered ); + } + } + FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) + { + scale_sig32( p_output_fx[n], *nSamplesRendered, 1 ); + } + } + } + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) + { + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + Word16 crendInPlaceRotation = FALSE; + move16(); + + test(); + test(); + test(); + IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + IF( LT_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) + { + crendInPlaceRotation = TRUE; + move16(); + + ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); + } + } + + /* Rendering */ + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); + gd_bits = find_guarded_bits_fx( subframe_len ); + exp = 13; + move16(); + IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ), IVAS_ERR_OK ) ) + { + return error; + } + IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) ) + { + return error; + } + exp = sub( exp, gd_bits ); + *st_ivas->hCrendWrapper->p_io_qfactor = exp; + move16(); + + IF( crendInPlaceRotation ) + { + FOR( i = 0; i < nchan_in; i++ ) + { + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor + } + } + ELSE + { + FOR( i = 0; i < nchan_in; i++ ) + { + scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor + } + } + + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + IF( ( error = ivas_rend_crendProcessSubframesSplitBin( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } + + ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); + } + + IF( crendInPlaceRotation ) + { + n = nchan_in; + } + ELSE + { + n = nchan_out; + } + move16(); + + FOR( i = 0; i < n; i++ ) + { + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 + } + + FOR( i = n; i < nchan_in; i++ ) + { + scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) + { + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) + { + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + else + { + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) + { + return error; + } + + ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); + } + } + } + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + ivas_mc_paramupmix_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx ); + + /* Rendering */ + test(); + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && !st_ivas->hDecoderConfig->Opt_Headrotation ) + { + /* handled in CLDFB domain already */ + IF( NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); + } + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) + { + ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); + } + } + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + Word16 channel_active_fx[MAX_OUTPUT_CHANNELS]; + Word16 nchan_out_cov; + Word16 nchan_out_cldfb = 0; + move16(); + + set16_fx( channel_active_fx, 0, MAX_LS_CHANNELS ); + Word16 nchan_transport_tmp = st_ivas->nchan_transport; + move16(); + output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); + Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + nchan_out_cldfb = BINAURAL_CHANNELS; + move16(); + set16_fx( channel_active_fx, 1, BINAURAL_CHANNELS ); + nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + } + ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) + { + nchan_out_cov = nchan_out_transport; + move16(); + nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + } + ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + { + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + nchan_out_cldfb = nchan_out_cov; + move16(); + set16_fx( channel_active_fx, 1, nchan_out_cov ); + } + ELSE + { + nchan_out_cov = nchan_out_transport; + move16(); + nchan_out_cldfb = nchan_out_transport; + move16(); + set16_fx( channel_active_fx, 1, nchan_out_cov ); + } + IF( st_ivas->hParamMC->max_band_decorr > 0 ) + { + Word16 tmp; + tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); + scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); // Q(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer+ tmp) + st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); + move16(); + } + /* CLDFB synthesis */ + FOR( ch = 0; ch < nchan_out_cldfb; ch++ ) + { + IF( st_ivas->cldfbSynDec[ch] ) + { + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5 + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; + move16(); + } + } + Word16 tempp; + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) + { + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) + st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); + move16(); + + IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) + { + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) + st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp ); + move16(); + } + } + + ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); + + FOR( ch = 0; ch < nchan_out_cldfb; ch++ ) + { + IF( st_ivas->cldfbSynDec[ch] ) + { + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11 + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); + } + } + IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) ) + { + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) + { + IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) + { + Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) ); + st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx]; + move16(); + } + Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) ); + st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]; + move16(); + } + } + } + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + nchan_remapped = st_ivas->nchan_transport; + move16(); + + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + } + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) /* rendering to CICPxx and Ambisonics */ + { + ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); + + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + /* we still need to copy the separate channel if available */ + IF( st_ivas->hOutSetup.separateChannelEnabled ) + { + Copy32( p_tc_fx[LFE_CHANNEL - 1], p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); + } + + ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); + } + ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) ) + { + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); n++ ) + { + set32_fx( p_output_fx[n], 0, *nSamplesRendered ); + } + } + } + + /* copy discrete C and TD LFE from internal TC to output */ + IF( st_ivas->hOutSetup.separateChannelEnabled ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) + { + Copy32( p_tc_fx[LFE_CHANNEL], p_output_fx[LFE_CHANNEL], *nSamplesRendered ); + Copy32( p_tc_fx[LFE_CHANNEL - 1], p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); + } + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 ) + { + Copy32( p_tc_fx[LFE_CHANNEL - 1], p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); + } + } + } + } + + /*----------------------------------------------------------------* + * Write IVAS output channels + * - compensation for saturation + * - float to integer conversion + *----------------------------------------------------------------*/ + + st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered ); + st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered ); + move16(); + move16(); + + /* update global combined orientation start index */ + ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); + + IF( st_ivas->hTcBuffer->n_samples_discard > 0 ) + { + FOR( n = 0; n < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ ) + { + p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard; + } + *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard ); + move16(); + st_ivas->hTcBuffer->n_samples_discard = 0; + move16(); + } + + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + const Word32 *p_output_fx_const[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; + + nchan_out_syn_output = i_mult( BINAURAL_CHANNELS, st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ); + + /* Save TD signals for pose correction if they are to be used. + * + * NOTE: Here BASOP differs from the float version. In float, we push samples to TD ring buffer in lib_dec.c function isar_render_poses. */ + IF( st_ivas->hSplitBinRend->hMultiBinTdData != NULL ) + { + FOR( i = 0; i < nchan_out_syn_output; i++ ) + { + p_output_fx_const[i] = p_output_fx[i]; + } + ivas_TD_RINGBUF_PushChannels( st_ivas->hSplitBinRend->hMultiBinTdData, p_output_fx_const, *nSamplesRendered ); + } + +#ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR + if ( st_ivas->flushing ) + { + nchan_out_syn_output = BINAURAL_CHANNELS; + move16(); + } +#endif + } + ELSE + { + nchan_out_syn_output = nchan_out; + move16(); + } + + IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 ) + { + IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) ) + { +#ifndef DISABLE_LIMITER + ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor ); +#endif + } + } + + ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out_syn_output, data ); + + *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; + move16(); + + pop_wmops(); + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_jbm_dec_flush_renderer() + * + * Flush samples if renderer granularity changes on a bitrate change in JBM + *--------------------------------------------------------------------------*/ + +ivas_error ivas_jbm_dec_flush_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 tc_granularity_new, /* i : new renderer granularity */ + const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ + const AUDIO_CONFIG intern_config_old, /* i : old internal config */ + const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ + const MC_MODE mc_mode_old, /* i : old MC mode */ + const ISM_MODE ism_mode_old, /* i : old ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal Q0*/ +) +{ + ivas_error error; + Word16 n_samples_still_available; + Word16 n_slots_still_available; + Word16 n_samples_to_render; + Word16 n_samples_granularity; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + Word32 *p_output_fx[MAX_LS_CHANNELS + MAX_NUM_OBJECTS]; + Word16 nchan_in, nchan_out; + Word16 ch_idx; + + + IF( !st_ivas->hDecoderConfig->Opt_tsm ) + { + return IVAS_ERR_OK; + } + + FOR( ch_idx = 0; ch_idx < ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); ch_idx++ ) + { + p_output_fx[ch_idx] = st_ivas->p_output_fx[ch_idx]; + } + + *nSamplesRendered = 0; + move16(); + hTcBuffer = st_ivas->hTcBuffer; + n_samples_granularity = hTcBuffer->n_samples_granularity; + move16(); + + /* get number of possible slots in new granularity */ + n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); + + // n_slots_still_available = n_samples_still_available / tc_granularity_new; + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e ); + n_slots_still_available = shr( tmp, sub( 15, tmp_e ) ); + *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new ); + n_samples_to_render = *nSamplesRendered; + move16(); + move16(); + n_samples_still_available = sub( n_samples_still_available, n_samples_to_render ); + assert( n_samples_still_available < tc_granularity_new ); + + /* update combined orientation access index */ + ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); + + IF( n_slots_still_available ) + { + + /* render available full slots (with new lower granularity) */ + FOR( ch_idx = 0; ch_idx < s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); ch_idx++ ) + { + /* move it at the beginning of the TC buffer with zero padding */ + Copy32( hTcBuffer->tc_buffer_old_fx[ch_idx], hTcBuffer->tc_fx[ch_idx], n_samples_to_render ); + set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, sub( hTcBuffer->n_samples_granularity, n_samples_to_render ) ); + } + + /* simple change of the slot info */ + hTcBuffer->num_slots = 1; + hTcBuffer->nb_subframes = 1; + hTcBuffer->subframes_rendered = 0; + hTcBuffer->slots_rendered = 0; + hTcBuffer->subframe_nbslots[0] = 1; + hTcBuffer->n_samples_buffered = add( n_samples_granularity, n_samples_still_available ); + hTcBuffer->n_samples_available = 0; + hTcBuffer->n_samples_flushed = n_samples_to_render; + hTcBuffer->n_samples_rendered = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + + test(); + IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) + { + IF( EQ_16( ism_mode_old, ISM_MODE_DISC ) ) + { + /* Binaural rendering */ + IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) ) + { + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, n_samples_granularity ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ + set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, n_samples_granularity ); // 32767=1.0f in Q15 + + ivas_ism_render_sf_fx( st_ivas, renderer_type_old, p_output_fx, n_samples_granularity ); + + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + *st_ivas->hCrendWrapper->p_io_qfactor = 11; + + move16(); + IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, + NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) + { + IF( EQ_16( mc_mode_old, MC_MODE_MCT ) ) + { + Word16 crendInPlaceRotation = FALSE; + + test(); + test(); + test(); + IF( NE_16( st_ivas->transport_config, intern_config_old ) && ( EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + IF( GT_16( sub( add( hIntSetupOld->nchan_out_woLFE, hIntSetupOld->num_lfe ), add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), 0 ) ) + { + crendInPlaceRotation = TRUE; + move16(); + ivas_mc2sba_fx( st_ivas->hTransSetup, hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, hIntSetupOld->ambisonics_order, GAIN_LFE_FX ); + } + } + + test(); + IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { + st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; + IF( NE_32( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) ) + { + return error; + } + + Word16 subframe_len, gd_bits; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], n_samples_granularity ); + gd_bits = find_guarded_bits_fx( subframe_len ); + *st_ivas->hCrendWrapper->p_io_qfactor = sub( 13, gd_bits ); + FOR( Word16 i = 0; i < nchan_in; i++ ) + { + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( *st_ivas->hCrendWrapper->p_io_qfactor, Q11 ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor + } + + IF( NE_32( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : st_ivas->hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ), IVAS_ERR_OK ) ) + { + return error; + } + + ivas_binaural_add_LFE_fx( st_ivas, n_samples_granularity, hTcBuffer->tc_fx, p_output_fx ); + + FOR( Word16 i = 0; i < nchan_in; i++ ) + { + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 + } + } + ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) ) + { + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, n_samples_granularity ) ), IVAS_ERR_OK ) ) + { + return error; + } + + ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, hTcBuffer->tc_fx, p_output_fx ); + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong renderer in MCT VoIP renderer flushing!" ); + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + { + IF( EQ_16( ism_mode_old, ISM_MASA_MODE_DISC ) ) + { + Word32 *tc_local_fx[MAX_NUM_OBJECTS]; + Word16 last_dirac_md_idx; + UWord16 nSamplesAvailableNext; + ISM_MODE ism_mode_orig; + RENDERER_TYPE renderer_type_orig; + Word32 ivas_total_brate; + + /* copy from ISM delay buffer to the correct place in TCs */ + move16(); + FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) + { + tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered]; + Copy32( st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size ); /*Q11*/ + } + + /* to render flushed samples, use configuration from the last received frame */ + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + renderer_type_orig = st_ivas->renderer_type; + ism_mode_orig = st_ivas->ism_mode; + st_ivas->ism_mode = ism_mode_old; + st_ivas->renderer_type = renderer_type_old; + st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; + + /* transfer adapted sf info from hTcBuffer to DirAC */ + st_ivas->hSpatParamRendCom->nb_subframes = 1; + st_ivas->hSpatParamRendCom->subframes_rendered = 0; + st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpatParamRendCom->slots_rendered = 0; + st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; + set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available ); + + IF( ( error = ivas_omasa_dirac_td_binaural_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, CPE_CHANNELS, p_output_fx ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* restore original configuration */ + st_ivas->ism_mode = ism_mode_orig; + st_ivas->renderer_type = renderer_type_orig; + st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + IF( EQ_32( ism_mode_old, ISM_SBA_MODE_DISC ) ) + { + Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; + Word16 last_spar_md_idx; + Word16 last_dirac_md_idx; + UWord16 nSamplesAvailableNext; + ISM_MODE ism_mode_orig; + RENDERER_TYPE renderer_type_orig; + Word32 ivas_total_brate; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + renderer_type_orig = st_ivas->renderer_type; + ism_mode_orig = st_ivas->ism_mode; + + /* to render flushed samples, use configuration from the last received frame */ + move32(); + st_ivas->ism_mode = ism_mode_old; + st_ivas->renderer_type = renderer_type_old; + st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + + last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1]; + last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; + move16(); + move16(); + + /* copy from ISM delay buffer to the correct place in TCs */ + FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) + { + tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx][hTcBuffer->n_samples_rendered]; + Copy32( st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size ); + } + + /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */ + st_ivas->hSpar->nb_subframes = 1; + st_ivas->hSpar->subframes_rendered = 0; + st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpar->slots_rendered = 0; + st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpatParamRendCom->nb_subframes = 1; + st_ivas->hSpatParamRendCom->subframes_rendered = 0; + st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; + st_ivas->hSpatParamRendCom->slots_rendered = 0; + st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + /* also adapt md maps, just use the last index */ + set16_fx( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available ); + set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available ); + + /* render the last subframe */ + IF( NE_32( ( error = ivas_osba_dirac_td_binaural_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* restore original configuration */ + st_ivas->ism_mode = ism_mode_orig; + st_ivas->renderer_type = renderer_type_orig; + st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" ); + } + + hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity; + } + + /* update global combined orientation start index */ + ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); + + *nSamplesRendered = n_samples_to_render; + move16(); + + /* Only write out the valid data*/ + IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 ) + { + IF( NE_16( st_ivas->ivas_format, MONO_FORMAT ) ) + { +#ifndef DISABLE_LIMITER + Word16 exp = 11; + move16(); + FOR( ch_idx = 0; ch_idx < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) + { + p_output_fx[ch_idx] = st_ivas->p_output_fx[ch_idx]; + } + ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp ); +#endif + } + } + + ivas_syn_output_fx( p_output_fx, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, data ); + + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_jbm_dec_set_discard_samples() + * + * Set number of samples to discard in the first subframe + * if the renderer granularity changes on a bitrate change in JBM processing + *--------------------------------------------------------------------------*/ + +ivas_error ivas_jbm_dec_set_discard_samples_fx( + Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ +) +{ + Word16 nMaxSlotsPerSubframe, nSlotsInFirstSubframe; + Word16 temp, temp_e; + + /* render first frame with front zero padding and discarding those samples */ + /* nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity; */ + temp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + temp = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e ); + nMaxSlotsPerSubframe = shr( temp, sub( 15, temp_e ) ); /* Q0 */ + nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); + + IF( nSlotsInFirstSubframe > 0 ) + { + st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity ); + /* set last subframes number to max to ensure correct continuation */ + st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe; + move16(); + move16(); + } + + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_adapted_linear_interpolator() + * + * Get an interpolator that is adapted to (time scale modified) IVAS frame + *--------------------------------------------------------------------------*/ + +void ivas_dec_get_adapted_linear_interpolator_fx( + const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ + const Word16 interp_length, /* i : length of the interpolator to be created */ + Word16 *interpolator_fx /* o : the interpolator Q15 */ +) +{ + Word16 segment_len, idx; + Word16 dec_fx; + Word16 dec_e; + + segment_len = shr( default_interp_length, 1 ); + dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/ + + interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */ + move16(); + interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision + move16(); + FOR( idx = interp_length - 3; idx >= segment_len; idx-- ) + { + interpolator_fx[idx] = s_max( 0, sub( interpolator_fx[idx + 1], dec_fx ) ); + move16(); + } + + IF( interpolator_fx[idx + 1] > 0 ) + { + dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( segment_len, 1 ), &dec_e ); + dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0 + FOR( ; idx >= 0; idx-- ) + { + interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx ); + move16(); + } + } + ELSE + { + set16_fx( interpolator_fx, 0, add( idx, 1 ) ); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_adapted_subframes() + * + * Get an interpolator that is adapted to (time scale modified) IVAS frame + *--------------------------------------------------------------------------*/ + +void ivas_dec_get_adapted_subframes_fx( + const Word16 nCldfbTs, /* i : number of time slots in the current frame */ + Word16 *subframe_nbslots, /* i/o: subframe grid */ + Word16 *nb_subframes /* i/o: number of subframes in the frame */ +) +{ + UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe; + UWord16 nCldfbSlotsLocal = nCldfbTs; + move16(); + Word16 temp, temp_e; + + /* get last subframe size from previous frame, determine how many slots have to be processed + in the first subframe (i.e. potential leftover of a 5ms subframe) */ + nSlotsInFirstSubframe = ( sub( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, subframe_nbslots[*nb_subframes - 1] ) ); + *nb_subframes = 0; + move16(); + IF( nSlotsInFirstSubframe > 0 ) + { + *nb_subframes = 1; + move16(); + nCldfbSlotsLocal = sub( nCldfbSlotsLocal, nSlotsInFirstSubframe ); + } + + temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e ); + *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0 + move16(); + nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME; + move16(); + + set16_fx( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes ); + + IF( nSlotsInFirstSubframe > 0 ) + { + subframe_nbslots[0] = nSlotsInFirstSubframe; + move16(); + } + + IF( nSlotsInLastSubframe > 0 ) + { + subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe; + move16(); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_md_map() + * + * Get an meta data map adapted to a time scale modified IVAS frame + *--------------------------------------------------------------------------*/ + +void ivas_dec_get_md_map_fx( + const Word16 default_len, /* i : default frame length in metadata slots */ + const Word16 len, /* i : length of the modified frames in metadata slots*/ + const Word16 subframe_len, /* i : default length of a subframe */ + const Word16 offset, /* i : current read offset into the MD buffer */ + const Word16 buf_len, /* i : length of the metadata buffer */ + Word16 *map /* o : metadata index map */ +) +{ + Word16 jbm_segment_len, map_idx, src_idx, src_idx_map; + Word32 dec_fx, src_idx_fx; + Word16 temp_e; + Word16 temp; + jbm_segment_len = shr( default_len, 1 ); + + FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) + { + temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 + src_idx_map = s_max( 0, temp ); + map[map_idx] = add( offset, src_idx_map ) % buf_len; + move16(); + } + + /* changed part (first segment), interpolate index to parameters + (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */ + IF( src_idx >= 0 ) + { + dec_fx = BASOP_Util_Divide3232_Scale( L_shl( add( src_idx, 1 ), 16 ), jbm_segment_len, &temp_e ); + dec_fx = L_shr( dec_fx, sub( 15, temp_e ) ); + src_idx_fx = L_sub( L_shl( add( src_idx, 1 ), 16 ), dec_fx ); + FOR( ; map_idx >= 0; map_idx-- ) + { + temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 + src_idx = s_max( 0, temp ); + map[map_idx] = add( offset, src_idx ) % buf_len; + src_idx_fx = L_sub( src_idx_fx, dec_fx ); + } + } + ELSE + { + set16_fx( map, offset, add( map_idx, 1 ) ); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_md_map_even_spacing() + * + * Get an meta data map adapted to (time scale modified) IVAS frame. + * Distribute slots evenly across the (modified) frame. + *--------------------------------------------------------------------------*/ + +void ivas_dec_get_md_map_even_spacing_fx( + const Word16 len, /* i : length of the modified frames in metadata slots*/ + const Word16 subframe_len, /* i : default length of a subframe */ + const Word16 offset, /* i : current read offset into the MD buffer */ + const Word16 buf_len, /* i : length of the metadata buffer */ + Word16 *map /* o : metadata index map */ +) +{ + Word16 map_idx, sf_idx, sf_length, increment, subframes_written; + Word32 decimal_fx, decimal_sum_fx, eps_fx; // q = 16 + Word16 subframe_map_length[MAX_PARAM_SPATIAL_SUBFRAMES]; + + /* subframe map length */ + sf_length = idiv1616( len, subframe_len ); + IF( len % subframe_len == 0 ) + { + /* even subframes */ + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + subframe_map_length[sf_idx] = sf_length; + move16(); + } + } + ELSE + { + /* uneven subframes */ + Word32 temp; + Word16 temp_e; + temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e ); + temp = L_shr( temp, sub( 15, temp_e ) ); // Q16 + decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16 + decimal_sum_fx = decimal_fx; + + eps_fx = 65; + move32(); + move32(); + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + increment = extract_l( L_shr( L_add( decimal_sum_fx, eps_fx ), 16 ) ); + subframe_map_length[sf_idx] = add( sf_length, increment ); + move16(); + IF( increment > 0 ) + { + decimal_sum_fx = L_sub( decimal_sum_fx, ONE_IN_Q16 ); + } + decimal_sum_fx = L_add( decimal_sum_fx, decimal_fx ); + } + } + + /* map slots to subframes */ + sf_idx = 0; + subframes_written = 0; + move16(); + move16(); + FOR( map_idx = 0; map_idx < len; map_idx++ ) + { + map[map_idx] = add( offset, sf_idx ) % buf_len; + move16(); + IF( GE_16( sub( map_idx, subframes_written ), sub( subframe_map_length[sf_idx], 1 ) ) ) + { + subframes_written = add( subframes_written, subframe_map_length[sf_idx] ); + sf_idx = add( sf_idx, 1 ); + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_get_render_granularity() + * + * Get renderer granularity + *--------------------------------------------------------------------------*/ + +/*! r: render granularity */ +Word16 ivas_dec_get_render_granularity_fx( + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const RENDERER_TYPE renderer_type_sec, /* i : secondary renderer type */ + const Word32 output_Fs /* i : sampling rate */ +) +{ + Word16 render_granularity; + + test(); + test(); + test(); + IF( EQ_32( renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || /* TD renderer */ + EQ_32( renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) || /* Crend */ + EQ_32( renderer_type_sec, RENDERER_BINAURAL_OBJECTS_TD ) /* TD rend as a secondary renderer -> set the common granularity for both renderers */ + ) + { + /* 5 ms granularity */ + render_granularity = NS2SA_FX2( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); + move16(); + } + ELSE + { + /* 1.25 ms granularity */ + render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ); + move16(); + } + + return render_granularity; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_tc_buffer_playout() + * + * Get TC buffer playout + *--------------------------------------------------------------------------*/ + +static void ivas_dec_tc_buffer_playout_fx( + Decoder_Struct *st_ivas, + const UWord16 nSamplesAsked, + UWord16 *nSamplesRendered, + Word32 *output_fx[] /*Q11*/ +) +{ + Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + + hTcBuffer = st_ivas->hTcBuffer; + slot_size = hTcBuffer->n_samples_granularity; + move16(); + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); + tmp = shr( tmp, sub( 15, e ) ); // Q0 + slots_to_render = s_min( sub( hTcBuffer->num_slots, hTcBuffer->slots_rendered ), tmp ); + hTcBuffer->slots_rendered = add( hTcBuffer->slots_rendered, slots_to_render ); // Q0 + *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size ); + first_sf = hTcBuffer->subframes_rendered; + last_sf = first_sf; + move16(); + move16(); + move16(); + move16(); + + WHILE( slots_to_render > 0 ) + { + slots_to_render = sub( slots_to_render, hTcBuffer->subframe_nbslots[last_sf] ); + last_sf = add( last_sf, 1 ); + } +#ifdef DEBUGGING + assert( slots_to_render == 0 ); +#endif + + FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_transport_rend; ch_idx++ ) + { + output_fx[ch_idx] = hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered; + move32(); + } + + hTcBuffer->subframes_rendered = last_sf; + move16(); + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_td_renderers_adapt_subframes() + * + * Adapt subframes for TD renderers + *--------------------------------------------------------------------------*/ + +void ivas_dec_td_renderers_adapt_subframes_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, tmp_e, tmp1, tmp2, s1, s2; + UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + + hTcBuffer = st_ivas->hTcBuffer; + + /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / hTcBuffer->n_samples_granularity; */ + tmp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + tmp = BASOP_Util_Divide1616_Scale( tmp, hTcBuffer->n_samples_granularity, &tmp_e ); + nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ + + /* nSlotsAvailable = hTcBuffer->n_samples_available / hTcBuffer->n_samples_granularity; */ + tmp = BASOP_Util_Divide1616_Scale( hTcBuffer->n_samples_available, hTcBuffer->n_samples_granularity, &tmp_e ); + nSlotsAvailable = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ + + hTcBuffer->num_slots = nSlotsAvailable; + move16(); + /* hTcBuffer->n_samples_available = nSlotsAvailable * hTcBuffer->n_samples_granularity; */ + hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, hTcBuffer->n_samples_granularity ); + move16(); + nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, hTcBuffer->subframe_nbslots[hTcBuffer->nb_subframes - 1] ); + hTcBuffer->nb_subframes = 0; + move16(); + + IF( nSlotsInFirstSubframe > 0 ) + { + hTcBuffer->nb_subframes = 1; + move16(); + nSlotsAvailable = sub( nSlotsAvailable, nSlotsInFirstSubframe ); + } + + s1 = sub( norm_s( nSlotsAvailable ), 1 ); + s2 = norm_s( nMaxSlotsPerSubframe ); + + tmp1 = shl( nSlotsAvailable, s1 ); + tmp2 = shl( nMaxSlotsPerSubframe, s2 ); + + tmp = div_s( tmp1, tmp2 ); + hTcBuffer->nb_subframes = add( hTcBuffer->nb_subframes, ceil_fx16( tmp, sub( 15, sub( s2, s1 ) ) ) ); + move16(); + + nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe; + move16(); + set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, hTcBuffer->nb_subframes ); + + if ( nSlotsInFirstSubframe > 0 ) + { + hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe; + move16(); + } + + if ( nSlotsInLastSubframe > 0 ) + { + hTcBuffer->subframe_nbslots[hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe; + move16(); + } + + hTcBuffer->slots_rendered = 0; + move16(); + hTcBuffer->subframes_rendered = 0; + move16(); + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_jbm_dec_masa_metadata_open() + * + * Open structure for MASA metadata buffering in JBM processing + *--------------------------------------------------------------------------*/ + +ivas_error ivas_jbm_dec_masa_metadata_open_fx( + Decoder_Struct *st_ivas ) +{ + JBM_METADATA_HANDLE hJbmMetadata; + + IF( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) ); + } + + hJbmMetadata->sf_write_idx = 0; + move16(); + hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + + hJbmMetadata->slot_write_idx = 0; + move16(); + hJbmMetadata->slot_read_idx = 0; + move16(); + hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16(); + + st_ivas->hJbmMetadata = hJbmMetadata; + + return IVAS_ERR_OK; +} + + +/*--------------------------------------------------------------------------* + * ivas_jbm_dec_copy_masa_meta_to_buffer() + * + * Copy decoded MASA metadata to a ring buffer in JBM processing + *--------------------------------------------------------------------------*/ + +static void ivas_jbm_dec_copy_masa_meta_to_buffer_fx( + Decoder_Struct *st_ivas ) +{ + Word16 sf, dir, band; + JBM_METADATA_HANDLE hJbmMetadata; + MASA_DECODER_EXT_OUT_META *extOutMeta; + Word16 write_idx; + + hJbmMetadata = st_ivas->hJbmMetadata; + extOutMeta = st_ivas->hMasa->data.extOutMeta; + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length; + move16(); + FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band]; + move16(); + hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band]; + move16(); + hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band]; + move16(); + } + } + + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band]; + move16(); + hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band]; + move16(); + } + + hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections; + move16(); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_jbm_masa_sf_to_slot_map() + * + * Map input MASA metadata subframes to slots in JBM processing + *--------------------------------------------------------------------------*/ + +static void ivas_jbm_masa_sf_to_slot_map_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +) +{ + Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; + Word16 num_slots_in_subfr; + JBM_METADATA_HANDLE hJbmMetadata; + Word16 slot_idx; + Word16 write_idx, sf_index; + + ivas_jbm_dec_copy_masa_meta_to_buffer_fx( st_ivas ); + + /* Set values */ + hJbmMetadata = st_ivas->hJbmMetadata; + num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + + /* Map input subframes to slots */ + ivas_dec_get_md_map_even_spacing_fx( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map ); + + FOR( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ ) + { + write_idx = ( add( hJbmMetadata->slot_write_idx, slot_idx ) ) % hJbmMetadata->slot_md_buffer_length; + move16(); + sf_index = ( add( hJbmMetadata->sf_write_idx, sf_to_slot_map[slot_idx] ) ) % hJbmMetadata->sf_md_buffer_length; + move16(); + + hJbmMetadata->sf_to_slot_map[write_idx] = sf_index; + move16(); + } + + hJbmMetadata->sf_write_idx = ( add( hJbmMetadata->sf_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) ) % hJbmMetadata->sf_md_buffer_length; + move16(); + hJbmMetadata->slot_write_idx = ( add( hJbmMetadata->slot_write_idx, nCldfbTs ) ) % hJbmMetadata->slot_md_buffer_length; + move16(); + + return; +} + +/*--------------------------------------------------------------------------* + * ivas_jbm_masa_sf_to_sf_map() + * + * Map input MASA metadata subframes to output subframes in JBM processing + *--------------------------------------------------------------------------*/ + +void ivas_jbm_masa_sf_to_sf_map_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES]; + JBM_METADATA_HANDLE hJbmMetadata; + MASA_DECODER_EXT_OUT_META *extOutMeta; + Word16 slot_read_idx, sf_read_idx; + Word16 sf_idx; + Word16 dir, band; + UWord8 numberOfDirections; + + /* Set values */ + hJbmMetadata = st_ivas->hJbmMetadata; + extOutMeta = st_ivas->hMasa->data.extOutMeta; + + /* Map slots to subframes */ + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + slot_read_idx = ( add( hJbmMetadata->slot_read_idx, 2 ) ) % hJbmMetadata->slot_md_buffer_length; /* Take the latter one of the middle slots of the output subframe */ + move16(); + sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx]; + move16(); + hJbmMetadata->slot_read_idx = ( add( hJbmMetadata->slot_read_idx, CLDFB_SLOTS_PER_SUBFRAME ) ) % hJbmMetadata->slot_md_buffer_length; + move16(); + } + + /* Copy mapped metadata to the EXT meta buffer for writing */ + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + sf_read_idx = sf_to_sf_map[sf_idx]; + move16(); + + FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) + { + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band]; + move16(); + extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band]; + move16(); + extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band]; + move16(); + } + } + + FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) + { + extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band]; + move16(); + extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band]; + move16(); + } + } + + /* Determine the number of directions for the frame to be written */ + numberOfDirections = 0; + move16(); + FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) + { + sf_read_idx = sf_to_sf_map[sf_idx]; + move16(); + + IF( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 ) + { + numberOfDirections = 1; + move16(); + BREAK; + } + } + + extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections; + move16(); + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_dec_prepare_renderer() + * + * Prepare IVAS renderer routine + *--------------------------------------------------------------------------*/ + +void ivas_dec_prepare_renderer_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 n, n_render_timeslots, n_samples_available, tmp, exp, shift; + AUDIO_CONFIG output_config; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + + push_wmops( "ivas_dec_prepare_renderer" ); + + output_config = st_ivas->hDecoderConfig->output_config; + move16(); + hTcBuffer = st_ivas->hTcBuffer; + n_samples_available = hTcBuffer->n_samples_available; + move16(); + + /* n_render_timeslots = n_samples_available / hTcBuffer->n_samples_granularity; */ + tmp = BASOP_Util_Divide1616_Scale( n_samples_available, hTcBuffer->n_samples_granularity, &exp ); + n_render_timeslots = shr( tmp, sub( 15, exp ) ); // Q0 + + test(); + IF( EQ_16( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) + { + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); + + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && st_ivas->hDecoderConfig->Opt_tsm ) + { + ivas_jbm_masa_sf_to_slot_map_fx( st_ivas, n_render_timeslots ); + } + /* MASA transport gaining for edited disc OMASA EXT. For ISMs, only metadata is modified */ + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->hMasaIsmData->masa_gain_is_edited, 1 ) ) + { + ivas_omasa_gain_masa_tc_fx( hTcBuffer->tc_fx, st_ivas->hMasaIsmData->gain_masa_edited_fx, st_ivas->nchan_ism, n_samples_available ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) || EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) ) + { + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); + } + ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) + { + /* Rendering */ + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + test(); + test(); + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots ); + + ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas ); + } + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) + { + ivas_param_ism_dec_prepare_renderer_fx( st_ivas, n_render_timeslots ); + } + } + ELSE /* ISM_MODE_DISC */ + { + ivas_ism_dec_digest_tc_fx( st_ivas ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + { + IF( st_ivas->hSCE[0] ) + { + shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + { + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); + } + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + } + + ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, n_samples_available ); + } + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + ivas_ism_dec_digest_tc_fx( st_ivas ); + + test(); + test(); + test(); + test(); + test(); + test(); + /* delay the objects here for all renderers where it is needed */ + IF( + ( + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) || + EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) && + ( NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) + { + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) + { + delay_signal32_fx( hTcBuffer->tc_fx[n], n_samples_available, st_ivas->hSbaIsmData->delayBuffer_fx[n], st_ivas->hSbaIsmData->delayBuffer_size ); + } + } + + IF( !st_ivas->sba_dirac_stereo_flag ) + { + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) + { + Word16 temp, temp_e; + temp = BASOP_Util_Divide1616_Scale( hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size, &temp_e ); + n_render_timeslots = extract_l( L_shr( L_mult0( n_render_timeslots, temp ), sub( 15, temp_e ) ) ); + } + + IF( st_ivas->hSCE[0] ) + { + shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + { + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); + } + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + } + ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, n_samples_available ); + } + } + ELSE + { + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); + + IF( st_ivas->hSCE[0] ) + { + shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + { + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); + } + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + } + + ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, n_samples_available ); + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + { + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) + { + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); + + IF( st_ivas->hDecoderConfig->Opt_tsm ) + { + ivas_jbm_masa_sf_to_slot_map_fx( st_ivas, n_render_timeslots ); + } + /* MASA transport gaining for edited param_one OMASA EXT. For ISMs, only metadata is modified. */ + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && EQ_16( st_ivas->hMasaIsmData->masa_gain_is_edited, 1 ) ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + v_multc_fx_16( hTcBuffer->tc_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, hTcBuffer->tc_fx[n], n_samples_available ); // Q8 + Scale_sig32( hTcBuffer->tc_fx[n], n_samples_available, Q3 ); // Q8 -> Q11 + } + } + } + ELSE + { + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + n_render_timeslots = i_mult( n_render_timeslots, idiv1616( hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) ); + } + + IF( st_ivas->hSCE[0] ) + { + shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + { + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); + } + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift) + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + move16(); + } + + ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, n_samples_available ); + + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + ivas_ism_dec_digest_tc_fx( st_ivas ); + } + } + + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) ) + { + Word16 nchan_transport_ism; + + /* Delay the signal to match CLDFB delay. Delay the whole buffer. */ + nchan_transport_ism = 0; + move16(); + + test(); + test(); + IF( ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) + { + nchan_transport_ism = 1; + move16(); + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + nchan_transport_ism = st_ivas->nchan_ism; + move16(); + } + + test(); + test(); + IF( st_ivas->hDecoderConfig->Opt_tsm && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) + { + /* Gain MASA part, if edited */ + IF( st_ivas->hMasaIsmData->masa_gain_is_edited ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + v_multc_fx_16( hTcBuffer->tc_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, hTcBuffer->tc_fx[n], n_samples_available ); + Scale_sig32( hTcBuffer->tc_fx[n], n_samples_available, Q3 ); // Q8 -> Q11 + } + } + } + + FOR( n = 0; n < nchan_transport_ism; n++ ) + { + test(); + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) + { + v_multc_fx_16( hTcBuffer->tc_fx[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN_FX, hTcBuffer->tc_fx[CPE_CHANNELS + n], n_samples_available ); + + IF( st_ivas->hMasaIsmData->ism_gain_is_edited[n] ) + { + v_multc_fx_16( hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hMasaIsmData->gain_ism_edited_fx[n], hTcBuffer->tc_fx[CPE_CHANNELS + n], n_samples_available ); + Scale_sig32( hTcBuffer->tc_fx[CPE_CHANNELS + n], n_samples_available, Q3 ); // Q8 -> Q11 + } + } + + test(); + IF( NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + delay_signal32_fx( hTcBuffer->tc_fx[CPE_CHANNELS + n], n_samples_available, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + + test(); + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) + { + IF( st_ivas->hMasaIsmData->masa_gain_is_edited ) + { + FOR( n = 0; n < BINAURAL_CHANNELS; n++ ) + { + v_multc_fx_16( hTcBuffer->tc_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, hTcBuffer->tc_fx[n], n_samples_available ); // Q8 + Scale_sig32( hTcBuffer->tc_fx[n], n_samples_available, Q3 ); // Q8 -> Q11 + } + } + } + } + } + ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) + { + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) + { + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + ivas_mc_paramupmix_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, n_samples_available ); + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + { + Word16 nchan_transport = st_ivas->nchan_transport; + move16(); + Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + Word16 nchan_out_cov; + + test(); + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + } + ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) + { + nchan_out_cov = nchan_out_transport; + move16(); + } + ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + { + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + } + ELSE + { + nchan_out_cov = nchan_out_transport; + move16(); + } + + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1) + st_ivas->hParamMC->proto_matrix_int_e = 1; + move16(); + + ivas_param_mc_dec_prepare_renderer( st_ivas, (UWord8) n_render_timeslots ); + + scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1) + + FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) + { + shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift) + st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift ); + move16(); + + shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift) + st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift ); + move16(); + } + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + IF( st_ivas->hSCE[0] ) + { + shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + { + shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); + } + scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + move16(); + } + + ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, n_samples_available ); + } + } + + pop_wmops(); + return; +} diff --git a/lib_dec/ivas_decision_matrix_dec_fx.c b/lib_dec/ivas_decision_matrix_dec_fx.c index 4ba2a386af868d3e2704f59ad6af93f1bc593e0b..06f11158acfd8fa947a04f850f59b01ee723d2d4 100644 --- a/lib_dec/ivas_decision_matrix_dec_fx.c +++ b/lib_dec/ivas_decision_matrix_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -115,6 +115,9 @@ void ivas_decision_matrix_dec_fx( { st->L_frame = L_FRAME16k; move16(); + st->nb_subfr = NB_SUBFR16k; + move16(); + st->bwidth = s_max( st->bwidth, WB ); } ELSE { diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index 2e14f6b9dcbe3e31129764bc9164c5ac327b5524..d61e3ff4bdc9101c4923d27fc65744d464110fe9 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" @@ -1967,9 +1965,9 @@ void ivas_dirac_dec_set_md_map_fx( hSpatParamRendCom->subframes_rendered = 0; move16(); - ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); + ivas_dec_get_adapted_subframes_fx( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); - /* copy also to tc buffer */ + /* copy also to TC buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ test(); test(); @@ -1988,15 +1986,15 @@ void ivas_dirac_dec_set_md_map_fx( test(); IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { - ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + ivas_dec_get_md_map_even_spacing_fx( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { - ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + ivas_dec_get_md_map_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } ELSE { - ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + ivas_dec_get_md_map_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } test(); @@ -3708,7 +3706,7 @@ void ivas_dirac_dec_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] ) { - ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx ); + ivas_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx ); st_ivas->hIsmRendererData->interp_offset_fx = 0; move16(); } diff --git a/lib_dec/ivas_dirac_output_synthesis_cov_fx.c b/lib_dec/ivas_dirac_output_synthesis_cov_fx.c index c53f66138f70e7fa4e7d1786cdeb82a25652a8e9..b18a76052527644f20421b0cc1edc650b383f22f 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov_fx.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,18 +37,13 @@ #include #include #include -#include #include "options.h" -#include "cnst.h" -#include "rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_stat_dec.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "wmc_auto.h" -#include "rom_dec.h" #include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* diff --git a/lib_dec/ivas_entropy_decoder_fx.c b/lib_dec/ivas_entropy_decoder_fx.c index f8bf3c0910563b96492446ff76aa581507552b77..ea350ff4a1f1996fb1a4101c9818bbf06f5e5bd6 100644 --- a/lib_dec/ivas_entropy_decoder_fx.c +++ b/lib_dec/ivas_entropy_decoder_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 4e3c652865b0d1b9e3b6737fae230c4aeba4e1bb..6e603171298e513797abf9fc04d7a2eaf1e22664 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,14 +31,11 @@ *******************************************************************************************************/ #include -#include #include #include "options.h" #include "ivas_cnst.h" #include "ivas_prot_rend_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" -#include "ivas_stat_enc.h" #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -111,7 +108,7 @@ ivas_error ivas_dec_get_format_fx( Word16 nchan_ism, element_mode_flag; Word16 sba_order, sba_planar, sba_analysis_order; Word32 ivas_total_brate; - int16_t Opt_tsm; + Word16 Opt_tsm; UWord16 *bit_stream_orig; AUDIO_CONFIG signaled_config; @@ -1560,7 +1557,7 @@ ivas_error ivas_init_decoder_front( IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF( NE_32( ( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_num_subframes ) ), IVAS_ERR_OK ) ) { return error; } @@ -1573,7 +1570,7 @@ ivas_error ivas_init_decoder_front( test(); IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF( NE_32( ( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_num_subframes ) ), IVAS_ERR_OK ) ) { return error; } @@ -1625,7 +1622,7 @@ ivas_error ivas_init_decoder_fx( Word16 i, n, k; Word16 sce_id, cpe_id; Word16 numCldfbAnalyses, numCldfbSyntheses; - Word16 granularity, n_channels_transport_jbm; + Word16 granularity, n_channels_transport; Word16 nchan_out_buff; Word32 output_Fs, ivas_total_brate, tmp_br, tmp32; Word32 delay_ns; @@ -1802,7 +1799,8 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* Init HRTF statistics */ - IF( NE_32( ( error = ivas_HRTF_statistics_init_fx( &st_ivas->hHrtfStatistics, output_Fs ) ), IVAS_ERR_OK ) ) + /* Allocate HRTF and init statistics */ + IF( NE_32( ( error = ivas_reverb_HRTF_statistics_open_fx( &( st_ivas->hHrtfStatistics ), output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -2862,7 +2860,7 @@ ivas_error ivas_init_decoder_fx( return error; } - IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -3081,16 +3079,16 @@ ivas_error ivas_init_decoder_fx( } /*-----------------------------------------------------------------* - * Allocate and initialize JBM struct + buffer + * Allocate and initialize TC struct + buffer *-----------------------------------------------------------------*/ IF( st_ivas->hTcBuffer == NULL ) { /* no module has yet open the TC buffer, open a default one */ - granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), output_Fs ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), output_Fs ); + n_channels_transport = ivas_dec_get_num_tc_channels_fx( st_ivas ); - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode_fx( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, ivas_dec_get_tc_buffer_mode_fx( st_ivas ), n_channels_transport, n_channels_transport, n_channels_transport, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -3102,7 +3100,7 @@ ivas_error ivas_init_decoder_fx( { IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - IF( NE_32( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_jbm_dec_masa_metadata_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -3359,7 +3357,7 @@ void ivas_initialize_handles_dec( { st_ivas->hTdRendHandles[i] = NULL; } - /* JBM handles */ + st_ivas->hTcBuffer = NULL; st_ivas->hJbmMetadata = NULL; @@ -3544,23 +3542,12 @@ void ivas_destroy_dec_fx( ivas_combined_orientation_close_fx( &st_ivas->hCombinedOrientationData ); /* Time Domain binaural renderer handle */ - IF( st_ivas->hBinRendererTd != NULL ) - { - ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); - } - - IF( st_ivas->hHrtfTD != NULL ) - { - BSplineModelEvalDealloc_fx( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); - - ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD ); - } + ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); + ivas_HRTF_td_binary_close_fx( &st_ivas->hHrtfTD ); /* CRend binaural renderer handle */ ivas_HRTF_CRend_binary_close_fx( &st_ivas->hHrtfCrend ); - /* Fastconv HRTF memories */ - ivas_binaural_hrtf_close_fx( &st_ivas->hHrtfFastConv ); /* Fastconv HRTF filters */ ivas_HRTF_fastconv_binary_close_fx( &st_ivas->hHrtfFastConv ); @@ -3569,7 +3556,7 @@ void ivas_destroy_dec_fx( ivas_HRTF_parambin_binary_close_fx( &st_ivas->hHrtfParambin ); /* HRTF statistics */ - ivas_HRTF_statistics_close_fx( &st_ivas->hHrtfStatistics ); + ivas_HRTF_statistics_binary_close_fx( &st_ivas->hHrtfStatistics ); /* Config. Renderer */ ivas_render_config_close_fx( &( st_ivas->hRenderConfig ) ); @@ -3591,8 +3578,8 @@ void ivas_destroy_dec_fx( st_ivas->hDecoderConfig = NULL; } - /* JBM TC buffer structure */ - ivas_jbm_dec_tc_buffer_close_fx( &st_ivas->hTcBuffer ); + /* TC buffer structure */ + ivas_dec_tc_buffer_close_fx( &st_ivas->hTcBuffer ); IF( st_ivas->hJbmMetadata != NULL ) { diff --git a/lib_dec/ivas_ism_dec_fx.c b/lib_dec/ivas_ism_dec_fx.c index 4537b384078329dd47d40a02b300be63b0232b09..b087ab906b537a98f5c1c328033644490acc74a8 100644 --- a/lib_dec/ivas_ism_dec_fx.c +++ b/lib_dec/ivas_ism_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -55,9 +55,6 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( Word32 element_brate_tmp[MAX_NUM_OBJECTS]; Word16 nSCE_old, nCPE_old; Word16 numCldfbAnalyses_old, numCldfbSyntheses_old, ism_mode; - TC_BUFFER_MODE tc_buffer_mode_new; - Word16 tc_nchan_tc_new; - Word16 tc_nchan_allocate_new; Word16 tc_granularity_new; Word16 nchan_out_buff; @@ -124,7 +121,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( test(); test(); - /* transfer subframe info from DirAC or ParamMC to central tc buffer */ + /* transfer subframe info from DirAC or ParamMC to central TC buffer */ /* only do this if we are not having done everything already in the TC decoding part and having only played out from the TC buffer */ IF( EQ_32( last_ism_mode, ISM_MODE_PARAM ) && st_ivas->hSpatParamRendCom != NULL && NE_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) { @@ -139,15 +136,15 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - /* 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 */ - tc_granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); + /* when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { /* flush already done in IVAS_DEC_ReadFormat() */ } - /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ + /* when granularity goes up set samples to discard at the beginning of the frame */ ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples_fx( st_ivas ) ), IVAS_ERR_OK ) ) @@ -303,18 +300,21 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( } /*-----------------------------------------------------------------* - * JBM TC buffers + * TC buffer *-----------------------------------------------------------------*/ Word16 tc_nchan_full_new; + TC_BUFFER_MODE tc_buffer_mode_new; + Word16 tc_nchan_rend_new; + Word16 tc_nchan_allocate_new; DECODER_TC_BUFFER_HANDLE hTcBuffer; hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode_fx( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; + tc_buffer_mode_new = ivas_dec_get_tc_buffer_mode_fx( st_ivas ); + tc_nchan_rend_new = ivas_dec_get_num_tc_channels_fx( st_ivas ); + tc_nchan_allocate_new = tc_nchan_rend_new; move16(); - tc_nchan_full_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_rend_new; move16(); test(); @@ -327,32 +327,32 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( move16(); } - /* reconfigure buffer */ + /* reconfigure TC buffer */ test(); test(); test(); - IF( NE_32( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || + IF( NE_32( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_rend, tc_nchan_rend_new ) || NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) ) { - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_rend_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) { return error; } } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + /* transfer subframe info from central TC buffer to ParamMC or McMASA (DirAC) */ IF( st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->nb_subframes = hTcBuffer->nb_subframes; move16(); - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->subframes_rendered = hTcBuffer->subframes_rendered; move16(); - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->num_slots = hTcBuffer->num_slots; move16(); - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + st_ivas->hSpatParamRendCom->slots_rendered = hTcBuffer->slots_rendered; move16(); - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_ism_dtx_dec_fx.c b/lib_dec/ivas_ism_dtx_dec_fx.c index 19d99a0bb1fe277e13efc6485f7230bb235ffcba..d283832b33714cb68193bd1795ea5852e733a732 100644 --- a/lib_dec/ivas_ism_dtx_dec_fx.c +++ b/lib_dec/ivas_ism_dtx_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include #include "options.h" #include "ivas_prot_fx.h" #include "prot_fx.h" @@ -127,6 +126,10 @@ void ivas_ism_dtx_dec_fx( move16(); } } + ELSE + { + set16_fx( nb_bits_metadata, 0, st_ivas->nchan_transport ); + } IF( !st_ivas->bfi ) { @@ -153,16 +156,34 @@ void ivas_ism_dtx_dec_fx( * for DTX frames where the energy of the sent noise estimate of the dominant object * is near silence, limit the other objects CNG energies to the same level *-------------------------------------------------------------------*/ + void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( - SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ - const Word16 sce_id_dtx, /* i : SCE DTX ID */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *Q_cngNoiseLevel /* i : stores Q factor of hFdCngCom->cngNoiseLevel for various channels*/ + SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ + const Word16 sce_id_dtx, /* i : SCE DTX ID */ + const Word16 nchan_transport /* i : number of transport channels */ ) { Word32 fac_fx, cng_noise_nrg_obj_fx, cng_noise_nrg_dominant_fx; Word16 ch, cng_noise_level_len, Q_cng_noise_nrg_dominant, exp; HANDLE_FD_CNG_COM hFdCngCom; + Word16 Q_cngNoiseLevel[MAX_SCE]; + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + IF( hSCE[ch] != NULL ) + { + Word16 shift = getScaleFactor32( hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); + if ( LT_16( sub( hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) + { + shift = sub( hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); + } + scale_sig32( hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-(cngNoiseLevelExp -shift) ) + hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); + Q_cngNoiseLevel[ch] = sub( 31, hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); + move16(); + move16(); + } + } hFdCngCom = hSCE[sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom; cng_noise_level_len = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); diff --git a/lib_dec/ivas_ism_metadata_dec_fx.c b/lib_dec/ivas_ism_metadata_dec_fx.c index 1a29a7a2c4498c23f53ea075d02659144dd683c4..e937b9dfe606c3389e295ffd22ca8efbde647b35 100644 --- a/lib_dec/ivas_ism_metadata_dec_fx.c +++ b/lib_dec/ivas_ism_metadata_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,17 +30,14 @@ *******************************************************************************************************/ -#include "move.h" #include #include "options.h" +#include "stl.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "prot_fx.h" -#include "ivas_stat_enc.h" -#include #include "wmc_auto.h" -#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* @@ -57,8 +54,8 @@ static Word16 decode_radius_fx( DEC_CORE_HANDLE st0, Word16 *last_radius_idx, Wo #define IVAS_ISM_DTX_HO_MAX 5 -#define CNG_MD_MAX_DIFF_AZIMUTH 5 -#define CNG_MD_MAX_DIFF_ELEVATION 5 +#define CNG_MD_MAX_DIFF_AZIMUTH_FX ( 5 << Q22 ) +#define CNG_MD_MAX_DIFF_ELEVATION_FX ( 5 << Q22 ) #define MAX_BITS_ISM_METADATA ( 2 * ISM_EXTENDED_METADATA_BITS + MAX_NUM_OBJECTS * ( 1 /*number of objects*/ + ISM_METADATA_MD_FLAG_BITS + 2 * ISM_METADATA_FLAG_BITS + ISM_METADATA_IS_NDP_BITS + 1 /*abs.flag*/ + ISM_AZIMUTH_NBITS + ISM_ELEVATION_NBITS + 1 /*abs.flag*/ + ISM_RADIUS_NBITS + 1 /*abs.flag*/ + ISM_AZIMUTH_NBITS + ISM_ELEVATION_NBITS ) + 10 /* margin */ ) /* max. bit-budget of ISM metadata */ @@ -98,20 +95,20 @@ static void ism_metadata_smooth_fx( } test(); - IF( GT_32( ism_total_brate, IVAS_SID_5k2 ) && GT_32( L_abs( diff_fx ), L_shl( IVAS_ISM_DTX_HO_MAX * CNG_MD_MAX_DIFF_AZIMUTH, Q22 ) ) ) + IF( GT_32( ism_total_brate, IVAS_SID_5k2 ) && GT_32( L_abs( diff_fx ), IVAS_ISM_DTX_HO_MAX * CNG_MD_MAX_DIFF_AZIMUTH_FX ) ) { /* skip the smoothing */ } - ELSE IF( GT_32( L_abs( diff_fx ), L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ) ) ) + ELSE IF( GT_32( L_abs( diff_fx ), CNG_MD_MAX_DIFF_AZIMUTH_FX ) ) { Word32 temp; IF( ( diff_fx > 0 ) ) { - temp = L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ); + temp = CNG_MD_MAX_DIFF_AZIMUTH_FX; } ELSE { - temp = L_negate( L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ) ); + temp = L_negate( CNG_MD_MAX_DIFF_AZIMUTH_FX ); } hIsmMetaData->azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, temp ); move32(); @@ -132,20 +129,20 @@ static void ism_metadata_smooth_fx( diff_fx = L_sub( hIsmMetaData->last_true_elevation_fx, hIsmMetaData->last_elevation_fx ); test(); - IF( GT_32( ism_total_brate, IVAS_SID_5k2 ) && GT_32( diff_fx, L_shl( IVAS_ISM_DTX_HO_MAX * CNG_MD_MAX_DIFF_ELEVATION, Q22 ) ) ) + IF( GT_32( ism_total_brate, IVAS_SID_5k2 ) && GT_32( L_abs( diff_fx ), IVAS_ISM_DTX_HO_MAX * CNG_MD_MAX_DIFF_ELEVATION_FX ) ) { /* skip the smoothing */ } - ELSE IF( GT_32( L_abs( diff_fx ), L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ) ) ) + ELSE IF( GT_32( L_abs( diff_fx ), CNG_MD_MAX_DIFF_ELEVATION_FX ) ) { Word32 temp; IF( ( diff_fx > 0 ) ) { - temp = L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ); + temp = CNG_MD_MAX_DIFF_ELEVATION_FX; } ELSE { - temp = L_negate( L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ) ); + temp = L_negate( CNG_MD_MAX_DIFF_ELEVATION_FX ); } hIsmMetaData->elevation_fx = L_add( hIsmMetaData->last_elevation_fx, temp ); move32(); diff --git a/lib_dec/ivas_ism_param_dec_fx.c b/lib_dec/ivas_ism_param_dec_fx.c index fadb2350d9ecff1732c31b46c3a182818e734243..00c95d6dca854c9fca1705b310646540067c482a 100644 --- a/lib_dec/ivas_ism_param_dec_fx.c +++ b/lib_dec/ivas_ism_param_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,16 +32,15 @@ #include #include -#include #include "options.h" #include "ivas_prot_rend_fx.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" -#include "ivas_rom_dec.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#ifdef DEBUGGING #include "debug.h" +#endif /*-----------------------------------------------------------------------* @@ -761,7 +760,7 @@ ivas_error ivas_param_ism_dec_open_fx( st_ivas->hParamIsmDec = hParamIsmDec; st_ivas->hSpatParamRendCom = hSpatParamRendCom; - granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); + granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); test(); IF( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) @@ -808,7 +807,7 @@ ivas_error ivas_param_ism_dec_open_fx( IF( st_ivas->hTcBuffer == NULL ) { - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -821,7 +820,7 @@ ivas_error ivas_param_ism_dec_open_fx( IF( st_ivas->hTcBuffer == NULL ) { Word16 nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -922,7 +921,7 @@ void ivas_ism_dec_digest_tc_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); test(); test(); @@ -980,9 +979,10 @@ void ivas_ism_dec_digest_tc_fx( } ELSE { - ivas_jbm_dec_get_adapted_linear_interpolator_fx( extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); + ivas_dec_get_adapted_linear_interpolator_fx( extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); move16(); } + st_ivas->hIsmRendererData->interp_offset_fx = 0; move16(); @@ -1093,7 +1093,7 @@ void ivas_param_ism_dec_digest_tc_fx( num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; move16(); output_frame = imult1616( nCldfbSlots, st_ivas->hSpatParamRendCom->num_freq_bands ); - n_ch_cldfb = sub( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ); + n_ch_cldfb = sub( st_ivas->hTcBuffer->nchan_transport_rend, st_ivas->hTcBuffer->nchan_buffer_full ); cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx; cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx; @@ -1227,11 +1227,11 @@ void ivas_param_ism_dec_prepare_renderer_fx( } /* general setup */ - ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator_fx ); + ivas_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator_fx ); ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); - /* set buffers to zero */ + /* set buffers to zero */ set_zero_fx( &cx_diag_fx[0][0], CLDFB_NO_CHANNELS_MAX * PARAM_ISM_MAX_DMX ); set16_zero_fx( &exp_cx_diag[0][0], CLDFB_NO_CHANNELS_MAX * PARAM_ISM_MAX_DMX ); diff --git a/lib_dec/ivas_ism_renderer_fx.c b/lib_dec/ivas_ism_renderer_fx.c index 32f54c45ab7755bcf229c219e3d619eebff8ad6a..bd1b654e9ca4b22e40b4b8467bb8a02a5e7539ea 100644 --- a/lib_dec/ivas_ism_renderer_fx.c +++ b/lib_dec/ivas_ism_renderer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,9 +38,7 @@ #include "ivas_prot_rend_fx.h" #include "ivas_stat_com.h" #include "ivas_rom_com.h" -#include "rom_com.h" #include "ivas_rom_dec.h" -#include #include "wmc_auto.h" @@ -175,7 +173,7 @@ void ivas_ism_render_sf_fx( Word32 gain_fx, prev_gain_fx; Word32 tc_local_fx[MAX_NUM_OBJECTS][L_FRAME48k]; Word32 *p_tc_fx[MAX_NUM_OBJECTS]; - Word16 ism_md_subframe_update_jbm, slots_to_render, first_sf, last_sf, subframe_idx; + Word16 ism_md_subframe_update, slots_to_render, first_sf, last_sf, subframe_idx; Word16 n_samples_rendered_loop; /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ @@ -211,11 +209,11 @@ void ivas_ism_render_sf_fx( /* Number of subframes to delay metadata to sync with audio */ IF( st_ivas->hDecoderConfig->Opt_delay_comp ) { - ism_md_subframe_update_jbm = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 3 ) ); + ism_md_subframe_update = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 3 ) ); } ELSE { - ism_md_subframe_update_jbm = sub( st_ivas->hTcBuffer->nb_subframes, 2 ); + ism_md_subframe_update = sub( st_ivas->hTcBuffer->nb_subframes, 2 ); } FOR( i = 0; i < num_objects; i++ ) @@ -237,7 +235,7 @@ void ivas_ism_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx], 1 ) ) { - ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_in_subframe, n_samples_in_subframe, st_ivas->hIsmRendererData->interpolator_fx ); + ivas_dec_get_adapted_linear_interpolator_fx( n_samples_in_subframe, n_samples_in_subframe, st_ivas->hIsmRendererData->interpolator_fx ); interp_offset = 0; move16(); } @@ -248,7 +246,7 @@ void ivas_ism_render_sf_fx( test(); IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx], 1 ) ) { - if ( GE_16( subframe_idx, ism_md_subframe_update_jbm ) ) + if ( GE_16( subframe_idx, ism_md_subframe_update ) ) { rotateAziEle_fx( extract_l( L_shr( st_ivas->hIsmMetaData[i]->edited_azimuth_fx, 22 ) ), extract_l( L_shr( st_ivas->hIsmMetaData[i]->edited_elevation_fx, 22 ) ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx], st_ivas->hIntSetup.is_planar_setup ); } @@ -407,7 +405,7 @@ void ivas_ism_get_stereo_gains_fx( * Open structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ -ivas_error ivas_omasa_separate_object_renderer_open( +ivas_error ivas_omasa_separate_object_renderer_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { @@ -456,7 +454,7 @@ ivas_error ivas_omasa_separate_object_renderer_open( * Close structures, free memory. *-------------------------------------------------------------------------*/ -void ivas_omasa_separate_object_renderer_close( +void ivas_omasa_separate_object_renderer_close_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { @@ -487,16 +485,16 @@ void ivas_omasa_separate_object_renderer_close( /*-------------------------------------------------------------------------* - * ivas_omasa_separate_object_render_jbm() + * ivas_omasa_separate_object_render() * - * Rendering separated objects and mixing them to the parametrically rendered signals for JBM + * Rendering separated objects and mixing them to the parametrically rendered signals *-------------------------------------------------------------------------*/ -void ivas_omasa_separate_object_render_jbm_fx( +void ivas_omasa_separate_object_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 nSamplesRendered, /* i : number of samples rendered */ - Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal Q11*/ - Word32 *output_fx[], /* o : rendered time signal Q11*/ + Word32 input_fx_in[][L_FRAME48k], /* i : separated object signal Q11*/ + Word32 *output_fx[], /* o : rendered time signal Q11*/ const Word16 subframes_rendered /* i : number of subframes rendered */ ) { diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c deleted file mode 100644 index cca59f2b6b21719471fc3e0dc4a5ab170993da6e..0000000000000000000000000000000000000000 --- a/lib_dec/ivas_jbm_dec_fx.c +++ /dev/null @@ -1,4433 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2025 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 -#include "options.h" -#include "cnst.h" -#include "ivas_cnst.h" -#include "rom_com.h" -#include "prot_fx.h" -#include "ivas_prot_fx.h" -#include "ivas_prot_rend_fx.h" -#include "ivas_rom_com.h" -#include -#include "wmc_auto.h" -#include "ivas_prot_fx.h" -#ifdef DEBUGGING -#include "debug.h" -#endif - - -/*-----------------------------------------------------------------------* - * Local function prototypes - *-----------------------------------------------------------------------*/ - -static void ivas_jbm_dec_tc_buffer_playout_fx( Decoder_Struct *st_ivas, const UWord16 nSamplesAsked, UWord16 *nSamplesRendered, Word32 *output_fx[] ); - -static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas ); - -static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const Word16 nCldfbTs ); - -static Word16 ceil_fx16( - const Word16 inp, - const Word16 Q ) -{ - Word16 ret = shr( inp, Q ); - - IF( ( s_and( inp, sub( shl( 1, Q ), 1 ) ) ) > 0 ) - { - ret = add( ret, 1 ); - } - - return ret; -} - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc() - * - * Principal IVAS JBM decoder routine, decoding of metadata and transport channels - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_tc_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) -{ - Word16 ch, n, output_frame, nchan_out, i, ii; - Decoder_State *st; /* used for bitstream handling */ - Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* buffer for output synthesis */ - Word16 nchan_remapped; - Word16 nb_bits_metadata[MAX_SCE + 1]; - Word32 output_Fs, ivas_total_brate; - AUDIO_CONFIG output_config; - ivas_error error; - Word16 num_md_sub_frames; - Word32 ism_total_brate; - Word16 s; - - CPE_DEC_HANDLE hCPE; - SCE_DEC_HANDLE hSCE; - push_wmops( "ivas_jbm_dec_tc" ); - - /*----------------------------------------------------------------* - * Initialization of local vars after struct has been set - *----------------------------------------------------------------*/ - - output_Fs = st_ivas->hDecoderConfig->output_Fs; - move32(); - nchan_out = st_ivas->hTcBuffer->nchan_transport_jbm; - move16(); - output_config = st_ivas->hDecoderConfig->output_config; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - move32(); - - output_frame = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) /* output_Fs / FRAMES_PER_SEC */; - - /* set pointers to transport channels audio */ - FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ ) - { - p_output_fx[n] = st_ivas->p_output_fx[n]; - - IF( p_output_fx[n] != NULL ) - { - set32_fx( p_output_fx[n], 0, L_FRAME48k ); - } - } - - /*----------------------------------------------------------------* - * Decoding + pre-rendering - *----------------------------------------------------------------*/ - - test(); - test(); - IF( st_ivas->bfi != 0 && st_ivas->ini_frame == 0 ) - { - /* zero output when first frame(s) is lost */ - FOR( n = 0; n < nchan_out; n++ ) - { - set32_fx( p_output_fx[n], 0, output_frame ); - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - st_ivas->hCPE[0]->element_brate = ivas_total_brate; - move32(); - Word16 q_output = 11; - move16(); - set32_fx( &p_output_fx[0][0], 0, L_FRAME48k ); - set32_fx( &p_output_fx[1][0], 0, L_FRAME48k ); - - IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - - IF( NE_16( q_output, Q11 ) ) - { - Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11 - Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11 - } - - /* HP filtering */ - FOR( n = 0; n < s_min( nchan_out, st_ivas->nchan_transport ); n++ ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) - { - /* Metadata decoding and configuration */ - test(); - IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) - { - ivas_ism_dtx_dec_fx( st_ivas, nb_bits_metadata ); - - set32_fx( p_output_fx[st_ivas->hISMDTX.sce_id_dtx], 0, L_FRAME48k ); - - IF( ( error = ivas_sce_dec_fx( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &p_output_fx[st_ivas->hISMDTX.sce_id_dtx], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK ) - { - return error; - } - Word16 Q_cngNoiseLevel[MAX_SCE]; - FOR( ch = 0; ch < 4; ch++ ) - { - IF( st_ivas->hSCE[ch] != NULL ) - { - Word16 shift = getScaleFactor32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) - { - shift = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); - } - scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-(cngNoiseLevelExp -shift) ) - st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); - Q_cngNoiseLevel[ch] = sub( 31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); - move16(); - move16(); - } - } - - ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport, Q_cngNoiseLevel ); - - ivas_param_ism_dec_dequant_md_fx( st_ivas ); - } - ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) - { - IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - ivas_param_ism_dec_dequant_md_fx( st_ivas ); - } - ELSE /* ISM_MODE_DISC */ - { - IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - FOR( n = 0; n < st_ivas->nchan_transport; n++ ) - { - /* for DTX frames, dominant object has already been decoded before */ - test(); - test(); - IF( !( ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) && EQ_16( n, st_ivas->hISMDTX.sce_id_dtx ) ) ) - { - set32_fx( p_output_fx[n], 0, L_FRAME48k ); - - IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[n], output_frame, nb_bits_metadata[n] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - /* HP filtering */ - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - - test(); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) - { - ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame ); - - Scale_sig32( p_output_fx[0], L_FRAME48k, 3 ); - } - ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) ) - { - /* loudness correction */ - ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, st_ivas->nchan_transport, output_frame ); /*returns Q-1*/ - - FOR( i = 0; i < st_ivas->nchan_transport; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) - { - set16_fx( nb_bits_metadata, 0, MAX_SCE ); - - - /* read parameters from the bitstream */ - test(); - IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->hQMetaData != NULL ) - { - // st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; - - IF( st_ivas->nSCE > 0 ) - { - st = st_ivas->hSCE[0]->hCoreCoder[0]; - } - ELSE - { - st = st_ivas->hCPE[0]->hCoreCoder[0]; - } - - IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) - { - IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - test(); - IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) ) - { - st_ivas->hCPE[0]->brate_surplus = 0; - move32(); - st_ivas->hCPE[0]->element_brate = ivas_total_brate; - move32(); - } - - /* core-decoding of transport channels */ - Word16 q_output = Q11; - move16(); - IF( EQ_16( st_ivas->nSCE, 1 ) ) - { - set32_fx( p_output_fx[0], 0, L_FRAME48k ); - - IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) - { - set32_fx( &p_output_fx[0][0], 0, L_FRAME48k ); - set32_fx( &p_output_fx[1][0], 0, L_FRAME48k ); - - IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( NE_16( q_output, Q11 ) ) - { - Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11 - Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11 - } - } - ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) - { - IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - /* TCs remapping */ - nchan_remapped = st_ivas->nchan_transport; - move16(); - - test(); - test(); - test(); - test(); - test(); - IF( st_ivas->sba_dirac_stereo_flag ) - { - nchan_remapped = nchan_out; - move16(); - - IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) - { - FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 - } - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; - Word16 nchan_transport; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - move16(); - nchan_out = nchan_transport; - move16(); - ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx ), ( p_output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); - - IF( st_ivas->hSpar->hPCA != NULL ) - { - ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output_fx ); - } - - ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); - } - { - Word16 q; - hCPE = st_ivas->hCPE[0]; - hSCE = st_ivas->hSCE[0]; - - s = 0; - move16(); - FOR( i = 0; i < 2; i++ ) - { - s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 ) /* Guard bits */; // L_frame should be used instead of L_FRAME48k */ - } - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s) - } - hCPE->hStereoDft->q_dft = add( Q11, s ); - move16(); - IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) - { - hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft; - move16(); - hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - } - q = hCPE->hStereoDft->q_dft; - move16(); - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - } - IF( hCPE->hCoreCoder[0] != NULL ) - { - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; - move16(); - } - IF( hCPE->hStereoDft != NULL ) - { - IF( LE_16( st_ivas->nchan_transport, 1 ) ) - { - st = hCPE->hCoreCoder[0]; - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && ( st->last_core == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - } - ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ - { - IF( !st->tcxonly ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - } - } - } - ELSE /* ACELP core */ - { - test(); - test(); - IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */ - { - test(); - test(); - test(); - test(); - IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - } - } - } - } - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft - hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - } - - IF( hSCE != NULL ) - { - Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); // q_dft - hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; - move16(); - Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); // q_dft - hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; - move16(); - } - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; - move16(); - } - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx - } - - ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, st_ivas->ivas_format == MC_FORMAT ); - - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) ); - } - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11 - } - - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - } - - IF( hCPE->hCoreCoder[0] != NULL ) - { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB - } - IF( hCPE->hStereoDft != NULL ) - { - IF( LE_16( st_ivas->nchan_transport, 1 ) ) - { - st = hCPE->hCoreCoder[0]; - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && st->core == ACELP_CORE && EQ_16( st->con_tcx, 1 ) ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - } - ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ - { - IF( !st->tcxonly ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - } - } - } - ELSE /* ACELP core */ - { - test(); - test(); - IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */ - { - test(); - test(); - test(); - test(); - IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - } - } - } - } - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 - hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; - test(); - } - - st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; - move16(); - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - hCPE->q_output_mem_fx[ii] = Q11; - move16(); - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) - { - nchan_remapped = 1; /* Only one channel transported */ - move16(); - } - - /* HP filtering */ - FOR( n = 0; n < nchan_remapped; n++ ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - - IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) - { - nchan_remapped = ivas_sba_remapTCs_fx( p_output_fx, st_ivas, output_frame ); - - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; - Word16 Q_p_output = MAX_16, temp_min; - move16(); - Word16 nchan_transport; - - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - move16(); - nchan_out = nchan_transport; - move16(); - FOR( ch = 0; ch < nchan_transport; ch++ ) - { - temp_min = L_norm_arr( p_output_fx[ch], output_frame ); - Q_p_output = s_min( Q_p_output, temp_min ); - } - Q_p_output = sub( Q_p_output, 2 ); - if ( GT_16( Q_p_output, 20 ) ) - { - Q_p_output = 20; - move16(); - } - FOR( ch = 0; ch < nchan_transport; ch++ ) - { - Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); // Q(11+Q_p_output) - } - - ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output ); - FOR( Word16 c = 0; c < nchan_transport; c++ ) - { - Scale_sig32( p_output_fx[c], output_frame, 11 ); // Q11 - } - } - ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) - { - Word16 size = st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; - move16(); - if ( EQ_16( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, 3 ) ) - size = add( size, 1 ); - - FOR( i = 0; i < size; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14 - } - - ivas_spar_dec_agc_pca_fx( st_ivas, p_output_fx, output_frame ); - } - } - - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) - { - Word16 q_shift = 0; - move16(); - - ivas_masa_prerender_fx( st_ivas, p_output_fx, &q_shift, output_frame, nchan_remapped ); - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, negate( q_shift ) ); - } - - test(); - /* external output */ - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) - { - FOR( n = 0; n < st_ivas->nchan_ism; n++ ) - { - set_zero_fx( p_output_fx[add( st_ivas->nchan_transport, n )], output_frame ); - } - - ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, output_frame ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) - { - /* loudness correction */ - ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, nchan_remapped, output_frame ); - - FOR( i = 0; i < st_ivas->nchan_transport; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) - { - Word16 nchan_ism, nchan_transport_ism; - Word16 dirac_bs_md_write_idx; - - set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); - - /* Set the number of objects for the parametric rendering */ - dirac_bs_md_write_idx = 0; - move16(); - IF( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->numIsmDirections = 0; - move16(); - test(); - if ( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) - { - st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism; - move16(); - } - - dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ - move16(); - } - - - /* set ISM parameters and decode ISM metadata in OMASA format */ - Word16 q_output = 11; - move16(); - // NOTE: the following is done to calculate the number of hIsmMetaData indices - Word16 tmp_nchan_ism; - IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) - { - tmp_nchan_ism = 1; - move16(); - } - ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - tmp_nchan_ism = 0; - move16(); - } - ELSE - { - tmp_nchan_ism = st_ivas->nchan_ism; - move16(); - } - - FOR( n = 0; n < tmp_nchan_ism; n++ ) - { - set32_fx( p_output_fx[n], 0, L_FRAME48k ); - } - - /* MASA metadata decoding */ - IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* Configuration of combined-format bit-budget distribution */ - ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); - - st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - - IF( NE_32( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - FOR( n = 0; n < nchan_transport_ism; n++ ) - { - IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - /* decode MASA channels */ - IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* shifting both the channels from variable q_output to constant Q-factor (Q11) */ - FOR( Word16 k = 0; k < output_frame; k++ ) - { - p_output_fx[0][k] = L_shr( p_output_fx[0][k], sub( Q11, q_output ) ); - move32(); - p_output_fx[1][k] = L_shr( p_output_fx[1][k], sub( Q11, q_output ) ); - move32(); - } - - IF( EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) - { - Copy32( p_output_fx[0], p_output_fx[1], output_frame ); /* Copy mono signal to stereo output channels */ - } - - FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - - Word16 output_q = 11; - move16(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) - { - ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame ); - - output_q = 8; - move16(); - } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) - { - ivas_omasa_rearrange_channels_fx( p_output_fx, nchan_transport_ism, output_frame ); - } - ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) - { - /* Convert separate object to MASA, combine with the original MASA, and output combined MASA + empty objects. */ - ivas_omasa_combine_separate_ism_with_masa_fx( st_ivas, p_output_fx, &output_q, st_ivas->nchan_ism, output_frame ); - } - ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - /* Extract objects from MASA, output MASA + all objects (i.e., extracted and separated objects) */ - ivas_omasa_render_objects_from_mix_fx( st_ivas, p_output_fx, st_ivas->nchan_ism, output_frame, &output_q ); - } - } - IF( NE_16( output_q, Q11 ) ) - { - FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ ) - { - Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); // Q11 - } - st_ivas->hCPE[0]->q_output_mem_fx[0] = output_q; - st_ivas->hCPE[0]->q_output_mem_fx[1] = output_q; - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - Word16 nchan_ism, sba_ch_idx; - - set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 ); - nchan_ism = st_ivas->nchan_ism; - move16(); - IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - /* set ISM parameters and decode ISM metadata in OSBA format */ - IF( NE_32( ( error = ivas_osba_ism_metadata_dec_fx( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) - { - return error; - } - sba_ch_idx = st_ivas->nchan_ism; - move16(); - } - ELSE - { - nb_bits_metadata[1] = add( nb_bits_metadata[1], NO_BITS_MASA_ISM_NO_OBJ ); - sba_ch_idx = 0; - move16(); - move16(); - } - - /* SBA metadata decoding */ - IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) ) - { - return error; - } - - test(); - IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) ) - { - st_ivas->hCPE[0]->element_brate = ivas_total_brate; - move32(); - } - - /* core-decoding of transport channels */ - Word16 q_output = 11; - move16(); - - IF( EQ_16( st_ivas->nSCE, 1 ) ) - { - set32_fx( p_output_fx[0], 0, L_FRAME48k ); - - IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) - { - - IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, add( nb_bits_metadata[0], nb_bits_metadata[1] ) ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( NE_16( q_output, Q11 ) ) - { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 - } - } - ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) - { - IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - IF( st_ivas->sba_dirac_stereo_flag ) - { - FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) - { - Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); // Q14 - } - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; - Word16 nchan_transport; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - move16(); - nchan_out = nchan_transport; - move16(); - ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); - - IF( st_ivas->hSpar->hPCA != NULL ) - { - ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &p_output_fx[sba_ch_idx] ); - } - ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); - { - Word16 q; - hCPE = st_ivas->hCPE[0]; - hSCE = st_ivas->hSCE[0]; - s = 0; - move16(); - FOR( i = 0; i < 2; i++ ) - { - s = s_min( s, L_norm_arr( p_output_fx[sba_ch_idx + i], L_FRAME48k ) - 11 /* Guard bits */ ); - } - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); // Q(11+s) - } - hCPE->hStereoDft->q_dft = add( Q11, s ); - move16(); - IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) - { - hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft; - hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - move16(); - } - - q = hCPE->hStereoDft->q_dft; - move16(); - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - } - IF( hCPE->hCoreCoder[0] != NULL ) - { - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; - move16(); - } - IF( hCPE->hStereoDft != NULL ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft - hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - } - - IF( hSCE != NULL ) - { - Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft - hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; - move16(); - Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft - hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; - move16(); - } - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; - move16(); - } - FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx - ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame, 0 ); - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, negate( s ) ); - } - - FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11 - - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - } - - IF( hCPE->hCoreCoder[0] != NULL ) - { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda - } - IF( hCPE->hStereoDft != NULL ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 - hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; - move16(); - } - - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - hCPE->q_output_mem_fx[ii] = Q11; - move16(); - } - } - } - - /* HP filtering */ - FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - - nchan_remapped = ivas_sba_remapTCs_fx( &p_output_fx[sba_ch_idx], st_ivas, output_frame ); - - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; - Word16 nchan_transport; - // num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - move16(); - nchan_out = nchan_transport; - move16(); - Word16 Q_p_output; - Word16 min_norm = 31; - move16(); - - FOR( ch = 0; ch < nchan_transport; ++ch ) - { - Word16 norm = L_norm_arr( p_output_fx[sba_ch_idx + ch], output_frame ); // Normalize per channel - min_norm = s_min( norm, min_norm ); - } - - Q_p_output = s_max( 3, sub( min_norm, 1 ) ); - - Q_p_output = s_min( Q_p_output, 19 ); // to restrict Q-factor of p_ouptut to Q30 - FOR( ch = 0; ch < nchan_transport; ch++ ) - { - Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, Q_p_output ); // Q_p_output + Q11 - } - Q_p_output = add( Q11, Q_p_output ); - hSpar->hMdDec->Q_mixer_mat = 31; - move16(); - - ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) ); - FOR( Word16 c = 0; c < nchan_transport; c++ ) - { - Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11 - } - } - ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 ) - { - Word16 size = add( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, sba_ch_idx ); - if ( EQ_16( size, 3 ) ) - { - size = add( size, 1 ); - } - - FOR( i = sba_ch_idx; i < size; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14 - } - - ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame ); - } - - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - /* loudness correction */ - ivas_dirac_dec_binaural_sba_gain_fx( &p_output_fx[sba_ch_idx], nchan_remapped, output_frame ); /*returns Q-1*/ - - FOR( i = 0; i < nchan_remapped; i++ ) - { - Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame ); - - Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); // Q11 - - /* add W */ - FOR( n = 0; n < nchan_out; n++ ) - { - v_add_32( p_output_fx[n], p_output_fx[n + s_max( nchan_out, nchan_ism )], p_output_fx[n], output_frame ); - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) - { - IF( st_ivas->nSCE > 0 ) - { - st = st_ivas->hSCE[0]->hCoreCoder[0]; - } - ELSE - { - st = st_ivas->hCPE[0]->hCoreCoder[0]; - } - - IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) - { - /* LFE channel decoder */ - ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); - - Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11 - IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* HP filtering */ - FOR( n = 0; n < st_ivas->nchan_transport; n++ ) - { - IF( NE_16( n, LFE_CHANNEL ) ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - } - - test(); - test(); - test(); - IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) - { - IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) - { - ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); - } - } - - test(); - test(); - IF( ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) - { - IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) - { - s = Q16 - Q11; - move16(); - s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) ); - FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) - { - Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s) - } - ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); - FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i ) - { - Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11 - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hOutSetup.ambisonics_order, 0 ); - } - } - } - ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) - { - /* LFE channel decoder */ - ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] ); - - Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11 - - ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); - - IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* HP filtering */ - FOR( n = 0; n < st_ivas->nchan_transport; n++ ) - { - IF( NE_16( n, LFE_CHANNEL ) ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - } - - /* Rendering */ - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) - { - /* Compensate loudness for not doing full upmix */ - FOR( n = 4; n < 8; n++ ) - { - Scale_sig32( p_output_fx[n], output_frame, 1 ); - } - - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) - { - s = Q16 - Q11; - move16(); - Word16 nchan_transport; - nchan_transport = audioCfg2channels( IVAS_AUDIO_CONFIG_5_1_2 ); - s = sub( s, find_guarded_bits_fx( nchan_transport ) ); - FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i ) - { - Scale_sig32( p_output_fx[i], output_frame, s ); - } - ivas_ls_setup_conversion_fx( st_ivas, nchan_transport, output_frame, p_output_fx, p_output_fx ); - FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i ) - { - Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); - } - } - } - } - ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) - { - /* read Parametric MC parameters from the bitstream */ - ivas_param_mc_dec_read_BS_fx( ivas_total_brate, st, st_ivas->hParamMC, &nb_bits_metadata[0] ); - - IF( EQ_16( st_ivas->nCPE, 1 ) ) - { - Word16 q_output = 11; - move16(); - - IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - IF( NE_16( q_output, Q11 ) ) - { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 - } - } - ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) - { - IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - /* HP filtering */ - FOR( n = 0; n < st_ivas->nchan_transport; n++ ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - - /* Rendering */ - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) - { - ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx ); - } - } - ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) - { - IF( st_ivas->hOutSetup.separateChannelEnabled ) - { - st = st_ivas->hCPE[0]->hCoreCoder[0]; /* Metadata is always with CPE in the case of separated channel */ - } - - /* read McMASA parameters from the bitstream */ - IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( st_ivas->hOutSetup.separateChannelEnabled ) - { - /* Decode the transport audio signals */ - Word16 q_output = 11; - move16(); - - IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - IF( NE_16( q_output, Q11 ) ) - { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 - } - - /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */ - n = LFE_CHANNEL - 1; - move16(); - - /* Decode the separated channel to output[n] to be combined with the synthesized channels */ - set32_fx( p_output_fx[n], 0, L_FRAME48k ); - IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */ - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || - EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - ivas_lfe_synth_with_filters_fx( st_ivas->hMasa->hMasaLfeSynth, p_output_fx, output_frame, n, LFE_CHANNEL ); - } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 ) - { - /* Delay the separated channel to sync with the DirAC rendering */ - delay_signal32_fx( p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); - } - } - ELSE - { - Word16 q_output = 11; - move16(); - IF( EQ_16( st_ivas->nSCE, 1 ) ) - { - set32_fx( p_output_fx[0], 0, L_FRAME48k ); - - IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) - { - IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) - { - return error; - } - IF( NE_16( q_output, Q11 ) ) - { - Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11 - Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11 - } - } - } - - IF( st_ivas->sba_dirac_stereo_flag != 0 ) /* use the flag to trigger the DFT upmix */ - { - Word16 q; - hCPE = st_ivas->hCPE[0]; - hSCE = st_ivas->hSCE[0]; - s = 0; - move16(); - FOR( i = 0; i < 2; i++ ) - { - s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 /* Guard bits */ ); - } - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s) - } - - hCPE->hStereoDft->q_dft = add( Q11, s ); - move16(); - IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) - { - hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft; - hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; - - move16(); - move16(); - } - - q = hCPE->hStereoDft->q_dft; - move16(); - - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - } - - IF( hCPE->hCoreCoder[0] != NULL ) - { - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; - move16(); - } - IF( hCPE->hStereoDft != NULL ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft - hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - } - IF( st_ivas->hSpar != NULL ) - { - st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; - move16(); - } - - IF( hSCE != NULL ) - { - Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft - hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft; - move16(); - Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft - hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft; - move16(); - } - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); // q_dft - hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; - move16(); - } - FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx - ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, 1 ); - FOR( i = 0; i < 2; i++ ) - { - Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) ); - } - FOR( i = 0; i < CPE_CHANNELS; i++ ) - Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11 - - scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); - FOR( i = 0; i < CPE_CHANNELS; ++i ) - { - scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - } - - IF( hCPE->hCoreCoder[0] != NULL ) - { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda - } - IF( hCPE->hStereoDft != NULL ) - { - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 - hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; - move16(); - } - IF( st_ivas->hSpar != NULL ) - { - FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) - { - scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - hCPE->q_output_mem_fx[ii] = Q11; - move16(); - } - } - } - - /* HP filtering */ - FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) - { - hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs ); - } - - IF( EQ_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) - { - ivas_mono_stereo_downmix_mcmasa_fx( st_ivas, p_output_fx, output_frame ); - } - } - } - - /*----------------------------------------------------------------* - * Common updates - *----------------------------------------------------------------*/ - - IF( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */ - { - st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; - move32(); - IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) - { - st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate; - move32(); - } - ELSE - { - st_ivas->last_active_ivas_total_brate = ivas_total_brate; - move32(); - } - } - - test(); - test(); - if ( LT_16( st_ivas->ini_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */ - { - st_ivas->ini_frame = add( st_ivas->ini_frame, 1 ); - move16(); - } - - test(); - test(); - if ( LT_16( st_ivas->ini_active_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */ - { - st_ivas->ini_active_frame = add( st_ivas->ini_active_frame, 1 ); - move16(); - } - - st_ivas->last_ivas_format = st_ivas->ivas_format; - move32(); - pop_wmops(); - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_dec_feed_tc_to_renderer() - * - * Feed decoded transport channels to the IVAS renderer routine - * + digest TC channels in ParamISM and ParamMC - *--------------------------------------------------------------------------*/ - -void ivas_jbm_dec_feed_tc_to_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ - Word16 *nSamplesResidual /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ -) -{ - Word32 tmp_buf_fx[MAX_JBM_L_FRAME48k]; - Word32 *p_data_fx[FOA_CHANNELS + MAX_NUM_OBJECTS]; - Word16 n, n_render_timeslots, n_ch_cldfb; - Word16 ch, offset, len_offset; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - n_ch_cldfb = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); - move16(); - - hTcBuffer->q_tc_fx = Q11; - move16(); - - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - Word16 n_samples_still_available; - Word16 n_ch_full_copy, n_ch_res_copy; - - n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); - hTcBuffer->n_samples_buffered = add( add( n_samples_still_available, nSamplesForRendering ), hTcBuffer->n_samples_discard ); - hTcBuffer->n_samples_available = i_mult( hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity ) ); - *nSamplesResidual = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available ); - move16(); - move16(); - move16(); - n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); - n_ch_res_copy = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); - - /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': - in case of 'length(hTcBuffer->tc[]) < length(p_output_f[])', reset of TC buffers - pointers is needed after ivas_buffer_interleaved_to_deinterleaved() */ - len_offset = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ); - IF( LT_16( len_offset, L_FRAME48k ) ) - { - offset = 0; - move16(); - FOR( ch = 0; ch < s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); ch++ ) - { - hTcBuffer->tc_fx[ch] = &hTcBuffer->tc_buffer_fx[offset]; - st_ivas->p_output_fx[ch] = hTcBuffer->tc_fx[ch]; - offset = add( offset, len_offset ); - } - } - - FOR( ch = 0; ch < n_ch_full_copy; ch++ ) - { - Copy32( hTcBuffer->tc_fx[ch], tmp_buf_fx, nSamplesForRendering ); - set_zero_fx( hTcBuffer->tc_fx[ch], hTcBuffer->n_samples_discard ); - Copy32( hTcBuffer->tc_buffer_old_fx[ch], hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available ); - Copy32( tmp_buf_fx, hTcBuffer->tc_fx[ch] + n_samples_still_available + hTcBuffer->n_samples_discard, nSamplesForRendering - *nSamplesResidual ); - Copy32( tmp_buf_fx + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old_fx[ch], *nSamplesResidual ); - } - - IF( n_ch_res_copy > 0 ) - { - FOR( ; ch < hTcBuffer->nchan_transport_jbm; ch++ ) - { - p_data_fx[ch] = hTcBuffer->tc_fx[ch]; - Copy32( hTcBuffer->tc_fx[ch], tmp_buf_fx, nSamplesForRendering ); - Copy32( hTcBuffer->tc_buffer_old_fx[ch], p_data_fx[ch], n_samples_still_available ); - Copy32( tmp_buf_fx, p_data_fx[ch] + n_samples_still_available, sub( nSamplesForRendering, *nSamplesResidual ) ); - Copy32( tmp_buf_fx + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old_fx[ch], *nSamplesResidual ); - } - } - - n_render_timeslots = idiv1616( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity ); - } - ELSE - { - FOR( n = 0; n < n_ch_cldfb; n++ ) - { - p_data_fx[n] = &st_ivas->p_output_fx[n][0]; - move16(); - } - - ch = s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); - FOR( n = 0; n < ch; n++ ) - { - hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; /* note: buffers needed in the TD decorellator */ - move16(); - } - - hTcBuffer->n_samples_buffered = nSamplesForRendering; - hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered; - *nSamplesResidual = 0; - move16(); - move16(); - move16(); - - n_render_timeslots = DEFAULT_JBM_CLDFB_TIMESLOTS; - move16(); - } - - /* CLDFB analysis for ParamMC/ParamISM */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) ) - { - ivas_param_ism_dec_digest_tc_fx( st_ivas, n_render_timeslots, p_data_fx, Q11 ); - } - ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) && EQ_32( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_RENDERER ) ) - { - ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, p_data_fx, Q11 ); - } - - hTcBuffer->n_samples_rendered = 0; - move16(); - hTcBuffer->subframes_rendered = 0; - move16(); - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_dec_render() - * - * Principal IVAS JBM rendering routine - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 nSamplesAsked, /* i : number of samples wanted */ - UWord16 *nSamplesRendered, /* o : number of samples rendered */ - UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - Word16 *data /* o : output synthesis signal Q0*/ -) -{ - Word16 n, nchan_out; - Word16 nchan_transport; - Word16 nchan_remapped; - Word32 output_Fs; - AUDIO_CONFIG output_config; - Word16 nSamplesAskedLocal; - ivas_error error; - Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS]; - Word16 subframe_len, gd_bits, exp, nchan_in, i, j, ch; - const Word16 output_q_factor = Q11; - move16(); - Word16 nchan_out_syn_output; - - push_wmops( "ivas_dec_render" ); - /*----------------------------------------------------------------* - * Initialization of local vars after struct has been set - *----------------------------------------------------------------*/ - - output_Fs = st_ivas->hDecoderConfig->output_Fs; - move32(); - nchan_out = st_ivas->hDecoderConfig->nchan_out; - move16(); - nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm; - move16(); - output_config = st_ivas->hDecoderConfig->output_config; - move32(); - nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard ); - move16(); - - FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) - { - p_output_fx[n] = st_ivas->p_output_fx[n]; - } - - IF( !st_ivas->hDecoderConfig->Opt_tsm ) - { - FOR( n = 0; n < MAX_INTERN_CHANNELS; n++ ) - { - st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; - } - } - - FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) - { - p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered]; - } - - st_ivas->hTcBuffer->no_channels = st_ivas->hTcBuffer->nchan_buffer_full; - move16(); - - /*----------------------------------------------------------------* - * Update combined orientation access index - *----------------------------------------------------------------*/ - - IF( st_ivas->hCombinedOrientationData != NULL ) - { - /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */ - st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard ); - move16(); - - ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); - } - - /*----------------------------------------------------------------* - * Rendering - *----------------------------------------------------------------*/ - - *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - move16(); - - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) - { - assert( 0 ); - } - ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) - { -#ifndef FIX_1435_MOVE_STEREO_PANNING - Word16 slot_size, tmp, e; - - slot_size = st_ivas->hTcBuffer->n_samples_granularity; - move16(); - - /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); - tmp = shr( tmp, sub( 15, e ) ); -#endif - ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) || EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - /* Rendering */ - IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) - { - ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - } -#ifdef FIX_1435_MOVE_STEREO_PANNING - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) - { - ivas_apply_non_diegetic_panning_fx( p_tc_fx[0], p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered ); - } -#endif - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { -#ifdef FIX_1454_FIX_STEREO_TO_FOA_JBM - ivas_stereo2sba_fx( p_tc_fx, p_output_fx, *nSamplesRendered ); -#else - ivas_stereo2sba_fx( p_output_fx, p_output_fx, *nSamplesRendered ); -#endif - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) - { - /* Rendering */ - IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) - { - test(); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - - IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - /* Convert CICP19 -> Ambisonics */ - ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); - } - } - } - ELSE /* ISM_MODE_DISC */ - { - test(); - test(); - /* Loudspeaker or Ambisonics rendering */ - IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) - { - /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ - ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_fx, *nSamplesRendered ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) - { - ivas_apply_non_diegetic_panning_fx( p_tc_fx[0], p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered ); - } -#ifdef DEBUGGING - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) -#else - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) -#endif - { - /* Convert to Ambisonics */ - FOR( i = 0; i < st_ivas->nchan_transport; i++ ) - { - FOR( j = 0; j < HOA3_CHANNELS; j++ ) - { - st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 - move32(); - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 - move32(); - } - } - - ivas_ism2sba_sf_fx( p_tc_fx, p_output_fx, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order ); - - Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) ); - FOR( j = 0; j < sba_num_chans; j++ ) - { - scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11 - } - - FOR( i = 0; i < st_ivas->nchan_transport; i++ ) - { - FOR( j = 0; j < 16; j++ ) - { - st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 - move32(); - st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30 - move32(); - } - } - } - - /* Binaural rendering */ - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) - { - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - IF( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE - { - IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) - { - st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); - gd_bits = find_guarded_bits_fx( subframe_len ); - exp = 13; - move16(); - nchan_in = 12; - move16(); - nchan_out = 2; - move16(); - exp = sub( exp, gd_bits ); - *st_ivas->hCrendWrapper->p_io_qfactor = exp; - move16(); - FOR( i = 0; i < nchan_in; i++ ) - { - scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11 - } - - IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - FOR( i = 0; i < nchan_out; i++ ) - { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 - } - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) - { - nchan_remapped = nchan_transport; - move16(); - test(); - test(); - /* Loudspeakers, Ambisonics or Binaural rendering */ - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) - { - IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) - { - ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - } - } - ELSE - { - IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) - { - nchan_remapped = st_ivas->nchan_transport; - move16(); - test(); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - test(); - IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) - { - IF( NE_32( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) - { - ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) - { - ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); - ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, *nSamplesRendered ); - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - nchan_remapped = nchan_transport; - move16(); - /* Loudspeakers, Ambisonics or Binaural rendering */ - IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) - { - SPAR_DEC_HANDLE hSpar; - hSpar = st_ivas->hSpar; - hSpar->hMdDec->Q_mixer_mat = 30; - move16(); - - IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ) - { - test(); - /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/ - IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) ) - { - Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered ); - Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered ); - p_tc_fx[1] = p_output_fx[2]; - p_tc_fx[2] = p_output_fx[3]; - } - - /* render objects */ - ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_fx, *nSamplesRendered ); - - /* add already rendered SBA part */ - ivas_osba_stereo_add_channels_fx( p_tc_fx, p_output_fx, st_ivas->hSbaIsmData->gain_bed_fx, nchan_out, st_ivas->nchan_ism, st_ivas->ism_mode, *nSamplesRendered ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) - { - IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/ - { - IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism] ) ), IVAS_ERR_OK ) ) - { - return error; - } - - FOR( n = 0; n < st_ivas->nchan_ism; n++ ) - { - Copy32( p_tc_fx[n], p_output_fx[n], *nSamplesRendered ); - } - } - ELSE - { - IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - - FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) - { - scale_sig32( p_output_fx[n], *nSamplesRendered, 1 ); - } - } - ELSE - { - IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) - { - Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered ); - } - FOR( n = 0; n < st_ivas->nchan_ism; n++ ) - { - set32_fx( p_output_fx[n], 0, *nSamplesRendered ); - } - } - FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) - { - scale_sig32( p_output_fx[n], *nSamplesRendered, 1 ); - } - } - } - ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) - { - IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) - { - Word16 crendInPlaceRotation = FALSE; - move16(); - - test(); - test(); - test(); - IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) - { - IF( LT_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) - { - crendInPlaceRotation = TRUE; - move16(); - - ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); - } - } - - test(); - /* Rendering */ - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) - { - st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); - gd_bits = find_guarded_bits_fx( subframe_len ); - exp = 13; - move16(); - IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ), IVAS_ERR_OK ) ) - { - return error; - } - IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) ) - { - return error; - } - exp = sub( exp, gd_bits ); - *st_ivas->hCrendWrapper->p_io_qfactor = exp; - move16(); - - IF( crendInPlaceRotation ) - { - FOR( i = 0; i < nchan_in; i++ ) - { - scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor - } - } - ELSE - { - FOR( i = 0; i < nchan_in; i++ ) - { - scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor - } - } - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - IF( ( error = ivas_rend_crendProcessSubframesSplitBin( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, - &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE - { - IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, - &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ), - IVAS_ERR_OK ) ) - { - return error; - } - - // Todo main-pc update: This might be needed also in the split rendering path - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); - } - - IF( crendInPlaceRotation ) - { - n = nchan_in; - } - ELSE - { - n = nchan_out; - } - move16(); - - FOR( i = 0; i < n; i++ ) - { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 - } - - FOR( i = n; i < nchan_in; i++ ) - { - scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) - { - ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) - { - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - IF( NE_32( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - else - { - IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) ) - { - return error; - } - - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); - } - } - } - ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) - { - ivas_mc_paramupmix_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx ); - - test(); - test(); - /* Rendering */ - IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && !st_ivas->hDecoderConfig->Opt_Headrotation ) - { - /* handled in CLDFB domain already */ - IF( NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); - } - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) - { - ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); - } - } - ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) - { - Word16 channel_active_fx[MAX_OUTPUT_CHANNELS]; - Word16 nchan_out_cov; - Word16 nchan_out_cldfb = 0; - move16(); - - set16_fx( channel_active_fx, 0, MAX_LS_CHANNELS ); - Word16 nchan_transport_tmp = st_ivas->nchan_transport; - move16(); - output_Fs = st_ivas->hDecoderConfig->output_Fs; - move32(); - Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) - { - nchan_out_cldfb = BINAURAL_CHANNELS; - move16(); - set16_fx( channel_active_fx, 1, BINAURAL_CHANNELS ); - nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - } - ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) - { - nchan_out_cov = nchan_out_transport; - move16(); - nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); - } - ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) - { - nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); - nchan_out_cldfb = nchan_out_cov; - move16(); - set16_fx( channel_active_fx, 1, nchan_out_cov ); - } - ELSE - { - nchan_out_cov = nchan_out_transport; - move16(); - nchan_out_cldfb = nchan_out_transport; - move16(); - set16_fx( channel_active_fx, 1, nchan_out_cov ); - } - IF( st_ivas->hParamMC->max_band_decorr > 0 ) - { - Word16 tmp; - tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); // Q(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer+ tmp) - st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); - move16(); - } - /* CLDFB synthesis */ - FOR( ch = 0; ch < nchan_out_cldfb; ch++ ) - { - IF( st_ivas->cldfbSynDec[ch] ) - { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5 - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; - move16(); - } - } - Word16 tempp; - FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) - { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) - st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); - move16(); - - IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) - { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) - st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp ); - move16(); - } - } - - ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); - - FOR( ch = 0; ch < nchan_out_cldfb; ch++ ) - { - IF( st_ivas->cldfbSynDec[ch] ) - { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11 - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; - move16(); - } - } - IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) ) - { - FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) - { - IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) - { - Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) ); - st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx]; - move16(); - } - Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) ); - st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]; - move16(); - } - } - } - ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) - { - nchan_remapped = st_ivas->nchan_transport; - move16(); - - test(); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) /* rendering to CICPxx and Ambisonics */ - { - ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - - test(); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - /* we still need to copy the separate channel if available */ - IF( st_ivas->hOutSetup.separateChannelEnabled ) - { - Copy32( p_tc_fx[LFE_CHANNEL - 1], p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - } - - ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); - } - ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) ) - { - FOR( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); n++ ) - { - set32_fx( p_output_fx[n], 0, *nSamplesRendered ); - } - } - } - - /* copy discrete C and TD LFE from internal TC to output */ - IF( st_ivas->hOutSetup.separateChannelEnabled ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || - EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || - EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) - { - Copy32( p_tc_fx[LFE_CHANNEL], p_output_fx[LFE_CHANNEL], *nSamplesRendered ); - Copy32( p_tc_fx[LFE_CHANNEL - 1], p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 ) - { - Copy32( p_tc_fx[LFE_CHANNEL - 1], p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - } - } - } - } - - /*----------------------------------------------------------------* - * Write IVAS output channels - * - compensation for saturation - * - float to integer conversion - *----------------------------------------------------------------*/ - - st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered ); - st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered ); - move16(); - move16(); - - /* update global combined orientation start index */ - ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); - - IF( st_ivas->hTcBuffer->n_samples_discard > 0 ) - { - FOR( n = 0; n < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ ) - { - p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard; - } - *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard ); - move16(); - st_ivas->hTcBuffer->n_samples_discard = 0; - move16(); - } - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - const Word32 *p_output_fx_const[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - - nchan_out_syn_output = i_mult( BINAURAL_CHANNELS, st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ); - - /* Save TD signals for pose correction if they are to be used. - * - * NOTE: Here BASOP differs from the float version. In float, we push samples to TD ring buffer in lib_dec.c function isar_render_poses. */ - IF( st_ivas->hSplitBinRend->hMultiBinTdData != NULL ) - { - FOR( i = 0; i < nchan_out_syn_output; i++ ) - { - p_output_fx_const[i] = p_output_fx[i]; - } - ivas_TD_RINGBUF_PushChannels( st_ivas->hSplitBinRend->hMultiBinTdData, p_output_fx_const, *nSamplesRendered ); - } - -#ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR - if ( st_ivas->flushing ) - { - nchan_out_syn_output = BINAURAL_CHANNELS; - move16(); - } -#endif - } - ELSE - { - nchan_out_syn_output = nchan_out; - move16(); - } - - IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 ) - { - IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) ) - { -#ifndef DISABLE_LIMITER - ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor ); -#endif - } - } - - ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out_syn_output, data ); - - *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; - move16(); - - pop_wmops(); - return IVAS_ERR_OK; -} - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_flush_renderer() - * - * Flush samples if renderer granularity changes on a bitrate change - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_flush_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 tc_granularity_new, /* i : new renderer granularity */ - const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ - const AUDIO_CONFIG intern_config_old, /* i : old internal config */ - const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ - const MC_MODE mc_mode_old, /* i : old MC mode */ - const ISM_MODE ism_mode_old, /* i : old ISM mode */ - UWord16 *nSamplesRendered, /* o : number of samples flushed */ - Word16 *data /* o : output synthesis signal Q0*/ -) -{ - ivas_error error; - Word16 n_samples_still_available; - Word16 n_slots_still_available; - Word16 n_samples_to_render; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - Word32 *p_output_fx[MAX_LS_CHANNELS + MAX_NUM_OBJECTS]; - Word16 nchan_in, nchan_out; - - IF( !st_ivas->hDecoderConfig->Opt_tsm ) - { - return IVAS_ERR_OK; - } - - *nSamplesRendered = 0; - move16(); - hTcBuffer = st_ivas->hTcBuffer; - - /* get number of possible slots in new granularity */ - n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); - - // n_slots_still_available = n_samples_still_available / tc_granularity_new; - Word16 tmp, tmp_e; - tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e ); - n_slots_still_available = shr( tmp, sub( 15, tmp_e ) ); - *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new ); - n_samples_to_render = *nSamplesRendered; - move16(); - move16(); - n_samples_still_available = sub( n_samples_still_available, n_samples_to_render ); - assert( n_samples_still_available < tc_granularity_new ); - - /* update combined orientation access index */ - ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); - - IF( n_slots_still_available ) - { - Word16 ch_idx; - - /* render available full slots (with new lower granularity) */ - FOR( ch_idx = 0; ch_idx < s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); ch_idx++ ) - { - /* move it at the beginning of the TC buffer with zero padding */ - Copy32( hTcBuffer->tc_buffer_old_fx[ch_idx], hTcBuffer->tc_fx[ch_idx], n_samples_to_render ); - set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, sub( hTcBuffer->n_samples_granularity, n_samples_to_render ) ); - } - - /* simple change of the slot info */ - hTcBuffer->num_slots = 1; - hTcBuffer->nb_subframes = 1; - hTcBuffer->subframes_rendered = 0; - hTcBuffer->slots_rendered = 0; - hTcBuffer->subframe_nbslots[0] = 1; - hTcBuffer->n_samples_buffered = add( hTcBuffer->n_samples_granularity, n_samples_still_available ); - hTcBuffer->n_samples_available = 0; - hTcBuffer->n_samples_flushed = n_samples_to_render; - hTcBuffer->n_samples_rendered = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - - FOR( ch_idx = 0; ch_idx < ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); ch_idx++ ) - { - p_output_fx[ch_idx] = st_ivas->p_output_fx[ch_idx]; - } - - test(); - IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) - { - IF( EQ_16( ism_mode_old, ISM_MODE_DISC ) ) - { - /* Binaural rendering */ - IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) ) - { - IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) - { - /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ - set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); // 32767=1.0f in Q15 - - ivas_ism_render_sf_fx( st_ivas, renderer_type_old, p_output_fx, hTcBuffer->n_samples_granularity ); - - st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - *st_ivas->hCrendWrapper->p_io_qfactor = 11; - - move16(); - IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, - NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ) ), - IVAS_ERR_OK ) ) - { - return error; - } - } - } - ELSE - { - return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) - { - IF( EQ_16( mc_mode_old, MC_MODE_MCT ) ) - { - Word16 crendInPlaceRotation = FALSE; - - test(); - test(); - test(); - IF( NE_16( st_ivas->transport_config, intern_config_old ) && ( EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_HOA3 ) ) ) - { - IF( GT_16( sub( add( hIntSetupOld->nchan_out_woLFE, hIntSetupOld->num_lfe ), add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), 0 ) ) - { - crendInPlaceRotation = TRUE; - move16(); - ivas_mc2sba_fx( st_ivas->hTransSetup, hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, hIntSetupOld->ambisonics_order, GAIN_LFE_FX ); - } - } - - test(); - IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) - { - st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - IF( NE_32( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) ) - { - return error; - } - - Word16 subframe_len, gd_bits; - subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); - gd_bits = find_guarded_bits_fx( subframe_len ); - *st_ivas->hCrendWrapper->p_io_qfactor = sub( 13, gd_bits ); - FOR( Word16 i = 0; i < nchan_in; i++ ) - { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( *st_ivas->hCrendWrapper->p_io_qfactor, Q11 ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor - } - - IF( NE_32( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : st_ivas->hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ), IVAS_ERR_OK ) ) - { - return error; - } - - ivas_binaural_add_LFE_fx( st_ivas, hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->tc_fx, p_output_fx ); - - FOR( Word16 i = 0; i < nchan_in; i++ ) - { - scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11 - } - } - ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) ) - { - IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) ) - { - return error; - } - - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc_fx, p_output_fx ); - } - ELSE - { - return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong renderer in MCT VoIP renderer flushing!" ); - } - } - ELSE - { - return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) - { - IF( EQ_16( ism_mode_old, ISM_MASA_MODE_DISC ) ) - { - Word32 *tc_local_fx[MAX_NUM_OBJECTS]; - Word16 last_dirac_md_idx; - UWord16 nSamplesAvailableNext; - ISM_MODE ism_mode_orig; - RENDERER_TYPE renderer_type_orig; - Word32 ivas_total_brate; - - /* copy from ISM delay buffer to the correct place in TCs */ - move16(); - FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) - { - tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered]; - Copy32( st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size ); /*Q11*/ - } - - /* to render flushed samples, use configuration from the last received frame */ - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - renderer_type_orig = st_ivas->renderer_type; - ism_mode_orig = st_ivas->ism_mode; - st_ivas->ism_mode = ism_mode_old; - st_ivas->renderer_type = renderer_type_old; - st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; - last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; - - /* transfer adapted sf info from hTcBuffer to DirAC */ - st_ivas->hSpatParamRendCom->nb_subframes = 1; - st_ivas->hSpatParamRendCom->subframes_rendered = 0; - st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; - st_ivas->hSpatParamRendCom->slots_rendered = 0; - st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; - set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available ); - - IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, CPE_CHANNELS, p_output_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* restore original configuration */ - st_ivas->ism_mode = ism_mode_orig; - st_ivas->renderer_type = renderer_type_orig; - st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - IF( EQ_32( ism_mode_old, ISM_SBA_MODE_DISC ) ) - { - Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; - Word16 last_spar_md_idx; - Word16 last_dirac_md_idx; - UWord16 nSamplesAvailableNext; - ISM_MODE ism_mode_orig; - RENDERER_TYPE renderer_type_orig; - Word32 ivas_total_brate; - - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - renderer_type_orig = st_ivas->renderer_type; - ism_mode_orig = st_ivas->ism_mode; - - /* to render flushed samples, use configuration from the last received frame */ - move32(); - st_ivas->ism_mode = ism_mode_old; - st_ivas->renderer_type = renderer_type_old; - st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; - - last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1]; - last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1]; - move16(); - move16(); - - /* copy from ISM delay buffer to the correct place in TCs */ - FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) - { - tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx][hTcBuffer->n_samples_rendered]; - Copy32( st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size ); - } - - /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */ - st_ivas->hSpar->nb_subframes = 1; - st_ivas->hSpar->subframes_rendered = 0; - st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; - st_ivas->hSpar->slots_rendered = 0; - st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; - st_ivas->hSpatParamRendCom->nb_subframes = 1; - st_ivas->hSpatParamRendCom->subframes_rendered = 0; - st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME; - st_ivas->hSpatParamRendCom->slots_rendered = 0; - st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - - /* also adapt md maps, just use the last index */ - set16_fx( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available ); - set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available ); - - /* render the last subframe */ - IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* restore original configuration */ - st_ivas->ism_mode = ism_mode_orig; - st_ivas->renderer_type = renderer_type_orig; - st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; - } - } - ELSE - { - return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" ); - } - - hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity; - } - - /* update global combined orientation start index */ - ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); - - *nSamplesRendered = n_samples_to_render; - move16(); - - /* Only write out the valid data*/ - IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 ) - { - IF( NE_16( st_ivas->ivas_format, MONO_FORMAT ) ) - { -#ifndef DISABLE_LIMITER - Word16 ch_idx, exp = 11; - move16(); - FOR( ch_idx = 0; ch_idx < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) - { - p_output_fx[ch_idx] = st_ivas->p_output_fx[ch_idx]; - } - ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp ); -#endif - } - } - - ivas_syn_output_fx( p_output_fx, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, data ); - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_set_discard_samples() - * - * Set number of samples to discard in the first subframe if the renderer granularity changes on a bitrate change - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_set_discard_samples_fx( - Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ -) -{ - Word16 nMaxSlotsPerSubframe, nSlotsInFirstSubframe; - Word16 temp, temp_e; - - /* render first frame with front zero padding and discarding those samples */ - /* nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity; */ - temp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); - temp = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e ); - nMaxSlotsPerSubframe = shr( temp, sub( 15, temp_e ) ); /* Q0 */ - nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); - IF( nSlotsInFirstSubframe > 0 ) - { - st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity ); - /* set last subframes number to max to ensure correct continuation */ - st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe; - move16(); - move16(); - } - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_adapted_linear_interpolator() - * - * Get an interpolator that is adapted to time scale modified IVAS frame - *--------------------------------------------------------------------------*/ -void ivas_jbm_dec_get_adapted_linear_interpolator_fx( - const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */ - const Word16 interp_length, /* i : length of the interpolator to be created */ - Word16 *interpolator_fx /* o : the interpolator Q15 */ -) -{ - Word16 jbm_segment_len, idx; - Word16 dec_fx; - Word16 dec_e; - - jbm_segment_len = shr( default_interp_length, 1 ); - dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/ - - interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */ - move16(); - interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision - move16(); - FOR( idx = interp_length - 3; idx >= jbm_segment_len; idx-- ) - { - interpolator_fx[idx] = s_max( 0, sub( interpolator_fx[idx + 1], dec_fx ) ); - move16(); - } - - IF( interpolator_fx[idx + 1] > 0 ) - { - dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( jbm_segment_len, 1 ), &dec_e ); - dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0 - FOR( ; idx >= 0; idx-- ) - { - interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx ); - move16(); - } - } - ELSE - { - set16_fx( interpolator_fx, 0, add( idx, 1 ) ); - } - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_adapted_subframes() - * - * Get an interpolator that is adapted to time scale modified IVAS frame - *--------------------------------------------------------------------------*/ - -void ivas_jbm_dec_get_adapted_subframes( - const Word16 nCldfbTs, /* i : number of time slots in the current frame */ - Word16 *subframe_nbslots, /* i/o: subframe grid */ - Word16 *nb_subframes /* i/o: number of subframes in the frame */ -) -{ - UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe; - UWord16 nCldfbSlotsLocal = nCldfbTs; - move16(); - Word16 temp, temp_e; - - /* get last subframe size from previous frame, determine how many slots have to be processed - in the first subframe (i.e. potential leftover of a 5ms subframe) */ - nSlotsInFirstSubframe = ( sub( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, subframe_nbslots[*nb_subframes - 1] ) ); - *nb_subframes = 0; - move16(); - IF( nSlotsInFirstSubframe > 0 ) - { - *nb_subframes = 1; - move16(); - nCldfbSlotsLocal = sub( nCldfbSlotsLocal, nSlotsInFirstSubframe ); - } - - temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e ); - *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0 - move16(); - nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME; - move16(); - - set16_fx( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set16_fx( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes ); - - IF( nSlotsInFirstSubframe > 0 ) - { - subframe_nbslots[0] = nSlotsInFirstSubframe; - move16(); - } - - IF( nSlotsInLastSubframe > 0 ) - { - subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe; - move16(); - } - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_adapted_linear_interpolator() - * - * Get an meta data map adapted to a time scale modified IVAS frame - *--------------------------------------------------------------------------*/ - -void ivas_jbm_dec_get_md_map( - const Word16 default_len, /* i : default frame length in metadata slots */ - const Word16 len, /* i : length of the modfied frames in metadata slots */ - const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ - const Word16 buf_len, /* i : length of the metadata buffer */ - Word16 *map /* o : metadata index map */ -) -{ - Word16 jbm_segment_len, map_idx, src_idx, src_idx_map; - Word32 dec_fx, src_idx_fx; - Word16 temp_e; - Word16 temp; - jbm_segment_len = shr( default_len, 1 ); - - FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) ) - { - temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); // Q0 - src_idx_map = s_max( 0, temp ); - map[map_idx] = add( offset, src_idx_map ) % buf_len; - move16(); - } - - /* changed part (first segment), interpolate index to parameters - (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */ - IF( src_idx >= 0 ) - { - dec_fx = BASOP_Util_Divide3232_Scale( L_shl( add( src_idx, 1 ), 16 ), jbm_segment_len, &temp_e ); - dec_fx = L_shr( dec_fx, sub( 15, temp_e ) ); - src_idx_fx = L_sub( L_shl( add( src_idx, 1 ), 16 ), dec_fx ); - FOR( ; map_idx >= 0; map_idx-- ) - { - temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); // Q0 - src_idx = s_max( 0, temp ); - map[map_idx] = add( offset, src_idx ) % buf_len; - src_idx_fx = L_sub( src_idx_fx, dec_fx ); - } - } - ELSE - { - set16_fx( map, offset, add( map_idx, 1 ) ); - } - - return; -} - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_md_map_even_spacing() - * - * Get an meta data map adapted to a time scale modified IVAS frame. Distribute slots evenly across the modified frame. - *--------------------------------------------------------------------------*/ - -void ivas_jbm_dec_get_md_map_even_spacing( - const Word16 len, /* i : length of the modfied frames in metadata slots */ - const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ - const Word16 buf_len, /* i : length of the metadata buffer */ - Word16 *map /* o : metadata index map */ -) -{ - Word16 map_idx, sf_idx, sf_length, increment, subframes_written; - Word32 decimal_fx, decimal_sum_fx, eps_fx; // q = 16 - Word16 subframe_map_length[MAX_PARAM_SPATIAL_SUBFRAMES]; - - /* subframe map length */ - sf_length = idiv1616( len, subframe_len ); - IF( len % subframe_len == 0 ) - { - /* even subframes */ - FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - subframe_map_length[sf_idx] = sf_length; - move16(); - } - } - ELSE - { - /* uneven subframes */ - Word32 temp; - Word16 temp_e; - temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e ); - temp = L_shr( temp, sub( 15, temp_e ) ); // Q16 - decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16 - decimal_sum_fx = decimal_fx; - - eps_fx = 65; - move32(); - move32(); - FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - increment = extract_l( L_shr( L_add( decimal_sum_fx, eps_fx ), 16 ) ); - subframe_map_length[sf_idx] = add( sf_length, increment ); - move16(); - IF( increment > 0 ) - { - decimal_sum_fx = L_sub( decimal_sum_fx, ONE_IN_Q16 ); - } - decimal_sum_fx = L_add( decimal_sum_fx, decimal_fx ); - } - } - - /* map slots to subframes */ - sf_idx = 0; - subframes_written = 0; - move16(); - move16(); - FOR( map_idx = 0; map_idx < len; map_idx++ ) - { - map[map_idx] = add( offset, sf_idx ) % buf_len; - move16(); - IF( GE_16( sub( map_idx, subframes_written ), sub( subframe_map_length[sf_idx], 1 ) ) ) - { - subframes_written = add( subframes_written, subframe_map_length[sf_idx] ); - sf_idx = add( sf_idx, 1 ); - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_num_tc_channels() - * - * Get the number of transport channels provided by the JBM transport channel decode function - *--------------------------------------------------------------------------*/ - - -Word16 ivas_jbm_dec_get_num_tc_channels_fx( - Decoder_Struct *st_ivas /* i : IVAS decoder handle */ -) -{ - Word16 num_tc; - Word32 ivas_total_brate; - AUDIO_CONFIG output_config; - - IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) - { - num_tc = st_ivas->hDecoderConfig->nchan_out; - move16(); - } - ELSE - { - num_tc = st_ivas->nchan_transport; - move16(); - } - output_config = st_ivas->hDecoderConfig->output_config; - move16(); - - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - move32(); - - test(); - test(); - test(); -#ifdef FIX_1435_MOVE_STEREO_PANNING - test(); - IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) - { - num_tc = 1; - move16(); - } - ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) -#else - IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) -#endif - { - num_tc = 1; - move16(); - } - ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) - { - if ( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) - { - num_tc = 1; - move16(); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - IF( st_ivas->sba_dirac_stereo_flag ) - { - num_tc = CPE_CHANNELS; - move16(); - } - ELSE IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && st_ivas->hCPE[0] != NULL && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) - { - num_tc = 1; /* Only one channel transported */ - move16(); - } - - test(); - test(); - test(); - test(); - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->nchan_transport, 2 ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) - { - num_tc = CPE_CHANNELS; - move16(); - } - IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) - { - if ( EQ_16( num_tc, 3 ) ) - { - num_tc = add( num_tc, 1 ); - } - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) - { - IF( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - test(); - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - num_tc = add( num_tc, 1 ); - } - ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) - { - num_tc = add( num_tc, st_ivas->nchan_ism ); - } - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - - - if ( st_ivas->sba_dirac_stereo_flag ) - { - num_tc = CPE_CHANNELS; - move16(); - } - - if ( EQ_16( num_tc, 3 ) ) - { - num_tc = add( num_tc, 1 ); - } - if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - num_tc = add( num_tc, st_ivas->nchan_ism ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) - { - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) - { - num_tc = 1; - move16(); - } - ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) - { - num_tc = 2; - move16(); - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) - { - /* do all static dmx already in the TC decoder if less channels than transported... */ - test(); - test(); - test(); - test(); - test(); - IF( NE_16( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) - { - if ( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) - { - num_tc = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); - } - } - ELSE IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) - { - num_tc = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); - } - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) - { - num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; - move16(); - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) - { - if ( st_ivas->hOutSetup.separateChannelEnabled ) - { - num_tc = add( num_tc, 1 ); - } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || - EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) ) - { - /* LFE is synthesized in TD with the TCs*/ - num_tc = add( num_tc, 1 ); - } - } - } -#ifndef FIX_1435_MOVE_STEREO_PANNING - ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) - { - num_tc = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; - move16(); - } -#endif - - return num_tc; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_render_granularity() - * - * - *--------------------------------------------------------------------------*/ - -/*! r: render granularity */ -Word16 ivas_jbm_dec_get_render_granularity_fx( - const RENDERER_TYPE renderer_type, /* i : renderer type */ - const RENDERER_TYPE renderer_type_sec, /* i : secondary renderer type */ - const Word32 output_Fs /* i : sampling rate */ -) -{ - Word16 render_granularity; - - test(); - test(); - test(); - IF( EQ_32( renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || /* TD renderer */ - EQ_32( renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) || /* Crend */ - EQ_32( renderer_type_sec, RENDERER_BINAURAL_OBJECTS_TD ) /* TD rend as a secondary renderer -> set the common granularity for both renderers */ - ) - { - /* 5 ms granularity */ - render_granularity = NS2SA_FX2( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - move16(); - } - ELSE - { - /* 1.25 ms granularity */ - render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ); - move16(); - } - - return render_granularity; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc_audio_allocate() - * - * allocate and initialize TC audio buffer - *--------------------------------------------------------------------------*/ - -static ivas_error ivas_jbm_dec_tc_audio_allocate_fx( - DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM TSM buffer handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 Opt_tsm /* i : TSM option flag */ -) -{ - Word16 nsamp_to_allocate; - Word16 ch_idx, n_samp_full, n_samp_residual, offset; - - IF( Opt_tsm ) - { - n_samp_full = NS2SA_FX2( output_Fs, MAX_JBM_L_FRAME_NS ); - n_samp_full = s_max( n_samp_full, L_FRAME48k ); /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': ensure minimal length */ - n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); - } - ELSE - { - n_samp_full = extract_l( Mpy_32_32( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - n_samp_residual = 0; - move16(); - } - - nsamp_to_allocate = imult1616( s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ), n_samp_full ); - - IF( Opt_tsm ) - { - /* note: this is stack memory buffer for time-scale modified audio signals */ - IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); - } - set_zero_fx( hTcBuffer->tc_buffer_fx, nsamp_to_allocate ); - - offset = 0; - move16(); - FOR( ch_idx = 0; ch_idx < s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; - offset = add( offset, n_samp_full ); - } - FOR( ; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - - /* memory buffer for TC audio samples not rendered in the previous frame */ - FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) - { - IF( ( hTcBuffer->tc_buffer_old_fx[ch_idx] = (Word32 *) malloc( n_samp_residual * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); - } - set_zero_fx( hTcBuffer->tc_buffer_old_fx[ch_idx], n_samp_residual ); - } - FOR( ; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) - { - hTcBuffer->tc_buffer_old_fx[ch_idx] = NULL; - } - } - else - { - hTcBuffer->tc_buffer_fx = NULL; - - FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - - FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) - { - hTcBuffer->tc_buffer_old_fx[ch_idx] = NULL; - } - } - - hTcBuffer->tc_buffer2_fx = NULL; - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc_audio_deallocate() - * - * deallocate TC audio buffer - *--------------------------------------------------------------------------*/ - -static void ivas_jbm_dec_tc_audio_deallocate_fx( - DECODER_TC_BUFFER_HANDLE hTcBuffer /* i/o: JBM TSM buffer handle */ -) -{ - Word16 ch_idx; - - IF( hTcBuffer != NULL ) - { - IF( hTcBuffer->tc_buffer_fx != NULL ) - { - FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - - free( hTcBuffer->tc_buffer_fx ); - hTcBuffer->tc_buffer_fx = NULL; - } - - FOR( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ ) - { - IF( hTcBuffer->tc_buffer_old_fx[ch_idx] != NULL ) - { - free( hTcBuffer->tc_buffer_old_fx[ch_idx] ); - hTcBuffer->tc_buffer_old_fx[ch_idx] = NULL; - } - } - - IF( hTcBuffer->tc_buffer2_fx != NULL ) - { - free( hTcBuffer->tc_buffer2_fx ); - hTcBuffer->tc_buffer2_fx = NULL; - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc_buffer_open() - * - * open and initialize JBM transport channel buffer - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_tc_buffer_open_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */ - const Word16 nchan_transport_jbm, /* i : number of real transport channels */ - const Word16 nchan_transport_internal, /* i : number of totally buffered channels */ - const Word16 nchan_full, /* i : number of channels to fully store */ - const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ -) -{ - DECODER_TC_BUFFER_HANDLE hTcBuffer; - Word16 nMaxSlotsPerSubframe; - ivas_error error; - Word16 tmp, tmp_e; - - /*-----------------------------------------------------------------* - * prepare library opening - *-----------------------------------------------------------------*/ - - IF( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) ); - } - - hTcBuffer->tc_buffer_mode = tc_buffer_mode; - move16(); - hTcBuffer->nchan_transport_jbm = nchan_transport_jbm; - move16(); - hTcBuffer->nchan_transport_internal = nchan_transport_internal; - move16(); - hTcBuffer->nchan_buffer_full = nchan_full; - move16(); - hTcBuffer->n_samples_granularity = n_samples_granularity; - move16(); - hTcBuffer->n_samples_available = 0; - move16(); - hTcBuffer->n_samples_buffered = 0; - move16(); - hTcBuffer->n_samples_rendered = 0; - move16(); - hTcBuffer->slots_rendered = 0; - move16(); - hTcBuffer->subframes_rendered = 0; - move16(); - hTcBuffer->n_samples_discard = 0; - move16(); - hTcBuffer->n_samples_flushed = 0; - move16(); - hTcBuffer->nb_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; - move16(); - - /* nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity; */ - tmp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); - tmp = BASOP_Util_Divide1616_Scale( tmp, hTcBuffer->n_samples_granularity, &tmp_e ); - nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ - - hTcBuffer->num_slots = mult0( nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES ); - move16(); - - set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES ); - - IF( ( error = ivas_jbm_dec_tc_audio_allocate_fx( hTcBuffer, st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->Opt_tsm ) ) != IVAS_ERR_OK ) - { - return error; - } - - st_ivas->hTcBuffer = hTcBuffer; - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc_buffer_reconfigure() - * - * open and initialize JBM transport channel buffer - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */ - const Word16 nchan_transport_jbm, /* i : new number of real transport channels */ - const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */ - const Word16 nchan_full, /* i : new number of channels to fully store */ - const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */ -) -{ - Word16 ch_idx, num_tc_buffer_mem, n_samples_still_available; - Word32 tc_buffer_mem[MAX_INTERN_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES - 1]; - ivas_error error; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - move16(); - - num_tc_buffer_mem = 0; - move16(); - n_samples_still_available = 0; - move16(); - - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - /* save samples of the TC buffer from the previous frame */ - num_tc_buffer_mem = s_min( hTcBuffer->nchan_transport_internal, nchan_transport_internal ); - n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered ); - - /* what is remaining from last frame needs always be smaller than the new granularity */ - assert( n_samples_still_available < n_samples_granularity ); - - FOR( ch_idx = 0; ch_idx < num_tc_buffer_mem; ch_idx++ ) - { - Copy32( hTcBuffer->tc_buffer_old_fx[ch_idx] + hTcBuffer->n_samples_flushed, tc_buffer_mem[ch_idx], n_samples_still_available ); - } - } - - /* if granularity changes, adapt subframe_nb_slots */ - IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) ) - { - Word16 nMaxSlotsPerSubframeNew; - Word16 tmp, tmp_e; - - /* nMaxSlotsPerSubframeNew = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / n_samples_granularity; */ - tmp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); - tmp = BASOP_Util_Divide1616_Scale( tmp, n_samples_granularity, &tmp_e ); - nMaxSlotsPerSubframeNew = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ - - /* if samples were flushed, take that into account here */ - test(); - IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 ) - { - hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = idiv1616( hTcBuffer->n_samples_flushed, n_samples_granularity ); - hTcBuffer->n_samples_flushed = 0; - move16(); - move16(); - } - ELSE - { - hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = nMaxSlotsPerSubframeNew; - move16(); - } - } - - hTcBuffer->tc_buffer_mode = tc_buffer_mode; - move16(); - hTcBuffer->nchan_transport_jbm = nchan_transport_jbm; - move16(); - hTcBuffer->nchan_transport_internal = nchan_transport_internal; - move16(); - hTcBuffer->nchan_buffer_full = nchan_full; - move16(); - hTcBuffer->n_samples_granularity = n_samples_granularity; - move16(); - - /* reallocate TC audio buffers */ - - ivas_jbm_dec_tc_audio_deallocate_fx( hTcBuffer ); - - IF( ( error = ivas_jbm_dec_tc_audio_allocate_fx( hTcBuffer, st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->Opt_tsm ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* propagate samples of the TC buffer from the previous frame */ - FOR( ch_idx = 0; ch_idx < num_tc_buffer_mem; ch_idx++ ) - { - Copy32( tc_buffer_mem[ch_idx], hTcBuffer->tc_buffer_old_fx[ch_idx], n_samples_still_available ); - } - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc_buffer_playout() - * - * - *--------------------------------------------------------------------------*/ - -static void ivas_jbm_dec_tc_buffer_playout_fx( - Decoder_Struct *st_ivas, - const UWord16 nSamplesAsked, - UWord16 *nSamplesRendered, - Word32 *output_fx[] /*Q11*/ -) -{ - Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e; - - slot_size = st_ivas->hTcBuffer->n_samples_granularity; - move16(); - - /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); - tmp = shr( tmp, sub( 15, e ) ); // Q0 - slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), tmp ); - st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); // Q0 - *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size ); - first_sf = st_ivas->hTcBuffer->subframes_rendered; - last_sf = first_sf; - move16(); - move16(); - move16(); - move16(); - - WHILE( slots_to_render > 0 ) - { - slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] ); - last_sf = add( last_sf, 1 ); - } -#ifdef DEBUGGING - assert( slots_to_render == 0 ); -#endif - - FOR( ch_idx = 0; ch_idx < st_ivas->hTcBuffer->nchan_transport_jbm; ch_idx++ ) - { - output_fx[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered; - move32(); - } - - st_ivas->hTcBuffer->subframes_rendered = last_sf; - move16(); - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_tc_buffer_close() - * - * Close JBM transport channel buffer - *--------------------------------------------------------------------------*/ - -void ivas_jbm_dec_tc_buffer_close_fx( - DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */ -) -{ - IF( *phTcBuffer != NULL ) - { - ivas_jbm_dec_tc_audio_deallocate_fx( *phTcBuffer ); - - free( *phTcBuffer ); - *phTcBuffer = NULL; - } - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_td_renderers_adapt_subframes() - * - * Close JBM transport channel buffer - *--------------------------------------------------------------------------*/ - -void ivas_jbm_dec_td_renderers_adapt_subframes( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) -{ - Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, tmp_e, tmp1, tmp2, s1, s2; - UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe; - - /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */ - tmp = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); - tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &tmp_e ); - nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ - - /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */ - tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &tmp_e ); - nSlotsAvailable = shr( tmp, sub( 15, tmp_e ) ); /* Q0 */ - - st_ivas->hTcBuffer->num_slots = nSlotsAvailable; - move16(); - /* st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; */ - st_ivas->hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, st_ivas->hTcBuffer->n_samples_granularity ); - move16(); - nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); - st_ivas->hTcBuffer->nb_subframes = 0; - move16(); - - IF( nSlotsInFirstSubframe > 0 ) - { - st_ivas->hTcBuffer->nb_subframes = 1; - move16(); - nSlotsAvailable = sub( nSlotsAvailable, nSlotsInFirstSubframe ); - } - - s1 = sub( norm_s( nSlotsAvailable ), 1 ); - s2 = norm_s( nMaxSlotsPerSubframe ); - - tmp1 = shl( nSlotsAvailable, s1 ); - tmp2 = shl( nMaxSlotsPerSubframe, s2 ); - - tmp = div_s( tmp1, tmp2 ); - st_ivas->hTcBuffer->nb_subframes = add( st_ivas->hTcBuffer->nb_subframes, ceil_fx16( tmp, sub( 15, sub( s2, s1 ) ) ) ); - move16(); - - nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe; - move16(); - set16_fx( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set16_fx( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes ); - - if ( nSlotsInFirstSubframe > 0 ) - { - st_ivas->hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe; - move16(); - } - - if ( nSlotsInLastSubframe > 0 ) - { - st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe; - move16(); - } - - st_ivas->hTcBuffer->slots_rendered = 0; - move16(); - st_ivas->hTcBuffer->subframes_rendered = 0; - move16(); - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_get_tc_buffer_mode() - * - * - *--------------------------------------------------------------------------*/ - -TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) -{ - TC_BUFFER_MODE buffer_mode; - - buffer_mode = TC_BUFFER_MODE_BUFFER; - move16(); - - SWITCH( st_ivas->renderer_type ) - { - /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */ - case RENDERER_DISABLE: - case RENDERER_MCMASA_MONO_STEREO: - case RENDERER_OSBA_STEREO: - case RENDERER_MONO_DOWNMIX: - buffer_mode = TC_BUFFER_MODE_BUFFER; - move16(); - BREAK; -#ifdef FIX_1435_MOVE_STEREO_PANNING - case RENDERER_NON_DIEGETIC_DOWNMIX: -#endif - case RENDERER_TD_PANNING: - case RENDERER_BINAURAL_OBJECTS_TD: - case RENDERER_BINAURAL_FASTCONV: - case RENDERER_BINAURAL_FASTCONV_ROOM: - case RENDERER_BINAURAL_PARAMETRIC: - case RENDERER_BINAURAL_PARAMETRIC_ROOM: - case RENDERER_STEREO_PARAMETRIC: - case RENDERER_DIRAC: - case RENDERER_PARAM_ISM: - case RENDERER_BINAURAL_MIXER_CONV: - case RENDERER_BINAURAL_MIXER_CONV_ROOM: - case RENDERER_OMASA_OBJECT_EXT: - case RENDERER_OMASA_MIX_EXT: - case RENDERER_OSBA_AMBI: - case RENDERER_OSBA_LS: - buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); - BREAK; -#ifndef FIX_1435_MOVE_STEREO_PANNING - case RENDERER_NON_DIEGETIC_DOWNMIX: - IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) - { - buffer_mode = TC_BUFFER_MODE_BUFFER; - move16(); - } - ELSE - { - buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); - } - break; -#endif - case RENDERER_MC_PARAMMC: - IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) - { - buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */ - move16(); - } - ELSE - { - buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); - } - BREAK; - case RENDERER_MC: - if ( NE_16( ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) ) - { - buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); - } - BREAK; - case RENDERER_SBA_LINEAR_ENC: - test(); - test(); - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( ( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), ( add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) ) - { - buffer_mode = TC_BUFFER_MODE_BUFFER; - move16(); - } - ELSE - { - buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); - } - BREAK; - case RENDERER_SBA_LINEAR_DEC: - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) - { - buffer_mode = TC_BUFFER_MODE_BUFFER; - move16(); - } - ELSE - { - buffer_mode = TC_BUFFER_MODE_RENDERER; - move16(); - } - BREAK; - } - - return buffer_mode; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_metadata_open() - * - * Open structure for metadata buffering in JBM - *--------------------------------------------------------------------------*/ - -ivas_error ivas_jbm_dec_metadata_open( - Decoder_Struct *st_ivas ) -{ - JBM_METADATA_HANDLE hJbmMetadata; - - IF( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) ); - } - - hJbmMetadata->sf_write_idx = 0; - move16(); - hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES; - move16(); - - hJbmMetadata->slot_write_idx = 0; - move16(); - hJbmMetadata->slot_read_idx = 0; - move16(); - hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - move16(); - - st_ivas->hJbmMetadata = hJbmMetadata; - - return IVAS_ERR_OK; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_dec_copy_masa_meta_to_buffer() - * - * Copy decoded MASA metadata to a ring buffer - *--------------------------------------------------------------------------*/ - -static void ivas_jbm_dec_copy_masa_meta_to_buffer( - Decoder_Struct *st_ivas ) -{ - Word16 sf, dir, band; - JBM_METADATA_HANDLE hJbmMetadata; - MASA_DECODER_EXT_OUT_META *extOutMeta; - Word16 write_idx; - - hJbmMetadata = st_ivas->hJbmMetadata; - extOutMeta = st_ivas->hMasa->data.extOutMeta; - - FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) - { - write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length; - move16(); - FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) - { - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) - { - hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band]; - move16(); - hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band]; - move16(); - hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band]; - move16(); - } - } - - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) - { - hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band]; - move16(); - hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band]; - move16(); - } - - hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections; - move16(); - } - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_jbm_masa_sf_to_slot_map() - * - * Map input MASA metadata subframes to slots in JBM processing - *--------------------------------------------------------------------------*/ - -static void ivas_jbm_masa_sf_to_slot_map( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nCldfbTs /* i : number of CLDFB time slots */ -) -{ - Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; - Word16 num_slots_in_subfr; - JBM_METADATA_HANDLE hJbmMetadata; - Word16 slot_idx; - Word16 write_idx, sf_index; - - ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas ); - - /* Set values */ - hJbmMetadata = st_ivas->hJbmMetadata; - num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; - move16(); - - /* Map input subframes to slots */ - ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map ); - - FOR( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ ) - { - write_idx = ( add( hJbmMetadata->slot_write_idx, slot_idx ) ) % hJbmMetadata->slot_md_buffer_length; - move16(); - sf_index = ( add( hJbmMetadata->sf_write_idx, sf_to_slot_map[slot_idx] ) ) % hJbmMetadata->sf_md_buffer_length; - move16(); - - hJbmMetadata->sf_to_slot_map[write_idx] = sf_index; - move16(); - } - - hJbmMetadata->sf_write_idx = ( add( hJbmMetadata->sf_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) ) % hJbmMetadata->sf_md_buffer_length; - move16(); - hJbmMetadata->slot_write_idx = ( add( hJbmMetadata->slot_write_idx, nCldfbTs ) ) % hJbmMetadata->slot_md_buffer_length; - move16(); - - return; -} - -/*--------------------------------------------------------------------------* - * ivas_jbm_masa_sf_to_sf_map() - * - * Map input MASA metadata subframes to output subframes in JBM processing - *--------------------------------------------------------------------------*/ - -void ivas_jbm_masa_sf_to_sf_map( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) -{ - Word16 sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES]; - JBM_METADATA_HANDLE hJbmMetadata; - MASA_DECODER_EXT_OUT_META *extOutMeta; - Word16 slot_read_idx, sf_read_idx; - Word16 sf_idx; - Word16 dir, band; - UWord8 numberOfDirections; - - /* Set values */ - hJbmMetadata = st_ivas->hJbmMetadata; - extOutMeta = st_ivas->hMasa->data.extOutMeta; - - /* Map slots to subframes */ - FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - slot_read_idx = ( add( hJbmMetadata->slot_read_idx, 2 ) ) % hJbmMetadata->slot_md_buffer_length; /* Take the latter one of the middle slots of the output subframe */ - move16(); - sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx]; - move16(); - hJbmMetadata->slot_read_idx = ( add( hJbmMetadata->slot_read_idx, CLDFB_SLOTS_PER_SUBFRAME ) ) % hJbmMetadata->slot_md_buffer_length; - move16(); - } - - /* Copy mapped metadata to the EXT meta buffer for writing */ - FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - sf_read_idx = sf_to_sf_map[sf_idx]; - move16(); - - FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ ) - { - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) - { - extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band]; - move16(); - extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band]; - move16(); - extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band]; - move16(); - } - } - - FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) - { - extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band]; - move16(); - extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band]; - move16(); - } - } - - /* Determine the number of directions for the frame to be written */ - numberOfDirections = 0; - move16(); - FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - sf_read_idx = sf_to_sf_map[sf_idx]; - move16(); - - IF( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 ) - { - numberOfDirections = 1; - move16(); - BREAK; - } - } - - extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections; - move16(); - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_dec_prepare_renderer() - * - * prepare IVAS renderer routine - *--------------------------------------------------------------------------*/ - -void ivas_dec_prepare_renderer_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) -{ - Word16 n, n_render_timeslots, tmp, exp, shift; - - push_wmops( "ivas_dec_prepare_renderer" ); - - /* n_render_timeslots = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */ - tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp ); - n_render_timeslots = shr( tmp, sub( 15, exp ) ); // Q0 - - test(); - IF( EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) - { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - - test(); - test(); - test(); - IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && st_ivas->hDecoderConfig->Opt_tsm ) - { - ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots ); - } - /* MASA transport gaining for edited disc OMASA EXT. For ISMs, only metadata is modified */ - test(); - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->hMasaIsmData->masa_gain_is_edited, 1 ) ) - { - ivas_omasa_gain_masa_tc_fx( st_ivas->hTcBuffer->tc_fx, st_ivas->hMasaIsmData->gain_masa_edited_fx, st_ivas->nchan_ism, st_ivas->hTcBuffer->n_samples_available ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) || EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - } - ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) ) - { - /* Rendering */ - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) - { - test(); - test(); - test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots ); - - ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas ); - } - ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) - { - ivas_param_ism_dec_prepare_renderer_fx( st_ivas, n_render_timeslots ); - } - } - ELSE /* ISM_MODE_DISC */ - { - ivas_ism_dec_digest_tc_fx( st_ivas ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) - { - IF( st_ivas->hSCE[0] ) - { - shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) - { - shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); - } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); - } - - ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) - { - IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - ivas_ism_dec_digest_tc_fx( st_ivas ); - - test(); - test(); - test(); - test(); - test(); - test(); - /* delay the objects here for all renderers where it is needed */ - IF( - ( - EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || - EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || - EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || - EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) || - EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) && - ( NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) - { - FOR( n = 0; n < st_ivas->nchan_ism; n++ ) - { - delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer_fx[n], st_ivas->hSbaIsmData->delayBuffer_size ); - } - } - - IF( !st_ivas->sba_dirac_stereo_flag ) - { - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) - { - Word16 temp, temp_e; - temp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size, &temp_e ); - n_render_timeslots = extract_l( L_shr( L_mult0( n_render_timeslots, temp ), sub( 15, temp_e ) ) ); - } - - IF( st_ivas->hSCE[0] ) - { - shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) - { - shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); - } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); - } - ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - } - } - ELSE - { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - - IF( st_ivas->hSCE[0] ) - { - shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) - { - shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); - } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); - } - - ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) - { - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) - { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots ); - } - /* MASA transport gaining for edited param_one OMASA EXT. For ISMs, only metadata is modified. */ - test(); - IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && EQ_16( st_ivas->hMasaIsmData->masa_gain_is_edited, 1 ) ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - v_multc_fx_16( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available ); // Q8 - Scale_sig32( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, Q3 ); // Q8 -> Q11 - } - } - } - ELSE - { - test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) - { - n_render_timeslots = i_mult( n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) ); - } - - IF( st_ivas->hSCE[0] ) - { - shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) - { - shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); - } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift) - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); - move16(); - } - - ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) - { - ivas_ism_dec_digest_tc_fx( st_ivas ); - } - } - - test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) ) - { - Word16 nchan_transport_ism; - - /* Delay the signal to match CLDFB delay. Delay the whole buffer. */ - nchan_transport_ism = 0; - move16(); - - test(); - test(); - IF( ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) - { - nchan_transport_ism = 1; - move16(); - } - ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) - { - nchan_transport_ism = st_ivas->nchan_ism; - move16(); - } - - test(); - test(); - IF( st_ivas->hDecoderConfig->Opt_tsm && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) - { - /* Gain MASA part, if edited */ - IF( st_ivas->hMasaIsmData->masa_gain_is_edited ) - { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - v_multc_fx_16( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available ); - Scale_sig32( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, Q3 ); // Q8 -> Q11 - } - } - } - - FOR( n = 0; n < nchan_transport_ism; n++ ) - { - test(); - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) - { - v_multc_fx_16( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN_FX, st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available ); - - IF( st_ivas->hMasaIsmData->ism_gain_is_edited[n] ) - { - v_multc_fx_16( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hMasaIsmData->gain_ism_edited_fx[n], st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available ); - Scale_sig32( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available, Q3 ); // Q8 -> Q11 - } - } - - test(); - IF( NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); - } - } - - test(); - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) - { - IF( st_ivas->hMasaIsmData->masa_gain_is_edited ) - { - FOR( n = 0; n < BINAURAL_CHANNELS; n++ ) - { - v_multc_fx_16( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available ); // Q8 - Scale_sig32( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, Q3 ); // Q8 -> Q11 - } - } - } - } - } - ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) - { - IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) - { - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) - { - ivas_mc_paramupmix_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) - { - Word16 nchan_transport = st_ivas->nchan_transport; - move16(); - Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - Word16 nchan_out_cov; - - test(); - test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) - { - nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - } - ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) - { - nchan_out_cov = nchan_out_transport; - move16(); - } - ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) - { - nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); - } - ELSE - { - nchan_out_cov = nchan_out_transport; - move16(); - } - - scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1) - st_ivas->hParamMC->proto_matrix_int_e = 1; - move16(); - - ivas_param_mc_dec_prepare_renderer( st_ivas, (UWord8) n_render_timeslots ); - - scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1) - - FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) - { - shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift) - st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift ); - move16(); - - shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift) - st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift ); - move16(); - } - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) - { - IF( st_ivas->hSCE[0] ) - { - shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); - if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) ) - { - shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); - } - scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift) - st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ); - move16(); - } - - ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); - } - } - - pop_wmops(); - return; -} diff --git a/lib_dec/ivas_lfe_dec_fx.c b/lib_dec/ivas_lfe_dec_fx.c index 74d8de662ea8aadd99c86363b514d42e8164fe1e..20b2ac7c72be1af61f308794e502fb0b0a7ccdfd 100644 --- a/lib_dec/ivas_lfe_dec_fx.c +++ b/lib_dec/ivas_lfe_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "rom_com.h" -#include "math.h" #include "wmc_auto.h" @@ -408,7 +407,7 @@ void ivas_lfe_dec_fx( IF( hLFE->filter_state.order > 0 ) { /* Low Pass Filter */ - ivas_filter_process_fx( &hLFE->filter_state, output_lfe_ch, output_frame, q_out ); + ivas_filter_process_fx32( &hLFE->filter_state, output_lfe_ch, output_frame ); } /* add delay to make overall max(block_offset, 11.5) */ diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index ac6da67598a31774ff7531ede0ba5a9052886a02..0d3da5e33e91f6b88914702a6a356d892cdcdf79 100755 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,7 +34,6 @@ #include "options.h" #include "prot_fx.h" #include "ivas_rom_com.h" -#include #include "wmc_auto.h" #include "ivas_prot_fx.h" diff --git a/lib_dec/ivas_ls_custom_dec_fx.c b/lib_dec/ivas_ls_custom_dec_fx.c index 5ad390f9a66786ed847e1f78cc278c1fa165826c..b6ae99039b6a6d5fcaf06fe46d23ba253dc56559 100644 --- a/lib_dec/ivas_ls_custom_dec_fx.c +++ b/lib_dec/ivas_ls_custom_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_masa_dec_fx.c b/lib_dec/ivas_masa_dec_fx.c index b91e5233c1bb34037043e31c5fe0bc9b4e7f4f82..140eb764de581bae399a18050ec25be7ec8da890 100644 --- a/lib_dec/ivas_masa_dec_fx.c +++ b/lib_dec/ivas_masa_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,12 +31,10 @@ *******************************************************************************************************/ #include -#include #include #include "options.h" #include "ivas_cnst.h" #include "ivas_prot_rend_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_stat_dec.h" #include "prot_fx.h" @@ -51,6 +49,9 @@ #define SPAR_META_DELAY_SUBFRAMES 2 /* Number of subframes to delay the SPAR metadata */ #define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */ +#define TOLERANCE_360_Q22 1510033326 /* 360 in Q22 + 0.02 in Q22*/ +#define MINUS_TOLERANCE_360_Q22 -1510033326 /* - (360 in Q22 + 0.02 in Q22) */ + /*-----------------------------------------------------------------------* * Local function prototypes @@ -924,7 +925,7 @@ ivas_error ivas_masa_dec_open_fx( move16(); } - nchan_transport = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + nchan_transport = ivas_dec_get_num_tc_channels_fx( st_ivas ); nchan_to_allocate = nchan_transport; move16(); @@ -950,9 +951,9 @@ ivas_error ivas_masa_dec_open_fx( nchan_to_allocate = add( nchan_to_allocate, 1 ); } - granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); + granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_transport, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_transport, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) { return error; } @@ -1936,7 +1937,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate ); /*-----------------------------------------------------------------* - * JBM TC buffers + * TC buffer *-----------------------------------------------------------------*/ { Word16 tc_nchan_to_allocate; @@ -1944,9 +1945,9 @@ ivas_error ivas_masa_dec_reconfigure_fx( TC_BUFFER_MODE buffer_mode_new; Word16 n_samples_granularity; - n_samples_granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); - buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode_fx( st_ivas ); - tc_nchan_transport = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + n_samples_granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); + buffer_mode_new = ivas_dec_get_tc_buffer_mode_fx( st_ivas ); + tc_nchan_transport = ivas_dec_get_num_tc_channels_fx( st_ivas ); tc_nchan_to_allocate = tc_nchan_transport; move16(); @@ -2006,11 +2007,13 @@ ivas_error ivas_masa_dec_reconfigure_fx( tc_nchan_transport = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); tc_nchan_to_allocate = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); } + + /* reconfigure TC buffer */ test(); test(); - IF( NE_16( tc_nchan_transport, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( buffer_mode_new, st_ivas->hTcBuffer->tc_buffer_mode ) ) + IF( NE_16( tc_nchan_transport, st_ivas->hTcBuffer->nchan_transport_rend ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( buffer_mode_new, st_ivas->hTcBuffer->tc_buffer_mode ) ) { - IF( NE_32( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ), IVAS_ERR_OK ) ) + IF( NE_32( error = ivas_dec_tc_buffer_reconfigure_fx( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index 478a4d00d1579ae7e5504072b4bf5457c3af6db5..fcfc9f911109b5a2429f3d85b3502f0e4a51f832 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,25 +33,20 @@ #include #include "options.h" #include -#include "cnst.h" -#include "rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" -#include "math.h" #include "wmc_auto.h" -#include "rom_dec.h" #include "ivas_prot_fx.h" -#define INV_EPSILON_MANT 214748365 - /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ +#define INV_EPSILON_MANT 214748365 + #define PARAM_MC_LOCAL_SZ_LFE_MAP 5 /*-----------------------------------------------------------------------* @@ -528,9 +523,9 @@ ivas_error ivas_param_mc_dec_open_fx( IF( st_ivas->hTcBuffer == NULL ) { - granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); + granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -1525,7 +1520,7 @@ void ivas_param_mc_dec_digest_tc_fx( /* Initialization */ num_freq_bands = st_ivas->hParamMC->num_freq_bands; move16(); - n_ch_cldfb = sub( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ); + n_ch_cldfb = sub( st_ivas->hTcBuffer->nchan_transport_rend, st_ivas->hTcBuffer->nchan_buffer_full ); cldfb_real_buffer = st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx; cldfb_imag_buffer = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx; @@ -1647,7 +1642,7 @@ void ivas_param_mc_dec_prepare_renderer( move16(); hParamMC->subframes_rendered = 0; move16(); - ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes ); + ivas_dec_get_adapted_subframes_fx( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes ); st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes; move16(); Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes ); @@ -2613,7 +2608,7 @@ static void ivas_param_mc_dec_compute_interpolator_fx( } ELSE { - ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator ); + ivas_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator ); } return; @@ -3147,6 +3142,7 @@ static void ivas_param_mc_dequantize_cov_fx( const PARAM_MC_ILD_MAPPING *h_ild_mapping; Word32 Cy_state_int_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; + Word16 nY_norm; set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS ); set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS ); @@ -3400,22 +3396,26 @@ static void ivas_param_mc_dequantize_cov_fx( Cyp_e += nY_cov; } } + nY_norm = nY_cov; + move16(); } ELSE { Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) ); Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) ); + nY_norm = nY_int; + move16(); } /*normalize output matrix to a common exponent*/ tmp = 0; - FOR( k = 0; k < nY_int * nY_int; k++ ) + FOR( k = 0; k < nY_norm * nY_norm; k++ ) { Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] ); move32(); tmp = s_max( tmp, Cy_buf_e[k] ); } - FOR( k = 0; k < nY_int * nY_int; k++ ) + FOR( k = 0; k < nY_norm * nY_norm; k++ ) { L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) ); Cy_state_fx[k] = L_tmp; diff --git a/lib_dec/ivas_mc_paramupmix_dec_fx.c b/lib_dec/ivas_mc_paramupmix_dec_fx.c index 889a7b37829ffa2da94079ee20848198f8c53f1d..608644c7246dbebee4c9893f8b29e81ec5a1a889 100644 --- a/lib_dec/ivas_mc_paramupmix_dec_fx.c +++ b/lib_dec/ivas_mc_paramupmix_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,17 +33,13 @@ #include #include #include "options.h" -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" -#include "math.h" #include "wmc_auto.h" -#include "rom_dec.h" /*-----------------------------------------------------------------------* @@ -220,9 +216,9 @@ void ivas_mc_paramupmix_dec_digest_tc_fx( ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering ); /* adapt subframes */ - ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas ); + ivas_dec_td_renderers_adapt_subframes_fx( st_ivas ); - ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator_fx ); + ivas_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator_fx ); pop_wmops(); return; @@ -403,10 +399,11 @@ ivas_error ivas_mc_paramupmix_dec_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); } + hMCParamUpmix->free_param_interpolator = 1; move16(); - ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator_fx ); + ivas_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator_fx ); IF( st_ivas->hTcBuffer == NULL ) { @@ -416,7 +413,7 @@ ivas_error ivas_mc_paramupmix_dec_open( TC_BUFFER_MODE buffer_mode; buffer_mode = TC_BUFFER_MODE_RENDERER; - nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + nchan_tc = ivas_dec_get_num_tc_channels_fx( st_ivas ); nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; move16(); move16(); @@ -439,9 +436,9 @@ ivas_error ivas_mc_paramupmix_dec_open( move16(); } - granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); + granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -500,12 +497,12 @@ void ivas_mc_paramupmix_dec_close( /*------------------------------------------------------------------------- - * paramupmix_td_decorr_process_jbm_fx() + * paramupmix_td_decorr_process() * * *------------------------------------------------------------------------*/ -static void paramupmix_td_decorr_process_jbm_fx( +static void paramupmix_td_decorr_process_fx( ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle */ Word32 *pcm_in[], /* i : input audio channels */ Word32 **pp_out_pcm, /* o : output audio channels */ @@ -565,8 +562,9 @@ static void paramupmix_td_decorr_process_jbm_fx( *------------------------------------------------------------------------*/ static void ivas_param_upmix_dec_decorr_subframes( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 nSamplesForRendering ) + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +) { MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; Word32 *pPcm_tmp_fx[MC_PARAMUPMIX_COMBINATIONS]; @@ -595,23 +593,21 @@ static void ivas_param_upmix_dec_decorr_subframes( WHILE( nSamplesLeftForTD ) { Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); + Word16 i, q_format[MC_PARAMUPMIX_COMBINATIONS]; + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - Word16 i, q_format[MC_PARAMUPMIX_COMBINATIONS]; - - FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) - { - q_format[i] = Q11; - move16(); - } + q_format[i] = Q11; + move16(); + } - paramupmix_td_decorr_process_jbm_fx( hMCParamUpmix->hTdDecorr, p_tc_fx, pPcm_tmp_fx, nSamplesToDecorr, q_format ); + paramupmix_td_decorr_process_fx( hMCParamUpmix->hTdDecorr, p_tc_fx, pPcm_tmp_fx, nSamplesToDecorr, q_format ); - FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) - { - Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); // Setting Q to changed q in q_format - } + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); // Setting Q to changed q in q_format } + FOR( ch = 0; ch < nchan_internal; ch++ ) { p_tc_fx[ch] += nSamplesToDecorr; diff --git a/lib_dec/ivas_mcmasa_dec_fx.c b/lib_dec/ivas_mcmasa_dec_fx.c index d12b190c640728b55825a1a5a4b948591e481b70..b4fa9d08cc31ce1158e4c0dcbfa328d7b07ccf2e 100644 --- a/lib_dec/ivas_mcmasa_dec_fx.c +++ b/lib_dec/ivas_mcmasa_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_mct_core_dec_fx.c b/lib_dec/ivas_mct_core_dec_fx.c index f96a20126250b065cfcc5d50b404ae4c780ba283..2bba7429bdcd74fed0b6e3aba0416dfde11fbc9c 100644 --- a/lib_dec/ivas_mct_core_dec_fx.c +++ b/lib_dec/ivas_mct_core_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,15 +34,12 @@ #include #include "options.h" #include "prot_fx.h" -#include "rom_com.h" #include "wmc_auto.h" -#include "cnst.h" +#include "ivas_cnst.h" #include "basop_proto_func.h" -#include "stat_com.h" -#include "ivas_stat_dec.h" -#include "ivas_stat_com.h" #include "ivas_prot_fx.h" + /*-----------------------------------------------------------------* * ivas_mct_side_bits() * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index b88d95b18e324ebcdc056424793aa0d103634f84..73993d99a213655b8e8e08b7937877f6a7ad88af 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,10 +33,7 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_rom_com.h" @@ -217,22 +214,40 @@ ivas_error ivas_mct_dec_fx( } } - Word32 Aq_fx_32[6][2][102]; /* MCT reconstruction and CoreCoder updates */ FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { + Word32 Aq_fx_32[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; hCPE = st_ivas->hCPE[cpe_id]; FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy_Scale_sig_16_32_DEPREC( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); // Q16 - x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 - x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 +#ifdef FIX_2397_COPY_AQ_MDCT_CORE_BFI + test(); + IF( !st_ivas->bfi && NE_16( hCPE->hCoreCoder[n]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) +#else + IF( NE_16( hCPE->hCoreCoder[n]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) +#endif + { + Word16 nSubframes; + + nSubframes = 1; /* Q0 */ + move16(); + if ( EQ_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) + { + nSubframes = NB_DIV; + move16(); + } + + Copy_Scale_sig_16_32_DEPREC( Aq_fx[cpe_id][n], Aq_fx_32[n], i_mult( nSubframes, M ), Q16 - Q12 ); // Q16 + } + x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 + x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 move16(); move16(); } - ivas_mdct_core_tns_ns_fx( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, 20 ); + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32, 1, 20 ); } test(); @@ -343,6 +358,7 @@ ivas_error ivas_mct_dec_fx( } /* Postprocessing for ACELP/MDCT core switching and synchronization */ +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { @@ -352,7 +368,7 @@ ivas_error ivas_mct_dec_fx( { set16_fx( output_mem_fx, 0, NS2SA_FX2( sts[n]->output_Fs, 3125000 ) ); } - +#endif Word16 Q_synth = sub( 15, e_sig[n] ); move16(); @@ -366,7 +382,12 @@ ivas_error ivas_mct_dec_fx( { dirac_stereo_flag = 0; } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], hCPE->output_mem_fx[1], 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#else + IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -383,7 +404,7 @@ ivas_error ivas_mct_dec_fx( save_synthesis_hq_fec_fx( sts[n], NULL, output_fx_, output_frame, 0, hCPE ); /* CoreCoder common updates */ - ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[( cpe_id * CPE_CHANNELS ) + n], 11 ); + updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, NULL, output_fx[( cpe_id * CPE_CHANNELS ) + n], Q11 ); } /* n_channels loop */ @@ -702,7 +723,7 @@ ivas_error mct_dec_reconfigure_fx( move16(); /* MDCT stereo initialization */ - IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } @@ -898,12 +919,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( Decoder_State *st; ivas_error error; MC_MODE mc_mode, last_mc_mode; + DECODER_TC_BUFFER_HANDLE hTcBuffer; TC_BUFFER_MODE tc_buffer_mode_new; Word16 tc_nchan_tc_new; Word16 tc_nchan_allocate_new; Word16 tc_granularity_new; Word16 nchan_out_buff; + hTcBuffer = st_ivas->hTcBuffer; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); nchan_transport_old = st_ivas->nchan_transport; @@ -949,45 +972,45 @@ static ivas_error ivas_mc_dec_reconfig_fx( /* side effect of the renderer selection can be a changed internal config */ ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - /* transfer subframe info from DirAC or ParamMC to central tc buffer */ - IF( NE_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) + /* transfer subframe info from DirAC or ParamMC to central TC buffer */ + IF( NE_32( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) { test(); IF( EQ_16( last_mc_mode, MC_MODE_PARAMMC ) ) { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes; + hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes; move16(); - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered; + hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered; move16(); - st_ivas->hTcBuffer->num_slots = st_ivas->hParamMC->num_slots; + hTcBuffer->num_slots = st_ivas->hParamMC->num_slots; move16(); - st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; + hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; move16(); - Copy( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hParamMC->subframe_nbslots, hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } ELSE IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; move16(); - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; move16(); - st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; move16(); - st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; move16(); - Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } } - /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv - render what still fits in the new granularity */ - tc_granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); - IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + /* when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); + IF( LT_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) { /* flush already done in IVAS_DEC_ReadFormat() */ } - /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ - ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + /* when granularity goes up set samples to discard at the beginning of the frame */ + ELSE IF( GT_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) { IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples_fx( st_ivas ) ), IVAS_ERR_OK ) ) { @@ -1525,16 +1548,13 @@ static ivas_error ivas_mc_dec_reconfig_fx( } /*-----------------------------------------------------------------* - * JBM TC buffers + * TC buffer *-----------------------------------------------------------------*/ - { Word16 tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode_fx( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + tc_buffer_mode_new = ivas_dec_get_tc_buffer_mode_fx( st_ivas ); + tc_nchan_tc_new = ivas_dec_get_num_tc_channels_fx( st_ivas ); tc_nchan_allocate_new = tc_nchan_tc_new; move16(); tc_nchan_full_new = tc_nchan_tc_new; @@ -1592,39 +1612,40 @@ static ivas_error ivas_mc_dec_reconfig_fx( test(); test(); test(); - IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || + IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_rend, tc_nchan_tc_new ) || NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) || NE_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) { - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) { return error; } } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + + /* transfer subframe info from central TC buffer to ParamMC or McMASA (DirAC) */ IF( st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->nb_subframes = hTcBuffer->nb_subframes; move16(); - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->subframes_rendered = hTcBuffer->subframes_rendered; move16(); - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->num_slots = hTcBuffer->num_slots; move16(); - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + st_ivas->hSpatParamRendCom->slots_rendered = hTcBuffer->slots_rendered; move16(); - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } ELSE IF( st_ivas->hParamMC != NULL ) { - st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hParamMC->nb_subframes = hTcBuffer->nb_subframes; move16(); - st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hParamMC->subframes_rendered = hTcBuffer->subframes_rendered; move16(); - st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hParamMC->num_slots = hTcBuffer->num_slots; move16(); - st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + st_ivas->hParamMC->slots_rendered = hTcBuffer->slots_rendered; move16(); - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + Copy( hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } } @@ -1633,7 +1654,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( *-----------------------------------------------------------------*/ nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); - IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff, st_ivas->hDecoderConfig->Opt_tsm, st_ivas->hTcBuffer ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff, st_ivas->hDecoderConfig->Opt_tsm, hTcBuffer ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_mct_dec_mct_fx_fx.c b/lib_dec/ivas_mct_dec_mct_fx_fx.c index c5e884f4694db0c4903c45293998e6be42b6fd61..f4d289ee28e28ef03bff8bf679f6d810a3fed9f0 100644 --- a/lib_dec/ivas_mct_dec_mct_fx_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,7 +36,6 @@ #include "prot_fx.h" #include "wmc_auto.h" #include -#include "stat_enc.h" #include "ivas_prot_fx.h" /*----------------------------------------------------------* diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 695051171fc29c24d3f1fe0fbc5f8a150733cad0..c085d5674d93cc609b236e82860de45c7ecbf739 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,15 +34,10 @@ #include #include "options.h" #include "prot_fx.h" -#include "rom_com.h" +#include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "cnst.h" #include "basop_proto_func.h" -#include "stat_com.h" -#include "ivas_stat_dec.h" -#include "ivas_stat_com.h" -#include #include "ivas_prot_fx.h" diff --git a/lib_dec/ivas_mono_dmx_renderer_fx.c b/lib_dec/ivas_mono_dmx_renderer_fx.c index fffcfff2ec363dd5a5f5c9de844170207d7d87db..36d5bd48aa7446b2c8c58386c7cb4d701a9a3d58 100644 --- a/lib_dec/ivas_mono_dmx_renderer_fx.c +++ b/lib_dec/ivas_mono_dmx_renderer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,13 +32,9 @@ #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" -#include "ivas_rom_com.h" -#include "ivas_rom_dec.h" #include "wmc_auto.h" diff --git a/lib_dec/ivas_objectRenderer_internal_fx.c b/lib_dec/ivas_objectRenderer_internal_fx.c index 069e2c0eb4e1f730aa4208d8b385d13af8949eaf..999fe3824c93ee34ad56e917605469209f9b4a26 100644 --- a/lib_dec/ivas_objectRenderer_internal_fx.c +++ b/lib_dec/ivas_objectRenderer_internal_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,11 +34,12 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" -#include #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#ifdef DEBUGGING #include "debug.h" +#endif /*---------------------------------------------------------------------* @@ -93,7 +94,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( Word16 ch, slot_size, slots_to_render, output_frame, tmp; ivas_error error; - Word16 ism_md_subframe_update_jbm; + Word16 ism_md_subframe_update; Word16 c_indx, nS, i; Word16 nchan_ism_internal, nchan_ism, ch_offset; @@ -135,16 +136,16 @@ ivas_error ivas_td_binaural_renderer_sf_fx( /* Number of subframes to delay metadata to sync with audio */ IF( st_ivas->hDecoderConfig->Opt_delay_comp ) { - ism_md_subframe_update_jbm = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 3 ) ); + ism_md_subframe_update = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 3 ) ); } ELSE { - ism_md_subframe_update_jbm = sub( st_ivas->hTcBuffer->nb_subframes, 2 ); + ism_md_subframe_update = sub( st_ivas->hTcBuffer->nb_subframes, 2 ); } IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - ism_md_subframe_update_jbm = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 2 ) ); + ism_md_subframe_update = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 2 ) ); } FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) @@ -205,7 +206,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( } } - IF( EQ_16( subframe_idx, ism_md_subframe_update_jbm ) ) + IF( EQ_16( subframe_idx, ism_md_subframe_update ) ) { test(); test(); @@ -310,7 +311,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( } /* Render subframe */ - /* ism_md_subframe_update_jbm != subframe_idx: trigger update only for ism_md_subframe_update_jbm == subframe_idx, + /* ism_md_subframe_updatem != subframe_idx: trigger update only for ism_md_subframe_update_jbm == subframe_idx, where then the two TDREND_GetMix()-arguments subframe_idx and ism_md_subframe_update are equal, and we want to enforce the update inside TDREND_GetMix to use subframe_idx == 0 */ IF( NE_32( ( error = TDREND_GetMix_fx( st_ivas->hBinRendererTd, output_fx_local, output_frame, 0 ) ), IVAS_ERR_OK ) ) { diff --git a/lib_dec/ivas_omasa_dec_fx.c b/lib_dec/ivas_omasa_dec_fx.c index af169985e1dee70ae407dc328791656961a80fb1..d13e17c1f33d50104cdd949c4964b90a3672b638 100644 --- a/lib_dec/ivas_omasa_dec_fx.c +++ b/lib_dec/ivas_omasa_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,14 +32,12 @@ #include "options.h" #include -#include #include "ivas_cnst.h" #include "ivas_prot_fx.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" /*------------------------------------------------------------------------- @@ -346,8 +344,12 @@ ivas_error ivas_omasa_data_open_fx( move16(); hMasaIsmData->preprocEneTarget_fx[band_idx] = 0; move32(); + hMasaIsmData->preprocEneTarget_e[band_idx] = 0; + move16(); hMasaIsmData->preprocEneRealized_fx[band_idx] = 0; move32(); + hMasaIsmData->preprocEneRealized_e[band_idx] = 0; + move16(); } hMasaIsmData->objectsEdited = 0; @@ -654,7 +656,7 @@ ivas_error ivas_omasa_dec_config_fx( IF( st_ivas->hMasaIsmData != NULL || st_ivas->hIsmRendererData != NULL ) { /* this calls also ivas_ism_renderer_close() closing st_ivas->hIsmRendererData used by the EXT renderers. also cleans st_ivas->hMasaIsmData */ - ivas_omasa_separate_object_renderer_close( st_ivas ); + ivas_omasa_separate_object_renderer_close_fx( st_ivas ); } test(); @@ -710,7 +712,7 @@ ivas_error ivas_omasa_dec_config_fx( } /* ISM renderer handle + ISM data handle */ - ivas_omasa_separate_object_renderer_close( st_ivas ); + ivas_omasa_separate_object_renderer_close_fx( st_ivas ); } } @@ -731,7 +733,7 @@ ivas_error ivas_omasa_dec_config_fx( return error; } - IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -739,7 +741,7 @@ ivas_error ivas_omasa_dec_config_fx( ELSE { /* ISM renderer handle + ISM data handle */ - ivas_omasa_separate_object_renderer_close( st_ivas ); + ivas_omasa_separate_object_renderer_close_fx( st_ivas ); } IF( EQ_32( old_renderer_type, RENDERER_MONO_DOWNMIX ) ) @@ -1077,19 +1079,20 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( return IVAS_ERR_OK; } + /*--------------------------------------------------------------------------* - * ivas_omasa_dirac_rend_jbm_fx() + * ivas_omasa_dirac_rend() * - * Rendering in OMASA format for JBM + * Rendering in OMASA format *--------------------------------------------------------------------------*/ -void ivas_omasa_dirac_rend_jbm_fx( +void ivas_omasa_dirac_rend_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of samples requested */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_fx[] /* o : rendered time signal Q11*/ + Word32 *output_fx[] /* o : rendered time signal Q11*/ ) { Word16 subframes_rendered; @@ -1152,7 +1155,7 @@ void ivas_omasa_dirac_rend_jbm_fx( scale_sig32( st_ivas->hIsmRendererData->prev_gains_fx[ind1], MAX_OUTPUT_CHANNELS, -1 ); // Q30 -> Q29 } - ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects, output_fx, subframes_rendered ); + ivas_omasa_separate_object_render_fx( st_ivas, *nSamplesRendered, data_separated_objects, output_fx, subframes_rendered ); FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) { @@ -1166,16 +1169,16 @@ void ivas_omasa_dirac_rend_jbm_fx( /*--------------------------------------------------------------------------* * ivas_omasa_dirac_td_binaural_render() * - * Binaural rendering in OMASA format for JBM + * Binaural rendering in OMASA format *--------------------------------------------------------------------------*/ -ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( +ivas_error ivas_omasa_dirac_td_binaural_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of samples requested */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_fx[] /* o : rendered time signal Q11*/ + Word32 *output_fx[] /* o : rendered time signal Q11*/ ) { Word16 n; diff --git a/lib_dec/ivas_osba_dec_fx.c b/lib_dec/ivas_osba_dec_fx.c index c9a6e0d70c9d3ec33361133896f95466067ad078..622cd88c853cf7f4e458e09125e78eaade9411d1 100644 --- a/lib_dec/ivas_osba_dec_fx.c +++ b/lib_dec/ivas_osba_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -119,17 +119,17 @@ void ivas_osba_data_close_fx( /*--------------------------------------------------------------------------* - * ivas_osba_dirac_td_binaural_jbm() + * ivas_osba_dirac_td_binaural() * - * Binaural rendering in JBM OSBA format + * Binaural rendering in OSBA format *--------------------------------------------------------------------------*/ -ivas_error ivas_osba_dirac_td_binaural_jbm_fx( +ivas_error ivas_osba_dirac_td_binaural_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[] /* o : rendered time signal Q11*/ + Word32 *output_fx[] /* o : rendered time signal Q11*/ ) { Word16 n; diff --git a/lib_dec/ivas_out_setup_conversion_fx.c b/lib_dec/ivas_out_setup_conversion_fx.c index 339d6eb4b4642e1872c3f790ce9370cac9e52898..a8fe1d0b0aabd9722e190bc3dc2f9328b7bba2e9 100644 --- a/lib_dec/ivas_out_setup_conversion_fx.c +++ b/lib_dec/ivas_out_setup_conversion_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" @@ -40,14 +39,15 @@ #include "ivas_rom_rend.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" - +#ifdef DEBUGGING #include "debug.h" +#endif + /*----------------------------------------------------------------------------------* * Local constants *----------------------------------------------------------------------------------*/ - #define LS_OUT_CONV_SMOOTHING_FACTOR_Q31 93415539 #define LS_OUT_CONV_CLIP_FACTOR_MAX_Q30 2147483647 #define LS_OUT_CONV_CLIP_FACTOR_MIN_Q30 322122547 diff --git a/lib_dec/ivas_output_config_fx.c b/lib_dec/ivas_output_config_fx.c index abf80add0da1b9f2af4f621c1d3680a42b573064..b57f4100b985753392cfa5b58e71a48c189e4c20 100644 --- a/lib_dec/ivas_output_config_fx.c +++ b/lib_dec/ivas_output_config_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -283,14 +283,14 @@ void ivas_renderer_select( * Non-binaural rendering configurations *-----------------------------------------------------------------*/ - ELSE IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) || EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { test(); test(); test(); test(); test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_NON_DIEGETIC_DOWNMIX; move16(); @@ -300,27 +300,12 @@ void ivas_renderer_select( *renderer_type = RENDERER_MC; move16(); } - } - ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && + ( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { *renderer_type = RENDERER_SBA_LINEAR_ENC; move16(); } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - *renderer_type = RENDERER_MC; - move16(); - } } ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 98611ab7cbcf9af52799eb55c91a6353ee726624..e5cab04c04b1854ff71d1d6b1ea8f3fccd889f0e 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,9 +36,9 @@ #include #include "ivas_cnst.h" #include "wmc_auto.h" -#include "math.h" #include "ivas_prot_fx.h" + /*-----------------------------------------------------------------------* * Local function definitions *-----------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_post_proc_fx.c b/lib_dec/ivas_post_proc_fx.c index f3254c4a547fa0f2d626ae87fe07da8b67067c98..b6eb91fd9a9f7649902dfdcff7f7a45b6185010f 100644 --- a/lib_dec/ivas_post_proc_fx.c +++ b/lib_dec/ivas_post_proc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include "cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" @@ -586,7 +584,7 @@ void stereo_dft_dec_core_switching_fx( IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) { Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); /*Q0*/ - Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )]; + Word32 tmp_fade_fx[STEREO_DFT_ALLPASS_FADELEN_16k /*max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )*/]; Copy32( st->hHQ_core->old_out_LB_fx32 + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->Q_old_out_fx32; diff --git a/lib_dec/ivas_qmetadata_dec_fx.c b/lib_dec/ivas_qmetadata_dec_fx.c index cc98c6ec494fba2b1fd1895bfb3e35de277421ce..7974350ce2b651139a251a2346f55c13c7d7d71e 100644 --- a/lib_dec/ivas_qmetadata_dec_fx.c +++ b/lib_dec/ivas_qmetadata_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include #include "options.h" -#include #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" diff --git a/lib_dec/ivas_qspherical_dec_fx.c b/lib_dec/ivas_qspherical_dec_fx.c index f443cc81de370ba99f5e6d3f4d018a40ff96322a..f0a7b03f67ee8025be0cc94b8579741fe4230af3 100644 --- a/lib_dec/ivas_qspherical_dec_fx.c +++ b/lib_dec/ivas_qspherical_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_range_uni_dec_fx.c b/lib_dec/ivas_range_uni_dec_fx.c index 9a49680e874a2d665b7ba37e3e0c2c47334cc18a..540c33123f7cdc50cc46fe61bc9803692b6bd6f6 100644 --- a/lib_dec/ivas_range_uni_dec_fx.c +++ b/lib_dec/ivas_range_uni_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include "ivas_cnst.h" #include "ivas_stat_dec.h" -#include "cnst.h" -#include "rom_com.h" #include #include "options.h" #include "prot_fx.h" diff --git a/lib_dec/ivas_rom_dec.h b/lib_dec/ivas_rom_dec.h index 0b29588b2207de3cbb2cb1d3d2f7dd9839a940f6..04613f1a541c1d04490915680f1e5935a5ba0451 100644 --- a/lib_dec/ivas_rom_dec.h +++ b/lib_dec/ivas_rom_dec.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_rom_dec_fx.c b/lib_dec/ivas_rom_dec_fx.c index 016335004b15655502a26eb2dca58deba1031052..f86a8ee88d1cde78201291a911ad1b974711d051 100644 --- a/lib_dec/ivas_rom_dec_fx.c +++ b/lib_dec/ivas_rom_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,11 +32,8 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include #include "wmc_auto.h" -#include "ivas_stat_dec.h" /* clang-format off */ diff --git a/lib_dec/ivas_sba_dec_fx.c b/lib_dec/ivas_sba_dec_fx.c index c4a1b0de109f168d1d6bdd22b9b9c2a4c7f0999b..789c0e954b36e8f0c2fecc64cdd3af5192fc8bbf 100644 --- a/lib_dec/ivas_sba_dec_fx.c +++ b/lib_dec/ivas_sba_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,21 +34,21 @@ #include #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" -#include #include "wmc_auto.h" #include "ivas_prot_fx.h" + + /*-------------------------------------------------------------------* * ivas_sba_set_cna_cng_flag() * * Set CNA/CNG flags in IVAS SBA decoder *-------------------------------------------------------------------*/ + void ivas_sba_set_cna_cng_flag( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -102,7 +102,7 @@ void ivas_sba_set_cna_cng_flag( } /*-------------------------------------------------------------------* - * ivas_sba_dec_reconfigure_fx() + * ivas_sba_dec_reconfigure() * * Reconfigure IVAS SBA decoder *-------------------------------------------------------------------*/ @@ -180,7 +180,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) { /* determine new granularity */ - granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); + granularity_new = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) @@ -585,9 +585,8 @@ ivas_error ivas_sba_dec_reconfigure_fx( } /*-----------------------------------------------------------------* - * JBM TC buffers + * TC buffer *-----------------------------------------------------------------*/ - { Word16 tc_nchan_to_allocate; Word16 tc_nchan_tc; @@ -595,8 +594,8 @@ ivas_error ivas_sba_dec_reconfigure_fx( tc_buffer_mode = TC_BUFFER_MODE_RENDERER; move16(); - tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ - tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/ + tc_nchan_tc = ivas_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ + tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/ move16(); test(); test(); @@ -647,19 +646,20 @@ ivas_error ivas_sba_dec_reconfigure_fx( } } + /* reconfigure TC buffer */ test(); test(); test(); - IF( NE_16( tc_nchan_tc, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( tc_buffer_mode, st_ivas->hTcBuffer->tc_buffer_mode ) || NE_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + IF( NE_16( tc_nchan_tc, st_ivas->hTcBuffer->nchan_transport_rend ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( tc_buffer_mode, st_ivas->hTcBuffer->tc_buffer_mode ) || NE_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - if ( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ), IVAS_ERR_OK ) ) + if ( NE_32( ( error = ivas_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ), IVAS_ERR_OK ) ) { return error; } } } - /* resync SPAR and DirAC JBM info from TC Buffer */ + /* resync SPAR and DirAC info from TC Buffer */ test(); IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) ) { diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 42a2524f1f6676a2f216159767685da2dbb0d4ae..0f18a6eab2a1fd0b39eb0bded7cfc7f5d1580e29 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -29,22 +29,28 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ + #include -#include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "wmc_auto.h" +/*-----------------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------------*/ + #define SIN_NEG_30_DEGREES_Q15 ( (Word16) 0xC000 ) #define SIN_30_DEGREES_Q15 ( (Word16) 0x4000 ) +#define SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ( (Word16) 0x2667 ) +#define SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX ( (Word32) 0x5B6DB6DB ) + + /*-------------------------------------------------------------------* * ivas_get_sba_dirac_stereo_flag() * @@ -1225,13 +1231,13 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( void ivas_sba_dirac_stereo_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : output frame length per channel Q0*/ - const Word16 mcmasa /* i : McMASA flag Q0*/ + const Word16 output_frame /* i : output frame length per channel Q0*/ ) { Word16 dtx_flag, fd_cng_flag; Word16 sba_mono_flag; Word16 memOffset; + Word32 output_Fs; Word32 tmp_buf[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; Word32 tmp_synth[L_FRAME16k]; Word32 hb_gain[NB_DIV]; @@ -1244,27 +1250,173 @@ void ivas_sba_dirac_stereo_dec_fx( SCE_DEC_HANDLE hSCE; CPE_DEC_HANDLE hCPE; STEREO_DFT_DEC_DATA_HANDLE hStereoDft; + Word16 mcmasa; - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + mcmasa = 0; + move16(); + if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { - set32_fx( DFT[i], 0, STEREO_DFT_BUF_MAX ); + mcmasa = 1; + move16(); } - hSCE = st_ivas->hSCE[0]; + output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); + hCPE = st_ivas->hCPE[0]; + hSCE = st_ivas->hSCE[0]; hStereoDft = hCPE->hStereoDft; - q = hCPE->hStereoDft->q_dft; + + /*----------------------------------------------------------------* + * Adjust scaling of buffers + *----------------------------------------------------------------*/ + + Decoder_State *st; + Word16 i, ii, s; + + s = 0; + move16(); + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + s = s_min( s, L_norm_arr( output[i], output_frame ) - Q11 ) /* Guard bits */; + } + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + Scale_sig32( output[i], output_frame, s ); // Q(11+s) + } + hStereoDft->q_dft = add( Q11, s ); + move16(); + IF( EQ_16( hStereoDft->first_frame, 1 ) ) + { + hStereoDft->q_smoothed_nrg = Q6; // hStereoDft->q_dft; + move16(); + hStereoDft->q_ap_delay_mem_fx = hStereoDft->q_dft; + move16(); + } + + q = hStereoDft->q_dft; + move16(); + + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hStereoDft->q_dft, Q11 ) ); // q_dft + FOR( i = 0; i < CPE_CHANNELS; ++i ) + { + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hStereoDft->q_dft, Q11 ) ); // q_dft + } + IF( hCPE->hCoreCoder[0] != NULL ) + { + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, output_frame, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q + hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; + move16(); + } + IF( hStereoDft != NULL ) + { + IF( LE_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + st = hCPE->hCoreCoder[0]; + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && ( st->last_core == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hStereoDft->q_dft, Q11 ) ); // q_dft + } + ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ + { + IF( !st->tcxonly ) + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hStereoDft->q_dft, Q11 ) ); // q_dft + } + } + } + ELSE /* ACELP core */ + { + test(); + test(); + IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */ + { + test(); + test(); + test(); + test(); + IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hStereoDft->q_dft, Q11 ) ); // q_dft + } + } + } + } + + IF( NE_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hStereoDft->q_dft, Q11 ) ); // q_dft + } + scale_sig32( hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hStereoDft->q_dft, hStereoDft->q_ap_fade_mem_fx ) ); // q_dft + hStereoDft->q_ap_fade_mem_fx = hStereoDft->q_dft; + move16(); + } + + test(); + if ( st_ivas->hSpar != NULL && EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + st_ivas->hSpar->hMdDec->Q_mixer_mat = Q30; + move16(); + } + + IF( hSCE != NULL ) + { + Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); // q_dft + hSCE->q_save_hb_synth_fx = hStereoDft->q_dft; + move16(); + Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); // q_dft + hSCE->q_save_synth_fx = hStereoDft->q_dft; + move16(); + } + FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) + { + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hStereoDft->q_dft, Q11 ) ); // q_dft + hCPE->q_output_mem_fx[ii] = hStereoDft->q_dft; + move16(); + } + FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) + { + Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx + } + + /*----------------------------------------------------------------* + * Processing + *----------------------------------------------------------------*/ + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + set32_fx( DFT[i], 0, STEREO_DFT_BUF_MAX ); + } + + q = hStereoDft->q_dft; move16(); - q_dft[0] = hCPE->hStereoDft->q_dft; + q_dft[0] = hStereoDft->q_dft; move16(); - q_dft[1] = hCPE->hStereoDft->q_dft; + q_dft[1] = hStereoDft->q_dft; move16(); - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); /*hSCE->q_prev_hb_synth_fx + hCPE->hStereoDft->q_dft - Q11*/ + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hStereoDft->q_dft ) ) ); /*hSCE->q_prev_hb_synth_fx + hStereoDft->q_dft - Q11*/ IF( hSCE != NULL ) { - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); /*hSCE->q_prev_hb_synth_fx + hCPE->hStereoDft->q_dft - Q11*/ - hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hStereoDft->q_dft ) ) ); /*hSCE->q_prev_hb_synth_fx + hStereoDft->q_dft - Q11*/ + hSCE->q_prev_hb_synth_fx = hStereoDft->q_dft; move16(); } @@ -1291,10 +1443,13 @@ void ivas_sba_dirac_stereo_dec_fx( move16(); ivas_sba_dirac_stereo_config( hStereoDft->hConfig ); + test(); test(); - hStereoDft->nbands = ivas_sba_dirac_stereo_band_config( hStereoDft->band_limits, st_ivas->hDecoderConfig->output_Fs, hStereoDft->NFFT, ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) ); + hStereoDft->nbands = ivas_sba_dirac_stereo_band_config( hStereoDft->band_limits, output_Fs, hStereoDft->NFFT, ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) ); + stereo_dft_dec_update_fx( hStereoDft, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); + IF( GT_16( st_ivas->nchan_transport, 1 ) ) { stereo_dft_dec_analyze_fx( hCPE, output[0], DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft[0] ); @@ -1312,7 +1467,7 @@ void ivas_sba_dirac_stereo_dec_fx( stereo_dft_dec_core_switching_fx( hCPE, output[0] /*hSCE->save_output*/, hSCE->save_synth_fx, hSCE->save_hb_synth_fx, DFT, output_frame, 0, dtx_flag, &q, &q_dft[0] ); /* do updates here after skipping this in SCE decoder (needs to be done after core switching) */ - ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q ); + updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, NULL, hSCE->save_synth_fx, q ); q_synth = sub( getScaleFactor32( tmp_synth, hSCE->hCoreCoder[0]->L_frame ), 10 ); scale_sig32( tmp_synth, hSCE->hCoreCoder[0]->L_frame, q_synth ); /*hSCE->q_save_synth_fx + q_synth*/ @@ -1335,7 +1490,7 @@ void ivas_sba_dirac_stereo_dec_fx( /* DFT Stereo upmix */ stereo_dft_dec_fx( hStereoDft, hCPE->hCoreCoder[0], DFT, NULL, NULL, 1 /*st_ivas->sba_dirac_stereo_flag*/, sba_mono_flag, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hMdDec : NULL, ( st_ivas->hSpar != NULL && ( !mcmasa ) ) ? st_ivas->hSpar->hFbMixer->cross_fade_start_offset : 0, - st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_transport, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); + output_Fs, st_ivas->nchan_transport, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); /* DFT synthesis */ stereo_dft_dec_synthesize_fx( hCPE, DFT, 0, output[0], output_frame ); @@ -1393,13 +1548,113 @@ void ivas_sba_dirac_stereo_dec_fx( set32_fx( output[ch], 0, output_frame ); } - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); /*hSCE->q_prev_hb_synth_fx + Q11 - hCPE->hStereoDft->q_dft*/ + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hStereoDft->q_dft ) ); /*hSCE->q_prev_hb_synth_fx + Q11 - hStereoDft->q_dft*/ IF( hSCE != NULL ) { - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); /*hSCE->q_prev_hb_synth_fx + Q11 - hCPE->hStereoDft->q_dft*/ + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hStereoDft->q_dft ) ); /*hSCE->q_prev_hb_synth_fx + Q11 - hStereoDft->q_dft*/ hSCE->q_prev_hb_synth_fx = Q11; move16(); } + /*----------------------------------------------------------------* + * Adjust scaling of buffers + *----------------------------------------------------------------*/ + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + Scale_sig32( output[i], output_frame, negate( s ) ); + } + + FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) + { + Scale_sig32( hCPE->prev_synth_fx[ii], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11 + } + + scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hStereoDft->q_dft ) ); + + FOR( i = 0; i < CPE_CHANNELS; ++i ) + { + scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hStereoDft->q_dft ) ); // Q11 + } + + IF( hCPE->hCoreCoder[0] != NULL ) + { + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, output_frame, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB + } + + IF( hStereoDft != NULL ) + { + IF( LE_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + st = hCPE->hCoreCoder[0]; + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && st->core == ACELP_CORE && EQ_16( st->con_tcx, 1 ) ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hStereoDft->q_dft ) ); // Q11 + } + ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ + { + IF( !st->tcxonly ) + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hStereoDft->q_dft ) ); // Q11 + } + } + } + ELSE /* ACELP core */ + { + test(); + test(); + IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */ + { + test(); + test(); + test(); + test(); + IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hStereoDft->q_dft ) ); // Q11 + } + } + } + } + + IF( NE_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + scale_sig32( hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hStereoDft->q_dft ) ); // Q11 + } + scale_sig32( hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hStereoDft->q_ap_fade_mem_fx ) ); // Q11 + hStereoDft->q_ap_fade_mem_fx = Q11; + test(); + } + + if ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) + { + st_ivas->hSpar->hMdDec->Q_mixer_mat = Q30; + move16(); + } + + FOR( ii = 0; ii < CPE_CHANNELS; ii++ ) + { + scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hStereoDft->q_dft ) ); // Q11 + hCPE->q_output_mem_fx[ii] = Q11; + move16(); + } + return; } diff --git a/lib_dec/ivas_sba_rendering_internal_fx.c b/lib_dec/ivas_sba_rendering_internal_fx.c index 5d8724a19fb86c6aa84c2f1e09fa89d886408d50..d595b8ae5494a6dd2ff0507cf4f2516c1b69111a 100644 --- a/lib_dec/ivas_sba_rendering_internal_fx.c +++ b/lib_dec/ivas_sba_rendering_internal_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,13 +36,13 @@ #include "ivas_prot_rend_fx.h" #include "ivas_stat_dec.h" #include "ivas_cnst.h" -#include #include "wmc_auto.h" #include "ivas_prot_fx.h" #ifdef DEBUGGING #include "debug.h" #endif + /*-------------------------------------------------------------------------* * ivas_sba2MC_cldfb() * diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 77c53c5ef63d18306328a6c065a495908be58b4f..75266dcefe26e5520f6efc901ca57ed6edf3b0f6 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,9 +33,7 @@ #include #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" @@ -387,6 +385,8 @@ ivas_error create_sce_dec( move16(); hSCE->element_brate = element_brate; /*Q0*/ move32(); + hSCE->last_element_brate = hSCE->element_brate; + move32(); set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); @@ -404,6 +404,8 @@ ivas_error create_sce_dec( st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ move32(); + st->element_brate = -1; + move32(); st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; move16(); st->is_ism_format = 0; diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index 05bf47cb98fcd38164633d75a1c62cb1beb5c214..1120c4eb969f732d1da5a977fc0d16bae3641dde 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,13 +33,12 @@ #include #include "options.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" -#include #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*------------------------------------------------------------------- * sns_1st_dec_fx() * @@ -82,7 +81,7 @@ static void sns_1st_dec_fx( FOR( i = 0; i < M / 2; i++ ) { - snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); // Q16 + snsq_fx[i] = L_mac( L_mult( ( *p_dico++ ), cdbk_fix ), means[i], means_fix ); // Q16 move32(); } @@ -90,7 +89,7 @@ static void sns_1st_dec_fx( FOR( i = M / 2; i < M; i++ ) { - snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); /*Q16*/ + snsq_fx[i] = L_mac( L_mult( ( *p_dico++ ), cdbk_fix ), means[i], means_fix ); /*Q16*/ move32(); } diff --git a/lib_dec/ivas_spar_decoder_fx.c b/lib_dec/ivas_spar_decoder_fx.c index 864d0543821e666566163296335a36ffc999ea3b..bc819763bab4f78b7d0ae0d1205162b3cbdb1747 100644 --- a/lib_dec/ivas_spar_decoder_fx.c +++ b/lib_dec/ivas_spar_decoder_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,18 +31,14 @@ *******************************************************************************************************/ #include -#include #include #include "options.h" #include "ivas_stat_dec.h" #include "prot_fx.h" -#include "string.h" #include "ivas_prot_rend_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "ivas_stat_com.h" -#include "stat_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #ifdef DEBUGGING @@ -250,8 +246,8 @@ ivas_error ivas_spar_dec_open_fx( buffer_mode = TC_BUFFER_MODE_RENDERER; move32(); - nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ - nchan_to_allocate = num_channels_internal; /*Q0*/ + nchan_tc = ivas_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/ + nchan_to_allocate = num_channels_internal; /*Q0*/ move16(); test(); @@ -292,9 +288,9 @@ ivas_error ivas_spar_dec_open_fx( move16(); } - granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), output_Fs ); + granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), output_Fs ); - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -1529,9 +1525,9 @@ void ivas_spar_dec_set_render_map_fx( move16(); set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpar->subframe_nbslots, &hSpar->nb_subframes ); + ivas_dec_get_adapted_subframes_fx( nCldfbTs, hSpar->subframe_nbslots, &hSpar->nb_subframes ); - /* copy also to tc buffer */ + /* copy also to TC buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ test(); IF( !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) @@ -1541,7 +1537,7 @@ void ivas_spar_dec_set_render_map_fx( Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); /*Q0*/ } - ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map ); + ivas_dec_get_md_map_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map ); return; } diff --git a/lib_dec/ivas_spar_md_dec_fx.c b/lib_dec/ivas_spar_md_dec_fx.c index 248518134d1350dcc9022a80e7571d11a9c2033e..9bce073cdd0a4ed0de63902af745980eae919633 100644 --- a/lib_dec/ivas_spar_md_dec_fx.c +++ b/lib_dec/ivas_spar_md_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include "math.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include @@ -44,6 +43,7 @@ /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ + #define DEG180_BY_PI_Q24 ( (Word32) 0x394BB835 ) /* 180.0/PI in Q24) */ #define IVAS_DEFAULT_DTX_CNG_RAMP ( 8 ) @@ -631,6 +631,11 @@ ivas_error ivas_spar_md_dec_init( hMdDec->first_valid_frame = 1; move16(); + hMdDec->spar_md.res_ind = 0; + hMdDec->spar_md.prior_dyn_active_w_flag = 0; + move16(); + move16(); + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 15100622536e8915bf5662d9725672dac522a016..1f406c3380e16b4b8e0dd1d9e9937bfc629abd33 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -993,7 +993,7 @@ typedef struct ivas_masa_ism_data_structure /*----------------------------------------------------------------------------------* - * JBM structures + * TC buffer structure, stores decoder and renderer audio samples, and rendering parameters *----------------------------------------------------------------------------------*/ typedef struct decoder_tc_buffer_structure @@ -1001,16 +1001,15 @@ typedef struct decoder_tc_buffer_structure Word32 *tc_buffer_old_fx[MAX_INTERN_CHANNELS]; /* TC audio samples not rendered in the previous frame */ Word32 *tc_buffer_fx; /* the buffer itself */ Word32 *tc_fx[MAX_INTERN_CHANNELS]; /* pointers into the buffer to the beginning of each tc */ - Word16 no_channels; /*Stores no of channels in tc_fx with values*/ - Word16 q_tc_fx; - TC_BUFFER_MODE tc_buffer_mode; /* mode of the buffer (no buffering, render buffering, out buffering) */ - Word16 nchan_transport_jbm; /* number of TCs after TC decoding */ - Word16 nchan_transport_internal; /* total number of TC buffer channels, can include e.g. TD decorr data */ - Word16 nchan_buffer_full; /* number of channels to be fully buffered */ - Word16 n_samples_available; /* samples still available for rendering in the current frame */ - Word16 n_samples_buffered; /* full number of samples in the buffer (including spill to next frame) */ - Word16 n_samples_rendered; /* samples already rendered in the current frame */ - Word16 n_samples_granularity; /* render granularity */ + Word16 q_tc_fx; /* TC channels Q-factor */ + TC_BUFFER_MODE tc_buffer_mode; /* mode of the buffer (no buffering, render buffering, out buffering) */ + Word16 nchan_transport_rend; /* number of TCs provided to the renderer */ + Word16 nchan_transport_internal; /* total number of TC buffer channels, can include e.g. TD decorr data */ + Word16 nchan_buffer_full; /* number of channels to be fully buffered */ + Word16 n_samples_available; /* samples still available for rendering in the current frame */ + Word16 n_samples_buffered; /* full number of samples in the buffer (including spill to next frame) */ + Word16 n_samples_rendered; /* samples already rendered in the current frame */ + Word16 n_samples_granularity; /* render granularity */ Word16 n_samples_flushed; Word16 subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; Word16 nb_subframes; @@ -1023,6 +1022,11 @@ typedef struct decoder_tc_buffer_structure } DECODER_TC_BUFFER, *DECODER_TC_BUFFER_HANDLE; + +/*----------------------------------------------------------------------------------* + * JBM metadata structure + *----------------------------------------------------------------------------------*/ + typedef struct jbm_metadata_structure { Word16 sf_write_idx; @@ -1069,8 +1073,8 @@ typedef struct decoder_config_structure Word16 Opt_aeid_on; /* indicates whether Acoustic environment option is used */ Word16 Opt_ObjEdit_on; /* indicates whether object editing option is used */ Word16 Opt_tsm; /* indicates whether time scaling modification is activated */ - IVAS_RENDER_FRAMESIZE render_framesize; - Word16 Opt_delay_comp; /* flag indicating delay compensation active */ + IVAS_RENDER_NUM_SUBFR render_num_subframes; /* renderer number of subframes */ + Word16 Opt_delay_comp; /* flag indicating delay compensation active */ } DECODER_CONFIG, *DECODER_CONFIG_HANDLE; @@ -1181,8 +1185,7 @@ typedef struct Decoder_Struct ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; /* ISAR split binaural rendering handle */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hTdRendHandles[MAX_HEAD_ROT_POSES - 1]; /* TD object renderer handles */ - /* JBM module */ - DECODER_TC_BUFFER_HANDLE hTcBuffer; /* JBM structure */ + DECODER_TC_BUFFER_HANDLE hTcBuffer; /* transport channels (TC) structure */ JBM_METADATA_HANDLE hJbmMetadata; /* Structure for metadata buffering in JBM */ Word32 last_active_ivas_total_brate; diff --git a/lib_dec/ivas_stereo_adapt_GR_dec_fx.c b/lib_dec/ivas_stereo_adapt_GR_dec_fx.c index 57166fae4c34e72e6145b560345ef2c264385b84..064f317199632999e021d0d3960cc07ecbe0686c 100644 --- a/lib_dec/ivas_stereo_adapt_GR_dec_fx.c +++ b/lib_dec/ivas_stereo_adapt_GR_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_stereo_cng_dec_fx.c b/lib_dec/ivas_stereo_cng_dec_fx.c index 124f89c5a12d3023a9aced6b273c902cc46bdf5c..bf09e23361b8a3e1055bf81da85661c33e50ba5f 100644 --- a/lib_dec/ivas_stereo_cng_dec_fx.c +++ b/lib_dec/ivas_stereo_cng_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,8 +32,6 @@ #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -121,11 +119,12 @@ static void stereo_dft_generate_comfort_noise_fx( Word32 tmp32_1, tmp32_2; Word16 q_div, q_sqrt1, q_sqrt2, q_sqrt, sqrt_res; Word16 q_shift, q_shift_1, q_shift_2, min_q; - + Word16 tmp16, tmp_p, tmp_s; hFdCngCom = st->hFdCngDec->hFdCngCom; push_wmops( "DFT_CNG" ); + set16_fx( dmpf, 0, M + 2 ); set16_fx( Atmp, 0, M + 2 ); @@ -163,7 +162,7 @@ static void stereo_dft_generate_comfort_noise_fx( } ELSE { - hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); /* Q15 */ + hStereoDft->g_state_fx[b] = mac_r( L_mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), A_GFILT_FX, hStereoDft->g_state_fx[b] ); /* Q15 */ move16(); } @@ -190,13 +189,13 @@ static void stereo_dft_generate_comfort_noise_fx( } ELSE { - hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); /* Q15 */ + hStereoCng->cm_fx[b] = mac_r( L_mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), A_GFILT_FX, hStereoCng->cm_fx[b] ); /* Q15 */ move16(); } } ELSE { - hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); /* Q15 */ + hStereoCng->cm_fx[b] = mac_r( L_mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), A_GFILT_FX, hStereoCng->cm_fx[b] ); /* Q15 */ move16(); } } @@ -228,13 +227,14 @@ static void stereo_dft_generate_comfort_noise_fx( } LR_ratio = extract_h( tdm_ratio_tabl_fx[hStereoCng->last_tdm_idx] ); /* Q15 */ + tmp16 = shr( hStereoDft->g_state_fx[b], 2 ); + tmp_p = add( ONE_IN_Q13, tmp16 ); + tmp_s = sub( ONE_IN_Q13, tmp16 ); + tmp16 = mult( gamma, 2048 ); + c = BASOP_Util_Divide3232_Scale( - L_add( L_mult( add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ), - add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ), - L_shr( L_mult( gamma, gamma ), 4 ) ), - L_add( L_mult( sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ), - sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ), - L_shr( L_mult( gamma, gamma ), 4 ) ), + L_mac( L_mult( tmp_p, tmp_p ), gamma, tmp16 ), + L_mac( L_mult( tmp_s, tmp_s ), gamma, tmp16 ), &c_e ); q_sqrt = c_e; move16(); diff --git a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c index 9b166c41a74204592214c56e42110a7c5ed592f2..125063b3f3daafb5a5e6bd7ddd9a6ecd0a82385e 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 5e1c8270f8e1e355e27d76a303e006f8dced3db7..b578f52c30791786936a82cf59a8cd0380d7d339 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,17 +33,13 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "rom_com.h" -#include "rom_dec.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" #include "basop_util.h" #ifdef DEBUGGING #include "debug.h" @@ -3723,8 +3719,7 @@ void stereo_dft_dec_sid_coh_fx( pred_fx = add( pred_fx, shl( mult( ( *pptr_fx++ ), cohBandq_fx[i] ), 2 ) ); /*q-13*/ } /* Weighted intra/inter-frame prediction */ - pred_fx = add( mult( alpha_fx, pred_fx ), mult( sub( 32767, alpha_fx ), shr( coh_fx[b], 2 ) ) ); /*q-13*/ - + pred_fx = mac_r( L_mult( alpha_fx, pred_fx ), sub( 32767, alpha_fx ), shr( coh_fx[b], 2 ) ); /*q-13*/ /* Read residual index from bitstream */ IF( LT_16( *nb_bits, nr_of_sid_stereo_bits ) ) /* If the bit limit is reached, res_index = 0 is assumed for remaining indices */ { @@ -3767,8 +3762,11 @@ void stereo_dft_dec_sid_coh_fx( get_next_indice_fx( st, 1 ); ( *nb_bits )++; } + return; } + + void stereo_dft_dequantize_itd_fx( Word16 *ind, /* Q0 */ Word32 *out_fx, /* Q15 */ @@ -3785,13 +3783,16 @@ void stereo_dft_dequantize_itd_fx( { itd = imult1616( -1, itd ); /* Q0 */ } - assert( ( ABSVAL( itd ) <= STEREO_DFT_ITD_MAX ) && ( ABSVAL( itd ) >= STEREO_DFT_ITD_MIN ) ); + assert( ( abs_s( itd ) <= STEREO_DFT_ITD_MAX ) && ( abs_s( itd ) >= STEREO_DFT_ITD_MIN ) ); /*Convert back @ fs*/ *out_fx = L_mult( itd, divide3232( output_Fs, STEREO_DFT_ITD_FS << 1 ) ); /*Q15*/ move32(); + return; } + + /*------------------------------------------------------------------------- * stereo_dft_dec_read_BS() * diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 6e4af32e5c6a1b0f13468ba98046cc7eafdfcc70..4ded8044f211e566a7ab650d2a8753b034ae9fff 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,14 +32,13 @@ #include #include "options.h" -#include "cnst.h" #include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" -#include "math.h" #include "wmc_auto.h" #include "basop_util.h" + /*--------------------------------------------------------------- * Local constants * ---------------------------------------------------------------*/ diff --git a/lib_dec/ivas_stereo_eclvq_dec_fx.c b/lib_dec/ivas_stereo_eclvq_dec_fx.c index 9d777c9b7bbd1d46ab705d89a8ad8ad1165e6cdc..f487d2f0c6383f7bca9254ca0cd400b75e5170cc 100644 --- a/lib_dec/ivas_stereo_eclvq_dec_fx.c +++ b/lib_dec/ivas_stereo_eclvq_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_stereo_esf_dec_fx.c b/lib_dec/ivas_stereo_esf_dec_fx.c index d4219f1e60464e7dbaf87c7effb4c814e18bc0ae..a438c3e5ccc5954b6038fb6327cce98e55cb35b0 100644 --- a/lib_dec/ivas_stereo_esf_dec_fx.c +++ b/lib_dec/ivas_stereo_esf_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/ivas_stereo_ica_dec_fx.c b/lib_dec/ivas_stereo_ica_dec_fx.c index 96458c4f2e01a7822dfa22552a5447ec66c1b988..9345fccaebfca269ed67ca8ac538e835852c3991 100644 --- a/lib_dec/ivas_stereo_ica_dec_fx.c +++ b/lib_dec/ivas_stereo_ica_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,12 +33,9 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_prot_fx.h" #include "basop32.h" @@ -196,7 +193,7 @@ void stereo_tca_dec_fx( IF( currentNCShift != 0 ) { - currentNCShift = add( mult( 19660 /* 0.6 in Q15 */, prevNCShift ), mult( 13106 /* 0.4 in Q15 */, currentNCShift ) ); /* Q0 */ + currentNCShift = mac_r( L_mult( 19660 /* 0.6 in Q15 */, prevNCShift ), 13106 /* 0.4 in Q15 */, currentNCShift ); /* Q0 */ } prevNCShift = hStereoTCA->interp_dec_prevNCShift; /* Q0 */ @@ -349,13 +346,10 @@ void stereo_tca_scale_R_channel_fx( test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - Word64 local_value; - // to be deleted next MR - // hCPE->hStereoDftDmx->prevTargetGain *= 2.0f; - // hCPE->hStereoDftDmx->prevTargetGain = min( hCPE->hStereoDftDmx->prevTargetGain, powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN ) ); - local_value = W_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); /* Q29 */ - hCPE->hStereoDftDmx->prevTargetGain_fx = (Word32) min( local_value, MAX_TARGET_GAIN_Q29 ); /* Q29 */ - hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ + Word32 local_value; + local_value = L_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); /* Q29 */ + hCPE->hStereoDftDmx->prevTargetGain_fx = L_min( local_value, MAX_TARGET_GAIN_Q29 ); /* Q29 */ + hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); flat_old = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ diff --git a/lib_dec/ivas_stereo_icbwe_dec_fx.c b/lib_dec/ivas_stereo_icbwe_dec_fx.c index 647ad6e77f1ccb7f3a374f2a1fc804310a77a8b5..a6fdf3aad1e13be4133e3090770ec7363424f8a7 100644 --- a/lib_dec/ivas_stereo_icbwe_dec_fx.c +++ b/lib_dec/ivas_stereo_icbwe_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" @@ -114,6 +112,12 @@ static Word16 FindScale( } +/*-------------------------------------------------------------------* + * stereo_icBWE_dec() + * + * Spatial mapping of reference to the non-reference channels in SHB + *-------------------------------------------------------------------*/ + void stereo_icBWE_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ @@ -152,6 +156,12 @@ void stereo_icBWE_dec_fx( STEREO_ICBWE_DEC_HANDLE hStereoICBWE = hCPE->hStereoICBWE; st = hCPE->hCoreCoder[0]; + if ( hCPE->hStereoDft != NULL ) + { + hCPE->hStereoDft->td_gain_fx[0] = 1; + move32(); + } + /*--------------------------------------------------------------------* * skip IC-BWE in case of mono DMX output * * -------------------------------------------------------------------*/ @@ -253,6 +263,7 @@ void stereo_icBWE_dec_fx( /*--------------------------------------------------------------------* * IC-BWE * * -------------------------------------------------------------------*/ + test(); test(); test(); @@ -267,7 +278,6 @@ void stereo_icBWE_dec_fx( return; } - set16_fx( fb_synth_nonref_fx, 0, L_FRAME48k ); /* core switching reset */ @@ -410,7 +420,6 @@ void stereo_icBWE_dec_fx( } // hStereoICBWE->prevgsMapping = powf( 10, hStereoICBWE->prevgsMapping ); - specMapping_fx = hStereoICBWE->prevSpecMapping_fx; // Q15 move16(); gsMapping_fx = hStereoICBWE->prevgsMapping_fx; // Q14 @@ -639,7 +648,6 @@ void stereo_icBWE_dec_fx( } /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ - tmp = 31; move16(); tmp = FindScale( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, Q_syn_shb, tmp ); @@ -671,7 +679,6 @@ void stereo_icBWE_dec_fx( alpha_fx = winSlope_fx; /* Q15 */ move16(); - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { ratio_L_fx = 16384; /* 0.5 in Q15 */ @@ -687,7 +694,6 @@ void stereo_icBWE_dec_fx( move16(); IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15 */ ) ) { tmp = mult_r( sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ), sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ) ); // Q15 @@ -777,8 +783,6 @@ void stereo_icBWE_dec_fx( } /* resample to output FS */ - - IF( EQ_32( st->output_Fs, 48000 /* Q0 */ ) ) { tmp = 31; @@ -831,7 +835,6 @@ void stereo_icBWE_dec_fx( } /* copy to outputHB and reset hb_synth values */ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { ratio_L_fx = 16384; /* 1.0 in Q15 */ @@ -928,6 +931,7 @@ void stereo_icBWE_dec_fx( return; } + /*-------------------------------------------------------------------* * stereo_icBWE_decproc() * @@ -1086,7 +1090,7 @@ void stereo_icBWE_decproc_fx( move32(); BREAK; } - // memOffset for 16K 32K 48K are 15 30 45 respectively.camera + // memOffset for 16K 32K 48K are 15 30 45 respectively } ELSE { @@ -1174,7 +1178,7 @@ void stereo_icBWE_decproc_fx( move16(); BREAK; } - // memOffset for 16K 32K 48K are 15 30 45 respectively.camera + // memOffset for 16K 32K 48K are 15 30 45 respectively } ELSE { @@ -1356,6 +1360,7 @@ void stereo_icBWE_decproc_fx( return; } + /*-------------------------------------------------------------------* * stereo_icBWE_init_dec() * diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 4d5996bb6db4a85e1a527987c0b1da2e27f29473..8a8c7dc305f73f1e2f52c5f3502d228150a02ba6 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,10 +33,8 @@ #include #include #include "options.h" -#include #include "prot_fx.h" -#include "cnst.h" -#include "stat_com.h" +#include "ivas_cnst.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -300,9 +298,15 @@ void stereo_mdct_core_dec_fx( FOR( ch = 0; ch < nChannels; ch++ ) { - nSubframes[ch] = EQ_16( sts[ch]->core, TCX_10_CORE ) ? NB_DIV : 1; /* Q0 */ + nSubframes[ch] = 1; /* Q0 */ move16(); + if ( EQ_16( sts[ch]->core, TCX_10_CORE ) ) + { + nSubframes[ch] = NB_DIV; + move16(); + } + FOR( k = 0; k < nSubframes[ch]; k++ ) { L_spec[ch] = idiv1616( sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); /* Q0 */ @@ -373,10 +377,20 @@ void stereo_mdct_core_dec_fx( } } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) +#ifdef FIX_2397_COPY_AQ_MDCT_CORE_BFI + IF( !bfi ) + { + FOR( ch = 0; ch < nChannels; ch++ ) + { + Copy_Scale_sig_16_32_DEPREC( Aq_fx[ch], Aq_fx_32[ch], i_mult( nSubframes[ch], M ), sub( Q16, Q12 ) ); /* Q16 */ + } + } +#else + FOR( ch = 0; ch < nChannels; ch++ ) { - Copy_Scale_sig_16_32_DEPREC( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); /* Q16 */ + Copy_Scale_sig_16_32_DEPREC( Aq_fx[ch], Aq_fx_32[ch], nSubframes[ch] * M, sub( Q16, Q12 ) ); /* Q16 */ } +#endif /*--------------------------------------------------------------------------------* * Stereo processing diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c b/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c index 1a639a3d7d4e79b5324f22361a7b1c97b31a5409..654f2bd13ac191aa1f35845cc986f408926661c3 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,11 +32,9 @@ #include #include -#include #include "options.h" #include "ivas_cnst.h" #include "prot_fx.h" -#include "rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -571,7 +569,7 @@ ivas_error initMdctStereoDtxData_fx( } /* Init FD-CNG */ - initFdCngDec_ivas_fx( st, st->cldfbSyn->scale ); + initFdCngDec_fx( st, st->cldfbSyn->scale ); } IF( st->first_CNG == 0 ) diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 237b5f9d5fac4fbf400b6cf7ef51d5d1fc58d5d7..63e9e792ed444a85b2be0c356976e8f8d2de7053 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,15 +32,12 @@ #include #include "options.h" -#include "cnst.h" -#include "rom_com.h" +#include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "assert.h" #include "wmc_auto.h" -#include -#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* @@ -652,7 +649,7 @@ ivas_error stereo_memory_dec_fx( return error; } - initFdCngDec_ivas_fx( st, st->cldfbSyn->scale ); + initFdCngDec_fx( st, st->cldfbSyn->scale ); configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); } @@ -759,7 +756,7 @@ ivas_error stereo_memory_dec_fx( } /* Init FD-CNG */ - initFdCngDec_ivas_fx( st, st->cldfbSyn->scale ); + initFdCngDec_fx( st, st->cldfbSyn->scale ); if ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { @@ -1079,7 +1076,8 @@ ivas_error stereo_memory_dec_fx( { return error; } - initFdCngDec_ivas_fx( hCPE->hCoreCoder[i], hCPE->hCoreCoder[i]->cldfbSyn->scale ); + + initFdCngDec_fx( hCPE->hCoreCoder[i], hCPE->hCoreCoder[i]->cldfbSyn->scale ); } } } diff --git a/lib_dec/ivas_stereo_td_dec_fx.c b/lib_dec/ivas_stereo_td_dec_fx.c index ec135d7a0d634cef179b28bad1fe8fe4c4d6bded..39b861ace07c42a23c0b0f5b5607a545571e2cdb 100644 --- a/lib_dec/ivas_stereo_td_dec_fx.c +++ b/lib_dec/ivas_stereo_td_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,9 +32,6 @@ #include #include "options.h" -#include -#include "cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" diff --git a/lib_dec/ivas_svd_dec_fx.c b/lib_dec/ivas_svd_dec_fx.c index d6811d2df5e53d7d48594daa858eefb15ef8dcd7..422617f7a9d8361adb36d166c442d2adf62982b2 100755 --- a/lib_dec/ivas_svd_dec_fx.c +++ b/lib_dec/ivas_svd_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -29,15 +29,16 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ + #include #include "options.h" #include "prot_fx.h" #include "ivas_stat_dec.h" #include "ivas_cnst.h" -#include #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ @@ -48,6 +49,8 @@ #define SVD_ZERO_FLUSH_THRESHOLD_FX ( 0 ) #define CONVERGENCE_FACTOR_FX 214748 /* factor for SVD convergence (as per latest float code: 1.0e-04f) */ +#define MINUS_ONE_IN_Q31 ( -2147483647 - 1 ) + /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 6cf2d46a9e348ecd0a5f0e50ec2b85111ec9c441..bea7d8e320a0714356d25070997ee4cec41ce075 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,22 +33,20 @@ #include #include #include "options.h" -#include #include "prot_fx.h" #include "rom_com.h" -#include "stat_dec.h" #include "wmc_auto.h" #include "basop_proto_func.h" -#include "stat_com.h" #include "ivas_prot_fx.h" /*-------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------*/ - static void dec_prm_tcx_ivas_fx( Decoder_State *st, Word16 param[], Word16 param_lpc[], Word16 *total_nbbits, const Word16 last_element_mode, Word16 *bitsRead ); static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Decoder_State *st, const Word16 MCT_flag, const Word16 last_element_mode, Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, Word16 *Q_syn_Overl_TDACFB, Word16 *Q_syn_OverlFB, Word16 *Q_old_out, Word16 *Q_old_outLB, Word16 *Q_old_Aq_12_8 ); + + /*-------------------------------------------------------------* * stereo_tcx_init_dec() * @@ -190,9 +188,13 @@ void stereo_tcx_init_dec_fx( *-------------------------------------------------------------------*/ void stereo_tcx_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const FRAME_MODE frameMode, /* i : Decoder frame mode */ - Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11*/ +#else + Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0*/ +#endif Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0*/ Word16 pitch_buf_fx[], /* o : Word16 pitch for each subframe, Q6*/ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ @@ -234,6 +236,9 @@ void stereo_tcx_core_dec_fx( Word32 psd_fx[L_FRAME16k]; Word32 psd_part_fx[NPART_SHAPING]; Word16 psd_part_e; +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word16 signal_out_fx[L_FRAME48k]; +#endif TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -755,13 +760,16 @@ void stereo_tcx_core_dec_fx( IF( st->hTdCngDec != NULL ) { - cng_params_upd_ivas_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + cng_params_upd_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); } } ELSE IF( st->hTdCngDec != NULL ) { - cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + cng_params_upd_fx( &lsp_fx[M], st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); } + /* Set 16k LSP flag for CNG buffer */ // st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); IF( EQ_16( st->L_frame, L_FRAME ) ) @@ -868,7 +876,9 @@ void stereo_tcx_core_dec_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { +#ifndef FIX_2280_REDUCTION_UNNECESSARY_SCALING Word32 signal_out_32_fx[L_FRAME48k]; +#endif Word16 exp; Copy_Scale_sig_16_32_no_sat( signal_out_fx, signal_out_32_fx, st->hFdCngDec->hFdCngCom->frameSize, Q6 ); generate_masking_noise_ivas_fx( signal_out_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); @@ -884,6 +894,10 @@ void stereo_tcx_core_dec_fx( } } +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Copy_Scale_sig_16_32_DEPREC( signal_out_fx, signal_out_32_fx, st->L_frame, sub( Q11, st->Q_syn_factor ) ); +#endif + pop_wmops(); return; } diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 32b5b3f87d609a93a90e3c797645bf71f6f9b88d..6273cd1862199ab438f2c233c8d79712b71dc335 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,8 +32,6 @@ #include #include "options.h" -#include "cnst.h" -#include "stat_enc.h" #include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" @@ -105,10 +103,6 @@ void tdm_low_rate_dec_fx( attack_flag = 0; move16(); - move16(); - move16(); - move16(); - move16(); /*--------------------------------------------------------------------------------------* * GSC decoder *--------------------------------------------------------------------------------------*/ @@ -154,12 +148,16 @@ void tdm_low_rate_dec_fx( Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[0], NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, L_FRAME * HIBND_ACB_L_FAC, L_shl( st->lp_gainc_fx, 13 /* Q3 -> Q16*/ ), &( st->Q_exc ), st->Q_subfr, NULL, 0, st->coder_type ); } + /*----------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *----------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame, 0 ); +#else pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame ); - +#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -250,9 +248,6 @@ void decod_gen_2sbfr_fx( error = 0; move16(); - move16(); - move16(); - move16(); /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ @@ -272,12 +267,13 @@ void decod_gen_2sbfr_fx( test(); IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && !( st->tdm_LRTD_flag ) ) ) { - tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); + tbe_celp_exc_fx( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, 0 ); } /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ + IF( st->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); @@ -297,7 +293,7 @@ void decod_gen_2sbfr_fx( * Innovation decoding *--------------------------------------------------------------*/ - inov_decode_ivas_fx( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code_fx, *pt_pitch, code, 2 * L_SUBFR ); + inov_decode_fx( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code_fx, *pt_pitch, code, 2 * L_SUBFR ); /*--------------------------------------------------------------* * Gain decoding @@ -305,12 +301,13 @@ void decod_gen_2sbfr_fx( *--------------------------------------------------------------*/ gain_dec_lbr_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); - st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */ + + st->tilt_code_fx = est_tilt_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR ); /* Q15 */ move16(); /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); - lp_gain_updt_ivas_fx( add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_fx( st->element_mode, i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_fx( st->element_mode, add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation diff --git a/lib_dec/jbm_jb4_circularbuffer.h b/lib_dec/jbm_jb4_circularbuffer.h index 36325c8c71942843674cb0388f01b553ab4cad6f..4817f16497928d81b274c7d7664cb884fde39a2b 100644 --- a/lib_dec/jbm_jb4_circularbuffer.h +++ b/lib_dec/jbm_jb4_circularbuffer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4_circularbuffer_fx.c b/lib_dec/jbm_jb4_circularbuffer_fx.c index 94341968436e8f28bf43ba8f4136a39b20062476..b26e8c49ed68bb1b0a947415f3fa8cbd510ab1fd 100644 --- a/lib_dec/jbm_jb4_circularbuffer_fx.c +++ b/lib_dec/jbm_jb4_circularbuffer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4_inputbuffer.h b/lib_dec/jbm_jb4_inputbuffer.h index 93174a08284b532b449f6bef2d05fe7c730e1dbe..efd782488481a7dd32c6931518c50d40ebc11825 100644 --- a/lib_dec/jbm_jb4_inputbuffer.h +++ b/lib_dec/jbm_jb4_inputbuffer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4_inputbuffer_fx.c b/lib_dec/jbm_jb4_inputbuffer_fx.c index 3e16f8ef5d415d17ee13950bee113812a37f8168..9dc8130228224d55546cd976c8a42308a82e656f 100644 --- a/lib_dec/jbm_jb4_inputbuffer_fx.c +++ b/lib_dec/jbm_jb4_inputbuffer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4_jmf.h b/lib_dec/jbm_jb4_jmf.h index 255c8a39a3025264bc2bffb1d84fee3e2e583f62..a55991780460d49e2791a182bbd7b1e1d7321888 100644 --- a/lib_dec/jbm_jb4_jmf.h +++ b/lib_dec/jbm_jb4_jmf.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4_jmf_fx.c b/lib_dec/jbm_jb4_jmf_fx.c index 086c76e5a1640493e37b0e659e9ec997abf5e7f0..ba17c5cd804ffd1880655c0d59d0a232b4e793f5 100644 --- a/lib_dec/jbm_jb4_jmf_fx.c +++ b/lib_dec/jbm_jb4_jmf_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4sb.h b/lib_dec/jbm_jb4sb.h index f579a5f25ef2104de71a7a53a5ca718550cffbbb..ced9edadbf025e6f28d8793405772e372ff71093 100644 --- a/lib_dec/jbm_jb4sb.h +++ b/lib_dec/jbm_jb4sb.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_jb4sb_fx.c b/lib_dec/jbm_jb4sb_fx.c index 43ef69a9846152b5a860e2e7aa2a9f458337eb28..e93e4f7cfd5a2b650645ba6f0c1a9f4b472dbf8f 100644 --- a/lib_dec/jbm_jb4sb_fx.c +++ b/lib_dec/jbm_jb4sb_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -39,7 +39,6 @@ /* system headers */ #include #include -#include #include #include "options.h" #include "wmc_auto.h" diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index 2fdc1f6253a48cdf75526760aba33b0f02b40a2c..220d301a7d74300aa71fbd6e76df17c9894c5dfa 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_pcmdsp_apa_fx.c b/lib_dec/jbm_pcmdsp_apa_fx.c index 82cebd2fbad9a8ad02d5516f0ef49b15e530c319..27fc1afa0672ebdc42f4d25a60e743f87e891885 100644 --- a/lib_dec/jbm_pcmdsp_apa_fx.c +++ b/lib_dec/jbm_pcmdsp_apa_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,7 +38,6 @@ /* system headers */ #include -#include #include #include #include @@ -691,11 +690,7 @@ UWord8 apa_exec_fx( ) { UWord16 i; -#ifdef FIX_1435_MOVE_STEREO_PANNING Word16 frm_in[APA_BUF_PER_CHANNEL]; /* NOTE: this buffer could be smaller if alocated dynamically based on the actual sampling rate */ -#else - Word16 frm_in[CPE_CHANNELS * APA_BUF / APA_MAX_NUM_CHANNELS]; /* in EVS, 2 output channels */ /* NOTE: this buffer could be smaller if alocated dynamically based on the actual sampling rate and number of channels */ -#endif UWord16 l_frm_out; Word16 l_rem; Word32 dl_scaled, dl_copied, l_frm_out_target; diff --git a/lib_dec/jbm_pcmdsp_fifo.h b/lib_dec/jbm_pcmdsp_fifo.h index 80a3ddb900a73fdf8c6ee86a3e27e99c5094e892..77e9b655ca4ecc2dd45caa43eb878aaa039058f9 100644 --- a/lib_dec/jbm_pcmdsp_fifo.h +++ b/lib_dec/jbm_pcmdsp_fifo.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 5b3b6ac61335005145ad9b6ca64505c4467f00a0..5ab60f3bea9a13cbe5731d451b4df963af6d5181 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_pcmdsp_similarityestimation_fx.c b/lib_dec/jbm_pcmdsp_similarityestimation_fx.c index ee800fcc0940aeec74a845a556fc6263255bbb2d..16fd9193f328427f11517cc28cfb20f69d86f89f 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation_fx.c +++ b/lib_dec/jbm_pcmdsp_similarityestimation_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,7 +38,6 @@ /* system headers */ #include -#include #include #include #include "options.h" diff --git a/lib_dec/jbm_pcmdsp_window.h b/lib_dec/jbm_pcmdsp_window.h index 2d0d0be0b193cb12ff62adbd2aa275053f4d602d..c18d11ec7e06412fe3f9e595845bc1c453c7fbd3 100644 --- a/lib_dec/jbm_pcmdsp_window.h +++ b/lib_dec/jbm_pcmdsp_window.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/jbm_pcmdsp_window_fx.c b/lib_dec/jbm_pcmdsp_window_fx.c index 3afeaf10661a044e5405fefe1bf87a41f3cd21ce..73faf37e21824d3693b98f462c10f5d2d4e3367d 100644 --- a/lib_dec/jbm_pcmdsp_window_fx.c +++ b/lib_dec/jbm_pcmdsp_window_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,7 +34,6 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ -#include #include #include #include "options.h" diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 733aefa92f196338744c551da9e5e8c4bedcf118..d89bd37c28613a70e06089f7d33ad7c0061cd3f9 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,6 +35,7 @@ #include "common_api_types.h" #include +#include "typedef.h" /*---------------------------------------------------------------------* @@ -86,7 +87,6 @@ typedef enum _IVAS_DEC_BS_FORMAT } IVAS_DEC_BS_FORMAT; typedef struct IVAS_DEC *IVAS_DEC_HANDLE; -typedef struct pidata_ts_struct *hPiDataTs; #ifdef SUPPORT_JBM_TRACEFILE /* Callback function for JBM tracefile writing */ @@ -112,7 +112,7 @@ ivas_error IVAS_DEC_Configure( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const UWord32 sampleRate, /* i : output sampling frequency */ const IVAS_AUDIO_CONFIG outputConfig, /* i : output configuration */ - const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes, /* i : rendering number of subframes */ const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const bool hrtfReaderEnabled, /* i : enable HRTF binary file input */ const bool enableHeadRotation, /* i : enable head rotation for binaural output */ @@ -352,14 +352,14 @@ ivas_error IVAS_DEC_EnableSplitRendering( IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ ); -ivas_error IVAS_DEC_SetRenderFramesize( +ivas_error IVAS_DEC_SetRenderNumSubfr( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes /* i : rendering number of subframes */ ); -ivas_error IVAS_DEC_GetRenderFramesize( +ivas_error IVAS_DEC_GetRenderNumSubfr( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */ + IVAS_RENDER_NUM_SUBFR *render_num_subframes /* o : rendering number of subframes */ ); ivas_error IVAS_DEC_GetRenderFramesizeSamples( @@ -372,14 +372,9 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( Word16 *update_frequency /* o : update frequency Q0 */ ); -ivas_error IVAS_DEC_GetNumOrientationSubframes( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *num_subframes /* o : render framesize */ -); - ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples Q0 */ + UWord32 *render_framesize_ms /* o : render framesize in ms Q0 */ ); @@ -515,7 +510,7 @@ ivas_error IVAS_DEC_GetJbmData( ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - hPiDataTs piData, /* i : PI data received in rtp packet */ + IVAS_PIDATA_TS *piData, /* i : PI data received in rtp packet */ UWord32 numPiData /* i : number of PI data received in rtp packet */ ); diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index bd86f5c6fee75e956203faeff560501a3bf2dfdf..918e01f404b8b9b8fac5de306e8aa5c9bb19ba19 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1,6 +1,6 @@ -/****************************************************************************************************** +/****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -41,12 +41,7 @@ #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" -#include "ivas_rtp_pi_data.h" -#include #include -#ifdef DEBUGGING -#include "float_to_fix_ops.h" -#endif #include "wmc_auto.h" @@ -121,7 +116,7 @@ static ivas_error ivas_dec_reconfig_split_rend( Decoder_Struct *st_ivas ); static ivas_error ivas_dec_init_split_rend( Decoder_Struct *st_ivas ); static ivas_error ivas_create_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out ); static void ivas_destroy_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out ); -static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize ); +static Word16 get_render_frame_size_ms( const IVAS_RENDER_NUM_SUBFR render_num_subframes ); static Word16 get_render_frame_size_samples( const DECODER_CONFIG_HANDLE hDecoderConfig ); static Word16 ivas_dec_split_rend_cldfb_in( const RENDERER_TYPE renderer_type ); static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered ); @@ -237,43 +232,41 @@ ivas_error IVAS_DEC_Open( move16(); /* set high-level parameters */ + st_ivas->codec_mode = 0; /* unknown before first frame */ + st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID; + st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID; + st_ivas->writeFECoffset = 0; + st_ivas->sba_analysis_order = 0; /* not really used in EVS mode, but initialize here to fix MSAN complaint */ + move16(); + move16(); + move16(); + move16(); + move16(); + IF( EQ_16( mode, IVAS_DEC_MODE_EVS ) ) { - st_ivas->codec_mode = 0; /* unknown before first frame */ st_ivas->element_mode_init = EVS_MONO; st_ivas->ivas_format = MONO_FORMAT; - st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID; - st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID; - st_ivas->writeFECoffset = 0; hIvasDec->hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */ move16(); move16(); move16(); - move16(); - move16(); - move16(); - move16(); return IVAS_ERR_OK; } ELSE IF( EQ_16( mode, IVAS_DEC_MODE_IVAS ) ) { - st_ivas->codec_mode = 0; /* unknown before first frame */ st_ivas->element_mode_init = -1; st_ivas->ivas_format = UNDEFINED_FORMAT; - st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID; - st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID; st_ivas->renderer_type = RENDERER_DISABLE; st_ivas->ini_frame = 0; st_ivas->ini_active_frame = 0; - st_ivas->writeFECoffset = 0; st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->mc_mode = MC_MODE_NONE; st_ivas->sba_order = 0; st_ivas->sba_planar = 0; - st_ivas->sba_analysis_order = 0; move16(); move16(); @@ -284,11 +277,6 @@ ivas_error IVAS_DEC_Open( move16(); move16(); move16(); - move16(); - move16(); - move16(); - move16(); - move16(); return IVAS_ERR_OK; } @@ -349,6 +337,9 @@ static void init_decoder_config( ) { hDecoderConfig->Opt_AMR_WB = 0; +#ifdef FIX_2392_MSAN_DESTROY_DEC + hDecoderConfig->output_Fs = -1; +#endif hDecoderConfig->nchan_out = 1; hDecoderConfig->output_config = IVAS_AUDIO_CONFIG_INVALID; hDecoderConfig->Opt_LsCustom = 0; @@ -366,6 +357,9 @@ static void init_decoder_config( hDecoderConfig->Opt_aeid_on = 0; hDecoderConfig->Opt_ObjEdit_on = 0; move16(); +#ifdef FIX_2392_MSAN_DESTROY_DEC + move32(); +#endif move16(); move16(); move16(); @@ -499,23 +493,23 @@ static ivas_error create_flush_buffer_fx( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Configure( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const UWord32 sampleRate, /* i : output sampling frequency */ - const IVAS_AUDIO_CONFIG outputConfig, /* i : output configuration */ - const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */ - const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ - const bool hrtfReaderEnabled, /* i : enable HRTF binary file input */ - const bool enableHeadRotation, /* i : enable head rotation for binaural output */ - const bool enableExternalOrientation, /* i : enable external orientations */ - const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ - const bool renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ - const IVAS_ROOM_SIZE_T roomSize, /* i : room size selector for reverb */ - const bool non_diegetic_pan_enabled, /* i : enabled diegetic panning */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ - const bool dpidEnabled, /* i : enable directivity pattern option */ - const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ - const bool objEditEnabled, /* i : enable object editing */ - const bool delayCompensationEnabled /* i : enable delay compensation */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const UWord32 sampleRate, /* i : output sampling frequency */ + const IVAS_AUDIO_CONFIG outputConfig, /* i : output configuration */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes, /* i : rendering number of subframes */ + const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ + const bool hrtfReaderEnabled, /* i : enable HRTF binary file input */ + const bool enableHeadRotation, /* i : enable head rotation for binaural output */ + const bool enableExternalOrientation, /* i : enable external orientations */ + const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ + const bool renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ + const IVAS_ROOM_SIZE_T roomSize, /* i : room size selector for reverb */ + const bool non_diegetic_pan_enabled, /* i : enabled diegetic panning */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const bool dpidEnabled, /* i : enable directivity pattern option */ + const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ + const bool objEditEnabled, /* i : enable object editing */ + const bool delayCompensationEnabled /* i : enable delay compensation */ ) { Decoder_Struct *st_ivas; @@ -619,18 +613,24 @@ ivas_error IVAS_DEC_Configure( move16(); move16(); - IF( EQ_16( renderFramesize, IVAS_RENDER_FRAMESIZE_UNKNOWN ) ) + IF( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + hDecoderConfig->Opt_Headrotation = 1; + move16(); + } + + IF( EQ_16( render_num_subframes, IVAS_RENDER_NUM_SUBFR_UNKNOWN ) ) { return IVAS_ERR_WRONG_PARAMS; } IF( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS; + hDecoderConfig->render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; } ELSE { - hDecoderConfig->render_framesize = renderFramesize; + hDecoderConfig->render_num_subframes = render_num_subframes; } move16(); @@ -684,7 +684,7 @@ ivas_error IVAS_DEC_EnableSplitRendering( hDecoderConfig->Opt_Headrotation = 1; move16(); - hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS; + hDecoderConfig->render_num_subframes = IVAS_RENDER_NUM_SUBFR_20MS; move32(); return IVAS_ERR_OK; @@ -697,35 +697,23 @@ ivas_error IVAS_DEC_EnableSplitRendering( * Get render framesize in ms *---------------------------------------------------------------------*/ +/*! r: render framesize in ms */ static Word16 get_render_frame_size_ms( - const IVAS_RENDER_FRAMESIZE render_framesize ) + const IVAS_RENDER_NUM_SUBFR render_num_subframes ) { - IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) - { - return ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ); - } - ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) - { - return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 ); - } - ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) - { - return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 ); - } - - return 0; + return (int16_t) ( render_num_subframes * ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) ); } /*---------------------------------------------------------------------* - * IVAS_DEC_SetRenderFramesize( ) + * IVAS_DEC_SetRenderNumSubfr( ) * - * Set render framesize + * Set number of rendering subrames *---------------------------------------------------------------------*/ -ivas_error IVAS_DEC_SetRenderFramesize( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */ +ivas_error IVAS_DEC_SetRenderNumSubfr( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes /* i : renderer number of subframes */ ) { test(); @@ -735,18 +723,18 @@ ivas_error IVAS_DEC_SetRenderFramesize( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - hIvasDec->st_ivas->hDecoderConfig->render_framesize = render_framesize; + hIvasDec->st_ivas->hDecoderConfig->render_num_subframes = render_num_subframes; move16(); IF( hIvasDec->st_ivas->hExtOrientationData != NULL ) { - hIvasDec->st_ivas->hExtOrientationData->num_subframes = (Word16) render_framesize; + hIvasDec->st_ivas->hExtOrientationData->num_subframes = (Word16) render_num_subframes; move16(); } IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) { - hIvasDec->st_ivas->hCombinedOrientationData->num_subframes = (Word16) render_framesize; + hIvasDec->st_ivas->hCombinedOrientationData->num_subframes = (Word16) render_num_subframes; move16(); } @@ -755,24 +743,24 @@ ivas_error IVAS_DEC_SetRenderFramesize( /*---------------------------------------------------------------------* - * IVAS_DEC_GetGetRenderFramesize( ) + * IVAS_DEC_GetRenderNumSubfr( ) * - * Get render framesize + * Get number of rendering subframes *---------------------------------------------------------------------*/ -ivas_error IVAS_DEC_GetRenderFramesize( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */ +ivas_error IVAS_DEC_GetRenderNumSubfr( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_RENDER_NUM_SUBFR *render_num_subframes /* o : rendering number of subframes */ ) { test(); test(); - IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL ) + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_num_subframes == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - *render_framesize = hIvasDec->st_ivas->hDecoderConfig->render_framesize; + *render_num_subframes = hIvasDec->st_ivas->hDecoderConfig->render_num_subframes; move16(); return IVAS_ERR_OK; @@ -793,15 +781,15 @@ static Word16 get_render_frame_size_samples( tmp = extract_l( Mpy_32_16_1( hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); - IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) + IF( EQ_16( hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_5MS ) ) { /* correct value already in tmp */ } - ELSE IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) + ELSE IF( EQ_16( hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_10MS ) ) { tmp = shl( tmp, 1 ); } - ELSE IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) + ELSE IF( EQ_16( hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_20MS ) ) { tmp = shl( tmp, 2 ); } @@ -815,7 +803,7 @@ static Word16 get_render_frame_size_samples( /*---------------------------------------------------------------------* - * IVAS_DEC_GetGetRenderFramesizeSamples( ) + * IVAS_DEC_GetRenderFramesizeSamples( ) * * Get render framesize in samples *---------------------------------------------------------------------*/ @@ -857,7 +845,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeMs( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - *render_framesize = get_render_frame_size_ms( hIvasDec->st_ivas->hDecoderConfig->render_framesize ); + *render_framesize = get_render_frame_size_ms( hIvasDec->st_ivas->hDecoderConfig->render_num_subframes ); move32(); return IVAS_ERR_OK; @@ -882,17 +870,17 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) + IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_5MS ) ) { *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; move16(); } - ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) + ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_10MS ) ) { *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 1; move16(); } - ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) + ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_20MS ) ) { *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 2; move16(); @@ -901,30 +889,6 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( return IVAS_ERR_OK; } -/*---------------------------------------------------------------------* - * IVAS_DEC_GetGetNumOrientationSubframes( ) - * - * Get the number of subframes for head/external orientation per render frame - *---------------------------------------------------------------------*/ - -ivas_error IVAS_DEC_GetNumOrientationSubframes( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *num_subframes /* o : render framesize */ -) -{ - test(); - test(); - IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || num_subframes == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } - - *num_subframes = (Word16) hIvasDec->st_ivas->hDecoderConfig->render_framesize; - move16(); - - return IVAS_ERR_OK; -} - /*---------------------------------------------------------------------* * IVAS_DEC_EnableVoIP( ) @@ -1155,12 +1119,12 @@ static Word16 isar_get_frame_size( test(); test(); - IF( NE_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) && + IF( NE_32( st_ivas->hDecoderConfig->render_num_subframes, IVAS_RENDER_NUM_SUBFR_20MS ) && ( EQ_32( st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) || EQ_32( st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) ) { nSamplesPerChannel = extract_l( Mpy_32_16_1( output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); - nSamplesPerChannel = imult1616( nSamplesPerChannel, st_ivas->hDecoderConfig->render_framesize ); + nSamplesPerChannel = imult1616( nSamplesPerChannel, st_ivas->hDecoderConfig->render_num_subframes ); } ELSE { @@ -1209,8 +1173,12 @@ static ivas_error isar_render_poses( /* hIvasDec->flushbuffer = (void *) malloc( sizeof( Word16 ) * numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); */ /* set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); */ Word16 num_samples_flushbuffer; - num_samples_flushbuffer = mult0( mult0( numPoses, BINAURAL_CHANNELS ), shl( div_l( hIvasDec->nSamplesFrame, IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ), 1 ) ); + num_samples_flushbuffer = mult0( shl( numPoses, 1 ) /* shl() == numPoses * BINAURAL_CHANNELS */, div_l( hIvasDec->nSamplesFrame, IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ); hIvasDec->flushbuffer = (void *) malloc( L_mult0( sizeof( Word16 ), num_samples_flushbuffer ) ); + if ( hIvasDec->flushbuffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate flush buffer" ); + } set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, num_samples_flushbuffer ); } @@ -1518,7 +1486,7 @@ ivas_error IVAS_DEC_GetSamplesRenderer( } /* render IVAS frames directly to the output buffer */ - IF( ( error = ivas_jbm_dec_render_fx( st_ivas, sub( nSamplesAsked, nSamplesRendered ), &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dec_render_fx( st_ivas, sub( nSamplesAsked, nSamplesRendered ), &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1619,16 +1587,10 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( { scale_sig32( p_head_pose_buf[i], numSamplesPerChannelToOutput, sub( Q11, Q_out[i] ) ); // Q11 } - IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) - { + #ifndef DISABLE_LIMITER - ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToOutput, st_ivas->BER_detect, Q11 ); + ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToOutput, st_ivas->BER_detect, Q11 ); #endif - } - ELSE - { - ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToOutput, st_ivas->BER_detect, Q11 ); - } ivas_syn_output_fx( p_head_pose_buf, Q11, numSamplesPerChannelToOutput, st_ivas->hDecoderConfig->nchan_out, pcmBuf_out ); } @@ -1653,18 +1615,7 @@ static ivas_error ivas_dec_setup_all( IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { -#ifdef FIX_1435_MOVE_STEREO_PANNING *nTransportChannels = 1; -#else - IF( EQ_16( (Word16) hIvasDec->st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) - { - *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; - } - ELSE - { - *nTransportChannels = 1; - } -#endif move16(); } ELSE @@ -1699,7 +1650,7 @@ static ivas_error ivas_dec_setup_all( } } - *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; + *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_rend; move16(); /*-----------------------------------------------------------------* @@ -2080,7 +2031,7 @@ ivas_error IVAS_DEC_GetMasaMetadata( IF( getFromJbmBuffer ) { - ivas_jbm_masa_sf_to_sf_map( hIvasDec->st_ivas ); + ivas_jbm_masa_sf_to_sf_map_fx( hIvasDec->st_ivas ); } *hMasaExtOutMeta = hIvasDec->st_ivas->hMasa->data.extOutMeta; @@ -2465,9 +2416,8 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */ -) + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics ) { test(); test(); @@ -2511,7 +2461,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( test(); IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_TDREND ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfTD == NULL ) { - IF( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_HRTF_td_binary_open_fx( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { return error; } @@ -2593,7 +2543,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( test(); IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_TDREND ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) ) { - ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD ); + ivas_HRTF_td_binary_close_fx( &st_ivas->hHrtfTD ); } test(); @@ -2606,8 +2556,6 @@ ivas_error IVAS_DEC_HRTF_binary_close( test(); IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) ) { - /* Fastconv HRTF memories */ - ivas_binaural_hrtf_close_fx( &st_ivas->hHrtfFastConv ); /* Fastconv HRTF filters */ ivas_HRTF_fastconv_binary_close_fx( &st_ivas->hHrtfFastConv ); @@ -3808,7 +3756,7 @@ ivas_error IVAS_DEC_ReadFormat( ( NE_32( renderer_type_old, st_ivas->renderer_type ) || NE_32( renderer_type_sec_old, renderer_type_sec_new ) ) ) { - Word16 tc_granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, renderer_type_sec_new, st_ivas->hDecoderConfig->output_Fs ); + Word16 tc_granularity_new = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, renderer_type_sec_new, st_ivas->hDecoderConfig->output_Fs ); st_ivas->nchan_transport = nchan_transport_old; move16(); @@ -3859,11 +3807,7 @@ static ivas_error apa_exec_evs_wrapper( { Word16 ch; UWord16 apa_buff_len; -#ifdef FIX_1435_MOVE_STEREO_PANNING Word16 tmp_apaExecBuffer[APA_BUF_PER_CHANNEL]; -#else - Word16 tmp_apaExecBuffer[CPE_CHANNELS * APA_BUF / APA_MAX_NUM_CHANNELS]; /* in EVS, 2 output channels */ -#endif DECODER_TC_BUFFER_HANDLE hTcBuffer; test(); @@ -3955,7 +3899,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } ELSE IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_IVAS ) ) { - IF( ( error = ivas_jbm_dec_tc_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -3990,7 +3934,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } /* convert deinterleaved decoded TC audio channels buffer to an interleaved one */ +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER + ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, st_ivas->hTcBuffer->tc_buffer_fx, nTransportChannels, hIvasDec->nSamplesFrame ); +#else ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, nTransportChannels, hIvasDec->nSamplesFrame, st_ivas->hTcBuffer->tc_buffer_fx ); +#endif IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { @@ -4010,7 +3958,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( move16(); /* convert interleaved time-scaled TC audio channels buffer to deinterleaved one */ +#ifdef FIX_2396_CONSTANT_STRIDE_IN_TC_BUFFER + ivas_buffer_interleaved_to_deinterleaved_fx( st_ivas->hTcBuffer->tc_buffer_fx, st_ivas->p_output_fx, nTransportChannels, nSamplesTcsScaled ); +#else ivas_buffer_interleaved_to_deinterleaved_fx( st_ivas->hTcBuffer->tc_buffer_fx, nTransportChannels, nSamplesTcsScaled, NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ) ); +#endif } else { @@ -4021,7 +3973,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( * Feed decoded transport channels samples to the renderer *-----------------------------------------------------------------*/ - ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples ); + ivas_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples ); IF( st_ivas->hDecoderConfig->Opt_tsm ) { @@ -4977,16 +4929,9 @@ IF( hIvasDec->hasDecodedFirstGoodFrame &&splitRendBits != NULL ) scale_sig32( p_head_pose_buf[i], *nSamplesRendered, sub( Q11, Q_out[i] ) ); // Q11 } - IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) - { #ifndef DISABLE_LIMITER - ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 ); + ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 ); #endif - } - ELSE - { - ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 ); - } ivas_syn_output_fx( p_head_pose_buf, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); } @@ -5167,7 +5112,7 @@ ivas_error IVAS_DEC_Flush( test(); IF( GT_16( nSamplesToRender, 0 ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, (Word16) MONO_FORMAT ) ) { - error = ivas_jbm_dec_render_fx( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); + error = ivas_dec_render_fx( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); } ELSE { @@ -5401,7 +5346,7 @@ static ivas_error printConfigInfo_dec( const bool quietModeEnabled ) { ivas_error error; - Word8 config_str[50]; + Word8 config_str[200]; AUDIO_CONFIG output_config; /*-----------------------------------------------------------------* @@ -5521,7 +5466,7 @@ static ivas_error printConfigInfo_dec( test(); IF( ( EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) { - fprintf( stdout, "Render framesize: %dms\n", get_render_frame_size_ms( st_ivas->hDecoderConfig->render_framesize ) ); + fprintf( stdout, "Render framesize: %dms\n", get_render_frame_size_ms( st_ivas->hDecoderConfig->render_num_subframes ) ); } IF( st_ivas->hDecoderConfig->Opt_HRTF_binary ) { @@ -5646,14 +5591,8 @@ static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas ) { DEC_CORE_HANDLE *hCoreCoder; -#ifndef FIX_1435_MOVE_STEREO_PANNING - Word16 mixer_left_fx, mixer_right_fx; - Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; - Word16 ch, i, nOutSamples; -#else Word32 *p_output_fx[1]; Word16 i, nOutSamples; -#endif Word16 output_16[L_FRAME48k]; ivas_error error; @@ -5667,18 +5606,7 @@ static ivas_error evs_dec_main_fx( mdct_switching_dec_fx( hCoreCoder[0] ); -#ifdef FIX_1435_MOVE_STEREO_PANNING p_output_fx[0] = st_ivas->p_output_fx[0]; -#else - FOR( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ ) - { - p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0 - IF( p_output_fx[ch] != NULL ) - { - set_zero_fx( p_output_fx[ch], L_FRAME48k ); - } - } -#endif /* run the main EVS decoding routine */ IF( EQ_16( hCoreCoder[0]->codec_mode, MODE1 ) ) @@ -5730,16 +5658,6 @@ static ivas_error evs_dec_main_fx( st_ivas->BER_detect = hCoreCoder[0]->BER_detect; move16(); -#ifndef FIX_1435_MOVE_STEREO_PANNING - IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) - { - mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14 - mixer_right_fx = sub( MAX16B, mixer_left_fx ); - - v_multc_fx_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */ - v_multc_fx_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples ); /* Q11 */ - } -#endif /*if ( st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )*/ { @@ -6360,7 +6278,7 @@ static ivas_error ivas_dec_init_split_rend( move16(); } - error = ISAR_PRE_REND_open( &st_ivas->hSplitBinRend->splitrend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hDecoderConfig->output_Fs, cldfb_in_flag, pcm_out_flag, st_ivas->hDecoderConfig->render_framesize, mixed_td_cldfb_flag ); + error = ISAR_PRE_REND_open( &st_ivas->hSplitBinRend->splitrend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hDecoderConfig->output_Fs, cldfb_in_flag, pcm_out_flag, st_ivas->hDecoderConfig->render_num_subframes, mixed_td_cldfb_flag ); move16(); return error; @@ -6434,7 +6352,7 @@ static ivas_error feedSinglePIorientation( { IF( !st_ivas->hExtOrientationData ) { - IF( NE_32( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) ) + IF( NE_32( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_num_subframes ), IVAS_ERR_OK ) ) { return error; } @@ -6442,7 +6360,7 @@ static ivas_error feedSinglePIorientation( IF( !st_ivas->hCombinedOrientationData ) { - IF( NE_32( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) ) + IF( NE_32( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_num_subframes ), IVAS_ERR_OK ) ) { return error; } @@ -6495,6 +6413,25 @@ static void setDiegeticInputPI( return; } +#ifdef DEBUGGING + +/*---------------------------------------------------------------------* + * fixedToFloat( ) + * + * + *---------------------------------------------------------------------*/ + +static float fixedToFloat( + const Word32 i, + const Word16 Q ) +{ + if ( Q < 0 ) + return ( i * (float) ( ( 1LL ) << ( -Q ) ) ); + else + return (float) ( i ) / (float) ( 1LL << Q ); +} + +#endif /*---------------------------------------------------------------------* * IVAS_DEC_FeedPiDataToDecoder( ) @@ -6504,7 +6441,7 @@ static void setDiegeticInputPI( ivas_error IVAS_DEC_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - hPiDataTs piData, /* i : PI data received in rtp packet */ + IVAS_PIDATA_TS *piData, /* i : PI data received in rtp packet */ UWord32 numPiData /* i : number of PI data received in rtp packet */ ) { diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 3af2e35ed787b63cec3d72949833666bf8ed04e8..32c8c99581caeac996bc96bdbd233d9afb94c2a3 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -236,10 +236,12 @@ void lsf_dec_fx( } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); } + /*-------------------------------------------------------------------------------------* * Mid-frame LSF decoding * LSP interpolation and conversion of LSPs to A(z) *-------------------------------------------------------------------------------------*/ + IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ @@ -298,13 +300,14 @@ void lsf_dec_fx( } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); } ELSE { /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_ivas_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); + int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); } + /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ diff --git a/lib_dec/rom_dec.h b/lib_dec/rom_dec.h index b4c7e4780e61b1727c14c3ee912fbbd50d2654e0..cfa8455bfa7fbc2301f388811da7c4fe7d13e9ee 100644 --- a/lib_dec/rom_dec.h +++ b/lib_dec/rom_dec.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/rom_dec_fx.c b/lib_dec/rom_dec_fx.c index 01be2c7cc6b7baabe998292d80626cdb6ccf93c9..f3539d64095a922968b574519abb8f691db135e1 100644 --- a/lib_dec/rom_dec_fx.c +++ b/lib_dec/rom_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 57072b9a436f30695aa72302cbce529fbcc92476..eafc5dd8a2cae335c68025f2f52f2d68ea8d9667 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -1258,7 +1258,6 @@ typedef struct Decoder_State Word16 last_L_frame_ori; Word16 previoussynth_fx[L_FRAME48k]; - Word32 previoussynth_fx_32[L_FRAME48k]; Word16 old_synth_sw_fx[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 1845b32e4dd244574a21a025fbf7db78d3aac582..61d5b345162cb15fb9ad075e970461d11e969152 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -355,8 +355,12 @@ Word16 WB_BWE_gain_deq_fx( /* o : Q_syn_hb */ Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Decoder_State *st_fx, /* i/o: decoder state structure */ +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ +#else + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ +#endif Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ @@ -370,6 +374,10 @@ Word16 ivas_wb_bwe_dec_fx( Word16 ysynth_fx[L_FRAME48k]; Word16 Q_syn, exp, Q_syn_hb; Word32 L_wtda_synth_fx[2 * L_FRAME48k], ysynth_32[L_FRAME48k], t_audio32_tmp[L_FRAME48k]; +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + Word16 output[L_FRAME16k]; + Word16 Q_input, sf; +#endif Word16 scl, new_input_fx_exp; Word16 i; FD_BWE_DEC_HANDLE hBWE_FD; @@ -380,12 +388,24 @@ Word16 ivas_wb_bwe_dec_fx( hBWE_FD = st_fx->hBWE_FD; /* MDCT of the core synthesis signal */ - new_input_fx_exp = *Qpost; move16(); test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { +#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING + sf = getScaleFactor32( output_fx32, st_fx->L_frame ); + + Q_input = 0; + move16(); + if ( LT_16( sf, 5 ) ) + { + Q_input = sub( sf, 5 ); + } + + Copy_Scale_sig_32_16( output_fx32, output, st_fx->L_frame, sub( Q_input, Q11 ) ); // Q_input + +#endif /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ /* IVAS_fmToDo: delay output[] by 1.25ms ? */ lerp( output, ysynth_fx, L_FRAME16k, st_fx->L_frame ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 5ca7ba1f640bc7d7c015c0833efcd0d66a6a4f57..2d99d9a4a27d6d849bd47e1bc6719296bf2a35d5 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2,22 +2,22 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ - #include #include "options.h" #include "rom_com.h" #include "prot_fx.h" #include "rom_dec.h" -#include "stl.h" - #include "ivas_prot_fx.h" /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ +#ifdef HARMONIZE_TBE +static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors, Word16 *MSFlag ); +#else static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors ); - +#endif static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2, Word16 *n_mem3 ); static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ); static void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ); @@ -27,15 +27,15 @@ static void Map_higher_LSF_fx( Word16 lsf_q[], const Word16 m, const Word16 grid static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16 *m ); static Word16 dotp_loc( const Word16 x[], const Word32 y[], const Word16 n ); static void find_max_mem_dec_m3( Decoder_State *st, Word16 *n_mem3 ); - -/* gain shape concealment code */ static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame ); + /*-------------------------------------------------------------------* * find_max_mem_dec() * * Find norm and max in TBE memories and past buffers *-------------------------------------------------------------------*/ + static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, @@ -219,14 +219,17 @@ static void find_max_mem_dec( because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); move16(); - /* --------------------------------------------------------------*/ + + return; } + /*-------------------------------------------------------------------* * rescale_genSHB_mem_dec() * * Rescale genSHB memories *-------------------------------------------------------------------*/ + static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ) @@ -255,20 +258,25 @@ static void rescale_genSHB_mem_dec( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { +#ifdef HARMONIZE_TBE + hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); +#else hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); +#endif move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { +#ifdef HARMONIZE_TBE + hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); +#else hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); +#endif move16(); } } - if ( EQ_16( st_fx->extl, FB_TBE ) ) - { - } hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); move32(); @@ -276,9 +284,14 @@ static void rescale_genSHB_mem_dec( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) + +static void find_max_mem_wb( + Decoder_State *st_fx, + Word16 *n_mem ) { Word16 i; Word16 max = 0; @@ -311,21 +324,18 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) FOR( i = 0; i < 7; i++ ) { - if ( GT_16( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ), max ) ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR( i = 0; i < 10; i++ ) { - if ( GT_16( abs_s( hBWE_TD->state_lpc_syn_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } FOR( i = 0; i < 5; i++ ) { - if ( GT_16( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } @@ -341,10 +351,8 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) move16(); } - FOR( i = 0; i < 2; i++ ) { - if ( GT_32( L_abs( hBWE_TD->mem_csfilt_fx[i] ), Lmax ) ) Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } @@ -363,9 +371,14 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) move16(); *n_mem = s_max( *n_mem, 0 ); move16(); + + return; } -void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) + +static void rescale_genWB_mem( + Decoder_State *st_fx, + Word16 sf ) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -466,6 +479,12 @@ static void InitSWBdecBuffer_fx( } +/*-------------------------------------------------------------------* + * ResetSHBbuffer_Dec() + * + * + *-------------------------------------------------------------------*/ + void ResetSHBbuffer_Dec_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 extl /* i : BWE extension layer */ @@ -587,20 +606,25 @@ void ResetSHBbuffer_Dec_fx( /* _Word16 *synth o : WB synthesis/final synthesis Q_synth */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx, i/o: decoder state structure */ +/* Decoder_State *st_fx, i/o: decoder state structure */ /*--------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ /* CALLED FROM : */ /*==========================================================================*/ + +#ifdef HARMONIZE_TBE +void wb_tbe_dec_fx( +#else void ivas_wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors Q15 */ - Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ +#endif + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc */ + const Word16 Q_exc, /* i : Q_exc factor */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -635,8 +659,10 @@ void ivas_wb_tbe_dec_fx( Word16 f, inc; Word64 W_tmp; TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; set32_fx( &dummy2[0], 0, HILBERT_MEM_SIZE ); + IF( st_fx->bws_cnt == 0 ) { /* Initialization */ @@ -750,9 +776,14 @@ void ivas_wb_tbe_dec_fx( } ELSE { +#ifdef HARMONIZE_TBE + /* de-quantization */ + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ ); +#else /* de-quantization */ Word16 ignore; ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); +#endif } } ELSE @@ -835,9 +866,21 @@ void ivas_wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; move32(); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } + } + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } } IF( Lmax == 0 ) { @@ -848,7 +891,16 @@ void ivas_wb_tbe_dec_fx( { Q_bwe_exc = norm_l( Lmax ); } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Q_bwe_exc = sub( Q_bwe_exc, 1 ); + } + ELSE +#endif + { + Q_bwe_exc = sub( Q_bwe_exc, 3 ); + } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); find_max_mem_wb( st_fx, &n_mem ); @@ -865,38 +917,82 @@ void ivas_wb_tbe_dec_fx( move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } - W_tmp = 0; - move64(); - IF( st_fx->element_mode > EVS_MONO ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + prev_pow = 0; + move32(); + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0_sat( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + } } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE +#endif { - W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ + W_tmp = 0; + move64(); + tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); + W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ + } + exp = W_norm( W_tmp ); + prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); + exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); } - exp = W_norm( W_tmp ); - prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); - exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } +#endif + sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); - move16(); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } + + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); + move16(); + } } Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, - bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); + } + ELSE +#endif + { + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); + } curr_pow = 0; move32(); @@ -915,8 +1011,16 @@ void ivas_wb_tbe_dec_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, - exp, &exp ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + } + ELSE +#endif + { + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, exp, &exp ); + } FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { @@ -932,7 +1036,6 @@ void ivas_wb_tbe_dec_fx( /* Update SHB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Adjust the subframe and frame gain of the synthesized shb signal */ /* Scale the shaped excitation */ ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, @@ -941,9 +1044,21 @@ void ivas_wb_tbe_dec_fx( max = 0; move16(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ + } + } + ELSE +#endif { - max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); + } } IF( max == 0 ) @@ -985,8 +1100,12 @@ void ivas_wb_tbe_dec_fx( } test(); +#ifdef HARMONIZE_TBE + IF( !st_fx->bfi && st_fx->prev_bfi ) +#else test(); IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) +#endif { IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) { @@ -1063,13 +1182,17 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); + } } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); + } } IF( EQ_32( st_fx->output_Fs, 32000 ) ) @@ -1178,10 +1301,21 @@ void ivas_wb_tbe_dec_fx( } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); - interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); - Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, Q11 ) ); - Copy_Scale_sig_32_16( upsampled_synth_32fx, synth, L_FRAME48k, sub( Qx, Q11 ) ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); + interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); + Copy( upsampled_synth, synth, L_FRAME48k ); + } + ELSE +#endif + { + Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); + interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); + Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, Q11 ) ); + Copy_Scale_sig_32_16( upsampled_synth_32fx, synth, L_FRAME48k, sub( Qx, Q11 ) ); + } } } ELSE @@ -1238,7 +1372,7 @@ void ivas_wb_tbe_dec_fx( return; } - +#ifndef HARMONIZE_TBE void wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -1535,7 +1669,7 @@ void wb_tbe_dec_fx( GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); curr_pow = 0; @@ -1877,7 +2011,7 @@ void wb_tbe_dec_fx( return; } - +#endif /*======================================================================================*/ /* FUNCTION : void swb_tbe_dec_fx () */ @@ -1896,13 +2030,14 @@ void wb_tbe_dec_fx( /* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ /*--------------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State *st_fx: : Decoder state structure */ +/* _ Decoder_State *st_fx: : Decoder state structure */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*======================================================================================*/ + void swb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -2210,10 +2345,14 @@ void swb_tbe_dec_fx( } ELSE { - /* de-quantization */ +#ifdef HARMONIZE_TBE + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, + &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); +#else dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, &shb_ener_sf_32, shb_res_gshape, &mixFactors ); +#endif Q_shb = 0; move16(); /* o: shb_ener_sf_32 in (2*Q_shb) */ @@ -2653,7 +2792,7 @@ void swb_tbe_dec_fx( /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ GenShapedSHBExcitation_fx( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, + coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); @@ -3867,6 +4006,7 @@ static Word16 dotp_loc( Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) @@ -3878,7 +4018,18 @@ static Word16 dotp_loc( return extract_h( suma ); /*Qx + Qy - 16*/ } + +/*-------------------------------------------------------------------* + * dequantizeSHBparams() + * + * Dequantize super highband spectral envolope, temporal gains and frame gain + *-------------------------------------------------------------------*/ + +#ifdef HARMONIZE_TBE +static void dequantizeSHBparams_fx( +#else void ivas_dequantizeSHBparams_fx_9_1( +#endif Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ Word32 extl_brate, /* i : extensiuon layer bitrate */ @@ -4310,7 +4461,7 @@ void ivas_dequantizeSHBparams_fx_9_1( return; } - +#ifndef HARMONIZE_TBE /*==========================================================================*/ /* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ /*--------------------------------------------------------------------------*/ @@ -4629,13 +4780,16 @@ static void dequantizeSHBparams_fx_9_1( return; } +#endif /*-------------------------------------------------------------------* * fb_tbe_dec() * * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ + void fb_tbe_dec_fx( +#ifndef HARMONIZE_TBE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, @@ -4690,9 +4844,13 @@ void fb_tbe_dec_fx( } void fb_tbe_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, +#ifdef HARMONIZE_TBE + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ +#endif Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ @@ -4754,17 +4912,31 @@ void fb_tbe_dec_ivas_fx( { Copy_Scale_sig( fb_synth, fb_synth_ref, L_FRAME48k, sub( Q_fb_synth_ref, add( hb_synth_exp, 16 ) ) ); // scaling is required } + /* add the fb_synth component to the hb_synth component */ - /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ - FOR( i = 0; i < L_FRAME48k; i++ ) +#ifdef HARMONIZE_TBE + IF( st->element_mode == EVS_MONO ) { - // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp - move16(); + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth16[i] = add_sat( hb_synth16[i], fb_synth[i] ); + move16(); + } + } + ELSE +#endif + { + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp + move16(); + } } + return; } + void tbe_read_bitstream_fx( Decoder_State *st_fx ) { @@ -5381,6 +5553,7 @@ static void calc_tilt_bwe_fx_loc( return; } +#ifndef HARMONIZE_TBE /*-------------------------------------------------------------------* * swb_tbe_dec() * @@ -5427,6 +5600,7 @@ static void rescale_genSHB_mem_dec_ivas( return; } +#endif static void find_max_mem_dec_m3( Decoder_State *st, @@ -5461,23 +5635,27 @@ static void find_max_mem_dec_m3( *n_mem3 = 15; move16(); } + + return; } + /*-------------------------------------------------------------------* * ivas_swb_tbe_dec_fx() * * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ + void ivas_swb_tbe_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ - Word16 *pitch_buf_fx, /* i : Q6 */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -5545,6 +5723,9 @@ void ivas_swb_tbe_dec_fx( hBWE_TD = st->hBWE_TD; + Word32 old_syn_12k8_16k_fx[L_FRAME16k]; + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) + /* initializations */ GainFrame_fx = 0; move32(); @@ -5790,8 +5971,13 @@ void ivas_swb_tbe_dec_fx( ELSE { /* de-quantization */ +#ifdef HARMONIZE_TBE + dequantizeSHBparams_fx( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, + &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); +#else ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); +#endif if ( hStereoICBWE != NULL ) { hStereoICBWE->MSFlag = MSFlag; @@ -6185,7 +6371,11 @@ void ivas_swb_tbe_dec_fx( sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc ); IF( sc != 0 ) { +#ifdef HARMONIZE_TBE + rescale_genSHB_mem_dec( st, sc ); +#else rescale_genSHB_mem_dec_ivas( st, sc ); +#endif } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 767e5c8e758f8e520fe9b1a52084213b7bf00426..93a5ab064261ff067116cc0ae0b1a43c248c0735 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -2,11 +2,8 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ -#define _USE_MATH_DEFINES - #include #include -#include #include "options.h" #include "basop_util.h" #include "options.h" @@ -212,8 +209,8 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( /* just the second half of the second last pcm output is needed */ set16_fx( hTonalMDCTConc->timeDataBuffer, 0, ( 3 * L_FRAME_MAX ) / 2 ); - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) / 2 )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * s_min( L_FRAME_MAX, nSamples ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - s_min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 240f9545c4cc8669299569d18ff755cbd35d77be..868c62fe7ccef8a24297047d6501b6d2a6633aa7 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -14,17 +14,18 @@ * * Common updates (all frame types) *-------------------------------------------------------------------*/ + void updt_dec_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */ + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */ const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe Q6*/ - const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ - const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ - const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ - const Word16 voice_factors[], /* i : voicing factors Q15*/ - const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ - const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ + const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ + const Word16 voice_factors[], /* i : voicing factors Q15*/ + const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ + const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ ) { Word16 i, len; @@ -56,6 +57,7 @@ void updt_dec_fx( st_fx->last_coder_type = UNVOICED; move16(); } + IF( st_fx->hGSCDec != NULL ) { test(); @@ -68,13 +70,13 @@ void updt_dec_fx( } /* this ensures that st_fx->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ - test(); if ( GT_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->coder_type, INACTIVE ) ) { st_fx->last_coder_type = GENERIC; move16(); } + test(); test(); test(); @@ -91,7 +93,6 @@ void updt_dec_fx( IF( !st_fx->Opt_AMR_WB ) { /* update voicing factor of TBE to help FEC */ - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR16k - 1]; move16(); if ( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -100,6 +101,7 @@ void updt_dec_fx( move16(); } } + test(); test(); IF( st_fx->hGSCDec != NULL && NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) ) @@ -159,7 +161,6 @@ void updt_dec_fx( move16(); } - /* FEC - update adaptive LSF mean vector */ Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M ); Copy( lsf_new_fx, st_fx->lsfoldbfi0_fx, M ); @@ -198,13 +199,15 @@ void updt_dec_fx( return; } + /*-------------------------------------------------------------------* * updt_IO_switch() * * Common updates for AMR-WB IO mode and EVS primary switching *-------------------------------------------------------------------*/ + void updt_IO_switch_dec_fx( - const Word16 output_frame, /* i : output frame length */ + const Word16 output_frame, /* i : output frame length */ Decoder_State *st_fx /* o : Decoder static variables structure */ ) { @@ -393,15 +396,24 @@ void updt_IO_switch_dec_fx( * Updates for BW switching *-------------------------------------------------------------------*/ -void updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : synthesis signal Qpost */ - const Word16 Qpost ) +static void updt_bw_switching_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *synth, /* i : synthesis signal Qpost */ + const Word32 *synth32, /* i : synthesis signal32 Qpost */ + const Word16 Qpost /* i : Synthesis Q value */ +) { test(); IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) { - st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11 + IF( st_fx->element_mode != EVS_MONO ) + { + st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx( synth32, Qpost, L_FRAME32k ); + } + ELSE + { + st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11 + } } st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q @@ -433,365 +445,21 @@ void updt_bw_switching_fx( move16(); } } + st_fx->prev_bws_cnt = st_fx->bws_cnt; move16(); + return; } + /*-------------------------------------------------------------------* * updt_dec_common() * * Common updates for MODE1 and MODE2 *-------------------------------------------------------------------*/ -void updt_dec_common_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16 *synth, /* i : decoded synthesis Qpostd */ - const Word16 Qpostd /* i : Synthesis Q value */ - -) -{ - Word16 i; - Word32 L_tmp; - - TCX_DEC_HANDLE hTcxDec; - hTcxDec = st_fx->hTcxDec; - - st_fx->last_codec_mode = st_fx->codec_mode; - move16(); - st_fx->last_extl = st_fx->extl; - move16(); - st_fx->last_L_frame = st_fx->L_frame; - move16(); - - st_fx->prev_old_bfi = st_fx->prev_bfi; - move16(); - st_fx->prev_bfi = st_fx->bfi; - move16(); - if ( NE_16( st_fx->core, AMR_WB_CORE ) ) - { - st_fx->old_bfi_cnt = st_fx->nbLostCmpt; - move16(); - } - move16(); - st_fx->last_con_tcx = st_fx->con_tcx; - move16(); - st_fx->con_tcx = 0; - - move16(); - if ( st_fx->hHQ_nbfec != NULL ) - { - st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core; - } - if ( st_fx->hTcxDec != NULL ) - { - hTcxDec->tcxConceal_recalc_exc = 0; - move16(); - } - test(); - test(); - IF( ( GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) && st_fx->use_partial_copy && st_fx->bfi ) || !st_fx->bfi ) - { - test(); - test(); - test(); - test(); - if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) - { - hTcxDec->tcxConceal_recalc_exc = 1; - move16(); - } - st_fx->last_good = st_fx->clas_dec; - move16(); - } - IF( st_fx->use_partial_copy ) - { - st_fx->prev_rf_frame_type = st_fx->rf_frame_type; - move16(); - } - ELSE - { - st_fx->prev_rf_frame_type = INACTIVE; - move16(); - } - - if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( NE_16( st_fx->bfi, 1 ) || st_fx->use_partial_copy != 0 ) ) - { - st_fx->rf_flag_last = st_fx->rf_flag; - move16(); - } - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - test(); - if ( !st_fx->bfi && ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) - { - move16(); - st_fx->last_active_brate = st_fx->total_brate; - } - - move16(); - move16(); - st_fx->last_core = st_fx->core; - if ( st_fx->hHQ_core != NULL ) - { - st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; - } - } - ELSE IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - test(); - if ( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) ) - { - move16(); - st_fx->last_active_brate = st_fx->total_brate; - } - /* INFO: moved from update_decoder_LPD_cng() */ - if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) - { - move16(); - st_fx->last_is_cng = 1; - } - - - if ( !st_fx->bfi ) - { - st_fx->last_core = st_fx->core; - } - move16(); - move16(); - st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */ - } - move16(); - st_fx->last_core_brate = st_fx->core_brate; - - /* save synthesis for core switching */ - test(); - IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) - { - Copy_Scale_sig( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); - } - test(); - test(); - test(); - IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) - - { - /* reset LP memories */ - set16_fx( st_fx->mem_MA_fx, 0, M ); - IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) - { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - } - } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - test(); - IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) ) - { - st_fx->last_nelp_mode_dec = 1; - move16(); - } - ELSE - { - st_fx->last_nelp_mode_dec = 0; - move16(); - } - } - - st_fx->prev_use_partial_copy = st_fx->use_partial_copy; - move16(); - - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - - st_fx->prev_Q_exc = st_fx->Q_exc; - move16(); - - L_tmp = L_mult( st_fx->tilt_code_dec_fx[0], 4096 ); - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mac( L_tmp, st_fx->tilt_code_dec_fx[i], 4096 ); - } - st_fx->prev_tilt_code_dec_fx = round_fx( L_tmp ); - - IF( EQ_16( st_fx->core, HQ_CORE ) ) - { - st_fx->prev_coder_type = GENERIC; - move16(); - } - ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) ) - { - st_fx->prev_coder_type = st_fx->coder_type; - move16(); - } - - test(); - IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL ) - { - if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) - { - st_fx->hTdCngDec->act_cnt = 0; - move16(); - } - - st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 ); - - test(); - if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) - { - st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 ); - } - - st_fx->hTdCngDec->act_cnt2 = add( st_fx->hTdCngDec->act_cnt2, 1 ); - if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) - { - st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD; - move16(); - } - } - - test(); - test(); - if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->first_CNG == 0 && ( EQ_16( st_fx->cng_type, LP_CNG ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - st_fx->first_CNG = 1; - move16(); - } - - /* update bandwidth switching parameters */ - st_fx->last_flag_cna = st_fx->flag_cna; - move16(); - if ( st_fx->hFdCngDec != NULL ) - { - st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; - move16(); - } - - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) - { - st_fx->m_old_frame_type = st_fx->m_frame_type; - move16(); - } - test(); - test(); - /* update bandwidth switching parameters */ - IF( EQ_16( st_fx->core, AMR_WB_CORE ) ) - { - st_fx->last_bwidth = WB; - - st_fx->prev_bws_cnt = 0; - st_fx->bws_cnt = 0; - st_fx->bws_cnt1 = 0; - move16(); - move16(); - move16(); - move16(); - } - ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) - { - updt_bw_switching_fx( st_fx, synth, Qpostd ); - } - ELSE - { - st_fx->last_bwidth = st_fx->bwidth; - st_fx->prev_bws_cnt = st_fx->bws_cnt; - move32(); - move16(); - } - - /* synchronisation of CNG seeds*/ - test(); - test(); - test(); - test(); - IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) ) - { - Random( &( st_fx->hTdCngDec->cng_seed ) ); - Random( &( st_fx->hTdCngDec->cng_ener_seed ) ); - } - - test(); - test(); - test(); - IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) - { - /* update the parameters used in waveform adjustment */ - concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); - } - - st_fx->last_total_brate_ber = st_fx->total_brate; - move32(); - IF( st_fx->bfi == 0 ) - { - st_fx->last_total_brate = st_fx->total_brate; - st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal; - move32(); - move32(); - } - st_fx->last_low_rate_mode = st_fx->low_rate_mode; - move16(); - if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) ) - { - st_fx->ini_frame = add( st_fx->ini_frame, 1 ); - } - - return; -} - - -static void ivas_updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 *synth, /* i : fixed point synthesis signal Qpost */ - const Word16 Qpost ) -{ - test(); - IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) - { - st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ); - } - - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q - move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q - move32(); - st_fx->last_bwidth = st_fx->bwidth; - move32(); - - IF( EQ_16( st_fx->core, ACELP_CORE ) ) - { - st_fx->last_inner_frame = L_FRAME32k; - move16(); - test(); - if ( EQ_16( st_fx->bwidth, WB ) && ( st_fx->bws_cnt == 0 ) ) - { - st_fx->last_inner_frame = L_FRAME16k; - move16(); - } - } - ELSE - { - test(); - test(); - test(); - IF( !( GE_16( st_fx->last_inner_frame, L_FRAME16k ) && LE_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && st_fx->bws_cnt > 0 && LT_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) ) - { - st_fx->last_inner_frame = inner_frame_tbl[st_fx->bwidth]; - move16(); - } - } - st_fx->prev_bws_cnt = st_fx->bws_cnt; - move16(); - return; -} - -static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx +static Word32 sum_32_32_fx( const Word32 *x, const Word16 length ) // Qx { Word64 sum = 0; Word16 i; @@ -802,19 +470,20 @@ static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx return W_round64_L( sum ); } -void ivas_updt_dec_common_fx( +void updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis Qpostd */ + const Word16 *synth16, /* i : decoded synthesis Qpostd */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) { Word16 i; Word32 L_tmp; - TCX_DEC_HANDLE hTcxDec; + hTcxDec = st_fx->hTcxDec; st_fx->last_codec_mode = st_fx->codec_mode; @@ -845,11 +514,12 @@ void ivas_updt_dec_common_fx( move16(); } - IF( st_fx->hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 0; move16(); } + test(); test(); test(); @@ -860,8 +530,7 @@ void ivas_updt_dec_common_fx( test(); test(); test(); - - if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) + if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 1; move16(); @@ -869,6 +538,7 @@ void ivas_updt_dec_common_fx( st_fx->last_good = st_fx->clas_dec; move16(); } + IF( st_fx->use_partial_copy ) { st_fx->prev_rf_frame_type = st_fx->rf_frame_type; @@ -879,9 +549,10 @@ void ivas_updt_dec_common_fx( st_fx->prev_rf_frame_type = INACTIVE; move16(); } + test(); test(); - if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 0 || st_fx->use_partial_copy != 0 ) ) + if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( NE_16( st_fx->bfi, 1 ) || st_fx->use_partial_copy != 0 ) ) { st_fx->rf_flag_last = st_fx->rf_flag; move16(); @@ -898,13 +569,23 @@ void ivas_updt_dec_common_fx( st_fx->last_active_brate = st_fx->total_brate; } - move16(); - move16(); - if ( !st_fx->bfi || st_fx->element_mode == EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) { st_fx->last_core = st_fx->core; + move16(); } - st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */ + ELSE + { + test(); + if ( !st_fx->bfi || st_fx->element_mode == EVS_MONO ) + { + st_fx->last_core = st_fx->core; + move16(); + } + st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */ + move16(); + } + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; @@ -919,14 +600,13 @@ void ivas_updt_dec_common_fx( move16(); st_fx->last_active_brate = st_fx->total_brate; } - /* INFO: moved from update_decoder_LPD_cng() */ + if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { move16(); st_fx->last_is_cng = 1; } - if ( !st_fx->bfi ) { st_fx->last_core = st_fx->core; @@ -942,8 +622,9 @@ void ivas_updt_dec_common_fx( test(); IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { - Copy_Scale_sig_32_16( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); + Copy_Scale_sig( synth16 + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); } + test(); test(); test(); @@ -987,6 +668,7 @@ void ivas_updt_dec_common_fx( Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } } + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); @@ -1035,7 +717,6 @@ void ivas_updt_dec_common_fx( test(); IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL ) { - if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) { st_fx->hTdCngDec->act_cnt = 0; @@ -1045,12 +726,15 @@ void ivas_updt_dec_common_fx( st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 ); test(); - if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) { st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 ); } + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + st_fx->hTdCngDec->act_cnt2 = add( st_fx->hTdCngDec->act_cnt2, 1 ); + } if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD; @@ -1101,7 +785,7 @@ void ivas_updt_dec_common_fx( } ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { - ivas_updt_bw_switching_fx( st_fx, synth, Qpostd ); + updt_bw_switching_fx( st_fx, synth16, synth, Qpostd ); } ELSE { @@ -1125,10 +809,17 @@ void ivas_updt_dec_common_fx( test(); test(); test(); - IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) + IF( hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) { /* update the parameters used in waveform adjustment */ - concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + concealment_update2_x( (const Word16 *) synth16, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); + } + ELSE + { + concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); + } } st_fx->last_total_brate_ber = st_fx->total_brate; @@ -1140,8 +831,10 @@ void ivas_updt_dec_common_fx( move32(); move32(); } + st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); + if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) ) { st_fx->ini_frame = add( st_fx->ini_frame, 1 ); diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index f72dfde5cb9a448bfda91c4f4ab3a65da22e20fb..1776d31a236c3d7bf2be8f6be3ce7be37bff2e3f 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -840,65 +840,6 @@ void concealment_init_x( } -void concealment_init_ivas_fx( - const Word16 L_frameTCX, - T_PLCInfo_HANDLE hPlcInfo ) -{ - Word16 i; - - hPlcInfo->L_frameTCX = L_frameTCX; - move16(); - hPlcInfo->Pitch_fx = 0; - move16(); - hPlcInfo->T_bfi_fx = 0; - move16(); - hPlcInfo->outx_new_n1_fx = 0; - move16(); - hPlcInfo->nsapp_gain_fx = 0; - move16(); - hPlcInfo->nsapp_gain_n_fx = 0; - move16(); - hPlcInfo->ener_mean_fx = L_deposit_l( 15213 ); - hPlcInfo->ener_fx = L_deposit_l( 0 ); - hPlcInfo->zp_fx = L_frameTCX; - move16(); - hPlcInfo->recovery_gain = 0; - move16(); - hPlcInfo->step_concealgain_fx = 0; - move16(); - hPlcInfo->concealment_method = TCX_NONTONAL; - move16(); - hPlcInfo->subframe_fx = 0; - move16(); - hPlcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); - move16(); - hPlcInfo->seed = RANDOM_INITSEED; - move16(); - - FOR( i = 0; i < TCX_TONALITY_INIT_CNT; i++ ) - { - hPlcInfo->TCX_Tonality[i] = 1; - move16(); - } - FOR( i = TCX_TONALITY_INIT_CNT; i < DEC_STATE_LEN; i++ ) - { - hPlcInfo->TCX_Tonality[i] = 0; - move16(); - } - FOR( i = 0; i < MAX_POST_LEN; i++ ) - { - hPlcInfo->Transient[i] = 1; - move16(); - } - - FOR( i = 0; i < L_FRAME_MAX; i++ ) - { - hPlcInfo->data_reci2_fx[i] = L_deposit_l( 0 ); - move32(); - } - return; -} - static Word16 own_random_fix( /* o : output random value */ Word16 *seed /* i/o: random seed Q0 */ ) @@ -924,7 +865,7 @@ void concealment_decode_fix( IF( EQ_16( curr_mode, 1 ) ) { /* copy the data of the last frame */ - MVR2R_WORD32( hPlcInfo->data_reci2_fx, invkoef, N ); + Copy32( hPlcInfo->data_reci2_fx, invkoef, N ); *invkoef_scale = hPlcInfo->data_reci2_scale; move16(); /* sign randomization */ @@ -1404,7 +1345,7 @@ static Word16 waveform_adj_fix( /* maximum pitch lag is 3/4 Framesize; pitch125_data is reused for temporary storage, since outdata2 (holding the pcm data of the last good frame) is still needed and overlapbuf overlaps outdata2 */ - Copy( &sbuf[Framesize / 4], pitch125_data, shr( imult1616( 3, Framesize ), 2 ) ); + Copy( &sbuf[shr( Framesize, 2 )], pitch125_data, shr( imult1616( 3, Framesize ), 2 ) ); hPlcInfo->nsapp_gain_fx = 0; move16(); @@ -1416,10 +1357,10 @@ static Word16 waveform_adj_fix( add_noise( sbuf, &( hPlcInfo->outx_new_n1_fx ), outdata2, tmp, &( hPlcInfo->nsapp_gain_fx ), &( hPlcInfo->nsapp_gain_n_fx ), 1 ); /* save current (noisy) output from IMDCT */ - MVR2R_WORD16( outx_new, hPlcInfo->data_noise, tmp ); + Copy( outx_new, hPlcInfo->data_noise, tmp ); /* overlapbuf can now be filled with sbuf, needed for subsequently lost frames */ - Copy( pitch125_data, &overlapbuf[Framesize / 4], shr( imult1616( 3, Framesize ), 2 ) ); + Copy( pitch125_data, &overlapbuf[shr( Framesize, 2 )], shr( imult1616( 3, Framesize ), 2 ) ); } FOR( i = 0; i < Framesize; i++ ) { @@ -1482,7 +1423,7 @@ void waveform_adj2_fix( /* save current (noisy) output from IMDCT */ IF( bfi ) { - MVR2R_WORD16( outx_new, noise_ptr, size ); + Copy( outx_new, noise_ptr, size ); } } test(); diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 91edc47a5bf9fadfcd14628755e9408acf72c9b9..b637047a2fa8f182e55c5cec56b5bdc0dcbba03d 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1099,8 +1099,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( } /*Shift old 4 bits, replace last 4 bits*/ - s = (UWord16) ( L_add( L_shl( s, 4 ), cp ) ); - t = (UWord16) L_and( s, 0xFF ); + s = add( shl( s_and( s, 0x0F ), 4 ), cp ); + t = s_and( s, 0xFF ); } /*end of the 2-tuples loop*/ } @@ -1564,7 +1564,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( cp = add( 12, esc_nb ); /* Q0 */ } /*shift old bits and replace last 4 bits*/ - s = (UWord16) L_add( L_shl( s, 4 ), cp ); + s = add( shl( s_and( s, 0x0F ), 4 ), cp ); t = s_and( s, 0xFF ); } /*end of the 2-tuples loop*/ diff --git a/lib_enc/FEC_enc_fx.c b/lib_enc/FEC_enc_fx.c index d6db81232ee9376c593bcaf04828c7e3bc90d869..3be0ff74c399dafafe2093c70288201e6cbd9585 100644 --- a/lib_enc/FEC_enc_fx.c +++ b/lib_enc/FEC_enc_fx.c @@ -3,12 +3,11 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "ivas_prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "prot_fx.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ /*============================================================================*/ @@ -63,6 +62,7 @@ void FEC_encode_fx( move16(); sign = 0; move16(); + test(); test(); IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && acelp_cfg.FEC_mode > 0 ) @@ -70,6 +70,7 @@ void FEC_encode_fx( /*-----------------------------------------------------------------* * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits) *-----------------------------------------------------------------*/ + IF( NE_16( coder_type, VOICED ) ) { /* encode signal clas with 2 bits */ @@ -94,12 +95,14 @@ void FEC_encode_fx( index = 3; move16(); } + push_indice( hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS ); } /*-----------------------------------------------------------------* * encode frame energy (5 bits) *-----------------------------------------------------------------*/ + IF( GT_16( acelp_cfg.FEC_mode, 1 ) ) /* GENERIC and VOICED frames */ { /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */ @@ -114,14 +117,16 @@ void FEC_encode_fx( Ltmp = Mpy_32_16( enr_lg_ent, enr_lg_frac, LG10_s3_0 ); /* Q14 */ tmpS = extract_h( L_shl( Ltmp, 1 ) ); /* Q15 + 1 -> Q0*/ - tmpS = s_min( tmpS, 31 ); + tmpS = s_min( tmpS, FEC_ENR_QLIMIT ); tmpS = s_max( tmpS, 0 ); push_indice( hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); } + /*-----------------------------------------------------------------* * Encode last glottal pulse position (8 bits) *-----------------------------------------------------------------*/ + IF( GT_16( acelp_cfg.FEC_mode, 2 ) ) /* GENERIC frames */ { /* retrieve the last glottal pulse position of the previous frame */ @@ -197,8 +202,8 @@ void FEC_encode_fx( *-------------------------------------------------------------------*/ void FEC_lsf_estim_enc_fx( - Encoder_State *st_fx, /* i : Encoder static memory */ - Word16 *lsf /* o : estimated LSF vector Qlog2(2.56)*/ + Encoder_State *st_fx, /* i : Encoder static memory */ + Word16 *lsf /* o : estimated LSF vector Qlog2(2.56)*/ ) { Word16 i; @@ -262,9 +267,11 @@ void FEC_lsf_estim_enc_fx( move16(); } } + /*----------------------------------------------------------------------* * Extrapolate LSF vector *----------------------------------------------------------------------*/ + tmp = sub( 32767, alpha ); /* Q15 */ /* extrapolate the old LSF vector */ FOR( i = 0; i < M; i++ ) @@ -292,175 +299,3 @@ void FEC_lsf_estim_enc_fx( return; } - -/*-------------------------------------------------------------------* - * FEC_encode() - * - * Encoder supplementary information for FEC - *-------------------------------------------------------------------*/ - -void FEC_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */ - const Word16 *synth, /* i : pointer to synthesized speech for E computation Q_Synth*/ - const Word16 coder_type, /* i : type of coder Q0*/ - Word16 clas, /* i : signal clas for current frame Q0*/ - const Word16 *fpit, /* i : close loop fractional pitch buffer Q6*/ - const Word16 *res, /* i : LP residual signal frame Qx*/ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse Q0*/ - const Word16 L_frame, /* i : Frame length Q0*/ - const Word32 total_brate, /* i : total codec bitrate Q0*/ - const Word16 Q_synth /* i : input scaling */ -) -{ - Word16 tmpS, index; - Word16 maxi, sign, tmp_FER_pitch; - Word32 enr_q, Ltmp; - Word16 exp_enrq; - - tmpS = 0; - move16(); - enr_q = 1; - move16(); - sign = 0; - move16(); - test(); - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && acelp_cfg.FEC_mode > 0 ) - { - /*-----------------------------------------------------------------* - * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits) - *-----------------------------------------------------------------*/ - IF( NE_16( coder_type, VOICED ) ) - { - /* encode signal clas with 2 bits */ - test(); - IF( clas == UNVOICED_CLAS ) - { - index = 0; - move16(); - } - ELSE IF( EQ_16( clas, VOICED_TRANSITION ) || EQ_16( clas, UNVOICED_TRANSITION ) ) - { - index = 1; - move16(); - } - ELSE IF( EQ_16( clas, VOICED_CLAS ) ) - { - index = 2; - move16(); - } - ELSE - { - index = 3; - move16(); - } - push_indice( hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS ); - } - - /*-----------------------------------------------------------------* - * encode frame energy (5 bits) - *-----------------------------------------------------------------*/ - IF( GT_16( acelp_cfg.FEC_mode, 1 ) ) /* GENERIC and VOICED frames */ - { - /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */ - /*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/ - Word32 synth32[L_FRAME16k]; - Copy_Scale_sig_16_32_DEPREC( synth, synth32, L_FRAME16k, 0 ); /* Qsynth */ - fer_energy_fx( L_frame, clas, synth32, Q_synth, shr_r( fpit[( L_frame >> 6 ) - 1], 6 ), &enr_q, L_frame ); - exp_enrq = sub( 31, shl( Q_synth, 1 ) ); - - test(); - test(); - if ( EQ_16( clas, VOICED_CLAS ) || EQ_16( clas, ONSET ) || EQ_16( clas, SIN_ONSET ) ) /* Voiced or Onset current frame */ - { - exp_enrq = 31; - move16(); - } - /* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */ - /*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP )*/ /*To be converted fl_2_fx*/ - - Ltmp = Mpy_32_32( BASOP_Util_Log10( enr_q, exp_enrq ), 894784853 /* 10 / FEC_ENR_STEP Q28 */ ); // Q 25 + 28 - 31 = Q22 - IF( Ltmp < 0 ) - { - tmpS = extract_l( L_negate( L_shr( L_negate( Ltmp ), Q22 ) ) ); /* Q0 */ - } - ELSE - { - tmpS = extract_l( L_shr( Ltmp, Q22 ) ); /* Q0 */ - } - - tmpS = s_min( tmpS, FEC_ENR_QLIMIT ); - tmpS = s_max( tmpS, 0 ); - - push_indice( hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); - } - /*-----------------------------------------------------------------* - * Encode last glottal pulse position (8 bits) - *-----------------------------------------------------------------*/ - - IF( GT_16( acelp_cfg.FEC_mode, 2 ) ) /* GENERIC frames */ - { - /* retrieve the last glottal pulse position of the previous frame */ - /* use the current pitch information to scale or not the quantization */ - tmp_FER_pitch = shr( fpit[0], 6 ); /* take the 1st subframe pit, since it is easier to get on decoder side */ - sign = 0; - move16(); - maxi = *last_pulse_pos; /* Q0 */ - move16(); - IF( maxi < 0 ) - { - sign = 1; - move16(); - /*maxi = -maxi; */ - maxi = negate( maxi ); - } - - if ( GE_16( tmp_FER_pitch, 128 ) ) - { - maxi = shr( maxi, 1 ); - } - - if ( GT_16( maxi, 127 ) ) - { - /* better not use the glottal pulse position at all instead of using a wrong pulse */ - /* can happen only with pitch > 254 and max pit = 289 and should happen very rarely */ - maxi = 0; - move16(); - } - - if ( EQ_16( sign, 1 ) ) - { - maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) Q0*/ - } - - push_indice( hBstr, IND_FEC_POS, maxi, FEC_BITS_POS ); - } - maxi = 0; - move16(); - - /* If bitrate < 24k4, then the pitch - is not represented in the same domain (12.k instead of 16k) */ - test(); - IF( GE_16( clas, VOICED_CLAS ) && GE_32( total_brate, ACELP_24k40 ) ) - { - /*maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); */ - maxi = findpulse_fx( L_frame, res, shr_r( fpit[( L_frame >> 6 ) - 1], 6 ), 0, &sign ); - if ( EQ_16( sign, 1 ) ) - { - /*maxi = -maxi;*/ - maxi = negate( maxi ); - } - } - - *last_pulse_pos = maxi; /* Q0 */ - move16(); - } - ELSE - { - *last_pulse_pos = 0; - move16(); - } - - return; -} diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index ff4c684e838c33e383021cd56e61be3292302b23..73a2e50c25f7661eda7ced243e219d814f0aa2e8 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -11,7 +11,6 @@ #include "rom_com.h" #include "rom_enc.h" /* Encoder static table prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#include "ivas_cnst.h" #include "ivas_prot_fx.h" /*-------------------------------------------------------------------* @@ -19,7 +18,9 @@ * * ACELP core encoder *--------------------------------------------------------------------*/ + ivas_error acelp_core_enc_fx( +#ifndef HARMONIZE_ACELP_ENC Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/ const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/ @@ -95,12 +96,9 @@ ivas_error acelp_core_enc_fx( ivas_error error; error = IVAS_ERR_OK; - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->core_brate, SID_2k40 ) ) - { - /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */ - return error; - } + + (void) hStereoTD; + (void) ener_fx; /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -196,31 +194,17 @@ ivas_error acelp_core_enc_fx( move16(); } - /* TD stereo */ - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) - { - tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; - tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; - tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; - tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf_fx; - } - ELSE { tdm_lp_reuse_flag = 0; tdm_low_rate_mode = 0; move16(); move16(); - if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) - { - tdm_low_rate_mode = 1; - move16(); - } tdm_Pitch_reuse_flag = 0; tdm_Pri_pitch_buf = NULL; move16(); move16(); } + /*-----------------------------------------------------------------* * ACELP@12k8 / ACELP@16k switching *-----------------------------------------------------------------*/ @@ -293,9 +277,10 @@ ivas_error acelp_core_enc_fx( { /* Run CNG post parameter update */ cng_params_postupd_fx( hTdCngEnc->ho_circ_ptr, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, - hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx ); + hTdCngEnc->cng_brate_buf, hTdCngEnc->ho_env_circ_fx, EVS_MONO, -1 ); + /* encode CNG parameters */ - CNG_enc_fx( st_fx, Aq_fx, inp_fx, ener_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); + CNG_enc_fx( st_fx, Aq_fx, inp_fx, lsp_mid_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sub( Q_new, 1 ), q_env, &sid_bw ); /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc_fx, exc2_fx, &hTdCngEnc->lp_ener_fx, st_fx->last_core_brate, @@ -436,7 +421,7 @@ ivas_error acelp_core_enc_fx( if ( !tdm_lp_reuse_flag ) { - lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, NULL, Q_new ); } /*---------------------------------------------------------------* @@ -510,7 +495,7 @@ ivas_error acelp_core_enc_fx( config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ - lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); + lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, 0, -1, NULL, Q_new ); /* recalculation of LP residual (filtering through A[z] filter) */ calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); @@ -551,21 +536,11 @@ ivas_error acelp_core_enc_fx( E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &hLPDmem->syn[M] ); Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); // Q_syn - test(); - IF( st_fx->element_mode > EVS_MONO && st_fx->hTcxEnc != NULL ) - { - Copy( syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2 ); // Q_syn - } - /*--------------------------------------------------------------------------------------* * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + IF( NE_16( nelp_mode, 1 ) ) { L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] ); move32(); @@ -640,7 +615,7 @@ ivas_error acelp_core_enc_fx( IF( !st_fx->Opt_SC_VBR ) { /* Apply a non linearity to the SHB excitation */ - non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame ); + non_linearity_fx( st_fx->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, coder_type, voice_factors_fx, st_fx->L_frame ); } test(); if ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) @@ -658,9 +633,8 @@ ivas_error acelp_core_enc_fx( IF( hTdCngEnc != NULL && ( st_fx->Opt_DTX_ON != 0 ) && ( GT_32( st_fx->core_brate, SID_2k40 ) ) ) { /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, - &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, - hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); + cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { @@ -694,12 +668,15 @@ ivas_error acelp_core_enc_fx( return error; } + /*-------------------------------------------------------------------* * acelp_core_enc_ivas_fx() * * ACELP core encoder *--------------------------------------------------------------------*/ + ivas_error acelp_core_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 inp[], /* i : input signal of the current frame Q_new*/ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ @@ -709,15 +686,23 @@ ivas_error acelp_core_enc_ivas_fx( Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/ const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/ - Word16 *q_old_syn_12k8_16, - Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits, /* o : number of unused bits Q0*/ - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ - Word16 Q_new ) +#ifndef HARMONIZE_ACELP_ENC + Word16 *q_old_syn_12k8_16, /* o : Q factor of old_syn_12k8_16k[] */ +#endif + Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ + Word16 *unbits, /* o : number of unused bits Q0*/ + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ +#ifdef HARMONIZE_ACELP_ENC + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift need to obtain 12 bits vectors */ +#else + const Word16 Q_new +#endif +) { Word16 i, nBits; /* reserved bits */ LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ @@ -726,14 +711,10 @@ ivas_error acelp_core_enc_ivas_fx( Word32 int_fs; Word16 nb_bits; /* parameters handling */ - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - Word16 pstreaklen; Word16 sid_bw = -1; move16(); - Word16 next_force_sf_bck; Word16 uc_two_stage_flag; Word16 position; - Word16 ppp_mode, nelp_mode; Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; /* bitstream */ @@ -748,61 +729,77 @@ ivas_error acelp_core_enc_ivas_fx( Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer Q_new */ Word16 *bwe_exc_fx; /* excitation for SWB TBE Q_new */ - Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], /*lsf_new_bck_fx[M],*/ lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; + +#ifdef HARMONIZE_ACELP_ENC + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + Word16 mCb1_fx, pstreaklen_fx; + Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; + Word16 tilt_code_bck_fx; + Word32 gc_threshold_bck_fx; + Word16 clip_var_bck_fx[6]; + Word16 next_force_sf_bck_fx; Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - + Word16 ppp_mode, nelp_mode; + Word16 enr, enr_index; +#else set16_fx( old_bwe_exc_fx, 0, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); set16_fx( old_exc_fx, 0, L_EXC ); set16_fx( Aq, 0, NB_SUBFR16k * ( M + 1 ) ); set16_fx( syn_fx, 0, L_FRAME16k ); +#endif - Word16 tilt_code_bck_fx; - Word32 gc_threshold_bck_fx; - Word16 clip_var_bck_fx[6]; Word32 q_env_fx[NUM_ENV_CNG]; +#ifndef HARMONIZE_ACELP_ENC set32_fx( q_env_fx, 0, NUM_ENV_CNG ); set16_fx( exc2_fx, 0, L_FRAME16k ); +#endif Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; Word16 *tdm_Pri_pitch_buf_fx; Word16 att_fx; Word16 tmpF_fx; + ivas_error error; - test(); - IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) - { - Scale_sig( st->hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2, sub( Q_new, st->prev_Q_new ) ); // Q_new - } - IF( st->hLPDmem ) + hLPDmem = st->hLPDmem; + +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode > EVS_MONO ) +#endif { - Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); // Q_new - st->hLPDmem->q_lpd_old_exc = Q_new; - move16(); - Scale_sig( st->hLPDmem->syn, M + 1, sub( Q_new, st->hLPDmem->q_lpd_syn ) ); // Q_new - st->hLPDmem->q_lpd_syn = Q_new; - move16(); - Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 - Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 - Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 - Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 - Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 - st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1 + test(); + IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) + { + Scale_sig( st->hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2, sub( Q_new, st->prev_Q_new ) ); // Q_new + } + IF( hLPDmem ) + { + Scale_sig( hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // Q_new + hLPDmem->q_lpd_old_exc = Q_new; + move16(); + Scale_sig( hLPDmem->syn, M + 1, sub( Q_new, hLPDmem->q_lpd_syn ) ); // Q_new + hLPDmem->q_lpd_syn = Q_new; + move16(); + Scale_sig( hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); // Q_new -1 + Scale_sig( hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); // Q_new -1 + hLPDmem->mem_w0 = shl_sat( hLPDmem->mem_w0, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); // Q_new -1 + move16(); + hLPDmem->q_mem_syn = sub( Q_new, 1 ); + move16(); + } + + Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); // Q_new + Q_scale - 2 + st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); move16(); - st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); // Q_new + Q_scale - 2 + st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); move16(); } - Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); // Q_new + Q_scale - 2 - st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); - move16(); - Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); // Q_new + Q_scale - 2 - st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); - move16(); - - ivas_error error; - error = IVAS_ERR_OK; move32(); @@ -818,14 +815,16 @@ ivas_error acelp_core_enc_ivas_fx( * Initialization *------------------------------------------------------------------*/ - hLPDmem = st->hLPDmem; - Es_pred_fx = 0; move16(); - exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); /* Q_new */ + exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); /* Q_new */ +#ifdef HARMONIZE_ACELP_ENC + set16_fx( old_exc_fx + L_EXC_MEM, 0, L_EXC - L_EXC_MEM ); +#else Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // Q_new +#endif IF( st->hBWE_TD != NULL ) { bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ @@ -882,8 +881,11 @@ ivas_error acelp_core_enc_ivas_fx( position = -1; move16(); +#ifdef HARMONIZE_ACELP_ENC /* SC-VBR temporary variables */ - pstreaklen = 0; + mCb1_fx = 0; + move16(); + pstreaklen_fx = 0; move16(); clip_var_fx = 0; move16(); @@ -895,23 +897,25 @@ ivas_error acelp_core_enc_ivas_fx( /* channel-aware mode */ reset_rf_indices_fx( st ); - /* VBR modes */ + /* SC-VBR modes */ IF( st->Opt_SC_VBR ) { ppp_mode = st->hSC_VBR->ppp_mode; nelp_mode = st->hSC_VBR->nelp_mode; + move16(); + move16(); } ELSE { ppp_mode = 0; nelp_mode = 0; + move16(); + move16(); } - move16(); - move16(); +#endif test(); /* TD stereo */ - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; // Q0 @@ -976,11 +980,11 @@ ivas_error acelp_core_enc_ivas_fx( IF( st->rate_switching_reset ) { /*extrapolation in case of unstable LSP*/ - int_lsp4_ivas_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); + int_lsp4_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); } ELSE { - int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 ); + int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 ); } /* Reset LPC mem */ @@ -1008,78 +1012,128 @@ ivas_error acelp_core_enc_ivas_fx( /*----------------------------------------------------------------* * Encoding of CNG frames *----------------------------------------------------------------*/ + test(); IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) { IF( st->cng_type == LP_CNG ) { /* Run CNG post parameter update */ - cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); + cng_params_postupd_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); /* encode CNG parameters */ - CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); + CNG_enc_fx( st, Aq, inp, lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate, &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho, q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO ); - Scale_sig( exc_fx, st->L_frame, 1 ); // Q_new + 1 +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode > EVS_MONO ) +#endif + { + Scale_sig( exc_fx, st->L_frame, 1 ); // Q_new + 1 + } } ELSE { - test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - FdCng_encodeSID_ivas_fx( st ); - st->hDtxEnc->last_CNG_L_frame = st->L_frame; - move16(); - } - - Word16 Q_cngNoise = Q31, zero_flag = 0; - move16(); - move16(); - FOR( Word16 j = 0; j < NPART; j++ ) +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) { - IF( st->hFdCngEnc->hFdCngCom->cngNoiseLevel[j] != 0 ) + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - zero_flag = 1; + FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac ); + st->hDtxEnc->last_CNG_L_frame = st->L_frame; move16(); - BREAK; } - } - IF( zero_flag ) - { - Q_cngNoise = getScaleFactor32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART ); - } - Scale_sig32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART, Q_cngNoise ); /* st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp - Q_cngNoise */ - st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise ); - move16(); - generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 ); - st->hTcxEnc->q_Txnq = Q_new; - move16(); - Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) ); /* Q12 */ - FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq, lsp_new, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - Copy( exc2_fx, exc3_fx, st->L_frame ); // Q_new + generate_comfort_noise_enc_fx( st, Q_new, 1 ); - IF( EQ_32( st->core_brate, SID_2k40 ) ) - { - IF( st->hTdCngEnc != NULL ) + FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, + st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq, lsp_new, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); + + Copy( exc2_fx, exc3_fx, st->L_frame ); // Q12 + + IF( EQ_32( st->core_brate, SID_2k40 ) ) { - Word16 enr, enr_index; - enr = cng_energy_ivas_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att_fx, exc_fx, st->L_frame, Q_new ); /* Q8 */ + IF( st->hTdCngEnc != NULL ) + { + enr = cng_energy_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/ 0, exc_fx, st->L_frame, Q_new ); // Q8 - /* calculate the energy quantization index */ - enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ - enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ + /* calculate the energy quantization index */ + enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ + enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ - /* limit the energy quantization index */ - enr_index = s_min( enr_index, 127 ); /* Q0 */ - enr_index = s_max( enr_index, 0 ); - st->hTdCngEnc->old_enr_index = enr_index; /* Q0 */ + /* limit the energy quantization index */ + enr_index = s_min( enr_index, 127 ); // Q0 + enr_index = s_max( enr_index, 0 ); + + st->hTdCngEnc->old_enr_index = enr_index; /* Q0 */ + move16(); + } + } + } + ELSE +#endif + { + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + FdCng_encodeSID_ivas_fx( st ); + st->hDtxEnc->last_CNG_L_frame = st->L_frame; move16(); } + + Word16 Q_cngNoise = Q31, zero_flag = 0; + move16(); + move16(); + FOR( i = 0; i < NPART; i++ ) + { + IF( st->hFdCngEnc->hFdCngCom->cngNoiseLevel[i] != 0 ) + { + zero_flag = 1; + move16(); + BREAK; + } + } + IF( zero_flag ) + { + Q_cngNoise = getScaleFactor32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART ); + } + Scale_sig32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART, Q_cngNoise ); /* st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp - Q_cngNoise */ + st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise ); + move16(); + + generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 ); + st->hTcxEnc->q_Txnq = Q_new; + move16(); + + Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) ); /* Q12 */ + FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq, lsp_new, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); + Copy( exc2_fx, exc3_fx, st->L_frame ); // Q_new + + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + IF( st->hTdCngEnc != NULL ) + { +#ifndef HARMONIZE_ACELP_ENC + Word16 enr, enr_index; +#endif + enr = cng_energy_ivas_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att_fx, exc_fx, st->L_frame, Q_new ); /* Q8 */ + + /* calculate the energy quantization index */ + enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ + enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ + + /* limit the energy quantization index */ + enr_index = s_min( enr_index, 127 ); /* Q0 */ + enr_index = s_max( enr_index, 0 ); + st->hTdCngEnc->old_enr_index = enr_index; /* Q0 */ + move16(); + } + } } } @@ -1090,27 +1144,33 @@ ivas_error acelp_core_enc_ivas_fx( move16(); } - Scale_sig( st->hLPDmem->mem_syn, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn - Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn - Scale_sig( st->hLPDmem->mem_syn2, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn - Scale_sig( st->hLPDmem->mem_syn3, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn - Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn - st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn - move16(); - st->hLPDmem->q_mem_syn = st->Q_syn; - move16(); - // Scaling Aq to Q12 - FOR( Word16 k = 0; k < NB_SUBFR16k; k++ ) +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) { - Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) ); + /* synthesis at 12.8kHz sampling rate */ + syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new, st->Q_syn ); + } + ELSE +#endif + { + Scale_sig( hLPDmem->mem_syn, M, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( hLPDmem->mem_syn2, M, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( hLPDmem->mem_syn3, M, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn + Scale_sig( hLPDmem->mem_syn_r, L_SYN_MEM, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn + hLPDmem->mem_w0 = shl_sat( hLPDmem->mem_w0, sub( st->Q_syn, hLPDmem->q_mem_syn ) ); // st->Q_syn + move16(); + hLPDmem->q_mem_syn = st->Q_syn; + move16(); + + /* synthesis at 12.8kHz sampling rate */ + syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn ); } - /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn ); /* reset the encoder */ CNG_reset_enc_fx( st, hLPDmem, pitch_buf, voice_factors_fx, 0 ); - /* update st->mem_syn1_flt for ACELP core switching */ + /* update st->mem_syn1_fx for ACELP core switching */ Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); /* hLPDmem->q_mem_syn */ /* update ACELP core synthesis filter memory */ @@ -1122,39 +1182,67 @@ ivas_error acelp_core_enc_ivas_fx( /* save and delay synthesis to be used by SWB BWE */ IF( st->hBWE_FD != NULL ) { - st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */ - move16(); - Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */ - save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - *q_old_syn_12k8_16 = st->Q_syn; - move16(); - st->hBWE_FD->q_mem_deemph_old_syn = st->Q_syn; - move16(); +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) + { + save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } + ELSE +#endif + { + st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */ + move16(); + Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */ + save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); +#ifdef HARMONIZE_ACELP_ENC + Scale_sig( old_syn_12k8_16k, st->L_frame, sub( sub( Q_new, 1 ), st->Q_syn ) ); // Q_syn +#else + *q_old_syn_12k8_16 = st->Q_syn; + move16(); +#endif + st->hBWE_FD->q_mem_deemph_old_syn = st->Q_syn; + move16(); + } } - Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); /* st->Q_syn */ - st->hLPDmem->q_lpd_syn = st->Q_syn; + Scale_sig( hLPDmem->syn, M + 1, sub( st->Q_syn, hLPDmem->q_lpd_syn ) ); /* st->Q_syn */ + hLPDmem->q_lpd_syn = st->Q_syn; move16(); /*Update MODE2 core switching memory*/ - deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) + { + E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st->preemph_fac, st->L_frame, &hLPDmem->syn[M] ); + } + ELSE +#endif + { + deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); + } Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 ); /* st->Q_syn */ } /*----------------------------------------------------------------* * Encoding of all other frames *----------------------------------------------------------------*/ + ELSE { +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode > EVS_MONO ) +#endif + { + Word16 temp = getScaleFactor16( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k ); + Scale_sig( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k, temp ); /* Q_last_exc_dct_in + temp */ + st->hGSCEnc->Q_last_exc_dct_in = add( st->hGSCEnc->Q_last_exc_dct_in, temp ); + move16(); + } /*-----------------------------------------------------------------* * Configure ACELP bit allocation *-----------------------------------------------------------------*/ - Word16 temp = getScaleFactor16( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k ); - Scale_sig( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k, temp ); /* Q_last_exc_dct_in + temp */ - st->hGSCEnc->Q_last_exc_dct_in = add( st->hGSCEnc->Q_last_exc_dct_in, temp ); - move16(); nb_bits = 0; move16(); st->acelp_cfg.FEC_mode = 0; @@ -1162,8 +1250,10 @@ ivas_error acelp_core_enc_ivas_fx( uc_two_stage_flag = 0; move16(); +#ifdef HARMONIZE_ACELP_ENC test(); IF( !nelp_mode && !ppp_mode ) +#endif { config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } @@ -1203,12 +1293,15 @@ ivas_error acelp_core_enc_ivas_fx( * A[z] calculation *-----------------------------------------------------------------*/ - /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ - lsf_syn_mem_backup_ivas_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen ); +#ifdef HARMONIZE_ACELP_ENC + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + lsf_syn_mem_backup_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, lsp_new, lsf_new_fx, lsp_mid, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, + lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx ); +#endif IF( !tdm_lp_reuse_flag ) { - lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); + lsf_enc_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new ); } ELSE { @@ -1244,20 +1337,16 @@ ivas_error acelp_core_enc_ivas_fx( st->stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); // Q15 move16(); } - // Scaling Aq to Q12 - FOR( Word16 k = 0; k < NB_SUBFR16k; k++ ) - { - Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) ); - } + test(); IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO ) { /* Prepare ACB memory from last HQ frame */ tmpF_fx = hLPDmem->old_exc[0]; move16(); - PREEMPH_FX( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF_fx ); + preemph_fx( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF_fx ); Copy( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M ); /* Q_new */ - Scale_sig( st->hLPDmem->mem_syn, M, sub( st->hLPDmem->q_mem_syn, Q_new ) ); + Scale_sig( hLPDmem->mem_syn, M, sub( hLPDmem->q_mem_syn, Q_new ) ); Residu3_fx( Aq, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 ); } @@ -1280,7 +1369,8 @@ ivas_error acelp_core_enc_ivas_fx( *---------------------------------------------------------------*/ calc_residu_fx( st, inp, res_fx, Aq ); - calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); + + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) ) { @@ -1312,38 +1402,48 @@ ivas_error acelp_core_enc_ivas_fx( /*------------------------------------------------------------* * Encode excitation according to coding type *------------------------------------------------------------*/ + test(); test(); IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { IF( LE_16( st->coder_type, UNVOICED ) ) { - tdm_low_rate_enc( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); + tdm_low_rate_enc_fx( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new ); } ELSE /* GENERIC */ { - encod_gen_2sbfr( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); + encod_gen_2sbfr_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); } } +#ifdef HARMONIZE_ACELP_ENC ELSE IF( nelp_mode ) { /* SC-VBR - NELP frames */ - encod_nelp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ); + encod_nelp_fx( st, inp, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); } - +#endif ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ); +#ifdef HARMONIZE_ACELP_ENC + encod_unvoiced_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ); +#else + encod_unvoiced_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ); +#endif } ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { - encod_tran_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, 0, Q_new ); +#ifdef HARMONIZE_ACELP_ENC + encod_tran_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, shift, Q_new ); +#else + encod_tran_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, 0, Q_new ); +#endif } +#ifdef HARMONIZE_ACELP_ENC ELSE IF( ppp_mode ) { - /* SC-VBR - PPP frames */ - IF( ( error = encod_ppp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = encod_ppp_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) { return error; } @@ -1351,32 +1451,47 @@ ivas_error acelp_core_enc_ivas_fx( IF( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ - lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); + lsf_syn_mem_restore_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, + lsp_new, lsf_new_fx, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, + lsp_mid_bck_fx, mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); /* Configure ACELP bit allocation */ config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); /* redo LSF quantization */ - lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new ); + lsf_enc_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, 0, -1, NULL, Q_new ); /* recalculation of LP residual (filtering through A[z] filter) */ calc_residu_fx( st, inp, res_fx, Aq ); + st->hTdCngEnc->burst_ho_cnt = 0; move16(); - - /* VOICED frames in SC-VBR */ - encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new ); + /* VOICED frames in SC-VBR when bumped up*/ + encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); } } +#endif ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ +#ifndef FIX_1904_HARM_GSC_ENC encod_audio_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); +#else +#ifdef HARMONIZE_ACELP_ENC + encod_audio_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, shift ); +#else + encod_audio_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 ); +#endif +#endif } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new ); +#ifdef HARMONIZE_ACELP_ENC + encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, shift, Q_new ); +#else + encod_gen_voic_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new ); +#endif } /* update mem_syn1_flt for ACELP core switching */ @@ -1384,33 +1499,60 @@ ivas_error acelp_core_enc_ivas_fx( /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ Copy( syn_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); // hLPDmem->q_mem_syn - // st->Q_syn = Q_new - 1; +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode > EVS_MONO ) + { + Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn + } +#else Scale_sig( syn_fx, L_FRAME16k, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn +#endif + /* save and delay synthesis to be used by SWB BWE */ IF( st->hBWE_FD != NULL ) { - st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) - move16(); - Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) + { + save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); + } + ELSE +#endif + { + st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) + move16(); + Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) - save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - *q_old_syn_12k8_16 = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); - move16(); - st->hBWE_FD->q_mem_deemph_old_syn = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); - move16(); - Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ) ); // st->Q_syn + save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); +#ifdef HARMONIZE_ACELP_ENC + Scale_sig( old_syn_12k8_16k, st->L_frame, sub( sub( Q_new, 1 ), st->Q_syn ) ); // Q_syn +#else + *q_old_syn_12k8_16 = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); + move16(); +#endif + st->hBWE_FD->q_mem_deemph_old_syn = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ); + move16(); + Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ) ); // st->Q_syn + } } /*Update MODE2 core switching memory*/ - Copy( syn_fx, syn1_fx, st->L_frame ); // st->Q_syn + Copy( syn_fx, syn1_fx, st->L_frame ); // Q_syn Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); // st->Q_syn st->hLPDmem->q_lpd_syn = st->Q_syn; move16(); - /*Update MODE2 core switching memory*/ - deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); - +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) + { + E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st->preemph_fac, st->L_frame, &hLPDmem->syn[M] ); + } + ELSE +#endif + { + deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) ); + } Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 ); // st->Q_syn test(); @@ -1425,26 +1567,47 @@ ivas_error acelp_core_enc_ivas_fx( /*--------------------------------------------------------------------------------------* * Modify the excitation signal when the noise is stationary *--------------------------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) { - /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ - Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new - Word16 q_exc2 = Q_new; - move16(); - stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); + IF( NE_16( nelp_mode, 1 ) ) + { + Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new + stat_noise_uv_enc_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new ); + } + } + ELSE +#endif + { + test(); + test(); + test(); + IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new + Word16 q_exc2 = Q_new; + move16(); + stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); + } } /*-----------------------------------------------------------------* * Encode supplementary information for Frame Error Concealment *-----------------------------------------------------------------*/ - Scale_sig( syn_fx, L_FRAME, sub( s_min( st->Q_syn, Q_new ), st->Q_syn ) ); // min( st->Q_syn, Q_new ) - Scale_sig( res_fx, st->L_frame, sub( s_min( st->Q_syn, Q_new ), Q_new ) ); // min( st->Q_syn, Q_new ) - FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, s_min( st->Q_syn, Q_new ) ); +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) + { + FEC_encode_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, Q_new, shift ); + } + ELSE +#endif + { + FEC_encode_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, add( st->Q_syn, 1 ), 0 ); + } + IF( st->hBWE_TD != NULL ) { IF( EQ_16( st->L_frame, L_FRAME ) ) @@ -1457,12 +1620,12 @@ ivas_error acelp_core_enc_ivas_fx( } } - } /* end of active inp coding */ /*-----------------------------------------------------------------* * Write ACELP unused bits *-----------------------------------------------------------------*/ + test(); test(); IF( NE_32( st->core_brate, SID_2k40 ) && st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, PPP_NELP_2k80 ) ) @@ -1491,9 +1654,13 @@ ivas_error acelp_core_enc_ivas_fx( test(); test(); test(); +#ifdef HARMONIZE_ACELP_ENC test(); test(); - IF( ( EQ_16( st->last_Opt_SC_VBR, 1 ) && st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) + IF( ( st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) +#else + IF( ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) +#endif { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); @@ -1504,13 +1671,26 @@ ivas_error acelp_core_enc_ivas_fx( test(); test(); test(); +#ifdef HARMONIZE_ACELP_ENC test(); IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) +#else + IF( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) +#endif { /* Apply a non linearity to the SHB excitation */ - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc - non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode == EVS_MONO ) + { + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); + } + ELSE +#endif + { + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + non_linearity_fx( st->element_mode, bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + } } test(); @@ -1525,40 +1705,61 @@ ivas_error acelp_core_enc_ivas_fx( * Updates *-----------------------------------------------------------------*/ - if ( st->hBWE_TD != NULL ) +#ifdef HARMONIZE_ACELP_ENC + IF( st->element_mode > EVS_MONO ) +#endif { - st->Q_exc = Q_new; + if ( st->hBWE_TD != NULL ) + { + st->Q_exc = Q_new; + move16(); + } +#ifdef HARMONIZE_ACELP_ENC + hLPDmem->q_lpd_old_exc = Q_new; move16(); +#endif } updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx ); +#ifndef HARMONIZE_ACELP_ENC st->hLPDmem->q_lpd_old_exc = Q_new; move16(); +#endif test(); test(); IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && GT_32( st->core_brate, SID_2k40 ) ) { /* update CNG parameters in active frames */ - Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0]; +#ifdef HARMONIZE_ACELP_ENC + Word16 q_exc = Q_new; move16(); - FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) + IF( st->element_mode > EVS_MONO ) { - q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ); - } - q_exc = s_min( q_exc, Q_new ); - - Scale_sig( exc_fx, L_EXC - L_EXC_MEM, sub( q_exc, Q_new ) ); // q_exc - FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ ) - { - Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); // Q_exc - st->hTdCngEnc->cng_Qexc_buf[ii] = q_exc; +#endif +#ifndef HARMONIZE_ACELP_ENC + Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0]; move16(); +#endif + FOR( i = 0; i < HO_HIST_SIZE; i++ ) + { + q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[i] ); + } + q_exc = s_min( q_exc, Q_new ); + + Scale_sig( exc_fx, L_EXC - L_EXC_MEM, sub( q_exc, Q_new ) ); // q_exc + FOR( i = 0; i < HO_HIST_SIZE; i++ ) + { + Scale_sig( st->hTdCngEnc->cng_exc2_buf + i * L_FFT, L_FFT, sub( q_exc, st->hTdCngEnc->cng_Qexc_buf[i] ) ); // Q_exc + st->hTdCngEnc->cng_Qexc_buf[i] = q_exc; + move16(); + } +#ifdef HARMONIZE_ACELP_ENC } - cng_params_upd_ivas_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, - &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, - st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, - st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#endif + + cng_params_upd_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, + q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); IF( EQ_16( st->L_frame, L_FRAME ) ) { @@ -1576,6 +1777,7 @@ ivas_error acelp_core_enc_ivas_fx( st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 1; } move16(); + /* efficient DTX hangover control */ IF( GT_16( st->hTdCngEnc->burst_ho_cnt, 1 ) ) { @@ -1583,15 +1785,15 @@ ivas_error acelp_core_enc_ivas_fx( } } +#ifdef HARMONIZE_ACELP_ENC /* SC-VBR update of average data rate */ - IF( EQ_16( st->vad_flag, 1 ) ) + test(); + IF( EQ_16( st->vad_flag, 1 ) && ( st->hSC_VBR != NULL ) ) { - /* reset in case of bitrate switching in EVS */ - if ( st->hSC_VBR != NULL ) - { - update_average_rate_fx( st->hSC_VBR, st->core_brate ); - } + update_average_rate_fx( st->hSC_VBR, st->core_brate ); } +#endif + pop_wmops(); return error; diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 2f51be28e414ed30a524fe93305985f51a158c48..b4c10b9acc5795dd1ab5351e9cca00f36055c22e 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -15,15 +15,12 @@ * Local function prototypes *---------------------------------------------------------------------*/ -static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); - -static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); +static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, const Word16 shift, const Word16 Q_new ); static void bwe_switch_enc_fx( Encoder_State *st_fx, const Word16 *new_speech ); -static void bwe_switch_enc_ivas_fx( Encoder_State *st_fx, const Word16 *new_speech ); +static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, const Word16 qx, const Word16 qy, Word16 *qo, const Word16 len, const Word16 delta ); -static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta ); /*-------------------------------------------------------------------* * acelp_core_switch_enc_fx() @@ -36,8 +33,8 @@ void acelp_core_switch_enc_fx( const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 i, j, T_op[2]; Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ @@ -164,117 +161,6 @@ void acelp_core_switch_enc_fx( } -void acelp_core_switch_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ - const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 shift, - Word16 Q_new ) -{ - Word16 i, j, T_op[2]; - Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ - const Word16 *inp; - Word32 cbrate; - Word16 Aq[2 * ( M + 1 )]; - LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - Word16 nb_bits; - UWord16 value; - - hLPDmem = st_fx->hLPDmem; - - /* initializations */ - exc = &old_exc[L_EXC_MEM]; - move16(); /* pointer to excitation signal in the current frame */ - Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */ - - Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); /* Q12 */ - Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); /* Q12 */ - T_op[0] = st_fx->pitch[0]; /* Q12 */ - move16(); - T_op[1] = st_fx->pitch[1]; /* Q12 */ - move16(); - - /*----------------------------------------------------------------* - * set switching frame bitrate - *----------------------------------------------------------------*/ - - IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) /* ACELP@12k8 core */ - { - inp = inp12k8; /* Q0 */ - - IF( GT_32( st_fx->core_brate, ACELP_24k40 ) ) - { - cbrate = L_add( ACELP_24k40, 0 ); - } - ELSE - { - cbrate = L_add( st_fx->core_brate, 0 ); - } - } - ELSE /* ACELP@16k core */ - { - inp = inp16k; /* Q0 */ - - IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - cbrate = L_add( ACELP_8k00, 0 ); - } - ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) ) - { - cbrate = L_add( ACELP_14k80, 0 ); - } - ELSE - { - cbrate = L_min( st_fx->core_brate, ACELP_22k60 ); /* Q0 */ - } - } - - IF( NE_16( st_fx->last_L_frame, L_FRAME ) ) - { - T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480 /* 1.25 in Q14 */, T_op[0] ), 2 ) ), 1 ), 1 ); /* Q0 */ - move16(); - T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480 /* 1.25 in Q14 */, T_op[1] ), 2 ) ), 1 ), 1 ); /* Q0 */ - move16(); - } - - /*----------------------------------------------------------------* - * Excitation encoding - *----------------------------------------------------------------*/ - - config_acelp1_fx( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); - - encod_gen_voic_core_switch_ivas_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); - - /*----------------------------------------------------------------* - * bit-stream: modify the layer of sub frame CELP - *----------------------------------------------------------------*/ - - i = find_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits ); /* Q0 */ - - while ( hBstr->ind_list[i].id == TAG_ACELP_SUBFR_LOOP_START ) - { - push_indice( hBstr, IND_CORE_SWITCHING_CELP_SUBFRAME, hBstr->ind_list[i].value, hBstr->ind_list[i].nb_bits ); - i++; - } - delete_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START ); - - /*----------------------------------------------------------------* - * BWE encoding - *----------------------------------------------------------------*/ - - test(); - test(); - IF( !( ( EQ_16( st_fx->last_L_frame, L_FRAME16k ) && EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) ) - { - bwe_switch_enc_ivas_fx( st_fx, (const Word16 *) st_fx->old_input_signal_fx ); - } - - return; -} - - /*-------------------------------------------------------------------* * encod_gen_voic_core_switch() * @@ -290,8 +176,8 @@ static void encod_gen_voic_core_switch_fx( const Word16 T_op[], /* i : open loop pitch Q0*/ Word16 *exc, /* i/o: current non-enhanced excitation Q_exc*/ const Word32 core_bitrate, /* i : switching frame bitrate Q0*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 res[L_SUBFR]; /* residual signal Qexc */ Word16 Ap[M + 1]; /* A(z) with spectral expansion Q12 */ @@ -374,7 +260,6 @@ static void encod_gen_voic_core_switch_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - Copy( res, exc, L_SUBFR ); /* Q1 */ IF( EQ_16( L_frame, L_FRAME16k ) ) @@ -419,6 +304,7 @@ static void encod_gen_voic_core_switch_fx( /*-----------------------------------------------------------------* * LP filtering of the adaptive excitation, codebook target computation *-----------------------------------------------------------------*/ + lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */ lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ @@ -432,11 +318,12 @@ static void encod_gen_voic_core_switch_fx( *-----------------------------------------------------------------*/ inov_encode_fx( st_fx, core_bitrate, 0, L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, - h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); + h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift, 0 ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ + IF( EQ_16( L_frame, L_FRAME ) ) { gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, @@ -489,216 +376,6 @@ static void encod_gen_voic_core_switch_fx( return; } -static void encod_gen_voic_core_switch_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 inp[], /* i : input signal Q0*/ - const Word16 Aq[], /* i : LP coefficients Q12*/ - const Word16 A[], /* i : unquantized A(z) filter Q12*/ - const Word16 T_op[], /* i : open loop pitch Q0*/ - Word16 *exc, /* i/o: current non-enhanced excitation Q_exc*/ - const Word32 core_bitrate, /* i : switching frame bitrate Q0*/ - Word16 shift, - Word16 Q_new ) -{ - Word16 res[L_SUBFR]; /* residual signal Qexc */ - Word16 Ap[M + 1]; /* A(z) with spectral expansion Q12 */ - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - - Word16 code[L_SUBFR]; /* Fixed codebook excitation Q9 */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit; /* Pitch gain Q15 */ - Word16 voice_fac; /* Voicing factor Q15 */ - Word32 gain_code; /* Gain of code Q16 */ - Word16 gain_inov; /* inovation gain */ - Word16 i, gcode16; /* tmp variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 T0_min, T0_max; /* pitch variables */ - - Word16 pitch, tmp16; /* floating pitch value */ - Word16 g_corr[6]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain; /* ISF clip gain */ - - Word16 unbits; /* number of unused bits for PI */ - Word32 norm_gain_code; - Word16 pitch_limit_flag; - Word32 L_tmp, Lgcode; - Word16 shift_wsp; - Word16 h2[L_SUBFR + ( M + 1 )]; - Word16 dummyF[NB_SUBFR16k]; - Word16 lp_select, lp_flag; - Word16 q_h1; - LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - BSTR_ENC_HANDLE hBstr; - - hLPDmem = st_fx->hLPDmem; - hBstr = st_fx->hBstr; - - // TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - shift_wsp = add( Q_new, shift ); - - unbits = 0; - move16(); - - IF( EQ_16( L_frame, L_FRAME ) ) - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max = PIT16k_MAX; - move16(); - T0_min = PIT16k_MIN; - move16(); - } - - /*------------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *------------------------------------------------------------------*/ - - tmp16 = st_fx->L_frame; /* Q0 */ - move16(); - st_fx->L_frame = L_SUBFR; - move16(); - calc_residu_fx( st_fx, inp, res, Aq ); - - // hTdCngEnc->burst_ho_cnt = 0; - st_fx->L_frame = tmp16; /* Q0 */ - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - - Copy( res, exc, L_SUBFR ); /* Q_exc */ - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - weight_a_fx( A, Ap, GAMMA16k, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_ivas_fx( inp, hLPDmem->mem_syn, 0, &( hLPDmem->mem_w0 ), Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1 ); - } - ELSE - { - weight_a_fx( A, Ap, GAMMA1, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_ivas_fx( inp, hLPDmem->mem_syn, 0, &( hLPDmem->mem_w0 ), Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn, h1 ); - } - - q_h1 = sub( 14, norm_s( h1[0] ) ); - Copy_Scale_sig( h1, h2, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn, L_SUBFR, shift ); /* Q_new */ - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - - set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */ - pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/, st_fx->element_mode, Q_new ); /* Q6 */ - - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4_ivas_fx( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - - clip_gain = gp_clip_fx( st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */ - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ - lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */ - Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14+shift*/ - lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */ - IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) - { - push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - - inov_encode_ivas_fx( st_fx, core_bitrate, 0, L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, - h2, hLPDmem->tilt_code, pitch, xn2, code, y2, &unbits, L_SUBFR, shift, Q_new ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - IF( EQ_16( L_frame, L_FRAME ) ) - { - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - ELSE - { - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - gp_clip_test_gain_pit_fx( st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx ); - - Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx( Lgcode ); /* Q0 */ - - // hLPDmem->tilt_code = Est_tilt2( exc + 0, gain_pit, code, gain_code, &voice_fac, shift ); - // Q_new or shift ?? ->Qexc - hLPDmem->tilt_code = est_tilt_ivas_fx( exc + 0, gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); /* Q15 */ - move16(); - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - *-----------------------------------------------------------------*/ - - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gcode16, code[i] ); /* Q10 */ - L_tmp = L_shl_sat( L_tmp, 5 ); /* Q15 */ - L_tmp = L_mac_sat( L_tmp, exc[i], gain_pit ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc[i] = round_fx_sat( L_tmp ); /* Q_exc */ - move16(); - } - - /* write reserved bits */ - IF( unbits ) - { - push_indice( hBstr, IND_UNUSED, 0, unbits ); - } - - /*-----------------------------------------------------------------* - * long term prediction on the 2nd sub frame - *-----------------------------------------------------------------*/ - - pred_lt4_ivas_fx( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - FOR( i = L_SUBFR; i < 2 * L_SUBFR; i++ ) - { - exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) ); /* Q_exc */ - move16(); - } - - return; -} /*-------------------------------------------------------------------* * bwe_switch_enc() @@ -850,155 +527,14 @@ static void bwe_switch_enc_fx( } -static void bwe_switch_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *new_speech_fx /* i : original input signal Q0 */ -) -{ - - Word16 k, Loverlapp_fx, d1m_fx, maxd1_fx, ind1_fx, gapsize_fx; - Word16 delta_fx, fdelay_fx; - const Word16 *hp_filter_fx; - const Word16 *fpointers_tab[6] = { hp12800_16000_fx, hp12800_32000_fx, hp12800_48000_fx, hp16000_48000_fx, hp16000_32000_fx, hp16000_48000_fx }; - Word16 tmp, shift; - const Word16 *ptmp; - Word16 tmp_mem_fx[2 * L_FILT48k], tmp_mem2_fx[2 * L_FILT48k], hb_synth_tmp_fx[480]; - Word16 Fs_kHz; - Word16 q_tmp1, q_tmp2, Qmc, Qsq; - Word32 L_tmp1, L_tmp2, L_tmp3, min_sq_cross_fx; - Word16 accA_fx, accB_fx, min_corr_fx, E1_fx, E2_fx, gain_fx; - Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ - Word16 n, L; - BSTR_ENC_HANDLE hBstr; - - hBstr = st_fx->hBstr; - L = NS2SA_FX2( st_fx->input_Fs, FRAME_SIZE_NS ); - - /* set multiplication factor according to the sampling rate */ - tmp = extract_l( L_shr( st_fx->input_Fs, 14 ) ); - delta_fx = add( tmp, 1 ); - Fs_kHz = shl( delta_fx, 4 ); - tmp = add( tmp, i_mult2( 3, ( sub( st_fx->last_L_frame, L_FRAME ) != 0 ) ) ); - ptmp = fpointers_tab[tmp]; - move16(); - - hp_filter_fx = ptmp; - fdelay_fx = i_mult2( 16, delta_fx ); - IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) - { - fdelay_fx = i_mult2( 20, delta_fx ); - } - - n = i_mult2( N16_CORE_SW, delta_fx ); - - set16_fx( tmp_mem_fx, 0, 2 * L_FILT48k ); - set16_fx( tmp_mem2_fx, 0, 2 * L_FILT48k ); - - Loverlapp_fx = i_mult2( delta_fx, SWITCH_OVERLAP_8k * 2 ); - gapsize_fx = i_mult2( delta_fx, NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) ); - - shift = sub( add( add( shr( L, 1 ), n ), Loverlapp_fx ), gapsize_fx ); - Copy( new_speech_fx + shift, synth_subfr_bwe_fx, add( gapsize_fx, fdelay_fx ) ); - Copy( new_speech_fx + sub( shift, fdelay_fx ), tmp_mem_fx, fdelay_fx ); - - tmp = add( gapsize_fx, fdelay_fx ); - fir_fx( synth_subfr_bwe_fx, hp_filter_fx, synth_subfr_bwe_fx, tmp_mem_fx, tmp, fdelay_fx, 0, 0 ); - Copy( synth_subfr_bwe_fx + shr( fdelay_fx, 1 ), synth_subfr_bwe_fx, sub( gapsize_fx, shr( fdelay_fx, 1 ) ) ); - - tmp = i_mult2( Fs_kHz, 10 ); - fir_fx( new_speech_fx, hp_filter_fx, hb_synth_tmp_fx, tmp_mem2_fx, tmp, fdelay_fx, 1, 0 ); - - min_sq_cross_fx = L_negate( 1 ); - Qsq = 0; - move16(); - min_corr_fx = 0; - move16(); - Qmc = 0; - move16(); - d1m_fx = 0; - move16(); - - maxd1_fx = sub( tmp, add( gapsize_fx, fdelay_fx ) ); - - IF( EQ_16( delta_fx, 2 ) ) - { - maxd1_fx = shr( maxd1_fx, 1 ); - } - ELSE IF( EQ_16( delta_fx, 3 ) ) - { - maxd1_fx = extract_h( L_mult( maxd1_fx, 10923 ) ); - } - - /* find delay */ - ptmp = &hb_synth_tmp_fx[fdelay_fx]; - - FOR( k = 0; k < maxd1_fx; k++ ) - { - accA_fx = dotprod_satcont( ptmp, ptmp, 0, 0, &q_tmp1, gapsize_fx, delta_fx ); - accB_fx = dotprod_satcont( ptmp, synth_subfr_bwe_fx, 0, 0, &q_tmp2, gapsize_fx, delta_fx ); - ptmp += delta_fx; - L_tmp1 = L_mult0( accB_fx, accB_fx ); /*2*q_tmp2; */ - L_tmp2 = Mult_32_16( L_tmp1, min_corr_fx ); /*2*q_tmp2+Qmc-15 */ - L_tmp3 = Mult_32_16( min_sq_cross_fx, accA_fx ); /*Qsq+q_tmp1-15 */ - shift = s_min( add( shl( q_tmp2, 1 ), Qmc ), add( q_tmp1, Qsq ) ); - L_tmp2 = L_shr( L_tmp2, sub( add( shl( q_tmp2, 1 ), Qmc ), shift ) ); - L_tmp3 = L_shr( L_tmp3, sub( add( q_tmp1, Qsq ), shift ) ); - - IF( GE_32( L_tmp2, L_tmp3 ) ) - { - d1m_fx = k; - move16(); - min_corr_fx = accA_fx; - move16(); - Qmc = q_tmp1; - move16(); - min_sq_cross_fx = L_add( L_tmp1, 0 ); - Qsq = shl( q_tmp2, 1 ); - move16(); - } - } - - push_indice( hBstr, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS ); - - tmp = add( i_mult2( d1m_fx, delta_fx ), fdelay_fx ); - ptmp = &hb_synth_tmp_fx[tmp]; - move16(); - E1_fx = dotprod_satcont( synth_subfr_bwe_fx, synth_subfr_bwe_fx, 0, 0, &q_tmp1, gapsize_fx, 1 ); - E2_fx = dotprod_satcont( ptmp, ptmp, 0, 0, &q_tmp2, gapsize_fx, 1 ); - - IF( !E1_fx ) - { - E1_fx = shl( 1, 14 ); - q_tmp1 = 14; - move16(); - } - IF( !E2_fx ) - { - E2_fx = shl( 1, 14 ); - q_tmp2 = 14; - move16(); - } - - tmp = div_s( shl( 1, 14 ), E1_fx ); /*Q(29-q_tmp1) */ - L_tmp1 = L_mult( tmp, E2_fx ); /*30-q_tmp1+q_tmp2 */ - q_tmp2 = sub( q_tmp1, q_tmp2 ); /*30-q_tmp2 */ - L_tmp1 = L_shl( L_tmp1, sub( q_tmp2, 24 ) ); - gain_fx = round_fx_sat( Isqrt( L_tmp1 ) ); /*Q12 */ - ind1_fx = usquant_fx( gain_fx, &gain_fx, shr( MINVALUEOFFIRSTGAIN_FX, 1 ), shr( DELTAOFFIRSTGAIN_FX, 4 ), ( 1 << NOOFGAINBITS1 ) ); - push_indice( hBstr, IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); - - return; -} - - static Word16 dotprod_satcont( const Word16 *x, /* qx */ const Word16 *y, /* qy */ - Word16 qx, - Word16 qy, + const Word16 qx, + const Word16 qy, Word16 *qo, - Word16 len, /* Q0 */ - Word16 delta /* Q0 */ + const Word16 len, /* Q0 */ + const Word16 delta /* Q0 */ ) { Word16 tmp_tabx[L_FRAME48k], tmp_taby[L_FRAME48k]; diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 26ca2a020123a1c560ef400954049903ec854b0a..cd93c7f13973c4ee3e1c3b801b96fba2483e925d 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -6,7 +6,6 @@ #include #include #include "options.h" -//#include "prot_fx.h" #include "basop_util.h" #include "cnst.h" #include "prot_fx.h" /* Function prototypes */ @@ -176,30 +175,6 @@ void E_ACELP_conv( } } -void E_ACELP_conv_ivas_fx( - const Word16 xn2[], /* i Qnew - 1*/ - const Word16 h2[], /* i Q12*/ - Word16 cn2[] /* o Qnew*/ -) -{ - Word16 i, k; - Word32 L_tmp; - - FOR( k = 0; k < L_SUBFR; k++ ) - { - /*cn2[k] = xn2[k]; */ - Word64 L_tmp_64; - L_tmp_64 = W_deposit32_l( L_mult0( xn2[k], 0x800 ) ); /* Qnew -1 + 12 */ - FOR( i = 0; i < k; i++ ) - { - /*cn2[k]-=cn2[i]*h2[k-i];*/ - L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*Qnew + 11*/ - } - L_tmp = W_sat_l( L_tmp_64 ); /* Qnew + 11 */ - cn2[k] = round_fx_sat( L_shl_sat( L_tmp, 5 ) ); /* Qnew*/ - move16(); - } -} void E_ACELP_build_code( Word16 nb_pulse, /* i Q0*/ const Word16 codvec[], /* i Q0*/ diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 9b20100ba13a75354a9069b188cc48b38997d9c2..876cc94fdea57a9c793cf063f1817efe14352b32 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -136,7 +136,7 @@ void amr_wb_enc_fx( /* Updates in case of HQ -> AMR-WB IO mode switching */ Q_new = 0; move16(); /* prevent compiler warning only*/ - core_switching_pre_enc_fx( st, NULL, NULL, 0, 0 ); + core_switching_pre_enc_fx( st, NULL, 0, NULL, 0, 0, 0 ); set16_fx( hf_gain_fx, 0, NB_SUBFR ); set16_fx( old_inp, 0, L_INP_12k8 ); @@ -310,7 +310,7 @@ void amr_wb_enc_fx( } /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL ); + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL, NULL ); /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled @@ -332,7 +332,7 @@ void amr_wb_enc_fx( move16(); } - dtx_fx( st, vad_flag_dtx, inp, Q_new ); + dtx_fx( st, -1, -1, vad_flag_dtx, inp, Q_new ); /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation @@ -459,7 +459,7 @@ void amr_wb_enc_fx( IF( EQ_32( st->core_brate, SID_1k75 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) { /* encode CNG parameters */ - CNG_enc_fx( st, Aq, inp, ener, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); + CNG_enc_fx( st, Aq, inp, isp_new, isp_new, isf_new, &allow_cn_step, sub( Q_new, 1 ), q_env, &sid_bw ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, L_FRAME, &hTdCngEnc->Enew_fx, &hTdCngEnc->cng_seed, exc, exc2, &hTdCngEnc->lp_ener_fx, @@ -579,7 +579,7 @@ void amr_wb_enc_fx( updt_enc_fx( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec parameters */ - updt_enc_common_fx( st, Etot, Q_new ); + updt_enc_common_fx( st, Q_new ); #ifdef DEBUG_MODE_INFO dbgwrite( &st->codec_mode, sizeof( short ), 1, input_frame, "res/codec" ); diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 8739661168a5dd90e7c596fd8b261f9b572ac612..162b87ea488cc23b5a98d80b8882628fd0cace1a 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -39,7 +39,7 @@ void analy_lp_fx( const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ const Word16 element_mode, /* i : element mode */ const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /* i : stores Q for speech */ + const Word16 Q_new, /* i : stores Q for speech */ Word16 *Q_r /*stores q for ener*/ ) { @@ -115,12 +115,12 @@ void analy_lp_fx( IF( EQ_16( sec_chan_low_rate, 1 ) ) { /* LSP interpolation */ - int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); } ELSE { /* LSP interpolation */ - int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); + int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); } Copy( lsp_new, lsp_old, M ); /* Q15 */ *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */ @@ -152,7 +152,7 @@ void analy_lp_AMR_WB_fx( Word16 isf_new[], /* o : current frame ISPs Q15*/ Word16 Top, /* i : open loop pitch lag Q0*/ Word16 Tnc, /* i : open loop pitch gain Qx*/ - Word16 Q_new, + const Word16 Q_new, Word16 *Q_r ) { Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index dc34ccc5b96557e1de1aeb9cde7e7d4941f845cb..e7d09c786d06b16f010c79b5529d09ca260195f1 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -6,13 +6,12 @@ #include "options.h" #include "cnst.h" #include "basop_util.h" -// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" #include -#include + /*-------------------------------------------------------------------* * Local prototypes *-------------------------------------------------------------------*/ @@ -21,6 +20,15 @@ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, static void ivas_find_enr( Word16 *data, Word16 q_data, Word32 *band, Word16 *q_band, Word32 *ptE, Word16 *q_ptE, Word64 *LEtot, const Word16 min_band, const Word16 max_band, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define SIZE_256 256 +#define NUM_STAGE_256 7 +#define SIZE2_256 ( SIZE_256 / 2 ) + + /*-------------------------------------------------------------------* * analy_sp_fx() * @@ -405,7 +413,7 @@ static void find_enr_dft_ivas_fx( move16(); L_lerp_fx( BinE_fx, Bin_E_fx, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2, q_Bin_E ); - MVR2R_WORD32( Bin_E_fx, ptE_fx, VOIC_BINS ); // *q_Bin_E + Copy32( Bin_E_fx, ptE_fx, VOIC_BINS ); // *q_Bin_E *q_ptE = *q_Bin_E; move16(); @@ -594,10 +602,10 @@ void ivas_analy_sp_fx( hCPE->hStereoDft->DFT_fx_e[0] = sub( hCPE->hStereoDft->DFT_fx_e[0], exp ); move16(); find_enr_dft_ivas_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, q_fr_bands, lf_E, q_lf_E, &LEtot, min_band, max_band, Bin_E, q_Bin_E, band_energies, sub( Q31, hCPE->hStereoDft->DFT_fx_e[0] ) ); - MVR2R_WORD32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); - MVR2R_WORD32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); - MVR2R_WORD32( band_energies, band_energies + NB_BANDS, NB_BANDS ); - MVR2R_WORD32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); + Copy32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); + Copy32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); + Copy32( band_energies, band_energies + NB_BANDS, NB_BANDS ); + Copy32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); /* Average total log energy over both half-frames */ *Etot = -838860800 /* 10.f * log10f(0.00001f) in Q24 : This is when LEtot is 0*/; diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index d42ae6c4dfd4d2f1b5f48640de08a663fa8c9629..e54dfeda293c25c78b4754231af24600de21acb7 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -3,10 +3,12 @@ ====================================================================================*/ #include -#include #include "options.h" /* Compilation switches */ #include "cnst.h" -#include /* Compilation switches */ +#include /* Compilation switches */ +#ifdef DEBUGGING +#include +#endif #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ @@ -547,7 +549,9 @@ void AVQ_encmux_fx( bit_tmp = add( unusedbitsFlag, unused_bits_idx ); /*nq_est = (int16_t)ceil(0.2f * (bits - 5 * (unusedbitsFlag + unused_bits_idx)));*/ nq_est = mult( 6554, sub( bits, add( shl( bit_tmp, 2 ), bit_tmp ) ) ); +#ifdef DEBUGGING assert( (Word16) ceil( 0.2f * ( bits - 5 * ( unusedbitsFlag + unused_bits_idx ) ) ) == nq_est ); +#endif if ( EQ_16( nq_est, 1 ) ) { @@ -605,7 +609,7 @@ void AVQ_cod_lpc_fx( Word16 i, l, pos; Word32 I; Word32 x1[8]; - UWord16 I16; + UWord16 I16 = 0; /* quantize all subvector using estimated gain */ diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 33e00aae1d6b6422ac3c30b6b12fb977f629615e..2e04b986ff3813d6ba305070632b388d41938a4b 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -16,7 +16,9 @@ /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ + #define BWD_MIN_BRATE_WIDER_BW_MDCT IVAS_48k +#define BWD_MIN_BRATE_WIDER_BW_MASA IVAS_48k #define BWD_MIN_BRATE_WIDER_BW_ISM IVAS_32k #define BWD_MAX_BRATE_WIDER_BW_MDCT IVAS_80k #define BWD_MAX_BRATE_WIDER_BW_ISM IVAS_64k @@ -28,8 +30,6 @@ #define BWD_COUNT_WIDER_BW 10 #define BWD_COUNT_WIDER_BW_MDCT 0 -#define BWD_N_BINS_MAX 13 - #define CLDFB_ENER_OFFSET_FX 26214 /* 1.6 in Q14 */ /*-------------------------------------------------------------------* @@ -40,8 +40,8 @@ void bw_detect_fx( Encoder_State *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - Word16 *spectrum, /* i : MDCT spectrum Q_spec */ + const Word16 signal_in[], /* i : input signal */ + Word16 *spectrum, /* i : MDCT spectrum Q_spec */ const Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ const Word16 *cldfbBuf_Ener_Exp, /* i : CLDFB Energy Exponent */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ @@ -75,12 +75,16 @@ void bw_detect_fx( test(); test(); test(); + test(); + test(); if ( st->ini_frame > 0 && ( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( GE_32( st->element_brate, BWD_MIN_BRATE_WIDER_BW_MDCT ) || mct_on ) ) || - ( EQ_16( ivas_format, ISM_FORMAT ) && GE_32( st->element_brate, BWD_MIN_BRATE_WIDER_BW_ISM ) ) ) ) + ( st->is_ism_format && GE_32( st->element_brate, BWD_MIN_BRATE_WIDER_BW_ISM ) ) || + ( EQ_16( ivas_format, MASA_FORMAT ) && GE_32( st->element_brate, BWD_MIN_BRATE_WIDER_BW_MASA ) ) ) ) { bwd_count_wider_bw = BWD_COUNT_WIDER_BW_MDCT; move16(); } + IF( GT_32( st->input_Fs, 8000 ) ) { diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index e51dd4884a0c67da51b2261aa6754de2c62cd071..e622c9857e3c3ffbd9c80d2769ad8e1cd079e62b 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1,6 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ @@ -8,9 +9,9 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -//#include "basop_mpy.h" - #include + + /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -20,24 +21,26 @@ #define INT_H 50 #define INT_L 8 + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ + static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx ); static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k ); -static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx ); -static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update ); + + /*---------------------------------------------------------------------* * CNG_enc() * * Confort noise generation for the coder *---------------------------------------------------------------------*/ + void CNG_enc_fx( Encoder_State *st_fx, /* i/o: State structure */ Word16 Aq[], /* o : LP coefficients Q12 */ const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ - const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ + const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ @@ -49,46 +52,34 @@ void CNG_enc_fx( Word16 i, j, ptr; Word16 m1; Word16 res[L_FRAME16k]; - Word16 step_inv = 0; - move16(); + Word16 step_inv; Word16 hi, lo; - Word16 maxl = 0; - move16(); - Word16 num_bits = 0; - move16(); - Word16 step = 0; - move16(); - Word16 *pt_res; - const Word16 *pt_sp; + Word16 maxl; + Word16 num_bits; + Word16 step; Word16 enr; - Word32 L_tmp, L_ener; + Word32 L_tmp; Word16 k, tmp1; Word16 weights; Word16 sp_enr; Word32 L_tmp1; Word16 exp; - Word16 m = 0; - move16(); + Word16 m; Word16 tmp[HO_HIST_SIZE * M]; Word16 ll, s_ptr; - Word16 tmpv, maxv, scale, att = 1; - move16(); + Word16 tmpv, att; Word16 lsf_tmp[M]; Word32 C[M]; Word32 max_val[2]; Word16 max_idx[2]; Word16 ftmp_fx; Word16 lsp_tmp[M]; - Word16 dev; - Word16 max_dev; - Word16 dist; - Word16 max_idx1[2] = { 0, 0 }; - move16(); - move16(); + Word32 dev, max_dev, dist; + Word16 dev16, max_dev16, dist16; + Word16 max_idx1[2]; Word16 fft_io[L_FRAME16k]; Word16 *ptR, *ptI; - Word32 enr1 = 0; - move32(); + Word32 enr1; Word32 env[NUM_ENV_CNG]; Word32 min1; Word16 min1_idx; @@ -98,53 +89,136 @@ void CNG_enc_fx( Word16 fra; Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; - Word16 force_cn_step = 0; - move16(); + Word16 force_cn_step; Word16 tmp_loop; Word16 st_lp_sp_enr; DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + Word16 lp_ener_thr_scale; + Word64 w_temp; + Word32 inv_frame_len; + Word32 L_ener; + Word16 *pt_res; + const Word16 *pt_sp; + + step_inv = 0; + move16(); + maxl = 0; + move16(); + num_bits = 0; + move16(); + step = 0; + move16(); + m = 0; + move16(); + att = 1; + move16(); + max_idx1[0] = 0; + max_idx1[1] = 0; + move16(); + move16(); + enr1 = 0; + move32(); + force_cn_step = 0; + move16(); st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; move16(); - Word16 lp_ener_thr_scale; - lp_ener_thr_scale = 8; /* 4.0f*/ /*IVAS_CODE Q2 */ + lp_ener_thr_scale = 8; /* 4.0f*/ /* Q1 */ move16(); if ( st_fx->element_mode != EVS_MONO ) { - lp_ener_thr_scale = 7; /* 3.5f;*/ + lp_ener_thr_scale = 7; /* 3.5f;*/ /* Q1 */ move16(); } - /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*/ /*9.1 */ - pt_sp = speech; - L_ener = L_deposit_l( 1 ); - /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - FOR( j = 0; j < 128; j++ ) - { - L_tmp = L_mult0( *pt_sp, *pt_sp ); - pt_sp++; - L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); - pt_sp++; - L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ + + IF( st_fx->element_mode == EVS_MONO ) { - FOR( i = 0; i < 2; i++ ) + pt_sp = speech; + L_ener = L_deposit_l( 1 ); + /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - FOR( j = 0; j < 80; j++ ) + FOR( j = 0; j < 128; j++ ) { L_tmp = L_mult0( *pt_sp, *pt_sp ); pt_sp++; L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); pt_sp++; - L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ + L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ + } + } + ELSE /* L_FRAME16k */ + { + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 80; j++ ) + { + L_tmp = L_mult0( *pt_sp, *pt_sp ); + pt_sp++; + L_tmp = L_mac0( L_tmp, *pt_sp, *pt_sp ); + pt_sp++; + L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*Q_new + 1, divide by L_frame done here */ + } } } } + ELSE + { + w_temp = 1; + move64(); + + FOR( j = 0; j < st_fx->L_frame; j++ ) + { + w_temp = W_mac0_16_16( w_temp, speech[j], speech[j] ); + } + exp = W_norm( w_temp ); + + inv_frame_len = 0; + move32(); + + SWITCH( st_fx->L_frame ) + { + case L_FRAME25_6k: + inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; + move16(); + BREAK; + case L_FRAME: + inv_frame_len = ONE_BY_L_FRAME_Q31; + move16(); + BREAK; + case L_FRAME48k: + inv_frame_len = ONE_BY_L_FRAME48k_Q31; + move16(); + BREAK; + case 240: + inv_frame_len = ONE_BY_240_Q31; + move16(); + BREAK; + case L_FRAME32k: + inv_frame_len = ONE_BY_L_FRAME32k_Q31; + move16(); + BREAK; + case L_FRAME16k: + inv_frame_len = ONE_BY_L_FRAME16k_Q31; + move16(); + BREAK; + case L_FRAME8k: + inv_frame_len = ONE_BY_L_FRAME8k_Q31; + move16(); + BREAK; + case L_FRAME4k: + inv_frame_len = ONE_BY_L_FRAME4k_Q31; + move16(); + BREAK; + default: + inv_frame_len = divide3216( 1, st_fx->L_frame ); + } + L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ + L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ + L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ + } hi = norm_l( L_ener ); lo = Log2_norm_lc( L_shl( L_ener, hi ) ); @@ -174,7 +248,7 @@ void CNG_enc_fx( IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16( hTdCngEnc->lp_sp_enr_fx, 1536 /*6.0f in Q8*/ ) && GT_16( sub( sp_enr, hTdCngEnc->lp_sp_enr_fx ), 1024 /*4.0f in Q8*/ ) && GT_16( sp_enr, 1536 /*6.0f in Q8*/ ) ) { - hTdCngEnc->lp_sp_enr_fx = sp_enr; + hTdCngEnc->lp_sp_enr_fx = sp_enr; /* Q8 */ move16(); force_cn_step = 1; move16(); @@ -185,6 +259,7 @@ void CNG_enc_fx( move16(); } } + /* update the pointer to circular buffer of old LSP vectors */ hTdCngEnc->cng_hist_ptr = add( hTdCngEnc->cng_hist_ptr, 1 ); move16(); @@ -201,6 +276,7 @@ void CNG_enc_fx( * Find CNG spectral envelope * Find LSP median *-----------------------------------------------------------------*/ + test(); test(); IF( ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) && GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) @@ -213,7 +289,7 @@ void CNG_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; /*(6400/(M+1))X2.56 */ + ftmp_fx = 964; /*(6400/(M+1))X2.56*/ move16(); /*QX2.56 */ tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ @@ -235,7 +311,7 @@ void CNG_enc_fx( L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536 */ } - C[i] = Mpy_32_16_1( L_tmp, 1928 /*.0588235f Q15*/ ); + C[i] = Mpy_32_16_1( L_tmp, 1928 ); move32(); /*QX6.5536 */ IF( GT_32( C[i], max_val[0] ) ) @@ -283,6 +359,7 @@ void CNG_enc_fx( * Quantize CNG spectral envelope (only in SID frame) * Quantize the LSF vector *-----------------------------------------------------------------*/ + *allow_cn_step = 0; move16(); test(); @@ -314,13 +391,12 @@ void CNG_enc_fx( FOR( i = 0; i < M; i++ ) { /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ - lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 ), lsp_new[i], 16384 /*.5 Q15*/ ); + lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 /*.5f Q15*/ ), lsp_new[i], 16384 /*.5f Q15*/ ); move16(); } } } - test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { @@ -331,8 +407,9 @@ void CNG_enc_fx( } ELSE { - lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 100, 0, 0, Q_new ); + lsf_enc_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 0, 0, NULL, Q_new ); } + /* Reset CNG history if CNG frame length is changed */ test(); test(); @@ -354,10 +431,12 @@ void CNG_enc_fx( * Find A(z) coefficients *---------------------------------------------------------------------*/ - IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) + test(); + test(); + IF( ( st_fx->last_core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) { /* Reset hangover counter if not first SID period */ - if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) + if ( st_fx->core_brate > FRAME_NO_DATA ) { hTdCngEnc->num_ho = 0; move16(); @@ -369,7 +448,7 @@ void CNG_enc_fx( FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - hDtxEnc->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); + hDtxEnc->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i] ), 32768 /*1f Q15*/ - CNG_ISF_FACT_FX, lsp_new[i] ); move16(); /* Q15 (15+15+1-16) */ } } @@ -381,7 +460,7 @@ void CNG_enc_fx( test(); test(); test(); - IF( st_fx->element_mode == EVS_MONO && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) + IF( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) { IF( GT_32( hDtxEnc->last_active_brate, ACELP_16k40 ) ) { @@ -456,23 +535,34 @@ void CNG_enc_fx( IF( hTdCngEnc->burst_ho_cnt > 0 ) { - /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ - /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ - /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ - L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); - IF( NE_16( lp_ener_thr_scale, 8 ) ) + IF( st_fx->element_mode == EVS_MONO ) + { + /**allow_cn_step |= ( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] > 4 * hTdCngEnc->lp_ener_fx ); */ + /*allow_cn_step |= (hDtxEnc->first_CNG || st->element_mode == EVS_MONO) && (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener);*/ + /* (hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener); */ + L_tmp1 = L_shr( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], 2 ); + IF( NE_16( lp_ener_thr_scale, 8 ) ) + { + L_tmp1 = L_add( L_tmp1, L_shr( hTdCngEnc->lp_ener_fx, 8 ) ); + } + L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); + w_temp = W_deposit32_l( L_tmp1 ); + } + ELSE { - L_tmp1 = L_add( L_tmp1, L_shr( hTdCngEnc->lp_ener_fx, 8 ) ); + /**allow_cn_step |= ( hDtxEnc->first_CNG || st->element_mode == EVS_MONO ) && ( hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener );*/ + w_temp = W_msu_32_16( W_shl( W_deposit32_l( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 2 ), hTdCngEnc->lp_ener_fx, lp_ener_thr_scale ); /*Q8*/ } - L_tmp1 = L_sub( L_tmp1, hTdCngEnc->lp_ener_fx ); + test(); test(); - IF( ( hDtxEnc->first_CNG > 0 || st_fx->element_mode == EVS_MONO ) && L_tmp1 > 0 ) + IF( ( hDtxEnc->first_CNG > 0 || ( st_fx->element_mode == EVS_MONO ) ) && w_temp > 0 ) { *allow_cn_step = s_or( *allow_cn_step, 1 ); move16(); } } + test(); IF( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) { @@ -482,13 +572,13 @@ void CNG_enc_fx( Copy( &( hTdCngEnc->ho_lsp_hist_fx[ptr * M] ), tmp, M ); m1 = 0; move16(); - IF( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x1 ) == 0 ) + IF( L_and( hTdCngEnc->ho_sid_bw, 1 ) == 0 ) { Copy32( &hTdCngEnc->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } - L_enr = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ + L_ener = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ weights = W_DTX_HO_FX[0]; /* Q15 */ move16(); @@ -509,13 +599,13 @@ void CNG_enc_fx( { /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ L_tmp1 = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ - L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ + L_ener = L_add( L_ener, L_tmp1 ); /* Q6 */ /*weights += W_DTX_HO[k]; */ weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); - IF( L_and( hTdCngEnc->ho_sid_bw, L_shl( (Word32) 0x1, k ) ) == 0 ) + IF( L_and( hTdCngEnc->ho_sid_bw, L_shl( 1, k ) ) == 0 ) { Copy32( &hTdCngEnc->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); m1 = add( m1, 1 ); @@ -527,10 +617,10 @@ void CNG_enc_fx( /*enr /= weights; */ exp = norm_s( weights ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ + L_tmp1 = Mult_32_16( L_ener, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ + L_ener = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ - hTdCngEnc->lp_ener_fx = L_enr; + hTdCngEnc->lp_ener_fx = L_ener; move32(); /* Q6 */ set32_fx( max_val, 0, 2 ); @@ -604,6 +694,7 @@ void CNG_enc_fx( tmpv = div_s( 1, sub( m, 1 ) ); /*Q15 */ L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ + move16(); } } ELSE @@ -617,29 +708,53 @@ void CNG_enc_fx( } L_tmp = L_sub( L_tmp, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15 */ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15 */ - L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ - lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15 */ /*Q15 */ + L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ /*Q15 */ + lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ /*Q15 */ + move16(); } } - dist = 0; /*Q15 */ - max_dev = 0; /*Q15 */ - move16(); - move16(); - FOR( i = 0; i < M; i++ ) + IF( st_fx->element_mode == EVS_MONO ) { - dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ - dist = add_sat( dist, dev ); /*Q15 */ - if ( GT_16( dev, max_dev ) ) + dist16 = 0; /*Q15 */ + move16(); + max_dev16 = 0; /*Q15 */ + move16(); + move16(); + FOR( i = 0; i < M; i++ ) { - max_dev = dev; - move16(); + dev16 = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ + dist16 = add_sat( dist16, dev16 ); /*Q15 */ + if ( GT_16( dev16, max_dev16 ) ) + { + max_dev16 = dev16; + move16(); + } + } + dist = L_deposit_l( dist16 ); + max_dev = L_deposit_l( max_dev16 ); + } + ELSE + { + dist = 0; /*Q15 */ + move32(); + max_dev = 0; /*Q15 */ + move32(); + FOR( i = 0; i < M; i++ ) + { + dev = L_abs( L_sub( L_deposit_l( lsp_tmp[i] ), L_deposit_l( lsp_new[i] ) ) ); /*Q15 */ + dist = L_add( dist, dev ); /*Q15 */ + if ( GT_32( dev, max_dev ) ) + { + max_dev = dev; + move32(); + } } } test(); - IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) + IF( GT_32( dist, 13107 ) || GT_32( max_dev, 3277 ) ) { FOR( i = 0; i < M; i++ ) { @@ -652,7 +767,7 @@ void CNG_enc_fx( FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - hDtxEnc->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); + hDtxEnc->lspCNG_fx[i] = add( mult_r( 26214 /*.8f Q15*/, lsp_tmp[i] ), mult_r( 6554 /*.2f Q15*/, lsp_new[i] ) ); /* Q15 */ move16(); } } @@ -679,24 +794,30 @@ void CNG_enc_fx( L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); } - env[i] = L_tmp; + env[i] = L_tmp; /* Q6*/ move32(); } - Copy32( env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG ); + Copy32( env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ } } ELSE { - Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ + Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ } } + IF( st_fx->Opt_AMR_WB != 0 ) { E_LPC_f_isp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); } ELSE { - E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ + E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); + IF( st_fx->element_mode != EVS_MONO ) + { + exp = sub( Q14, norm_s( Aq[0] ) ); + Scale_sig( Aq, M + 1, sub( Q12, exp ) ); // Q12 + } } tmp_loop = shr( st_fx->L_frame, 6 ); @@ -704,6 +825,7 @@ void CNG_enc_fx( { Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); } + /*-----------------------------------------------------------------* * Find residual signal * Calculate residual signal energy per sample @@ -711,12 +833,16 @@ void CNG_enc_fx( /* calculate the residual signal */ Residu3_fx( Aq, speech, res, st_fx->L_frame, 0 ); - Copy( res, res1, st_fx->L_frame ); + Copy( res, res1, st_fx->L_frame ); /* Q_new */ test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { + L_tmp1 = L_mult0( hTdCngEnc->CNG_att_fx, 26214 /* 1/20.0f in Q19 */ ); // Q26 (7 + 19) + L_tmp1 = BASOP_Util_fPow( 1342177280 /*10 in Q27 */, 4, L_tmp1, 5, &exp ); + att = extract_h( L_shl( L_sub( L_tmp1, EPSILON_FX ), exp ) ); // Q15 // Subtracting by EPSILON_FX to avoid assertion when L_tmp1 value is 1073741824 and exp =1 + v_multc_fx_16_16( res1, att, res1, st_fx->L_frame ); /* Q_new */ } - ELSE IF( NE_16( st_fx->bwidth, NB ) ) + ELSE IF( st_fx->bwidth != NB ) { test(); IF( EQ_16( st_fx->bwidth, WB ) && hDtxEnc->CNG_mode >= 0 ) @@ -726,13 +852,13 @@ void CNG_enc_fx( } ELSE { - ftmp_fx = 19661; /*0.6f in Q15*/ + ftmp_fx = 19661; /*.6f in Q15*/ move16(); } - att = mult( ftmp_fx, 5461 /*1/6f in Q15*/ ); /* Q15 */ - L_tmp = L_mult( att, 8 ); /* Q16 */ - tmp1 = extract_l( L_shr( L_tmp, 2 ) ); /* Q14 */ + att = mult( ftmp_fx, 5461 ); /* Q15 */ + L_tmp = L_mult( att, 8 ); /* Q16 */ + tmp1 = extract_l( L_shr( L_tmp, 2 ) ); /* Q14 */ tmp1 = add( 16384, tmp1 ); att = div_s( 16374, tmp1 ); /* Q15 */ @@ -747,7 +873,7 @@ void CNG_enc_fx( } /* calculate the spectrum of residual signal */ - Copy( res1, fft_io, st_fx->L_frame ); + Copy( res1, fft_io, st_fx->L_frame ); /* Q_new */ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { @@ -775,49 +901,124 @@ void CNG_enc_fx( /* calculate the residual signal energy */ /*enr = dotp( res, res, L_frame ) / L_frame; */ - maxv = 0; - move16(); - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - maxv = s_max( maxv, abs_s( res[i] ) ); - } - scale = norm_s( maxv ); - pt_res = res; - L_ener = L_deposit_l( 1 ); - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( st_fx->element_mode == EVS_MONO ) { - FOR( j = 0; j < 128; j++ ) + Word16 maxv, scale; + + maxv = 0; + move16(); + FOR( i = 0; i < st_fx->L_frame; i++ ) + { + maxv = s_max( maxv, abs_s( res[i] ) ); + } + scale = norm_s( maxv ); + pt_res = res; + L_ener = L_deposit_l( 1 ); + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + FOR( j = 0; j < 128; j++ ) + { + tmpv = shl( *pt_res, scale ); + L_tmp = L_mult0( tmpv, tmpv ); + pt_res++; + tmpv = shl( *pt_res, scale ); + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + } + } + ELSE /* L_FRAME16k */ { - tmpv = shl( *pt_res, scale ); - L_tmp = L_mult0( tmpv, tmpv ); - pt_res++; - tmpv = shl( *pt_res, scale ); - L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add_sat( L_ener, L_shr( L_tmp, 7 ) ); /* 2*(Q_new+scale)+1, divide by L_frame done here */ + FOR( j = 0; j < 160; j++ ) + { + tmpv = shl( *pt_res, scale ); + L_tmp = L_mult0( tmpv, tmpv ); + pt_res++; + tmpv = shl( *pt_res, scale ); + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ + pt_res++; + L_ener = L_add_sat( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + } } + + /* convert log2 of residual signal energy */ + /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 29, hi ); /* log2 exp in Q2*(Q_new+scale) */ + hi = sub( hi, shl( add( Q_new, scale ), 1 ) ); /* Q0 */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } - ELSE /* L_FRAME16k */ + ELSE { - FOR( j = 0; j < 160; j++ ) + w_temp = 1; + move64(); + FOR( j = 0; j < st_fx->L_frame; j++ ) + { + w_temp = W_mac0_16_16( w_temp, res[j], res[j] ); + } + exp = W_norm( w_temp ); + + SWITCH( st_fx->L_frame ) + { + case L_FRAME25_6k: + inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; + move16(); + BREAK; + case L_FRAME: + inv_frame_len = ONE_BY_L_FRAME_Q31; + move16(); + BREAK; + case L_FRAME48k: + inv_frame_len = ONE_BY_L_FRAME48k_Q31; + move16(); + BREAK; + case 240: + inv_frame_len = ONE_BY_240_Q31; + move16(); + BREAK; + case L_FRAME32k: + inv_frame_len = ONE_BY_L_FRAME32k_Q31; + move16(); + BREAK; + case L_FRAME16k: + inv_frame_len = ONE_BY_L_FRAME16k_Q31; + move16(); + BREAK; + case L_FRAME8k: + inv_frame_len = ONE_BY_L_FRAME8k_Q31; + move16(); + BREAK; + case L_FRAME4k: + inv_frame_len = ONE_BY_L_FRAME4k_Q31; + move16(); + BREAK; + default: + inv_frame_len = divide3216( 1, st_fx->L_frame ); + } + L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ + L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ + L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ + + /* convert log2 of residual signal energy */ + /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ + + IF( L_ener == 0 ) + { + enr = -850; /*log(0.1) base 2 in Q8*/ + move16(); + } + ELSE { - tmpv = shl( *pt_res, scale ); - L_tmp = L_mult0( tmpv, tmpv ); - pt_res++; - tmpv = shl( *pt_res, scale ); - L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add_sat( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ + hi = norm_l( L_ener ); + lo = Log2_norm_lc( L_shl( L_ener, hi ) ); + hi = sub( 29, hi ); /* log2 exp in Q2*Q_new */ + hi = sub( hi, shl( Q_new, 1 ) ); /* Q0 */ + L_tmp = L_Comp( hi, lo ); /* Q16 */ + enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ } } - /* convert log2 of residual signal energy */ - /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ - hi = norm_l( L_ener ); - lo = Log2_norm_lc( L_shl( L_ener, hi ) ); - hi = sub( 29, hi ); /* log2 exp in Q2*(Q_new+scale) */ - hi = sub( hi, shl( add( Q_new, scale ), 1 ) ); /* Q0 */ - L_tmp = L_Comp( hi, lo ); /* Q16 */ - enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ /* update the circular buffer of old energies */ hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; @@ -826,6 +1027,7 @@ void CNG_enc_fx( /*-----------------------------------------------------------------* * Quantize residual signal energy (only in SID frame) *-----------------------------------------------------------------*/ + test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { @@ -891,8 +1093,9 @@ void CNG_enc_fx( test(); IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { + enr = add( enr, mult( hTdCngEnc->CNG_att_fx, FAC_LOG2_BY10_Q16 ) ); /* Q8 (Q7 + Q16 - Q15)*/ } - ELSE IF( NE_16( st_fx->bwidth, NB ) ) + ELSE IF( st_fx->bwidth != NB ) { IF( EQ_16( st_fx->bwidth, WB ) ) { @@ -912,14 +1115,14 @@ void CNG_enc_fx( ELSE { att = 384; - move16(); /*Q8*/ + move16(); /*1.5f Q8*/ } enr = sub( enr, att ); } /* intialize the energy quantization parameters */ IF( st_fx->Opt_AMR_WB == 0 ) { - step = STEP_SID_FX; + step = STEP_SID_FX; // Q12 move16(); step_inv = ISTEP_SID_FX; move16(); @@ -1027,7 +1230,8 @@ void CNG_enc_fx( } /* codebook search */ - min1 = L_add( 1310588928, 0 ); /* Q17 */ + min1 = 1310588928; /* 9999.0f Q17 */ + move32(); min1_idx = 0; move16(); @@ -1043,12 +1247,13 @@ void CNG_enc_fx( tmp1 = extract_h( L_tmp ); /*Q(exp+6-16)=exp-10*/ L_tmp = L_mult_sat( tmp1, tmp1 ); /*Q(2*exp - 19)*/ L_tmp = L_shr( L_tmp, sub( add( exp, exp ), 36 ) ); /* Q17 */ - d = L_add( d, L_tmp ); + d = L_add( d, L_tmp ); /* Q17 */ } IF( LT_32( d, min1 ) ) { - min1 = L_add( d, 0 ); + min1 = d; + move32(); min1_idx = i; move16(); } @@ -1125,7 +1330,7 @@ void CNG_enc_fx( push_indice( hBstr, IND_ACELP_16KHZ, 0, 1 ); } - push_indice( hBstr, IND_CNG_HO, s_min( hTdCngEnc->burst_ho_cnt, 7 ), 3 ); + push_indice( hBstr, IND_CNG_HO, s_min( hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE - 1 ), 3 ); hTdCngEnc->num_ho = m; move16(); push_indice( hBstr, IND_SID_TYPE, 0, 1 ); @@ -1142,6 +1347,7 @@ void CNG_enc_fx( /*-----------------------------------------------------------------* * Updates *-----------------------------------------------------------------*/ + /* update the SID frames counter */ test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) @@ -1163,1555 +1369,18 @@ void CNG_enc_fx( return; } -void CNG_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - // Word32 L_ener, /* i : residual energy from Levinson-Durbin Q6 */ - const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ - Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ - Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 Q_new, /* i : Q value of speech */ - Word32 *q_env, - Word16 *sid_bw ) -{ - Word16 enr_index; - Word16 i, j, ptr; - Word16 m1; - Word16 res[L_FRAME16k]; - Word16 step_inv; - Word16 hi, lo; - Word16 maxl; - Word16 num_bits; - Word16 step; - Word16 enr; - Word32 L_tmp; - Word16 k, tmp1; - Word16 weights; - Word16 sp_enr; - Word32 L_tmp1; - Word16 exp; - Word16 m; - Word16 tmp[HO_HIST_SIZE * M]; - Word16 ll, s_ptr; - Word16 tmpv, att; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max_val[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 lsp_tmp[M]; - Word32 dev; - Word32 max_dev; - Word32 dist; - Word16 max_idx1[2]; - Word16 fft_io[L_FRAME16k]; - Word16 *ptR, *ptI; - Word32 enr1; - Word32 env[NUM_ENV_CNG]; - Word32 min1; - Word16 min1_idx; - Word32 d; - Word16 res1[L_FRAME16k]; - Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word16 force_cn_step; - Word16 tmp_loop; - Word16 st_lp_sp_enr; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - Word16 lp_ener_thr_scale; - Word64 w_temp; - Word32 inv_frame_len; - Word32 L_ener; - - step_inv = 0; - move16(); - maxl = 0; - move16(); - num_bits = 0; - move16(); - step = 0; - move16(); - m = 0; - move16(); - att = 1; - move16(); - max_idx1[0] = 0; - max_idx1[1] = 0; - move16(); - move16(); - enr1 = 0; - move32(); - force_cn_step = 0; - move16(); - st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; - move16(); - /* Temp variables for floating point functions */ - - lp_ener_thr_scale = 8; /* 4.0f*/ /* Q1 */ - move16(); - if ( st_fx->element_mode != EVS_MONO ) - { - lp_ener_thr_scale = 7; /* 3.5f;*/ /* Q1 */ - move16(); - } - - w_temp = 1; - move64(); - - FOR( j = 0; j < st_fx->L_frame; j++ ) - { - w_temp = W_mac0_16_16( w_temp, speech[j], speech[j] ); - } - exp = W_norm( w_temp ); - - inv_frame_len = 0; - move32(); - - SWITCH( st_fx->L_frame ) - { - case L_FRAME25_6k: - inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; - move16(); - BREAK; - case L_FRAME: - inv_frame_len = ONE_BY_L_FRAME_Q31; - move16(); - BREAK; - case L_FRAME48k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; - move16(); - BREAK; - case 240: - inv_frame_len = ONE_BY_240_Q31; - move16(); - BREAK; - case L_FRAME32k: - inv_frame_len = ONE_BY_L_FRAME32k_Q31; - move16(); - BREAK; - case L_FRAME16k: - inv_frame_len = ONE_BY_L_FRAME16k_Q31; - move16(); - BREAK; - case L_FRAME8k: - inv_frame_len = ONE_BY_L_FRAME8k_Q31; - move16(); - BREAK; - case L_FRAME4k: - inv_frame_len = ONE_BY_L_FRAME4k_Q31; - move16(); - BREAK; - default: - inv_frame_len = divide3216( 1, st_fx->L_frame ); - } - L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ - L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ - L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ - - hi = norm_l( L_ener ); - lo = Log2_norm_lc( L_shl( L_ener, hi ) ); - hi = sub( 29, hi ); /* log2 exp in Q2*Q_new */ - hi = sub( hi, shl( Q_new, 1 ) ); /* Q0 */ - L_tmp = L_Comp( hi, lo ); /* Q16 */ - sp_enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ - - if ( sp_enr < 0 ) - { - sp_enr = 0; - move16(); - } - test(); - IF( hDtxEnc->first_CNG == 0 || hTdCngEnc->old_enr_index < 0 ) - { - hTdCngEnc->lp_sp_enr_fx = sp_enr; - move16(); /* Q8 */ - } - ELSE - { - test(); - test(); - test(); - test(); - test(); - IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->hTdCngEnc->burst_ho_cnt > 0 ) && LT_16( hTdCngEnc->lp_sp_enr_fx, 1536 /*6.0f in Q8*/ ) && - GT_16( sub( sp_enr, hTdCngEnc->lp_sp_enr_fx ), 1024 /*4.0f in Q8*/ ) && GT_16( sp_enr, 1536 /*6.0f in Q8*/ ) ) - { - hTdCngEnc->lp_sp_enr_fx = sp_enr; /* Q8 */ - move16(); - force_cn_step = 1; - move16(); - } - ELSE - { - hTdCngEnc->lp_sp_enr_fx = round_fx( L_mac( L_mult( 29491 /* 0.9, Q15 */, hTdCngEnc->lp_sp_enr_fx ), 3277 /* 0.1, Q15 */, sp_enr ) ); /* Q8 (8+15+1-16) */ - move16(); - } - } - /* update the pointer to circular buffer of old LSP vectors */ - hTdCngEnc->cng_hist_ptr = add( hTdCngEnc->cng_hist_ptr, 1 ); - move16(); - if ( EQ_16( hTdCngEnc->cng_hist_ptr, DTX_HIST_SIZE ) ) - { - hTdCngEnc->cng_hist_ptr = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &( hTdCngEnc->cng_lsp_hist_fx[( hTdCngEnc->cng_hist_ptr ) * M] ), M ); - - /*-----------------------------------------------------------------* - * Find CNG spectral envelope - * Find LSP median - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) && GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) - { - set32_fx( max_val, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i = 0; i < hDtxEnc->cng_hist_size; i++ ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; /*(6400/(M+1))X2.56*/ - move16(); /*QX2.56 */ - tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &hTdCngEnc->cng_lsp_hist_fx[i * M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; /*(8000/(M+1))X2.56*/ - move16(); /*QX2.56 */ - tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ - } - - tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56 */ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536 */ - FOR( j = 0; j < M - 1; j++ ) - { - tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56 */ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536 */ - } - - C[i] = Mpy_32_16_1( L_tmp, 1928 ); - move32(); /*QX6.5536 */ - - IF( GT_32( C[i], max_val[0] ) ) - { - max_val[1] = max_val[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max_val[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF( GT_32( C[i], max_val[1] ) ) - { - max_val[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - FOR( i = 0; i < M; i++ ) - { - L_tmp = 0; - move32(); - FOR( j = 0; j < hDtxEnc->cng_hist_size; j++ ) - { - L_tmp = L_add( L_tmp, L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[j * M + i] ) ); /*Q15 */ - } - - L_tmp = L_sub( L_tmp, L_add( L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[max_idx[0] * M + i] ), L_deposit_l( hTdCngEnc->cng_lsp_hist_fx[max_idx[1] * M + i] ) ) ); /*Q15 */ - tmpv = div_s( 1, sub( hDtxEnc->cng_hist_size, 2 ) ); /*Q15 */ - L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ - lsp_new[i] = extract_l( L_tmp ); /*Q15 */ - move16(); - } - max_idx1[0] = max_idx[0]; - move16(); - max_idx1[1] = max_idx[1]; - move16(); - } - - /*-----------------------------------------------------------------* - * Quantize CNG spectral envelope (only in SID frame) - * Quantize the LSF vector - *-----------------------------------------------------------------*/ - *allow_cn_step = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( hDtxEnc->cng_cnt == 0 ) && - GT_16( hTdCngEnc->lp_sp_enr_fx, 1536 /* 6.0, Q8 */ ) && - ( LT_16( add( st_lp_sp_enr, 1024 /* 4.0, Q8 */ ), sp_enr ) ) && - ( hDtxEnc->first_CNG != 0 ) && - ( hTdCngEnc->old_enr_index >= 0 ) && - ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) ) || - EQ_16( force_cn_step, 1 ) ) - { - *allow_cn_step = 1; - move16(); - } - - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( hDtxEnc->first_CNG == 0 ) - { - Copy( st_fx->lsp_old_fx, hDtxEnc->lspCNG_fx, M ); - - /* Average the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->element_mode != EVS_MONO ) - { - FOR( i = 0; i < M; i++ ) - { - /*lsp_new[i] = 0.5f * (lsp_mid[i] + lsp_new[i]);*/ - lsp_new[i] = mac_r( L_mult( lsp_mid[i], 16384 /*.5f Q15*/ ), lsp_new[i], 16384 /*.5f Q15*/ ); - move16(); - } - } - } - - - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) - { - /* LSF quantization */ - IF( st_fx->Opt_AMR_WB != 0 ) - { - isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0 ); - } - ELSE - { - lsf_enc_ivas_fx( st_fx, lsf_new, lsp_new, NULL, NULL, 0, 0, NULL, Q_new ); - } - /* Reset CNG history if CNG frame length is changed */ - test(); - test(); - if ( EQ_16( st_fx->bwidth, WB ) && hDtxEnc->first_CNG != 0 && NE_16( st_fx->L_frame, hDtxEnc->last_CNG_L_frame ) ) - { - hTdCngEnc->ho_hist_size = 0; - move16(); - } - } - ELSE - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); - } - - /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ - test(); - test(); - IF( ( st_fx->last_core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) - { - /* Reset hangover counter if not first SID period */ - if ( st_fx->core_brate > FRAME_NO_DATA ) - { - hTdCngEnc->num_ho = 0; - move16(); - } - /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ - test(); - IF( LT_16( hTdCngEnc->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngEnc->Enew_fx, 21845 /*1/1.5f, Q15*/ ), hTdCngEnc->lp_ener_fx ) ) - { - FOR( i = 0; i < M; i++ ) - { - /* AR low-pass filter */ - hDtxEnc->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, hDtxEnc->lspCNG_fx[i] ), 32768 /*1f Q15*/ - CNG_ISF_FACT_FX, lsp_new[i] ); - move16(); /* Q15 (15+15+1-16) */ - } - } - } - ELSE - { - /* Update CNG_mode if allowed */ - test(); - test(); - test(); - test(); - IF( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !hDtxEnc->first_CNG || GE_16( hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) ) ) - { - IF( GT_32( hDtxEnc->last_active_brate, ACELP_16k40 ) ) - { - hDtxEnc->CNG_mode = -1; - move16(); - } - ELSE - { - hDtxEnc->CNG_mode = get_cng_mode( hDtxEnc->last_active_brate ); - move16(); - } - } - - /* If first sid after active burst update LSF history from circ buffer */ - hTdCngEnc->burst_ho_cnt = s_min( hTdCngEnc->burst_ho_cnt, hTdCngEnc->ho_circ_size ); - move16(); - hTdCngEnc->act_cnt = 0; - move16(); - s_ptr = add( sub( hTdCngEnc->ho_circ_ptr, hTdCngEnc->burst_ho_cnt ), 1 ); - - if ( s_ptr < 0 ) - { - s_ptr = add( s_ptr, hTdCngEnc->ho_circ_size ); - } - - FOR( ll = hTdCngEnc->burst_ho_cnt; ll > 0; ll-- ) - { - hTdCngEnc->ho_hist_ptr = add( hTdCngEnc->ho_hist_ptr, 1 ); - move16(); - if ( EQ_16( hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE ) ) - { - hTdCngEnc->ho_hist_ptr = 0; - move16(); - } - - /* Conversion between 12.8k and 16k LSPs */ - test(); - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngEnc->ho_16k_lsp[s_ptr], 1 ) ) - { - /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); - } - ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngEnc->ho_16k_lsp[s_ptr] == 0 ) - { - /* 16k LSPs already converted and stored, just copy to the other buffer */ - Copy( &( hTdCngEnc->ho_lsp_circ2_fx[s_ptr * M] ), &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), M ); - } - /* update the circular buffers */ - Copy( &( hTdCngEnc->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngEnc->ho_lsp_hist_fx[hTdCngEnc->ho_hist_ptr * M] ), M ); - Copy32( &( hTdCngEnc->ho_ener_circ_fx[s_ptr] ), &( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 1 ); - hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - move32(); - Copy32( &( hTdCngEnc->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngEnc->ho_env_hist_fx[hTdCngEnc->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); - - hTdCngEnc->ho_hist_size = add( hTdCngEnc->ho_hist_size, 1 ); - move16(); - if ( GT_16( hTdCngEnc->ho_hist_size, HO_HIST_SIZE ) ) - { - hTdCngEnc->ho_hist_size = HO_HIST_SIZE; - move16(); - } - - s_ptr = add( s_ptr, 1 ); - - if ( EQ_16( s_ptr, hTdCngEnc->ho_circ_size ) ) - { - s_ptr = 0; - move16(); - } - } - - IF( hTdCngEnc->burst_ho_cnt > 0 ) - { - /**allow_cn_step |= ( hDtxEnc->first_CNG || st->element_mode == EVS_MONO ) && ( hTdCngEnc->ho_ener_hist[hTdCngEnc->ho_hist_ptr] > lp_ener_thr_scale * hTdCngEnc->lp_ener );*/ - w_temp = W_msu_32_16( W_shl( W_deposit32_l( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ), 2 ), hTdCngEnc->lp_ener_fx, lp_ener_thr_scale ); /*Q8*/ - - test(); - test(); - IF( ( hDtxEnc->first_CNG > 0 || ( st_fx->element_mode == EVS_MONO ) ) && w_temp > 0 ) - { - *allow_cn_step = s_or( *allow_cn_step, 1 ); - move16(); - } - } - test(); - IF( *allow_cn_step == 0 && hTdCngEnc->ho_hist_size > 0 ) - { - /* Use average of energies below last energy */ - ptr = hTdCngEnc->ho_hist_ptr; - move16(); - Copy( &( hTdCngEnc->ho_lsp_hist_fx[ptr * M] ), tmp, M ); - m1 = 0; - move16(); - IF( L_and( hTdCngEnc->ho_sid_bw, 1 ) == 0 ) - { - Copy32( &hTdCngEnc->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); - m1 = 1; - move16(); - } - L_ener = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ - - weights = W_DTX_HO_FX[0]; /* Q15 */ - move16(); - m = 1; - move16(); - FOR( k = 1; k < hTdCngEnc->ho_hist_size; k++ ) - { - ptr = sub( ptr, 1 ); - if ( ptr < 0 ) - { - ptr = HO_HIST_SIZE - 1; - move16(); - } - - test(); - IF( LT_32( Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] ) && - GT_32( hTdCngEnc->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr], BUF_L_NRG_FX ) ) ) - { - /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ - L_tmp1 = Mult_32_16( hTdCngEnc->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ - L_ener = L_add( L_ener, L_tmp1 ); /* Q6 */ - - /*weights += W_DTX_HO[k]; */ - weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - - Copy( &hTdCngEnc->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); - IF( L_and( hTdCngEnc->ho_sid_bw, L_shl( 1, k ) ) == 0 ) - { - Copy32( &hTdCngEnc->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); - m1 = add( m1, 1 ); - } - m = add( m, 1 ); - } - } - - /*enr /= weights; */ - exp = norm_s( weights ); - tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16( L_ener, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ - L_ener = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ - - hTdCngEnc->lp_ener_fx = L_ener; - move32(); /* Q6 */ - - set32_fx( max_val, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i = 0; i < m; i++ ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; /*(6400/(M+1))X2.56*/ - move16(); /*QX2.56 */ - tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; /*(8000/(M+1))X2.56*/ - move16(); /*QX2.56 */ - tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56 */ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536 */ - } - - tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56 */ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536 */ - FOR( j = 0; j < M - 1; j++ ) - { - tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56 */ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536 */ - } - - C[i] = Mpy_32_16_1( L_tmp, 1928 ); - move32(); /*QX6.5536 */ - - IF( GT_32( C[i], max_val[0] ) ) - { - max_val[1] = max_val[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max_val[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF( GT_32( C[i], max_val[1] ) ) - { - max_val[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - IF( EQ_16( m, 1 ) ) - { - Copy( tmp, lsp_tmp, M ); - } - ELSE IF( LT_16( m, 4 ) ) - { - FOR( i = 0; i < M; i++ ) - { - L_tmp = L_deposit_l( 0 ); - FOR( j = 0; j < m; j++ ) - { - L_tmp = L_add( L_tmp, L_deposit_l( tmp[j * M + i] ) ); - } - - L_tmp = L_sub( L_tmp, L_deposit_l( tmp[max_idx[0] * M + i] ) ); - tmpv = div_s( 1, sub( m, 1 ) ); /*Q15 */ - L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ - lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ - move16(); - } - } - ELSE - { - FOR( i = 0; i < M; i++ ) - { - L_tmp = L_deposit_l( 0 ); - FOR( j = 0; j < m; j++ ) - { - L_tmp = L_add( L_tmp, L_deposit_l( tmp[j * M + i] ) ); - } - - L_tmp = L_sub( L_tmp, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15 */ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15 */ /*Q15 */ - L_tmp = Mpy_32_16_1( L_tmp, tmpv ); /*Q15 */ /*Q15 */ - lsp_tmp[i] = extract_l( L_tmp ); /*Q15 */ /*Q15 */ - move16(); - } - } - - dist = 0; /*Q15 */ - move32(); - max_dev = 0; /*Q15 */ - move32(); - FOR( i = 0; i < M; i++ ) - { - dev = L_abs( L_sub( L_deposit_l( lsp_tmp[i] ), L_deposit_l( lsp_new[i] ) ) ); /*Q15 */ - dist = L_add( dist, dev ); /*Q15 */ - if ( GT_32( dev, max_dev ) ) - { - max_dev = dev; - move32(); - } - } - - test(); - IF( GT_32( dist, 13107 ) || GT_32( max_dev, 3277 ) ) - { - FOR( i = 0; i < M; i++ ) - { - hDtxEnc->lspCNG_fx[i] = lsp_tmp[i]; - move16(); /*Q15 */ - } - } - ELSE - { - FOR( i = 0; i < M; i++ ) - { - /* AR low-pass filter */ - hDtxEnc->lspCNG_fx[i] = add( mult_r( 26214 /*.8f Q15*/, lsp_tmp[i] ), mult_r( 6554 /*.2f Q15*/, lsp_new[i] ) ); /* Q15 */ - move16(); - } - } - IF( m1 > 0 ) - { - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - L_tmp = L_deposit_l( 0 ); - FOR( j = 0; j < m1; j++ ) - { - /* env[i] += tmp_env[j*NUM_ENV_CNG+i]; */ - L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); - } - /* env[i] /= (float)m1; */ - /* env[i] = env[i] - 2*hTdCngEnc->lp_ener_fx; */ - IF( EQ_16( m1, 1 ) ) - { - L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); - } - ELSE - { - tmp1 = div_s( 1, m1 ); - L_tmp = Mult_32_16( L_tmp, tmp1 ); - L_tmp = L_sub_sat( L_tmp, L_add_sat( hTdCngEnc->lp_ener_fx, hTdCngEnc->lp_ener_fx ) ); - } - - env[i] = L_tmp; /* Q6*/ - move32(); - } - Copy32( env, hTdCngEnc->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ - } - } - ELSE - { - Copy( lsp_new, hDtxEnc->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ - } - } - IF( st_fx->Opt_AMR_WB != 0 ) - { - E_LPC_f_isp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); - } - ELSE - { - E_LPC_f_lsp_a_conversion( hDtxEnc->lspCNG_fx, Aq, M ); - exp = sub( Q14, norm_s( Aq[0] ) ); - Scale_sig( Aq, M + 1, sub( Q12, exp ) ); // Q12 - } - - tmp_loop = shr( st_fx->L_frame, 6 ); - FOR( i = 1; i < tmp_loop; i++ ) - { - Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); - } - /*-----------------------------------------------------------------* - * Find residual signal - * Calculate residual signal energy per sample - *-----------------------------------------------------------------*/ - - /* calculate the residual signal */ - Residu3_fx( Aq, speech, res, st_fx->L_frame, 0 ); - Copy( res, res1, st_fx->L_frame ); /* Q_new */ - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - L_tmp1 = L_mult0( hTdCngEnc->CNG_att_fx, 26214 /* 1/20.0f in Q19 */ ); // Q26 (7 + 19) - L_tmp1 = BASOP_Util_fPow( 1342177280 /*10 in Q27 */, 4, L_tmp1, 5, &exp ); - att = extract_h( L_shl( L_sub( L_tmp1, EPSILON_FX ), exp ) ); // Q15 // Subtracting by EPSILON_FX to avoid assertion when L_tmp1 value is 1073741824 and exp =1 - v_multc_fx_16_16( res1, att, res1, st_fx->L_frame ); /* Q_new */ - } - ELSE IF( st_fx->bwidth != NB ) - { - test(); - IF( EQ_16( st_fx->bwidth, WB ) && hDtxEnc->CNG_mode >= 0 ) - { - ftmp_fx = HO_ATT_FX[hDtxEnc->CNG_mode]; - move16(); - } - ELSE - { - ftmp_fx = 19661; /*.6f in Q15*/ - move16(); - } - - att = mult( ftmp_fx, 5461 ); /* Q15 */ - L_tmp = L_mult( att, 8 ); /* Q16 */ - tmp1 = extract_l( L_shr( L_tmp, 2 ) ); /* Q14 */ - tmp1 = add( 16384, tmp1 ); - att = div_s( 16374, tmp1 ); /* Q15 */ - - att = s_max( att, ftmp_fx ); - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - /*res1[i] *= att;*/ - res1[i] = mult( res1[i], att ); - move16(); /* Q_new */ - } - att = shr( att, 7 ); /* Q8 */ - } - - /* calculate the spectrum of residual signal */ - Copy( res1, fft_io, st_fx->L_frame ); /* Q_new */ - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0 ); - } - - fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT - 1]; - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ - L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_new+1 */ - L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_new+1 */ - L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_new+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_new+1 */ - tmp1 = add( add( Q_new, Q_new ), 1 ); - env[i] = L_shr( L_tmp, sub( tmp1, 6 ) ); - move32(); /* Q6 */ - ptR++; - ptI--; - } - - Copy32( env, &( hTdCngEnc->cng_res_env_fx[( hTdCngEnc->cng_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); - - /* calculate the residual signal energy */ - /*enr = dotp( res, res, L_frame ) / L_frame; */ - w_temp = 1; - move64(); - FOR( j = 0; j < st_fx->L_frame; j++ ) - { - w_temp = W_mac0_16_16( w_temp, res[j], res[j] ); - } - exp = W_norm( w_temp ); - - SWITCH( st_fx->L_frame ) - { - case L_FRAME25_6k: - inv_frame_len = ONE_BY_L_FRAME25_6k_Q31; - move16(); - BREAK; - case L_FRAME: - inv_frame_len = ONE_BY_L_FRAME_Q31; - move16(); - BREAK; - case L_FRAME48k: - inv_frame_len = ONE_BY_L_FRAME48k_Q31; - move16(); - BREAK; - case 240: - inv_frame_len = ONE_BY_240_Q31; - move16(); - BREAK; - case L_FRAME32k: - inv_frame_len = ONE_BY_L_FRAME32k_Q31; - move16(); - BREAK; - case L_FRAME16k: - inv_frame_len = ONE_BY_L_FRAME16k_Q31; - move16(); - BREAK; - case L_FRAME8k: - inv_frame_len = ONE_BY_L_FRAME8k_Q31; - move16(); - BREAK; - case L_FRAME4k: - inv_frame_len = ONE_BY_L_FRAME4k_Q31; - move16(); - BREAK; - default: - inv_frame_len = divide3216( 1, st_fx->L_frame ); - } - L_ener = W_extract_h( W_shl( w_temp, exp ) ); /* Q = 2*Q_new+exp-32 */ - L_ener = Mpy_32_32( L_ener, inv_frame_len ); /* Q = 2*Q_new+exp-32 */ - L_ener = L_shl( L_ener, sub( 33, exp ) ); /* Q = 2*Q_new+1 */ - - /* convert log2 of residual signal energy */ - /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ - - IF( L_ener == 0 ) - { - enr = -850; /*log(0.1) base 2 in Q8*/ - move16(); - } - ELSE - { - hi = norm_l( L_ener ); - lo = Log2_norm_lc( L_shl( L_ener, hi ) ); - hi = sub( 29, hi ); /* log2 exp in Q2*Q_new */ - hi = sub( hi, shl( Q_new, 1 ) ); /* Q0 */ - L_tmp = L_Comp( hi, lo ); /* Q16 */ - enr = round_fx( L_shl( L_tmp, 8 ) ); /* Q8 (16+8-16) */ - } - /* update the circular buffer of old energies */ - hTdCngEnc->cng_ener_hist_fx[hTdCngEnc->cng_hist_ptr] = enr; - move16(); /* Q8 */ - - /*-----------------------------------------------------------------* - * Quantize residual signal energy (only in SID frame) - *-----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) - { - IF( GE_16( hDtxEnc->cng_cnt, sub( hDtxEnc->cng_hist_size, 1 ) ) ) - { - /* average the envelope except outliers */ - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - L_tmp1 = L_add( env[i], 0 ); - FOR( j = 0; j < hDtxEnc->cng_hist_size; j++ ) - { - L_tmp1 = L_add_sat( L_tmp1, hTdCngEnc->cng_res_env_fx[j * NUM_ENV_CNG + i] ); - } - L_tmp = L_add( hTdCngEnc->cng_res_env_fx[max_idx1[0] * NUM_ENV_CNG + i], hTdCngEnc->cng_res_env_fx[max_idx1[1] * NUM_ENV_CNG + i] ); - L_tmp1 = L_sub( L_tmp1, L_tmp ); - - /* env[i] /= (float)(st_fx->cng_hist_size - 2); */ - tmp1 = sub( hDtxEnc->cng_hist_size, 2 ); - IF( GT_16( tmp1, 1 ) ) - { - tmp1 = div_s( 1, tmp1 ); - L_tmp1 = Mult_32_16( L_tmp1, tmp1 ); - } - - env[i] = L_tmp1; - move32(); - } - /* compute average excitation energy */ - L_tmp = L_deposit_l( 0 ); - ptr = hTdCngEnc->cng_hist_ptr; - move16(); - - FOR( k = 0; k < hDtxEnc->cng_hist_size; k++ ) - { - /* enr += W_HIST[k]*cng_ener_hist[ptr] */ - L_tmp = L_mac0( L_tmp, W_HIST_FX[k], hTdCngEnc->cng_ener_hist_fx[ptr] ); /* Q24 (8+16) */ - ptr = sub( ptr, 1 ); - if ( ptr < 0 ) /* check for circular pointer */ - { - ptr = DTX_HIST_SIZE - 1; - move16(); - } - } - /*----------------------------------------------------------- - * here we want to divide L_tmp by the sum - * of all the coefs used W_HIST[0..cng_hist_size-1] - * The table W_HIST_S already contains the inverted sum. - * That is - * W_HIST_S[k] 1 - * ------------- = --------------------------- - * 4096 W_HIST[0] + ... + W_HIST[k] - * - * 1 / Sum(W_HIST[0..k]) is always > 1 since the sum - * of the coefs 0..k is always < 1 but > 0 - * enr is in Q8 since the history buffer constains Q8 energies - *-----------------------------------------------------------*/ - /*L_tmp = Mpy_32_16_1(L_tmp, W_HIST_S_FX[k-1]); */ /* normalize average value */ - L_tmp = Mult_32_16( L_tmp, W_HIST_S_FX[k - 1] ); /* Q21 (24+12+1-16) */ - L_tmp = L_shl( L_tmp, 3 ); /* Q24 */ - enr = round_fx( L_tmp ); /* Q8 */ - } - /* decrease the energy in case of WB input */ - test(); - IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) - { - enr = add( enr, mult( hTdCngEnc->CNG_att_fx, FAC_LOG2_BY10_Q16 ) ); /* Q8 (Q7 + Q16 - Q15)*/ - } - ELSE IF( st_fx->bwidth != NB ) - { - IF( EQ_16( st_fx->bwidth, WB ) ) - { - IF( hDtxEnc->CNG_mode >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[hDtxEnc->CNG_mode]; - move16(); - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - move16(); - } - } - ELSE - { - att = 384; - move16(); /*1.5f Q8*/ - } - enr = sub( enr, att ); - } - /* intialize the energy quantization parameters */ - IF( st_fx->Opt_AMR_WB == 0 ) - { - step = STEP_SID_FX; // Q12 - move16(); - step_inv = ISTEP_SID_FX; - move16(); - maxl = 127; - move16(); - num_bits = 7; - move16(); - } - ELSE - { - step = STEP_AMR_WB_SID_FX; - move16(); - step_inv = ISTEP_AMR_WB_SID_FX; - move16(); - maxl = 63; - move16(); - num_bits = 6; - move16(); - } - - /* calculate the energy quantization index */ - enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ - enr_index = extract_l( L_shr( L_mult0( enr_index, step ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min( enr_index, maxl ); - enr_index = s_max( enr_index, 0 ); - - /* allow only slow energy increase */ - test(); - IF( hTdCngEnc->old_enr_index >= 0 && GT_16( enr_index, add( hTdCngEnc->old_enr_index, MAX_DELTA ) ) ) - { - IF( *allow_cn_step != 0 ) - { - tmp1 = mult( 27853 /* Q15(0.85) */, sub( enr_index, hTdCngEnc->old_enr_index ) ); - enr_index = add( hTdCngEnc->old_enr_index, tmp1 ); - } - ELSE - { - enr_index = add( hTdCngEnc->old_enr_index, MAX_DELTA ); - } - } - hTdCngEnc->old_enr_index = enr_index; - move16(); - - push_indice( hBstr, IND_ENERGY, enr_index, num_bits ); - if ( enr_index == 0 ) - { - enr_index = -5; - move16(); - } - /* Find quantized energy */ - /* *Enew = (float)enr_index / step - 2.0 */ - /* *Enew = (float)pow(2.0, *Enew) */ - L_tmp = L_mult( enr_index, step_inv ); /* Q16(0+15+1) */ - /* substract by 2 not done to leave Energy in Q2 */ - lo = L_Extract_lc( L_tmp, &hi ); - hTdCngEnc->Enew_fx = Pow2( add( hi, 4 ), lo ); /* Q6 */ - move32(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l( hTdCngEnc->Enew_fx ); - L_tmp = L_shl( hTdCngEnc->Enew_fx, exp ); /*Q(exp+6) */ - L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /* Q(exp+6+5-15=exp-4) */ - - L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /* Q6 */ - - exp = norm_l( L_tmp ); - fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 6 ); - L_tmp = L_Comp( exp, fra ); - enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* env[i] -= 2 * st->Enew;*/ - L_tmp1 = L_add( env[i], 0 ); - L_tmp = L_add( hTdCngEnc->Enew_fx, hTdCngEnc->Enew_fx ); - L_tmp1 = L_sub( L_tmp1, L_tmp ); /*Q6*/ - - IF( L_tmp1 < 0 ) - { - L_tmp1 = L_deposit_l( 6 ); /* (0.1)Q6 */ - } - /* env[i] = (float)log10( env[i] + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l( L_tmp1 ); - fra = Log2_norm_lc( L_shl( L_tmp1, exp ) ); - exp = sub( sub( 30, exp ), 6 ); - L_tmp = L_Comp( exp, fra ); - L_tmp1 = L_shr( L_tmp, 10 ); /* Q6 */ - - L_tmp = L_shr( L_deposit_l( att ), 2 ); /* Q6 */ - L_tmp1 = L_sub( L_tmp1, L_tmp ); - - IF( L_tmp1 < 0 ) - { - L_tmp1 = L_deposit_l( 0 ); - } - - L_tmp1 = L_sub( enr1, L_tmp1 ); - - env[i] = L_tmp1; - move32(); - } - - /* codebook search */ - min1 = 1310588928; /* 9999.0f Q17 */ - move32(); - min1_idx = 0; - move16(); - - FOR( i = 0; i < 64; i++ ) - { - d = L_deposit_l( 0 ); - FOR( j = 0; j < NUM_ENV_CNG; j++ ) - { - /* d += (env[j] - CNG_details_codebook_fx[i][j]) * (env[j] - CNG_details_codebook_fx[i][j]);*/ - L_tmp = L_sub( env[j], L_deposit_l( CNG_details_codebook_fx[i][j] ) ); /* Q6 */ - exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /*Q(exp+6)*/ - tmp1 = extract_h( L_tmp ); /*Q(exp+6-16)=exp-10*/ - L_tmp = L_mult_sat( tmp1, tmp1 ); /*Q(2*exp - 19)*/ - L_tmp = L_shr( L_tmp, sub( add( exp, exp ), 36 ) ); /* Q17 */ - d = L_add( d, L_tmp ); /* Q17 */ - } - - IF( LT_32( d, min1 ) ) - { - min1 = d; - move32(); - min1_idx = i; - move16(); - } - } - push_indice( hBstr, IND_CNG_ENV1, min1_idx, 6 ); - /* get quantized res_env_details */ - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - q_env[i] = L_deposit_l( CNG_details_codebook_fx[min1_idx][i] ); - move32(); - } - } - /* Update hangover memory during CNG */ - test(); - IF( *allow_cn_step == 0 && LT_32( Mult_32_16( hTdCngEnc->Enew_fx, 21845 /*1/1.5f, Q15*/ ), hTdCngEnc->lp_ener_fx ) ) - { - /* update the pointer to circular buffer of old LSP vectors */ - hTdCngEnc->ho_hist_ptr = add( hTdCngEnc->ho_hist_ptr, 1 ); - move16(); - if ( EQ_16( hTdCngEnc->ho_hist_ptr, HO_HIST_SIZE ) ) - { - hTdCngEnc->ho_hist_ptr = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &( hTdCngEnc->ho_lsp_hist_fx[( hTdCngEnc->ho_hist_ptr ) * M] ), M ); - - /* update the hangover energy buffer */ - hTdCngEnc->ho_ener_hist_fx[hTdCngEnc->ho_hist_ptr] = hTdCngEnc->Enew_fx; - move32(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* get quantized envelope */ - /* env[i] = pow(2.0f,(enr1 - q_env[i])) + 2*st->Enew;*/ - L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ - L_tmp = L_shl( L_tmp, 10 ); /* 16 */ - temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - - exp_pow = sub( 14, temp_hi_fx ); - L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ - env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); - move32(); /* Q6 */ - L_tmp = L_add( hTdCngEnc->Enew_fx, hTdCngEnc->Enew_fx ); - env[i] = L_add( env[i], L_tmp ); - move32(); /* Q6 */ - } - Copy32( env, &( hTdCngEnc->ho_env_hist_fx[( hTdCngEnc->ho_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); - } - hTdCngEnc->ho_hist_size = add( hTdCngEnc->ho_hist_size, 1 ); - move16(); - if ( GT_16( hTdCngEnc->ho_hist_size, HO_HIST_SIZE ) ) - { - hTdCngEnc->ho_hist_size = HO_HIST_SIZE; - move16(); - } - } - } - /* dithering bit for AMR-WB IO mode is always set to 0 */ - IF( EQ_32( st_fx->core_brate, SID_1k75 ) ) - { - push_indice( hBstr, IND_DITHERING, 0, 1 ); - } - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - push_indice( hBstr, IND_ACELP_16KHZ, 1, 1 ); - } - ELSE - { - push_indice( hBstr, IND_ACELP_16KHZ, 0, 1 ); - } - - push_indice( hBstr, IND_CNG_HO, s_min( hTdCngEnc->burst_ho_cnt, HO_HIST_SIZE - 1 ), 3 ); - hTdCngEnc->num_ho = m; - move16(); - push_indice( hBstr, IND_SID_TYPE, 0, 1 ); - - test(); - IF( LT_32( st_fx->input_Fs, 32000 ) && NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) - { - push_indice( hBstr, IND_SID_BW, 0, 1 ); - *sid_bw = 0; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - /* update the SID frames counter */ - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) - { - hDtxEnc->cng_cnt = 0; - move16(); - hTdCngEnc->cng_hist_ptr = -1; - move16(); - /* update frame length memory */ - hDtxEnc->last_CNG_L_frame = st_fx->L_frame; - move16(); - } - ELSE - { - hDtxEnc->cng_cnt = add( hDtxEnc->cng_cnt, 1 ); - move16(); - } - - return; -} -/*---------------------------------------------------------------------* - * swb_CNG_enc() - * - * SWB DTX/CNG encoding - *---------------------------------------------------------------------*/ -void swb_CNG_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ -) -{ - Word16 shb_SID_updt_fx = 0; - move16(); - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) || st_fx->core_brate == FRAME_NO_DATA ) - { - IF( EQ_16( st_fx->cng_type, LP_CNG ) ) - { - IF( GE_32( st_fx->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) ) - { - /* decide if SHB SID encoding or not */ - shb_SID_updt_fx = shb_DTX_fx( st_fx, shb_speech_fx, syn_12k8_16k_fx ); - - /* SHB CNG encoding */ - shb_CNG_encod_fx( st_fx, shb_SID_updt_fx ); - } - ELSE IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - } - } - hTdCngEnc->last_vad = 0; - move16(); - } - ELSE - { - hTdCngEnc->last_vad = 1; - move16(); - } - - return; -} - -/*---------------------------------------------------------------------* - * shb_CNG_encod() - * - * SID parameters encoding for SHB signal - *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 update_fx /* i : SID update flag */ -) -{ - Word16 idx_ener_fx; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - idx_ener_fx = 0; - move16(); - IF( EQ_16( update_fx, 1 ) ) - { - /* SHB energy quantization */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - idx_ener_fx = shr( add( mult( hTdCngEnc->mov_shb_cng_ener_fx, 9797 ), 1510 ), 8 ); /* Q0 */ - } - ELSE - { - } - - if ( LT_16( st_fx->bwidth, SWB ) ) - { - idx_ener_fx = 0; - move16(); - } - - IF( GT_16( idx_ener_fx, 15 ) ) - { - idx_ener_fx = 15; - move16(); - } - ELSE - { - idx_ener_fx = s_max( idx_ener_fx, 0 ); - } - - push_indice( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4 ); - push_indice( hBstr, IND_SID_BW, 1, 1 ); - delete_indice( hBstr, IND_CNG_ENV1 ); - move16(); - move16(); - - if ( st_fx->element_mode == IVAS_CPE_DFT ) - { - } - else - { - push_indice( hBstr, IND_UNUSED, 0, 2 ); - } - hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - hTdCngEnc->ho_sid_bw = L_or( hTdCngEnc->ho_sid_bw, 0x1L ); - move32(); - move32(); - } - ELSE - { - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - hTdCngEnc->ho_sid_bw = L_shl( L_and( hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - push_indice( hBstr, IND_SID_BW, 0, 1 ); - } - } - - return; -} - -/*---------------------------------------------------------------------* - * shb_DTX() - * - * Decide if encoding SHB SID or not - *---------------------------------------------------------------------*/ -static Word16 shb_DTX_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ -) -{ - Word16 i; - Word16 update_fx; - Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4]; - Word16 *shb_new_speech_fx; - Word32 wb_ener_fx; - Word32 shb_ener_fx; - Word16 log_wb_ener_fx; - Word16 log_shb_ener_fx; - Word16 tmp; - Word16 exp; - Word16 fra; - Word16 att; /*Q8*/ - Word16 allow_cn_step_fx = 0; - move16(); - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4; - Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); - Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); - - shb_ener_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - shb_ener_fx = L_mac_sat( shb_ener_fx, shb_old_speech_fx[i], shb_old_speech_fx[i] ); - } - - shb_ener_fx = L_add( Mpy_32_16_1( shb_ener_fx, 102 ), 1 ); /* 102 in Q15, shb_ener_fx in Q1 */ - - wb_ener_fx = L_deposit_l( 0 ); - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - wb_ener_fx = L_mac_sat( wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i] ); - } - - wb_ener_fx = L_add( Mpy_32_16_1( wb_ener_fx, 128 ), 1 ); /* 128 in Q15, wb_ener_fx in Q1 */ - - exp = norm_l( wb_ener_fx ); - fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); - exp = sub( 30 - 1, exp ); - wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - log_wb_ener_fx = round_fx_sat( L_shl_sat( wb_ener_fx, 10 ) ); /* log_wb_ener_fx in Q8 */ - exp = norm_l( shb_ener_fx ); - fra = Log2_norm_lc( L_shl( shb_ener_fx, exp ) ); - exp = sub( 30 - 1, exp ); - shb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - - test(); - IF( EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) - { - att = 0; - move16(); - } - ELSE - { - att = 1664; /*6.5 in Q8*/ - move16(); - } - - log_shb_ener_fx = sub_sat( round_fx_sat( L_shl_sat( shb_ener_fx, 10 ) ), att ); /* log_shb_ener_fx in Q8 */ - IF( hDtxEnc->first_CNG == 0 ) - { - hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - hTdCngEnc->last_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - } - - if ( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12.0f Q8*/ ) ) - { - allow_cn_step_fx = 1; - move16(); - } - - IF( EQ_16( allow_cn_step_fx, 1 ) ) - { - hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - } - ELSE - { - tmp = sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ); /* Q8 */ - tmp = mult( tmp, 29491 /*.9f in Q15*/ ); /* Q8 */ - hTdCngEnc->mov_wb_cng_ener_fx = add( hTdCngEnc->mov_wb_cng_ener_fx, tmp ); /* Q8 */ - move16(); - tmp = sub( log_shb_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ); - tmp = mult( tmp, 8192 /*.25f in Q15*/ ); /* Q8 */ - hTdCngEnc->mov_shb_cng_ener_fx = add( hTdCngEnc->mov_shb_cng_ener_fx, tmp ); /* Q8 */ - move16(); - } - hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); - move16(); - update_fx = 0; - move16(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - test(); - test(); - IF( hDtxEnc->first_CNG == 0 || EQ_16( hTdCngEnc->last_vad, 1 ) || GE_16( hTdCngEnc->shb_NO_DATA_cnt, 100 ) ) - { - update_fx = 1; - move16(); - } - ELSE - { - IF( hTdCngEnc->shb_cng_ini_cnt > 0 ) - { - update_fx = 1; - move16(); - hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); - move16(); - } - ELSE - { - IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 /*3.0f in Q8*/ ) ) - { - update_fx = 1; - move16(); - } - ELSE - { - test(); - IF( GE_16( st_fx->bwidth, SWB ) && LT_16( hTdCngEnc->last_SID_bwidth, SWB ) ) - { - update_fx = 1; - move16(); - } - ELSE - { - test(); - IF( LT_16( st_fx->bwidth, SWB ) && GE_16( hTdCngEnc->last_SID_bwidth, SWB ) ) - { - update_fx = 1; - move16(); - } - } - } - } - } - - hTdCngEnc->last_SID_bwidth = st_fx->bwidth; - move16(); - } - /* LF-boost not yet implemented in decoder which means that the specific wb_sid information is not used */ - test(); - test(); - if ( ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - update_fx = 1; - move16(); - } - - IF( EQ_16( update_fx, 1 ) ) - { - hTdCngEnc->last_wb_cng_ener_fx = hTdCngEnc->mov_wb_cng_ener_fx; - move16(); - hTdCngEnc->last_shb_cng_ener_fx = hTdCngEnc->mov_shb_cng_ener_fx; - move16(); - hTdCngEnc->shb_NO_DATA_cnt = 0; - move16(); - } - - - return ( update_fx ); -} - -/*---------------------------------------------------------------------* - * calculate_hangover_attenuation_gain_fx() - * - * - *---------------------------------------------------------------------*/ -void calculate_hangover_attenuation_gain_fx( - Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor Q15 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -) -{ - Word16 offset; - TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; - - *att = 32767; // 1.0f in Q15 - - move16(); - /* smoothing in case of CNG */ - IF( hTdCngEnc != NULL ) - { - test(); - test(); - test(); - IF( hTdCngEnc->burst_ho_cnt > 0 && ( vad_hover_flag != 0 ) && ( NE_16( st->bwidth, NB ) || st->element_mode > EVS_MONO ) ) /* corresponds to line 504 in FLT acelp_core_enc.c */ - { - if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) - { - } - else - { - offset = 5; - move16(); - test(); - if ( EQ_16( st->bwidth, WB ) && st->hDtxEnc->CNG_mode >= 0 ) - { - offset = st->hDtxEnc->CNG_mode; - move16(); - } - assert( hTdCngEnc->burst_ho_cnt > 0 ); - *att = CNG_burst_att_fx[offset][hTdCngEnc->burst_ho_cnt - 1]; /*Q15*/ - move16(); - } - } - } - return; -} - -void calculate_hangover_attenuation_gain_ivas_fx( - Encoder_State *st, /* i : encoder state structure */ - Word16 *att, /* o : attenuation factor Q15 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ -) + +/*---------------------------------------------------------------------* + * calculate_hangover_attenuation_gain_fx() + * + * + *---------------------------------------------------------------------*/ + +void calculate_hangover_attenuation_gain_fx( + Encoder_State *st, /* i : encoder state structure */ + Word16 *att, /* o : attenuation factor Q15 */ + const Word16 vad_hover_flag /* i : VAD hangover flag */ +) { Word16 lim, result_e; @@ -2732,6 +1401,20 @@ void calculate_hangover_attenuation_gain_ivas_fx( *att = extract_h( L_shl_sat( L_tmp, result_e ) ); move16(); } + ELSE IF( st->element_mode == EVS_MONO ) + { + Word16 offset = 5; + move16(); + test(); + if ( EQ_16( st->bwidth, WB ) && st->hDtxEnc->CNG_mode >= 0 ) + { + offset = st->hDtxEnc->CNG_mode; + move16(); + } + assert( st->hTdCngEnc->burst_ho_cnt > 0 ); + *att = CNG_burst_att_fx[offset][st->hTdCngEnc->burst_ho_cnt - 1]; /*Q15*/ + move16(); + } ELSE { test(); @@ -2761,10 +1444,17 @@ void calculate_hangover_attenuation_gain_ivas_fx( return; } -void swb_CNG_enc_ivas_fx( - Encoder_State *st, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ + +/*---------------------------------------------------------------------* + * swb_CNG_enc() + * + * SWB DTX/CNG encoding + *---------------------------------------------------------------------*/ + +void swb_CNG_enc_fx( + Encoder_State *st, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ ) { Word16 shb_SID_updt; @@ -2778,10 +1468,10 @@ void swb_CNG_enc_ivas_fx( IF( GE_32( st->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) ) { /* decide if SHB SID encoding or not */ - shb_SID_updt = shb_DTX_ivas_fx( st, shb_speech_fx, syn_12k8_16k_fx ); + shb_SID_updt = shb_DTX_fx( st, shb_speech_fx, syn_12k8_16k_fx ); /* SHB CNG encoding */ - shb_CNG_encod_ivas_fx( st, shb_SID_updt ); + shb_CNG_encod_fx( st, shb_SID_updt ); } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_32( st->core_brate, SID_2k40 ) ) { @@ -2811,7 +1501,7 @@ void swb_CNG_enc_ivas_fx( * SID parameters encoding for SHB signal *---------------------------------------------------------------------*/ -static void shb_CNG_encod_ivas_fx( +static void shb_CNG_encod_fx( Encoder_State *st, /* i/o: State structure */ const Word16 update /* i : SID update flag */ ) @@ -2819,17 +1509,13 @@ static void shb_CNG_encod_ivas_fx( Word16 idx_ener = 0; move16(); BSTR_ENC_HANDLE hBstr = st->hBstr; - Word16 ener_mid_dec_thr_fx; IF( EQ_16( update, 1 ) ) { IF( st->element_mode == EVS_MONO ) { - /* 6.0 in Q8 -> 1510 */ - /* 0.9 in Q15 29491 */ - /* ( 1 / log10(2.0) ) * 0.1 in Q15 ->10886 */ - idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 29491 ), 8 ); /* Q0 */ + idx_ener = shr( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 9797 ), 1510 ), 8 ); /* Q0 */ } ELSE { @@ -2840,7 +1526,6 @@ static void shb_CNG_encod_ivas_fx( idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 22938 ), 8 ); /* Q0 */ } - if ( LT_16( st->bwidth, SWB ) ) { idx_ener = 0; @@ -2901,6 +1586,7 @@ static void shb_CNG_encod_ivas_fx( push_indice( hBstr, IND_SHB_CNG_GAIN, idx_ener, 4 ); push_indice( hBstr, IND_SID_BW, 1, 1 ); delete_indice( hBstr, IND_CNG_ENV1 ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 ); @@ -2909,6 +1595,7 @@ static void shb_CNG_encod_ivas_fx( { push_indice( hBstr, IND_UNUSED, 0, 2 ); } + st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); st->hTdCngEnc->ho_sid_bw = L_or( st->hTdCngEnc->ho_sid_bw, 0x1L ); move32(); @@ -2924,21 +1611,21 @@ static void shb_CNG_encod_ivas_fx( return; } + /*---------------------------------------------------------------------* * shb_DTX() * * Decide if encoding SHB SID or not *---------------------------------------------------------------------*/ -static Word16 shb_DTX_ivas_fx( +static Word16 shb_DTX_fx( Encoder_State *st, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ ) { Word16 i; Word16 update; - Word16 allow_cn_step = 0; move16(); Word16 shb_old_speech_fx[( ACELP_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 4]; @@ -2987,7 +1674,6 @@ static Word16 shb_DTX_ivas_fx( exp = sub( 30 - 1, exp ); shb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - test(); IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { @@ -3001,7 +1687,7 @@ static Word16 shb_DTX_ivas_fx( } ELSE { - att_fx = -1664; // Q8 + att_fx = 1664; /*6.5 in Q8*/ move16(); } @@ -3009,8 +1695,6 @@ static Word16 shb_DTX_ivas_fx( IF( st->hDtxEnc->first_CNG == 0 ) { - - hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; // Q8 hTdCngEnc->mov_shb_cng_ener_fx = log_shb_ener_fx; // Q8 hTdCngEnc->last_wb_cng_ener_fx = log_wb_ener_fx; // Q8 @@ -3020,6 +1704,7 @@ static Word16 shb_DTX_ivas_fx( move16(); move16(); } + IF( GT_16( abs_s( sub( log_wb_ener_fx, hTdCngEnc->mov_wb_cng_ener_fx ) ), 3072 /*12 in Q8*/ ) ) { allow_cn_step = 1; @@ -3057,7 +1742,6 @@ static Word16 shb_DTX_ivas_fx( hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); update = 0; - move16(); move16(); @@ -3071,7 +1755,7 @@ static Word16 shb_DTX_ivas_fx( update = 1; move16(); } - ELSE IF( hTdCngEnc->shb_cng_ini_cnt > 0 ) + ELSE IF( st->element_mode != EVS_MONO && hTdCngEnc->shb_cng_ini_cnt > 0 ) { hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); update = 1; @@ -3088,6 +1772,13 @@ static Word16 shb_DTX_ivas_fx( update = 1; move16(); } + ELSE IF( st->element_mode == EVS_MONO && hTdCngEnc->shb_cng_ini_cnt > 0 ) + { + hTdCngEnc->shb_cng_ini_cnt = sub( hTdCngEnc->shb_cng_ini_cnt, 1 ); + update = 1; + move16(); + move16(); + } ELSE IF( GT_16( abs_s( sub( sub( hTdCngEnc->mov_wb_cng_ener_fx, hTdCngEnc->mov_shb_cng_ener_fx ), sub( hTdCngEnc->last_wb_cng_ener_fx, hTdCngEnc->last_shb_cng_ener_fx ) ) ), 768 ) ) { update = 1; diff --git a/lib_enc/cod4t64_fast_fx.c b/lib_enc/cod4t64_fast_fx.c index 7079f65971792963c9701841da0e9cc00e80bd54..4bba582550f9f62581730bb163b60a4e43de336b 100644 --- a/lib_enc/cod4t64_fast_fx.c +++ b/lib_enc/cod4t64_fast_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 66819c4acfaff9185d2be31f54171452a3ba7286..f4b74b351d9928d059ea9a61eb36108a7fe691fc 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -262,7 +262,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( st->igf != 0 ) { - tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); + tbe_celp_exc_fx( EVS_MONO, 0, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, 0 ); } pitch_buf[i_subfr / L_SUBFR] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index a60d070a5ee6e7471e8f1f6d554019cc19310a7f..d2dd0bf03f841acdada0a5f3f5d395ec07fb083f 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -12,7 +12,6 @@ #include "basop_util.h" #include "stl.h" #include "prot_fx_enc.h" -#include #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #ifdef DEBUGGING @@ -622,7 +621,9 @@ void ShapeSpectrum_ivas_fx( } test(); - IF( LE_32( total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) + test(); + test(); + IF( ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ) ) { max_low_pre = 0; move32(); @@ -698,7 +699,9 @@ void ShapeSpectrum_ivas_fx( /* reduce the peaks in the IGF region, to make life of the core-coder easier... */ test(); - IF( LE_32( total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) + test(); + test(); + IF( ( LE_32( total_brate, ACELP_13k20 ) || ( LE_32( st->element_brate, IVAS_16k4 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( st->bwidth, SWB ) ) { Word16 sf_width; Word16 dist_low, dist_high; @@ -3618,7 +3621,7 @@ void QuantizeTCXSpectrum_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); *gain_tcx_fx = mult( *gain_tcx_fx, att_fx ); move16(); } @@ -3909,8 +3912,8 @@ void coder_tcx_post_fx( const Word16 *A, const Word16 *Ai, Word16 *wsig, - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, + const Word16 shift ) { Word16 xn_buf[L_FRAME_MAX]; diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index a8c674170365bd4a43a6d0cee9216e58ffa83ab3..c944bc5f473ce969750d2893041c5673b6c45fa6 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -361,7 +361,11 @@ static void init_tcx_fx( IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); +#else InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); +#endif } /* TCX-LTP */ diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index cdecaf3d6f34caa5d7f2bce86f20c85b8bc0ace5..2cbbd5c9aa8454dd7513aeb90790cb99d7241afd 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -460,18 +460,14 @@ void core_encode_openloop_fx( E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); E_LPC_a_lsp_conversion( A, lsptmp, lsp_new, M ); Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 1 ); - cng_params_upd_fx( lsptmp, res, st->L_frame, &hTdCngEnc->ho_circ_ptr, - hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, - Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, - hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate ); + + cng_params_upd_fx( lsptmp, res, st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); } ELSE { - cng_params_upd_fx( lsp_new, hLPDmem->old_exc + L_EXC_MEM - st->L_frame, - st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, - &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, Q_new, ENC, NULL, - &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, - hDtxEnc->last_active_brate ); + cng_params_upd_fx( lsp_new, hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &hTdCngEnc->ho_circ_ptr, hTdCngEnc->ho_ener_circ_fx, &hTdCngEnc->ho_circ_size, hTdCngEnc->ho_lsp_circ_fx, + Q_new, ENC, NULL, &hTdCngEnc->cng_buf_cnt, hTdCngEnc->cng_exc2_buf, hTdCngEnc->cng_Qexc_buf, hTdCngEnc->cng_brate_buf, hDtxEnc->last_active_brate, EVS_MONO, -1 ); } IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index b61609e50c06e942b791564429ee2dad0f04fae0..27c429ded7f03b07c847cd9022c6d5caeb55170e 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -109,7 +109,11 @@ void core_coder_mode_switch_fx( move16(); IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); +#else InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); +#endif } st->narrowBand = 0; @@ -333,7 +337,11 @@ void core_coder_mode_switch_ivas_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); +#else InitTnsConfigs_ivas_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); +#endif SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT ); } diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index 94a2ef74651e237f5f7d2930b346d7cd00143bf1..f6aba6f612395a6ef00d9b002f6376151556a4af 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ #include -//#include "prot_fx.h" #include "options.h" #include "cnst.h" /* Common constants */ #include "basop_util.h" @@ -12,60 +11,13 @@ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ -void core_encode_update_fx( Encoder_State *st ) -{ - Word16 n; - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - - /*--------------------------------------------------------------* - * Update Buffers - *---------------------------------------------------------------*/ - - /* Update Input Signal Buffers */ - - n = add( st->encoderPastSamples_enc, st->encoderLookahead_enc ); - - Copy( st->buf_speech_enc + st->L_frame, st->buf_speech_enc, n ); - Copy( st->buf_speech_enc_pe + st->L_frame, st->buf_speech_enc_pe, n ); - - - IF( !st->tcxonly ) - { - n = add( st->L_frame, shr( st->L_frame, 2 ) ); - Copy( st->buf_wspeech_enc + st->L_frame, st->buf_wspeech_enc, n ); - } - - - IF( hTcxEnc != NULL ) - { - IF( ( st->core == ACELP_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core, AMR_WB_CORE ) ) - { - Copy( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame ); - } - } - n = add( st->encoderPastSamples_enc, st->encoderLookahead_enc ); - Copy( st->buf_synth + st->L_frame, st->buf_synth, add( st->L_frame, L_SUBFR ) ); - if ( hTcxEnc != NULL ) - { - Copy( hTcxEnc->buf_speech_ltp + st->L_frame, hTcxEnc->buf_speech_ltp, n ); - } - /* Update previous mode */ - test(); - test(); - test(); - IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && EQ_16( st->codec_mode, MODE2 ) ) ) - { - /* reset LP memories */ - set16_fx( st->mem_MA_fx, 0, M ); - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); - } -} /*-------------------------------------------------------------------* * core_encode_update_cng_fx() * * Common updates in case of CNG *-------------------------------------------------------------------*/ + void core_encode_update_cng_fx( Encoder_State *st, Word16 *timeDomainBuffer, @@ -150,7 +102,6 @@ void core_encode_update_cng_fx( p_A += ( M + 1 ); } - tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) ); E_UTIL_deemph2( negate( shift ), wsyn, st->preemph_fac, st->L_frame, &tmp ); hLPDmem->mem_w0 = sub_sat( st->wspeech_enc[st->L_frame - 1], tmp ); @@ -200,7 +151,7 @@ void core_encode_update_cng_fx( * Common updates of buffers *-------------------------------------------------------------------*/ -void core_encode_update_ivas_fx( +void core_encode_update_fx( Encoder_State *st /* i/o: Encoder state structure */ ) { @@ -226,11 +177,18 @@ void core_encode_update_ivas_fx( test(); IF( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) ) { - Word16 max_e = s_max( st->hTcxEnc->exp_buf_speech_ltp, st->exp_buf_speech_enc ); - Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( sub( max_e, st->hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(31-max_e) - Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, negate( sub( max_e, st->exp_buf_speech_enc ) ) ); // Q(31-max_e) - st->hTcxEnc->exp_buf_speech_ltp = max_e; - move16(); + IF( st->element_mode == EVS_MONO ) + { + Copy( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame ); + } + ELSE + { + Word16 max_e = s_max( st->hTcxEnc->exp_buf_speech_ltp, st->exp_buf_speech_enc ); + Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( sub( max_e, st->hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(31-max_e) + Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, negate( sub( max_e, st->exp_buf_speech_enc ) ) ); // Q(31-max_e) + st->hTcxEnc->exp_buf_speech_ltp = max_e; + move16(); + } } } @@ -265,5 +223,6 @@ void core_encode_update_ivas_fx( set16_fx( st->mem_MA_fx, 0, M ); Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); // 2.56 scaling } + return; } diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index aa06b12d20d5eeff4b7469045355661ab18be1d9..497f4ad9e4410f381ca3d485ceaff6042686a7c1 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -19,9 +19,11 @@ *---------------------------------------------------------------------*/ void core_switching_pre_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ + Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz Qx*/ + const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ const Word16 *old_inp_16k, /* i : old input signal @16kHz Qx*/ + const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ const Word16 active_cnt, /* i : active frame counter Q0*/ const Word16 last_element_mode /* i : last_element_mode Q0*/ ) @@ -64,6 +66,7 @@ void core_switching_pre_enc_fx( set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } + test(); IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { @@ -112,7 +115,7 @@ void core_switching_pre_enc_fx( test(); test(); test(); - IF( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) + if ( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) { /* very first frame is HQ_CORE */ st_fx->last_core = HQ_CORE; @@ -200,12 +203,15 @@ void core_switching_pre_enc_fx( /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { - move16(); hLPDmem->syn[M] = 0; move16(); set16_fx( hLPDmem->mem_syn2, 0, M ); set16_fx( hLPDmem->mem_syn, 0, M ); set16_fx( hLPDmem->mem_syn1_fx, 0, M ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hLPDmem->q_mem_syn = Q15; + } hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; @@ -237,7 +243,14 @@ void core_switching_pre_enc_fx( } Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); /*Q6*/ - set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16 ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR << 6, tmp16 ); + } + ELSE + { + set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16 ); + } /* Reset old ACELP buffers */ test(); @@ -251,12 +264,14 @@ void core_switching_pre_enc_fx( /* reset BWE memories */ hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); } IF( hBWE_FD != NULL ) { set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } + test(); test(); test(); @@ -292,7 +307,7 @@ void core_switching_pre_enc_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move16(); + move32(); } /* reset BWE memories */ @@ -301,6 +316,7 @@ void core_switching_pre_enc_fx( set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } + test(); test(); test(); @@ -341,7 +357,25 @@ void core_switching_pre_enc_fx( } Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); } - Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + IF( GT_16( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ) + { + Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) ); // prev_Q_input_lp + } + ELSE + { + Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_12k8 + hBWE_FD->prev_Q_input_lp = q_old_inp_12k8; + move16(); + Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + } + } + ELSE + { + Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + } } ELSE { @@ -356,12 +390,30 @@ void core_switching_pre_enc_fx( Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); } - Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + IF( GT_16( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ) + { + Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) ); // prev_Q_input_lp + } + ELSE + { + Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_16k + hBWE_FD->prev_Q_input_lp = q_old_inp_16k; + move16(); + Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + } + } + ELSE + { + Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + } } tmp = sub( L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP ); Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); /*Q(Q_shb_spch)*/ - add( 0, 0 ); + hBWE_FD->Q_new_input_hp = 0; + move16(); IF( NE_16( st_fx->last_extl, WB_BWE ) ) { @@ -377,6 +429,33 @@ void core_switching_pre_enc_fx( move16(); /* Set to a High Exponent so it is 1^-30 */ } + /*---------------------------------------------------------------------* + * band-width switching from WB -> SWB/FB + *---------------------------------------------------------------------*/ + + IF( st_fx->element_mode > EVS_MONO ) + { + IF( st_fx->bwidth_sw_cnt == 0 ) + { + test(); + IF( GE_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) + { + st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); + move16(); + } + } + ELSE + { + st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); + move16(); + IF( EQ_16( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ) ) + { + st_fx->bwidth_sw_cnt = 0; + move16(); + } + } + } + return; } @@ -386,13 +465,14 @@ void core_switching_pre_enc_fx( * * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ + void core_switching_post_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 old_inp_12k8[], /* i : input signal @12.8 kHz Qinp */ const Word16 old_inp_16k[], /* i : input signal @16 kHz Qinp */ const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, + const Word16 Qshift, + const Word16 Q_new, const Word16 Qsp, /* i/o : Q from acelp synthsis */ Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ) @@ -416,11 +496,20 @@ void core_switching_post_enc_fx( hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hBWE_FD->q_mem_deemph_old_syn = 0; + move16(); + } } ELSE { - *Qmus = Qsp; /* Write Qout */ - move16(); + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + *Qmus = Qsp; /* Write Qout */ + move16(); + } + IF( hBWE_TD == NULL ) { return; @@ -454,23 +543,44 @@ void core_switching_post_enc_fx( test(); test(); test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) ) ) { set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + InitSWBencBufferStates_fx( st_fx->hBWE_TD, NULL ); + } + ELSE + { + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + } swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); - set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + set16_fx( st_fx->hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); + } + ELSE + { + set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); + } } ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && - ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || - NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_mode, st_fx->rf_mode_last ) ) ) + ( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) ) || + ( NE_16( st_fx->last_bwidth, st_fx->bwidth ) ) || ( NE_16( st_fx->last_codec_mode, MODE1 ) ) || ( NE_16( st_fx->rf_mode_last, st_fx->rf_mode ) ) ) ) { set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); @@ -483,6 +593,7 @@ void core_switching_post_enc_fx( { TBEreset_enc_fx( st_fx->hBWE_TD, st_fx->last_core, st_fx->bwidth ); } + test(); test(); test(); @@ -493,6 +604,16 @@ void core_switching_post_enc_fx( hBWE_TD->fb_tbe_demph_fx = 0; fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } + + /* Fade towards init value for non HQ_CORE */ + test(); + IF( NE_16( st_fx->element_mode, EVS_MONO ) && st_fx->hHQ_core != NULL ) + { + st_fx->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st_fx->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), L_shr( HQ_CREST_THRESHOLD_FX, sub( Q28, st_fx->hHQ_core->crest_lp_q ) ) ) ); /*crest_lp_q*/ + move32(); + st_fx->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st_fx->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), L_shr( HQ_CREST_MOD_THRESHOLD_FX, sub( Q29, st_fx->hHQ_core->crest_mod_lp_q ) ) ) ); /*crest_mod_lp_q*/ + move32(); + } } return; @@ -627,554 +748,3 @@ void core_switching_hq_prepare_enc_fx( } return; } - -void core_switching_pre_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz q_old_inp_12k8 */ - const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ - const Word16 *old_inp_16k, /* i : old input signal @16kHz q_old_inp_16k */ - const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ - const Word16 active_cnt, /* i : active frame counter */ - const Word16 last_element_mode /* i : last_element_mode */ -) -{ - Word16 Sample_Delay_HP, Sample_Delay_LP; - Word16 tmp16; - Word16 tmp; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; - FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; - - /* Mode switching */ - test(); - test(); - test(); - IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && ( st_fx->element_mode > EVS_MONO ) ) ) ) - { - IF( hLPDmem != NULL ) - { - Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); - } - - if ( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - st_fx->igf = 0; - move16(); - } - - IF( hBWE_TD != NULL ) - { - IF( st_fx->last_core != ACELP_CORE ) - { - /* reset BWE memories */ - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - } - - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - } - test(); - IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) - { - if ( st_fx->element_mode == EVS_MONO ) - { - st_fx->last_core = HQ_CORE; - move16(); - } - IF( hHQ_core != NULL ) - { - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - - hHQ_core->mode_count = 0; - move16(); - hHQ_core->mode_count1 = 0; - move16(); - - set16_fx( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); - hHQ_core->prev_frm_hfe2 = 0; - move16(); - hHQ_core->prev_stab_hfe2 = 0; - move16(); - } - test(); - /*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/ - IF( ( st_fx->element_mode == EVS_MONO ) && hTcxEnc != NULL ) - { - set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); - } - } - - test(); - IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) ) - { - Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); - - st_fx->rate_switching_reset_16kHz = lsp_convert_poly_fx( st_fx->lsp_old16k_fx, st_fx->L_frame, 0 ); - move16(); - } - - st_fx->use_acelp_preq = 0; - move16(); - } - - test(); - test(); - test(); - if ( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) - { - /* very first frame is HQ_CORE */ - st_fx->last_core = HQ_CORE; - move16(); - } - - test(); - test(); - IF( EQ_16( st_fx->core, HQ_CORE ) && ( ( st_fx->last_core == ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* HQ init */ - { - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - - hHQ_core->mode_count = 0; - move16(); - hHQ_core->mode_count1 = 0; - move16(); - - set16_fx( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); - hHQ_core->prev_frm_hfe2 = 0; - move16(); - hHQ_core->prev_stab_hfe2 = 0; - move16(); - - IF( hTcxEnc != NULL ) - { - set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); - } - } - - /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores - within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ - test(); - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) - { - IF( hSC_VBR != NULL ) - { - hSC_VBR->last_last_ppp_mode = 0; - move16(); - hSC_VBR->last_ppp_mode = 0; - move16(); - hSC_VBR->last_nelp_mode = 0; - move16(); - } - } - - test(); - test(); - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) ) - { - st_fx->act_count = 3; - move16(); - st_fx->uv_count = 0; - move16(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( ( st_fx->core == ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) /* EVS and HQ -> ACELP */ || - ( ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( active_cnt, 1 ) ) || - ( st_fx->core == ACELP_CORE && GT_16( st_fx->last_L_frame, L_FRAME16k ) ) /* TCX @ 25.6/32 kHz -> ACELP */ ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_16k ); - } - ELSE - { - Copy( TRWB_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - } - - /* Reset ACELP parameters */ - IF( hLPDmem != NULL ) - { - move16(); - hLPDmem->syn[M] = 0; - move16(); - set16_fx( hLPDmem->mem_syn2, 0, M ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - hLPDmem->q_mem_syn = Q15; - move16(); - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - /* set16_fx( st_fx->dispMem, 0, 8 ); */ - set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); - hLPDmem->dm_fx.prev_state = 0; - move16(); - hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); - } - st_fx->Nb_ACELP_frames = 0; - move16(); - - set16_fx( st_fx->mem_MA_fx, 0, M ); - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - init_gp_clip_fx( st_fx->clip_var_fx ); - st_fx->last_coder_type = GENERIC; - move16(); - - tmp16 = add( NB_SUBFR, 1 ); - - if ( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - tmp16 = NB_SUBFR; - move16(); - } - - Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); - set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR << 6, tmp16 ); - /* Reset old ACELP buffers */ - test(); - IF( ( st_fx->element_mode == EVS_MONO ) && hLPDmem != NULL ) - { - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - } - IF( hBWE_TD != NULL ) - { - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - - /* reset BWE memories */ - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - } - IF( hBWE_FD != NULL ) - { - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - } - } - test(); - test(); - test(); - IF( ( ( st_fx->core == ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) ) - { - /* Reset the ACELP core in case of TCX->ACELP core switching */ - st_fx->Nb_ACELP_frames = 0; - move16(); - - IF( hLPDmem != NULL ) - { - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - init_gp_clip_fx( st_fx->clip_var_fx ); - set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); - hLPDmem->dm_fx.prev_state = 0; - move16(); - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - } - - st_fx->last_coder_type = GENERIC; - move16(); - - tmp16 = shr( st_fx->L_frame, 6 ); - Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); - set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR << 6, tmp16 ); - /* Reset old TD BWE buffers */ - IF( hBWE_TD != NULL ) - { - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - } - - /* reset BWE memories */ - IF( hBWE_FD != NULL ) - { - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - } - } - test(); - test(); - test(); - IF( GE_32( st_fx->input_Fs, 16000 ) && NE_16( st_fx->last_extl, WB_BWE ) && EQ_16( st_fx->extl, WB_BWE ) && hBWE_FD != NULL ) - { - test(); - IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) - { - hBWE_FD->prev_mode = NORMAL; - move16(); - hBWE_FD->modeCount = 0; - move16(); - } - - hBWE_FD->prev_L_swb_norm1 = 8; - move16(); - } - - test(); - test(); - test(); - test(); - test(); - IF( ( GE_32( st_fx->input_Fs, 32000 ) && NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || - ( GE_32( st_fx->input_Fs, 48000 ) && NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) ) - { - /* we are switching to SWB BWE - reset SWB BWE buffers */ - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); - Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); - IF( ( st_fx->element_mode > EVS_MONO ) ) - { - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); - } - Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); - } - IF( GT_16( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ) - { - Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) ); // prev_Q_input_lp - } - ELSE - { - Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_12k8 - hBWE_FD->prev_Q_input_lp = q_old_inp_12k8; - move16(); - Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); - } - } - ELSE - { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); - Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) - { - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); - } - Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); - } - IF( GT_16( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ) - { - Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) ); // prev_Q_input_lp - } - ELSE - { - Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_16k - hBWE_FD->prev_Q_input_lp = q_old_inp_16k; - move16(); - Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); - } - } - - tmp = sub( L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP ); - Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); - hBWE_FD->Q_new_input_hp = 0; - move16(); - - IF( NE_16( st_fx->last_extl, WB_BWE ) ) - { - hBWE_FD->prev_mode = NORMAL; - move16(); - hBWE_FD->modeCount = 0; - move16(); - } - hBWE_FD->EnergyLF_fx = 0; - hBWE_FD->EnergyLF_exp = 0; - move32(); - move16(); - hBWE_FD->prev_L_swb_norm1 = 8; - move16(); /*8.0 in Q0 */ - st_fx->EnergyLT_fx_exp = 30; - move16(); /* Set to a High Exponent so it is 1^-30 */ - } - /*---------------------------------------------------------------------* - * band-width switching from WB -> SWB/FB - *---------------------------------------------------------------------*/ - IF( st_fx->element_mode > EVS_MONO ) - { - IF( st_fx->bwidth_sw_cnt == 0 ) - { - test(); - IF( GE_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) - { - st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); - move16(); - } - } - ELSE - { - st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); - move16(); - IF( EQ_16( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ) ) - { - st_fx->bwidth_sw_cnt = 0; - move16(); - } - } - } - - return; -} - -/*---------------------------------------------------------------------* - * core_switching_post_enc() - * - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - -void core_switching_post_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz Q_new-1 */ - Word16 *old_inp_16k_fx, /* i : old input signal @16kHz Q_new-1 */ - Word16 A_fx[], /* i : unquant. LP filter coefs. Q12 */ - Word16 Q_new ) -{ - IF( EQ_16( st->core, HQ_CORE ) ) - { - st->use_acelp_preq = 0; - move16(); - test(); - test(); - IF( ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) && st->element_mode == EVS_MONO ) /* core switching ==> ACELP subframe encoding */ - { - /* Memory scaling to keep everything in common q */ - Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ - Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ - Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ - Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ - Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ - st->hLPDmem->mem_w0 = shl( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); /* Q_new-1 */ - move16(); - st->hLPDmem->q_mem_syn = sub( Q_new, 1 ); - move16(); - - acelp_core_switch_enc_ivas_fx( st, old_inp_12k8_fx + L_INP_MEM - NS2SA( INT_FS_12k8, ACELP_LOOK_NS ), old_inp_16k_fx + L_INP_MEM - NS2SA( INT_FS_16k, ACELP_LOOK_NS ), A_fx, 0, sub( Q_new, 1 ) ); - } - - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - st->hBWE_FD->mem_deemph_old_syn_fx = 0; - move16(); - st->hBWE_FD->q_mem_deemph_old_syn = 0; - move16(); - } - ELSE - { - IF( st->hBWE_TD == NULL ) - { - return; - } - - test(); - /* reset SWB TBE buffers */ - IF( EQ_16( st->extl, WB_TBE ) && NE_16( st->last_extl, WB_TBE ) ) - { - wb_tbe_extras_reset_fx( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - - IF( NE_16( st->last_extl, WB_BWE ) ) - { - set16_fx( st->hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( st->hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - } - - set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); - set16_fx( st->hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st->hBWE_TD->mem_csfilt_fx, 0, 2 ); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - - IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && - ( EQ_16( st->last_core, HQ_CORE ) || NE_16( st->L_frame, st->last_L_frame ) || ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) ) ) - { - set16_fx( st->hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - - InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); - swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); - - set16_fx( st->hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); - set16_fx( st->hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); - } - ELSE IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && ( ( EQ_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_32( st->last_total_brate, st->total_brate ) ) || ( NE_16( st->last_bwidth, st->bwidth ) ) || ( NE_16( st->last_codec_mode, MODE1 ) ) || ( NE_16( st->rf_mode_last, st->rf_mode ) ) ) ) - { - set16_fx( st->hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st->hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st->hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; - move16(); - } - ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) - { - TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); - } - - test(); - test(); - test(); - test(); - /* Interp_3_2 CNG buffers reset */ - IF( EQ_16( st->extl, FB_TBE ) && ( ( NE_16( st->last_extl, FB_TBE ) && NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) || NE_16( st->L_frame, st->last_L_frame ) ) ) - { - set16_fx( st->hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st->hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); - } - /* Fade towards init value for non HQ_CORE */ - IF( st->hHQ_core != NULL ) - { - st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), L_shr( HQ_CREST_THRESHOLD_FX, sub( Q28, st->hHQ_core->crest_lp_q ) ) ) ); /*crest_lp_q*/ - move32(); - st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), L_shr( HQ_CREST_MOD_THRESHOLD_FX, sub( Q29, st->hHQ_core->crest_mod_lp_q ) ) ) ); /*crest_mod_lp_q*/ - move32(); - } - } - - return; -} diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index 086b6e86aedcdb5772da37fd780e00be60f03e7a..ed6c09bb761b0b58490c5ac8200bf6e68ad4415f 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -174,6 +174,11 @@ void decision_matrix_enc_fx( } } +#ifdef HARMONIZE_ACELP_ENC + /* set inactive coder_type flag in ACELP core to GSC */ + st_fx->inactive_coder_type_flag = 1; +#endif + return; } @@ -752,85 +757,12 @@ void signalling_enc_fx( } /*---------------------------------------------------------------------* - * signalling_enc_rf() + * signaling_enc_rf() * * write channel-aware signalling information into the bitstream *---------------------------------------------------------------------*/ -void signaling_enc_rf_fx( - Encoder_State *st /* i : encoder state structure */ -) -{ - Word16 i; - Word16 sfr; - RF_ENC_HANDLE hRF = st->hRF; - - /* write partial copy into bitstream */ - IF( EQ_16( st->rf_mode, 1 ) ) - { - enc_prm_rf_ivas_fx( st, hRF->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset ); - hRF->rf_indx_tbeGainFr[0] = hRF->RF_bwe_gainFr_ind; /*Q0*/ - move16(); - } - /* Shift the RF indices such that the partial copy associated with - (n-fec_offset)th frame is included in the bitstream in nth frame. */ - IF( hRF != NULL ) - { - FOR( i = st->rf_fec_offset; i >= 0; i-- ) - { - /* rf frame type */ - hRF->rf_indx_frametype[i + 1] = hRF->rf_indx_frametype[i]; - move16(); - /* rf target bits buffer */ - hRF->rf_targetbits_buff[i + 1] = hRF->rf_targetbits_buff[i]; - move16(); - /* lsf indx */ - hRF->rf_indx_lsf[i + 1][0] = hRF->rf_indx_lsf[i][0]; - hRF->rf_indx_lsf[i + 1][1] = hRF->rf_indx_lsf[i][1]; - hRF->rf_indx_lsf[i + 1][2] = hRF->rf_indx_lsf[i][2]; - move16(); - move16(); - move16(); - /* ES pred energy */ - hRF->rf_indx_EsPred[i + 1] = hRF->rf_indx_EsPred[i]; - move16(); - /* LTF mode, sfr params: pitch, fcb and gain */ - FOR( sfr = 0; sfr < st->nb_subfr; sfr++ ) - { - hRF->rf_indx_ltfMode[i + 1][sfr] = hRF->rf_indx_ltfMode[i][sfr]; - hRF->rf_indx_pitch[i + 1][sfr] = hRF->rf_indx_pitch[i][sfr]; - hRF->rf_indx_fcb[i + 1][sfr] = hRF->rf_indx_fcb[i][sfr]; - hRF->rf_indx_gain[i + 1][sfr] = hRF->rf_indx_gain[i][sfr]; - move16(); - move16(); - move16(); - move16(); - } - - /* shift the nelp indices */ - hRF->rf_indx_nelp_iG1[i + 1] = hRF->rf_indx_nelp_iG1[i]; - hRF->rf_indx_nelp_iG2[i + 1][0] = hRF->rf_indx_nelp_iG2[i][0]; - hRF->rf_indx_nelp_iG2[i + 1][1] = hRF->rf_indx_nelp_iG2[i][1]; - hRF->rf_indx_nelp_fid[i + 1] = hRF->rf_indx_nelp_fid[i]; - move16(); - move16(); - move16(); - move16(); - /* tbe gain Fr shift */ - hRF->rf_indx_tbeGainFr[i + 1] = hRF->rf_indx_tbeGainFr[i]; - hRF->rf_clas[i + 1] = hRF->rf_clas[i]; - hRF->rf_gain_tcx[i + 1] = hRF->rf_gain_tcx[i]; - hRF->rf_tcxltp_param[i + 1] = hRF->rf_tcxltp_param[i]; - move16(); - move16(); - move16(); - move16(); - } - } - return; -} - -void signalling_enc_rf_fx( +void signaling_enc_rf_fx( Encoder_State *st /* i : encoder state structure */ ) { diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 71c56cecf76462223fb91a1f104a79b2dd5b9b5a..173092cdf8562ab854f5c880534346183d0c701f 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 483304cdedf36ced3b85cb458bcec935acadf4fd..b6b4e5a3414aca3d9d28c4a8bb1c4edd63c9f3f7 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -43,7 +43,7 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, /*==================================================================================*/ -/* FUNCTION : dtx_ivas_fx() */ +/* FUNCTION : dtx_fx() */ /*----------------------------------------------------------------------------------*/ /* PURPOSE : Discontinuous transmission operation */ /*----------------------------------------------------------------------------------*/ @@ -58,595 +58,66 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, /* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ /* _ (Encoder_State_Fx) st_fx : encoder state structure */ /*----------------------------------------------------------------------------------*/ - /*----------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*==================================================================================*/ -void dtx_ivas_fx( + +void dtx_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ const Word16 vad, /* i : vad flag for DTX Q0*/ const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ - Word16 Q_speech /* i : Q factor for speech */ + const Word16 Q_speech /* i : Q factor for speech */ ) { Word16 alpha, i, j, Q_speech2; Word32 L_tmp; DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; Word32 total_brate_ref; + Word16 flag_lp_noise; - total_brate_ref = st_fx->total_brate; - move32(); - - IF( st_fx->dtx_sce_sba != 0 ) - { - last_br_cng_flag = 1; - last_br_flag = 1; - move16(); - move16(); - } - ELSE - { - test(); - test(); - test(); - last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) ); - - test(); - test(); - test(); - - last_br_flag = ( st_fx->element_mode == EVS_MONO && LE_32( st_fx->last_total_brate, MAX_BRATE_DTX_EVS ) ) || - ( st_fx->element_mode != EVS_MONO && LE_32( last_ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || - LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ); - } - - /* Initialization */ - IF( st_fx->ini_frame == 0 ) - { - st_fx->active_cnt = CNG_TYPE_HO; - move16(); - - st_fx->cng_type = FD_CNG; - move16(); - test(); - test(); - test(); - if ( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && NE_16( st_fx->element_mode, IVAS_SCE ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - st_fx->cng_type = LP_CNG; - move16(); - } - } - test(); - test(); - test(); - test(); - test(); - IF( st_fx->Opt_DTX_ON && vad == 0 && - GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */ - st_fx->fd_cng_reset_flag == 0 && - NE_16( st_fx->last_core, AMR_WB_CORE ) && - st_fx->Opt_AMR_WB == 0 ) - { - test(); - test(); - test(); - IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) && - NE_32( st_fx->last_total_brate_cng, st_fx->total_brate ) && last_br_cng_flag ) - { - st_fx->total_brate = st_fx->last_total_brate_cng; - move32(); - test(); - if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) - { - st_fx->Opt_SC_VBR = 0; - move16(); - } - st_fx->rf_mode = st_fx->last_rf_mode_cng; - move16(); - st_fx->bwidth = st_fx->last_bwidth_cng; - move16(); - st_fx->codec_mode = st_fx->last_codec_mode_cng; - move16(); - } - test(); - test(); - IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag ) - - { - st_fx->total_brate = st_fx->last_total_brate; - move32(); - test(); - if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) - { - st_fx->Opt_SC_VBR = 0; - move16(); - } - - st_fx->Opt_RF_ON = 0; - move16(); - test(); - test(); - test(); - if ( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && ( st_fx->bwidth != NB ) ) - { - st_fx->Opt_RF_ON = 1; - move16(); - } - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); - st_fx->bwidth = st_fx->last_bwidth; - move32(); - IF( st_fx->element_mode > EVS_MONO ) - { - st_fx->codec_mode = MODE1; - move16(); - } - ELSE - { - st_fx->codec_mode = get_codec_mode( st_fx->total_brate ); - move16(); - } - } - } - - /*------------------------------------------------------------------------* - * Select SID or FRAME_NO_DATA frame if DTX is enabled - *------------------------------------------------------------------------*/ - - br_dtx_flag = 1; + flag_lp_noise = 0; move16(); - - IF( st_fx->dtx_sce_sba == 0 ) - { - test(); - test(); - test(); - test(); - br_dtx_flag = ( ( st_fx->element_mode == EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) || - ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || - LT_16( extract_h( st_fx->lp_noise_32fx ), DTX_THR * 256 ); - } - test(); - test(); test(); test(); - IF( st_fx->Opt_DTX_ON && vad == 0 && - GT_16( st_fx->ini_frame, 2 ) && /* CNG coding starts after 2 frames */ - br_dtx_flag && - st_fx->fd_cng_reset_flag == 0 ) - { - /* reset counter */ - st_fx->active_cnt = 0; - move16(); - - IF( st_fx->Opt_AMR_WB ) - { - st_fx->last_total_brate_cng = -1; - move16(); - } - ELSE - { - st_fx->last_total_brate_cng = st_fx->total_brate; - move16(); - st_fx->last_bwidth_cng = st_fx->bwidth; - move16(); - st_fx->last_codec_mode_cng = st_fx->codec_mode; - move16(); - st_fx->last_rf_mode_cng = st_fx->rf_mode; - move16(); - } - - IF( hDtxEnc->cnt_SID == 0 ) - { - /* this will be a SID frame */ - IF( st_fx->Opt_AMR_WB ) - { - st_fx->core_brate = SID_1k75; - move32(); - } - ELSE - { - st_fx->core_brate = SID_2k40; - move32(); - } - } - ELSE - { - /* this will be a no data frame */ - st_fx->core_brate = FRAME_NO_DATA; - move32(); - } - - test(); - test(); - IF( ( st_fx->core_brate == FRAME_NO_DATA ) && ( st_fx->last_core != ACELP_CORE ) && !st_fx->Opt_AMR_WB ) - { - /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */ - st_fx->core_brate = SID_2k40; - move32(); - } - test(); - test(); - IF( ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) ) - { - st_fx->cng_type = FD_CNG; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->element_mode == EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_48k ) || EQ_32( st_fx->total_brate, HQ_96k ) || EQ_32( st_fx->total_brate, HQ_128k ) ) ) - { - st_fx->codec_mode = MODE2; - move16(); - } - } - ELSE - { - test(); - test(); - test(); - test(); - IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */ - { - test(); - test(); - test(); - IF( ( st_fx->element_mode == EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) ) - { - st_fx->codec_mode = MODE2; - move16(); - } - } - ELSE - { - st_fx->cng_type = LP_CNG; - move16(); - if ( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - hTdCngEnc->lp_cng_mode2 = 1; - move16(); - } - st_fx->codec_mode = MODE1; - move16(); - } - } - /* reset the bitstream (IVAS format signalling was already written) */ - test(); - IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL ) - { - - reset_indices_enc_fx( st_fx->hBstr, st_fx->hBstr->nb_ind_tot ); - } - } - ELSE IF( st_fx->element_mode != EVS_MONO ) - { - st_fx->total_brate = total_brate_ref; - move32(); - } - - /*------------------------------------------------------------------------* - * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame) - *------------------------------------------------------------------------*/ - /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ - test(); - test(); - IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( st_fx->core_brate != FRAME_NO_DATA ) ) - { - IF( hDtxEnc != NULL ) - { - hDtxEnc->cnt_SID = 0; - move16(); - - /* change SID update rate */ - /* first SID update is only 8 (3) frames after the active speech end */ - IF( !st_fx->Opt_AMR_WB ) - { - hDtxEnc->max_SID = FIXED_SID_RATE; - move16(); - } - ELSE - { - hDtxEnc->max_SID = 3; - move16(); /* first SID update is only 3 frames after the active speech end */ - } - - if ( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) ) - { - hDtxEnc->max_SID = hDtxEnc->interval_SID; - move16(); /* change SID update rate */ - } - - hDtxEnc->cng_cnt = 0; - move16(); /* reset the counter of CNG frames for averaging */ - } - test(); - test(); - IF( GE_16( st_fx->active_cnt, CNG_TYPE_HO ) && st_fx->Opt_AMR_WB == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( EQ_16( st_fx->element_mode, IVAS_SCE ) ) - { - Word32 lp_thresh, fd_thresh; - test(); - IF( st_fx->Opt_DTX_ON && EQ_16( st_fx->dtx_sce_sba, 1 ) ) - { - lp_thresh = 327680; // 5 in Q16 - move32(); - fd_thresh = 131072; // 2 in Q16 - move32(); - } - ELSE - { - lp_thresh = 655360; // 10 in Q16 - move32(); - fd_thresh = 327680; // 5 in Q16 - move32(); - } - - /*More conservative selection of LP-CNG for SCE*/ - test(); - test(); - test(); - IF( st_fx->cng_type == LP_CNG && ( GT_32( st_fx->bckr_tilt_lt, lp_thresh ) ) ) - { - st_fx->cng_type = FD_CNG; - move16(); - } - ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( LT_32( st_fx->bckr_tilt_lt, fd_thresh ) ) && ( GT_32( st_fx->lp_noise_32fx, 67108864 /* 2 in Q24 */ ) ) ) - { - st_fx->cng_type = LP_CNG; - move16(); - } - } - ELSE - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->cng_type == LP_CNG ) && ( ( ( st_fx->input_bwidth == NB ) && GT_32( st_fx->bckr_tilt_lt, 589824 /*9.f Q16*/ ) ) || ( ( st_fx->input_bwidth > NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) ) - { - st_fx->cng_type = FD_CNG; - move16(); - } - ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( ( st_fx->input_bwidth == NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( ( st_fx->input_bwidth > NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) ) - { - st_fx->cng_type = LP_CNG; - move16(); - } - } - st_fx->last_total_brate_cng = -1; - move16(); - } - ELSE IF( st_fx->Opt_AMR_WB ) - { - st_fx->cng_type = LP_CNG; - move16(); - } - st_fx->active_cnt = add( st_fx->active_cnt, 1 ); - move16(); - st_fx->active_cnt = s_min( st_fx->active_cnt, 200 ); - move16(); - } - - /*------------------------------------------------------------------------* - * Update speech and background noise long-term energy - *------------------------------------------------------------------------*/ - IF( hDtxEnc != NULL ) - { - hDtxEnc->frame_ener_fx = L_deposit_l( 0 ); - move32(); - - IF( st_fx->Opt_DTX_ON ) - { - Q_speech2 = add( shl( Q_speech, 1 ), 7 ); - FOR( j = 0; j < 16; j++ ) - { - L_tmp = L_mult0( *speech, *speech ); /*2*Q_speech*/ - speech++; - FOR( i = 1; i < L_FRAME / 16; i++ ) - { - L_tmp = L_mac0_sat( L_tmp, *speech, *speech ); /*2*Q_speech*/ - speech++; - } - hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /* Q(-7) */ - move32(); - } - - /* Active speech (voiced) */ - - IF( EQ_16( st_fx->clas, VOICED_CLAS ) ) - { - alpha = ALPHA_ENER_SLOW_FX; /*Q15 */ - move16(); - if ( GT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx ) ) - { - alpha = ALPHA_ENER_FAST_FX; /*Q15 */ - move16(); - } - - /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub( hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx ); /*Q(-7)*/ - L_tmp = Mult_32_16( L_tmp, alpha ); /*Q(-7)*/ - hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /* Q(-7) */ - move32(); - - hDtxEnc->VarDTX_cnt_voiced = add( hDtxEnc->VarDTX_cnt_voiced, 1 ); - move16(); - - hDtxEnc->VarDTX_cnt_voiced = s_min( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ); - move16(); - } - /* Background noise */ - ELSE IF( !st_fx->Opt_AMR_WB ) - { - alpha = ALPHA_ENER_SLOW_FX; /*Q15*/ - move16(); - if ( LT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx ) ) - { - alpha = ALPHA_ENER_FAST_FX; /*Q15*/ - move16(); - } - - /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); /* Q(-7) */ - L_tmp = Mult_32_16( L_tmp, alpha ); /* Q(-7) */ - hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /* Q(-7) */ - move32(); - - hDtxEnc->VarDTX_cnt_noise = add( hDtxEnc->VarDTX_cnt_noise, 1 ); - move16(); - - hDtxEnc->VarDTX_cnt_noise = s_min( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ); - move16(); - } - } - } - - /* Update of the SID counter */ - update_SID_cnt_fx( hDtxEnc, st_fx->core_brate, st_fx->Opt_AMR_WB ); - - /* Update encoded bandwidth */ - test(); - test(); - IF( st_fx->Opt_DTX_ON && ( EQ_32( st_fx->core_brate, SID_2k40 ) || ( st_fx->core_brate == FRAME_NO_DATA ) ) ) - { - - st_fx->bwidth = st_fx->last_bwidth; - move16(); - test(); - IF( GT_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate_cng, -1 ) ) - { - st_fx->bwidth = st_fx->last_bwidth_cng; - move16(); - } - - test(); - test(); - IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( ( st_fx->bwidth == NB ) ) ) - { - st_fx->codec_mode = MODE1; - move16(); - reset_rf_indices_fx( st_fx ); - st_fx->Opt_RF_ON = 0; - move16(); - st_fx->rf_mode = 0; - move16(); - } - - test(); - IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) ) - { - reset_rf_indices_fx( st_fx ); - move16(); - st_fx->Opt_RF_ON = 0; - move16(); - st_fx->rf_mode = 0; - } - - /* Set and limit the encoded bandwidth */ - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - Word16 n, bits_frame_nominal; - - UWord16 lsb; - Word16 tmpbandwidthMin; - - Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - - FOR( n = 0; n < FRAME_SIZE_NB; n++ ) - { - IF( EQ_16( FrameSizeConfig[n].frame_bits, bits_frame_nominal ) ) - { - BREAK; - } - } - IF( EQ_16( n, FRAME_SIZE_NB ) ) - { - assert( !"Bitrate not supported: not part of EVS" ); - } - tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min; - move16(); - if ( EQ_16( st_fx->rf_mode, 1 ) ) - { - tmpbandwidthMin = WB; - move16(); - } - st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin ); - move16(); - } - } - - return; -} - -/*==================================================================================*/ -/* FUNCTION : dtx_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : Discontinuous transmission operation */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Encoder_State_Fx) st_fx : encoder state structure */ -/* _ (Word16) vad : vad flag Q0 */ -/* _ (Word16[]) speech_fx : Pointer to the speech frame qSpeech */ -/* _ (Word16) qSpeech : speech buffer qformat value */ -/* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ -/* _ (Encoder_State_Fx) st_fx : encoder state structure */ -/*----------------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ -void dtx_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag for DTX Q0*/ - const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ - Word16 Q_speech /* i : Q factor for speech */ - -) -{ - Word16 alpha, j, i, Q_speech2; - Word32 L_tmp; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; + test(); + IF( ( st_fx->element_mode == EVS_MONO && LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) ) || + ( st_fx->element_mode != EVS_MONO && LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) ) ) + { + flag_lp_noise = 1; + move16(); + } - Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; + total_brate_ref = st_fx->total_brate; + move32(); IF( st_fx->dtx_sce_sba != 0 ) { last_br_cng_flag = 1; last_br_flag = 1; - br_dtx_flag = 1; - move16(); move16(); move16(); } ELSE { - last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, ACELP_32k ) ); + test(); + test(); + test(); + last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || flag_lp_noise || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) ); - last_br_flag = LE_32( st_fx->last_total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate, ACELP_32k ) ); - br_dtx_flag = 0; - move16(); + test(); + test(); + test(); + test(); + last_br_flag = ( st_fx->element_mode == EVS_MONO && LE_32( st_fx->last_total_brate, MAX_BRATE_DTX_EVS ) ) || + ( st_fx->element_mode != EVS_MONO && LE_32( last_ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || + flag_lp_noise; } + /* Initialization */ IF( st_fx->ini_frame == 0 ) { @@ -655,13 +126,20 @@ void dtx_fx( st_fx->cng_type = FD_CNG; move16(); + test(); - IF( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && EQ_16( st_fx->element_mode, IVAS_SCE ) && EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + test(); + test(); + if ( ( EQ_16( st_fx->codec_mode, MODE1 ) || st_fx->Opt_AMR_WB ) && NE_16( st_fx->element_mode, IVAS_SCE ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { st_fx->cng_type = LP_CNG; move16(); } } + + test(); + test(); + test(); test(); test(); IF( st_fx->Opt_DTX_ON && vad == 0 && @@ -678,12 +156,14 @@ void dtx_fx( { st_fx->total_brate = st_fx->last_total_brate_cng; move32(); + test(); - IF( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) + if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) { st_fx->Opt_SC_VBR = 0; move16(); } + st_fx->rf_mode = st_fx->last_rf_mode_cng; move16(); st_fx->bwidth = st_fx->last_bwidth_cng; @@ -691,15 +171,16 @@ void dtx_fx( st_fx->codec_mode = st_fx->last_codec_mode_cng; move16(); } + test(); test(); IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag ) - { st_fx->total_brate = st_fx->last_total_brate; move32(); + test(); - IF( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) + if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) ) { st_fx->Opt_SC_VBR = 0; move16(); @@ -710,16 +191,18 @@ void dtx_fx( test(); test(); test(); - IF( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && NE_16( st_fx->bwidth, NB ) ) + if ( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && EQ_32( st_fx->total_brate, ACELP_13k20 ) && ( st_fx->bwidth != NB ) ) { st_fx->Opt_RF_ON = 1; move16(); } + st_fx->rf_mode = st_fx->Opt_RF_ON; move16(); st_fx->bwidth = st_fx->last_bwidth; move32(); - IF( ( st_fx->element_mode > EVS_MONO ) ) + + IF( st_fx->element_mode > EVS_MONO ) { st_fx->codec_mode = MODE1; move16(); @@ -727,6 +210,7 @@ void dtx_fx( ELSE { st_fx->codec_mode = get_codec_mode( st_fx->total_brate ); + move16(); } } } @@ -735,11 +219,20 @@ void dtx_fx( * Select SID or FRAME_NO_DATA frame if DTX is enabled *------------------------------------------------------------------------*/ - if ( st_fx->dtx_sce_sba == 0 ) + br_dtx_flag = 1; + move16(); + + IF( st_fx->dtx_sce_sba == 0 ) { - br_dtx_flag = LE_32( st_fx->total_brate, ACELP_24k40 ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || - EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st_fx->element_brate, IVAS_64k ) || LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) ) ); + test(); + test(); + test(); + test(); + br_dtx_flag = ( ( st_fx->element_mode == EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) || + ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) || + flag_lp_noise; } + test(); test(); test(); @@ -756,17 +249,17 @@ void dtx_fx( IF( st_fx->Opt_AMR_WB ) { st_fx->last_total_brate_cng = -1; - st_fx->last_rf_mode_cng = st_fx->rf_mode; - move32(); move16(); } ELSE { st_fx->last_total_brate_cng = st_fx->total_brate; + move16(); st_fx->last_bwidth_cng = st_fx->bwidth; + move16(); st_fx->last_codec_mode_cng = st_fx->codec_mode; - move32(); move16(); + st_fx->last_rf_mode_cng = st_fx->rf_mode; move16(); } @@ -800,16 +293,37 @@ void dtx_fx( move32(); } + test(); + test(); + IF( ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) ) + { + st_fx->cng_type = FD_CNG; + move16(); + + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->element_mode == EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_48k ) || EQ_32( st_fx->total_brate, HQ_96k ) || EQ_32( st_fx->total_brate, HQ_128k ) ) ) + { + st_fx->codec_mode = MODE2; + move16(); + } + } + ELSE { test(); test(); test(); test(); - IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, ACELP_24k40 ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( st_fx->total_brate, ACELP_32k ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */ + IF( ( EQ_16( st_fx->cng_type, FD_CNG ) && ( LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) || ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) /* at highest bitrates, use exclusively LP_CNG */ { test(); test(); - IF( EQ_16( st_fx->element_mode, EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) ) + test(); + IF( ( st_fx->element_mode == EVS_MONO ) && ( EQ_32( st_fx->total_brate, ACELP_9k60 ) || EQ_32( st_fx->total_brate, ACELP_16k40 ) || EQ_32( st_fx->total_brate, ACELP_24k40 ) ) ) { st_fx->codec_mode = MODE2; move16(); @@ -819,7 +333,7 @@ void dtx_fx( { st_fx->cng_type = LP_CNG; move16(); - IF( st_fx->codec_mode == MODE2 ) + if ( EQ_16( st_fx->codec_mode, MODE2 ) ) { hTdCngEnc->lp_cng_mode2 = 1; move16(); @@ -830,16 +344,23 @@ void dtx_fx( } /* reset the bitstream (IVAS format signalling was already written) */ + test(); IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL ) { + reset_indices_enc_fx( st_fx->hBstr, st_fx->hBstr->nb_ind_tot ); } } + ELSE IF( st_fx->element_mode != EVS_MONO ) + { + st_fx->total_brate = total_brate_ref; + move32(); + } /*------------------------------------------------------------------------* * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame) *------------------------------------------------------------------------*/ - /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ + test(); test(); IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( st_fx->core_brate != FRAME_NO_DATA ) ) @@ -862,7 +383,7 @@ void dtx_fx( move16(); /* first SID update is only 3 frames after the active speech end */ } - IF( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) ) + if ( LT_16( hDtxEnc->interval_SID, hDtxEnc->max_SID ) ) { hDtxEnc->max_SID = hDtxEnc->interval_SID; move16(); /* change SID update rate */ @@ -872,10 +393,42 @@ void dtx_fx( move16(); /* reset the counter of CNG frames for averaging */ } test(); + test(); IF( GE_16( st_fx->active_cnt, CNG_TYPE_HO ) && st_fx->Opt_AMR_WB == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( EQ_16( st_fx->element_mode, IVAS_SCE ) ) { + Word32 lp_thresh, fd_thresh; + test(); + IF( st_fx->Opt_DTX_ON && EQ_16( st_fx->dtx_sce_sba, 1 ) ) + { + lp_thresh = 327680; // 5 in Q16 + move32(); + fd_thresh = 131072; // 2 in Q16 + move32(); + } + ELSE + { + lp_thresh = 655360; // 10 in Q16 + move32(); + fd_thresh = 327680; // 5 in Q16 + move32(); + } + + /*More conservative selection of LP-CNG for SCE*/ + test(); + test(); + test(); + IF( st_fx->cng_type == LP_CNG && ( GT_32( st_fx->bckr_tilt_lt, lp_thresh ) ) ) + { + st_fx->cng_type = FD_CNG; + move16(); + } + ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( LT_32( st_fx->bckr_tilt_lt, fd_thresh ) ) && ( GT_32( st_fx->lp_noise_32fx, 67108864 /* 2 in Q24 */ ) ) ) + { + st_fx->cng_type = LP_CNG; + move16(); + } } ELSE { @@ -887,34 +440,41 @@ void dtx_fx( test(); test(); test(); - IF( EQ_16( st_fx->cng_type, LP_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 589824l /*9.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) ) + IF( ( st_fx->cng_type == LP_CNG ) && ( ( ( st_fx->input_bwidth == NB ) && GT_32( st_fx->bckr_tilt_lt, 589824 /*9.f Q16*/ ) ) || ( ( st_fx->input_bwidth > NB ) && GT_32( st_fx->bckr_tilt_lt, 2949120l /*45.f Q16*/ ) ) ) ) { st_fx->cng_type = FD_CNG; move16(); } - ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( EQ_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( GT_16( st_fx->input_bwidth, NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) ) + ELSE IF( EQ_16( st_fx->cng_type, FD_CNG ) && ( ( ( st_fx->input_bwidth == NB ) && LT_32( st_fx->bckr_tilt_lt, 131072l /*2.f Q16*/ ) ) || ( ( st_fx->input_bwidth > NB ) && LT_32( st_fx->bckr_tilt_lt, 655360l /*10.f Q16*/ ) ) ) ) { st_fx->cng_type = LP_CNG; move16(); } } + st_fx->last_total_brate_cng = -1; + move16(); } ELSE IF( st_fx->Opt_AMR_WB ) { st_fx->cng_type = LP_CNG; move16(); } + st_fx->active_cnt = add( st_fx->active_cnt, 1 ); + move16(); st_fx->active_cnt = s_min( st_fx->active_cnt, 200 ); + move16(); } /*------------------------------------------------------------------------* * Update speech and background noise long-term energy *------------------------------------------------------------------------*/ + IF( hDtxEnc != NULL ) { hDtxEnc->frame_ener_fx = L_deposit_l( 0 ); + move32(); IF( st_fx->Opt_DTX_ON ) { @@ -928,14 +488,14 @@ void dtx_fx( L_tmp = L_mac0_sat( L_tmp, *speech, *speech ); /*2*Q_speech*/ speech++; } - hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /*Q(-7) */ + hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /* Q(-7) */ + move32(); } /* Active speech (voiced) */ - IF( EQ_16( st_fx->clas, VOICED_CLAS ) ) { - alpha = ALPHA_ENER_SLOW_FX; + alpha = ALPHA_ENER_SLOW_FX; /*Q15 */ move16(); if ( GT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_voiced_fx ) ) { @@ -946,32 +506,37 @@ void dtx_fx( /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ L_tmp = L_sub( hDtxEnc->lt_ener_voiced_fx, hDtxEnc->frame_ener_fx ); /*Q(-7)*/ L_tmp = Mult_32_16( L_tmp, alpha ); /*Q(-7)*/ - hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /*Q(-7)*/ + hDtxEnc->lt_ener_voiced_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /* Q(-7) */ + move32(); hDtxEnc->VarDTX_cnt_voiced = add( hDtxEnc->VarDTX_cnt_voiced, 1 ); + move16(); hDtxEnc->VarDTX_cnt_voiced = s_min( hDtxEnc->VarDTX_cnt_voiced, MIN_CNT ); + move16(); } /* Background noise */ ELSE IF( !st_fx->Opt_AMR_WB ) { - alpha = ALPHA_ENER_SLOW_FX; /*Q15 */ + alpha = ALPHA_ENER_SLOW_FX; /*Q15*/ move16(); if ( LT_32( hDtxEnc->frame_ener_fx, hDtxEnc->lt_ener_noise_fx ) ) { - alpha = ALPHA_ENER_FAST_FX; /*Q15 */ + alpha = ALPHA_ENER_FAST_FX; /*Q15*/ move16(); } /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); /*Q(-7)*/ - L_tmp = Mult_32_16( L_tmp, alpha ); /*Q(-7)*/ - hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /*Q(-7)*/ + L_tmp = L_sub( hDtxEnc->lt_ener_noise_fx, hDtxEnc->frame_ener_fx ); /* Q(-7) */ + L_tmp = Mult_32_16( L_tmp, alpha ); /* Q(-7) */ + hDtxEnc->lt_ener_noise_fx = L_add( L_tmp, hDtxEnc->frame_ener_fx ); /* Q(-7) */ move32(); hDtxEnc->VarDTX_cnt_noise = add( hDtxEnc->VarDTX_cnt_noise, 1 ); + move16(); hDtxEnc->VarDTX_cnt_noise = s_min( hDtxEnc->VarDTX_cnt_noise, MIN_CNT ); + move16(); } } } @@ -982,9 +547,8 @@ void dtx_fx( /* Update encoded bandwidth */ test(); test(); - IF( st_fx->Opt_DTX_ON && ( st_fx->core_brate == SID_2k40 || st_fx->core_brate == FRAME_NO_DATA ) ) + IF( st_fx->Opt_DTX_ON && ( EQ_32( st_fx->core_brate, SID_2k40 ) || ( st_fx->core_brate == FRAME_NO_DATA ) ) ) { - st_fx->bwidth = st_fx->last_bwidth; move16(); test(); @@ -996,7 +560,7 @@ void dtx_fx( test(); test(); - IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( EQ_16( st_fx->bwidth, NB ) ) ) + IF( st_fx->Opt_RF_ON && ( EQ_32( st_fx->total_brate, ACELP_13k20 ) ) && ( ( st_fx->bwidth == NB ) ) ) { st_fx->codec_mode = MODE1; move16(); @@ -1007,7 +571,6 @@ void dtx_fx( move16(); } - test(); test(); IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) ) { @@ -1016,14 +579,12 @@ void dtx_fx( st_fx->Opt_RF_ON = 0; move16(); st_fx->rf_mode = 0; - move16(); } /* Set and limit the encoded bandwidth */ IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { Word16 n, bits_frame_nominal; - UWord16 lsb; Word16 tmpbandwidthMin; @@ -1041,18 +602,25 @@ void dtx_fx( { assert( !"Bitrate not supported: not part of EVS" ); } + tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min; + move16(); + if ( EQ_16( st_fx->rf_mode, 1 ) ) { tmpbandwidthMin = WB; + move16(); } + st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin ); + move16(); } } return; } + /*---------------------------------------------------------------------* * update_SID_cnt() * @@ -1201,6 +769,12 @@ static void update_SID_cnt_fx( } +/*-------------------------------------------------------------------* + * dtx_hangover_control() + * + * + *-------------------------------------------------------------------*/ + void dtx_hangover_control_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 lsp_new_fx[M] /* i : current frame LSPs Q15*/ @@ -1480,6 +1054,7 @@ void dtx_hangover_control_fx( return; } + /*-------------------------------------------------------------------* * td_cng_enc_init_fx() * @@ -1492,96 +1067,6 @@ void td_cng_enc_init_fx( const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ ) { - - hTdCngEnc->cng_seed = RANDOM_INITSEED; - hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; - hTdCngEnc->cng_ener_seed1 = RANDOM_INITSEED; - hTdCngEnc->lp_ener_fx = 0; - hTdCngEnc->old_enr_index = -1; - hTdCngEnc->Enew_fx = 0; - - hTdCngEnc->lp_sp_enr_fx = 0; - hTdCngEnc->last_allow_cn_step = 0; - move16(); - move32(); - move16(); - move16(); - move32(); - move16(); - move16(); - - IF( Opt_DTX_ON ) - { - hTdCngEnc->cng_hist_ptr = -1; - move16(); - set16_fx( hTdCngEnc->cng_lsp_hist_fx, 0, DTX_HIST_SIZE * M ); - set16_fx( hTdCngEnc->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); - - hTdCngEnc->ho_hist_ptr = -1; - move16(); - hTdCngEnc->ho_sid_bw = L_deposit_l( 0 ); - set16_fx( hTdCngEnc->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); - set32_fx( hTdCngEnc->ho_ener_hist_fx, 0, HO_HIST_SIZE ); - set32_fx( hTdCngEnc->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); - hTdCngEnc->ho_hist_size = 0; - move16(); - hTdCngEnc->act_cnt = 0; - move16(); - } - - set16_fx( hTdCngEnc->ho_16k_lsp, 0, HO_HIST_SIZE ); - hTdCngEnc->act_cnt2 = 0; - hTdCngEnc->num_ho = 0; - move16(); - move16(); - - hTdCngEnc->ho_circ_ptr = -1; - move16(); - set16_fx( hTdCngEnc->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); - set32_fx( hTdCngEnc->ho_ener_circ_fx, 0, HO_HIST_SIZE ); - set32_fx( hTdCngEnc->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); - hTdCngEnc->ho_circ_size = 0; - hTdCngEnc->burst_ho_cnt = 0; - move16(); - move16(); - - hTdCngEnc->cng_buf_cnt = 0; - - - set32_fx( hTdCngEnc->lp_env_fx, 0, 20 ); - set32_fx( hTdCngEnc->cng_res_env_fx, 0, 20 * 8 ); - set16_fx( hTdCngEnc->exc_mem_fx, 0, 24 ); - set16_fx( hTdCngEnc->exc_mem1_fx, 0, 30 ); - set16_fx( hTdCngEnc->exc_mem2_fx, 0, 30 ); - set32_fx( hTdCngEnc->old_env_fx, 0, NUM_ENV_CNG ); - - /* SWB CNG/DTX */ - hTdCngEnc->last_wb_cng_ener_fx = -1541; /* Q8 */ - move16(); - hTdCngEnc->last_shb_cng_ener_fx = -1541; /* Q8 */ - move16(); - hTdCngEnc->mov_wb_cng_ener_fx = -1541; /* Q8 */ - move16(); - hTdCngEnc->mov_shb_cng_ener_fx = -1541; /* Q8 */ - move16(); - hTdCngEnc->shb_cng_ini_cnt = 1; - move16(); - hTdCngEnc->shb_NO_DATA_cnt = 0; - move16(); - hTdCngEnc->last_SID_bwidth = s_min( max_bwidth, SWB ); - hTdCngEnc->last_vad = 0; - move16(); - - return; -} - -void td_cng_enc_init_ivas_fx( - TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ - const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation Q0*/ - const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ -) -{ - hTdCngEnc->cng_seed = RANDOM_INITSEED; move16(); hTdCngEnc->cng_ener_seed = RANDOM_INITSEED; @@ -1672,6 +1157,7 @@ void td_cng_enc_init_ivas_fx( return; } + /*-------------------------------------------------------------------* * dtx_enc_init_fx() * @@ -1734,5 +1220,6 @@ void dtx_enc_init_fx( move16(); } } + return; } diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index ba09a659407b4a72e66fd6d7d7d62fca96c19229..0f4e772534fcb5eb5a9ff452ca4899210a21de8e 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -615,7 +615,7 @@ Word16 E_ACELP_xy1_corr_fx( /* Note: shl works as shl or shr. */ exp_tmp = sub( exp_tmp, 1 ); BASOP_SATURATE_WARNING_OFF_EVS - tmp = round_fx_sat( L_shl_sat( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp ) ); /*Q14*/ + tmp = round_fx_sat( L_shl_sat( Mpy_32_16_1( ACELP_GAINS_CONST_Q31, tmp ), exp_tmp ) ); /*Q14*/ BASOP_SATURATE_WARNING_ON_EVS gain = s_min( gain, tmp ); /*Q14*/ @@ -997,7 +997,10 @@ void E_ACELP_corrmatrix_fx( p3 = &rrixiy[2][pos]; /* Q9 */ p2 = &rrixiy[1][pos]; p1 = &rrixiy[0][pos]; - p0 = &rrixiy[3][pos - 16]; + p0 = &rrixiy[3][pos]; + /* decrement pointer instead of indexing the array to avoid CLANG Usan complaint */ + /* for last loop iteration, this points to rrixiy[3][-1], but is not actually accessed in later loop (k = 15 then, so inner loop will not run) */ + p0 -= 16; cor = L_deposit_h( 0 ); ptr_h1 = h; /*Q12*/ diff --git a/lib_enc/enc_acelp_tcx_main_fx.c b/lib_enc/enc_acelp_tcx_main_fx.c index da8443f06c0045c58772ae2284c051a81a7e5126..b3bd7d112b850a0f708343296bd577beb645013b 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -63,15 +63,15 @@ void enc_acelp_tcx_main_fx( { core_encode_twodiv_fx( new_samples, st, st->coder_type, Aw, vad_hover_flag, Q_new, shift ); } + /*-----------------------------------------------------------------* * Apply non linearity to the SHB excitation *-----------------------------------------------------------------*/ - test(); IF( EQ_16( st->core, ACELP_CORE ) && st->igf != 0 ) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame ); + non_linearity_fx( EVS_MONO, ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame ); /* update the old BWE exe memory */ Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/ diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 95104c76ca247bbd3f99052eae64f5cee21b4971..a5b11f3b06ca27d9da208a793c7c7d8a54d0d14c 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -292,9 +292,8 @@ static void E_ACELP_1pulse_searchx_fx( /*alp0 = *alp + R[0]; INDIRECT(1);*/ ps0 = *ps; /* Qdn */ move16(); - alp0 = L_deposit_h( *alp ); /* Q22 */ - alp0 = L_mac( alp0, R[0], sign_val_1 ); /* Qalp = (Q_R=Q_cor)*Q_signval */ - + alp0 = L_deposit_h( *alp ); /* Q22 */ + alp0 = L_mac_sat( alp0, R[0], sign_val_1 ); /* Qalp = (Q_R=Q_cor)*Q_signval */ /* Ensure that in the loop below s > 0 in the first iteration, the actual values do not matter. */ move16(); move16(); diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index f68b94daf048b36d3bc6bced9833598f64a1c11a..e31578c7a3993e639d5bbcce12002687d1f863d4 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -29,8 +29,8 @@ void encod_amr_wb_fx( Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6*/ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain Q0*/ const Word16 *speech16k_fx, /* i : input speech @16kHz Qx*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, + const Word16 Q_new ) { Word16 xn[L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ @@ -175,7 +175,7 @@ void encod_amr_wb_fx( *-----------------------------------------------------------------*/ inov_encode_fx( st, st->core_brate, 1, L_FRAME, st->last_L_frame, -1, -1, 0, i_subfr, -1, p_Aq, gain_pit, cn, - exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, L_SUBFR, shift ); + exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, L_SUBFR, shift, 0 ); /*-----------------------------------------------------------------* * Gain encoding diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index 8c53a5d12204779630e1f0bc893a2b76dd8311fd..2e1a5019b0358a1056cd07e600984cb0596e86a2 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -5,6 +5,7 @@ #include #include #include "options.h" +#include "stl.h" #include "cnst.h" #include "rom_com.h" #include "rom_enc.h" @@ -253,7 +254,7 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ { Word16 corr_v[32 + 2 * L_INTERPOL1 + 1]; Word16 cor_max, max, temp; - Word16 *corr; + Word16 corr_idx; Word16 i, fraction, frac1, frac2, step; Word16 t0, t_min, t_max; @@ -269,27 +270,29 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ move16(); move16(); - /* allocate memory to normalized correlation vector */ - corr = &corr_v[negate( t_min )]; /* corr[t_min..t_max] */ + corr_idx = negate( t_min ); /* Compute normalized correlation between target and filtered excitation */ E_GAIN_norm_corr_fx( exc, xn, h, t_min, t_max, corr_v, L_subfr ); /* find integer pitch */ - max = corr[t0_min]; /*(Q15+(Q_new+shift-1)+scale)*/ + max = corr_v[add( t0_min, corr_idx )]; /*(Q15+(Q_new+shift-1)+scale)*/ move16(); t0 = t0_min; /*Q0*/ move16(); FOR( i = t0_min + 1; i <= t0_max; i++ ) { + Word16 corr_tmp; + + corr_tmp = corr_v[add( corr_idx, i )]; BASOP_SATURATE_WARNING_OFF_EVS; - if ( GE_16( corr[i], max ) ) + if ( GE_16( corr_tmp, max ) ) { t0 = i; move16(); } - max = s_max( max, corr[i] ); + max = s_max( max, corr_tmp ); BASOP_SATURATE_WARNING_ON_EVS; } @@ -354,15 +357,16 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ } assert( frac1 <= 0 && frac2 >= 0 && frac2 > frac1 ); + corr_idx = add( corr_idx, t0 ); IF( EQ_16( pit_res_max, 6 ) ) { - cor_max = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ - fraction = frac1; /*Q0*/ + cor_max = E_GAIN_norm_corr_interpolate6_fx( &corr_v[corr_idx], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ + fraction = frac1; /*Q0*/ move16(); FOR( i = ( frac1 + step ); i <= frac2; i += step ) { - temp = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ + temp = E_GAIN_norm_corr_interpolate6_fx( &corr_v[corr_idx], i ); /*(Q15+(Q_new+shift-1)+scale)*/ IF( GT_16( temp, cor_max ) ) { cor_max = temp; /*(Q15+(Q_new+shift-1)+scale)*/ @@ -374,13 +378,13 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ } ELSE { - cor_max = E_GAIN_norm_corr_interpolate_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ - fraction = frac1; /*Q0*/ + cor_max = E_GAIN_norm_corr_interpolate_fx( &corr_v[corr_idx], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ + fraction = frac1; /*Q0*/ move16(); FOR( i = ( frac1 + step ); i <= frac2; i += step ) { - temp = E_GAIN_norm_corr_interpolate_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ + temp = E_GAIN_norm_corr_interpolate_fx( &corr_v[corr_idx], i ); /*(Q15+(Q_new+shift-1)+scale)*/ IF( GT_16( temp, cor_max ) ) { cor_max = temp; /*(Q15+(Q_new+shift-1)+scale)*/ diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index bfe50a588edf8c5f1fe5f0313c815d22fc7b6f77..5e1a43a8cde4dcc1150fd16238950a50c4731080 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -80,22 +80,23 @@ static void rem_offset( void encod_gen_voic_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Q0*/ + const Word16 speech_fx[], /* i : input speech Q0 / Qnew -1 */ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* i/o: core synthesis Q_new*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ + Word16 *syn_fx, /* i/o: core synthesis Qnew / Q_new - 1*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0 / Q_new*/ + Word16 *exc2_fx, /* i/o: current enhanced excitation Q0 / Q_new*/ Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 shift, - Word16 Q_new ) + const Word16 shift, /* i : Shift needed to obtain 12 bits vectors */ + const Word16 Q_new /* i : Scaling factor */ +) { Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ @@ -109,8 +110,8 @@ void encod_gen_voic_fx( move16(); Word16 voice_fac_fx; /* Voicing factor */ Word32 gain_code_fx = 0; /* Gain of code */ - move32(); Word16 gain_inov_fx = 0; /* inovation gain */ + move32(); move16(); Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ @@ -141,9 +142,9 @@ void encod_gen_voic_fx( Word16 shift_wsp; Word16 harm_flag_acelp; Word16 lp_select, lp_flag, L_frame; + Word16 q_h1; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; /*------------------------------------------------------------------* @@ -162,7 +163,6 @@ void encod_gen_voic_fx( L_frame = st_fx->L_frame; move16(); - IF( EQ_16( L_frame, L_FRAME ) ) { T0_max_fx = PIT_MAX; @@ -183,14 +183,19 @@ void encod_gen_voic_fx( *unbits_fx = 0; move16(); - p_Aw_fx = Aw_fx; /* Q12 */ - p_Aq_fx = Aq_fx; /* Q12 */ - pt_pitch_fx = pitch_buf_fx; /* Q6 */ + p_Aw_fx = Aw_fx; /*Q12*/ + p_Aq_fx = Aq_fx; /*Q12*/ + pt_pitch_fx = pitch_buf_fx; /*Q6*/ gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); shift_wsp = add( Q_new, shift ); + test(); + if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_32( st_fx->element_mode, EVS_MONO ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } /* set and write harmonicity flag */ harm_flag_acelp = 0; @@ -224,386 +229,39 @@ void encod_gen_voic_fx( Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/ - find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); /*Q11*/ - Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - *----------------------------------------------------------------*/ - - *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ - - - tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - *-----------------------------------------------------------------*/ - - clip_gain_fx = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr_fx, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); - - if ( EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( st_fx->element_mode == EVS_MONO ) { - /* in case of AVQ inactive, limit the gain to 0.65 */ - clip_gain_fx = 2; - move16(); - } + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); /*Q11*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/ - lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->coder_type, i_subfr_fx, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); - - IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) - { - push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ - hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ - - /*-----------------------------------------------------------------* - * Transform domain contribution encoding - active frames - *-----------------------------------------------------------------*/ - - test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) - { - transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, - xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); - } - - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - - inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame, - st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, - gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - - IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - gain_enc_lbr_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->coder_type, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx, L_SUBFR, - st_fx->element_mode ); - } - ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) - { - gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr_fx, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, shift_wsp ); + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); } ELSE { - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); - } - IF( st_fx->Opt_SC_VBR ) - { - if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) ) - { - /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ - st_fx->clip_var_fx[1] = gain_pit_fx; /*Q14*/ - move16(); - } - } - gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); - - Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_sat( Lgcode ); /*Q0*/ - hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */ - move16(); - - /*-----------------------------------------------------------------* - * Transform domain contribution encoding - inactive frames - *-----------------------------------------------------------------*/ + find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) - { - transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, - Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); - } - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ + q_h1 = sub( 14, norm_s( h1_fx[0] ) ); + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ + Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); /*Q10*/ - Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15+shift*/ - Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ ); /* Q_new-1+shift+14+1 */ - Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*Q14*/ ); /* Q_new-1+shift+14+1 */ - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* 15 + Q_new */ - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ - move16(); - IF( gain_preQ_fx != 0 ) - { - tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); - - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* Contribution from AVQ layer */ - Ltmp1 = L_mult_sat( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ - - /* Compute exc2 */ - Ltmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /* Q16 */ - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); /* Q0 */ - move16(); - - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ - Ltmp = L_shl( Ltmp, 5 ); /* Q15 */ - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); /* Q0 */ - } - } - ELSE - { - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ + /* scaling of xn[] to limit dynamic at 12 bits */ + Scale_sig( xn_fx, L_SUBFR, shift ); - FOR( i = 0; i < L_SUBFR; i++ ) + test(); + test(); + IF( Es_pred_fx < 0 && LE_16( i_subfr_fx, L_SUBFR ) && NE_16( st_fx->last_core, ACELP_CORE ) ) { - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ - Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 */ - Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp ); /* Q0 */ + /* During core transition, when the temporal correlation is non existent */ + rem_offset( xn_fx, xn_fx, L_SUBFR ); + rem_offset( cn_fx, cn_fx, L_SUBFR ); } } - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q10, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); - - p_Aw_fx += ( M + 1 ); - p_Aq_fx += ( M + 1 ); - pt_pitch_fx++; - } - - /* write reserved bits */ - WHILE( unbits_PI_fx > 0 ) - { - i = s_min( unbits_PI_fx, 16 ); - push_indice( hBstr, IND_UNUSED, 0, i ); - unbits_PI_fx -= i; - } - IF( st_fx->Opt_SC_VBR ) - { - /* SC-VBR */ - hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */ - move16(); - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ - move16(); - } - - return; -} - - -void encod_gen_voic_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Qnew -1 */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* i/o: core synthesis Q_new - 1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q_new*/ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ - Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 shift, - Word16 Q_new ) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1_fx[L_SUBFR] = { 0 }; /* Filtered adaptive excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit_fx = 0; /* Pitch gain */ - move16(); - Word16 voice_fac_fx; /* Voicing factor */ - Word32 gain_code_fx = 0; /* Gain of code */ - Word16 gain_inov_fx = 0; /* inovation gain */ - move32(); - move16(); - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ - Word16 i, i_subfr_fx; /* tmp variables */ - Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ - move16(); - move16(); - Word16 T0_min_fx, T0_max_fx; /* pitch variables */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain_fx; /* LSF clip gain */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ - Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - move16(); - move16(); - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ - Word32 norm_gain_code_fx = 0; - move16(); - move32(); - Word16 pitch_limit_flag; - Word16 gcode16; - Word32 Ltmp; - Word32 Ltmp1; - Word32 Lgcode; - Word16 tmp1_fx; - Word16 shift_wsp; - Word16 harm_flag_acelp; - Word16 lp_select, lp_flag, L_frame; - Word16 q_h1; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - gain_pit_fx = 0; - move16(); - gain_code_fx = L_deposit_l( 0 ); - gain_preQ_fx = 0; - move16(); - unbits_PI_fx = 0; - move16(); - error_fx = 0; - move16(); - L_frame = st_fx->L_frame; - move16(); - - IF( EQ_16( L_frame, L_FRAME ) ) - { - T0_max_fx = PIT_MAX; - move16(); - T0_min_fx = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max_fx = PIT16k_MAX; - move16(); - T0_min_fx = PIT16k_MIN; - move16(); - } - lp_flag = st_fx->acelp_cfg.ltf_mode; - move16(); - - *unbits_fx = 0; - move16(); - - p_Aw_fx = Aw_fx; /*Q12*/ - p_Aq_fx = Aq_fx; /*Q12*/ - pt_pitch_fx = pitch_buf_fx; /*Q6*/ - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); - - shift_wsp = add( Q_new, shift ); - if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) - { - shift_wsp = sub( shift_wsp, 1 ); - } - - /* set and write harmonicity flag */ - harm_flag_acelp = 0; - move16(); - - test(); - test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) - { - if ( GT_16( st_fx->last_harm_flag_acelp, 2 ) ) - { - harm_flag_acelp = 1; - move16(); - } - - push_indice( hBstr, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); - } - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) - { - - /*----------------------------------------------------------------* - * Find the the excitation search target "xn" and innovation - * target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - - Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/ - - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - - q_h1 = sub( 14, norm_s( h1_fx[0] ) ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ - Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); - test(); - test(); - IF( Es_pred_fx < 0 && LE_16( i_subfr_fx, L_SUBFR ) && NE_16( st_fx->last_core, ACELP_CORE ) ) - { - /* During core transition, when the temporal correlation is non existent */ - rem_offset( xn_fx, xn_fx, L_SUBFR ); - rem_offset( cn_fx, cn_fx, L_SUBFR ); - } - /*----------------------------------------------------------------* * Close-loop pitch search and quantization *----------------------------------------------------------------*/ @@ -612,13 +270,20 @@ void encod_gen_voic_ivas_fx( L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ move16(); - tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); + tbe_celp_exc_fx( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ - pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( st_fx->element_mode == EVS_MONO ) + { + pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4_ivas_fx( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure @@ -645,6 +310,9 @@ void encod_gen_voic_ivas_fx( push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); } + /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ + st_fx->hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, st_fx->hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ + /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames *-----------------------------------------------------------------*/ @@ -652,17 +320,16 @@ void encod_gen_voic_ivas_fx( test(); IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) { - transf_cdbk_enc_ivas_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, - xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); + transf_cdbk_enc_fx( st_fx, harm_flag_acelp, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, + xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); } /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ - inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame, - st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, - gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift, Q_new ); + inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, i_subfr_fx, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, L_SUBFR, shift, Q_new ); /*-----------------------------------------------------------------* * Gain encoding @@ -698,7 +365,14 @@ void encod_gen_voic_ivas_fx( Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); - hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); /* Q15 */ + IF( st_fx->element_mode == EVS_MONO ) + { + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */ + } + ELSE + { + hLPDmem->tilt_code = est_tilt_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR ); /* Q15 */ + } move16(); /*-----------------------------------------------------------------* @@ -708,38 +382,53 @@ void encod_gen_voic_ivas_fx( test(); IF( !st_fx->inactive_coder_type_flag && EQ_16( st_fx->coder_type, INACTIVE ) ) { - transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, - Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); + transf_cdbk_enc_fx( st_fx, 0, i_subfr_fx, cn_fx, exc_fx, p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, + Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift ); } /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ - /*At this point - xn has to be in Qnew - yn has to be in Qnew - y2_fx has to be in Q9 - gcode16 in Q_new - gain_pit_fx in Q14 - */ - Scale_sig( xn_fx, L_SUBFR, 1 ); - Scale_sig( y1_fx, L_SUBFR, 1 ); - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); - Ltmp = L_negate( Ltmp ); - Word32 Ltmp2 = L_mult0( xn_fx[L_SUBFR - 1], 16384 ); - Ltmp = L_add( Ltmp, Ltmp2 ); - Word32 Ltmp3 = L_mult0( y1_fx[L_SUBFR - 1], gain_pit_fx ); - Ltmp = L_sub( Ltmp, Ltmp3 ); - - /*Ltmp is in Q14 + Qnew here - We need memWo in Qnew -1 */ - - Ltmp = L_shl( Ltmp, sub( 1, shift ) ); // Q14 + Qnew + 1 - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ - move16(); + IF( st_fx->element_mode == EVS_MONO ) + { + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); /*Q10*/ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15+shift*/ + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ ); /* Q_new-1+shift+14+1 */ + Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*Q14*/ ); /* Q_new-1+shift+14+1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* 15 + Q_new */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + } + ELSE + { + /*At this point + xn has to be in Qnew + yn has to be in Qnew + y2_fx has to be in Q9 + gcode16 in Q_new + gain_pit_fx in Q14 + */ + Scale_sig( xn_fx, L_SUBFR, 1 ); + Scale_sig( y1_fx, L_SUBFR, 1 ); + /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ + Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); + Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_negate( Ltmp ); + Word32 Ltmp2 = L_mult0( xn_fx[L_SUBFR - 1], 16384 ); + Ltmp = L_add( Ltmp, Ltmp2 ); + Word32 Ltmp3 = L_mult0( y1_fx[L_SUBFR - 1], gain_pit_fx ); + Ltmp = L_sub( Ltmp, Ltmp3 ); + + /*Ltmp is in Q14 + Qnew here + We need memWo in Qnew -1 */ + + Ltmp = L_shl( Ltmp, sub( 1, shift ) ); // Q14 + Qnew + 1 + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + move16(); + } + IF( gain_preQ_fx != 0 ) { tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); @@ -756,10 +445,10 @@ void encod_gen_voic_ivas_fx( move16(); /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ - Ltmp = L_shl( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ - Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1 */ /* saturation can occur here Q16*/ + Ltmp = L_mult( gcode16, code_fx[i] ); /*Q10 / Qnew + 9 + 1 */ + Ltmp = L_shl( Ltmp, 5 ); /*Q15 / Qnew + 9+ 1+5 */ + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Q15 / Qnew + 14 + 1*/ + Ltmp = L_shl_sat( Ltmp, 1 ); /*Q15 / Qnew + 14 + 1 +1 */ exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); move16(); } @@ -775,10 +464,10 @@ void encod_gen_voic_ivas_fx( { /* code in Q9, gain_pit in Q14 */ /*gcode16 in Qnew*/ - Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ - Ltmp = L_shl_sat( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ - Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ - Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1 */ + Ltmp = L_mult( gcode16, code_fx[i] ); /*Q10 / Qnew + 9 + 1 */ + Ltmp = L_shl_sat( Ltmp, 5 ); /*Q15 / Qnew + 9+ 1+5 */ + Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Q15 / Qnew + 14 + 1*/ + Ltmp = L_shl_sat( Ltmp, 1 ); /*Q15 / Qnew + 14 + 1 +1 */ exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp ); } } @@ -797,7 +486,14 @@ void encod_gen_voic_ivas_fx( * Update A(z) filters *-----------------------------------------------------------------*/ - syn_filt_fx( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); + IF( st_fx->element_mode == EVS_MONO ) + { + Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); + } + ELSE + { + syn_filt_fx( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, hLPDmem->mem_syn, 1 ); + } p_Aw_fx += ( M + 1 ); p_Aq_fx += ( M + 1 ); @@ -811,6 +507,7 @@ void encod_gen_voic_ivas_fx( push_indice( hBstr, IND_UNUSED, 0, i ); unbits_PI_fx -= i; } + IF( st_fx->Opt_SC_VBR ) { /* SC-VBR */ diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 455fc03229f66888bc00c416d4cebd1dccf3f092..24bf48838bdb9584f095f79c2f889e114930026f 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -22,6 +22,7 @@ static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq *-----------------------------------------------------------------*/ #define Q_MINUS 4 + void transf_cdbk_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ @@ -74,7 +75,7 @@ void transf_cdbk_enc_fx( Nsv = 8; move16(); - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; /* Q0 */ + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[i_subfr >> 6]; /* Q0 */ move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -99,7 +100,6 @@ void transf_cdbk_enc_fx( Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); /* Q_new + 14 + shift */ Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ - move16(); } find_cn_fx( x_tran, Ap, p_Aq, x_in ); } @@ -136,366 +136,15 @@ void transf_cdbk_enc_fx( * Split algebraic vector quantizer based on RE8 lattice *--------------------------------------------------------------*/ - AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); - - /*--------------------------------------------------------------* - * Find prequantizer excitation gain - * Quantize the gain - *--------------------------------------------------------------*/ - - L_corr = L_deposit_l( 0 ); - L_ener = L_deposit_l( 0 ); - FOR( i = 0; i < Nsv * 8; i++ ) - { - /*fcorr += fx_tran[i]*(float)ix_norm[i];*/ - /*fener += (float)ix_norm[i]*(float)ix_norm[i];*/ - stmp = shl_sat( x_norm[i], Q_AVQ_OUT ); - L_corr = L_mac_sat( L_corr, x_tran[i], stmp ); - L_ener = L_mac_sat( L_ener, stmp, stmp ); - } - L_ener = L_max( L_ener, 1 ); - - /* No negative gains allowed in the quantizer*/ - L_corr = L_max( L_corr, 0 ); - - e_corr = norm_l( L_corr ); - m_corr = extract_h( L_shl( L_corr, e_corr ) ); - e_corr = sub( 30, add( e_corr, sub( Qdct, Q_AVQ_OUT ) ) ); - e_ener = norm_l( L_ener ); - m_ener = extract_h( L_shl( L_ener, e_ener ) ); - e_ener = sub( 30, e_ener ); - - IF( GT_16( m_corr, m_ener ) ) - { - m_corr = shr( m_corr, 1 ); - e_corr = add( e_corr, 1 ); - } - m_corr = div_s( m_corr, m_ener ); /* e_corr - e_ener */ - e_corr = sub( e_corr, e_ener ); - Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) - { - Ltmp1 = L_max( gain_code, 1 ); - e_den = norm_l( Ltmp1 ); - m_den = extract_h( L_shl_sat( Ltmp1, e_den ) ); - /* ensure m_corr < m_den */ - test(); - IF( m_corr > 0 && m_den > 0 ) - { - m_corr = div_s( 16384, m_den ); - e_corr = sub( 14 + 4, e_den ); - Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ - stmp = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); /* Q12 */ - } - ELSE - { - stmp = 0; - move16(); - } - IF( GT_32( st_fx->core_brate, 56000 ) ) - { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ - } - ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) - { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ - } - ELSE - { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ - } - Ltmp = Mult_32_16( gain_code, stmp ); /* Q16 * Q12 - 15 -> Q13*/ - Ltmp = L_shl_sat( Ltmp, 5 ); /* Q13 -> Q18*/ - *gain_preQ = round_fx_sat( Ltmp ); /* Q2*/ - } - ELSE - { - IF( Es_pred < 0 ) - { - Es_pred_loc = shr( negate( Es_pred ), 2 ); /* Q8 */ - } - ELSE - { - Es_pred_loc = Es_pred; /* Q8 */ - move16(); - } - - e_den = norm_s( Es_pred_loc ); - m_den = shl( Es_pred_loc, e_den ); - /* ensure m_corr < m_den */ - test(); - IF( m_corr > 0 && m_den > 0 ) - { - m_corr = div_s( 16384, m_den ); /* 14 - 8 - e_den */ - e_corr = sub( 14 - 8, e_den ); - Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /* Q18 */ - } - ELSE - { - Ltmp = L_deposit_l( 0 ); - } - test(); - IF( LE_32( st_fx->core_brate, 42000 ) && GT_32( st_fx->core_brate, ACELP_24k40 ) ) - { - index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); /* Q0 */ - } - ELSE - { - index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); /* Q0 */ - } - Ltmp = L_mult( stmp, Es_pred_loc ); /* Q0*Q8 -> Q9*/ - Ltmp = L_shl( Ltmp, add( e_den, 9 ) ); /* Q18*/ - *gain_preQ = round_fx( Ltmp ); /* Q2*/ - } - push_indice( st_fx->hBstr, IND_AVQ_GAIN, index, G_AVQ_BITS ); - - /*--------------------------------------------------------------* - * Encode and multiplex subvectors into bit-stream - *--------------------------------------------------------------*/ - - trgtSvPos = Nsv - 1; - move16(); - test(); - test(); - test(); - test(); - test(); - IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) + IF( st_fx->element_mode == EVS_MONO ) { - trgtSvPos = 2; - avq_bit_sFlag = 2; - move16(); - move16(); - } - - AVQ_encmux_fx( st_fx->hBstr, -1, x_norm, &nBits, Nsv, nq, avq_bit_sFlag, trgtSvPos ); - - /* save # of AVQ unused bits for next subframe */ - *unbits = nBits; /* Q0 */ - move16(); - - /* at the last subframe, write AVQ unused bits */ - test(); - test(); - IF( EQ_16( i_subfr, 4 * L_SUBFR ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) - { - WHILE( *unbits > 0 ) - { - i = s_min( *unbits, 16 ); - push_indice( st_fx->hBstr, IND_UNUSED, 0, i ); - *unbits -= i; - } - } - - /*--------------------------------------------------------------* - * DCT transform - *--------------------------------------------------------------*/ - - FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) - { - x_tran[i] = shl_sat( x_norm[i], Q_AVQ_OUT_DEC ); - move16(); - } - - test(); - test(); - test(); - IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) - { - Copy( x_tran, code_preQ, L_SUBFR ); /* Q_AVQ_OUT_DEC */ + AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); } ELSE { - Qdct = 0; - move16(); - edct2_fx( L_SUBFR, 1, x_tran, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); - /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/ - Qdct = negate( Qdct ); - Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in Q_AVQ_OUT_DEC */ - /*qdct = Q_AVQ_OUT_DEC;*/ + AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, Qdct ); } - /*--------------------------------------------------------------* - * Preemphasise - *--------------------------------------------------------------*/ - - /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ - test(); - if ( ( nq[7] != 0 ) && ( GT_16( sub( st_fx->last_nq_preQ, nq[0] ), 7 ) ) ) - { - /* *mem_preemp /= 16; */ - st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); - move16(); - } - st_fx->last_nq_preQ = nq[7]; - move16(); - - PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); - - /*--------------------------------------------------------------* - * For inactive segments - * - Zero-memory filtered pre-filter excitation - * - Update of targets and gain_pit - * For inactive segments - * - Update xn[L_subfr-1] for updating the memory of the weighting filter - *--------------------------------------------------------------*/ - - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) - { - /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/ - Ltmp = L_mult( code_preQ[0], h1[L_SUBFR - 1] ); /*1+14+shift + Q_AVQ_OUT */ - FOR( i = 1; i < L_SUBFR; i++ ) - { - /*ftemp += fcode_preQ[i] * fh1[L_SUBFR-1-i];*/ - Ltmp = L_mac( Ltmp, code_preQ[i], h1[L_SUBFR - 1 - i] ); - } - /*fxn[L_SUBFR-1] -= *fgain_preQ * ftemp;*/ - Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( Q_AVQ_OUT_DEC, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */ - xn[L_SUBFR - 1] = round_fx( L_sub( L_mult( xn[L_SUBFR - 1], 32767 ), Ltmp ) ); /* -> Q_new + shift -1 */ - } - ELSE - { - conv_fx( code_preQ, h1, x_tran, L_SUBFR ); - updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); - - updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); - *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); /* Q14 */ - /* clip gain if necessary to avoid problems at decoder */ - test(); - if ( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) - { - *gain_pit = 15565; /* 0.95 in Q15 */ - move16(); - } - updt_tar_fx( xn, xn2, y1, *gain_pit, L_SUBFR ); - } - - st_fx->use_acelp_preq = 1; - move16(); - - return; -} - - -void transf_cdbk_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ - const Word16 i_subfr, /* i : subframe index Q0*/ - Word16 cn[], /* i/o: target vector in residual domain Q_new*/ - Word16 exc[], /* i/o: pointer to excitation signal frame Q_new*/ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ - const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ - const Word16 h1[], /* i : weighted filter input response Q15*/ - Word16 xn[], /* i/o: target vector Q_new + shift -1*/ - Word16 xn2[], /* i/o: target vector for innovation search Q_new + shift -1*/ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation Q_new + shift -1*/ - const Word16 y2[], /* i : zero-memory filtered innovative excitation Q9*/ - const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ - Word16 *gain_pit, /* i/o: adaptive excitation gain Q14*/ - const Word32 gain_code, /* i : innovative excitation gain Q16*/ - Word16 g_corr[], /* o : ACELP correlation values Q15*/ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0*/ - Word16 *gain_preQ, /* o : prequantizer excitation gain Q2*/ - Word16 code_preQ[], /* o : prequantizer excitation Q_AVQ_OUT_DEC*/ - Word16 *unbits, /* o : number of AVQ unused bits Q0*/ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ -) -{ - Word16 i, index, nBits, Nsv, Es_pred_loc; - Word16 x_in[L_SUBFR], x_tran[L_SUBFR], gcode16, stmp; - Word16 e_corr, m_corr, e_ener, m_ener, m_den, e_den; - Word16 x_norm[L_SUBFR + L_SUBFR / WIDTH_BAND]; - Word32 L_corr, L_ener, Ltmp, Ltmp1; - Word16 nq[L_SUBFR / WIDTH_BAND]; - Word32 out32[L_SUBFR]; - Word16 Qdct; - Word16 avq_bit_sFlag; - Word16 trgtSvPos; - Flag Overflow = 0; - move32(); - - avq_bit_sFlag = 0; - move16(); - if ( st_fx->element_mode > EVS_MONO ) - { - avq_bit_sFlag = 1; - move16(); - } - - /*--------------------------------------------------------------* - * Set bit-allocation - *--------------------------------------------------------------*/ - - Nsv = 8; - move16(); - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[i_subfr >> 6]; /* Q0 */ - move16(); - - /* increase # of AVQ allocated bits by unused bits from the previous subframe */ - nBits = add( nBits, *unbits ); - - /*--------------------------------------------------------------* - * Compute/Update target - * For inactive frame, find target in residual domain - * Deemphasis - *--------------------------------------------------------------*/ - - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) - { - gcode16 = round_fx_sat( L_shl_sat( gain_code, Q_new ) ); - FOR( i = 0; i < L_SUBFR; i++ ) - { - /*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/ - Ltmp = L_mult( gcode16, y2[i] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); - Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn[i], 16384 ); - Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); /* Q_new + 14 + shift */ - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ - x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ - } - find_cn_fx( x_tran, Ap, p_Aq, x_in ); - } - ELSE - { - updt_tar_fx( cn, x_in, &exc[i_subfr], *gain_pit, L_SUBFR ); - } - Deemph2( x_in, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_deemp_preQ_fx ) ); - - /*--------------------------------------------------------------* - * DCT-II - *--------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) - { - Copy_Scale_sig( x_in, x_tran, L_SUBFR, -Q_MINUS + 1 ); /*Q_new-1 -> Q_new-4*/ - /*Copy( x_in, x_tran, L_SUBFR );*/ - Qdct = sub( Q_new, Q_MINUS ); - } - ELSE - { - Qdct = 0; - move16(); - edct2_fx( L_SUBFR, -1, x_in, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); - Qdct = negate( Qdct ); - Copy_Scale_sig_32_16( out32, x_tran, L_SUBFR, sub( Qdct, Q_MINUS - 1 ) ); /* Output in Q_new-4 */ - Qdct = sub( Q_new, Q_MINUS ); - } - - /*--------------------------------------------------------------* - * Split algebraic vector quantizer based on RE8 lattice - *--------------------------------------------------------------*/ - -#ifndef FIX_2015_PREMPH_SAT_ALT_PART2 - AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); -#else - AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, Qdct ); -#endif - /*--------------------------------------------------------------* * Find prequantizer excitation gain * Quantize the gain @@ -714,7 +363,7 @@ void transf_cdbk_enc_ivas_fx( st_fx->last_code_preq = shr( code_preQ[L_SUBFR - 1], 9 ); // Q0 move16(); - PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); /*--------------------------------------------------------------* * For inactive segments @@ -779,7 +428,7 @@ static void find_cn_fx( Copy( xn, tmp_fl + M, L_SUBFR ); /* Qx */ tmp = 0; move16(); - PREEMPH_FX( tmp_fl + M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); + preemph_fx( tmp_fl + M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); syn_filt_s_lc_fx( 0, Ap, tmp_fl + M, tmp_fl + M, L_SUBFR ); Residu3_lc_fx( p_Aq, M, tmp_fl + M, cn, L_SUBFR, 1 ); diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index 30756d19d6abcbf03857c417d4caaa5555cdb62d..5181a08ffc86760cf387885ed8b0953bc65bdbc7 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -171,143 +171,3 @@ void encod_nelp_fx( return; } - -void encod_nelp_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, - /* i : input speech */ /* Q_new-1 */ - const Word16 Aw_fx[], - /* i : weighted A(z) unquantized for subframes */ /*exp(norm_s(Aw_fx[0])+1)*/ - const Word16 Aq_fx[], - /* i : 12k8 Lp coefficient */ /*exp(norm_s(Aw_fx[0])+1)*/ - Word16 *res_fx, - /* o : residual signal */ /* Q_new */ - Word16 *synth_fx, - /* o : core synthesis */ /* Q_new */ - Word16 *tmp_noise_fx, - /* o : long-term noise energy */ /* Q8 */ - Word16 *exc_fx, - /* i/o: current non-enhanced excitation */ /* Q_new */ - Word16 *exc2_fx, - /* i/o: current enhanced excitation */ /* Q_new */ - Word16 *pitch_buf_fx, - /* o : floating pitch values for each subframe */ /* Q6 */ - Word16 *voice_factors_fx, - /* o : voicing factors */ /* Q15 */ - Word16 *bwe_exc_fx, - /* o : excitation for SWB TBE */ /* Q_new */ - Word16 Q_new, - Word16 shift ) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ - Word16 exc_nelp_fx[L_FRAME]; - - Word16 i_subfr, j; - - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ - Word16 saved_Q_new = Q_new; - move16(); - - Word16 reduce_gains = 0; - move16(); - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - - test(); - IF( EQ_16( st_fx->bwidth, NB ) && GE_32( st_fx->input_Fs, 16000 ) ) - { - IF( hSC_VBR->last_nelp_mode == 0 ) - { - set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 ); - } - Scale_sig( hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER * 2, sub( Q_new, st_fx->prev_Q_new ) ); /* Q_new */ - - pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3 ); /*16-Q of filter coeff*/ - } - - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - - - FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) - { - /*----------------------------------------------------------------* - * - Bandwidth expansion of A(z) filter coefficients - * - Find the excitation search target "xn" and innovation - * target in residual domain "cn" - * - Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx ); - - /* scale xn[] and h1[] to avoid overflow in dot_product12() */ - Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits Q_new-1+shift */ - - IF( i_subfr == 0 ) - { - test(); - IF( EQ_16( hSC_VBR->Local_VAD, 1 ) && EQ_16( st_fx->bwidth, NB ) ) - { - reduce_gains = 1; - move16(); - } - - nelp_encoder_ivas_fx( st_fx, res_fx, exc_nelp_fx, &Q_new, reduce_gains ); - - Scale_sig( exc_nelp_fx, L_FRAME, ( saved_Q_new - Q_new ) ); /* saved_Q_new */ - } - - - *tmp_noise_fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - Syn_filt_s( 1, p_Aq_fx, M, &exc_nelp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - - p_Aw_fx += ( M + 1 ); - p_Aq_fx += ( M + 1 ); - *pitch_buf_fx = L_SUBFR_Q6; /* Q6 */ - move16(); - - pitch_buf_fx++; - } - - Copy( exc_nelp_fx, exc_fx, L_FRAME ); /* Q_new */ - - /*-----------------------------------------------------------------* - * Updates: last value of new target is stored in mem_w0 - *-----------------------------------------------------------------*/ - - hLPDmem->mem_w0 = sub_sat( shr_sat( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); - move16(); /*Q_new-1 */ - hLPDmem->tilt_code = 0; - move16(); /* purely unvoiced */ - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; - move16(); - - Copy( exc_fx, exc2_fx, L_FRAME ); /* Q_new */ - - hSC_VBR->prev_ppp_gain_pit_fx = 0; - move16(); - - hLPDmem->dm_fx.prev_state = 0; - move16(); - hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; /* Q14 */ - move16(); - - FOR( j = 1; j < 5; j++ ) - { - hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j - 1]; /* Q14 */ - move16(); - } - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); - set16_fx( voice_factors_fx, 0, NB_SUBFR16k ); - - return; -} diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index 200c22a1a1f61c5469a8bdaa6b8d6e580ccd925a..00095a89dd3b7b178705be19cba4d4e4eea986f1 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -63,8 +63,8 @@ void enc_pit_exc_fx( Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, + const Word16 shift ) { Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ @@ -81,8 +81,12 @@ void enc_pit_exc_fx( Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ Word16 clip_gain, i; /* LSF clip gain and LP flag */ const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ - Word16 *pt_pitch; /* pointer to floating pitch */ +#ifdef FIX_1904_HARM_GSC_ENC + Word16 cn[PIT_EXC_L_SUBFR]; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ +#else + Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ +#endif + Word16 *pt_pitch; /* pointer to floating pitch */ Word16 L_subfr; Word16 cum_gpit, gpit_tmp; Word32 Local_BR, Pitch_BR; @@ -103,6 +107,10 @@ void enc_pit_exc_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; +#ifdef FIX_1904_HARM_GSC_ENC + Word16 q_h1 = 0; + move16(); +#endif /*------------------------------------------------------------------* * Initialization @@ -225,17 +233,27 @@ void enc_pit_exc_fx( * ACELP subframe loop *------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + set16_fx( cn, 0, PIT_EXC_L_SUBFR ); +#else cn = NULL; if ( EQ_16( L_subfr, L_SUBFR ) ) { cn = cn1; move16(); } +#endif p_Aw = Aw; p_Aq = Aq; pt_pitch = pitch_buf; /* pointer to the pitch buffer */ shift_wsp = add( Q_new, shift ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } +#endif FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) { @@ -249,10 +267,23 @@ void enc_pit_exc_fx( Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */ /* condition on target (compared to float) has been put outside the loop */ - find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, - res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */ - Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq, + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + + q_h1 = sub( 14, norm_s( h1[0] ) ); + Copy_Scale_sig( h1, h2, L_subfr, sub( 11, q_h1 ) ); /*Q11*/ + } + ELSE +#endif + { + find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */ + Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + } /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */ @@ -265,12 +296,27 @@ void enc_pit_exc_fx( *pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc, L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, st_fx->element_mode, Q_new ); /* Q6 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ // TVTODO to be check if it would still be BE when moved above + } +#endif /*-----------------------------------------------------------------* * Find adaptive exitation *-----------------------------------------------------------------*/ - pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE +#endif + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure @@ -292,7 +338,16 @@ void enc_pit_exc_fx( } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ - hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hSpMusClas->lowrate_pitchGain = mac_r_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 3277, gain_pit ); /* Q14*Q16(0.1) + Q15 -> Q15 Q14*Q15 + Q14 -> Q14 lowrate_pitchGain is compared to Q14 in sp_music_classif */ + } + ELSE +#endif + { + hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ + } gpit_tmp = gain_pit; move16(); /*Q14*/ @@ -324,14 +379,13 @@ void enc_pit_exc_fx( *-----------------------------------------------------------------*/ inov_encode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, st_fx->last_L_frame, GENERIC, st_fx->bwidth, 0, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift ); + gain_pit, cn, exc, h2, st_fx->hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, 2 * L_SUBFR, shift, Q_new ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, - st_fx->element_mode ); + gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, shift_wsp, y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, st_fx->element_mode ); } ELSE { @@ -340,23 +394,38 @@ void enc_pit_exc_fx( *-----------------------------------------------------------------*/ inov_encode_fx( st_fx, Local_BR, 0, st_fx->L_frame, st_fx->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); + gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, st_fx->L_frame, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); +#else gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_FRAME, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); +#endif } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); + IF( use_fcb != 0 ) { - hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hLPDmem->tilt_code = est_tilt_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr ); /* Q15 */ + } + ELSE +#endif + { + hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ + } move16(); } ELSE @@ -371,13 +440,31 @@ void enc_pit_exc_fx( IF( use_fcb != 0 ) { - Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ + } + ELSE +#endif + { + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ + } Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); /* Q15 + Q_new + shift */ Ltmp = L_negate( Ltmp ); Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 ); /* Q_new + Q15 + shift */ Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + Q15 + shift */ Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ + } + ELSE +#endif + { + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + } move16(); } ELSE @@ -385,7 +472,16 @@ void enc_pit_exc_fx( Ltmp = L_mult( xn[L_subfr - 1], 16384 ); /* Q_new + 14 -shift */ Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + 14 -shift */ Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ + } + ELSE +#endif + { + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + } move16(); } @@ -532,7 +628,7 @@ void enc_pit_exc_fx( return; } - +#ifndef FIX_1904_HARM_GSC_ENC void enc_pit_exc_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 *speech, /* i : Input speech Q_new-1*/ @@ -1013,3 +1109,4 @@ void enc_pit_exc_ivas_fx( return; } +#endif diff --git a/lib_enc/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c index 70360f9d2c281e2c988ab6e82ac103f5d98dd708..5f097660449be0efb6aa925ba1995735af12dbf4 100644 --- a/lib_enc/enc_ppp_fx.c +++ b/lib_enc/enc_ppp_fx.c @@ -1,17 +1,15 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ -/*Temporary location to be move in prot* when merge is done */ -void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); /*=======================================================================================*/ /* FUNCTION : encod_ppp_fx() */ @@ -51,6 +49,7 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); /*---------------------------------------------------------------------------------------*/ /* CALLED FROM : TX */ /*=======================================================================================*/ + ivas_error encod_ppp_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q_new*/ @@ -63,8 +62,9 @@ ivas_error encod_ppp_fx( Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors, /* o : voicing factors Q15*/ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ @@ -233,185 +233,3 @@ ivas_error encod_ppp_fx( return error; } - -ivas_error encod_ppp_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, - Word16 shift ) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 i_subfr; /* tmp variables */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ - - Word16 k; - Word16 p_Aq_old_fx[M + 1], excQ_ppp_fx[L_FRAME], p_Aq_curr_fx[M], pitch_fx[NB_SUBFR]; - Word16 LPC_de_old_fx[M + 1], LPC_de_curr_fx[M + 1]; - Word16 shift_wsp = add( Q_new, shift ); - Word16 rate_ctrl_fx; - Word16 saved_Q_new = Q_new; - move16(); - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - ivas_error error; - - error = IVAS_ERR_OK; - move16(); - rate_ctrl_fx = hSC_VBR->rate_control; - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) - { - /*----------------------------------------------------------------* - * Bandwidth expansion of A(z) filter coefficients - * Find the the excitation search target "xn" and innovation - * target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - - Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx ); - - /* scale xn[] and h1[] to avoid overflow in dot_product12() */ - Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits */ - - /* call voiced encoder at this point */ - IF( i_subfr == 0 ) /* generate the L_FRAME exc */ - { - FOR( k = 0; k < M; k++ ) - { - p_Aq_curr_fx[k] = p_Aq_fx[k + ( 3 * ( M + 1 ) ) + 1]; /* Q12 */ - move16(); - } - - E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, p_Aq_old_fx, M ); - deemph_lpc_fx( p_Aq_curr_fx, p_Aq_old_fx, LPC_de_curr_fx, LPC_de_old_fx, 1 ); - /* both outputs LPC_de_curr_fx and LPC_de_old_fx are in Q12 */ - - - /* last frame-end lpc and curr frame-end lpc */ - IF( ( error = ppp_voiced_encoder_fx( hBstr, hSC_VBR, st_fx->bwidth, st_fx->last_coder_type_raw, st_fx->old_pitch_buf_fx, res_fx, - excQ_ppp_fx, st_fx->pitch[1], LPC_de_old_fx, LPC_de_curr_fx, exc_fx, pitch_fx, Q_new ) ) != IVAS_ERR_OK ) - { - return error; - } - - Scale_sig( exc_fx, L_FRAME, sub( saved_Q_new, Q_new ) ); /* saved_Q_new */ - if ( EQ_16( hSC_VBR->bump_up, 1 ) ) - { - i_subfr = L_FRAME; - move16(); - } - } - - IF( NE_16( hSC_VBR->bump_up, 1 ) ) - { - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); - - - /* run the above to maintain gain clipping memories */ - gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, hSC_VBR->prev_ppp_gain_pit_fx, st_fx->clip_var_fx ); - - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq_fx, M, &excQ_ppp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - - - p_Aw_fx += ( M + 1 ); - p_Aq_fx += ( M + 1 ); - } - - } /* end of subframe loop */ - - IF( hSC_VBR->bump_up ) - { - /* PPP failed, bump up */ - hSC_VBR->ppp_mode = 0; - move16(); - st_fx->core_brate = ACELP_7k20; - move16(); - hSC_VBR->pppcountE = 0; - move16(); - - IF( hSC_VBR->set_ppp_generic ) - { - st_fx->coder_type = GENERIC; - move16(); - } - ELSE - { - st_fx->coder_type = VOICED; - move16(); - } - - /* We write signalling indices again only in case of bump_up */ - /* delete previous indices */ - reset_indices_enc_fx( hBstr, hBstr->nb_ind_tot ); - /* signalling matrix (writing of signalling bits) */ - signalling_enc_fx( st_fx ); - } - ELSE - { - Copy( excQ_ppp_fx, exc_fx, L_FRAME ); /* Q_new */ - - /*-----------------------------------------------------------------* - * Updates: last value of new target is stored in mem_w0 - *-----------------------------------------------------------------*/ - - hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); /*Q_new-1 */ - - Copy( exc_fx, exc2_fx, L_FRAME ); /* Q_new */ - - hLPDmem->dm_fx.prev_state = 2; - move16(); /*Q0 dispMem index 0 */ - hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; - move16(); /*Q14 dispMem index 2 */ - - FOR( k = 1; k < 5; k++ ) - { - hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k - 1]; /* Q14 */ - move16(); - } - - hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx; /* Q15 */ - move16(); - Copy( pitch_fx, pitch_buf_fx, NB_SUBFR ); - pitch_buf_fx[NB_SUBFR16k - 1] = pitch_fx[NB_SUBFR - 1]; - - interp_code_5over2_fx( exc2_fx, bwe_exc, L_FRAME ); - set16_fx( voice_factors, 0, NB_SUBFR16k ); - } - - hSC_VBR->rate_control = rate_ctrl_fx; /* Q0 */ - move16(); - - set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 ); - - return error; -} diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index 6a861b8aff23a5fe0ad63888449f9b3eccfb3a97..e28dd0bf99392be34f6c528b1a6fc31db9afd3c2 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -23,7 +23,6 @@ static void enc_prm_hm( Word8 flag; BSTR_ENC_HANDLE hBstr = st->hBstr; - /* Disable HM for non-GC,VC modes */ test(); IF( NE_16( st->hTcxCfg->coder_type, VOICED ) && NE_16( st->hTcxCfg->coder_type, GENERIC ) ) @@ -93,184 +92,14 @@ static void enc_prm_hm_ivas_fx( } } + /*-----------------------------------------------------------------* - * Function enc_prm_rf_fx() * + * Function enc_prm_rf_fx() * * ~~~~~~~~~~~~~~~~~~~~~~ * * * * encode RF parameters for ACELP and TCX partial copy * *-----------------------------------------------------------------*/ -void enc_prm_rf_ivas_fx( - Encoder_State *st, - const Word16 rf_frame_type, /* Q0 */ - const Word16 fec_offset /* Q0 */ -) -{ - Word16 sfr, nb_subfr, n, index; - Word16 ltp_mode, ltf_mode, gains_mode; - RF_ENC_HANDLE hRF = st->hRF; - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - BSTR_ENC_HANDLE hBstr = st->hBstr; - - - nb_subfr = st->nb_subfr; /* Q0 */ - move16(); - /* partial copy bitstream writing */ - test(); - IF( GE_16( rf_frame_type, RF_TCXFD ) && LE_16( rf_frame_type, RF_TCXTD2 ) ) - { - /* TCX frames partial copy write */ - - /* LSF indices */ - IF( EQ_16( rf_frame_type, RF_TCXFD ) ) - { - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][0], lsf_numbits[0] ); /* VQ 1 */ - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][1], lsf_numbits[1] ); /* VQ 2 */ - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][2], lsf_numbits[2] ); /* VQ 3 */ - } - - /* classification */ - test(); - IF( EQ_16( hRF->rf_clas[fec_offset], UNVOICED_CLAS ) ) - { - index = 0; - move16(); - } - ELSE IF( ( EQ_16( hRF->rf_clas[fec_offset], VOICED_TRANSITION ) ) || ( EQ_16( hRF->rf_clas[fec_offset], UNVOICED_TRANSITION ) ) ) - { - index = 1; - move16(); - } - ELSE IF( EQ_16( hRF->rf_clas[fec_offset], VOICED_CLAS ) ) - { - index = 2; - move16(); - } - ELSE - { - index = 3; - move16(); - } - push_next_indice( hBstr, index, 2 ); - - IF( EQ_16( rf_frame_type, RF_TCXFD ) ) - { - /* TCX global gain = 7 bits */ - push_next_indice( hBstr, hRF->rf_gain_tcx[fec_offset], 7 ); - /*window info - 1 bit for long overlap - 2 if minimum or half overlap*/ - } - ELSE - { - /*gains adapt - gains inov*/ - - /*LPC on full rate -> excitation */ - /* pitch and gain */ - /* LTP data */ - test(); - test(); - IF( ( EQ_16( rf_frame_type, RF_TCXTD1 ) || EQ_16( rf_frame_type, RF_TCXTD2 ) ) && hTcxEnc->tcxltp != 0 ) - { - push_next_indice( hBstr, hRF->rf_tcxltp_param[fec_offset], 9 ); - } - } - } - ELSE IF( EQ_16( rf_frame_type, 7 ) ) /* NELP bitstream writing */ - { - /* LSF indices */ - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8 ); /* VQ 1 */ - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8 ); /* VQ 2 */ - - /* NELP gain indices */ - push_next_indice( hBstr, hRF->rf_indx_nelp_iG1[fec_offset], 5 ); - push_next_indice( hBstr, hRF->rf_indx_nelp_iG2[fec_offset][0], 6 ); - push_next_indice( hBstr, hRF->rf_indx_nelp_iG2[fec_offset][1], 6 ); - - /* NELP filter selection index */ - push_next_indice( hBstr, hRF->rf_indx_nelp_fid[fec_offset], 2 ); - - /* tbe gainFr */ - push_next_indice( hBstr, hRF->rf_indx_tbeGainFr[fec_offset], 5 ); - } - ELSE IF( GE_16( rf_frame_type, 4 ) ) /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6 */ - { - /* LSF indices */ - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][0], 8 ); /* VQ 1 */ - push_next_indice( hBstr, hRF->rf_indx_lsf[fec_offset][1], 8 ); /* VQ 2 */ - - /* ES pred */ - push_next_indice( hBstr, hRF->rf_indx_EsPred[fec_offset], 3 ); - - ltp_mode = ACELP_LTP_MODE[1][1][rf_frame_type]; - ltf_mode = ACELP_LTF_MODE[1][1][rf_frame_type]; - gains_mode = ACELP_GAINS_MODE[1][1][rf_frame_type]; - move16(); - move16(); - move16(); - /* Subframe parameters */ - FOR( sfr = 0; sfr < nb_subfr; sfr++ ) - { - /* Pitch lag (5, or 8 bits) */ - n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; - move16(); - IF( n != 0 ) - { - push_next_indice( hBstr, hRF->rf_indx_pitch[fec_offset][sfr], n ); - } - - /* Adaptive codebook filtering (1 bit) */ - IF( EQ_16( ltf_mode, 2 ) ) - { - push_next_indice( hBstr, hRF->rf_indx_ltfMode[fec_offset][sfr], 1 ); - } - - /*Innovative codebook*/ - test(); - test(); - test(); - IF( ( EQ_16( rf_frame_type, RF_NOPRED ) ) || - ( EQ_16( rf_frame_type, RF_GENPRED ) && - ( sfr == 0 || EQ_16( sfr, 2 ) ) ) ) - { - push_next_indice( hBstr, hRF->rf_indx_fcb[fec_offset][sfr], 7 ); - } - - /* Gains (5b, 6b or 7b / subfr) */ - test(); - IF( sfr == 0 || EQ_16( sfr, 2 ) ) - { - n = ACELP_GAINS_BITS[gains_mode]; - move16(); - push_next_indice( hBstr, hRF->rf_indx_gain[fec_offset][sfr], n ); - } - } - /* tbe gainFr */ - push_next_indice( hBstr, hRF->rf_indx_tbeGainFr[fec_offset], 2 ); - } - - /***************/ - /*IMPORTANT: The last three bits are always the rf_frame_type in the bitstream (for both acelp and tcx partial copy); - the rf_frame_type indicates the length of the partial copy payload at the decoder. - The 2 bits before the rf_frame_type contains the fec_offset */ - - /***************/ - /* write FEC offset just before the rf_frame_type */ - test(); - test(); - IF( EQ_16( fec_offset, 2 ) ) - { - push_next_indice( hBstr, 0, 2 ); - } - ELSE IF( EQ_16( fec_offset, 3 ) || EQ_16( fec_offset, 5 ) || EQ_16( fec_offset, 7 ) ) - { - push_next_indice( hBstr, shr( sub( fec_offset, 1 ), 1 ), 2 ); - } - - /* write RF frame type last in the bitstream */ - push_next_indice( hBstr, rf_frame_type, 3 ); -} void enc_prm_rf_fx( Encoder_State *st, const Word16 rf_frame_type, /* Q0 */ @@ -449,14 +278,14 @@ void enc_prm_rf_fx( *-----------------------------------------------------------------*/ void enc_prm_fx( - const Word16 coder_type, /* (i) : coding type */ - Word16 param[], /* (i) : parameters Q0*/ - Word16 param_lpc[], /* (i) : LPC parameters Q0*/ - Encoder_State *st, /* i/o : quantization Analysis values */ - Word16 L_frame, /* Q0 */ + const Word16 coder_type, /* (i) : coding type */ + Word16 param[], /* (i) : parameters Q0*/ + const Word16 param_lpc[], /* (i) : LPC parameters Q0*/ + Encoder_State *st, /* i/o : quantization Analysis values */ + const Word16 L_frame, /* Q0 */ CONTEXT_HM_CONFIG hm_cfg[], - Word16 *bits_param_lpc, /* Q0 */ - Word16 no_param_lpc /* Q0 */ + Word16 *bits_param_lpc, /* Q0 */ + const Word16 no_param_lpc /* Q0 */ ) { Word16 j, k, n, sfr, core, last_core, *prm, tmp; @@ -1108,15 +937,12 @@ void enc_prm_fx( } /* k, window index */ } - /*--------------------------------------------------------------------------------* * END *--------------------------------------------------------------------------------*/ - total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */ - /* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */ if ( st->bits_frame_core && ( total_nbbits > st->bits_frame_core ) ) { @@ -1149,7 +975,7 @@ void writeLPCparam_fx( IF( st->enableTcxLpc && st->core != ACELP_CORE ) { /* Encode the indices */ - *nbits_lpc = enc_lsf_tcxlpc_ivas_fx( ¶m_lpc, hBstr ); /* Q0 */ + *nbits_lpc = enc_lsf_tcxlpc_fx( ¶m_lpc, hBstr ); /* Q0 */ move16(); } ELSE @@ -1168,7 +994,7 @@ void writeLPCparam_fx( move16(); } - *nbits_lpc = encode_lpc_avq_ivas_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode ); /* Q0 */ + *nbits_lpc = encode_lpc_avq_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode ); /* Q0 */ move16(); } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) @@ -1178,13 +1004,12 @@ void writeLPCparam_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) { assert( st->element_mode == EVS_MONO ); - - *nbits_lpc = lsf_bctcvq_encprm_ivas_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc ); /* Q0 */ + *nbits_lpc = lsf_bctcvq_encprm_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc ); /* Q0 */ move16(); } ELSE { - *nbits_lpc = lsf_msvq_ma_encprm_ivas_fx( hBstr, param_lpc, st->core, st->coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); /* Q0 */ + *nbits_lpc = lsf_msvq_ma_encprm_fx( hBstr, param_lpc, st->core, st->coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); /* Q0 */ move16(); } } diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 879ed6dd038b6eb099713e169b84888e116fe48d..10e458fb5710a073f8c2f61cbd3b433e3e228791 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -60,7 +60,7 @@ Word16 encod_tran_fx( Word16 tc_subfr, /* i/o: TC subframe classification Q0*/ Word16 position, /* i : maximum of residual signal index Q0*/ Word16 *unbits, /* i/o: number of unused bits Q0*/ - const Word16 shift, /* i : Scaling to get 12 bits */ + const Word16 shift_r, /* i : Scaling to get 12 bits */ const Word16 Q_new /* i : Input scaling */ ) { @@ -93,10 +93,15 @@ Word16 encod_tran_fx( Word16 L_frame_fx; Word16 shift_wsp; Word32 L_tmp; + Word16 q_h1; + Word16 shift, tmp; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; + shift = shift_r; /* for IVAS, shift_r is always 0 */ + /* will be reusing the EVS shift strategy later on to allow of H1 overshoot */ + move16(); L_frame_fx = st_fx->L_frame; move16(); @@ -134,13 +139,18 @@ Word16 encod_tran_fx( *unbits = 0; move16(); - p_Aw = Aw_fx; /* Q12 */ - p_Aq = Aq_fx; /* Q12 */ - pt_pitch = pitch_buf_fx; /* Q6 */ + p_Aw = Aw_fx; /* Q12 */ + p_Aq = Aq_fx; /* Q12 */ + pt_pitch = pitch_buf_fx; gain_preQ = 0; move16(); set16_fx( code_preQ, 0, L_SUBFR ); shift_wsp = add( Q_new, shift ); + test(); + if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_32( st_fx->element_mode, EVS_MONO ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } /*----------------------------------------------------------------* * ACELP subframe loop @@ -156,11 +166,30 @@ Word16 encod_tran_fx( Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, - res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + IF( st_fx->element_mode == EVS_MONO ) + { + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + + Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 ); + Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + } + ELSE + { + find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - Copy_Scale_sig( h1, h2_fx, L_SUBFR, -2 ); - Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + q_h1 = sub( 14, norm_s( h1[0] ) ); + tmp = sub( 14, norm_arr( h1, L_SUBFR ) ); + shift = sub( q_h1, tmp ); /* shift is initialized to shift_r ( to 0) at the beginning of the scope, re-compute shift_wsp in case it has changed */ + shift_wsp = add( Q_new, shift ); + if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } + Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ + Scale_sig( h1, L_SUBFR, add( sub( 14, q_h1 ), shift ) ); + } /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_SUBFR, shift ); @@ -188,7 +217,7 @@ Word16 encod_tran_fx( *-----------------------------------------------------------------*/ inov_encode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, - i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift ); + i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); test(); test(); @@ -230,408 +259,30 @@ Word16 encod_tran_fx( Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); - hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ - L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] ); /* Q10 + Q_new */ - L_tmp = L_shl( L_tmp, add( 5, shift ) ); /* Q15 + Q_new + shift */ - L_tmp = L_negate( L_tmp ); - L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 ); - L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit ); - L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); /* Q_new + 15 */ - hLPDmem->mem_w0 = round_fx_sat( L_tmp ); /*Q_new-1*/ - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - - /* Here, all these conditions have one purpose: to use */ - /* the most efficient loop (the one with the least ops) */ - /* This is done by upscaling gain_pit_fx and/or gain_code16 */ - /* when they don't use all 16 bits of precision */ - - /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */ - IF( norm_s( gain_pit ) == 0 ) + IF( st_fx->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_SUBFR; i++ ) - { - exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_new */ - } + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ } ELSE { - Gain_pitX2 = shl( gain_pit, 1 ); /* Q15 */ - FOR( i = 0; i < L_SUBFR; i++ ) - { - exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_new */ - } - } - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ - L_tmp = L_shl_sat( L_tmp, 5 ); /* Q15 + Q_new */ - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here Q16 + Q_new */ - exc_fx[i + i_subfr] = round_fx_sat( L_tmp ); /* Q_new */ - } - - /*-----------------------------------------------------------------* - * Add the ACELP pre-quantizer contribution - *-----------------------------------------------------------------*/ - - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) - { - tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); - FOR( i = 0; i < L_SUBFR; i++ ) - { - L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ - L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ - tmp_fx = round_fx_sat( L_tmp ); - exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); /* Q_exc */ - move16(); - exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); /* Q_exc */ - move16(); - } - } - - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q10, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - - p_Aw += ( M + 1 ); - p_Aq += ( M + 1 ); - pt_pitch++; - } - - /* write reserved bits */ - WHILE( unbits_PI > 0 ) - { - i = s_min( unbits_PI, 16 ); - push_indice( hBstr, IND_UNUSED, 0, i ); - unbits_PI -= i; - } - - /* write TC configuration */ - IF( EQ_16( L_frame_fx, L_FRAME ) ) - { - IF( EQ_16( tc_subfr, TC_0_0 ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - } - ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( tc_subfr == 0 ) - { - push_indice( hBstr, IND_TC_SUBFR, 0, 2 ); - } - ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 1, 2 ); + hLPDmem->tilt_code = est_tilt_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR ); // Q15 } - ELSE IF( EQ_16( tc_subfr, 2 * L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 2, 2 ); - } - ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 3, 2 ); - push_indice( hBstr, IND_TC_SUBFR, 0, 1 ); - } - ELSE IF( EQ_16( tc_subfr, 4 * L_SUBFR ) ) - { - push_indice( hBstr, IND_TC_SUBFR, 3, 2 ); - push_indice( hBstr, IND_TC_SUBFR, 1, 1 ); - } - } - - IF( st_fx->Opt_SC_VBR ) - { - /* SC-VBR */ - hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */ move16(); - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ - move16(); - } - - return tc_subfr; -} - - -Word16 encod_tran_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Q0*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* i/o: core synthesis Q_new*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q0*/ - Word16 tc_subfr, /* i/o: TC subframe classification Q0*/ - Word16 position, /* i : maximum of residual signal index Q0*/ - Word16 *unbits, /* i/o: number of unused bits Q0*/ - const Word16 shift_r, /* i : Scaling to get 12 bits */ - const Word16 Q_new /* i : Input scaling */ -) -{ - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit = 0, Gain_pitX2, gcode16; /* Pitch gain */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code = 0; /* Gain of code */ - Word32 Lgcode; - Word16 gain_inov = 0; /* inovation gain */ - Word16 i, i_subfr, tmp1_fx, tmp_fx; /* tmp variables */ - Word16 unbits_ACELP; - Word16 T0_min, T0_max; /* pitch and TC variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 *pt_pitch; /* pointer to floating pitch buffer */ - Word16 g_corr[10]; /* ACELP correlation values and gain pitch */ - Word16 clip_gain; /* LSF clip gain */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ - Word16 Jopt_flag; /* joint optimization flag */ - Word16 unbits_PI = 0; /* saved bits for PI */ - Word32 norm_gain_code = 0; - Word16 L_frame_fx; - Word16 shift_wsp; - Word32 L_tmp; - Word16 q_h1; - Word16 shift, tmp; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - shift = shift_r; /* for IVAS, shift_r is always 0 */ - /* will be reusing the EVS shift strategy later on to allow of H1 overshoot */ - move16(); - L_frame_fx = st_fx->L_frame; - move16(); - - set16_fx( h1, 0, L_SUBFR + ( M + 1 ) ); - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - gain_pit = 0; - move16(); - gain_code = L_deposit_l( 0 ); - gain_preQ = 0; - move16(); - unbits_PI = 0; - move16(); - IF( EQ_16( L_frame_fx, L_FRAME ) ) - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max = PIT16k_MAX; - move16(); - T0_min = PIT16k_MIN; - move16(); - } - - /**unbits = 0;move16();*/ - Jopt_flag = 0; - move16(); - unbits_ACELP = *unbits; /* Q0 */ - move16(); - *unbits = 0; - move16(); - - p_Aw = Aw_fx; /* Q12 */ - p_Aq = Aq_fx; /* Q12 */ - pt_pitch = pitch_buf_fx; - gain_preQ = 0; - move16(); - set16_fx( code_preQ, 0, L_SUBFR ); - shift_wsp = add( Q_new, shift ); - if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) - { - shift_wsp = sub( shift_wsp, 1 ); - } - - /*----------------------------------------------------------------* - * ACELP subframe loop - *----------------------------------------------------------------*/ - - FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR ) - { - /*----------------------------------------------------------------* - * Find the the excitation search target "xn" and innovation - * target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - - Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - - - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, - res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - - q_h1 = sub( 14, norm_s( h1[0] ) ); - tmp = sub( 14, norm_arr( h1, L_SUBFR ) ); - shift = sub( q_h1, tmp ); /* shift is initialized to shift_r ( to 0) at the beginning of the scope, re-compute shift_wsp in case it has changed */ - shift_wsp = add( Q_new, shift ); - if ( LT_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) - { - shift_wsp = sub( shift_wsp, 1 ); - } - Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ - Scale_sig( h1, L_SUBFR, add( sub( 14, q_h1 ), shift ) ); - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn, L_SUBFR, shift ); /*-----------------------------------------------------------------* - * TC: subframe determination & - * adaptive/glottal part of excitation construction - *-----------------------------------------------------------------*/ - - transition_enc_ivas_fx( st_fx, i_subfr, &tc_subfr, &Jopt_flag, &position, &T0, &T0_frac, &T0_min, &T0_max, exc_fx, y1, - h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx, &unbits_ACELP, Q_new, shift ); - - /*-----------------------------------------------------------------* - * Transform domain contribution encoding - active frames - *-----------------------------------------------------------------*/ - - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) - { - transf_cdbk_enc_ivas_fx( st_fx, 0, i_subfr, cn, exc_fx, p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, - &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits, Q_new, shift ); - } - - /*-----------------------------------------------------------------* - * ACELP codebook search + pitch sharpening - *-----------------------------------------------------------------*/ - - inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, st_fx->last_L_frame, st_fx->coder_type, st_fx->bwidth, st_fx->sharpFlag, - i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, L_SUBFR, shift, Q_new ); - - test(); - test(); - test(); - if ( ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) && ( tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( T0, 2 * L_SUBFR ) ) ) - { - Jopt_flag = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * Quantize the gains - * Test quantized gain of pitch for pitch clipping algorithm - * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced) + * Update memory of the weighting filter *-----------------------------------------------------------------*/ - IF( Jopt_flag == 0 ) + /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ + IF( st_fx->element_mode == EVS_MONO ) { - /* SQ gain_code */ - gain_enc_tc_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp ); + L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] ); /* Q10 + Q_new */ } ELSE { - IF( GT_32( st_fx->core_brate, ACELP_32k ) ) - { - /* SQ gain_pit and gain_code */ - gain_enc_SQ_fx( hBstr, st_fx->acelp_cfg.gains_mode, i_subfr, xn, y1, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp ); - } - ELSE - { - /* VQ gain_pit and gain_code */ - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame_fx, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } + L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] ); } - gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); - - Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_sat( Lgcode ); - hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15 - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - - /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ - L_tmp = L_mult0( gcode16, y2[L_SUBFR - 1] ); L_tmp = L_shl( L_tmp, add( 5, shift ) ); // Q_new+14+shift L_tmp = L_negate( L_tmp ); L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 ); // Q_new-1+15+shift @@ -654,7 +305,7 @@ Word16 encod_tran_ivas_fx( { FOR( i = 0; i < L_SUBFR; i++ ) { - exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_exc */ + exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_new / Q_exc */ } } ELSE @@ -662,7 +313,7 @@ Word16 encod_tran_ivas_fx( Gain_pitX2 = shl( gain_pit, 1 ); FOR( i = 0; i < L_SUBFR; i++ ) { - exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_exc */ + exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_new / Q_exc */ } } diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index eb614935941d19c4b4c467a5fd05438dc2e914db..160814bc07d2e3c1c319d16d9ca90ebd9b80386c 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -25,17 +25,19 @@ void encod_unvoiced_fx( const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* o : core synthesis Q_new -1 */ + Word16 *syn_fx, /* o : core synthesis Q_new-1 (EVS) / Qnew*/ Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ - const Word16 Q_new, - const Word16 shift ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ + Word16 h2_fx[L_SUBFR]; /* Impulse response vector */ Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ @@ -56,6 +58,8 @@ void encod_unvoiced_fx( Word32 gain_code_vect[2], Ltmp, Ltmp2; Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i; Word16 index, i_subfr_idx; + Word16 unbits_PI; + Word16 q_h1; acelp_cfg = &( st_fx->acelp_cfg ); SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -63,6 +67,7 @@ void encod_unvoiced_fx( /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ + gain_pit_fx = 0; move16(); @@ -79,7 +84,6 @@ void encod_unvoiced_fx( p_Aw_fx = Aw_fx; p_Aq_fx = Aq_fx; pt_pitch_fx = pitch_buf_fx; - move16(); Q_xn = add( sub( Q_new, 1 ), shift ); Q_new_p5 = add( Q_new, 5 ); @@ -94,248 +98,24 @@ void encod_unvoiced_fx( i_subfr_idx = shr( i_subfr, 6 ); Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - - /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ - Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); - - /*----------------------------------------------------------------* - * Unvoiced subframe processing - *----------------------------------------------------------------*/ - - IF( !uc_two_stage_flag ) + IF( st_fx->element_mode == EVS_MONO ) { - *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, - &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, - &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */ + find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); + + /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ } ELSE { - /*----------------------------------------------------------------* - * Unvoiced subframe processing in two stages - *----------------------------------------------------------------*/ - - /* No adaptive codebook (UC) */ - set16_fx( y1, 0, L_SUBFR ); - set16_fx( exc_fx + i_subfr, 0, L_SUBFR ); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - - Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); - *pt_pitch_fx = L_SUBFR; - move16(); - - /*----------------------------------------------------------------------* - * Encode the algebraic innovation * - *----------------------------------------------------------------------*/ - - E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate ); - - E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn ); - - g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 ); /* -18 (y2*y2: Q9*Q9) */ - g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ - g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ - g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) ); /* -(Q_xn+Q_xn) (xn: Q_xn) */ - - assert( gain_pit_fx == 0 ); - gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); - - /*----------------------------------------------------------* - * - Compute the fixed codebook gain * - * - quantize fixed codebook gain * - *----------------------------------------------------------*/ - - index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, - st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */ - -#ifdef DEBUGGING - assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); -#endif - push_indice( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] ); - - gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); - - gain_code_vect[0] = L_gain_code_fx; - move32(); - gain_code_vect[1] = L_gain_code_fx; - move32(); - - /*----------------------------------------------------------* - * - voice factor (for pitch enhancement) * - *----------------------------------------------------------*/ - - E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift ); - - IF( st_fx->Opt_RF_ON ) - { - st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code; - } - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ + find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, + res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */ - Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); /* Q15 + Q_xn */ - Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); /* Q15 + Q_xn */ - /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */ - Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); /* Q15 + Q_xn */ - Ltmp = L_add( Ltmp, Ltmp2 ); /* Q15 + Q_xn */ - hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); /* Q_xn */ - move16(); - BASOP_SATURATE_WARNING_OFF_EVS; - hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/ - BASOP_SATURATE_WARNING_ON_EVS; - - /*-------------------------------------------------------* - * - Find the total excitation. * - *-------------------------------------------------------*/ - - tmp2 = shr( L_SUBFR, 1 ); - FOR( j = 0; j < 2; j++ ) - { - FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) - { - /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ - Ltmp = L_shl( Ltmp, Q_new_p5 ); /* Q15 + Q_new */ - Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q_new + Q15 */ - Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); /* Q10 */ - Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */ - Ltmp = L_add( Ltmp, Ltmp2 ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ - exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ - } - tmp2 = L_SUBFR; - move16(); - } + q_h1 = sub( 14, norm_s( h1_fx[0] ) ); + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); + Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); } - *tmp_noise_fx = extract_h( norm_gain_code_fx ); /* Q0 */ - voice_factors_fx[i_subfr / L_SUBFR] = 0; - move16(); - - interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - - p_Aw_fx += ( M + 1 ); - p_Aq_fx += ( M + 1 ); - pt_pitch_fx++; - } - - /* SC-VBR */ - hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */ - move16(); - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ - move16(); - - return; -} - - -void encod_unvoiced_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ - const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ - const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* o : core synthesis Q_new*/ - Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ - const Word16 Q_new, - const Word16 shift ) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 gain_pit_fx; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 L_gain_code_fx; /* gain of code */ - Word16 gain_inov_fx; /* inovative gain */ - Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code2[L_SUBFR]; /* Gaussian excitation */ - Word16 y22[L_SUBFR]; /* Filtered Gaussian excitation */ - // Word16 prm_t[2 * NPRM_DIV], *prm = prm_t; - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ - Word32 norm_gain_code_fx; - ACELP_config *acelp_cfg; - ACELP_CbkCorr g_corr; - Word32 gain_code2; - Word32 gain_code_vect[2], Ltmp, Ltmp2; - Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i; - Word16 index, i_subfr_idx; - Word16 unbits_PI; - Word16 q_h1; - acelp_cfg = &( st_fx->acelp_cfg ); - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - gain_pit_fx = 0; - move16(); - - test(); - test(); - test(); - IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) ) - { - /* SC_VBR - reset the encoder, to avoid memory not updated issue for the - case when UNVOICED mode is used to code inactive speech */ - CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 ); - } - - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; - Q_xn = add( sub( Q_new, 1 ), shift ); - Q_new_p5 = add( Q_new, 5 ); - - FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) - { - /*----------------------------------------------------------------* - * Bandwidth expansion of A(z) filter coefficients - * Find the excitation search target "xn" and innovation target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - - i_subfr_idx = shr( i_subfr, 6 ); - Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - - q_h1 = sub( 14, norm_s( h1_fx[0] ) ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); - Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) ); - /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift @@ -366,16 +146,28 @@ void encod_unvoiced_ivas_fx( *-----------------------------------------------------------------*/ Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn ); + *pt_pitch_fx = L_SUBFR << 6; move16(); + if ( st_fx->element_mode == EVS_MONO ) + { + *pt_pitch_fx = L_SUBFR; + move16(); + } /*----------------------------------------------------------------------* * Encode the algebraic innovation * *----------------------------------------------------------------------*/ - inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, - UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx, - gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); + IF( st_fx->element_mode == EVS_MONO ) + { + E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate ); + } + ELSE + { + inov_encode_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame, UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx, + gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new ); + } E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn ); @@ -389,7 +181,14 @@ void encod_unvoiced_ivas_fx( move16(); assert( gain_pit_fx == 0 ); - gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + IF( st_fx->element_mode == EVS_MONO ) + { + gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + } + ELSE + { + gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift ); + } /*----------------------------------------------------------* * - Compute the fixed codebook gain * diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index b9ea2d49e442f76dd864cf37b2ed88905a7e7c9b..dae547e35456e4dd0c35e24426621ba2c87234ad 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -89,7 +89,17 @@ Word16 Pit_exc_contribution_len_fx( move16(); } - minimum_fx( pitch_buf, nb_subfr, &low_pit ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); // This should be the only version if #2253 is included in #1292 + } + ELSE +#endif + { + minimum_fx( pitch_buf, nb_subfr, &low_pit ); + } + exp1 = norm_s( low_pit ); tmp = shl( low_pit, exp1 ); tmp_dec = 12800; @@ -381,13 +391,18 @@ Word16 Pit_exc_contribution_len_fx( set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k ); /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ +#ifdef FIX_1904_HARM_GSC_ENC + FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) +#else for ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) +#endif { delete_indice( hBstr, i ); } delete_indice( hBstr, IND_ES_PRED ); } + IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) @@ -416,16 +431,13 @@ Word16 Pit_exc_contribution_len_fx( return last_pit_bin; } - +#ifndef FIX_1904_HARM_GSC_ENC Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */ Encoder_State *st_fx, /* i/o: state structure */ const Word16 *dct_res, /* i : DCT of residual Q_new*/ Word16 *dct_pitex, /* i/o: DCT of pitch contribution Q_new*/ Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ -#ifndef FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ -#endif - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ) { @@ -457,11 +469,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher Mbands_loc = MBANDS_LOC; move16(); } -#ifndef FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH - minimum_fx( pitch_buf, nb_subfr, &low_pit ); -#else minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); -#endif exp1 = norm_s( low_pit ); tmp = shl( low_pit, exp1 ); tmp_dec = 12800; @@ -785,3 +793,4 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher return last_pit_bin; } +#endif diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 416c2f4e974134a63139b6f4cb74cd4dc16b3a02..8dfb02edabe899b9940dd54a4615cb8b2e5eb5e9 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -43,11 +43,13 @@ ivas_error evs_enc_fx( Word32 ener; /* residual energy from Levinson-Durbin */ Word16 A[NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ - Word16 epsP_h[M + 1]; /* LP prediction errors */ - Word16 epsP_l[M + 1]; /* LP prediction errors */ - Word32 epsP[M + 1]; /* LP prediction errors */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ +#ifndef HARMONIZE_ACELP_ENC + Word16 epsP_h[M + 1]; /* LP prediction errors */ + Word16 epsP_l[M + 1]; /* LP prediction errors */ +#endif + Word32 epsP[M + 1]; /* LP prediction errors */ + Word16 lsp_new[M]; /* LSPs at the end of the frame */ + Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ Word16 vad_hover_flag; Word16 hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ @@ -79,9 +81,6 @@ ivas_error evs_enc_fx( #endif ivas_error error; SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - // NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; - // VAD_HANDLE hVAD = st->hVAD; - // DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; LPD_state_HANDLE hLPDmem = st->hLPDmem; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; @@ -95,7 +94,6 @@ ivas_error evs_enc_fx( Q_shb_spch = 0; move16(); /* to avoid compiler warnings */ - /*------------------------------------------------------------------* * Initializiation *-----------------------------------------------------------------*/ @@ -176,19 +174,25 @@ ivas_error evs_enc_fx( /*---------------------------------------------------------------------* * Pre-processing *---------------------------------------------------------------------*/ + #ifdef FIX_I4_OL_PITCH - pre_proc( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type ); +#ifdef HARMONIZE_ACELP_ENC + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, #else - pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, - pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, - &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, - &hq_core_type, &Q_new, &shift, Q_r ); + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, +#endif + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); +#else +#ifdef HARMONIZE_ACELP_ENC + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, pitch_orig, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, +#else + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, +#endif + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #endif - // st->sharpFlag = sharpFlag; IF( EQ_16( st->mdct_sw, MODE2 ) ) { - Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ st->bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ @@ -260,7 +264,7 @@ ivas_error evs_enc_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_pre_enc_fx( st, old_inp_12k8, old_inp_16k, 0, 0 ); + core_switching_pre_enc_fx( st, old_inp_12k8, 0, old_inp_16k, 0, 0, 0 ); /*---------------------------------------------------------------------* * ACELP core encoding @@ -268,9 +272,17 @@ ivas_error evs_enc_fx( IF( EQ_16( st->core, ACELP_CORE ) ) { +#ifdef HARMONIZE_ACELP_ENC + IF( NE_32( ( error = acelp_core_enc_fx( st, inp, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL, Q_new, shift ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, Q_new, shift ); +#endif } + /*---------------------------------------------------------------------* * HQ core encoding *---------------------------------------------------------------------*/ @@ -283,6 +295,7 @@ ivas_error evs_enc_fx( /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ + core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, A, shift, Q_new, st->Q_syn2, &Q_synth ); #ifndef FIX_I4_OL_PITCH IF( EQ_16( st->core, HQ_CORE ) ) @@ -427,8 +440,11 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ +#ifdef HARMONIZE_TBE + wb_tbe_enc_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); +#else wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); - +#endif IF( EQ_16( st->codec_mode, MODE2 ) ) { tbe_write_bitstream_fx( st ); @@ -444,6 +460,7 @@ ivas_error evs_enc_fx( * SWB(FB) TBE encoding * SWB BWE encoding *---------------------------------------------------------------------*/ + test(); IF( !st->Opt_SC_VBR && GE_32( st->input_Fs, 32000 ) ) { @@ -473,7 +490,11 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ +#ifdef HARMONIZE_TBE + fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc, 0 ); +#else fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); +#endif } IF( EQ_16( st->codec_mode, MODE2 ) ) @@ -531,9 +552,13 @@ ivas_error evs_enc_fx( * Channel-aware mode - write signaling information into the bitstream *---------------------------------------------------------------------*/ - signalling_enc_rf_fx( st ); + signaling_enc_rf_fx( st ); - updt_enc_common_fx( st, Etot, Q_new ); + /*---------------------------------------------------------------------* + * Updates + *---------------------------------------------------------------------*/ + + updt_enc_common_fx( st, Q_new ); if ( EQ_16( st->mdct_sw, MODE1 ) ) { @@ -642,9 +667,11 @@ static void initFrameHeader_loc( Encoder_State *st ) * * Write MODE2 frame header *-------------------------------------------------------------------*/ -static void writeFrameHeader_loc( Encoder_State *st ) -{ +static void writeFrameHeader_loc( + Encoder_State *st /* i/o: encoder state structure */ +) +{ BSTR_ENC_HANDLE hBstr = st->hBstr; IF( NE_32( st->core_brate, FRAME_NO_DATA ) ) diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 435bfb52dc7f04f49d042556868e5322bcfe7bd0..33181714765ea239bdf078dacdcc47392a934156 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -6,13 +6,11 @@ #include #include "options.h" #include "cnst.h" -// #include "prot_fx.h" #include "rom_com.h" #include "basop_util.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include -#include /*-------------------------------------------------------------------* @@ -426,7 +424,7 @@ void core_signal_analysis_high_bitrate_fx( interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; /* exp(spectrum_e) */ move32(); } - MVR2R_WORD32( interleaveBuf, spectrum[frameno], tcx10SizeFB ); + Copy32( interleaveBuf, spectrum[frameno], tcx10SizeFB ); } /*--------------------------------------------------------------* @@ -456,7 +454,7 @@ void core_signal_analysis_high_bitrate_fx( } /* Copy memory */ - MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); /* Q15 */ + Copy( lsp_new, st->lspold_enc_fx, M ); /* Q15 */ } } @@ -601,7 +599,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( { Copy( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame ); // Assuming both exp_buf_speech_enc_pe and exp_buf_speech_enc are same - PREEMPH_FX( st->new_speech_enc_pe, st->preemph_fac, L_frame, &( st->mem_preemph_enc ) ); // using this to keep values alligned in Q-1 + preemph_fx( st->new_speech_enc_pe, st->preemph_fac, L_frame, &( st->mem_preemph_enc ) ); // using this to keep values alligned in Q-1 } /* Rescale Memory */ @@ -1134,7 +1132,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { Word16 Q; - Copy_Scale_sig_16_32_no_sat( mdstWin, L_tmpbuf, N_MAX + L_MDCT_OVLP_MAX, 16 ); + Copy_Scale_sig_16_32_no_sat( mdstWin, L_tmpbuf, L_subframe, 16 ); Q = add( q_mdstWin, 16 ); move16(); @@ -1223,7 +1221,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( interleaveBuf[2 * i + 1] = hTcxEnc->spectrum_fx[frameno][tcx5SizeFB + i]; /* hTcxEnc->spectrum_e */ move32(); } - MVR2R_WORD32( interleaveBuf, hTcxEnc->spectrum_fx[frameno], tcx10SizeFB ); + Copy32( interleaveBuf, hTcxEnc->spectrum_fx[frameno], tcx10SizeFB ); } /*--------------------------------------------------------------* @@ -1261,7 +1259,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { /* Copy memory */ - MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); + Copy( lsp_new, st->lspold_enc_fx, M ); } return; diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index 5b3ab4792a05a9c77c52a5183f23f976b7a2f5bd..9a236731f51865204b2cfdcd8f9a5b65b6aec7fe 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -173,7 +173,8 @@ void find_targets_ivas_fx( { Word16 i; Word16 temp[M + 6 * L_SUBFR]; /* error of quantization */ - Word16 scale, scaleq, j, d, s, s2, tmp; + Word16 scale, scaleq, j, d, s, tmp; + Word32 s2; Word16 Aqs[M + 1]; Word32 h1_32[6 * L_SUBFR]; Word16 sf; @@ -233,44 +234,44 @@ void find_targets_ivas_fx( { Copy( p_Aq, Aqs, M + 1 ); /* Q12 */ s = add( scaleq, 1 ); - s2 = shr( 16384, d ); + s2 = L_shr( ( 16384 << 16 ), d ); } ELSE { Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); /* Q12 */ s = add( scale, 1 ); - s2 = 16384; - move16(); + s2 = ( 16384 << 16 ); + move32(); } set32_fx( h1_32, 0, L_subfr ); FOR( i = 0; i < M; i++ ) { - Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ + Ltmp64 = W_mult_32_16( s2, Ap[i] ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { - Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_sat( h1_32[i - j], s ) ) ); /* Q27 */ + Ltmp64 = W_msu_32_16( Ltmp64, L_shl_sat( h1_32[i - j], s ), Aqs[j] ); /* Q27 */ } - h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */ + h1_32[i] = W_sat_m( Ltmp64 ); /* Q27 */ move32(); } - Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ + Ltmp64 = W_mult_32_16( s2, Ap[i] ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { - Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_sat( h1_32[i - j], s ) ) ); /* Q27 */ + Ltmp64 = W_msu_32_16( Ltmp64, L_shl_sat( h1_32[i - j], s ), Aqs[j] ); /* Q27 */ } - h1_32[M] = W_extract_l( Ltmp64 ); /* Q27 */ + h1_32[M] = W_sat_m( Ltmp64 ); /* Q27 */ move32(); FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp64 = W_msu_16_16( 0, Aqs[1], extract_h( L_shl_sat( h1_32[i - 1], s ) ) ); /* Q27 */ + Ltmp64 = W_msu_32_16( 0, L_shl_sat( h1_32[i - 1], s ), Aqs[1] ); /* Q27 */ FOR( j = 2; j <= M; j++ ) { - Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_sat( h1_32[i - j], s ) ) ); /* Q27 */ + Ltmp64 = W_msu_32_16( Ltmp64, L_shl_sat( h1_32[i - j], s ), Aqs[j] ); /* Q27 */ } - h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */ + h1_32[i] = W_sat_m( Ltmp64 ); /* Q27 */ move32(); } diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index a0fa4dbbd163b2de097f81659d929125cf00aaf7..063989affe6fee9784922d101ecaa172c316fd8c 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -1,14 +1,15 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ #include "rom_com.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ + /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -23,9 +24,10 @@ * energy is trailing off after a spike *-------------------------------------------------------------------*/ -static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10*/ - const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search Q0*/ - const Word32 *pt_enr_ssf /* i : Pointer to the energy buffer Qx*/ +/*! r: maximum energy ratio Q10*/ +static Word16 find_ener_decrease_fx( + const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search Q0*/ + const Word32 *pt_enr_ssf /* i : Pointer to the energy buffer Qx*/ ) { Word16 i, j, end, flag; @@ -65,7 +67,6 @@ static Word16 find_ener_decrease_fx( /* o : maximum minEnr = L_min( minEnr, pt_enr_ssf[i] ); /* Qx */ } - minEnr = L_add_sat( minEnr, 100000 ); exp0 = norm_l( minEnr ); wtmp0 = extract_h( L_shl( minEnr, exp0 ) ); @@ -77,27 +78,31 @@ static Word16 find_ener_decrease_fx( /* o : maximum return dE2; } + /*-------------------------------------------------------------------* * find_uv_fx() * * Decision about coder type *-------------------------------------------------------------------*/ -Word16 find_uv_fx( /* o : coding type */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ - const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ - const Word16 relE, /* i : relative frame energy Q8*/ - const Word16 Etot, /* i : total energy Q8*/ - const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ - const Word16 Q_new, - Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation Q0*/ - const Word16 shift, - const Word16 last_core_orig /* i : original last core Q0*/ -) +/*! r: coder type */ +Word16 find_uv_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ + const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ + const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ + const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ + Word32 *dE1X, /* o : sudden energy increase for S/M classifier Q13*/ + const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ + const Word16 relE, /* i : relative frame energy Q8*/ + const Word16 Etot, /* i : total energy Q8*/ + const Word32 hp_E[], /* i : energy in HF q_hp_E*/ + Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation Q0*/ + const Word16 last_core_orig, /* i : original last core Q0*/ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const Word16 Q_new, + const Word16 shift, + const Word16 q_hp_E ) { Word16 coder_type, i; Word32 mean_ee, dE1, fac_32; @@ -106,7 +111,7 @@ Word16 find_uv_fx( /* o : coding type Word16 dE2; Word16 ind_deltaMax, tmp_offset_flag; Word32 Ltmp0, *pt_enr_ssf, *pt_enr_ssf1, dE2_th; - Word16 exp0, exp1, Q_in; + Word16 exp0, exp1; Word16 wtmp0, wtmp1; Word16 fac, mean_voi3, dE3; Word16 relE_thres; @@ -117,497 +122,16 @@ Word16 find_uv_fx( /* o : coding type SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; Word16 Last_Resort; Word16 vadnoise; + Word16 Q_in, loc_lp_noise; - IF( hSC_VBR != NULL ) - { - Last_Resort = hSC_VBR->Last_Resort; /* Q0 */ - vadnoise = hSC_VBR->vadnoise_fx; - move16(); - move16(); - } - ELSE - { - Last_Resort = 0; - vadnoise = 0; - move16(); - move16(); - } - - Q_in = sub( Q_new, 1 ); - - /*-----------------------------------------------------------------* - * Detect sudden energy increases to catch voice and music - * temporal events (dE1) - * - * - Find maximum energy per short subblocks. - * Two subblock sets are used shifted by half the subblock length - * - Find maximum energy ratio between adjacent subblocks - *-----------------------------------------------------------------*/ - - /* Find maximum energy per short subblocks */ - pt_speech = speech - SSF; /* Q_new */ - pt_enr_ssf = enr_ssf + 2 * NB_SSF; - FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ ) - { - emaximum_fx( Q_in, pt_speech, SSF, pt_enr_ssf ); - pt_speech += ( SSF / 2 ); - pt_enr_ssf++; - } - - dE1 = 0; - move16(); - ind_deltaMax = 0; - move16(); - pt_enr_ssf = enr_ssf + 2 * NB_SSF; - pt_enr_ssf1 = pt_enr_ssf + 2; - - /* Test on energy increase between adjacent sub-subframes */ - exp1 = 0; - move16(); - FOR( i = 0; i < 2 * NB_SSF; i++ ) - { - /*fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1);*/ - Ltmp0 = L_max( *pt_enr_ssf, 1 ); - exp0 = norm_l( Ltmp0 ); - wtmp0 = extract_h( L_shl( Ltmp0, exp0 ) ); - exp1 = sub( norm_l( *pt_enr_ssf1 ), 1 ); - wtmp1 = extract_h( L_shl( *pt_enr_ssf1, exp1 ) ); - fac = div_s( wtmp1, wtmp0 ); - fac_32 = L_shr_sat( L_deposit_l( fac ), add( sub( exp1, exp0 ), 15 - 13 ) ); /* fac32 in Q13*/ - - if ( GT_32( fac_32, dE1 ) ) - { - ind_deltaMax = i; - move16(); - } - - dE1 = L_max( dE1, fac_32 ); /* Q13 */ - - pt_enr_ssf++; - pt_enr_ssf1++; - } - - /*-----------------------------------------------------------------* - * Average spectral tilt - * Average voicing (normalized correlation) - *-----------------------------------------------------------------*/ - - /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ - mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */ - mean_ee = Mult_32_16( mean_ee, 10923 /* 1/3 in Q15 */ ); /*Q6*/ - - /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ - Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ ); /* Q31 */ - Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 /* 1/3 in Q15 */ ); /* Q31 */ - mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 /* 1/3 in Q15 */ ); /*Q15*/ - /*-----------------------------------------------------------------* - * Total frame energy difference (dE3) - *-----------------------------------------------------------------*/ - - dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/ - - /*-----------------------------------------------------------------* - * Energy decrease after spike (dE2) - *-----------------------------------------------------------------*/ - - /* set different thresholds and conditions for NB and WB input */ - dE2_th = 30 << 10; - move32(); - nb_cond = 1; - move16(); /* no additional condition for WB input */ - IF( EQ_16( st_fx->input_bwidth, NB ) ) - { - dE2_th = 21 << 10; - move32(); - if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 /* 0.68 in Q15 */ ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ - { - nb_cond = 0; - move16(); - } - } - - /* calcualte maximum energy decrease */ - dE2 = 0; - move16(); /* Test on energy decrease after an energy spike */ - pt_enr_ssf = enr_ssf + 2 * NB_SSF; - - test(); - IF( GT_32( dE1, 30 << 13 ) && nb_cond ) /*>30 Q13*/ - { - IF( LT_16( sub( shl( NB_SSF, 1 ), ind_deltaMax ), L_ENR ) ) - { - st_fx->old_ind_deltaMax = ind_deltaMax; /* Q0 */ - move16(); - Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2 * NB_SSF ); /* Qx */ - } - ELSE - { - st_fx->old_ind_deltaMax = -1; - move16(); - dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/ - - if ( GT_32( dE2, dE2_th ) ) - { - st_fx->spike_hyst = 0; - move16(); - } - } - } - ELSE - { - IF( st_fx->old_ind_deltaMax >= 0 ) - { - Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2 * NB_SSF ); /* Qx */ - dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax, enr_ssf ); /* Q10 */ - - if ( GT_32( dE2, dE2_th ) ) - { - st_fx->spike_hyst = 1; - move16(); - } - } - - st_fx->old_ind_deltaMax = -1; - move16(); - } - - /*-----------------------------------------------------------------* - * Detection of voiced offsets (tmp_offset_flag) - *-----------------------------------------------------------------*/ - - tmp_offset_flag = 1; + Q_in = Q_new; move16(); - IF( NE_16( st_fx->input_bwidth, NB ) ) - { - ee0_th = 154; /*2.4 in Q6 */ - move16(); - voi_th = 24248; /*0.74f Q15 */ - move16(); - } - ELSE - { - ee0_th = 627; /*9.8f Q6 */ - move16(); - voi_th = 24904; /*0.76f Q15*/ - move16(); - } - - test(); - test(); - test(); - if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ - ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], L_shl( E_MIN_FX, Q_new ) ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) ) /* normalized correlation is low */ - { - tmp_offset_flag = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * Decision about UC - *-----------------------------------------------------------------*/ - - /* SC-VBR - set additional parameters and thresholds for SC-VBR */ - mean_voi3_offset = 0; - move16(); - flag_low_relE = 0; - move16(); - ee1_th = 608; /*9.5 Q6*/ - move16(); - IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */ + if ( st_fx->element_mode == EVS_MONO ) { - ee1_th = 544; /*8.5f Q6*/ - move16(); - - /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */ - IF( NE_16( st_fx->input_bwidth, NB ) ) - { - /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */ - L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, st_fx->lp_noise_fx ); // Q24 - if ( Last_Resort == 0 ) - { - /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, st_fx->lp_noise_fx ); // Q24 - } - relE_thres = round_fx( L_tmp ); - } - ELSE - { - - /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, st_fx->lp_noise_fx ); // Q24 - relE_thres = round_fx( L_tmp ); - } - relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */ - - /* SC-VBR = set flag on low relative energy */ - if ( LT_16( relE, relE_thres ) ) - { - flag_low_relE = 1; - move16(); - } - - /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */ - test(); - if ( EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) ) /* vadnoise in Q8, constant Q0<<8 */ - { - mean_voi3_offset = 1638; /*0.05f Q15*/ - move16(); - } + Q_in = sub( Q_new, 1 ); } - /* make decision whether frame is unvoiced */ - E_min_th = L_shl( E_MIN_FX, Q_new ); - coder_type = GENERIC; - move16(); - IF( EQ_16( st_fx->input_bwidth, NB ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ - { - coder_type = UNVOICED; - move16(); - } - } - ELSE - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ - { - coder_type = UNVOICED; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Decision about VC - *-----------------------------------------------------------------*/ - if ( st_fx->Opt_SC_VBR ) - { - hSC_VBR->set_ppp_generic = 0; - } - move16(); - - test(); - test(); - IF( EQ_16( st_fx->localVAD, 1 ) && EQ_16( coder_type, GENERIC ) && NE_16( last_core_orig, AMR_WB_CORE ) ) - { - dpit1 = abs_s( sub( T_op_fr[1], T_op_fr[0] ) ); // Q6 - dpit2 = abs_s( sub( T_op_fr[2], T_op_fr[1] ) ); // Q6 - dpit3 = abs_s( sub( T_op_fr[3], T_op_fr[2] ) ); // Q6 - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GT_16( voicing_fr[0], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 1st sf. */ - ( GT_16( voicing_fr[1], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 2st sf. */ - ( GT_16( voicing_fr[2], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 3st sf. */ - ( GT_16( voicing_fr[3], 19825 /* 0.605 in Q15 */ ) ) && /* normalized correlation high in 4st sf. */ - ( GT_32( mean_ee, 256 /* 4.0f in Q6 */ ) ) && /* energy concentrated in low frequencies */ - ( LT_16( dpit1, 3 << 6 ) ) && - ( LT_16( dpit2, 3 << 6 ) ) && - ( LT_16( dpit3, 3 << 6 ) ) ) - { - coder_type = VOICED; - move16(); - } - ELSE IF( st_fx->Opt_SC_VBR && EQ_16( st_fx->input_bwidth, NB ) && LT_16( vadnoise, 20 << 8 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_16( voicing_fr[0], 8192 /* 0.25 in Q15 */ ) && /* normalized correlation high in 1st sf. */ - ( GT_16( voicing_fr[1], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 2st sf. */ - ( GT_16( voicing_fr[2], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 3st sf. */ - ( GT_16( voicing_fr[3], 8192 /* 0.25 in Q15 */ ) ) && /* normalized correlation high in 4st sf. */ - ( GT_32( mean_ee, 64 ) ) && /* energy concentrated in low frequencies */ - ( LT_16( dpit1, 5 << 6 ) ) && - ( LT_16( dpit2, 5 << 6 ) ) && - ( LT_16( dpit3, 5 << 6 ) ) ) - { - hSC_VBR->set_ppp_generic = 1; - move16(); - coder_type = VOICED; - move16(); - } - } - - /* set VOICED mode for frames with very stable pitch and high correlation - and avoid to switch to AUDIO/MUSIC later */ - voicing_m = mac_r( L_mac( L_mac( L_mult( voicing_fr[3], 8192 /* 0.25 in Q15 */ ), voicing_fr[2], 8192 /* 0.25 in Q15 */ ), voicing_fr[1], 8192 /* 0.25 in Q15 */ ), voicing_fr[0], 8192 /* 0.25 in Q15 */ ); - test(); - test(); - test(); - test(); - test(); - IF( *flag_spitch || ( LE_16( dpit1, 3 << 6 ) && LE_16( dpit2, 3 << 6 ) && LE_16( dpit3, 3 << 6 ) && - GT_16( voicing_m, 31130 /* 0.95f in Q15 */ ) && GT_16( st_fx->voicing_sm_fx, 31785 /* 0.97f in Q15 */ ) ) ) - { - coder_type = VOICED; - move16(); - *flag_spitch = 1; - move16(); /*to avoid switch to AUDIO/MUSIC later*/ - } - } - - /*-----------------------------------------------------------------* - * Channel-aware mode - set RF mode and total bitrate - *-----------------------------------------------------------------*/ - - st_fx->rf_mode = st_fx->Opt_RF_ON; /* Q0 */ - move16(); - - IF( EQ_16( coder_type, GENERIC ) ) - { - test(); - test(); - test(); - test(); - IF( ( LT_16( voicing_fr[0], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf. */ - ( LT_16( voicing_fr[1], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 2st sf. */ - ( LT_16( voicing_fr[2], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 3rd sf. */ - ( LT_16( voicing_fr[3], 6554 /* 0.2f in Q15 */ ) ) && /* normalized correlation high in 4th sf. */ - ( GT_16( vadnoise, 25 << 8 ) ) ) /* when speech is clean */ - - { - st_fx->rf_mode = 0; - move16(); - /* Current frame cannot be compressed to pack the partial redundancy;*/ - - if ( st_fx->rf_mode != st_fx->Opt_RF_ON ) - { - core_coder_mode_switch_fx( st_fx, st_fx->last_total_brate, 0, shift ); - } - } - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update spike hysteresis parameters */ - test(); - if ( st_fx->spike_hyst >= 0 && LT_16( st_fx->spike_hyst, 2 ) ) - { - st_fx->spike_hyst = add( st_fx->spike_hyst, 1 ); /* Q0 */ - } - - /* reset spike hysteresis */ - test(); - test(); - test(); - if ( ( GT_16( st_fx->spike_hyst, 1 ) ) && - ( GT_16( dE3, 5 << 8 ) || /* energy increases */ - ( GT_16( relE, -3328 ) && ( GT_16( add_sat( mean_voi3, corr_shift ), 22774 ) ) ) ) ) /* normalized correlation is high */ - { - st_fx->spike_hyst = -1; - move16(); - } - - /* update tilt parameters */ - st_fx->ee_old_fx = ee[1]; - move32(); /*Q6*/ - st_fx->old_dE1_fx = dE1; - move32(); /*Q13*/ - - /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */ - st_fx->coder_type_raw = coder_type; - move16(); - - return coder_type; -} - -/*-------------------------------------------------------------------* - * find_uv() - * - * Decision about coder type - *-------------------------------------------------------------------*/ -Word16 find_uv_ivas_fx( /* o : coding type */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ - const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ - Word32 *dE1X, /* o : sudden energy increase for S/M classifier Q13*/ - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ - const Word16 relE, /* i : relative frame energy Q8*/ - const Word16 Etot, /* i : total energy Q8*/ - const Word32 hp_E[], /* i : energy in HF q_hp_E*/ - Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation Q0*/ - const Word16 last_core_orig, /* i : original last core Q0*/ - STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - const Word16 Q_new, - const Word16 q_hp_E ) -{ - Word16 coder_type, i; - Word32 mean_ee, dE1, fac_32; - const Word16 *pt_speech; - Word32 L_tmp, enr_ssf[2 * NB_SSF + 2 * NB_SSF + 2], E_min_th; - Word16 dE2; - Word16 ind_deltaMax, tmp_offset_flag; - Word32 Ltmp0, *pt_enr_ssf, *pt_enr_ssf1, dE2_th; - Word16 exp0, exp1; - Word16 wtmp0, wtmp1; - Word16 fac, mean_voi3, dE3; - Word16 relE_thres; - Word16 mean_voi3_offset; - Word16 voicing_m, dpit1, dpit2, dpit3; - Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE; - NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - Word16 Last_Resort; - Word16 vadnoise; - IF( hSC_VBR != NULL ) { Last_Resort = hSC_VBR->Last_Resort; /* Q0 */ @@ -637,7 +161,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ pt_enr_ssf = enr_ssf + 2 * NB_SSF; FOR( i = 0; i < 2 * ( NB_SSF + 1 ); i++ ) { - emaximum_fx( Q_new, pt_speech, SSF, pt_enr_ssf ); + emaximum_fx( Q_in, pt_speech, SSF, pt_enr_ssf ); pt_speech += ( SSF / 2 ); pt_enr_ssf++; } @@ -675,7 +199,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ pt_enr_ssf1++; } - IF( hStereoClassif != NULL ) + IF( hStereoClassif != NULL ) /* IVAS only */ { IF( st_fx->idchan == 0 ) { @@ -712,11 +236,19 @@ Word16 find_uv_ivas_fx( /* o : coding typ Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ ); /* Q31 */ Ltmp0 = L_mac( Ltmp0, st_fx->voicing_fx[1], 10923 /* 1/3 in Q15 */ ); /* Q31 */ mean_voi3 = mac_r_sat( Ltmp0, st_fx->voicing_fx[2], 10923 /* 1/3 in Q15 */ ); /*Q15*/ + /*-----------------------------------------------------------------* * Total frame energy difference (dE3) *-----------------------------------------------------------------*/ - dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/ + IF( st_fx->element_mode == EVS_MONO ) /* Overwrite dE3 in case of EVS */ + { + dE3 = sub( Etot, hNoiseEst->Etot_last_fx ); /*Q8*/ + } + ELSE + { + dE3 = sub( Etot, extract_h( hNoiseEst->Etot_last_32fx ) ); /*Q8*/ + } /*-----------------------------------------------------------------* * Energy decrease after spike (dE2) @@ -806,6 +338,10 @@ Word16 find_uv_ivas_fx( /* o : coding typ } E_min_th = L_shl( E_MIN_IVAS_FX_Q31, sub( q_hp_E, Q31 ) ); + if ( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ + { + E_min_th = L_shl( E_MIN_FX, Q_new ); + } test(); test(); @@ -830,6 +366,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ move16(); ee1_th = 608; /*9.5 Q6*/ move16(); + test(); test(); IF( st_fx->Opt_SC_VBR || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) /* Allow the low energy flag for the secondary channel */ @@ -837,15 +374,24 @@ Word16 find_uv_ivas_fx( /* o : coding typ ee1_th = 544; /*8.5f Q6*/ move16(); + IF( st_fx->element_mode == EVS_MONO ) /* Overwrite E_min_th in case of EVS */ + { + loc_lp_noise = st_fx->lp_noise_fx; + } + ELSE + { + loc_lp_noise = extract_h( st_fx->lp_noise_32fx ); + } + /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */ IF( st_fx->input_bwidth != NB ) { /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */ - L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 + L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 22938 /* 0.7 in Q15 */, loc_lp_noise ); // Q24 IF( Last_Resort == 0 ) { /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 + L_tmp = L_mac( -562036736 /* 33.5f in Q24 */, 21299 /* 0.650f in Q15 */, loc_lp_noise ); // Q24 } relE_thres = round_fx( L_tmp ); } @@ -853,7 +399,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ { /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, extract_h( st_fx->lp_noise_32fx ) ); // Q24 + L_tmp = L_mac( -473117491 /* 28.2f in Q24 */, 19661 /* 0.6f in Q15 */, loc_lp_noise ); // Q24 relE_thres = round_fx( L_tmp ); } relE_thres = s_max( relE_thres, -6400 /* -25.0f in Q8 */ ); /* Q8 */ @@ -889,22 +435,39 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); test(); - IF( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); } } + ELSE IF( st_fx->element_mode == EVS_MONO ) + { + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ + { + coder_type = UNVOICED; + move16(); + } + } ELSE { test(); @@ -917,7 +480,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ + /* ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ @@ -935,6 +498,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ /*-----------------------------------------------------------------* * Decision about VC *-----------------------------------------------------------------*/ + if ( st_fx->Opt_SC_VBR ) { hSC_VBR->set_ppp_generic = 0; @@ -1035,11 +599,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ { st_fx->rf_mode = 0; move16(); - /* Current frame cannot be compressed to pack the partial redundancy;*/ - IF( NE_16( st_fx->rf_mode, st_fx->Opt_RF_ON ) ) + /* Current frame cannot be compressed to pack the partial redundancy */ + IF( NE_16( st_fx->rf_mode, st_fx->Opt_RF_ON ) ) /* can happen only for EVS format */ { - core_coder_mode_switch_ivas_fx( st_fx, st_fx->last_total_brate, 0 ); + core_coder_mode_switch_fx( st_fx, st_fx->last_total_brate, 0, shift ); } } } diff --git a/lib_enc/find_wsp_fx.c b/lib_enc/find_wsp_fx.c index 6e75c36c2ce874ceb10b13e29c04967fdf12dc7f..a16f1a95c1a0f5fc4fe36566d4d8a53b20136797 100644 --- a/lib_enc/find_wsp_fx.c +++ b/lib_enc/find_wsp_fx.c @@ -77,60 +77,3 @@ void find_wsp_fx( deemph_fx( &wsp[L_frame], preemph_fac, lookahead, &wtmp ); } } - -/*-------------------------------------------------------------------* - * ivas_find_wsp_fx() - * - * Compute weighted speech used in open-loop pitch search - *-------------------------------------------------------------------*/ -void ivas_find_wsp_fx( - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 L_subfr, /* i : length of subframe Q0*/ - const Word16 nb_subfr, /* i : number of subframes Q0*/ - const Word16 *A_fx, - /* i : A(z) filter coefficients */ // Q12 - Word16 *Aw_fx, - /* o : weighted A(z) filter coefficients */ // Q12 - const Word16 *speech_fx, - /* i : pointer to the denoised speech frame */ // Q_new - const Word16 tilt_fact, - /* i : tilt factor */ // Q15 - Word16 *wsp_fx, - /* o : poitnter to the weighted speech frame */ // Q_new - Word16 *mem_wsp_fx, - /* i/o: W(Z) denominator memory */ // Q_new - const Word16 gamma, - /* i : weighting factor */ // Q15 - const Word16 L_look /* i : look-ahead Q0*/ -) -{ - Word16 *p_Aw_fx, tmp_fx; - Word16 i_subfr; - - - /*-----------------------------------------------------------------* - * Compute weighted A(z) unquantized for subframes - *-----------------------------------------------------------------*/ - weight_a_subfr_fx( nb_subfr, A_fx, Aw_fx, gamma, M ); - - /*-----------------------------------------------------------------* - * Compute weighted speech for all subframes - *-----------------------------------------------------------------*/ - p_Aw_fx = Aw_fx; - FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr ) - { - Residu3_fx( p_Aw_fx, &speech_fx[i_subfr], &wsp_fx[i_subfr], L_subfr, 0 ); - p_Aw_fx += ( M + 1 ); - } - p_Aw_fx -= ( M + 1 ); - - /*-----------------------------------------------------------------* - * Weighted speech computation is extended on look-ahead - *-----------------------------------------------------------------*/ - - deemph_fx( wsp_fx, tilt_fact, L_frame, mem_wsp_fx ); - Residu3_fx( p_Aw_fx, &speech_fx[L_frame], &wsp_fx[L_frame], L_look, 0 ); - tmp_fx = *mem_wsp_fx; - deemph_fx( &wsp_fx[L_frame], tilt_fact, L_look, &tmp_fx ); - return; -} diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index d565fea0cac33f830efc20e7992439704c43dfad..11f5fe90c065742fa8f21e9ab0ae3bd667d88a5f 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index f3e85bd291818277c610845e1a5d90843f1fb2a9..4037aaa5eb262286c4465ec5887d352a44a0eecf 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -14,7 +14,7 @@ * Local function prototypes *-------------------------------------------------------------------*/ -static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, Word16 Qnew ); +static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, const Word16 Qnew ); /*-------------------------------------------------------------------* @@ -39,8 +39,9 @@ void encod_audio_fx( Word16 *tmp_noise, /* o : noise energy Q2 */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0 */ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6 */ - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { const Word16 *p_Aq; Word16 i, i_subfr, nb_subfr, last_pit_bin; @@ -60,6 +61,9 @@ void encod_audio_fx( GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; +#ifdef FIX_1904_HARM_GSC_ENC + Word16 Q_exc; +#endif m_mean = 0; move16(); @@ -70,9 +74,21 @@ void encod_audio_fx( move16(); T0_frac_tmp = 0; move16(); - Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); /* hLPDmem->q_mem_syn */ - hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; - move16(); + +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + Copy_Scale_sig( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); + Copy_Scale_sig( &hLPDmem->mem_w0, &hGSCEnc->mem_w0_tmp_fx, 1, sub( sub( Q_new, 1 ), hLPDmem->q_mem_syn ) ); + } + ELSE +#endif + { + Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); /* hLPDmem->q_mem_syn */ + hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; + move16(); + } + Es_pred = 0; move16(); @@ -82,6 +98,14 @@ void encod_audio_fx( * Encode GSC SWB speech flag *---------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + test(); + IF( NE_16( st_fx->element_mode, EVS_MONO ) && st_fx->idchan == 0 ) + { + push_indice( hBstr, IND_GSC_IVAS_SP, st_fx->GSC_IVAS_mode, 2 ); + } +#endif + IF( attack_flag > 0 ) { push_indice( hBstr, IND_GSC_ATTACK, 1, 1 ); @@ -91,7 +115,6 @@ void encod_audio_fx( push_indice( hBstr, IND_GSC_ATTACK, 0, 1 ); } - test(); test(); test(); @@ -104,9 +127,11 @@ void encod_audio_fx( { push_indice( hBstr, IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech, 1 ); } + /*---------------------------------------------------------------* * Find and encode the number of subframes *---------------------------------------------------------------*/ + test(); IF( GE_32( st_fx->core_brate, ACELP_9k60 ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) { @@ -120,6 +145,7 @@ void encod_audio_fx( } } } + test(); test(); test(); @@ -190,6 +216,7 @@ void encod_audio_fx( push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 1 ); } } + test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) { @@ -233,11 +260,14 @@ void encod_audio_fx( /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ + edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); edct_16fx( res, dct_res, st_fx->L_frame, 7, st_fx->element_mode ); + /*---------------------------------------------------------------* * Calculate energy dynamics *---------------------------------------------------------------*/ + Lm_mean = L_deposit_l( 0 ); FOR( i = 7; i < 15; i++ ) { @@ -325,12 +355,12 @@ void encod_audio_fx( tmp_nb_bits_tot = hBstr->nb_bits_tot; move16(); - if ( st_fx->extl_brate > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); } + test(); test(); if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) @@ -339,7 +369,14 @@ void encod_audio_fx( tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); } +#ifdef FIX_1904_HARM_GSC_ENC + Q_exc = Q_new; + move16(); + + gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); +#else gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, Q_new ); +#endif /*--------------------------------------------------------------------------------------* * iDCT transform @@ -347,15 +384,29 @@ void encod_audio_fx( edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); + +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + Scale_sig( exc, st_fx->L_frame, sub( Q_new, Q_exc ) ); /* TV This could probably be removed, but won't be BE */ + Scale_sig( exc_wo_nf, st_fx->L_frame, sub( Q_new, Q_exc ) ); + } +#endif + /*--------------------------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame, st_fx->element_mode ); +#else pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame ); +#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ + IF( st_fx->hBWE_TD != NULL ) { IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) @@ -369,6 +420,7 @@ void encod_audio_fx( interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); } } + /*--------------------------------------------------------------------------------------* * Synthesis *--------------------------------------------------------------------------------------*/ @@ -384,13 +436,25 @@ void encod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ - hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; - move16(); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + Copy_Scale_sig( &hGSCEnc->mem_w0_tmp_fx, &hLPDmem->mem_w0, 1, sub( hLPDmem->q_mem_syn, sub( Q_new, 1 ) ) ); + } + ELSE +#endif + { + hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; + move16(); + } + Copy( exc_wo_nf, exc, st_fx->L_frame ); return; } + +#ifndef FIX_1904_HARM_GSC_ENC void encod_audio_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 speech[], /* i : input speech Q_new */ @@ -599,10 +663,13 @@ void encod_audio_ivas_fx( Es_pred_enc_fx( &Es_pred, &indice, st_fx->L_frame, res, st_fx->voicing_fx, nb_bits, 0, Q_new ); push_indice( hBstr, IND_ES_PRED, indice, nb_bits ); } - +#ifdef FIX_1904_HARM_GSC_ENC + enc_pit_exc_fx( st_fx, speech, Aw, Aq, Es_pred, res, synth, exc, &T0_tmp, + &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); +#else enc_pit_exc_ivas_fx( st_fx, speech, Aw, Aq, Es_pred, res, synth, exc, &T0_tmp, &T0_frac_tmp, pitch_buf, nb_subfr, &hGSCEnc->lt_gpitch_fx, &saved_bit_pos, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); - +#endif /*---------------------------------------------------------------* * DCT transform *---------------------------------------------------------------*/ @@ -674,9 +741,8 @@ void encod_audio_ivas_fx( /*---------------------------------------------------------------* * Find and encode the last band where the adaptive (pitch) contribution is significant *---------------------------------------------------------------*/ - -#ifndef FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH - last_pit_bin = Pit_exc_contribution_len_ivas_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); +#ifdef FIX_1904_HARM_GSC_ENC + last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); #else last_pit_bin = Pit_exc_contribution_len_ivas_fx( st_fx, dct_res, dct_epit, pitch_buf, &hGSCEnc->pit_exc_hangover, Q_new ); #endif @@ -716,8 +782,11 @@ void encod_audio_ivas_fx( Word16 Q_exc = Q_new; move16(); +#ifdef FIX_1904_HARM_GSC_ENC + gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); +#else gsc_enc_ivas_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf, tmp_noise, &Q_exc ); - +#endif /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ @@ -772,8 +841,9 @@ void encod_audio_ivas_fx( return; } +#endif /*================================================================================*/ -/* FUNCTION : void gsc_enc_fx () */ +/* FUNCTION : void gsc_enc_fx() */ /*--------------------------------------------------------------------------------*/ /* PURPOSE : Generic audio signal encoder */ /*--------------------------------------------------------------------------------*/ @@ -789,25 +859,33 @@ void encod_audio_ivas_fx( /* _ None */ /*--------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State *st_fx:Encoder State Structure */ +/* Encoder_State *st_fx:Encoder State Structure */ /* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Q_exc */ /*--------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _None */ /*================================================================================*/ - void gsc_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 res_dct_in[], /* i : dct of residual signal Q_exc*/ + Encoder_State *st_fx, /* i/o: State structure */ + Word16 res_dct_in[], /* i : dct of residual signal Q_exc*/ Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ +#ifndef FIX_1904_HARM_GSC_ENC + Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ +#else + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ +#endif Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *tmp_noise, /* o : noise energy Q2*/ - Word16 Q_exc ) +#ifndef FIX_1904_HARM_GSC_ENC + Word16 Q_exc +#else + Word16 *Q_exc +#endif +) { Word16 y2_filt[L_FRAME16k]; Word16 exc_diffQ[L_FRAME16k]; @@ -820,7 +898,11 @@ void gsc_enc_fx( Word16 concat_in[L_FRAME16k]; Word16 concat_out[L_FRAME16k]; Word16 max_ener_band[MBANDS_GN_BITALLOC16k], j; +#ifndef FIX_1904_HARM_GSC_ENC Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; +#else + Word16 Ener_per_bd_iQ[MBANDS_GN16k]; +#endif Word16 last_bin, mean_gain; Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; Word16 bitallocation_exc[2]; @@ -831,6 +913,13 @@ void gsc_enc_fx( Word16 seed_init; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; +#ifdef FIX_1904_HARM_GSC_ENC + Word32 L_tmp; + Word16 max_eq = 0; + Word16 Q_concat = Q_PVQ_OUT; + move16(); + move16(); +#endif set16_fx( inpulses_fx, 0, NB_SFM ); set16_fx( imaxpulse_fx, 0, NB_SFM ); @@ -866,6 +955,7 @@ void gsc_enc_fx( * This improves the stability of the differnece spectrum since the spectral shape of the * residual signal is less suseptible to rapid changes than the difference spectrum *--------------------------------------------------------------------------------------*/ + IF( Diff_len == 0 ) { tmp_band = 0; @@ -877,11 +967,16 @@ void gsc_enc_fx( move16(); } +#ifndef FIX_1904_HARM_GSC_ENC Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1 /*, st_fx->L_frame IVAS_CODE*/ ); +#else + Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, *Q_exc, MBANDS_GN, 1, st_fx->L_frame ); +#endif /*--------------------------------------------------------------------------------------* * Gain quantizaion *--------------------------------------------------------------------------------------*/ + i = 0; move16(); WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) @@ -902,8 +997,7 @@ void gsc_enc_fx( i--; } - mean_gain = gsc_gainQ_fx( hBstr, /*st_fX->element_mode, st_fx->idchan,IVAS_CODE*/ Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth /*, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate*/ ); - + mean_gain = gsc_gainQ_fx( hBstr, st_fx->idchan, Ener_per_bd_iQ, Ener_per_bd_iQ, brate_intermed_tbl[i], st_fx->coder_type, st_fx->bwidth, st_fx->L_frame, st_fx->tdm_LRTD_flag, st_fx->core_brate ); *tmp_noise = mult_r( 320, mean_gain ); /*10 in Q5 lp_gainc in Q3 */ move16(); @@ -911,23 +1005,42 @@ void gsc_enc_fx( * Frequency encoder *--------------------------------------------------------------------------------------*/ +#ifndef FIX_1904_HARM_GSC_ENC bands_and_bit_alloc_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, st_fx->coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); - Q_tmp = Q_exc; +#else + bands_and_bit_alloc_ivas_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, + st_fx->coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); + Q_tmp = *Q_exc; +#endif move16(); + IF( bit == 0 ) { set16_fx( concat_out, 0, L_FRAME16k ); } ELSE { - tmp = pvq_core_enc_fx( hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, - gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ - bit = sub( bit, tmp ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could probably be harmonized */ + { + Q_concat = Q12; + move16(); + bit = sub( bit, pvq_core_enc_ivas_fx( hBstr, concat_in, concat_out, &Q_concat, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ) ); + } + ELSE +#endif + { + tmp = pvq_core_enc_fx( hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, + gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); + + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_concat, Q_tmp ) ); /* Q_PVQ_OUT */ + bit = sub( bit, tmp ); + } } + /* write unused bits */ WHILE( bit > 0 ) { @@ -935,6 +1048,7 @@ void gsc_enc_fx( push_indice( hBstr, IND_UNUSED, 0, i ); bit = sub( bit, i ); } + /* Reorder Q bands */ seed_init = 0; move16(); @@ -942,6 +1056,32 @@ void gsc_enc_fx( move16(); set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k ); +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could be harmonized, but won't be mathematically BE */ + { + max_eq = 0; + move16(); + + test(); + test(); + test(); + test(); + IF( ( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) ) || GE_16( st_fx->GSC_IVAS_mode, 1 ) ) + { + j = emaximum_fx( Q12, concat_out, shl( nb_subbands, 4 ), &L_tmp ); + IF( LE_16( add( abs_s( concat_out[j] ), 41 /* 0.01f in Q12 */ ), ONE_IN_Q12 ) ) + { + max_eq = 32767; /* Q15 */ + move16(); + } + ELSE + { + max_eq = div_s( ONE_IN_Q12, add( abs_s( concat_out[j] ), 41 /* 0.01f in Q12 */ ) ); /* Q15 */ + } + } + } +#endif + FOR( j = 0; j < nb_subbands; j++ ) { Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); /*Q12*/ @@ -998,17 +1138,65 @@ void gsc_enc_fx( * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) + { + FOR( i = 64; i < st_fx->L_frame; i++ ) + { + exc_diffQ[i] = mult( exc_diffQ[i], max_eq ); /* Q12 */ + move16(); + } + } + ELSE IF( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) && LE_16( st_fx->coder_type, UNVOICED ) ) + { + FOR( i = 0; i < L_FRAME; i++ ) + { + exc_diffQ[i] = mult( exc_diffQ[i], max_eq ); /* Q12 */ + move16(); + } + } + ELSE +#endif + { + freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st_fx->coder_type, hGSCEnc->noise_lev, st_fx->core_brate, exc_diffQ, Q_concat /*Q12 or Q10*/, st_fx->L_frame ); + } + +#ifdef FIX_1904_HARM_GSC_ENC + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could be harmonized, but won't be BE */ { - freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st_fx->coder_type, hGSCEnc->noise_lev, st_fx->core_brate, exc_diffQ, Q_PVQ_OUT, st_fx->L_frame ); + Word16 Q_exc_new = s_min( *Q_exc, hGSCEnc->Q_last_exc_dct_in ); + IF( NE_16( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ) + { + Scale_sig( hGSCEnc->last_exc_dct_in_fx, st_fx->L_frame, sub( Q_exc_new, hGSCEnc->Q_last_exc_dct_in ) ); /* Q_exc_new */ + hGSCEnc->Q_last_exc_dct_in = Q_exc_new; + move16(); + } + ELSE + { + Scale_sig( exc_dct_in, st_fx->L_frame, sub( Q_exc_new, *Q_exc ) ); /* Q_exc_new */ + *Q_exc = Q_exc_new; + move16(); + } } +#endif + /*--------------------------------------------------------------------------------------* * Estimate noise level *--------------------------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ /* Q12 */, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in /* Q_exc */, + st_fx->last_coder_type, bitallocation_band, lsf_new /* x2.56 */, hGSCEnc->last_exc_dct_in_fx /* Q_exc */, &hGSCEnc->last_ener_fx /* Q0 */, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, + st_fx->bwidth, exc_wo_nf, Q_concat, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); +#else highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, hGSCEnc->last_exc_dct_in_fx, &hGSCEnc->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); +#endif exc_dct_in[0] = 0; move16(); @@ -1016,7 +1204,7 @@ void gsc_enc_fx( return; } - +#ifndef FIX_1904_HARM_GSC_ENC void gsc_enc_ivas_fx( Encoder_State *st, /* i/o: State structure */ Word16 res_dct_in_fx[], @@ -1102,9 +1290,11 @@ void gsc_enc_ivas_fx( tmp_band = hGSCEnc->mem_last_pit_band; } move16(); - +#ifdef FIX_1904_HARM_GSC_ENC + Ener_per_band_comp_fx( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); +#else Ener_per_band_comp_ivas_fx( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); - +#endif /*--------------------------------------------------------------------------------------* * Gain quantizaion *--------------------------------------------------------------------------------------*/ @@ -1304,6 +1494,8 @@ void gsc_enc_ivas_fx( return; } +#endif + /*======================================================================*/ /* FUNCTION : edyn_fx() */ @@ -1326,10 +1518,11 @@ void gsc_enc_ivas_fx( /* _ None */ /*=======================================================================*/ -static Word16 edyn_fx( /* o : ratio of max to mean */ - const Word16 *vec, /* i : input vector Qnew*/ - const Word16 lvec, /* i : length of input vector */ - Word16 Qnew ) +/* o : ratio of max to mean */ +static Word16 edyn_fx( + const Word16 *vec, /* i : input vector Qnew*/ + const Word16 lvec, /* i : length of input vector */ + const Word16 Qnew ) { Word16 j = 0; Word16 dyn; @@ -1375,6 +1568,7 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ dyn = 1280; /* 10.0f in Q7 */ move16(); } + return dyn; /* Q7 */ } @@ -1420,6 +1614,5 @@ void GSC_enc_init_fx( hGSCEnc->past_dyn_dec = 0; move16(); - return; } diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 1966a4256d90814ef52592010c1f6d0f313b5ca7..6c4aa6bf4ab9bd8f7398d3d8e6d7807be77d7bf3 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -505,8 +505,7 @@ void hq_core_enc_ivas_fx( move16(); IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { - - hq_lr_enc_ivas_fx( st, t_audio_fx, inner_frame, &num_bits, is_transient ); + /* this cannot happen in IVAS */ } ELSE { diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 7f18bd48acb52566672112ce1bcd3cb09c5be3fb..7c5a7884c757ea1d20486bd3448ccba0261f3a83 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -337,7 +337,7 @@ void hq_hr_enc_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); v_multc_att32( t_audio_fx, att_fx, t_audio_fx, sfm_end[( num_sfm - 1 )] ); /* Q12 */ } @@ -477,7 +477,7 @@ void hq_hr_enc_ivas_fx( ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); } - MVR2R_WORD32( t_audio_q_fx, t_audio_fx, length ); + Copy32( t_audio_q_fx, t_audio_fx, length ); return; } diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 48b3edc383944273200df8743edd40630a2f06fc..74a3a15dfe24a4ef7a0d5b1530454c8f28e7ccc9 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -23,32 +23,6 @@ static Word16 p2a_threshold_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_a static void mdct_spectrum_fine_gain_enc_fx( Encoder_State *st_fx, const Word32 L_ybuf[] /*Q12*/, Word32 L_y2[] /*Q12*/, const Word16 band_start[], const Word16 band_end[], const Word16 k_sort[], const Word16 bands, const Word32 L_qint /*Q29*/, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); -static Word16 p2a_threshold_quant_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio /*Q12*/, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th /*Q11*/, Word16 *p2a_flags ); -static void mdct_spectrum_fine_gain_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_ybuf[], /* i : Q12 : input spectrum */ - Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ - const Word16 bands, /* i : Q0 : nubmber of subbands */ - const Word32 L_qint, /* i : Q29 : */ - const Word16 Ngq, /* i : Q0 : */ - const Word16 gqlevs, /* i : Q0 : quantized level */ - const Word16 gqbits /* i : Q0 : quantized bits */ -); - -static Word16 band_energy_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *L_t_audio, /* Q12 */ - const Word16 band_start[], /* Q0 */ - const Word16 band_end[], /* Q0 */ - Word32 L_band_energy[], /* Q14 */ - const Word16 bands_fx, /* Q0 */ - const Word32 L_qint, /* Q29 */ - const Word16 eref_fx, /* Q10 */ - const Word16 is_transient /* Q0 */ ); - /*--------------------------------------------------------------------------* * spt_shorten_domain_set() * @@ -126,77 +100,6 @@ static void spt_shorten_domain_set_fx( return; } -static void spt_shorten_domain_set_ivas_fx( - Encoder_State *st_fx, /* i: encoder state structure */ - const Word32 L_t_audio[], /* i: input spectrum Q12*/ - const Word16 p2a_flags[], /* i: p2a anlysis information Q0*/ - const Word16 new_band_start[], /* i: new band start position Q0*/ - const Word16 new_band_end[], /* i: new band end position Q0*/ - const Word16 new_band_width[], /* i: new subband band width Q0*/ - const Word16 bands, /* i: total number of subbands Q0*/ - Word16 band_start[], /* i/o: band start position Q0*/ - Word16 band_end[], /* i/o: band end position Q0*/ - Word16 band_width[], /* i: sub band band width Q0*/ - Word16 *bit_budget /* i/o: bit budget Q0*/ -) -{ - Word16 i, j, k; - Word16 kpos; - Word32 L_max_y2; - Word16 max_y2_pos; - Word16 spt_shorten_flag[SPT_SHORTEN_SBNUM]; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - - kpos = 0; - j = 0; - move16(); - move16(); - FOR( k = ( bands - SPT_SHORTEN_SBNUM ); k < bands; k++ ) - { - IF( EQ_16( p2a_flags[k], 1 ) ) - { - spt_shorten_flag[j] = 0; - move16(); - IF( hHQ_core->prev_SWB_peak_pos[kpos] != 0 ) - { - L_max_y2 = L_deposit_l( 0 ); - max_y2_pos = 0; - move16(); - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - IF( LT_32( L_max_y2, L_abs( L_t_audio[i] ) ) ) - { - L_max_y2 = L_abs( L_t_audio[i] ); /* Q12 */ - move32(); - max_y2_pos = i; - move16(); - } - } - test(); - IF( GE_16( max_y2_pos, new_band_start[j] ) && LE_16( max_y2_pos, new_band_end[j] ) ) - { - band_start[k] = new_band_start[j]; /* Q0 */ - move16(); - band_end[k] = new_band_end[j]; /* Q0 */ - move16(); - band_width[k] = new_band_width[j]; /* Q0 */ - move16(); - spt_shorten_flag[j] = 1; - move16(); - } - } - push_indice( st_fx->hBstr, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1 ); - *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ - move16(); - } - - kpos += 1; - j += 1; - } - - return; -} - /*--------------------------------------------------------------------------* * hq_lr_enc_fx() @@ -1097,1398 +1000,107 @@ void hq_lr_enc_fx( return; } -void hq_lr_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word32 L_t_audio[], /* i/o: transform-domain coefs. Q12*/ - const Word16 inner_frame, /* i : inner frame length Q0*/ - Word16 *num_bits, /* i/o: number of available bits Q0*/ - const Word16 is_transient /* i : transient flag Q0*/ -) -{ - Word16 i; - Word16 bit_budget, pbits; - Word16 bands, length, ni_seed, gqlevs, gqbits, Ngq, p2a_bands; - Word16 p2a_flags[BANDS_MAX]; - Word16 band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX]; - Word32 L_band_energy[BANDS_MAX]; - Word16 ebits_fx; - - Word32 Rk_fx[BANDS_MAX]; - Word16 k1_step_fx, k2_step_fx; - Word16 k1_fx, k2_fx; - - Word32 L_qint; /* Q29 */ - Word16 eref_fx; /* Q10 */ - Word16 bit_alloc_weight_fx; /* Q13 */ - Word16 k_sort[BANDS_MAX]; - Word16 npulses[BANDS_MAX]; - Word32 inp_vector[L_FRAME48k]; - - Word16 ld_slope_fx /*, Qldslope=15*/; - Word16 p2a_th_fx /*, Qp2ath=11*/; - Word16 pd_thresh_fx /*, Qpdth=15*/; - Word16 ni_coef_fx /*, Qnicoef=14*/; - - Word32 L_y2[L_FRAME48k]; - Word32 L_y2_ni[L_FRAME48k]; - - Word16 hqswb_clas; - Word16 lowlength; - Word16 highlength; - Word16 exp_norm; - Word32 L_m[L_FRAME32k]; - - Word16 har_bands; - - Word16 lowband, highband, bw_low = 0, bw_high = 20; - move16(); - move16(); - - Word32 bwe_br; - Word16 trans_bit, p2a_flags_tmp[BANDS_MAX]; - Word16 adjustFlag = 0; - move16(); - Word16 prev_SWB_peak_pos_tmp[SPT_SHORTEN_SBNUM]; - Word16 k, j; - Word16 flag_spt; - Word16 org_band_start[SPT_SHORTEN_SBNUM]; - Word16 org_band_end[SPT_SHORTEN_SBNUM]; - Word16 org_band_width[SPT_SHORTEN_SBNUM]; - Word16 new_band_start[SPT_SHORTEN_SBNUM]; - Word16 new_band_end[SPT_SHORTEN_SBNUM]; - Word16 new_band_width[SPT_SHORTEN_SBNUM]; - Word16 bws_cnt = 0; - move16(); - Word32 L_tmp, L_tmp2, L_tmp3; - Word16 exp, tmp, exp2, tmp1, tmp2, tmp3, alpha_fx, frac1; - Word32 enerH_fx; - Word32 enerL_fx; - Word32 Ep_fx[BANDS_MAX]; - Word32 Ep_avrg_fx, Ep_vari_fx; - Word32 Ep_avrgL_fx; - Word32 Ep_peak_fx; - Word32 Ep_tmp_fx[BANDS_MAX]; - Word16 gama_fx; /*Q15 0.85f; */ - Word16 beta_fx; /*Q14 1.05f; */ - Word32 L_band_energy_tmp[BANDS_MAX]; - UWord16 lo; - Word16 Q_band_energy; - BSTR_ENC_HANDLE hBstr = st->hBstr; - HQ_ENC_HANDLE hHQ_core = st->hHQ_core; - set32_fx( L_y2, 0x0L, L_FRAME48k ); - set32_fx( inp_vector, 0, inner_frame ); - flag_spt = 0; - move16(); - set16_fx( prev_SWB_peak_pos_tmp, 0, SPT_SHORTEN_SBNUM ); - adjustFlag = 0; - move16(); - bw_low = 0; - move16(); - bw_high = 20; - move16(); - enerL_fx = L_deposit_l( 0 ); - enerH_fx = L_deposit_l( 0 ); +/*--------------------------------------------------------------------------* + * small_symbol_enc_tran() + * + * Huffman encoding of differential energies, estimating or packing bits + * if flag_pack = 0, LC mode info. is output else LC mode info. is input + * if flag_pack = 0, estimatng else packing bits + *--------------------------------------------------------------------------*/ +static Word16 small_symbol_enc_tran_fx( /* o : bits */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ + const Word16 is_transient /* Q0 */ ) +{ + Word16 i, bits; + Word16 difidx[BANDS_MAX]; - bwe_br = st->core_brate; - hqswb_clas = HQ_NORMAL; - move16(); + FOR( i = 0; i < BANDS; i++ ) + { + difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ + move16(); + } - test(); - test(); - IF( EQ_16( st->bwidth, SWB ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) ) + FOR( i = 0; i < BANDS; ++i ) { - IF( EQ_16( is_transient, 1 ) ) - { - hqswb_clas = HQ_TRANSIENT; /* Q0 */ - move16(); - } - ELSE + test(); + IF( GT_16( difidx[i], LRMDCT_BE_LIMIT ) || difidx[i] < 0 ) { - hqswb_clas = peak_avrg_ratio_fx( st->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ + /* Huffman cannot encode this vector */ + return -1; } + } - /* write the classification information into the bitstream */ - push_indice( hBstr, IND_HQ2_SWB_CLAS, hqswb_clas, 2 ); - ( *num_bits ) = sub( *num_bits, 2 ); - move16(); - IF( EQ_16( hqswb_clas, HQ_NORMAL ) ) - { - flag_spt = 1; - move16(); - } + /* Preparing lossless coding input */ + IF( flag_pack == 0 ) + { + /* estimating # of bits */ + bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ } ELSE { - /* write the transient bit into the bitstream */ - push_indice( st->hBstr, IND_HQ2_SWB_CLAS, is_transient, 1 ); - - /* subtract one bit for the transient flag */ - ( *num_bits ) = sub( *num_bits, 1 ); + bits = 0; move16(); + encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); } - /* Configure encoder for different bandwidths, bitrates, etc. */ + return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ +} + - hq2_core_configure_fx( inner_frame, *num_bits, is_transient, &bands, &length, band_width, band_start, band_end, - &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs, &Ngq, &p2a_bands, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, bwe_br ); +/*--------------------------------------------------------------------------* + * small_symbol_enc() + * + * Huffman encoding of differential energies, estimating or packing bits + * if flag_pack = 0, LC mode info. is output else LC mode info. is input + * if flag_pack = 0, estimatng else packing bits + *--------------------------------------------------------------------------*/ +/* o : bits */ +static Word16 small_symbol_enc_fx( + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ + const Word16 is_transient /* Q0 */ ) +{ + Word16 i, bits; + Word16 difidx[BANDS_MAX], LSB[BANDS_MAX]; - highlength = band_end[( bands - 1 )]; /* Q0 */ - move16(); - har_bands = bands; /* Q0 */ + /* Preparing lossless coding input */ + difidx[0] = add( qbidx[0], DE_OFFSET0 ); /* Q0 */ move16(); - - test(); - test(); - test(); - IF( EQ_16( st->bwidth, SWB ) && is_transient == 0 && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) ) + FOR( i = 1; i < BANDS; ++i ) { - /* reserve bits for HQ_NORMAL2 and HQ_HARMONIC modes */ - test(); - IF( EQ_16( hqswb_clas, HQ_NORMAL ) || EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - ( *num_bits ) = sub( *num_bits, get_usebit_npswb_fx( hqswb_clas ) ); - move16(); - } + difidx[i] = add( qbidx[i], DE_OFFSET1 ); /* Q0 */ + move16(); } - test(); - test(); - IF( ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) && EQ_16( st->bwidth, SWB ) ) + FOR( i = 0; i < BANDS; ++i ) { - IF( NE_16( hHQ_core->prev_hqswb_clas, HQ_NORMAL ) ) + test(); + IF( GE_16( difidx[i], DE_LIMIT ) || difidx[i] < 0 ) { - j = 0; - move16(); - FOR( k = ( bands - SPT_SHORTEN_SBNUM ); k < bands; k++ ) - { - hHQ_core->prev_SWB_peak_pos[j] = 0; - move16(); - j += 1; - } + /* Huffman cannot encode this vector */ + return -1; } } - test(); - IF( GT_16( inner_frame, length ) && is_transient ) + /* splitting MSB and LSB */ + FOR( i = 0; i < BANDS; ++i ) { - /* If so, collapse transient frame (4 short transforms) to remove uncoded coefficients */ - - k1_step_fx = shr( length, 2 ); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS Q0*/ - k2_step_fx = shr( inner_frame, 2 ); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS Q0*/ - k1_fx = k1_step_fx; /* Q0 */ - k2_fx = k2_step_fx; /* Q0 */ + LSB[i] = s_and( difidx[i], 1 ); /* Q0 */ move16(); + difidx[i] = shr( difidx[i], 1 ); /* Q0 */ move16(); - FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) - { - /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ - /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ - - Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); /* Q12 */ - - k1_fx = add( k1_fx, k1_step_fx ); - k2_fx = add( k2_fx, k2_step_fx ); - } - } - - /* Spectral energy calculation/quantization */ - - ebits_fx = band_energy_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, L_band_energy, bands, - L_qint, eref_fx, is_transient ); /* Q0 */ - - /* First pass bit budget for TCQ of spectral band information */ - exp_norm = norm_s( gqlevs ); /* gqbits_fx = (short int) log2_f ((float) gqlevs_fx); */ - gqbits = sub( 14, exp_norm ); - - bit_budget = sub( sub( *num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq, gqbits ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ - - - pbits = 0; - move16(); - - test(); - test(); - IF( EQ_16( st->bwidth, SWB ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) ) - { - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - set16_fx( p2a_flags, 1, har_bands ); - } - ELSE - { - /* High band tonality detector based on per band peak-to-average ratio */ - pbits = p2a_threshold_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th_fx, p2a_flags ); /* Q0 */ - bit_budget = sub( bit_budget, pbits ); - - IF( EQ_16( hqswb_clas, HQ_NORMAL ) ) - { - return_bits_normal2_fx( &bit_budget, p2a_flags, bands, bits_lagIndices_modeNormal ); - } - } - } - ELSE - { - /* High band tonality detector based on per band peak-to-average ratio */ - pbits = p2a_threshold_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th_fx, p2a_flags ); /* Q0 */ - bit_budget = sub( bit_budget, pbits ); - } - - IF( EQ_16( flag_spt, 1 ) ) - { - /* initialize the desired parameters for SPT */ - spt_shorten_domain_band_save_fx( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); - spt_shorten_domain_pre_fx( band_start, band_end, hHQ_core->prev_SWB_peak_pos, bands, bwe_br, new_band_start, new_band_end, new_band_width ); - spt_shorten_domain_set_ivas_fx( st, L_t_audio, p2a_flags, new_band_start, new_band_end, new_band_width, bands, band_start, band_end, band_width, &bit_budget ); - } - -#define WMC_TOOL_SKIP - /* Estimate number of bits per band */ - Q_band_energy = SWB_BWE_LR_Qbe; - move16(); - FOR( i = 0; i < bands; i++ ) - { - L_tmp = L_shl( L_band_energy[i], sub( 16, Q_band_energy ) ); /*Q16 */ - - frac1 = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - L_tmp = Pow2( 30, frac1 ); - exp = sub( exp, 30 ); - Ep_fx[i] = L_shl( L_tmp, sub( exp, 6 ) ); /* Q -6 */ - move32(); - } - - FOR( i = 0; i < bands; i++ ) - { - L_tmp2 = Ep_fx[i]; /* Q -6 */ - L_tmp = L_max( 1, L_tmp2 ); - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); /* Q -6 + exp - 16 */ - - L_tmp3 = L_deposit_l( band_width[i] ); /* Q0 */ - exp2 = norm_l( L_tmp3 ); - tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); /* exp2 - 16 */ - - exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - - tmp3 = sub( tmp2, tmp ); - IF( tmp3 > 0 ) - { - tmp2 = shr( tmp2, 1 ); - } - IF( tmp3 > 0 ) - { - exp2 = add( exp2, 1 ); - } - tmp = div_s( tmp2, tmp ); /* Q15 */ - L_tmp = L_deposit_h( tmp ); /* Q31 */ - L_tmp = Isqrt_lc1( L_tmp, &exp2 ); /*Q(31-exp2) */ - move32(); - Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q16 */ - move32(); - } -#undef WMC_TOOL_SKIP - - test(); - test(); - test(); - test(); - test(); - test(); - IF( is_transient == 0 && EQ_16( inner_frame, L_FRAME8k ) && LE_32( st->core_brate, ACELP_13k20 ) ) - { -#define WMC_TOOL_SKIP - lowband = 6; - move16(); - trans_bit = 2; - move16(); - bit_budget = sub( bit_budget, trans_bit ); - gama_fx = 27852; /*Q15 0.85f */ - beta_fx = 17203; /*Q14 1.05f */ - move16(); - move16(); - set_s( &p2a_flags_tmp[bands - trans_bit], 0, 2 ); - - IF( EQ_32( st->core_brate, ACELP_13k20 ) ) - { - beta_fx = 13107; /* Q14 1.25f */ - move16(); - gama_fx = 31130; /* 0.95f Q15 */ - move16(); - mvs2s( &p2a_flags[( bands - trans_bit )], &p2a_flags_tmp[( bands - trans_bit )], trans_bit ); - } - - /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - Ep_vari_fx = 0; - move32(); - Ep_avrg_fx = 0; - move32(); - Ep_avrgL_fx = 0; - move32(); - Ep_peak_fx = 0; - move32(); - FOR( i = 0; i < bands; i++ ) - { - IF( sub( i, lowband ) >= 0 ) - { - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[( i - 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ - IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) - { - Ep_peak_fx = Ep_tmp_fx[i]; /*Q15 */ - move32(); - } - } - } - /* modify the last p2a_bands subbands band_energies */ - k = bands; - move16(); - mvl2l( L_band_energy, L_band_energy_tmp, k ); /*Q_band_energy */ - Mpy_32_16_ss( Ep_peak_fx, 24576, &L_tmp, &lo ); - Mpy_32_16_ss( Ep_peak_fx, shl( sub( bands, lowband ), 9 ), &L_tmp2, &lo ); - Mpy_32_16_ss( Ep_avrg_fx, 1126, &L_tmp3, &lo ); - - test(); - test(); - test(); - IF( ( ( L_sub( L_tmp, L_shr( Ep_avrgL_fx, 1 ) ) < 0 && EQ_32( st->core_brate, ACELP_13k20 ) ) || LT_32( st->core_brate, ACELP_13k20 ) ) && - L_sub( L_tmp2, L_tmp3 ) < 0 && L_sub( L_tmp2, L_shr( Ep_avrg_fx, 7 ) ) > 0 ) - { - FOR( i = lowband; i < bands; i++ ) - { - Mpy_32_16_ss( Ep_avrg_fx, 24576, &L_tmp, &lo ); - IF( L_sub( L_shr( Ep_tmp_fx[i], 1 ), L_tmp ) < 0 ) - { - Mpy_32_16_ss( Ep_peak_fx, sub( bands, lowband ), &L_tmp, &lo ); - tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-4 */ - IF( tmp != 0 ) - { - exp = norm_s( tmp ); - tmp = shl( tmp, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_avrg_fx, tmp, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +4 = 15) */ - L_tmp2 = L_add( L_tmp, 13107 ); /*15 */ - tmp2 = extract_l( L_min( L_max( L_tmp2, 16384 ), gama_fx ) ); /*15 = 15 */ - Mpy_32_16_ss( L_band_energy_tmp[i], tmp2, &L_band_energy_tmp[i], &lo ); - } - } - } - ELSE - { - j = 0; - move16(); - FOR( i = ( bands - trans_bit ); i < bands; i++ ) - { - alpha_fx = 16384; /*Q14 */ - move16(); - IF( sub( p2a_flags_tmp[i], 1 ) == 0 ) - { - Mpy_32_16_ss( Ep_tmp_fx[i], sub( bands, lowband ), &L_tmp, &lo ); - tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-4 */ - IF( tmp != 0 ) - { - exp = norm_s( tmp ); - tmp = shl( tmp, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_vari_fx, 3277, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, tmp, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 12, exp ) ); /*Q(13+exp-15 +12-exp +4 = 14) */ - - tmp2 = extract_h( Ep_avrg_fx ); /*Q13-16=-3 */ - IF( tmp2 != 0 ) - { - exp = norm_s( tmp2 ); - tmp2 = shl( tmp2, exp ); /*Q(exp) */ - tmp2 = div_s( 16384, tmp2 ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - tmp2 = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_vari_fx, 6554, &L_tmp2, &lo ); - Mpy_32_16_ss( L_tmp2, tmp2, &L_tmp2, &lo ); - L_tmp2 = L_shl( L_tmp2, sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +3 = 14) */ - L_tmp = L_min( L_tmp, L_tmp2 ); /*14 */ - tmp = extract_l( L_min( L_tmp, 13107 ) ); /*14 */ - alpha_fx = add( 16384, tmp ); /* Q14 */ - } - IF( sub( hHQ_core->last_bitalloc_max_band[j++], 1 ) == 0 ) - { - Mpy_32_16_ss( Ep_tmp_fx[i], sub( bands, lowband ), &L_tmp, &lo ); - tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-2 */ - IF( tmp != 0 ) - { - exp = norm_s( tmp ); - tmp = shl( tmp, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_avrg_fx, tmp, &L_tmp, &lo ); - L_tmp = L_shl_sat( L_tmp, sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ - L_tmp = L_max( L_tmp, 16384 ); /*14 */ - tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ - alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ - } - ELSE - { - tmp2 = extract_h( Ep_avrg_fx ); /*13 -16 =-3 */ - IF( tmp2 != 0 ) - { - exp = norm_s( tmp2 ); - tmp2 = shl( tmp2, exp ); /*Q(exp) */ - tmp2 = div_s( 16384, tmp2 ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp2 = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_tmp_fx[i], tmp2, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 19, exp ) ); /*Q(13+exp-15 +19-exp +3 = 20) */ - Mpy_32_16_ss( L_tmp, shl( sub( bands, lowband ), 9 ), &L_tmp, &lo ); - L_tmp = L_max( L_tmp, 13926 ); /*14 */ - tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*14 */ - alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =14 */ - } - Mpy_32_16_ss( L_band_energy_tmp[i], alpha_fx, &L_tmp, &lo ); - L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q(Q_band_energy+14-15 +1= Q_band_energy) */ - move32(); - } - } - lowband = 3; - move16(); - Ep_avrg_fx = 0; - move32(); - Ep_avrgL_fx = 0; - move32(); - Ep_peak_fx = 0; - move32(); - FOR( i = 0; i < bands; i++ ) - { - IF( sub( i, lowband ) >= 0 ) - { - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ - IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) - { - Ep_peak_fx = Ep_tmp_fx[i]; /*Q13 */ - move32(); - } - } - } - Mpy_32_16_ss( Ep_peak_fx, 28262, &L_tmp, &lo ); - Mpy_32_16_ss( Ep_avrgL_fx, 24576, &L_tmp2, &lo ); - - test(); - test(); - IF( L_sub( L_shr( Ep_avrg_fx, 2 ), L_tmp2 ) > 0 && L_sub( L_shr( Ep_avrg_fx, 4 ), L_tmp2 ) < 0 && L_sub( L_tmp, Ep_avrgL_fx ) > 0 ) - { - adjustFlag = 1; - move16(); - FOR( i = 0; i < lowband; i++ ) - { - tmp = extract_h( Ep_avrgL_fx ); /*Q-4 */ - IF( tmp != 0 ) - { - exp = norm_s( tmp ); - tmp = shl( tmp, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_peak_fx, tmp, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, lowband, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, 18842, &L_tmp, &lo ); - L_tmp = L_shl_sat( L_tmp, sub( 27, exp ) ); /*Q14 0.5 */ - tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ - Mpy_32_16_ss( L_band_energy_tmp[i], tmp2, &L_tmp, &lo ); - L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ - move32(); - } - } -#undef WMC_TOOL_SKIP - - - hq2_bit_alloc_fx( L_band_energy_tmp, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, band_width, *num_bits, hqswb_clas, st->bwidth, is_transient ); - - /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - FOR( i = 0; i < 2; i++ ) - { - push_indice( hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band[i], 1 ); - } - } - ELSE IF( is_transient == 0 && EQ_16( inner_frame, L_FRAME16k ) ) - { -#define WMC_TOOL_SKIP - bit_budget = sub( bit_budget, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ - FOR( i = 0; i < bands; i++ ) - { - Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); /* Q15 */ - move32(); - } - IF( EQ_32( st->core_brate, ACELP_13k20 ) ) - { - lowband = 8; - move16(); - highband = 15; - move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ - bw_high = sub( add( band_end[( bands - 1 )], 1 ), band_start[highband] ); /* Q0 */ - } - ELSE - { - lowband = 8; - move16(); - highband = 16; - move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ - bw_high = sub( add( band_end[( bands - 1 )], 1 ), band_start[highband] ); /* Q0 */ - } - /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - enerL_fx = 0; - move32(); - enerH_fx = 0; - move32(); - Ep_vari_fx = 0; - move32(); - Ep_avrg_fx = 0; - move32(); - FOR( i = 0; i < bands; i++ ) - { - test(); - IF( sub( i, lowband ) >= 0 && add( sub( i, bands ), p2a_bands ) < 0 ) - { - Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ - } - - IF( sub( i, highband ) >= 0 ) - { - enerH_fx = L_add( enerH_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ - } - ELSE IF( sub( i, lowband ) >= 0 ) - { - enerL_fx = L_add( enerL_fx, L_shl( Ep_fx[i], 2 ) ); /*Q0 */ - } - } - /* modify the last p2a_bands subbands band_energies */ - k = bands; - move16(); - mvl2l( L_band_energy, L_band_energy_tmp, k ); /*Q_band_energy */ - - L_tmp = L_max( enerH_fx, enerL_fx ); - tmp = s_max( bw_low, bw_high ); - i = norm_l( L_tmp ); - j = norm_s( tmp ); - Mpy_32_16_ss( L_shl( enerH_fx, i ), shl( bw_low, j ), &L_tmp, &lo ); - Mpy_32_16_ss( L_shl( enerL_fx, i ), shl( bw_high, j ), &L_tmp2, &lo ); - L_tmp2 = L_sub( L_tmp, L_tmp2 ); - - FOR( i = ( bands - p2a_bands ); i < bands; i++ ) - { - test(); - IF( sub( p2a_flags[i], 1 ) == 0 || L_tmp2 > 0 ) - { - tmp = sub( bands, p2a_bands ); - tmp = sub( tmp, lowband ); /*Q0 */ - - tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ - IF( tmp1 != 0 ) - { - exp = norm_s( tmp1 ); - tmp1 = shl( tmp1, exp ); /*Q(exp) */ - tmp1 = div_s( 16384, tmp1 ); /*Q(15+14-exp = 29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - tmp1 = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_tmp_fx[i], tmp1, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, tmp, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, 16384, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 32, exp ) ); /*Q15 */ - tmp = extract_l( L_min( L_tmp, 6554 ) ); /*Q15 */ - Mpy_32_16_ss( Ep_vari_fx, tmp1, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, tmp, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 15, exp ) ); /*Q15 */ - tmp = extract_l( L_shr( L_min( L_tmp, 13107 ), 1 ) ); /*Q14 */ - alpha_fx = add( tmp, 16384 ); /*Q14 */ - } - ELSE - { - alpha_fx = 16384; /* Q14 */ - move16(); - } - - IF( add( sub( i, bands ), p2a_bands ) > 0 ) - { - tmp = sub( bands, p2a_bands ); - IF( sub( hHQ_core->last_bitalloc_max_band[( i - ( tmp + 1 ) )], 1 ) == 0 ) - { - tmp = sub( tmp, lowband ); - Mpy_32_16_ss( Ep_tmp_fx[i], tmp, &L_tmp, &lo ); - tmp = extract_h( L_shl_sat( L_tmp, 16 ) ); /*Q0 */ - IF( tmp != 0 ) - { - exp = norm_s( tmp ); - tmp = shl( tmp, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_avrg_fx, tmp, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 14, exp ) ); /*Q14 */ - tmp = extract_l( L_min( L_max( L_tmp, 16384 ), 20480 ) ); /*Q14 */ - L_tmp = L_mult( alpha_fx, tmp ); /*Q(14+14+1=29) */ - alpha_fx = extract_l( L_shr( L_tmp, 15 ) ); /*Q14*/ - } - ELSE - { - tmp = sub( tmp, lowband ); - tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ - IF( tmp1 != 0 ) - { - exp = norm_s( tmp1 ); - tmp1 = shl( tmp1, exp ); /*Q(exp) */ - tmp1 = div_s( 16384, tmp1 ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - tmp1 = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_tmp_fx[i], tmp1, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, tmp, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 29, exp ) ); /*Q14 */ - tmp = extract_l( L_min( L_max( L_tmp, 13926 ), 16384 ) ); /*Q14 */ - L_tmp = L_mult( alpha_fx, tmp ); /*Q(14+14+1=29) */ - alpha_fx = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ - } - } - Mpy_32_16_ss( L_band_energy_tmp[i], alpha_fx, &L_tmp, &lo ); - L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q Q_band_energy */ - move32(); - } - lowband = 6; - move16(); - Ep_avrg_fx = 0; - move32(); - Ep_avrgL_fx = 0; - move32(); - Ep_peak_fx = 0; - move32(); - FOR( i = 0; i < bands; i++ ) - { - IF( sub( i, lowband ) >= 0 ) - { - Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ - IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) - { - Ep_peak_fx = Ep_tmp_fx[i]; /* Q15 */ - move32(); - } - } - } - - Mpy_32_16_ss( Ep_peak_fx, 24576, &L_tmp, &lo ); - Mpy_32_16_ss( Ep_peak_fx, 19661, &L_tmp2, &lo ); - Mpy_32_16_ss( Ep_avrgL_fx, 24576, &L_tmp3, &lo ); - - test(); - test(); - test(); - test(); - test(); - IF( ( L_sub( L_shr( Ep_avrgL_fx, 1 ), Ep_avrg_fx ) > 0 && L_sub( L_tmp, L_shr( Ep_avrgL_fx, 2 ) ) > 0 && L_sub( L_shr( Ep_avrgL_fx, 1 ), L_tmp2 ) < 0 ) || - ( L_sub( L_shr( Ep_avrg_fx, 1 ), Ep_avrgL_fx ) > 0 && L_sub( L_shr( Ep_avrg_fx, 3 ), L_tmp3 ) < 0 && L_sub( L_tmp, L_shr( Ep_avrgL_fx, 2 ) ) > 0 ) ) - { - adjustFlag = 1; - move16(); - FOR( i = 0; i < lowband; i++ ) - { - tmp = extract_h( L_shl_sat( Ep_avrgL_fx, 1 ) ); /*Q0 */ - IF( tmp != 0 ) - { - exp = norm_s( tmp ); - tmp = shl( tmp, exp ); /*Q(exp) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp=29-exp) */ - exp = sub( 29, exp ); - } - ELSE - { - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - Mpy_32_16_ss( Ep_peak_fx, tmp, &L_tmp, &lo ); - Mpy_32_16_ss( L_tmp, lowband, &L_tmp, &lo ); - L_tmp = L_shl( L_tmp, sub( 28, exp ) ); /*Q14 0.5 */ - tmp = extract_l( L_min( L_tmp, 19661 ) ); /*Q14 */ - Mpy_32_16_ss( L_band_energy_tmp[i], tmp, &L_tmp, &lo ); - L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ - move32(); - } - } -#undef WMC_TOOL_SKIP - - hq2_bit_alloc_fx( L_band_energy_tmp, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, band_width, *num_bits, hqswb_clas, st->bwidth, is_transient ); - - /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - FOR( i = 0; i < 2; i++ ) - { - push_indice( hBstr, IND_HQ2_LAST_BA_MAX_BAND, hHQ_core->last_bitalloc_max_band[i], 1 ); - } - } - ELSE IF( EQ_16( st->bwidth, SWB ) && EQ_16( hqswb_clas, HQ_HARMONIC ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) ) - { - /* bit allocation for harmonic mode */ - hq2_bit_alloc_har_fx( L_band_energy, bit_budget, bands, Rk_fx, p2a_bands, bwe_br, p2a_flags, band_width ); - } - ELSE - { - - /* estimate number of bits per band */ - hq2_bit_alloc_fx( L_band_energy, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, band_width, *num_bits, hqswb_clas, st->bwidth, is_transient ); - } - - tcq_core_LR_enc_ivas_fx( hBstr, inp_vector, L_t_audio, L_y2, bit_budget, bands, band_start, band_end, band_width, Rk_fx, npulses, k_sort, p2a_flags, p2a_bands, hHQ_core->last_bitalloc_max_band, inner_frame, adjustFlag, is_transient ); - - test(); - test(); - IF( ( EQ_16( inner_frame, L_FRAME8k ) && LE_32( st->core_brate, ACELP_13k20 ) ) || EQ_16( inner_frame, L_FRAME16k ) ) - { - j = 0; - FOR( i = 2; i > 0; i-- ) - { - IF( npulses[bands - i] > 0 ) - { - hHQ_core->last_bitalloc_max_band[j] = 1; - move16(); - } - ELSE - { - hHQ_core->last_bitalloc_max_band[j] = 0; - move16(); - } - j++; - } - } - - /* Denormalize the coded MDCT spectrum */ - mdct_spectrum_denorm_ivas_fx( inp_vector, L_y2, band_start, band_end, band_width, L_band_energy, npulses, bands, ld_slope_fx, pd_thresh_fx ); - - /* Apply fine gain quantization to denormalized coded spectrum */ - mdct_spectrum_fine_gain_enc_ivas_fx( st, L_t_audio, L_y2, band_start, band_end, k_sort, bands, L_qint, Ngq, gqlevs, gqbits ); - - /* reStore the subband information*/ - IF( EQ_16( flag_spt, 1 ) ) - { - spt_shorten_domain_band_restore_fx( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); - } - - /* Inject noise into components having relatively low pulse energy per band */ - ni_seed = add( add( add( npulses[0], npulses[1] ), npulses[2] ), npulses[3] ); /* Q0 */ - - Copy32( L_y2, L_y2_ni, band_end[bands - 1] + 1 ); /* Q12 */ - test(); - test(); - IF( EQ_16( st->bwidth, SWB ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) ) - { - test(); - IF( EQ_16( hqswb_clas, HQ_NORMAL ) || EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - preset_hq2_swb_fx( hqswb_clas, band_end, &har_bands, p2a_bands, length, bands, &lowlength, &highlength, L_m ); - - swb_bwe_enc_lr_ivas_fx( st, L_y2, SWB_BWE_LR_Qs, L_t_audio, L_m, bwe_br, - bands, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, p2a_flags, hqswb_clas, lowlength, highlength, - hHQ_core->prev_frm_index, har_bands, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, band_width, L_y2_ni, &ni_seed ); - - post_hq2_swb_fx( L_m, lowlength, highlength, hqswb_clas, har_bands, bands, p2a_flags, band_start, band_end, L_y2, npulses ); - - IF( EQ_16( hqswb_clas, HQ_NORMAL ) ) - { - spt_swb_peakpos_tmp_save_fx( L_y2, bands, band_start, band_end, prev_SWB_peak_pos_tmp ); - FOR( k = 0; k < SPT_SHORTEN_SBNUM; k++ ) - { - test(); - IF( p2a_flags[bands - SPT_SHORTEN_SBNUM + k] == 0 || npulses[bands - SPT_SHORTEN_SBNUM + k] == 0 ) - { - prev_SWB_peak_pos_tmp[k] = 0; - move16(); - } - } - } - Copy32( L_y2_ni, L_y2, lowlength ); /* Q12 */ - } - ELSE - { - Copy32( L_y2_ni, L_y2, band_end[bands - 1] + 1 ); /* HQ_TRANSIENT Q12*/ - } - } - ELSE - { - Copy32( L_y2_ni, L_y2, band_end[bands - 1] + 1 ); /* NB, WB Q12*/ - } - - updat_prev_frm_fx( L_y2, L_t_audio, bwe_br, length, inner_frame, bands, st->bwidth, is_transient, hqswb_clas, &hHQ_core->prev_hqswb_clas, hHQ_core->prev_SWB_peak_pos, prev_SWB_peak_pos_tmp, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, bws_cnt ); - - IF( NE_16( st->bwidth, SWB ) ) - { - /* reset HQ classifier memories */ - hHQ_core->mode_count = 0; - move16(); - hHQ_core->mode_count1 = 0; - move16(); - } - - - test(); - test(); - test(); - IF( NE_16( hqswb_clas, HQ_HARMONIC ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) && EQ_16( st->bwidth, SWB ) ) - { - hHQ_core->prev_frm_index[0] = -1; - move16(); - hHQ_core->prev_frm_index[1] = -1; - move16(); - } - - /* update number of unused bits */ - *num_bits = 0; - move16(); - - hHQ_core->hvq_hangover = 0; - move16(); - - return; -} - - -/*--------------------------------------------------------------------------* - * small_symbol_enc_tran() - * - * Huffman encoding of differential energies, estimating or packing bits - * if flag_pack = 0, LC mode info. is output else LC mode info. is input - * if flag_pack = 0, estimatng else packing bits - *--------------------------------------------------------------------------*/ - -static Word16 small_symbol_enc_tran_fx( /* o : bits */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ - const Word16 BANDS, /* i : number of bands Q0*/ - Word16 *hLCmode, /* i/o: LC mode info Q0*/ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ - const Word16 is_transient /* Q0 */ ) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX]; - - FOR( i = 0; i < BANDS; i++ ) - { - difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ - move16(); - } - - FOR( i = 0; i < BANDS; ++i ) - { - test(); - IF( GT_16( difidx[i], LRMDCT_BE_LIMIT ) || difidx[i] < 0 ) - { - /* Huffman cannot encode this vector */ - return -1; - } - } - - /* Preparing lossless coding input */ - IF( flag_pack == 0 ) - { - /* estimating # of bits */ - bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ - } - ELSE - { - bits = 0; - move16(); - encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); - } - - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ -} - - -static Word16 small_symbol_enc_tran_ivas_fx( /* o : bits */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ - const Word16 BANDS, /* i : number of bands Q0*/ - Word16 *hLCmode, /* i/o: LC mode info Q0*/ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ - const Word16 is_transient /* Q0 */ ) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX]; - - FOR( i = 0; i < BANDS; i++ ) - { - difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ - move16(); - } - - FOR( i = 0; i < BANDS; ++i ) - { - test(); - IF( GT_16( difidx[i], LRMDCT_BE_LIMIT ) || difidx[i] < 0 ) - { - /* Huffman cannot encode this vector */ - return -1; - } - } - - /* Preparing lossless coding input */ - IF( flag_pack == 0 ) - { - /* estimating # of bits */ - bits = encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ - } - ELSE - { - bits = 0; - move16(); - encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); - } - - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ -} - - -/*--------------------------------------------------------------------------* - * small_symbol_enc() - * - * Huffman encoding of differential energies, estimating or packing bits - * if flag_pack = 0, LC mode info. is output else LC mode info. is input - * if flag_pack = 0, estimatng else packing bits - *--------------------------------------------------------------------------*/ - -/* o : bits */ -static Word16 small_symbol_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ - const Word16 BANDS, /* i : number of bands Q0*/ - Word16 *hLCmode, /* i/o: LC mode info Q0*/ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ - const Word16 is_transient /* Q0 */ ) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX], LSB[BANDS_MAX]; - - /* Preparing lossless coding input */ - difidx[0] = add( qbidx[0], DE_OFFSET0 ); /* Q0 */ - move16(); - - FOR( i = 1; i < BANDS; ++i ) - { - difidx[i] = add( qbidx[i], DE_OFFSET1 ); /* Q0 */ - move16(); - } - - FOR( i = 0; i < BANDS; ++i ) - { - test(); - IF( GE_16( difidx[i], DE_LIMIT ) || difidx[i] < 0 ) - { - /* Huffman cannot encode this vector */ - return -1; - } - } - - /* splitting MSB and LSB */ - FOR( i = 0; i < BANDS; ++i ) - { - LSB[i] = s_and( difidx[i], 1 ); /* Q0 */ - move16(); - difidx[i] = shr( difidx[i], 1 ); /* Q0 */ - move16(); - } - - /* Preparing lossless coding input */ - IF( flag_pack == 0 ) - { - /* estimating # of bits */ - /* Encoding MSB bits */ - bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ - - /* Encoding LSB bit packing */ - bits = add( bits, BANDS ); /* Q0 */ - } - ELSE - { - /* Encoding MSB bits */ - bits = 0; - move16(); - encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); - - /* Encoding LSB bit packing */ - FOR( i = 0; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB[i], BITS_DE_LSB ); - } - } - - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ -} - -static Word16 small_symbol_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ - const Word16 BANDS, /* i : number of bands Q0*/ - Word16 *hLCmode, /* i/o: LC mode info Q0*/ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ - const Word16 is_transient /* Q0 */ ) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX], LSB[BANDS_MAX]; - - /* Preparing lossless coding input */ - difidx[0] = add( qbidx[0], DE_OFFSET0 ); /* Q0 */ - move16(); - - FOR( i = 1; i < BANDS; ++i ) - { - difidx[i] = add( qbidx[i], DE_OFFSET1 ); /* Q0 */ - move16(); - } - - FOR( i = 0; i < BANDS; ++i ) - { - test(); - IF( GE_16( difidx[i], DE_LIMIT ) || difidx[i] < 0 ) - { - /* Huffman cannot encode this vector */ - return -1; - } - } - - /* splitting MSB and LSB */ - FOR( i = 0; i < BANDS; ++i ) - { - LSB[i] = s_and( difidx[i], 1 ); /* Q0 */ - move16(); - difidx[i] = shr( difidx[i], 1 ); /* Q0 */ - move16(); - } - - /* Preparing lossless coding input */ - IF( flag_pack == 0 ) - { - /* estimating # of bits */ - /* Encoding MSB bits */ - bits = encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies Q0*/ - - /* Encoding LSB bit packing */ - bits = add( bits, BANDS ); /* Q0 */ - } - ELSE - { - /* Encoding MSB bits */ - bits = 0; - move16(); - encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); - - /* Encoding LSB bit packing */ - FOR( i = 0; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB[i], BITS_DE_LSB ); - } - } - - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ -} - - -/* o : bits Q0 */ -static Word16 large_symbol_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ - const Word16 BANDS, /* i : number of bands Q0*/ - Word16 *hLCmode0, /* i/o: LC mode info Q0*/ - const Word16 flag_pack /* i : indicator of packing or estimating bits Q0*/ -) -{ - Word16 i, bits, tmp; - Word16 LSB1[BANDS_MAX]; - Word16 min_q, max_q, offset0; - Word16 min_bits, min_bits_pos; - Word16 tdifidx0[BANDS_MAX], tdifidx1[BANDS_MAX]; - Word16 basic_shift; - Word16 bitsmode0, bitsmode1; - Word16 lsbdepth1; - Word16 cnt_outlyer, pos_outlyer, cnt_outlyer0; - - min_q = 513; /* Q0 */ - move16(); - max_q = -1; - move16(); - - cnt_outlyer0 = 0; - move16(); - cnt_outlyer = 0; - move16(); - bitsmode0 = 0; - move16(); - bitsmode1 = 0; - move16(); - pos_outlyer = 0; - move16(); - lsbdepth1 = 0; - move16(); - - test(); - test(); - IF( flag_pack == 0 || ( EQ_16( flag_pack, 1 ) && *hLCmode0 == 0 ) ) - { - test(); - test(); - IF( GT_16( qbidx[0], sub( ABS_ENG_OFFSET, 1 ) ) || LT_16( qbidx[0], -ABS_ENG_OFFSET ) ) - { - cnt_outlyer0 = 2; - move16(); - } - ELSE IF( GT_16( qbidx[0], 3 ) || LT_16( qbidx[0], -4 ) ) - { - cnt_outlyer0 = 1; - move16(); - } - ELSE - { - cnt_outlyer0 = 0; - move16(); - } - - cnt_outlyer = 0; - move16(); - pos_outlyer = -1; - move16(); - FOR( i = 1; i < BANDS; ++i ) - { - test(); - IF( GT_16( qbidx[i], 3 ) || LT_16( qbidx[i], -4 ) ) - { - cnt_outlyer = add( cnt_outlyer, 1 ); /* Q0 */ - pos_outlyer = i; - move16(); - } - - test(); - IF( GT_16( qbidx[i], ( ABS_ENG_OFFSET - 1 ) ) || LT_16( qbidx[i], -ABS_ENG_OFFSET ) ) - { - cnt_outlyer = add( cnt_outlyer, 1 ); /* Q0 */ - } - } - - test(); - test(); - IF( cnt_outlyer0 == 0 && LE_16( cnt_outlyer, 1 ) ) - { - bitsmode0 = ( BITS_DE_8SMODE + BITS_DE_8SMODE_N0 ) + BITS_DE_8SMODE_N1; /* Q0 */ - move16(); - IF( EQ_16( cnt_outlyer, 1 ) ) - { - /* 01 */ - bitsmode0 = add( bitsmode0, ( BITS_DE_8SPOS + BITS_ABS_ENG ) ); /* Q0 */ - } - - FOR( i = 0; i < pos_outlyer; ++i ) - { - tdifidx0[i] = qbidx[i]; /* Q0 */ - move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - - FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) - { - tdifidx0[i] = qbidx[i]; /* Q0 */ - move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - } - ELSE IF( EQ_16( cnt_outlyer0, 1 ) && LE_16( cnt_outlyer, 1 ) ) - { - bitsmode0 = ( BITS_DE_8SMODE + BITS_DE_8SMODE_N0 ) + BITS_DE_8SMODE_N1; /* Q0 */ - move16(); - tdifidx0[0] = qbidx[0]; /* Q0 */ - move16(); - bitsmode0 = add( bitsmode0, BITS_ABS_ENG ); - IF( EQ_16( cnt_outlyer, 1 ) ) - { - /* 11 */ - bitsmode0 = add( bitsmode0, ( BITS_DE_8SPOS + BITS_ABS_ENG ) ); /* Q0 */ - } - ELSE - { - pos_outlyer = 0; - move16(); - } - - FOR( i = 1; i < pos_outlyer; ++i ) - { - tdifidx0[i] = qbidx[i]; /* Q0 */ - move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - - FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) - { - tdifidx0[i] = qbidx[i]; /* Q0 */ - move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - } - ELSE - { - bitsmode0 = 20000; - move16(); - } - } - - test(); - IF( flag_pack == 0 || EQ_16( *hLCmode0, 1 ) ) - { - /* components 0 range : -256~255 */ - max_q = MINIMUM_ENERGY_LOWBRATE; - move16(); - min_q = MAXIMUM_ENERGY_LOWBRATE; - move16(); - FOR( i = 0; i < BANDS; ++i ) - { - max_q = s_max( qbidx[i], max_q ); - min_q = s_min( qbidx[i], min_q ); - } - - /* Counting bits for transmitting all components using same method */ - FOR( i = 0;; ++i ) - { - /*if (max_q <= ((2<<(i+1))-1) && min_q >= -(2<<(i+1))) */ - test(); - IF( LE_16( max_q, sub( shl( 2, add( i, 1 ) ), 1 ) ) && GE_16( min_q, -shl( 2, add( i, 1 ) ) ) ) - { - BREAK; - } - } - basic_shift = i; - move16(); - - min_bits = 1000; /* Q0 */ - move16(); - min_bits_pos = basic_shift; /* Q0 */ - move16(); - tmp = add( basic_shift, 3 ); - FOR( offset0 = basic_shift; offset0 < tmp; offset0++ ) - { - max_q = MINIMUM_ENERGY_LOWBRATE; - move16(); - min_q = MAXIMUM_ENERGY_LOWBRATE; - move16(); - - bitsmode1 = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); /* Q0 */ - FOR( i = 0; i < BANDS; ++i ) - { - bitsmode1 = add( bitsmode1, add( hessize[( ( qbidx[i] >> offset0 ) + 4 )], offset0 ) ); - } - - IF( GT_16( min_bits, bitsmode1 ) ) - { - min_bits_pos = offset0; /* Q0 */ - move16(); - min_bits = bitsmode1; /* Q0 */ - move16(); - } - } - - bitsmode1 = min_bits; - move16(); - lsbdepth1 = min_bits_pos; - move16(); - - FOR( i = 0; i < BANDS; ++i ) - { - LSB1[i] = s_and( qbidx[i], sub( shl( 1, lsbdepth1 ), 1 ) ); - tdifidx1[i] = shr( qbidx[i], lsbdepth1 ); - move16(); - move16(); - } } /* Preparing lossless coding input */ @@ -2496,128 +1108,33 @@ static Word16 large_symbol_enc_fx( { /* estimating # of bits */ /* Encoding MSB bits */ - IF( LT_16( bitsmode0, bitsmode1 ) ) - { - bits = bitsmode0; /* Q0 */ - move16(); - *hLCmode0 = 0; - move16(); - } - ELSE - { - bits = bitsmode1; /* Q0 */ - move16(); - *hLCmode0 = 1; - move16(); - } - } - ELSE - { - /* Encoding MSB bits */ - IF( *hLCmode0 == 0 ) - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE, 0, BITS_DE_8SMODE ); - bits = BITS_DE_8SMODE; - move16(); - IF( cnt_outlyer0 == 0 ) - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N0, 0, BITS_DE_8SMODE_N0 ); - bits = add( bits, BITS_DE_8SMODE_N0 ); - IF( EQ_16( cnt_outlyer, 1 ) ) - { - /* 01 */ - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ - push_indice( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); - bits = add( bits, BITS_DE_8SPOS ); - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[pos_outlyer] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); - } - ELSE - { - /* 00 */ - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ - } - - FOR( i = 0; i < pos_outlyer; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - - FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - } - ELSE IF( EQ_16( cnt_outlyer0, 1 ) ) - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N0, 1, BITS_DE_8SMODE_N0 ); - bits = add( bits, BITS_DE_8SMODE_N0 ); - IF( EQ_16( cnt_outlyer, 1 ) ) - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ - push_indice( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); - bits = add( bits, BITS_DE_8SPOS ); - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[pos_outlyer] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); - } - ELSE - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); /* Q0 */ - } - - FOR( i = 1; i < pos_outlyer; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - - FOR( i = pos_outlyer + 1; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - } - } - ELSE - { - bits = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); /* Q0 */ - push_indice( hBstr, IND_HQ2_DENG_8SMODE, 1, BITS_DE_8SMODE ); - push_indice( hBstr, IND_HQ2_DENG_8SDEPTH, lsbdepth1, BITS_MAX_DEPTH ); + bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ - FOR( i = 0; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx1[i] + 4], hessize[tdifidx1[i] + 4] ); - bits = add( bits, hessize[tdifidx1[i] + 4] ); /* Q0 */ - } + /* Encoding LSB bit packing */ + bits = add( bits, BANDS ); /* Q0 */ + } + ELSE + { + /* Encoding MSB bits */ + bits = 0; + move16(); + encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); - IF( lsbdepth1 > 0 ) - { - FOR( i = 0; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB1[i], lsbdepth1 ); - } - /*bits += BANDS * lsbdepth1; */ - bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); /* Q0 */ - } + /* Encoding LSB bit packing */ + FOR( i = 0; i < BANDS; ++i ) + { + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB[i], BITS_DE_LSB ); } } - return bits; /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ + return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } -static Word16 large_symbol_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ +/* o : bits Q0 */ +static Word16 large_symbol_enc_fx( + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ const Word16 BANDS, /* i : number of bands Q0*/ Word16 *hLCmode0, /* i/o: LC mode info Q0*/ @@ -2704,7 +1221,7 @@ static Word16 large_symbol_enc_ivas_fx( IF( EQ_16( cnt_outlyer, 1 ) ) { /* 01 */ - bitsmode0 = add( bitsmode0, add( BITS_DE_8SPOS, BITS_ABS_ENG ) ); /* Q0 */ + bitsmode0 = add( bitsmode0, ( BITS_DE_8SPOS + BITS_ABS_ENG ) ); /* Q0 */ } FOR( i = 0; i < pos_outlyer; ++i ) @@ -2714,7 +1231,7 @@ static Word16 large_symbol_enc_ivas_fx( bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } - FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) + FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) { tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); @@ -2727,7 +1244,7 @@ static Word16 large_symbol_enc_ivas_fx( move16(); tdifidx0[0] = qbidx[0]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, BITS_ABS_ENG ); /* Q0 */ + bitsmode0 = add( bitsmode0, BITS_ABS_ENG ); IF( EQ_16( cnt_outlyer, 1 ) ) { /* 11 */ @@ -2746,7 +1263,7 @@ static Word16 large_symbol_enc_ivas_fx( bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } - FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) + FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) { tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); @@ -2755,7 +1272,7 @@ static Word16 large_symbol_enc_ivas_fx( } ELSE { - bitsmode0 = 20000; /* Q0 */ + bitsmode0 = 20000; move16(); } } @@ -2799,11 +1316,10 @@ static Word16 large_symbol_enc_ivas_fx( min_q = MAXIMUM_ENERGY_LOWBRATE; move16(); - bitsmode1 = ( BITS_DE_8SMODE + BITS_MAX_DEPTH ); /* Q0 */ - move16(); + bitsmode1 = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); /* Q0 */ FOR( i = 0; i < BANDS; ++i ) { - bitsmode1 = add( bitsmode1, add( hessize[( ( qbidx[i] >> offset0 ) + 4 )], offset0 ) ); /* Q0 */ + bitsmode1 = add( bitsmode1, add( hessize[( ( qbidx[i] >> offset0 ) + 4 )], offset0 ) ); } IF( GT_16( min_bits, bitsmode1 ) ) @@ -2815,9 +1331,9 @@ static Word16 large_symbol_enc_ivas_fx( } } - bitsmode1 = min_bits; /* Q0 */ + bitsmode1 = min_bits; move16(); - lsbdepth1 = min_bits_pos; /* Q0 */ + lsbdepth1 = min_bits_pos; move16(); FOR( i = 0; i < BANDS; ++i ) @@ -2892,286 +1408,93 @@ static Word16 large_symbol_enc_ivas_fx( } ELSE IF( EQ_16( cnt_outlyer0, 1 ) ) { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N0, 1, BITS_DE_8SMODE_N0 ); - bits = add( bits, BITS_DE_8SMODE_N0 ); /* Q0 */ - IF( EQ_16( cnt_outlyer, 1 ) ) - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ - push_indice( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); - bits = add( bits, BITS_DE_8SPOS ); - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[pos_outlyer] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); - } - ELSE - { - push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); /* Q0 */ - } - - FOR( i = 1; i < pos_outlyer; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - - FOR( i = pos_outlyer + 1; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ - } - } - } - ELSE - { - bits = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); - push_indice( hBstr, IND_HQ2_DENG_8SMODE, 1, BITS_DE_8SMODE ); - push_indice( hBstr, IND_HQ2_DENG_8SDEPTH, lsbdepth1, BITS_MAX_DEPTH ); - - FOR( i = 0; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx1[i] + 4], hessize[tdifidx1[i] + 4] ); - bits = add( bits, hessize[tdifidx1[i] + 4] ); /* Q0 */ - } - - IF( lsbdepth1 > 0 ) - { - FOR( i = 0; i < BANDS; ++i ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB1[i], lsbdepth1 ); - } - /*bits += BANDS * lsbdepth1; */ - bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); /* Q0 */ - } - } - } - - return bits; /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ -} - -/*-------------------------------------------------------------------* - * band_energy_quant() - * - * - *-------------------------------------------------------------------*/ - -static Word16 band_energy_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *L_t_audio, /* i : Q12 : input MDCT signal (Qs) */ - const Word16 band_start[], /* i : Q0 : band start table */ - const Word16 band_end[], /* i : Q0 : band end table */ - Word32 L_band_energy[], /* i : Q14 : band energy (Qbe) */ - const Word16 bands_fx, /* i : Q0 : number of bands */ - const Word32 L_qint, /* i : Q29 */ - const Word16 eref_fx, /* i : Q10 */ - const Word16 is_transient_fx /* i : Q0 : indicator for HQ_TRANSIENT */ -) -{ - Word16 i, k; - Word16 ebits; - Word16 hLCmode0, hLCmode1, deng_bits; - Word16 deng_cmode = 0; - Word16 hbits; - move16(); - - Word32 L_E; - Word16 QE; - - Word16 rev_qint_fx; /* 1/qint */ - Word16 Qrev_qint; /* Q value for 1/qint */ - - Word16 bq0_fx; - Word16 bq1_fx[BANDS_MAX]; - Word16 bq2_fx[BANDS_MAX]; - - Word16 bq1_temp_fx[BANDS_MAX]; - Word16 bq2_temp_fx[BANDS_MAX]; - - Word32 L_tmp; - Word16 temp_fx; - Word16 frac, exp; - Word16 exp_safe; - Word16 exp_norm; - Word16 exp_norm2; - Word16 exp_normd; - - /* Calculate the band energies */ - exp_safe = 4; - move16(); /* 4: never overflow happen at L_E */ - FOR( k = 0; k < bands_fx; k++ ) - { - L_tmp = L_deposit_l( 1295 ); /* 1295 = sqrt(0.1) (Qs) */ - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); /* Qs */ - } - exp_norm = norm_l( L_tmp ); - exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ - - QE = add( shl( sub( add( SWB_BWE_LR_Qs, exp_norm ), 16 ), 1 ), 1 ); - L_E = L_shl( 590L, sub( QE, 15 ) ); /* 590 0.018f(Q15 -> QE) */ - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - /*E += yos[i] * yos[i]; */ - temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Qs+exp_norm-16 */ - L_E = L_mac( L_E, temp_fx, temp_fx ); /* (Qs+exp_norm-16)*2+1 */ - } - - /*band_energy[k] = (float) log2_f (E + 1.0e-1f); */ - exp_norm2 = norm_l( L_E ); - exp = add( add( shl( sub( add( SWB_BWE_LR_Qs, exp_norm ), 16 ), 1 ), 1 ), exp_norm2 ); - L_E = L_shl( L_E, exp_norm2 ); /* (Qs+exp_norm-16)*2 + 1 + exp_norm2 */ - frac = Log2_norm_lc( L_E ); - exp = sub( 30, exp ); - L_tmp = L_Comp( exp, frac ); - L_band_energy[k] = L_shr( L_tmp, 2 ); /* Q16->Qbe(Q14) */ - move32(); - } - - IF( is_transient_fx ) - { - reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); - } - - - /* Quantize the reference and band energies */ - exp_normd = norm_l( L_qint ); - rev_qint_fx = div_s( 0x4000, round_fx( L_shl( L_qint, exp_normd ) ) ); /* Q14-(29+exp_normd-16)+15 */ - Qrev_qint = sub( 14 - ( 29 - 16 ) + 15, exp_normd ); - - bq0_fx = round_fx( L_shl( L_mult( eref_fx, rev_qint_fx ), sub( 5, Qrev_qint ) ) ); /* 16-(10+Qrev_qint+1) */ - FOR( k = 0; k < bands_fx; k++ ) - { - /*bq1[k] = round_f (band_energy[k] / qint); */ - L_tmp = Mpy_32_16_1( L_band_energy[k], rev_qint_fx ); /* Q14+Qrev_qint-15 */ - bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* Q0 */ - move16(); - } - - IF( is_transient_fx ) - { - - Copy( bq1_fx, bq1_temp_fx, bands_fx ); /* Q0 */ - - /* Calculate the differential energies */ - diffcod_lrmdct_fx( bands_fx, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient_fx ); - } - - /* Calculate the differential energies */ - bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); /* Q0 */ - move16(); - FOR( k = 1; k < bands_fx; k++ ) - { - bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); /* Q0 */ - move16(); - } - - /* Modifying qbidx to be located in the range -256~255 */ - FOR( i = 0; i < bands_fx; ++i ) - { - IF( GT_16( bq2_fx[i], MAXIMUM_ENERGY_LOWBRATE ) ) - { - bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; /* Q0 */ - move16(); - } - IF( LT_16( bq2_fx[i], MINIMUM_ENERGY_LOWBRATE ) ) - { - bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; /* Q0 */ - move16(); - } - } - - /* Get number of bits by Huffman0 coding */ - ebits = large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 0 ); /* Q0 */ - - IF( is_transient_fx ) - { - /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_tran_fx( hBstr, bq2_temp_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); /* Q0 */ - } - ELSE - { - /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); /* Q0 */ - } - - /* comparing used bits */ - test(); - IF( LT_16( ebits, hbits ) || EQ_16( hbits, -1 ) ) - { - deng_cmode = 0; - move16(); - push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 1 ); - deng_bits = add( ebits, BITS_DE_CMODE ); /* Q0 */ - } - ELSE - { - /* setting energy difference coding mode and storing it */ - deng_cmode = 1; - move16(); - push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); + push_indice( hBstr, IND_HQ2_DENG_8SMODE_N0, 1, BITS_DE_8SMODE_N0 ); + bits = add( bits, BITS_DE_8SMODE_N0 ); + IF( EQ_16( cnt_outlyer, 1 ) ) + { + push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ + push_indice( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); + bits = add( bits, BITS_DE_8SPOS ); + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); + bits = add( bits, BITS_ABS_ENG ); + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[pos_outlyer] + ABS_ENG_OFFSET, BITS_ABS_ENG ); + bits = add( bits, BITS_ABS_ENG ); + } + ELSE + { + push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); + bits = add( bits, BITS_ABS_ENG ); /* Q0 */ + } - deng_bits = add( hbits, BITS_DE_CMODE ); /* Q0 */ + FOR( i = 1; i < pos_outlyer; ++i ) + { + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); + bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ + } - /* packing indice */ - IF( is_transient_fx ) - { - Copy( bq2_temp_fx, bq2_fx, bands_fx ); /* Q0 */ - small_symbol_enc_tran_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 1, is_transient_fx ); + FOR( i = pos_outlyer + 1; i < BANDS; ++i ) + { + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); + bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ + } + } } ELSE { - small_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 1, is_transient_fx ); - } - } - - /* Reconstruct quantized spectrum */ - bq1_fx[0] = add( bq2_fx[0], bq0_fx ); /* Q0 */ - move16(); - FOR( k = 1; k < bands_fx; k++ ) - { - bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); /* Q0 */ - move16(); - } + bits = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); /* Q0 */ + push_indice( hBstr, IND_HQ2_DENG_8SMODE, 1, BITS_DE_8SMODE ); + push_indice( hBstr, IND_HQ2_DENG_8SDEPTH, lsbdepth1, BITS_MAX_DEPTH ); - FOR( k = 0; k < bands_fx; k++ ) - { - L_band_energy[k] = Mpy_32_16_1( L_qint, bq1_fx[k] ); /* 29+0-15 -> Qbe(Q14) */ - move32(); - } + FOR( i = 0; i < BANDS; ++i ) + { + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx1[i] + 4], hessize[tdifidx1[i] + 4] ); + bits = add( bits, hessize[tdifidx1[i] + 4] ); /* Q0 */ + } - IF( is_transient_fx ) - { - reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); + IF( lsbdepth1 > 0 ) + { + FOR( i = 0; i < BANDS; ++i ) + { + push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB1[i], lsbdepth1 ); + } + /*bits += BANDS * lsbdepth1; */ + bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); /* Q0 */ + } + } } - return ( deng_bits ); /* Q0 */ + return bits; /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } -static Word16 band_energy_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *L_t_audio, /* i : Q12 : input MDCT signal (Qs) */ - const Word16 band_start[], /* i : Q0 : band start table */ - const Word16 band_end[], /* i : Q0 : band end table */ - Word32 L_band_energy[], /* i : Q14 : band energy (Qbe) */ - const Word16 bands, /* i : Q0 : number of bands */ - const Word32 L_qint, /* i : Q29 */ - const Word16 eref_fx, /* i : Q10 */ - const Word16 is_transient /* i : Q0 : indicator for HQ_TRANSIENT */ +/*-------------------------------------------------------------------* + * band_energy_quant() + * + * + *-------------------------------------------------------------------*/ + +static Word16 band_energy_quant_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32 *L_t_audio, /* i : Q12 : input MDCT signal (Qs) */ + const Word16 band_start[], /* i : Q0 : band start table */ + const Word16 band_end[], /* i : Q0 : band end table */ + Word32 L_band_energy[], /* i : Q14 : band energy (Qbe) */ + const Word16 bands_fx, /* i : Q0 : number of bands */ + const Word32 L_qint, /* i : Q29 */ + const Word16 eref_fx, /* i : Q10 */ + const Word16 is_transient_fx /* i : Q0 : indicator for HQ_TRANSIENT */ ) { Word16 i, k; Word16 ebits; Word16 hLCmode0, hLCmode1, deng_bits; Word16 deng_cmode = 0; - move16(); Word16 hbits; + move16(); + Word32 L_E; Word16 QE; @@ -3191,13 +1514,12 @@ static Word16 band_energy_quant_ivas_fx( Word16 exp_safe; Word16 exp_norm; Word16 exp_norm2; - Word16 exp_normd; - /* Calculate the band energies */ + /* Calculate the band energies */ exp_safe = 4; move16(); /* 4: never overflow happen at L_E */ - FOR( k = 0; k < bands; k++ ) + FOR( k = 0; k < bands_fx; k++ ) { L_tmp = L_deposit_l( 1295 ); /* 1295 = sqrt(0.1) (Qs) */ FOR( i = band_start[k]; i <= band_end[k]; i++ ) @@ -3227,253 +1549,135 @@ static Word16 band_energy_quant_ivas_fx( move32(); } - IF( is_transient ) + IF( is_transient_fx ) { - reverse_transient_frame_energies_fx( L_band_energy, bands ); + reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); } -#define WMC_TOOL_SKIP + + /* Quantize the reference and band energies */ exp_normd = norm_l( L_qint ); rev_qint_fx = div_s( 0x4000, round_fx( L_shl( L_qint, exp_normd ) ) ); /* Q14-(29+exp_normd-16)+15 */ Qrev_qint = sub( 14 - ( 29 - 16 ) + 15, exp_normd ); bq0_fx = round_fx( L_shl( L_mult( eref_fx, rev_qint_fx ), sub( 5, Qrev_qint ) ) ); /* 16-(10+Qrev_qint+1) */ - FOR( k = 0; k < bands; k++ ) + FOR( k = 0; k < bands_fx; k++ ) { /*bq1[k] = round_f (band_energy[k] / qint); */ - L_tmp = L_mls( L_band_energy[k], rev_qint_fx ); /* Q14+Qrev_qint-15 */ + L_tmp = Mpy_32_16_1( L_band_energy[k], rev_qint_fx ); /* Q14+Qrev_qint-15 */ bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* Q0 */ move16(); } -#undef WMC_TOOL_SKIP - IF( is_transient ) + IF( is_transient_fx ) { - Copy( bq1_fx, bq1_temp_fx, bands ); /* Q0 */ + Copy( bq1_fx, bq1_temp_fx, bands_fx ); /* Q0 */ /* Calculate the differential energies */ - diffcod_lrmdct_fx( bands, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient ); /* Q0 */ + diffcod_lrmdct_fx( bands_fx, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient_fx ); } /* Calculate the differential energies */ bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); /* Q0 */ move16(); - FOR( k = 1; k < bands; k++ ) + FOR( k = 1; k < bands_fx; k++ ) { bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); /* Q0 */ move16(); } - /* Modifying qbidx to be located in the range -256~255 */ - FOR( i = 0; i < bands; ++i ) + FOR( i = 0; i < bands_fx; ++i ) { IF( GT_16( bq2_fx[i], MAXIMUM_ENERGY_LOWBRATE ) ) { - bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; /* Q0 */ - move16(); - } - IF( LT_16( bq2_fx[i], MINIMUM_ENERGY_LOWBRATE ) ) - { - bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; /* Q0 */ - move16(); - } - } - - /* Get number of bits by Huffman0 coding */ - ebits = large_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode0, 0 ); /* Q0 */ - - IF( is_transient ) - { - /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_tran_ivas_fx( hBstr, bq2_temp_fx, bands, &hLCmode1, 0, is_transient ); /* Q0 */ - } - ELSE - { - /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode1, 0, is_transient ); /* Q0 */ - } - - test(); - IF( LT_16( ebits, hbits ) || EQ_16( hbits, -1 ) ) - { - deng_cmode = 0; - move16(); - push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - large_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode0, 1 ); - deng_bits = add( ebits, BITS_DE_CMODE ); /* Q0 */ - } - ELSE - { - /* setting energy difference coding mode and storing it */ - deng_cmode = 1; - move16(); - push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - - deng_bits = add( hbits, BITS_DE_CMODE ); /* Q0 */ - - /* packing indice */ - IF( is_transient ) - { - Copy( bq2_temp_fx, bq2_fx, bands ); /* Q0 */ - small_symbol_enc_tran_ivas_fx( hBstr, bq2_fx, bands, &hLCmode1, 1, is_transient ); - } - ELSE - { - small_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode1, 1, is_transient ); - } - } - - /* Reconstruct quantized spectrum */ - bq1_fx[0] = add( bq2_fx[0], bq0_fx ); /* Q0 */ - move16(); - FOR( k = 1; k < bands; k++ ) - { - bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); /* Q0 */ - move16(); - } - - FOR( k = 0; k < bands; k++ ) - { -#define WMC_TOOL_SKIP - L_band_energy[k] = L_mls( L_qint, (Word16) bq1_fx[k] ); /* 29+0-15 -> Qbe(Q14) */ - move32(); -#undef WMC_TOOL_SKIP - } - - IF( is_transient ) - { - reverse_transient_frame_energies_fx( L_band_energy, bands ); - } - - return ( deng_bits ); /* Q0 */ -} - - -/*-------------------------------------------------------------------* - * p2a_threshold_quant() - * - * - *-------------------------------------------------------------------*/ - -static Word16 p2a_threshold_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: : bit stream */ - const Word32 *L_t_audio, /* i : Q12 : input spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word16 bands, /* i : Q0 : number of subbands */ - const Word16 p2a_bands, /* i : Q0 : tonality indicator */ - const Word16 p2a_th_fx, /* i : Q11 : threshold tonal or not */ - Word16 *p2a_flags_fx /* i/o: Q0 : tonality flag */ -) -{ - Word16 i, j, k; - Word32 L_a, L_p, L_e; - Word16 Qa; - Word32 L_tmp; - Word16 temp_fx; - Word16 exp_norm; - Word16 exp_safe; - Word16 exp_normn, exp_normd; - - Word16 norm_a_fx, Qnorm_a; - Word16 pa_fx, Qpa; - - Word16 exp, frac; - - Word32 L_p2a; - Word16 p2a_fx; - - exp_safe = 4; /* never happen overflow. */ - move16(); - - set16_fx( p2a_flags_fx, 1, bands ); - move16(); - - j = 0; - move16(); - FOR( k = ( bands - p2a_bands ); k < bands; k++ ) - { - L_a = L_deposit_l( 0 ); - L_p = L_deposit_l( 0 ); - - L_tmp = L_deposit_l( 0 ); - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); /* Q12 */ - } - exp_norm = norm_l( L_tmp ); - exp_norm = sub( exp_norm, exp_safe ); - - FOR( i = band_start[k]; i <= band_end[k]; i++ ) - { - temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Q12+exp_norm-16 -> exp_norm-4 */ - L_e = L_mult( temp_fx, temp_fx ); /* 2*(exp_norm-4)+1 */ - - IF( GT_32( L_e, L_p ) ) - { - L_p = L_add( L_e, 0 ); - } - L_a = L_add( L_a, L_e ); - } - Qa = sub( shl( exp_norm, 1 ), 7 ); /* (exp_norm-4)*2+1 */ - - IF( L_a > 0x0L ) - { - /* a /= band_width[k]; */ - exp_normn = norm_l( L_a ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_s( band_width[k] ); - norm_a_fx = div_l( L_shl( L_a, exp_normn ), shl( band_width[k], exp_normd ) ); /* (Qa+exp_normn)-exp_normd-1); */ - Qnorm_a = sub( sub( add( Qa, exp_normn ), exp_normd ), 1 ); - - /*p2a = 10.0f * (float) log10 (p / a); */ - p2a_fx = 0; + bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; /* Q0 */ move16(); - IF( norm_a_fx > 0 ) - { - exp_normn = norm_l( L_p ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_s( norm_a_fx ); - pa_fx = div_l( L_shl( L_p, exp_normn ), shl( norm_a_fx, exp_normd ) ); /* Qpa + exp_normn + Qnorm_a + exp_normd - 1 */ - Qpa = sub( sub( add( Qa, exp_normn ), add( Qnorm_a, exp_normd ) ), 1 ); + } + IF( LT_16( bq2_fx[i], MINIMUM_ENERGY_LOWBRATE ) ) + { + bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; /* Q0 */ + move16(); + } + } - L_tmp = L_deposit_h( pa_fx ); - Qpa = add( Qpa, 16 ); - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( 30, exp ); - exp = sub( exp, Qpa ); - L_tmp = L_Comp( exp, frac ); + /* Get number of bits by Huffman0 coding */ + ebits = large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 0 ); /* Q0 */ - /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ - L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */ + IF( is_transient_fx ) + { + /* Get number of bits by Huffman coding */ + hbits = small_symbol_enc_tran_fx( hBstr, bq2_temp_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); /* Q0 */ + } + ELSE + { + /* Get number of bits by Huffman coding */ + hbits = small_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); /* Q0 */ + } - p2a_fx = round_fx_sat( L_shl_sat( L_p2a, 13 ) ); /* 27 -16 -> 11 */ - } + /* comparing used bits */ + test(); + IF( LT_16( ebits, hbits ) || EQ_16( hbits, -1 ) ) + { + deng_cmode = 0; + move16(); + push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); + large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 1 ); + deng_bits = add( ebits, BITS_DE_CMODE ); /* Q0 */ + } + ELSE + { + /* setting energy difference coding mode and storing it */ + deng_cmode = 1; + move16(); + push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - IF( LE_16( p2a_fx, p2a_th_fx ) ) - { - p2a_flags_fx[k] = 0; - move16(); - } + deng_bits = add( hbits, BITS_DE_CMODE ); /* Q0 */ + + /* packing indice */ + IF( is_transient_fx ) + { + Copy( bq2_temp_fx, bq2_fx, bands_fx ); /* Q0 */ + small_symbol_enc_tran_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 1, is_transient_fx ); } ELSE { - p2a_flags_fx[k] = 0; - move16(); + small_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 1, is_transient_fx ); } + } - push_indice( hBstr, IND_HQ2_P2A_FLAGS, p2a_flags_fx[k], 1 ); - j = add( j, 1 ); + /* Reconstruct quantized spectrum */ + bq1_fx[0] = add( bq2_fx[0], bq0_fx ); /* Q0 */ + move16(); + FOR( k = 1; k < bands_fx; k++ ) + { + bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); /* Q0 */ + move16(); } - return ( j ); /* Q0 */ + FOR( k = 0; k < bands_fx; k++ ) + { + L_band_energy[k] = Mpy_32_16_1( L_qint, bq1_fx[k] ); /* 29+0-15 -> Qbe(Q14) */ + move32(); + } + + IF( is_transient_fx ) + { + reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); + } + + return ( deng_bits ); /* Q0 */ } -static Word16 p2a_threshold_quant_ivas_fx( + +/*-------------------------------------------------------------------* + * p2a_threshold_quant() + * + * + *-------------------------------------------------------------------*/ + +static Word16 p2a_threshold_quant_fx( BSTR_ENC_HANDLE hBstr, /* i/o: : bit stream */ const Word32 *L_t_audio, /* i : Q12 : input spectrum */ const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ @@ -3506,6 +1710,7 @@ static Word16 p2a_threshold_quant_ivas_fx( move16(); set16_fx( p2a_flags_fx, 1, bands ); + move16(); j = 0; move16(); @@ -3525,7 +1730,7 @@ static Word16 p2a_threshold_quant_ivas_fx( FOR( i = band_start[k]; i <= band_end[k]; i++ ) { temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Q12+exp_norm-16 -> exp_norm-4 */ - L_e = L_mult( temp_fx, temp_fx ); /* (exp_norm-4)*2 + 1 */ + L_e = L_mult( temp_fx, temp_fx ); /* 2*(exp_norm-4)+1 */ IF( GT_32( L_e, L_p ) ) { @@ -3752,161 +1957,3 @@ static void mdct_spectrum_fine_gain_enc_fx( return; } - -static void mdct_spectrum_fine_gain_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_ybuf[], /* i : Q12 : input spectrum */ - Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ - const Word16 bands, /* i : Q0 : nubmber of subbands */ - const Word32 L_qint, /* i : Q29 : */ - const Word16 Ngq, /* i : Q0 : */ - const Word16 gqlevs, /* i : Q0 : quantized level */ - const Word16 gqbits /* i : Q0 : quantized bits */ -) -{ - Word16 i, k; - - Word16 delta_fx, Qdelta; - Word32 L_delta; - Word32 L_q; - - Word16 gain_table_fx[MAX_GQLEVS]; - Word16 Qgt; - Word16 gamma_fx; - Word16 Qgamma; - - Word16 exp_safe; - Word16 exp_normn, exp_normd; - Word16 exp_norm; - - Word32 L_temp; - Word16 temp_lo_fx, temp_hi_fx, temp_fx, temp2_fx; - - Word32 L_Eyy, L_Exy; - /*Word16 QE; */ - - Word16 d_fx; - Word16 dmin_fx; - Word16 imin_fx; - - /* Fine gain quantization on only the most significant energy bands */ - - /*delta = qint / gqlevs; */ - exp_normn = norm_l( L_qint ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_s( gqlevs ); - delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); - Qdelta = add( sub( exp_normn, exp_normd ), 28 ); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); /* Q29 */ - /*q = (-qint + delta) / 2.0f; */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q29 */ - - FOR( i = 0; i < gqlevs; i++ ) - { - /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ - L_temp = L_shr( L_shr( L_q, 1 ), sub( 29, 16 ) ); /* Q16 */ - temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); - Qgt = sub( 14, temp_hi_fx ); - gain_table_fx[i] = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qgt */ - move16(); - - /*q += delta; */ - L_q = L_add( L_q, L_delta ); - gain_table_fx[i] = shl( gain_table_fx[i], sub( 14, Qgt ) ); /* Qgt -> Q14 */ - move16(); - } - - FOR( k = sub( bands, Ngq ); k < bands; k++ ) - { - /*Eyy = 0.0f; */ - /*Exy = 0.0f; */ - /*for (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) */ - /*{ */ - /* Eyy += y2[i] * y2[i]; */ - /* Exy += ybuf[i] * y2[i]; */ - /*} */ - exp_safe = 4; - move16(); /* 4 is too large. but never happen overflow */ - L_temp = L_deposit_l( 0 ); - FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) - { - L_temp = L_or( L_temp, L_abs( L_y2[i] ) ); /* Q12 */ - L_temp = L_or( L_temp, L_abs( L_ybuf[i] ) ); /* Q12 */ - } - exp_norm = norm_l( L_temp ); - exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ - - L_Eyy = L_deposit_l( 0 ); - L_Exy = L_deposit_l( 0 ); - /*QE = add(shl(add(Qs-16, exp_norm), 1), 1); //(Qs+exp_norm-16)*2+1; */ - FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) - { - /*Eyy += y2[i] * y2[i]; */ - temp_fx = round_fx( L_shl( L_y2[i], exp_norm ) ); /* Q12 + exp_norm - 16 */ - L_Eyy = L_mac( L_Eyy, temp_fx, temp_fx ); /* (Q12 + exp_norm - 16)*2 + 1 */ - - /*Exy += ybuf[i] * y2[i]; */ - temp2_fx = round_fx( L_shl( L_ybuf[i], exp_norm ) ); /* Q12 + exp_norm - 16 */ - L_Exy = L_mac( L_Exy, temp2_fx, temp_fx ); /* (Q12 + exp_norm - 16)*2 + 1 */ - } - - test(); - IF( L_Eyy > 0x0L && L_Exy > 0x0L ) - { - /*gamma = Exy / Eyy; */ - exp_normn = norm_l( L_Exy ); - exp_normn = sub( exp_normn, 1 ); - exp_normd = norm_l( L_Eyy ); - gamma_fx = div_l( L_shl( L_Exy, exp_normn ), round_fx_sat( L_shl( L_Eyy, exp_normd ) ) ); /* Qgamma */ - Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ - gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ - - dmin_fx = 32767; - move16(); - imin_fx = -1; - move16(); - FOR( i = 0; i < gqlevs; i++ ) - { - d_fx = abs_s( sub( gamma_fx, gain_table_fx[i] ) ); /* Q14 */ - IF( LT_16( d_fx, dmin_fx ) ) - { - dmin_fx = d_fx; /* Q14 */ - move16(); - imin_fx = i; /* Q0 */ - move16(); - } - } - - gamma_fx = gain_table_fx[imin_fx]; /* Q14 */ - move16(); - - FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) - { - /*y2[i] *= gamma; */ - /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ - IF( L_y2[i] >= 0x0 ) - { - L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); /* Q12 */ - move32(); - } - ELSE - { - L_y2[i] = L_negate( L_shl( Mpy_32_16_1( L_abs( L_y2[i] ), gamma_fx ), 1 ) ); /* Q12 */ - move32(); - } - } - } - ELSE - { - imin_fx = 0; - move16(); - } - - push_indice( st_fx->hBstr, IND_HQ2_SUBBAND_GAIN, imin_fx, gqbits ); - } - - return; -} diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index d9d7c052585e634e0c97b1af28d8299bd8ae0f21..72a26b2482533cde5902e0b020ed60d1f0ca799b 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -3320,9 +3320,13 @@ static void IGF_Whitening_ivas_fx( FOR( sb = hGrid->tile[p]; sb < hGrid->tile[p + 1]; sb++ ) { IF( LT_32( powerSpectrum[sb], 1 ) ) - hPrivateData->logSpec[sb] = 0; /* max(0,FLT_MIN_EXP )*/ + { + hPrivateData->logSpec[sb] = 0; /* max(0,FLT_MIN_EXP=-125 )*/ + } ELSE + { hPrivateData->logSpec[sb] = extract_l( L_max( 0, L_shr( L_add( BASOP_Util_Log2( powerSpectrum[sb] ), L_shl( powerSpectrum_e[sb], Q25 ) ), Q25 ) ) ); + } move16(); } } @@ -4137,7 +4141,7 @@ void IGFEncApplyMono_ivas_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); + calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag ); } IGF_CalculateEnvelope_ivas_fx( st->hIGFEnc, pMDCTSpectrum_fx, e_mdct, pPowerSpectrumParameter_fx, pPowerSpectrumParameter_exp, igfGridIdx, st->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, st->element_mode, att_fx ); @@ -4267,6 +4271,8 @@ void IGFEncApplyStereo_fx( { pPowerSpectrumParameter_fx[0] = NULL; pPowerSpectrumParameter_fx[1] = NULL; + exp_pPowerSpectrumParameter_fx[0] = NULL; + exp_pPowerSpectrumParameter_fx[1] = NULL; pPowerSpectrumParameterMsInv_fx[0] = NULL; pPowerSpectrumParameterMsInv_fx[1] = NULL; q_pPowerSpectrumParameterMsInv_fx[0] = NULL; @@ -4289,6 +4295,7 @@ void IGFEncApplyStereo_fx( ELSE { pPowerSpectrumParameter_fx[ch] = NULL; + exp_pPowerSpectrumParameter_fx[ch] = NULL; } IGF_Whitening_ivas_fx( hIGFEnc[ch], pPowerSpectrumParameter_fx[ch], exp_pPowerSpectrumParameter_fx[ch], igfGridIdx, sts[ch]->hTranDet->transientDetector.bIsAttackPresent, last_core_acelp, ( sts[0]->hTcxEnc->fUseTns[frameno] || sts[1]->hTcxEnc->fUseTns[frameno] ), sp_aud_decision0, element_brate, sts[ch]->element_mode ); diff --git a/lib_enc/igf_scf_enc.c b/lib_enc/igf_scf_enc.c index 16f2560d1e4a858f0c52b217bf2a956aaa1f7876..c9a549e5a383a37e05cae2b9700969e77afd7784 100644 --- a/lib_enc/igf_scf_enc.c +++ b/lib_enc/igf_scf_enc.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 7c29b4e06757134f1092b24d5013ee6ce1b86719..e06b42f68c2816e42502a1219dc602b9649fcccb 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -545,6 +545,7 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } +#ifndef FIX_2405_HARM_SMC_INIT IF( st->element_mode == EVS_MONO ) { speech_music_clas_init_fx( st->hSpMusClas ); @@ -553,6 +554,10 @@ ivas_error init_encoder_fx( { speech_music_clas_init_ivas_fx( st->hSpMusClas ); } +#else + speech_music_clas_init_fx( st->element_mode, st->hSpMusClas ); +#endif + st->sp_aud_decision0 = 0; move16(); st->sp_aud_decision1 = 0; @@ -686,14 +691,7 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - IF( st->element_mode == EVS_MONO ) - { - td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); - } - ELSE - { - td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); - } + td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); } ELSE { @@ -849,8 +847,9 @@ ivas_error init_encoder_fx( { return error; } - +#ifndef HARMONIZE_TBE InitSWBencBuffer_fx( st->hBWE_TD ); +#endif } ELSE { @@ -858,9 +857,13 @@ ivas_error init_encoder_fx( { return error; } - +#ifndef HARMONIZE_TBE InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 81b9ba49e904333c5881cfc372e0e98dfe11db49..0efcf795b2369c00a81ab0d120095893cf4166db 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -78,16 +78,18 @@ Word16 inov_encode_fx( Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ Word16 *unbits, /* o : number of unused bits for PI */ const Word16 L_subfr, /* i : subframe length */ - Word16 shift ) + const Word16 shift, + Word16 Q_new ) { - Word16 dn[2 * L_SUBFR]; + Word16 dn[2 * L_SUBFR], Qdn, Qcn, Qh2; Word16 nBits, cmpl_flag; Word16 stack_pulses; Word16 g1, g2; Word16 Rw[L_SUBFR]; Word16 acelpautoc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - (void) last_L_frame; + Word16 i, k; + Word16 Qxn, max_xn2; stack_pulses = 0; move16(); @@ -106,304 +108,31 @@ Word16 inov_encode_fx( move16(); } - /*----------------------------------------------------------------* - * Update target vector for codebook search in residual domain - * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning) - * Correlation between target xn2[] and impulse response h1[] - *----------------------------------------------------------------*/ - - test(); - test(); - IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) ) - { - acelpautoc = 1; - move16(); - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_SUBFR ); - /* h2: Q11, Rw: (Rw_e)Q */ - /* Rw_e = */ E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 ); - - E_ACELP_conv( xn2, h2, cn ); - - /* dn_e -> Rw_e*Q_xn */ - /*dn_e = */ E_ACELP_toeplitz_mul_fx( Rw, cn, dn, L_SUBFR, 1 ); - } - ELSE - { - acelpautoc = 0; - move16(); - updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr ); - /* scaling of cn[] to limit dynamic at 12 bits */ - Scale_sig( cn, L_subfr, shift ); - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - corr_xh_fx( xn2, dn, h2 ); - } - - /*-----------------------------------------------------------------* - * Set complexity reduction flag to limit the number of iterations - * in algebraic innovation search - *-----------------------------------------------------------------*/ - cmpl_flag = 0; - move16(); - test(); - IF( st_fx->acelp_cfg.fcb_mode ) - { - /* set number of iterations in TD stereo, secondary channel */ - test(); - if ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) - { - cmpl_flag = 1; - move16(); - } - } - ELSE IF( EQ_16( L_frame, L_FRAME ) && EQ_16( coder_type, TRANSITION ) ) + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) { - test(); - test(); - if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - test(); - if ( EQ_32( core_brate, ACELP_11k60 ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || EQ_16( tc_subfr, TC_0_0 ) || ( EQ_16( i_subfr, 3 * L_SUBFR ) && EQ_16( tc_subfr, TC_0_64 ) ) ) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - if ( ( EQ_32( core_brate, ACELP_13k20 ) || EQ_32( core_brate, ACELP_12k15 ) ) && ( ( i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) || LE_16( tc_subfr, TC_0_64 ) ) ) - { - cmpl_flag = 3; - move16(); - } - } - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - IF( LE_32( core_brate, ACELP_32k ) ) - { - cmpl_flag = 4; - move16(); - - test(); - IF( EQ_16( coder_type, TRANSITION ) && GT_16( bwidth, WB ) ) - { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } - } - } - ELSE IF( LE_32( core_brate, ACELP_48k ) ) - { - cmpl_flag = 3; - move16(); - - IF( EQ_16( coder_type, TRANSITION ) ) - { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } - } - } - ELSE - { - cmpl_flag = 4; - move16(); - - IF( EQ_16( coder_type, TRANSITION ) ) - { - IF( LE_16( i_subfr, L_SUBFR ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - ELSE - { - cmpl_flag = sub( cmpl_flag, 2 ); - } - } - - if ( coder_type == INACTIVE ) - { - cmpl_flag = 4; - move16(); - } - } - } - - test(); - test(); - test(); - IF( NE_16( L_frame, st_fx->last_L_frame ) && GT_32( core_brate, ACELP_13k20 ) && ( LT_32( core_brate, ACELP_32k ) || EQ_16( bwidth, WB ) ) ) - { - if ( GT_16( cmpl_flag, 1 ) ) - { - cmpl_flag = sub( cmpl_flag, 1 ); - } - } - - /*-----------------------------------------------------------------* - * Find and encode the algebraic innovation - *-----------------------------------------------------------------*/ - - set16_fx( y2, 0, L_SUBFR ); - - IF( !Opt_AMR_WB ) - { - IF( st_fx->acelp_cfg.fcb_mode ) + maximum_abs_16_fx( xn2, L_subfr, &max_xn2 ); + IF( max_xn2 ) { + Qxn = add( sub( Q_new, 1 ), shift ); } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; + Qxn = 0; move16(); - - - IF( EQ_16( nBits, 7 ) ) - { - acelp_1t64_fx( hBstr, dn, h2, code, y2, L_SUBFR ); - } - ELSE IF( EQ_16( nBits, 12 ) ) - { - acelp_2t32_fx( hBstr, dn, h2, code, y2 ); - } - ELSE - { - *unbits = add( *unbits, acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ) ); - move16(); - } - } - } - ELSE - { - IF( EQ_32( core_brate, ACELP_6k60 ) ) - { - acelp_2t32_fx( hBstr, dn, h2, code, y2 ); - } - ELSE IF( ( EQ_32( core_brate, ACELP_8k85 ) ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); - } - ELSE IF( EQ_32( core_brate, ACELP_12k65 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); - } - ELSE IF( EQ_32( core_brate, ACELP_14k25 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); - } - ELSE IF( EQ_32( core_brate, ACELP_15k85 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); - } - ELSE IF( EQ_32( core_brate, ACELP_18k25 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); - } - ELSE IF( EQ_32( core_brate, ACELP_19k85 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); - } - ELSE IF( EQ_32( core_brate, ACELP_23k05 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB, st_fx->element_mode ); } - ELSE IF( EQ_32( core_brate, ACELP_23k85 ) ) - { - acelp_4t64_fx( hBstr, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB, st_fx->element_mode ); - } - } - - /*----------------------------------------------------------------* - * Pitch sharpening - *----------------------------------------------------------------*/ - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - - return stack_pulses; -} - - -Word16 inov_encode_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter input response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ - const Word16 L_subfr, /* i : subframe length */ - Word16 shift, - Word16 Q_new ) -{ - Word16 dn[2 * L_SUBFR], Qdn, Qcn, Qh2; - Word16 nBits, cmpl_flag; - Word16 stack_pulses; - Word16 g1, g2; - Word16 Rw[L_SUBFR]; - Word16 acelpautoc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - Word16 i, k; - Word16 Qxn, max_xn2; - stack_pulses = 0; - move16(); - - IF( EQ_16( L_frame, L_FRAME ) ) - { - g1 = FORMANT_SHARPENING_G1; - move16(); - g2 = FORMANT_SHARPENING_G2; + Qcn = Q_new; move16(); } ELSE { - g1 = FORMANT_SHARPENING_G1_16k; - move16(); - g2 = FORMANT_SHARPENING_G2_16k; + Q_new = 0; move16(); - } - maximum_abs_16_fx( xn2, L_subfr, &max_xn2 ); - IF( max_xn2 ) - { - Qxn = add( sub( Q_new, 1 ), shift ); - } - ELSE - { Qxn = 0; move16(); + Qcn = 0; + move16(); } /*----------------------------------------------------------------* @@ -414,8 +143,6 @@ Word16 inov_encode_ivas_fx( test(); test(); - Qcn = Q_new; - move16(); IF( GT_32( core_brate, ACELP_13k20 ) && !Opt_AMR_WB && EQ_16( L_subfr, L_SUBFR ) ) { acelpautoc = 1; @@ -436,23 +163,40 @@ Word16 inov_encode_ivas_fx( acelpautoc = 0; move16(); updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_subfr ); + /* scaling of cn[] to limit dynamic at 12 bits */ Scale_sig( cn, L_subfr, shift ); - Word16 q_h1 = sub( 14, norm_s( h2[0] ) ); - Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/ - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); - corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 - IF( LT_16( Qdn, Qcn ) ) + + IF( st_fx->element_mode == EVS_MONO ) { - scale_sig( cn, L_subfr, sub( Qdn, Qcn ) ); - Qcn = Qdn; + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); + + corr_xh_fx( xn2, dn, h2 ); + + Qdn = 0; move16(); } ELSE { - scale_sig( dn, L_subfr, sub( Qcn, Qdn ) ); - Qdn = Qcn; - move16(); + Word16 q_h1 = sub( 14, norm_s( h2[0] ) ); + Scale_sig( h2, L_SUBFR, sub( 11, q_h1 ) ); /* set h2[] in Q11*/ + + cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr( add( pt_pitch, 26 ), 6 ), 0, L_subfr ); + + corr_xh_ivas_fx( xn2, Qxn, dn, &Qdn, h2, L_subfr ); // Q(dn) = Q_new+1 + + IF( LT_16( Qdn, Qcn ) ) + { + scale_sig( cn, L_subfr, sub( Qdn, Qcn ) ); + Qcn = Qdn; + move16(); + } + ELSE + { + scale_sig( dn, L_subfr, sub( Qcn, Qdn ) ); + Qdn = Qcn; + move16(); + } } } @@ -584,8 +328,11 @@ Word16 inov_encode_ivas_fx( set16_fx( y2, 0, L_SUBFR ); - Qh2 = sub( 14, norm_s( h2[0] ) ); - Scale_sig( h2, L_SUBFR, sub( Q12, Qh2 ) ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + Qh2 = sub( 14, norm_s( h2[0] ) ); + Scale_sig( h2, L_SUBFR, sub( Q12, Qh2 ) ); + } IF( !Opt_AMR_WB ) { @@ -683,7 +430,7 @@ Word16 inov_encode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr >> 6]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; move16(); diff --git a/lib_enc/isf_enc_amr_wb_fx.c b/lib_enc/isf_enc_amr_wb_fx.c index d58998565bdb404e232a6b7b8c5e0318eae1c3a4..bbb734f9c38d29ccc72586a203f5544c9537160d 100644 --- a/lib_enc/isf_enc_amr_wb_fx.c +++ b/lib_enc/isf_enc_amr_wb_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/ivas_agc_enc_fx.c b/lib_enc/ivas_agc_enc_fx.c index 10d7cb8c71c2b736bc7fa24bbd467bed6f7dc94b..52e5fbea5e8ef01b0d96bfb7a6bab2bfdd9a3b87 100644 --- a/lib_enc/ivas_agc_enc_fx.c +++ b/lib_enc/ivas_agc_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,13 +30,10 @@ *******************************************************************************************************/ - #include -#include #include #include "options.h" #include "prot_fx.h" -#include "rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "basop_util.h" diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 96bbca887782fdb1e711c4ff9ae0b289ab940d66..859b8b449641454a393535a2b5d119b04b78c8a7 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,15 +32,11 @@ #include #include "options.h" -#include "cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_cnst.h" #include "wmc_auto.h" -#include #include "prot_fx_enc.h" #include "ivas_prot_fx.h" -#include "prot_fx_enc.h" #ifdef DEBUGGING #include "debug.h" #endif @@ -91,12 +87,8 @@ ivas_error ivas_core_enc_fx( STEREO_ICBWE_ENC_HANDLE hStereoICBWE; STEREO_TD_ENC_DATA_HANDLE hStereoTD; Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ - Word32 shb_speech_fx32[L_FRAME16k]; - Word32 *new_swb_speech_fx; Word16 *inp_fx[CPE_CHANNELS]; Word16 *shb_speech_fx; - Word16 Q_shb_spch; - Word32 new_swb_speech_buffer_fx[L_FRAME48k + STEREO_DFT_OVL_MAX]; Word16 new_inp_resamp16k_fx[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ Word16 *hb_speech_fx; Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ @@ -114,12 +106,11 @@ ivas_error ivas_core_enc_fx( Word16 max_num_indices_BWE; Word16 i, shift, Q_min; - set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); - FOR( i = 0; i < CPE_CHANNELS; i++ ) { set_zero_fx( bwe_exc_extended_fx[i], L_FRAME32k + NL_BUFF_OFFSET ); set16_fx( old_syn_12k8_16k_fx[i], 0, L_FRAME16k ); + set16_fx( voice_factors_fx[i], 0, NB_SUBFR16k ); } push_wmops( "ivas_core_enc" ); @@ -127,9 +118,6 @@ ivas_error ivas_core_enc_fx( error = IVAS_ERR_OK; move32(); - Q_shb_spch = 0; - move16(); - /*------------------------------------------------------------------* * General initialization *-----------------------------------------------------------------*/ @@ -226,29 +214,21 @@ ivas_error ivas_core_enc_fx( // fft_buff_fx_exp = add(fft_buff_fx_exp,1); FOR( i = 0; i < st->nb_subfr; i++ ) { - Scale_sig( &A_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 } + + Word32 last_element_brate_tmp = element_brate; + move32(); IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, - &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], - vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ), - IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, - &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], - vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ), - IVAS_ERR_OK ) ) - { - return error; - } + last_element_brate_tmp = last_element_brate; + move32(); } + + pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate_tmp, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */, + &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n], + vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ); + test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, IVAS_SCE ) ) { @@ -310,7 +290,7 @@ ivas_error ivas_core_enc_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_pre_enc_ivas_fx( st, old_inp_12k8_fx[n], sub( Q_new[n], 1 ), old_inp_16k_fx[n], sub( Q_new[n], 1 ), sts[0]->active_cnt, last_element_mode ); + core_switching_pre_enc_fx( st, old_inp_12k8_fx[n], sub( Q_new[n], 1 ), old_inp_16k_fx[n], sub( Q_new[n], 1 ), sts[0]->active_cnt, last_element_mode ); /*---------------------------------------------------------------------* * ACELP core encoding @@ -321,23 +301,25 @@ ivas_error ivas_core_enc_fx( IF( st->core == ACELP_CORE ) { /* ACELP core encoder */ +#ifdef HARMONIZE_ACELP_ENC + IF( NE_32( ( error = acelp_core_enc_fx( st, inp_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n], 0 ) ), IVAS_ERR_OK ) ) +#else Word16 Q_old_syn_12k8_16k = 0; move16(); IF( NE_32( ( error = acelp_core_enc_ivas_fx( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ), IVAS_ERR_OK ) ) +#endif { return error; } +#ifndef HARMONIZE_ACELP_ENC Scale_sig( old_syn_12k8_16k_fx[n], st->L_frame, sub( sub( Q_new[n], 1 ), Q_old_syn_12k8_16k ) ); // Q_old_syn_12k8_16k -> Q_new[n] - 1 +#endif } test(); test(); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - FOR( i = 0; i < st->nb_subfr; i++ ) - { - Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 - } TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; Word16 Q_spec_old, L_spec; @@ -620,8 +602,6 @@ ivas_error ivas_core_enc_fx( * Postprocessing, BWEs and Updates *---------------------------------------------------------------------*/ - Word16 tmp_input_fx[L_FRAME48k], tmp_old_input_fx[L_FRAME48k], q_inp[2]; - FOR( n = 0; n < n_CoreChannels; n++ ) { st = sts[n]; @@ -636,22 +616,11 @@ ivas_error ivas_core_enc_fx( move16(); } - Copy( st->input_fx - input_frame, tmp_old_input_fx, input_frame ); - Copy( st->input_fx, tmp_input_fx, input_frame ); - q_inp[0] = st->q_old_inp; - q_inp[1] = st->q_inp; - - Scale_sig( st->input_fx - input_frame, 2 * input_frame, sub( -1, st->q_inp ) ); - st->q_inp = -1; - move16(); - st->q_old_inp = -1; - move16(); - /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - core_switching_post_enc_ivas_fx( st, old_inp_12k8_fx[n], old_inp_16k_fx[n], A_fx[n], Q_new[n] ); + core_switching_post_enc_fx( st, NULL, NULL, NULL, 0, 0, 0, NULL ); /*---------------------------------------------------------------------* * WB TBE encoding @@ -673,7 +642,11 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ +#ifdef HARMONIZE_TBE + wb_tbe_enc_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); +#else wb_tbe_enc_ivas_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); +#endif } ELSE IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { @@ -686,7 +659,19 @@ ivas_error ivas_core_enc_fx( * SWB(FB) BWE encoding *---------------------------------------------------------------------*/ - new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; + Word16 q_inp_orig; + q_inp_orig = st->q_inp; + move16(); + test(); + IF( GE_32( input_Fs, 32000 ) && st->hBWE_TD != NULL ) + { + st->q_inp = -1; + st->q_old_inp = -1; + move16(); + move16(); + Scale_sig( st->input_fx - input_frame, shl( input_frame, 1 ), sub( st->q_inp, q_inp_orig ) ); + } + new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); shb_speech_fx = new_inp_resamp16k_fx[n]; /* reuse existing buffer: shb_speech[L_FRAME16k] */ @@ -719,7 +704,7 @@ ivas_error ivas_core_enc_fx( st->cldfbSynTd->Q_cldfb_state = sub( q_re_im_buf[n], 1 ); } - swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, &Q_shb_spch, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf[n], hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, shb_speech_fx, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf[n], hCPE ); st->cldfbSynTd->Q_cldfb_state = sub( q_re_im_buf[n], 1 ); } @@ -731,12 +716,6 @@ ivas_error ivas_core_enc_fx( } } - Word16 Q_shb_spch_16 = Q_shb_spch; - move16(); - shift = add( getScaleFactor16( shb_speech_fx, L_FRAME16k ), Q16 ); - Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch - Q_shb_spch = add( Q_shb_spch, shift ); - IF( st->hBWE_FD ) { shift = getScaleFactor16( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k ); @@ -756,24 +735,34 @@ ivas_error ivas_core_enc_fx( Word16 Q_fb_exc; Word16 fb_exc_fx[L_FRAME16k]; - swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], Q_shb_spch_16, st->voicing_fx, pitch_buf_fx[n] ); + swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ +#ifdef HARMONIZE_TBE + fb_tbe_enc_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); +#else fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); +#endif } } } ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) ) { - Copy_Scale_sig_32_16( shb_speech_fx32, shb_speech_fx, L_FRAME16k, -Q16 ); // Q_shb_spch - 16 /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx[n], old_inp_16k_fx[n], old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, st->q_inp, shb_speech_fx, sub( Q_shb_spch, Q16 ), sub( Q_new[n], 1 ) ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx[n], old_inp_16k_fx[n], old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, st->q_inp, shb_speech_fx, sub( Q_new[n], 1 ) ); } Scale_sig( old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q1, Q_new[n] ) ); // Q0 + IF( GE_32( input_Fs, 32000 ) && st->hBWE_TD != NULL ) + { + Scale_sig( st->input_fx, input_frame, sub( q_inp_orig, st->q_inp ) ); + st->q_inp = q_inp_orig; + move16(); + } + /*---------------------------------------------------------------------* * SWB DTX/CNG encoding *---------------------------------------------------------------------*/ @@ -784,66 +773,29 @@ ivas_error ivas_core_enc_fx( IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( GE_16( input_frame, L_FRAME32k ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) { /* SHB DTX/CNG encoder */ - Copy_Scale_sig_32_16( shb_speech_fx32, shb_speech_fx, L_FRAME16k, negate( Q_shb_spch ) ); // Q0 - swb_CNG_enc_ivas_fx( st, shb_speech_fx /* Unmodified */, old_syn_12k8_16k_fx[n] ); + swb_CNG_enc_fx( st, shb_speech_fx, old_syn_12k8_16k_fx[n] ); } /*-------------------------------------------------------------------* * Inter-channel BWE encoding *-------------------------------------------------------------------*/ - Word16 q_new_swb_speech_buffer = getScaleFactor16( new_swb_speech_buffer_fx_16, L_FRAME48k + STEREO_DFT_OVL_MAX ); - Scale_sig( new_swb_speech_buffer_fx_16, L_FRAME48k + STEREO_DFT_OVL_MAX, q_new_swb_speech_buffer ); // st->q_inp+q_new_swb_speech_buffer - q_new_swb_speech_buffer = add( st->q_inp, q_new_swb_speech_buffer ); test(); test(); IF( n == 0 && GE_32( input_Fs, 32000 ) && hStereoICBWE != NULL ) { - Word32 voice_factors_fx32[CPE_CHANNELS][NB_SUBFR16k]; - stereo_icBWE_preproc_fx( hCPE, input_frame, new_swb_speech_buffer_fx_16 /*tmp buffer*/, q_new_swb_speech_buffer ); - - q_new_swb_speech_buffer = add( q_new_swb_speech_buffer, 16 ); - Copy_Scale_sig_16_32_no_sat( new_swb_speech_buffer_fx_16, new_swb_speech_buffer_fx, L_FRAME48k + STEREO_DFT_OVL_MAX, Q16 ); // q_new_swb_speech_buffer+st->q_inp - 16 - > q_new_swb_speech_buffer+st->q_inp - Copy_Scale_sig_16_32_no_sat( voice_factors_fx[0], voice_factors_fx32[0], NB_SUBFR16k, Q16 ); // Q31 + stereo_icBWE_preproc_fx( hCPE, input_frame, new_swb_speech_buffer_fx_16 /*tmp buffer*/, st->q_inp ); - stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, sub( Q31, Q_shb_spch ), new_swb_speech_buffer_fx, sub( Q31, q_new_swb_speech_buffer ), voice_factors_fx32[0] ); - - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - test(); - test(); - test(); - IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) - { - } - ELSE - { - hStereoICBWE->prevSpecMapping_fx = 0; - move32(); - } - } + stereo_icBWE_enc_fx( hCPE, shb_speech_fx, new_swb_speech_buffer_fx_16, st->q_inp, voice_factors_fx[0] ); } - Copy( tmp_old_input_fx, st->input_fx - input_frame, input_frame ); - Copy( tmp_input_fx, st->input_fx, input_frame ); - st->q_old_inp = q_inp[0]; - move16(); - st->q_inp = q_inp[1]; - move16(); - - /*---------------------------------------------------------------------* - * Channel-aware mode - write signaling information into the bitstream - *---------------------------------------------------------------------*/ - - signaling_enc_rf_fx( st ); - /*---------------------------------------------------------------------* * Common updates *---------------------------------------------------------------------*/ IF( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ { - updt_enc_common_ivas_fx( st, Q_new[n] ); + updt_enc_common_fx( st, Q_new[n] ); } IF( st->hBWE_FD != NULL ) diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index d62fa49c181ebc85fddb0e74f850d3f1625d405a..e4576ceaaf52f180e4bd2a06bc5bbbce1197c1ca 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,22 +32,16 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" #include "prot_fx_enc.h" #include "ivas_prot_fx.h" #include "wmc_auto.h" -#include #ifdef DEBUGGING #include "debug.h" #include "string.h" #endif -#include "prot_fx_enc.h" -#include "ivas_prot_fx.h" /*---------------------------------------------------------------* * Local constants @@ -56,15 +50,13 @@ #define SCE_SMC_THR 16000 -static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, Word32 enerBuffer_dft[], const Word16 no_channels, const Word32 input_Fs, Word16 enerBuffer_dft_e[] ); - /*-------------------------------------------------------------------* - * pre_proc_front_ivas() - * - * Front Pre-processing for IVAS - * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) + * Local function prototypes *--------------------------------------------------------------------*/ -static Word16 get_zero_flag( Word32 arr[], Word16 len ) + +static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, Word32 enerBuffer_dft[], const Word16 no_channels, const Word32 input_Fs, Word16 enerBuffer_dft_e[] ); + +static Word16 get_zero_flag( const Word32 arr[], const Word16 len ) { FOR( Word16 j = 0; j < len; j++ ) { @@ -76,76 +68,71 @@ static Word16 get_zero_flag( Word32 arr[], Word16 len ) return 0; } -ivas_error pre_proc_front_ivas_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ - const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - const Word16 n, /* i : channel number Q0*/ - Word16 old_inp_12k8_fx[], /* o : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ - Word16 *relE_fx, /* o : frame relative energy Q8*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ - Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ - Word16 *epsP_fx_q, - Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ - Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ - Word16 *attack_flag, /* o : flag signaling attack Q0*/ - Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ - Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ - Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ - Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ - Word16 *q_old_wsp, - Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ - Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ - Word16 *loc_harm, /* o : harmonicity flag Q0*/ - Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ - Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ - Word16 *enerBuffer_fx_exp, /* o : energy buffer */ - Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ - Word16 *fft_buff_fx_q, /* o : FFT buffer */ - const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ - const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ - const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ - const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ - Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) fr_bands_LR_fx_q*/ - Word16 fr_bands_LR_fx_q[CPE_CHANNELS], - const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ - Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q)*/ - Word16 lf_E_LR_fx_q, - const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN (band_energies_LR_fx_q)*/ - Word16 band_energies_LR_fx_q, - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ - const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ - const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ - const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ - Word16 *Q_new -#ifdef DEBUG_MODE_INFO - , - const Word16 ch_idx -#endif + +/*-------------------------------------------------------------------* + * pre_proc_front_ivas() + * + * Front Pre-processing for IVAS + * (resampling, spectral analysis, LP analysis, VAD, OL pitch calculation, classification) + *--------------------------------------------------------------------*/ + +void pre_proc_front_ivas_fx( + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word32 element_brate, /* i : SCE/CPE element bitrate Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 n, /* i : channel number Q0*/ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 *relE_fx, /* o : frame relative energy Q8*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[M + 1], /* o : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* o : Q factor of LP prediction errors */ + Word16 lsp_new_fx[M], /* o : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* o : LSPs in the middle of the frame Q15*/ + Word16 *vad_hover_flag, /* o : VAD hangover flag Q0*/ + Word16 *attack_flag, /* o : flag signaling attack Q0*/ + Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer Q(q_re_im_buf)*/ + Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer Q(q_re_im_buf)*/ + Word16 *q_re_im_buf, /* i/o: Q-factor of real and imag buffer */ + Word16 old_wsp_fx[], /* o : weighted input signal buffer q_old_wsp*/ + Word16 *q_old_wsp, /* o : Q factor of weighted input signal buffer */ + Word16 pitch_fr_fx[NB_SUBFR], /* o : fractional pitch values Q6*/ + Word16 voicing_fr_fx[NB_SUBFR], /* o : fractional pitch gains Q15*/ + Word16 *loc_harm, /* o : harmonicity flag Q0*/ + Word16 *cor_map_sum_fx, /* o : speech/music clasif. parameter Q8*/ + Word16 *vad_flag_dtx, /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 *enerBuffer_fx_exp, /* o : energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* o : FFT buffer fft_buff_fx_q*/ + Word16 *fft_buff_fx_q, /* o : FFT buffer */ + const Word16 tdm_A_PCh_fx[M + 1], /* i : unq. LP coeff. of primary channel Q12*/ + const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15*/ + const Word32 currFlatness_fx, /* i : flatness parameter Q21*/ + const Word16 tdm_ratio_idx, /* i : Current Ratio_L index Q0*/ + Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands fr_bands_LR_fx_q*/ + Word16 fr_bands_LR_fx_q[CPE_CHANNELS], /* i : Q factors of energy in frequency bands */ + const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/ + Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels lf_E_LR_fx_q*/ + const Word16 lf_E_LR_fx_q, /* i : Q factor of per bin spectrum energy in lf, LR channels */ + const Word16 localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels Q0*/ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN band_energies_LR_fx_q*/ + const Word16 band_energies_LR_fx_q, /* o : Q factors of energy in critical bands without minimum noise floor */ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + const Word16 front_vad_flag, /* i : front-VAD flag to overwrite VAD decision Q0*/ + const Word16 force_front_vad, /* i : flag to force VAD decision Q0*/ + const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX Q0*/ + Word16 *Q_new /* i/o : Q factor of speech buffers */ ) { Encoder_State *st; - IF( hSCE != NULL ) - { - st = hSCE->hCoreCoder[n]; - } - ELSE - { - st = hCPE->hCoreCoder[n]; - } - Word16 q_tmpN_LR[CPE_CHANNELS]; Word16 q_tmpE_LR[CPE_CHANNELS]; Word16 q_tmpN; @@ -170,23 +157,18 @@ ivas_error pre_proc_front_ivas_fx( STEREO_CLASSIF_HANDLE hStereoClassif; Word16 old_pitch1; /* previous frame OL pitch[1] @12.8 kHz */ Word16 LR_localVAD; - ivas_error error; - - push_wmops( "pre_proc_front" ); - Word16 *signal_in_fx; Word32 *signal32_in_fx; Word16 *inp_12k8_fx, *new_inp_12k8_fx; /* pointers to current frame and new data */ CLDFB_SCALE_FACTOR cldfbScale; - Word16 *temp1F_icatdmResampBuf_fx; - Word16 *mem_decim_dummy_fx; /* dummy decimation filter memory */ + Word16 temp1F_icatdmResampBuf_fx[L_FILT_MAX]; /* temp buffers for ICA TDM resamplers */ + Word16 mem_decim_dummy_fx[2 * L_FILT_MAX]; /* dummy decimation filter memory */ Word32 tmpF_fx[STEREO_DFT_BAND_MAX]; Word32 *res_cod_SNR_M_fx; Word16 snr_sum_he_fx; /* HE SAD parameters */ Word16 new_inp_out_size; Word16 Q_new_inp; Word16 mem_decim_size; - Word16 dummy_fx; Word16 ncharX_fx; Word16 ncharX_LR_fx; /* noise character for sp/mus classifier */ @@ -220,77 +202,22 @@ ivas_error pre_proc_front_ivas_fx( Word16 Qfact_PS, q_lf_E_fx; Word16 enerBuffer_fx_exp_buf[CLDFB_NO_CHANNELS_MAX]; Word32 bckr_temp[NB_BANDS]; -#ifdef DEBUG_MODE_INFO - Word32 *in_buff_temp; - Word16 in_q_temp; -#endif - - mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) ); - temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) ); - set16_fx( fft_buff_fx, 0, 512 ); - - Word16 Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); - Word16 input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) - Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); - Q_min = s_max( -2, Q_min ); - Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min - st->q_inp = Q_min; - move16(); - st->q_old_inp = Q_min; - move16(); - -#ifdef DEBUG_MODE_INFO - IF( hSCE != NULL ) - { - in_buff_temp = hSCE->hCoreCoder[n]->input32_fx; - in_q_temp = hSCE->hCoreCoder[n]->q_inp32; - } - ELSE - { - in_buff_temp = hCPE->hCoreCoder[n]->input32_fx; - in_q_temp = hCPE->hCoreCoder[n]->q_inp32; - } -#endif - - -#ifdef DEBUG_MODE_INFO - if ( !( hCPE != NULL && hCPE->hStereoTD != NULL && ch_idx > 0 ) ) - { - /* for TD stereo only write out first channel. The existence of a second channel can vary, this is just easier to handle */ - int16_t tmpF[L_FRAME48k]; - for ( int16_t isample = 0; isample < input_frame; isample++ ) - { - tmpF[isample] = (int16_t) ( (float) in_buff_temp[isample - NS2SA( st->input_Fs, ACELP_LOOK_NS )] / ( (float) ( 1 << in_q_temp ) ) ); - } - dbgwrite( &tmpF, sizeof( int16_t ), input_frame, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, ch_idx + 1, ENC ), ".pcm" ) ); - } -#endif - - FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) - { - set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); - } + Word16 Q_min; + Word16 input_frame_full; Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; - Word16 Q_inp_const = -1; move16(); - Word16 headroom = 0, preemp_len = 0, inp_max = 0; - move16(); - move16(); - move16(); + Word16 headroom, preemp_len, inp_max; Word16 *preemp_start_idx = NULL; - Word32 sig_out[960], max_32; + Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k /* = max( L_FRAME16k + STEREO_DFT_OVL_16k, L_FRAME16k + L_FILT16k + lMemRecalc_16k ) */], max_32; + push_wmops( "pre_proc_front" ); /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ - error = IVAS_ERR_OK; - move32(); - - cldfbScale.lb_scale = 31; - cldfbScale.hb_scale = 31; + cldfbScale.lb_scale = Q31; + cldfbScale.hb_scale = Q31; move16(); move16(); @@ -303,12 +230,6 @@ ivas_error pre_proc_front_ivas_fx( LR_localVAD = 0; move16(); - IF( st->cldfbAnaEnc != NULL ) - { - scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); /* Q11 */ - st->cldfbAnaEnc->Q_cldfb_state = Q11; - move16(); - } IF( hSCE != NULL ) { @@ -419,6 +340,16 @@ ivas_error pre_proc_front_ivas_fx( move16(); } + Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); + input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) + Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); + Q_min = s_max( -2, Q_min ); + Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min + st->q_inp = Q_min; + move16(); + st->q_old_inp = Q_min; + move16(); + L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ move16(); @@ -454,6 +385,13 @@ ivas_error pre_proc_front_ivas_fx( last_core_orig = st->last_core; /* Q0 */ move16(); + IF( st->cldfbAnaEnc != NULL ) + { + scale_sig32( st->cldfbAnaEnc->cldfb_state_fx, sub( sub( st->cldfbAnaEnc->p_filter_length, st->cldfbAnaEnc->no_channels ), st->cldfbAnaEnc->zeros ), sub( Q11, st->cldfbAnaEnc->Q_cldfb_state ) ); /* Q11 */ + st->cldfbAnaEnc->Q_cldfb_state = Q11; + move16(); + } + /*--------------------------------------------------------------* * energy analysis *---------------------------------------------------------------*/ @@ -496,6 +434,7 @@ ivas_error pre_proc_front_ivas_fx( * Change the sampling frequency to 12.8 kHz * (if not available from downsampled DMX) *----------------------------------------------------------------*/ + Scale_sig( st->mem_decim_fx_q_inp, 2 * L_FILT_MAX, sub( st->q_inp, st->mem_q ) ); /* st->q_inp */ test(); @@ -507,8 +446,8 @@ ivas_error pre_proc_front_ivas_fx( move16(); Copy( st->mem_decim_fx_q_inp, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* Q(-1) */ set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); - new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ + new_inp_out_size = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_12k8_fx + L_FRAME, INT_FS_12k8, mem_decim_dummy_fx, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -581,17 +520,16 @@ ivas_error pre_proc_front_ivas_fx( * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ - *Q_new = 0; - move16(); - set32_fx( sig_out, 0, 960 ); - headroom = 2; move16(); + preemp_len = 0; + move16(); st->mem_preemph_fx_q_inp = shl_sat( st->mem_preemph_fx_q_inp, sub( st->q_inp, st->mem_preemph_q ) ); /*st->q_inp*/ move16(); st->mem_preemph_DFT_fx_q_inp = shl_sat( st->mem_preemph_DFT_fx_q_inp, sub( st->q_inp, st->mem_preemph_q ) ); /*st->q_inp*/ move16(); + test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { @@ -602,13 +540,11 @@ ivas_error pre_proc_front_ivas_fx( st->mem_preemph_DFT_fx_q_inp = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* st->q_inp */ move16(); - // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); + preemph_copy_32fx2( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); dummy_fx = st->mem_preemph_fx_q_inp; move16(); - // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); - PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); + preemph_copy_32fx2( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); preemp_start_idx = new_inp_12k8_fx - STEREO_DFT_OVL_12k8; move16(); preemp_len = STEREO_DFT_OVL_12k8 + L_FRAME; @@ -623,8 +559,7 @@ ivas_error pre_proc_front_ivas_fx( st->mem_preemph_fx_q_inp = st->mem_preemph_DFT_fx_q_inp; /* st->q_inp */ move16(); Copy_Scale_sig( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, sub( st->q_inp, Q_inp_const ) ); /* st->q_inp */ - // PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx_q_inp ); + preemph_copy_32fx2( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx_q_inp ); preemp_start_idx = new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); move16(); preemp_len = STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT; @@ -641,19 +576,16 @@ ivas_error pre_proc_front_ivas_fx( { Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); move16(); - // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, sig_out, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx_q_inp ); + preemph_copy_32fx2( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, sig_out, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx_q_inp ); preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8; preemp_len = length_12k8; move16(); } - // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8, sig_out + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); + preemph_copy_32fx2( new_inp_12k8_fx - lMemRecalc_12k8, sig_out + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); dummy_fx = st->mem_preemph_fx_q_inp; /* st->q_inp */ move16(); - // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); - PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, sig_out + preemp_len + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); + preemph_copy_32fx2( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, sig_out + preemp_len + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); test(); IF( preemp_start_idx && preemp_len ) @@ -670,16 +602,15 @@ ivas_error pre_proc_front_ivas_fx( } ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ { - // PREEMPH_FX( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); + preemph_copy_32fx2( new_inp_12k8_fx, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx_q_inp ); dummy_fx = st->mem_preemph_fx_q_inp; move16(); - // PREEMPH_FX( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); - PREEMPH_32FX( new_inp_12k8_fx + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); + preemph_copy_32fx2( new_inp_12k8_fx + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); preemp_start_idx = new_inp_12k8_fx; preemp_len = L_FRAME + L_FILT; move16(); } + st->mem_preemph_fx = shl_sat( st->mem_preemph_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1) saturation added as float value goes above 65536 for +10 dB test (ltv48_MC512.wav and ltv48_MC51.wav) */ move16(); st->mem_preemph_DFT_fx = shl_sat( st->mem_preemph_DFT_fx_q_inp, sub( -1, st->q_inp ) ); /*Q(-1)*/ @@ -779,16 +710,6 @@ ivas_error pre_proc_front_ivas_fx( st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, fr_bands_fx_q, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->vad_flag, sizeof( int16_t ), 1, fname( st->force_dir, "force_vad_flag.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, 1, "res/force_vad_flag.enf" ); - } -#endif test(); IF( EQ_16( force_front_vad, 1 ) || EQ_16( front_vad_flag, 1 ) ) @@ -804,7 +725,7 @@ ivas_error pre_proc_front_ivas_fx( test(); IF( ( hCPE != NULL && !( lr_vad_enabled && st->idchan == 0 ) ) || hSCE != NULL ) { - *vad_flag_dtx = ivas_dtx_hangover_addition_fx( st, st->vad_flag, extract_h( L_sub( st->lp_speech_32fx, st->lp_noise_32fx ) ), 0, vad_hover_flag, NULL, NULL, NULL ); /* Q0 */ + *vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, extract_h( L_sub( st->lp_speech_32fx, st->lp_noise_32fx ) ), 0, vad_hover_flag, NULL, NULL, NULL ); /* Q0 */ move16(); } ELSE @@ -815,7 +736,6 @@ ivas_error pre_proc_front_ivas_fx( *vad_flag_dtx = *vad_flag_dtx || st->vad_flag; /* Q0 */ move16(); - /* Determine hangover flag status based on LR localVAD and downmix localVAD */ test(); test(); @@ -872,7 +792,6 @@ ivas_error pre_proc_front_ivas_fx( set_bw_fx( element_mode, element_brate, st, MODE1 ); } - /* set the BW of the TD secondary channel in LRTD mode same as BW of the primary channel (only at higher bitrates) */ test(); test(); @@ -883,18 +802,6 @@ ivas_error pre_proc_front_ivas_fx( move16(); } -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->bwidth, sizeof( int16_t ), 1, fname( st->force_dir, "force_bwidth.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->bwidth, sizeof( int16_t ), 1, 1, "res/force_bwidth.enf" ); - } -#endif - - /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation * Long-term energies and relative frame energy updates @@ -921,6 +828,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * FD-CNG Noise Estimator *----------------------------------------------------------------*/ + IF( st->hFdCngEnc != NULL ) { resetFdCngEnc_fx( st ); @@ -972,6 +880,7 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ + test(); test(); if ( hCPE != NULL && NE_16( element_mode, IVAS_CPE_DFT ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) @@ -990,7 +899,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - dtx_ivas_fx( st, last_ivas_total_brate, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, *Q_new ); + dtx_fx( st, last_ivas_total_brate, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, *Q_new ); test(); test(); @@ -1004,6 +913,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ + test(); test(); test(); @@ -1020,7 +930,9 @@ ivas_error pre_proc_front_ivas_fx( { total_brate = imult3216( FRAMES_PER_SEC, st->bits_frame_nominal ); /* Q0 */ } + configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate ); + IF( hCPE != NULL ) { st->hFdCngEnc->hFdCngCom->CngBitrate = L_sub( hCPE->element_brate, 1 ); /* Q0 */ @@ -1077,6 +989,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * LP analysis *----------------------------------------------------------------*/ + Word16 stab_fac_fx; Word16 Q_r[2]; set16_fx( Q_r, 0, 2 ); @@ -1125,6 +1038,7 @@ ivas_error pre_proc_front_ivas_fx( * Comparison of the LP coefficents to determine if it is possible * to reuse the primary channel LP coefficients in the secondary channel *----------------------------------------------------------------*/ + Word32 speech_buff[L_FRAME + M]; Copy_Scale_sig_16_32_DEPREC( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 ); /* Q_new + 12 */ hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( *Q_new, 12 ) ); /* Q0 */ @@ -1143,7 +1057,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); - ivas_find_wsp_fx( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + find_wsp_fx( A_fx, inp_12k8_fx, wsp_fx, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw_fx, GAMMA1, NB_SUBFR ); Word16 Q_wsp = *Q_new; move16(); @@ -1177,6 +1091,7 @@ ivas_error pre_proc_front_ivas_fx( pitch_ol_ivas_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift_fx, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, *relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR, Q_wsp ); + /* Updates for adaptive lag window memory */ st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); @@ -1190,8 +1105,9 @@ ivas_error pre_proc_front_ivas_fx( move16(); Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) ); /* Q7 */ + /* Detection of very short stable pitch period */ - StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); + StableHighPitchDetect_fx( element_mode, &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *q_old_wsp, st->lgBin_E_fx ); /* 1/4 pitch precision improvement */ IF( LE_32( element_brate, IVAS_32k ) ) @@ -1226,6 +1142,7 @@ ivas_error pre_proc_front_ivas_fx( /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ + Word16 scale = s_min( Q31, add( st->hNoiseEst->ave_enr_q, s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) ) ) ); scale = s_min( scale, add( q_tmpE, L_norm_arr( tmpE_fx, NB_BANDS ) ) ); scale = sub( scale, 1 ); // guard bits @@ -1295,6 +1212,7 @@ ivas_error pre_proc_front_ivas_fx( /*------------------------------------------------------------------* * Update parameters used in the VAD and DTX *-----------------------------------------------------------------*/ + vad_param_updt_fx( st, old_pitch1, corr_shift_fx, corr_shift_fx, A_fx, NULL, 1 ); test(); @@ -1302,6 +1220,7 @@ ivas_error pre_proc_front_ivas_fx( { vad_param_updt_fx( st, old_pitch1, corr_shiftL_fx, corr_shiftR_fx, A_fx, &hCPE->hFrontVad[0], CPE_CHANNELS ); } + /*-----------------------------------------------------------------* * Find spectral tilt * UC and VC frame selection @@ -1316,23 +1235,10 @@ ivas_error pre_proc_front_ivas_fx( find_tilt_ivas_fx( fr_bands_fx, fr_bands_fx_q, bckr_temp, scale, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, q_lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, - &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, fr_bands_fx_q ); // Q0 - Copy_Scale_sig_16_32_no_sat( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); - -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &st->coder_type, sizeof( int16_t ), 1, fname( st->force_dir, "force_coder_type.enf", -1, -1, -1 ) ); - dbgread( &st->coder_type_raw, sizeof( int16_t ), 1, fname( st->force_dir, "force_coder_type_raw.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &st->coder_type, sizeof( int16_t ), 1, 1, "res/force_coder_type.enf" ); - dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, 1, "res/force_coder_type_raw.enf" ); - } -#endif + st->coder_type = find_uv_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, extract_h( Etot_fx ), hp_E_fx, + &flag_spitch, last_core_orig, hStereoClassif, *Q_new, 0, fr_bands_fx_q ); // Q0 + Copy_Scale_sig_16_32_no_sat( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); /*-----------------------------------------------------------------* * channel aware mode configuration * @@ -1348,7 +1254,11 @@ ivas_error pre_proc_front_ivas_fx( * TC frame selection *-----------------------------------------------------------------*/ +#ifndef FIX_2404_HARM_SIGNAL_CLAS st->clas = signal_clas_ivas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ +#else + st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ +#endif move16(); select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); @@ -1362,6 +1272,7 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Collect stereo classifier features *-----------------------------------------------------------------*/ + IF( hStereoClassif != NULL ) { Word16 max_e_Etot; @@ -1376,6 +1287,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); move16(); + stereo_classifier_features_ivas_fx( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new_fx, epsP_fx, st->pitch, st->voicing_fx, *cor_map_sum_fx, non_staX_fx, sp_div_fx, st->clas, sub( 31, *epsP_fx_q ), ( 31 - Q8 ) /* exp of cor_map_sum */, ( 31 - Q20 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); @@ -1385,23 +1297,11 @@ ivas_error pre_proc_front_ivas_fx( * 1st stage speech/music classification (GMM model) *----------------------------------------------------------------*/ - SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; shift = getScaleFactor32( PS_fx, 128 ); scale_sig32( PS_fx, 128, shift ); Qfact_PS = add( Qfact_PS, shift ); - smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, extract_h( Etot_fx ), lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, hSpMusClas->past_PS_Q ); /* Q0 */ - -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc1.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc1.enf" ); - } -#endif + smc_dec = ivas_smc_gmm_fx( st, hStereoClassif, localVAD_HE_SAD, extract_h( Etot_fx ), lsp_new_fx, *cor_map_sum_fx /*Q8*/, epsP_fx, PS_fx, non_staX_fx, *relE_fx, &high_lpn_flag, flag_spitch, Qfact_PS, *epsP_fx_q, st->hSpMusClas->past_PS_Q ); /* Q0 */ #ifdef DEBUGGING if ( st->idchan == 0 ) @@ -1450,6 +1350,7 @@ ivas_error pre_proc_front_ivas_fx( st->GSC_IVAS_mode = 0; move16(); + test(); IF( EQ_16( st->idchan, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { @@ -1506,6 +1407,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); st->hTcxEnc->spectrum_e[1] = 16; move16(); + IF( flag_16k_smc ) { Word16 Q_old_inp_16k = -1; @@ -1539,15 +1441,10 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_old_inp_12k8 = *Q_new; move16(); + /* Compute core-coder buffers at internal sampling rate */ - error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, - A_fx, Aw_fx, - epsP_fx, - lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); - IF( NE_32( error, IVAS_ERR_OK ) ) - { - return error; - } + ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); + *epsP_fx_q = add( Q_r[0], 1 ); move16(); @@ -1608,23 +1505,6 @@ ivas_error pre_proc_front_ivas_fx( ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, extract_h( Etot_fx ), attack_flag, inp_12k8_fx, *Q_new, S_map_fx, flag_spitch ); } -#ifdef DEBUG_FORCE_DIR - if ( st->force_dir[0] != '\0' ) - { - dbgread( &smc_dec, sizeof( int16_t ), 1, fname( st->force_dir, "force_smc_dec_loc2.enf", -1, -1, -1 ) ); - dbgread( &st->sp_aud_decision0, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision0.enf", -1, -1, -1 ) ); - dbgread( &st->sp_aud_decision1, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision1.enf", -1, -1, -1 ) ); - dbgread( &st->sp_aud_decision2, sizeof( int16_t ), 1, fname( st->force_dir, "force_sp_aud_decision2.enf", -1, -1, -1 ) ); - } - else - { - dbgwrite( &smc_dec, sizeof( int16_t ), 1, 1, "res/force_smc_dec_loc2.enf" ); - dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision0.enf" ); - dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision1.enf" ); - dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, 1, "res/force_sp_aud_decision2.enf" ); - } -#endif - /*----------------------------------------------------------------* * Final VAD correction (when HE-SAD is used instead of the normal VAD, * rewrite the VAD flag by VAD flag with DTX hangover for further processing) @@ -1640,26 +1520,26 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Update old input signal buffer *-----------------------------------------------------------------*/ + shift = getScaleFactor16( &old_inp_12k8_fx[L_FRAME], L_INP_MEM ); Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift ); /* Q_new + shift */ st->exp_old_inp_12k8 = sub( Q15, add( *Q_new, shift ) ); move16(); - *Q_new = sub( *Q_new, Q_inp_const ); // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - 1 move16(); - free( mem_decim_dummy_fx ); - free( temp1F_icatdmResampBuf_fx ); pop_wmops(); - return error; + return; } + /*-------------------------------------------------------------------* * calculate_energy_buffer() * * calculate DFT-based energies *--------------------------------------------------------------------*/ + static void calculate_energy_buffer_ivas_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ Word32 enerBuffer_dft_fx[], /* o : energy buffer() exp(enerBuffer_dft_e)*/ @@ -1729,5 +1609,6 @@ static void calculate_energy_buffer_ivas_fx( enerBuffer_dft_e[i] = 0; move16(); } + return; } diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index cb5c157152f8b385d2db17db4f8dd8966a9fb57f..25bd4393552ee68e60214ff120d73db6d546c4c7 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,10 +32,7 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -48,48 +45,46 @@ * Pre-processing (Selection of internal Fs, classification, SC VBR decision, * Decision matrix, Preprocessing at other Fs, core switching decision, ...) *--------------------------------------------------------------------*/ -ivas_error pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ - const Word32 last_element_brate, /* i : last element bitrate Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ - Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ - Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ - Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ - Word16 *epsP_fx_q, /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ - Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ - Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ - Word16 e_old_wsp, - const Word16 loc_harm, /* i : harmonicity flag Q0*/ - const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ - const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ - Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* e_enerBuffer */ - Word16 e_enerBuffer, - Word16 fft_buff_fx[2 * L_FFT], /* Qx */ - Word16 cor_map_sum_fx, /* Q8 */ - Word16 *Q_new ) + +void pre_proc_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 last_element_brate, /* i : last element bitrate Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ + Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame Q_new*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 *epsP_fx_q, /* i : LP prediction errors */ + Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ + Word16 *new_inp_resamp16k_fx, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_new-1*/ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC Q0*/ + Word16 old_wsp_fx[], /* i : weighted input signal buffer e_old_wsp*/ + const Word16 e_old_wsp, /* i : Q value of weighted input signal buffer */ + const Word16 loc_harm, /* i : harmonicity flag Q0*/ + const Word16 vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + const Word16 flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ + Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer e_enerBuffer */ + const Word16 e_enerBuffer, /* i : Q value of energy buffer */ + Word16 fft_buff_fx[2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 cor_map_sum_fx, /* i : speech/music clasif. parameter Q8*/ + Word16 *Q_new /* i/o: Q factor of speech buffers */ +) { Word16 L_look, element_mode, lMemRecalc_12k8; Word16 *inp_16k_fx, *new_inp_12k8_fx, *inp_12k8_fx; /* pointers to current frame and new data */ Word16 *wsp_fx; /* weighted input signal buffer */ Word32 sr_core_tmp, total_brate_tmp; - ivas_error error; push_wmops( "pre_proc" ); - error = IVAS_ERR_OK; - move32(); - /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ @@ -114,6 +109,7 @@ ivas_error pre_proc_ivas_fx( lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS ); move16(); } + /*----------------------------------------------------------------* * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) *----------------------------------------------------------------*/ @@ -166,24 +162,23 @@ ivas_error pre_proc_ivas_fx( move16(); } - test(); - test(); - test(); - Word16 flag_1 = 0; - move16(); IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - flag_1 = ACELP_16k40; + total_brate_tmp = ACELP_16k40; move16(); } ELSE { - flag_1 = ACELP_9k60; + total_brate_tmp = ACELP_9k60; move16(); } + + test(); + test(); + test(); IF( st->hFdCngEnc != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) && ( ( NE_16( st->hFdCngEnc->hFdCngCom->frameSize, st->L_frame ) ) || ( NE_16( st->hFdCngEnc->hFdCngCom->CngBandwidth, st->input_bwidth ) ) ) ) { - configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), flag_1 ); + configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate_tmp ); } if ( st->ini_frame == 0 ) @@ -227,6 +222,7 @@ ivas_error pre_proc_ivas_fx( * IC frames selection * enforce TC frames in case of switching *-----------------------------------------------------------------*/ + test(); test(); test(); @@ -287,7 +283,6 @@ ivas_error pre_proc_ivas_fx( move16(); } - /*---------------------------------------------------------------------* * Decision matrix (selection of technologies) *---------------------------------------------------------------------*/ @@ -308,6 +303,7 @@ ivas_error pre_proc_ivas_fx( /* core selection */ ivas_decision_matrix_enc_fx( st, element_brate, fft_buff_fx, enerBuffer_fx, e_enerBuffer, last_element_mode ); + test(); test(); if ( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */ @@ -399,14 +395,14 @@ ivas_error pre_proc_ivas_fx( } } - /*-----------------------------------------------------------------* * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) *-----------------------------------------------------------------*/ + test(); test(); test(); - IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << 8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) + IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << Q8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) ) { st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); /* Q0 */ move16(); @@ -474,15 +470,6 @@ ivas_error pre_proc_ivas_fx( } } - /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */ - test(); - test(); - if ( st->rf_mode && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) ) ) - { - st->sharpFlag = 1; - move16(); - } - /* TD stereo, secondary channel - due to lack of signaling bits, sharpFlag is always 1 */ test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) @@ -517,6 +504,7 @@ ivas_error pre_proc_ivas_fx( /*-----------------------------------------------------------------* * Compute core-coder buffers at internal sampling rate *-----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) { sr_core_tmp = INT_FS_16k; @@ -570,16 +558,15 @@ ivas_error pre_proc_ivas_fx( move16(); st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); move16(); - Word16 Q_inp_12k8 = *Q_new; - move16(); - Word16 Q_inp_16k = *Q_new; - move16(); + IF( !flag_16k_smc ) { - error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx, - A_fx, Aw_fx, - epsP_fx, - lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, &Q_inp_16k ); + Word16 Q_inp_12k8 = *Q_new; + move16(); + Word16 Q_inp_16k; + + ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, &Q_inp_16k ); + IF( GT_16( Q_inp_16k, Q_inp_12k8 ) ) { Scale_sig( old_inp_16k_fx, L_INP, sub( Q_inp_12k8, Q_inp_16k ) ); @@ -592,11 +579,6 @@ ivas_error pre_proc_ivas_fx( } move16(); - IF( error != IVAS_ERR_OK ) - { - return error; - } - test(); IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { @@ -604,6 +586,7 @@ ivas_error pre_proc_ivas_fx( move16(); } } + test(); IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) { @@ -681,15 +664,17 @@ ivas_error pre_proc_ivas_fx( } pop_wmops(); - return error; + return; } + /*-------------------------------------------------------------------* * ivas_compute_core_buffers() * * Compute core-coder buffers at internal sampling rate *--------------------------------------------------------------------*/ -ivas_error ivas_compute_core_buffers_fx( + +void ivas_compute_core_buffers_fx( Encoder_State *st, /* i/o: encoder state structure */ Word16 **inp16k_out_fx, /* o : ptr. to inp. signal in the current frame Q_new-1*/ Word16 *old_inp_16k_fx, /* i/o: buffer of old input signal @ 16kHz Q_new-1*/ @@ -703,7 +688,7 @@ ivas_error ivas_compute_core_buffers_fx( Word32 epsP_fx[M + 1], /* i/o: LP prediction errors Q_r*/ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame Q15*/ Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame Q15*/ - Word16 Q_old_inp_16k, + const Word16 Q_old_inp_16k, Word16 Q_r[2], Word16 *Q_new ) { @@ -719,18 +704,10 @@ ivas_error ivas_compute_core_buffers_fx( Word16 Q_tmp, mem_decim16k_size, size_modified; Word16 epsP_h[M + 1]; Word16 epsP_l[M + 1]; - - Word16 headroom = 1, preemp_len = 0, inp_max = 0; - move16(); - move16(); - move16(); + Word16 i, shift, Q_min; + Word16 preemp_len, inp_max; Word16 *preemp_start_idx = NULL; - Word32 sig_out[960], max_32; - /*Word16 Q_exp, Q_wsp_exp*/; - set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); - set16_fx( epsP_h, 0, M + 1 ); - set16_fx( epsP_l, 0, M + 1 ); - set16_fx( input_buf_fx, 0, L_FRAME48k * 2 ); + Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k + L_FILT16k], max_32; Copy_Scale_sig( st->input_fx - input_frame, input_buf_fx, input_frame, sub( -1, st->q_old_inp ) ); Copy_Scale_sig( st->input_fx, input_buf_fx + input_frame, input_frame, sub( -1, st->q_inp ) ); @@ -757,9 +734,9 @@ ivas_error ivas_compute_core_buffers_fx( /*---------------------------------------------------------------* * Preprocessing at other sampling frequency rate (16/25.6/32kHz) *----------------------------------------------------------------*/ + IF( st->tcxonly == 0 ) { - L_frame_tmp = L_FRAME16k; move16(); } @@ -848,14 +825,14 @@ ivas_error ivas_compute_core_buffers_fx( Scale_sig( new_inp_16k_fx - lMemRecalc_16k - length_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } - size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ - Scale_sig( new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - lMemRecalc_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx - lMemRecalc_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ Copy( st->mem_decim16k_fx, mem_decim16k_dummy_fx, 2 * L_FILT_MAX ); IF( lMemRecalc > 0 ) { - size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ - Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ + size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - lMemRecalc_16k, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ + Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - lMemRecalc_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); @@ -939,22 +916,15 @@ ivas_error ivas_compute_core_buffers_fx( move16(); } - test(); - test(); - *Q_new = 0; move16(); - set32_fx( sig_out, 0, 960 ); - test(); - test(); - if ( ( ( st->bwidth == NB ) || ( st->max_bwidth == NB ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) - { - headroom = add( headroom, 1 ); - } - test(); + test(); - IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { + preemp_len = 0; + move16(); + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching Q(-1) */ @@ -968,13 +938,11 @@ ivas_error ivas_compute_core_buffers_fx( { Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); /* Q(-1) */ } - // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx - STEREO_DFT_OVL_16k, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ tmp_fx = st->mem_preemph16k_fx; move16(); - // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx - STEREO_DFT_OVL_16k; move16(); preemp_len = STEREO_DFT_OVL_16k + L_FRAME16k; @@ -986,9 +954,8 @@ ivas_error ivas_compute_core_buffers_fx( { st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; move16(); - Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* Q(-1) */ - // PREEMPH_FX(new_inp_16k_fx - L_MEM_RECALC_16K - (STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx); - PREEMPH_32FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), sig_out, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); /* Q(-1) */ + Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), sig_out, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); move16(); preemp_len = STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k; @@ -1004,8 +971,7 @@ ivas_error ivas_compute_core_buffers_fx( Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); move16(); - // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, sig_out, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx - lMemRecalc_16k - length_16k, sig_out, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx - lMemRecalc_16k - length_16k; preemp_len = length_16k; move16(); @@ -1015,12 +981,10 @@ ivas_error ivas_compute_core_buffers_fx( { Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); /* Q_new - 1 */ } - // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k, sig_out + preemp_len, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx - lMemRecalc_16k, sig_out + preemp_len, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ tmp_fx = st->mem_preemph16k_fx; move16(); - // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, sig_out + preemp_len + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, sig_out + preemp_len + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); /* Q(-1) */ IF( preemp_start_idx && preemp_len ) { preemp_len = add( preemp_len, add( L_FRAME16k + L_FILT16k, lMemRecalc_16k ) ); @@ -1035,12 +999,10 @@ ivas_error ivas_compute_core_buffers_fx( } ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { - // PREEMPH_FX(new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); /* Q(-1) */ tmp_fx = st->mem_preemph16k_fx; move16(); - // PREEMPH_FX(new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); /* Q(-1) */ + preemph_copy_32fx2( new_inp_16k_fx + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); /* Q(-1) */ preemp_start_idx = new_inp_16k_fx; preemp_len = L_FRAME16k + L_FILT16k; move16(); @@ -1048,8 +1010,7 @@ ivas_error ivas_compute_core_buffers_fx( maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); inp_max = s_max( extract_h( max_32 ), 1 ); - Word16 shift = sub( norm_s( inp_max ), headroom ); - Word16 Q_min, i; + shift = sub( norm_s( inp_max ), 1 /* headroom */ ); shift = s_max( shift, 0 ); shift = s_min( shift, Q_MAX ); minimum_fx( st->Q_max_16k, L_Q_MEM, &Q_min ); @@ -1074,19 +1035,9 @@ ivas_error ivas_compute_core_buffers_fx( Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, add( *Q_new, 1 ) ); Scale_sig( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ), *Q_new ); } - ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */ + ELSE /* keep memory up-to-date in case of bitrate switching */ { - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) - { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; /* Q_new - 1 */ - move16(); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) - { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; /* Q_new - 1 */ - move16(); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { st->mem_preemph16k_fx = 0; move16(); @@ -1109,7 +1060,6 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { /* update signal buffers */ - Word16 shift; shift = negate( *Q_new ); move16(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) @@ -1145,11 +1095,17 @@ ivas_error ivas_compute_core_buffers_fx( analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r ); } + FOR( i = 0; i < M + 1; i++ ) + { + epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); + move32(); + } + /*--------------------------------------------------------------* * Compute Weighted Input *---------------------------------------------------------------*/ - ivas_find_wsp_fx( L_FRAME16k, L_SUBFR, NB_SUBFR16k, A_fx, Aw_fx, st->speech_enc_pe, PREEMPH_FAC_16k, st->wspeech_enc, &st->mem_wsp_enc, st->gamma, L_LOOK_16k ); + find_wsp_fx( A_fx, st->speech_enc_pe, st->wspeech_enc, &st->mem_wsp_enc, PREEMPH_FAC_16k, L_FRAME16k, L_LOOK_16k, L_SUBFR, Aw_fx, st->gamma, NB_SUBFR16k ); } /*-----------------------------------------------------------------* @@ -1159,20 +1115,19 @@ ivas_error ivas_compute_core_buffers_fx( /* update old input signal @16kHz buffer */ test(); test(); - test(); IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) { set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); st->exp_old_inp_16k = 0; move16(); } - ELSE IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) ) + ELSE IF( EQ_32( sr_core, INT_FS_16k ) ) { Copy( &old_inp_16k_fx[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); st->exp_old_inp_16k = sub( Q16, *Q_new ); //(*Q_new - 1) move16(); } - ELSE IF( GT_32( input_Fs, 8000 ) ) + ELSE { lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 ); Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) ); @@ -1189,15 +1144,6 @@ ivas_error ivas_compute_core_buffers_fx( { Copy( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k ); } - test(); - IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) - { - FOR( Word16 i = 0; i < M + 1; i++ ) - { - epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] ); - move32(); - } - } - return IVAS_ERR_OK; + return; } diff --git a/lib_enc/ivas_corecoder_enc_reconfig_fx.c b/lib_enc/ivas_corecoder_enc_reconfig_fx.c index a277c965bd63c9be6a5831cb589586b51c10fcc6..9c845eb400fa2b3c81e21df8ec80810198f2917a 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig_fx.c +++ b/lib_enc/ivas_corecoder_enc_reconfig_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,17 +37,18 @@ #include "prot_fx_enc.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "math.h" #include "wmc_auto.h" #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) #include #endif + + /*-------------------------------------------------------------------* * ivas_corecoder_enc_reconfig() * * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ -/* Some float operations are still pending */ + ivas_error ivas_corecoder_enc_reconfig_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 nSCE_old, /* i : number of SCEs in previous frame Q0*/ @@ -235,8 +236,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ); - shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); - scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ + shift = sub( getScaleFactor16( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame ), Q1 ); + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp, shift ); move16(); q_com_sce = s_min( q_com_sce, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ); @@ -246,8 +247,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32, shift ); move16(); q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 ); - shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); - scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ + shift = sub( getScaleFactor32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, input_frame ), Q1 ); + scale_sig32( st_ivas->hSCE[k]->hCoreCoder[0]->input32_fx, input_frame, shift ); /* st_ivas->hSCE[k]->hCoreCoder[0]->q_inp + shift */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, shift ); move16(); q_com_sce32 = s_min( q_com_sce32, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 ); @@ -266,8 +267,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ); - shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); - scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ + shift = sub( getScaleFactor16( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame ), Q1 ); + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp, shift ); move16(); q_com_cpe = s_min( q_com_cpe, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ); @@ -277,8 +278,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32, shift ); move16(); q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 ); - shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ) ), Q1 ); - scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ + shift = sub( getScaleFactor32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, input_frame ), Q1 ); + scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input32_fx, input_frame, shift ); /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp + shift */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, shift ); move16(); q_com_cpe32 = s_min( q_com_cpe32, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 ); @@ -293,10 +294,10 @@ ivas_error ivas_corecoder_enc_reconfig_fx( scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp ) ); /* q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp = q_com; move16(); - scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ + scale_sig( st_ivas->hSCE[k]->hCoreCoder[0]->input_fx, input_frame, sub( q_com, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp ) ); /* q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp = q_com; move16(); - Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ + Copy_Scale_sig_16_32_DEPREC( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff_fx, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, shl( input_frame, 1 ), Q6 ); /* Q6 + q_com */ st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = add( Q6, q_com ); st_ivas->hSCE[k]->hCoreCoder[0]->q_old_inp32 = add( Q6, q_com ); move16(); @@ -313,10 +314,10 @@ ivas_error ivas_corecoder_enc_reconfig_fx( scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp ) ); /* q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp = q_com; move16(); - scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, sub( L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_frame ), sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ + scale_sig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_fx, input_frame, sub( q_com, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp ) ); /* q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp = q_com; move16(); - Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) + L_FRAME48k, Q6 ); /* Q6 + q_com */ + Copy_Scale_sig_16_32_DEPREC( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, shl( input_frame, 1 ), Q6 ); /* Q6 + q_com */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = add( Q6, q_com ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_old_inp32 = add( Q6, q_com ); move16(); diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 033e13034c4c260f7bfc5fdec574d9a384a2bbb5..be1caae8320de6582080ec6b5cebfd1181d5ba63 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,18 +33,15 @@ #include #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" -#include "prot_fx_enc.h" #include "ivas_rom_com.h" +#include "rom_com.h" #ifdef DEBUGGING #include "debug.h" #endif #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "ivas_rom_enc.h" #include "prot_fx_enc.h" @@ -130,9 +127,11 @@ ivas_error ivas_cpe_enc_fx( Word16 old_wsp_fx[CPE_CHANNELS][L_WSP]; Word16 e_old_wsp[CPE_CHANNELS], q_old_wsp; Word16 Q_new[CPE_CHANNELS] = { 0 }; + Word16 NFFT_inner; move16(); move16(); - Word16 q_com, shift, q_min, gb; + Word16 input_frame_2; + Word16 i, j, q_com, shift, q_min, gb; error = IVAS_ERR_OK; move32(); @@ -158,6 +157,7 @@ ivas_error ivas_cpe_enc_fx( * Initialization - general *-----------------------------------------------------------------*/ + input_frame_2 = shl( input_frame, 1 ); set16_fx( q_re_im_buf, 0, CPE_CHANNELS ); tdm_SM_or_LRTD_Pri = 0; @@ -180,7 +180,7 @@ ivas_error ivas_cpe_enc_fx( set16_fx( voicing_fr_fx[0], 0, NB_SUBFR ); set16_fx( voicing_fr_fx[1], 0, NB_SUBFR ); - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { set16_zero_fx( fft_buff_fx[i], 2 * L_FFT ); set16_zero_fx( old_inp_16k_16fx[i], L_INP ); @@ -254,9 +254,9 @@ ivas_error ivas_cpe_enc_fx( move16(); } - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { - FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) { set_zero_fx( realBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); set_zero_fx( imagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX ); @@ -336,6 +336,12 @@ ivas_error ivas_cpe_enc_fx( Word16 q_band_energies_LR; Word16 q_fr_bands[2], q_lf_E[2]; + q_band_energies_LR = 0; + q_lf_E[0] = 0; + q_lf_E[1] = 0; + move16(); + move16(); + move16(); IF( NE_32( ( error = front_vad_fx( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR_fx, &q_band_energies_LR, NULL, NULL, NULL, Q_inp, Q_buffer, Q_add, &front_create_flag ) ), @@ -402,8 +408,8 @@ ivas_error ivas_cpe_enc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { gb = find_guarded_bits_fx( sts[0]->encoderLookahead_FB ); - shift = L_norm_arr( sts[1]->old_input_signal32_fx, shl( input_frame, 1 ) ); - shift = s_min( shift, L_norm_arr( sts[0]->old_input_signal32_fx, shl( input_frame, 1 ) ) ); + shift = L_norm_arr( sts[1]->old_input_signal32_fx, input_frame_2 ); + shift = s_min( shift, L_norm_arr( sts[0]->old_input_signal32_fx, input_frame_2 ) ); IF( LT_16( shift, gb ) ) { @@ -429,10 +435,10 @@ ivas_error ivas_cpe_enc_fx( * Temporal inter-channel alignment, stereo adjustment *----------------------------------------------------------------*/ - shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ); + shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, input_frame_2 ), L_norm_arr( sts[1]->input_buff32_fx, input_frame_2 ) ); q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) ); - scale_sig32( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ - scale_sig32( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[1]->input_buff32_fx, input_frame_2, sub( q_min, sts[1]->q_inp32 ) ); /* q_min */ + scale_sig32( sts[0]->input_buff32_fx, input_frame_2, sub( q_min, sts[0]->q_inp32 ) ); /* q_min */ sts[0]->q_inp32 = sts[1]->q_inp32 = sts[0]->q_old_inp32 = sts[1]->q_old_inp32 = q_min; move16(); move16(); @@ -441,11 +447,10 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); - shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ); - shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[1]->q_inp32 ), 16 ) ); - Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift - Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift - + shift = sub( add( L_norm_arr( sts[0]->input_buff32_fx, input_frame_2 ), sts[0]->q_inp32 ), 16 ); + shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, input_frame_2 ), sts[1]->q_inp32 ), 16 ) ); + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, input_frame_2, sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, input_frame_2, sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = shift; move16(); move16(); @@ -602,7 +607,13 @@ ivas_error ivas_cpe_enc_fx( { sts[n]->bits_frame_nominal = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ sts[n]->bits_frame_channel = idiv1616( extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), n_CoreChannels ); /* Q0 */ - sts[n]->total_brate = L_shl( div_l( hCPE->element_brate, n_CoreChannels ), 1 ); /* Q0 */ + /* sts[n]->total_brate = hCPE->element_brate / n_CoreChannels; */ + assert( n_CoreChannels == 1 || n_CoreChannels == 2 ); + sts[n]->total_brate = hCPE->element_brate; + if ( n_CoreChannels == 2 ) + { + sts[n]->total_brate = L_shr( hCPE->element_brate, 1 ); + } move32(); move16(); move16(); @@ -709,12 +720,9 @@ ivas_error ivas_cpe_enc_fx( move16(); /* Determine the energy ratio between the 2 channels */ - tdm_ratio_idx = stereo_tdm_ener_analysis_fx( - ivas_format, - hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */ + tdm_ratio_idx = stereo_tdm_ener_analysis_fx( ivas_format, hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Q0 */ /* Compute the downmix signal based on the ratio index */ - Word16 tdm_SM_flag; IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) { @@ -836,11 +844,11 @@ ivas_error ivas_cpe_enc_fx( // Normalise the input buffer from Q15 Word16 input_norm, q_inp; //, common_q, fir_delay_len; - input_norm = L_norm_arr( sts[0]->input32_fx - input_frame, shl( input_frame, 1 ) ); + input_norm = L_norm_arr( sts[0]->input32_fx - input_frame, input_frame_2 ); q_inp = sub( add( Q15, input_norm ), 16 ); // Rescale the old input, input and FIR delay section of input buffer - Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, shl( input_frame, 1 ), sub( add( Q16, q_inp ), Q15 ) ); // Q15 -> q_inp + Copy_Scale_sig32_16( sts[0]->input32_fx - input_frame, sts[0]->input_fx - input_frame, input_frame_2, sub( add( Q16, q_inp ), Q15 ) ); // Q15 -> q_inp // Update the Q-factors sts[0]->q_inp = q_inp; @@ -912,23 +920,16 @@ ivas_error ivas_cpe_enc_fx( { front_vad_flag = 0; } + move16(); + + pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n], + &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], + realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], + fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD, + band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate, &Q_new[n] ); - error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n], - &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], - realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], - fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD, - band_energies_LR_fx, q_band_energies_LR, 0, front_vad_flag, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate, &Q_new[n] -#ifdef DEBUG_MODE_INFO - , - ( st_ivas->nSCE + ( cpe_id * CPE_CHANNELS ) + n ) -#endif - ); e_old_wsp[n] = sub( Q15, q_old_wsp ); move16(); - IF( error != IVAS_ERR_OK ) - { - return error; - } } /*making Q common*/ @@ -1096,7 +1097,7 @@ ivas_error ivas_cpe_enc_fx( IF( ( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->element_mode, IVAS_CPE_TD ) ) || n == 0 ) /* modify coder_type of primary channel */ { /* limit coder_type depending on the bitrate */ - coder_type_modif_ivas_fx( sts[n], relE_fx[n] ); + coder_type_modif_fx( sts[n], relE_fx[n] ); } } @@ -1124,6 +1125,10 @@ ivas_error ivas_cpe_enc_fx( IF( EQ_32( sts[0]->core_brate, SID_2k40 ) || sts[0]->core_brate == FRAME_NO_DATA ) { /* Reconfigure DFT Stereo for inactive frames */ + /* -- nbands may need to be updated here in case the bandwidth was changed due to inactive frames */ + NFFT_inner = shl( inner_frame_tbl[sts[0]->bwidth], 1 ); + hCPE->hStereoDft->nbands = stereo_dft_band_config_fx( hCPE->hStereoDft->band_limits, hCPE->hStereoDft->hConfig->band_res, NFFT_inner, ENC ); + move16(); IF( EQ_32( sts[0]->core_brate, SID_2k40 ) ) { stereo_dft_config_fx( hConfigDft, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); @@ -1184,7 +1189,7 @@ ivas_error ivas_cpe_enc_fx( } } - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + FOR( i = 0; i < CPE_CHANNELS; i++ ) { Copy_Scale_sig_16_32_no_sat( old_inp_12k8_16fx[i], old_inp_12k8_fx[i], L_INP_12k8, Q16 ); // Q(-1) -> Q15 } diff --git a/lib_enc/ivas_decision_matrix_enc_fx.c b/lib_enc/ivas_decision_matrix_enc_fx.c index 42e2f446ef539a3105237d0597f67c086fd7cb42..79448bd19be0fd79461feb378067270014c7b822 100644 --- a/lib_enc/ivas_decision_matrix_enc_fx.c +++ b/lib_enc/ivas_decision_matrix_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,15 +32,11 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" -#include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" /* Function prototypes */ -#include "ivas_prot_fx.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ + /*-----------------------------------------------------------------* * ivas_decision_matrix_enc() diff --git a/lib_enc/ivas_dirac_enc_fx.c b/lib_enc/ivas_dirac_enc_fx.c index 0264a21994e7f06d2d79bece1d4c19210d8d1858..16934822576d785bb3402878939bafc2b3400403 100644 --- a/lib_enc/ivas_dirac_enc_fx.c +++ b/lib_enc/ivas_dirac_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" @@ -233,7 +231,7 @@ ivas_error ivas_dirac_enc_reconfigure( } ELSE { - MVR2R_WORD16( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); } return error; @@ -1576,9 +1574,9 @@ void computeDiffuseness_mdft_fx( set_zero_fx( intensity_slow, i_mult( DIRAC_NUM_DIMS, MASA_FREQUENCY_BANDS ) ); set16_fx( intensity_slow_e, 0, i_mult( DIRAC_NUM_DIMS, MASA_FREQUENCY_BANDS ) ); set_zero_fx( intensity_slow_abs, MASA_FREQUENCY_BANDS ); - set16_fx( intensity_slow_abs_e, 0, no_col_avg_diff ); + set16_fx( intensity_slow_abs_e, 0, MASA_FREQUENCY_BANDS ); set_zero_fx( energy_slow, MASA_FREQUENCY_BANDS ); - set16_fx( energy_slow_e, 0, no_col_avg_diff ); + set16_fx( energy_slow_e, 0, MASA_FREQUENCY_BANDS ); FOR( i = 0; i < no_col_avg_diff; ++i ) { diff --git a/lib_enc/ivas_enc_cov_handler_fx.c b/lib_enc/ivas_enc_cov_handler_fx.c index 32360fd41724fee407902034120f7dc671a4cab8..2d652a68329b8a1aee4036f44c05b92b2f8cee9b 100644 --- a/lib_enc/ivas_enc_cov_handler_fx.c +++ b/lib_enc/ivas_enc_cov_handler_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/ivas_enc_fx.c b/lib_enc/ivas_enc_fx.c index 34c6c320fcf380d3041a5c8344c9934a95a0e986..cde2237841f4cff1954f3cbf5a36ce257ca7af3c 100644 --- a/lib_enc/ivas_enc_fx.c +++ b/lib_enc/ivas_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,11 +31,8 @@ *******************************************************************************************************/ #include -#include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_rom_com.h" #ifdef DEBUGGING @@ -44,6 +41,7 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * ivas_enc() * @@ -139,7 +137,7 @@ ivas_error ivas_enc_fx( } ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - IF( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_osba_enc_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_entropy_coder_fx.c b/lib_enc/ivas_entropy_coder_fx.c index 3c8cf92e2f2ef39cf45042599aa58217fad99328..eb4b00cf8e52b405193c9ffed143d7efd1ec32d7 100644 --- a/lib_enc/ivas_entropy_coder_fx.c +++ b/lib_enc/ivas_entropy_coder_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,13 +36,13 @@ #include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_rom_com.h" -#include "math.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #ifdef DEBUGGING #include "debug.h" #endif + /*-----------------------------------------------------------------------------------------* * Function ivas_get_dyn_freq_model_fx() * diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index 35400f652ca47ba8e9f04a4e195a6af7edad38f1..e4cac36d27450af839f3a9752f238305199176dc 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,15 +32,10 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" -#include "prot_fx_enc.h" #include #include "wmc_auto.h" -#include #include "prot_fx_enc.h" #include "ivas_prot_fx.h" @@ -226,7 +221,7 @@ ivas_error front_vad_fx( /* Move previous frame 12k8 signal */ - MVR2R_WORD16( hFrontVad->buffer_12k8_fx + L_FFT, hFrontVad->buffer_12k8_fx, L_FFT / 2 ); + Copy( hFrontVad->buffer_12k8_fx + L_FFT, hFrontVad->buffer_12k8_fx, L_FFT / 2 ); /* Resample to 12k8 */ modify_Fs_ivas_fx( sts[n]->input_fx, input_frame, sts[0]->input_Fs, hFrontVad->buffer_12k8_fx + L_FFT / 2, INT_FS_12k8, hFrontVad->mem_decim_fx, ( sts[0]->max_bwidth == NB ), &Qband, &mem_decim_size ); @@ -237,7 +232,7 @@ ivas_error front_vad_fx( hFrontVad->q_mem_preemph_fx = add( Q_inp, Qband ); move16(); - PREEMPH_FX( hFrontVad->buffer_12k8_fx + L_FFT / 2, PREEMPH_FAC, L_FRAME, &hFrontVad->mem_preemph_fx ); + preemph_fx( hFrontVad->buffer_12k8_fx + L_FFT / 2, PREEMPH_FAC, L_FRAME, &hFrontVad->mem_preemph_fx ); Q_new = s_min( add( add( Q_inp, Qband ), Q_add ), Q_buffer[n] ); scale_sig( hFrontVad->buffer_12k8_fx, L_FFT / 2, sub( Q_new, Q_buffer[n] ) ); /* Q_new */ @@ -291,7 +286,8 @@ ivas_error front_vad_fx( sts[1]->last_coder_type = sts[0]->last_coder_type; /* Q0 */ move16(); } - vad_flag_dtx[n] = ivas_dtx_hangover_addition_fx( sts[n], hFrontVad->hVAD->vad_flag, sub( hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ), 0 /* <- no cldfb addition */, &vad_hover_flag[n], hFrontVad->hVAD, hFrontVad->hNoiseEst, &hFrontVads[n]->rem_dtx_ho ); /* Q0 */ + + vad_flag_dtx[n] = dtx_hangover_addition_fx( sts[n], hFrontVad->hVAD->vad_flag, sub( hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ), 0 /* <- no cldfb addition */, &vad_hover_flag[n], hFrontVad->hVAD, hFrontVad->hNoiseEst, &hFrontVads[n]->rem_dtx_ho ); /* Q0 */ move16(); if ( EQ_16( n_chan, 1 ) ) @@ -344,13 +340,12 @@ ivas_error front_vad_fx( IF( PS_out_fx != NULL ) { - MVR2R_WORD32( PS_fx, PS_out_fx, L_FRAME / 2 ); + Copy32( PS_fx, PS_out_fx, L_FRAME / 2 ); } IF( Bin_E_out_fx != NULL ) { - - MVR2R_WORD16( lgBin_E_fx, Bin_E_out_fx, L_FRAME / 2 ); + Copy( lgBin_E_fx, Bin_E_out_fx, L_FRAME / 2 ); } pop_wmops(); @@ -533,7 +528,7 @@ ivas_error front_vad_spar_fx( inp_12k8_fx = hFrontVad->buffer_12k8_fx; - MVR2R_WORD16( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); + Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; st->core_brate = -1; /* updated in dtx() */ @@ -605,7 +600,7 @@ ivas_error front_vad_spar_fx( corr_shift_fx = correlation_shift_fx( extract_h( hFrontVad->hNoiseEst->totalNoise_32fx ) ); /* Q15 */ - dtx_ivas_fx( st, hEncoderConfig->last_ivas_total_brate, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); + dtx_fx( st, hEncoderConfig->last_ivas_total_brate, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); /* linear prediction analysis */ alw_pitch_lag_12k8[0] = st->old_pitch_la; /* Q0 */ @@ -636,12 +631,11 @@ ivas_error front_vad_spar_fx( } relE_fx = sub( Etot_fx[0], extract_h( st->lp_speech_32fx ) ); - Scale_sig( A_fx, ( L_FRAME / L_SUBFR ) * ( M + 1 ), -2 ); // Q12 - st->mem_wsp_fx = (Word16) shl_sat( st->mem_wsp_fx, Q_inp_12k8 - st->mem_wsp_q ); /* Q_inp_12k8 */ st->mem_wsp_q = Q_inp_12k8; move16(); - ivas_find_wsp_fx( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); + + find_wsp_fx( A_fx, inp_12k8_fx, wsp_fx, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw_fx, GAMMA1, NB_SUBFR ); IF( st->vad_flag == 0 ) { @@ -689,7 +683,8 @@ ivas_error front_vad_spar_fx( st->old_pitch_la = st->pitch[2]; /* Q0 */ move16(); - StableHighPitchDetect_ivas_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q_wsp, st->lgBin_E_fx ); + StableHighPitchDetect_fx( IVAS_SCE /* needs to be other than EVS_MONO */, &flag_spitch, st->pitch, st->voicing_fx, wsp_fx, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, Q_wsp, st->lgBin_E_fx ); + IF( st->hSpMusClas != NULL ) { Word16 dummy_int; @@ -704,7 +699,7 @@ ivas_error front_vad_spar_fx( { cor_strong_limit = &dummy_int; } - loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */ + loc_harm = multi_harm_fx( EVS_MONO, st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */ } scale = getScaleFactor32( epsP_fx, M + 1 ); @@ -735,8 +730,9 @@ ivas_error front_vad_spar_fx( lf_E_fx[0], q_lf_E[0], &hFrontVad->hNoiseEst->harm_cor_cnt, extract_h( hFrontVad->hNoiseEst->Etot_l_lp_32fx ), hFrontVad->hNoiseEst->Etot_v_h2_32fx, &hFrontVad->hNoiseEst->bg_cnt, st->lgBin_E_fx, &sp_floor, S_map_fx, NULL, hFrontVad, hFrontVad->ini_frame ); - MVR2R_WORD16( st->pitch, st->pitch, 3 ); + Copy( st->pitch, st->pitch, 3 ); vad_param_updt_fx( st, st->pitch[1], corr_shift_fx, corr_shift_fx, A_fx, &hFrontVad, 1 ); + /* 1st stage speech/music classification (GMM model) */ /* run only to get 'high_lpn_flag' parameter */ SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index ce623be9c2a0c8fdb10304258f34001ae9fc22ff..06df36fe5b260a211c6ed3829042b8a9f7ad2669 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -39,7 +39,6 @@ #include "ivas_stat_enc.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" #include "prot_fx_enc.h" #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) #include diff --git a/lib_enc/ivas_ism_dtx_enc_fx.c b/lib_enc/ivas_ism_dtx_enc_fx.c index 3474b218bd411a2b07bd60a923f32d95a6260c5c..940cf63f8f09e228c326ea80eaa047578dc3596f 100644 --- a/lib_enc/ivas_ism_dtx_enc_fx.c +++ b/lib_enc/ivas_ism_dtx_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include #include "options.h" #include "ivas_cnst.h" #include "prot_fx.h" diff --git a/lib_enc/ivas_ism_enc_fx.c b/lib_enc/ivas_ism_enc_fx.c index ea509dd1020653f78a9ad5a0835f270b027a92fe..94548ad2f9bfa812196d7d9890ac0cd3febd0396 100644 --- a/lib_enc/ivas_ism_enc_fx.c +++ b/lib_enc/ivas_ism_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -238,31 +238,19 @@ ivas_error ivas_ism_enc_fx( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ - FOR( i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ ) - { - Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12 - } set16_fx( old_wsp_fx[sce_id][0], 0, L_WSP ); q_old_wsp = Q15; move16(); Word16 q_fr_bands[2]; - error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], - &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], - fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] -#ifdef DEBUG_MODE_INFO - , - st->id_element -#endif - ); + pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], + &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], + realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], + fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] ); + e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp ); move16(); - IF( error != IVAS_ERR_OK ) - { - return error; - } IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { @@ -450,8 +438,7 @@ ivas_error ivas_ism_enc_fx( } /* modify the coder_type depending on the total_brate per channel */ - coder_type_modif_ivas_fx( st, relE_fx[sce_id][0] ); - + coder_type_modif_fx( st, relE_fx[sce_id][0] ); /*----------------------------------------------------------------* * Encoder *----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_ism_metadata_enc_fx.c b/lib_enc/ivas_ism_metadata_enc_fx.c index e685566645353a7d5f81aa4b460be74ecaf11502..f4866c7f3646cc40a7038015354f92b41e4ec313 100644 --- a/lib_enc/ivas_ism_metadata_enc_fx.c +++ b/lib_enc/ivas_ism_metadata_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,9 +38,7 @@ #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "prot_fx.h" -#include #include "wmc_auto.h" -#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* @@ -1076,7 +1074,7 @@ static void encode_radius_fx( nbits_diff_radius = 1; move16(); } - ELSE IF( LE_16( ABSVAL( diff ), ISM_MAX_RADIUS_DIFF_IDX ) ) + ELSE IF( LE_16( abs_s( diff ), ISM_MAX_RADIUS_DIFF_IDX ) ) { idx_radius = 2; // shl( 1, 1 ); move16(); diff --git a/lib_enc/ivas_ism_param_enc_fx.c b/lib_enc/ivas_ism_param_enc_fx.c index 47da31a1ab0c03b5be9d96ed9d931e6e55ee11c1..2d149d030af4f91ae78853ccb0387c4ec7f327ee 100644 --- a/lib_enc/ivas_ism_param_enc_fx.c +++ b/lib_enc/ivas_ism_param_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,12 +31,10 @@ *******************************************************************************************************/ #include -#include #include #include "options.h" #include "ivas_prot_fx.h" #include "prot_fx.h" -#include "cnst.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -294,7 +292,7 @@ void ivas_param_ism_stereo_dmx_fx( { tmp = L_add( tmp, 2 * EVS_PI_FX ); } - cardioid_left[i] = add( shr( alpha, 1 ), mult( sub( ONE_IN_Q15 - 1, alpha ), getCosWord16( extract_l( tmp ) ) ) ); // Q14 + cardioid_left[i] = mac_r( L_mult( alpha, 16384 ), sub( ONE_IN_Q15 - 1, alpha ), getCosWord16( extract_l( tmp ) ) ); // Q14 move16(); IF( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 0 ) @@ -302,7 +300,7 @@ void ivas_param_ism_stereo_dmx_fx( Word16 last_cardioid_right; last_cardioid_right = sub( ONE_IN_Q14 /* 1.0f in Q14 */, last_cardioid_left ); /* Smoothing */ - cardioid_left[i] = add( mult( 24576 /* 0.75f in Q15 */, cardioid_left[i] ), mult( 8192 /* 0.25f in Q15 */, last_cardioid_left ) ); // Q14 + cardioid_left[i] = mac_r( L_mult( 24576 /* 0.75f in Q15 */, cardioid_left[i] ), 8192 /* 0.25f in Q15 */, last_cardioid_left ); // Q14 move16(); Word32 grad_32 = L_mult( sub( cardioid_left[i], last_cardioid_left ), shl( one_by_input_frame, 1 ) /* 2.0f / (float) input_frame*/ ); /* Q14+Q16 = Q30 */ /* for the right cardioid, multiply with -1 */ /* Cardioids sum up to 1 */ diff --git a/lib_enc/ivas_lfe_enc_fx.c b/lib_enc/ivas_lfe_enc_fx.c index 96959c9dd46fe0d60f391fcbb4c5da5f0e2d3f50..a76db70a1ce806bf03fb557648bc01d8470a9c86 100644 --- a/lib_enc/ivas_lfe_enc_fx.c +++ b/lib_enc/ivas_lfe_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include "math.h" #include "prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -45,6 +44,7 @@ * * LFE Arithmetic coding block. Writes encoded data to bitstream. *-----------------------------------------------------------------------------------------*/ + static void ivas_lfe_arith_coding_fx( LFE_ENC_HANDLE hLFE, BSTR_ENC_HANDLE hBstr, @@ -684,7 +684,7 @@ void ivas_lfe_lpf_enc_apply_fx( const Word16 input_frame /* i : input frame length per channel */ ) { - ivas_filter_process_fx( hLfeLpf, data_lfe_ch, input_frame, (Word16) Q11 ); + ivas_filter_process_fx32( hLfeLpf, data_lfe_ch, input_frame ); return; } diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 5613866ccc57e63116e7c224fcdfba71db62d480..6bfea1f19540db98ecc8ea5190a0d3f2ba23bd60 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include #include "options.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -1801,33 +1800,37 @@ void ivas_masa_combine_directions_fx( } } - /* Estimate the importance of having two directions instead of one */ - /* Reduced precision of importance_fx intentionally to Q13 to maintatin 0.0001f resolution */ - FOR( i = 0; i < numCodingBands; i++ ) + IF( GT_16( hMasa->config.numTwoDirBands, 0 ) ) { - importance_fx[i] = 0; - move32(); - FOR( j = 0; j < numSf; j++ ) + /* Estimate the importance of having two directions instead of one */ + /* Reduced precision of importance_fx intentionally to Q13 to maintatin 0.0001f resolution */ + FOR( i = 0; i < numCodingBands; i++ ) { - tempImportance_fx = L_shr( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), Q30 - Q13 ); // Q13 - tempImportance_fx = L_sub( tempImportance_fx, L_shr( sumVecLen_fx[j][i], sub( sub( Q31, exp_sumVecLen ), Q13 ) ) ); // Q13 - importance_fx[i] = L_add( importance_fx[i], tempImportance_fx ); // Q13 + importance_fx[i] = 0; move32(); - } + FOR( j = 0; j < numSf; j++ ) + { + tempImportance_fx = L_shr( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), Q30 - Q13 ); // Q13 + tempImportance_fx = L_sub( tempImportance_fx, L_shr( sumVecLen_fx[j][i], sub( sub( Q31, exp_sumVecLen ), Q13 ) ) ); // Q13 + importance_fx[i] = L_add( importance_fx[i], tempImportance_fx ); // Q13 + move32(); + } - IF( NE_16( numSf, 1 ) ) - { - importance_fx[i] = L_shr( importance_fx[i], 2 ); // Q13 + IF( NE_16( numSf, 1 ) ) + { + importance_fx[i] = L_shr( importance_fx[i], 2 ); // Q13 + move32(); + } + importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); //(Q13, Q30) -> Q12 move32(); } - importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); //(Q13, Q30) -> Q12 - move32(); + exp_importance = Q31 - Q12; + move16(); + + /* Determine bands where to use two directions */ + find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); } - exp_importance = Q31 - Q12; - move16(); - /* Determine bands where to use two directions */ - find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); FOR( i = 0; i < numCodingBands; i++ ) { diff --git a/lib_enc/ivas_mc_param_enc_fx.c b/lib_enc/ivas_mc_param_enc_fx.c index 67353a279874abd481163efd96eeaadc75d37759..f17bee69a9b53c0e65ed8094f6cd7a69de915a87 100644 --- a/lib_enc/ivas_mc_param_enc_fx.c +++ b/lib_enc/ivas_mc_param_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -45,19 +45,15 @@ y_fx = W_extract_h( W_shl( x_64, norm ) ); \ y_e = sub( sub35gb, norm ); \ } -#include + #include #include "options.h" -#include "cnst.h" -#include "rom_enc.h" #include "ivas_rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" - #include "prot_fx_enc.h" /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_mc_paramupmix_enc_fx.c b/lib_enc/ivas_mc_paramupmix_enc_fx.c index 0e8c845e145f04160a57bf7442cb56b6a4251643..2776799ed37158dfbc44c3ad607f1ef8b46d34a0 100644 --- a/lib_enc/ivas_mc_paramupmix_enc_fx.c +++ b/lib_enc/ivas_mc_paramupmix_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,12 +30,8 @@ *******************************************************************************************************/ -#include #include #include "options.h" -#include "cnst.h" -#include "rom_enc.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "basop_util.h" @@ -47,6 +43,7 @@ #include "debug.h" #endif + /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_mcmasa_enc_fx.c b/lib_enc/ivas_mcmasa_enc_fx.c index 280da94568e28c042476055c9fef075341e20982..2507d6a0dbd6e1502235a206b44e499180448a4f 100644 --- a/lib_enc/ivas_mcmasa_enc_fx.c +++ b/lib_enc/ivas_mcmasa_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include #include #include #include "ivas_cnst.h" @@ -41,8 +40,6 @@ #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" - /*------------------------------------------------------------------------- * Local constants @@ -72,14 +69,15 @@ static void ivas_mcmasa_dmx_fx( const Word16 nchan_transport, const Word16 nchan_inp ); +/* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */ static void compute_cov_mtx_fx( - Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] */ - Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] */ - const Word16 freq, /* i : Freq to process */ - const Word16 N, /* i : Number of channels */ - CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ - Word16 inp_exp /*Stores exponent for temp*/ -); + Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] (inp_exp) */ + Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] (inp_exp) */ + Word16 num_freq_bands, + const Word16 N, /* i : Number of channels */ + CovarianceMatrix pCOVls[MASA_FREQUENCY_BANDS], /* o : Output matrix, contains upper part of cov mtx */ + Word16 inp_exp, /*Stores exponent for temp*/ + Word16 *band_grouping ); static void computeIntensityVector_enc_fx( const Word16 *band_grouping, @@ -919,7 +917,7 @@ void ivas_mcmasa_param_est_enc_fx( Word32 renormalization_factor_diff_fx[MASA_FREQUENCY_BANDS]; // renormalization_factor_diff_e Word16 renormalization_factor_diff_e[MASA_FREQUENCY_BANDS]; Word32 norm_tmp_fx; - Word16 mrange[2], brange[2]; + Word16 mrange[2]; Word16 numSubFramesForRatio; CovarianceMatrix COVls[MASA_FREQUENCY_BANDS]; Word32 absCOVls_fx[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; @@ -1023,6 +1021,12 @@ void ivas_mcmasa_param_est_enc_fx( move32(); hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; move32(); + hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] = 0; + move16(); + hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] = 0; + move16(); + hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] = 0; + move16(); } /* Reset variable */ @@ -1065,17 +1069,19 @@ void ivas_mcmasa_param_est_enc_fx( inp_q = add( inp_q, sf ); /* Compute covariance matrix */ + + assert( mrange[1] - mrange[0] == 1 ); + /*if this ever comes up, + 1. backup COVls to COVls_old + 2. reinitialize COVls (setzero) + 3. call compute_cov_mtx_fx(..,COVls,...) + 4. Add COVls_old to COVls + */ + + compute_cov_mtx_fx( Chnl_RealBuffer_fx, Chnl_ImagBuffer_fx, num_freq_bands, numAnalysisChannels, COVls, sub( 31, inp_q ), hMcMasa->band_grouping ); + FOR( i = 0; i < num_freq_bands; i++ ) { - brange[0] = hMcMasa->band_grouping[i]; - move16(); - brange[1] = hMcMasa->band_grouping[i + 1]; - move16(); - FOR( j = brange[0]; j < brange[1]; j++ ) - { - compute_cov_mtx_fx( Chnl_RealBuffer_fx, Chnl_ImagBuffer_fx, j, numAnalysisChannels, &( COVls[i] ), sub( 31, inp_q ) ); - } - /* Store energies for guiding metadata encoding */ FOR( j = 0; j < numAnalysisChannels; j++ ) { @@ -2087,53 +2093,72 @@ static void ivas_mcmasa_dmx_fx( return; } + + /* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */ static void compute_cov_mtx_fx( Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] (inp_exp) */ Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] (inp_exp) */ - const Word16 freq, /* i : Freq to process */ - const Word16 N, /* i : Number of channels */ - CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ - Word16 inp_exp /*Stores exponent for temp*/ -) + Word16 num_freq_bands, + const Word16 N, /* i : Number of channels */ + CovarianceMatrix pCOVls[MASA_FREQUENCY_BANDS], /* o : Output matrix, contains upper part of cov mtx */ + Word16 inp_exp, /*Stores exponent for temp*/ + Word16 *band_grouping ) { - Word16 i, j; - Word64 temp64_1, temp64_2; - Word16 tmp_16, max_exp; - Word16 temp_exp = shl( inp_exp, 1 ); + Word16 brange[2]; + Word16 freq; + int k; + int i, j; + Word16 tmp_16; + Word16 temp_exp = add( 1, shl( inp_exp, 1 ) ); + Word64 temp64_1_r_acc, temp64_1_i_acc; + FOR( i = 0; i < N; i++ ) { FOR( j = i; j < N; j++ ) { - temp64_1 = W_mac_32_32( W_mult_32_32( sr[i][freq], sr[j][freq] ), si[i][freq], si[j][freq] ); // exp:2*inp_exp - temp64_2 = W_deposit32_h( COVls->xr_fx[i][j] ); // exp:COVls->xr_e[i][j] - max_exp = s_max( COVls->xr_e[i][j], temp_exp ); - temp64_2 = W_shl( temp64_2, sub( COVls->xr_e[i][j], max_exp ) ); // exp:max_exp - temp64_1 = W_shl( temp64_1, sub( temp_exp, max_exp ) ); // exp:max_exp - temp64_1 = W_add( temp64_1, temp64_2 ); // exp:max_exp - tmp_16 = W_norm( temp64_1 ); - - COVls->xr_fx[i][j] = W_extract_h( W_shl( temp64_1, tmp_16 ) ); // exp:max_exp-tmp_16 - COVls->xr_e[i][j] = sub( max_exp, tmp_16 ); - move32(); - move16(); + FOR( k = 0; k < num_freq_bands; k++ ) + { + brange[0] = band_grouping[k]; + move16(); + brange[1] = band_grouping[k + 1]; + move16(); + CovarianceMatrix *COVls = &( pCOVls[k] ); - temp64_1 = W_sub( W_mult_32_32( si[i][freq], sr[j][freq] ), W_mult_32_32( sr[i][freq], si[j][freq] ) ); // exp :2*inp_exp - temp64_2 = W_deposit32_h( COVls->xi_fx[i][j] ); // exp:COVls->xi_e[i][j] - max_exp = s_max( COVls->xi_e[i][j], temp_exp ); - temp64_2 = W_shl( temp64_2, sub( COVls->xi_e[i][j], max_exp ) ); // exp:max_exp - temp64_1 = W_shl( temp64_1, sub( temp_exp, max_exp ) ); // exp:max_exp - temp64_1 = W_add( temp64_1, temp64_2 ); // exp:max_exp - tmp_16 = W_norm( temp64_1 ); + move64(); + temp64_1_r_acc = 0; + move64(); + temp64_1_i_acc = 0; - COVls->xi_fx[i][j] = W_extract_h( W_shl( temp64_1, tmp_16 ) ); // exp:max_exp-tmp_16 - COVls->xi_e[i][j] = sub( max_exp, tmp_16 ); - move32(); + FOR( freq = brange[0]; freq < brange[1]; freq++ ) + { + temp64_1_r_acc = W_mac0_32_32( temp64_1_r_acc, si[i][freq], si[j][freq] ); // exp:2*inp_exp + temp64_1_r_acc = W_mac0_32_32( temp64_1_r_acc, sr[i][freq], sr[j][freq] ); // exp:2*inp_exp + + temp64_1_i_acc = W_mac0_32_32( temp64_1_i_acc, si[i][freq], sr[j][freq] ); + temp64_1_i_acc = W_msu0_32_32( temp64_1_i_acc, sr[i][freq], si[j][freq] ); + } + + tmp_16 = W_norm( temp64_1_r_acc ); + + COVls->xr_fx[i][j] = W_extract_h( W_shl( temp64_1_r_acc, tmp_16 ) ); // exp:max_exp-tmp_16 + COVls->xr_e[i][j] = sub( temp_exp, tmp_16 ); + move32(); + move16(); + + tmp_16 = W_norm( temp64_1_i_acc ); + + COVls->xi_fx[i][j] = W_extract_h( W_shl( temp64_1_i_acc, tmp_16 ) ); // exp:max_exp-tmp_16 + COVls->xi_e[i][j] = sub( temp_exp, tmp_16 ); + move32(); + move16(); + } } } return; } + static void computeIntensityVector_enc_fx( const Word16 *band_grouping, Word32 Cldfb_RealBuffer[FOA_CHANNELS][DIRAC_NO_FB_BANDS_MAX], /*inp_q*/ diff --git a/lib_enc/ivas_mct_core_enc_fx.c b/lib_enc/ivas_mct_core_enc_fx.c index 9bbf1260c8ed61e487b4b01a99eb6c38ebaea869..2ab37c67e9adc210497d3394028de3024905a5ce 100644 --- a/lib_enc/ivas_mct_core_enc_fx.c +++ b/lib_enc/ivas_mct_core_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,13 +33,11 @@ #include #include #include "options.h" -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" -#include "rom_com.h" #include "wmc_auto.h" #include "prot_fx_enc.h" #include "ivas_prot_fx.h" -#include /*----------------------------------------------------------* diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index 39735ad030624045c49913f5a43e4c28e5f070b0..091b8c6b28f56579288fe4690ed858b4702897f8 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,14 +33,11 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "prot_fx_enc.h" -#include "rom_com.h" /*-----------------------------------------------------------------------* @@ -485,9 +482,9 @@ ivas_error ivas_mct_enc_fx( Copy32( hCPE->hCoreCoder[n]->input32_fx, hCPE->hCoreCoder[n]->old_input_signal32_fx, input_frame ); hCPE->hCoreCoder[n]->q_old_inp32 = hCPE->hCoreCoder[n]->q_inp32; move16(); - /* common encoder updates */ - updt_enc_common_ivas_fx( hCPE->hCoreCoder[n], Q_new_out[cpe_id][n] ); + /* common encoder updates */ + updt_enc_common_fx( hCPE->hCoreCoder[n], Q_new_out[cpe_id][n] ); } } diff --git a/lib_enc/ivas_mct_enc_mct_fx.c b/lib_enc/ivas_mct_enc_mct_fx.c index d402d834f9fa1b5dcbd409f5902e09c25ee907da..c725950b164569cbdddd20e0153cb120f6d760d5 100644 --- a/lib_enc/ivas_mct_enc_mct_fx.c +++ b/lib_enc/ivas_mct_enc_mct_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "ivas_cnst.h" #include "ivas_prot_fx.h" #include "prot_fx.h" @@ -89,19 +88,20 @@ void getChannelEnergies_fx( gb = find_guarded_bits_fx( (Word32) L_subframe ); - sum2_e = st->hTcxEnc->spectrum_e[0]; - move16(); nrg[ch] = 0; move32(); + nrg_e[ch] = 0; /* if the mantissa is 0, the exponent gets set to sum2_e inside BASOP_Util_Add_Mant32Exp() */ + move16(); + FOR( n = 0; n < nSubframes; n++ ) { + sum2_e = st->hTcxEnc->spectrum_e[n]; + move16(); + sum2 = sum2_32_exp_fx( st->hTcxEnc->spectrum_fx[n], L_subframe, &sum2_e, gb ); // 31 - sum2_e nrg[ch] = BASOP_Util_Add_Mant32Exp( nrg[ch], nrg_e[ch], sum2, sum2_e, &nrg_e[ch] ); move32(); - - sum2_e = st->hTcxEnc->spectrum_e[0]; - move16(); } nrg[ch] = Sqrt32( nrg[ch], &nrg_e[ch] ); // nrg_e diff --git a/lib_enc/ivas_mdct_core_enc_fx.c b/lib_enc/ivas_mdct_core_enc_fx.c index b4eba62010700dd4e91a3944c7a4f0b6b936d6f9..560cd81bd4b542e53725da58e0a8d9c5ecb556d0 100644 --- a/lib_enc/ivas_mdct_core_enc_fx.c +++ b/lib_enc/ivas_mdct_core_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,14 +30,11 @@ *******************************************************************************************************/ -#include "ivas_cnst.h" #include #include #include "options.h" -#include -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #include "prot_fx_enc.h" @@ -2448,14 +2445,13 @@ void ivas_mdct_core_whitening_enc_fx( } } - encode_lpc_avq_ivas_fx( hBstr, num_sns, param_lpc[ch], st->core, st->element_mode ); + encode_lpc_avq_fx( hBstr, num_sns, param_lpc[ch], st->core, st->element_mode ); st->side_bits_frame_channel = add( st->side_bits_frame_channel, sub( hBstr->nb_bits_tot, nbits_start_sns ) ); move16(); } } - /*update pitch buffer*/ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -2477,6 +2473,8 @@ void ivas_mdct_core_whitening_enc_fx( pop_wmops(); return; } + + void ivas_mdct_quant_coder_fx( CPE_ENC_HANDLE hCPE, /* i/o: Encoder CPE handle */ Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : bits needed for TNS parameters */ diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index 1311181dd78594bc9cfdcd78ed66741994668fd5..f49e9ebbc984da60aeb5c08fd0ada843eac7b34a 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include "options.h" #include #include -#include #include "ivas_cnst.h" #include "ivas_prot_fx.h" #include "prot_fx.h" @@ -1542,8 +1541,8 @@ static void ivas_omasa_dmx_fx( { g1 = interpolator[k]; move16(); - g2 = sub( MAX_WORD16, g1 ); /*q15*/ - data_out[j][k] = L_add( data_out[j][k], Mpy_32_32( L_add( L_mult( g1, gains[j] ), L_mult( g2, prev_gains[i][j] ) ) /*q31*/, data_in[i][k] ) ); /*Qx*/ + g2 = sub( MAX_WORD16, g1 ); /*q15*/ + data_out[j][k] = L_add( data_out[j][k], Mpy_32_32( L_mac( L_mult( g1, gains[j] ), g2, prev_gains[i][j] ) /*q31*/, data_in[i][k] ) ); /*Qx*/ move32(); } } diff --git a/lib_enc/ivas_osba_enc_fx.c b/lib_enc/ivas_osba_enc_fx.c index 3629b856285ae840e4540f4f21685b290e1d624c..1f19fa21d47bec73cb81253e7eedbef5fc3a2dcc 100644 --- a/lib_enc/ivas_osba_enc_fx.c +++ b/lib_enc/ivas_osba_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include "options.h" #include #include -#include #include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_rom_com.h" @@ -45,6 +44,7 @@ /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ + static void ivas_osba_render_ism_to_sba_fx( Word32 *data_in_fx[], Word32 data_out_fx[][L_FRAME48k], @@ -55,11 +55,13 @@ static void ivas_osba_render_ism_to_sba_fx( Word32 prev_gains_fx[][MAX_INPUT_CHANNELS], const Word32 interpolator_fx[L_FRAME48k], Word16 *Q_data ); + /*-------------------------------------------------------------------* * ivas_merge_sba_transports() * * Merge SBA transport channels *-------------------------------------------------------------------*/ + static void ivas_merge_sba_transports_fx( Word32 data_in_f1[][L_FRAME48k], // Q_f1 Word32 *data_in_f2[], // Q_f2 @@ -82,13 +84,17 @@ static void ivas_merge_sba_transports_fx( } } *Q_out = sub( Q_f1, 1 ); + return; } + + /*--------------------------------------------------------------------------* * ivas_osba_enc_open() * * Allocate and initialize OMASA handle *--------------------------------------------------------------------------*/ + ivas_error ivas_osba_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -139,11 +145,13 @@ ivas_error ivas_osba_enc_open_fx( return error; } + /*--------------------------------------------------------------------------* * ivas_omasa_enc_close() * * Close OMASA handle *--------------------------------------------------------------------------*/ + void ivas_osba_enc_close_fx( OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ ) @@ -168,12 +176,14 @@ void ivas_osba_enc_close_fx( return; } + /*--------------------------------------------------------------------------* * ivas_osba_enc_reconfig() * * oSBA encoder reconfiguration *--------------------------------------------------------------------------*/ -ivas_error ivas_osba_enc_reconfig( + +ivas_error ivas_osba_enc_reconfig_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { @@ -387,6 +397,8 @@ ivas_error ivas_osba_enc_reconfig( return error; } + + /*--------------------------------------------------------------------------* * ivas_osba_enc() * @@ -396,7 +408,7 @@ ivas_error ivas_osba_enc_reconfig( void ivas_osba_enc_fx( OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - Word32 *data_in_fx[], /* i/o: Input / transport audio signals q_data*/ + Word32 *data_in_fx[], /* i/o: Input / transport audio signals q_data*/ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ const ISM_MODE ism_mode, /* i : ISM mode */ @@ -415,7 +427,7 @@ void ivas_osba_enc_fx( /*keep the delay buffer up to date*/ FOR( n = 0; n < nchan_ism; n++ ) { - MVR2R_WORD32( &data_in_fx[n][input_frame - delay_s], hOSba->input_data_mem_fx[n], delay_s ); // Q_data + Copy32( &data_in_fx[n][input_frame - delay_s], hOSba->input_data_mem_fx[n], delay_s ); // Q_data } /* Convert ISM to SBA */ diff --git a/lib_enc/ivas_pca_enc_fx.c b/lib_enc/ivas_pca_enc_fx.c index 7eb4f18e71e4fc428d47427a68b9349633fd6667..7228d134e5157f78944584fe048128d57b06f8dc 100644 --- a/lib_enc/ivas_pca_enc_fx.c +++ b/lib_enc/ivas_pca_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,10 +34,8 @@ #include "options.h" #include "prot_fx.h" #include "ivas_cnst.h" -#include #include #include "wmc_auto.h" - #include "ivas_prot_fx.h" diff --git a/lib_enc/ivas_qmetadata_enc_fx.c b/lib_enc/ivas_qmetadata_enc_fx.c index 3f18527746af83315451c5160e22d3e48c496f38..7bc4560cfe9bdd4a19f62435dd67921c9bd27a32 100644 --- a/lib_enc/ivas_qmetadata_enc_fx.c +++ b/lib_enc/ivas_qmetadata_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include #include "options.h" -#include #include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" diff --git a/lib_enc/ivas_qspherical_enc_fx.c b/lib_enc/ivas_qspherical_enc_fx.c index 3f17a423e7025e5e4e34de78a2d49c3f5305a7e1..5a9c3bb4f3ce83b3e7ff54f9709b812068ad853d 100644 --- a/lib_enc/ivas_qspherical_enc_fx.c +++ b/lib_enc/ivas_qspherical_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include #include "options.h" -#include #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_stat_enc.h" diff --git a/lib_enc/ivas_range_uni_enc_fx.c b/lib_enc/ivas_range_uni_enc_fx.c index 6c322a3d953bfa19abc3df4d0196203117d76867..2efcf8f23243746735aff4a98aa96c2f8c146cbc 100644 --- a/lib_enc/ivas_range_uni_enc_fx.c +++ b/lib_enc/ivas_range_uni_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,8 +34,6 @@ #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_stat_enc.h" -#include "cnst.h" -#include "rom_com.h" #include #include "options.h" #include "prot_fx.h" diff --git a/lib_enc/ivas_rom_enc.h b/lib_enc/ivas_rom_enc.h index d1e644a93e45e0ffb4ef355a64c6eb3308e3fc9c..cd296fa140467f90180a9b65c1ce700f5faa8e5c 100644 --- a/lib_enc/ivas_rom_enc.h +++ b/lib_enc/ivas_rom_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/ivas_rom_enc_fx.c b/lib_enc/ivas_rom_enc_fx.c index 1b7bed2106883a12aa346153477f04f065a94988..6829a16ce35006c46f3b578b8eab47c815d25f9f 100644 --- a/lib_enc/ivas_rom_enc_fx.c +++ b/lib_enc/ivas_rom_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include #include "wmc_auto.h" diff --git a/lib_enc/ivas_sba_enc_fx.c b/lib_enc/ivas_sba_enc_fx.c index e630a70d954f4e5764dba5b446df8b125884a346..c2a63a2e03e89315b6e9d3faa3287b5820b0fedf 100644 --- a/lib_enc/ivas_sba_enc_fx.c +++ b/lib_enc/ivas_sba_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,16 +32,12 @@ #include #include -#include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index fa58f267479a7a380618fd19f7063b0541fa3d30..17635449055476fe4d1f31472934d2561af8dc6f 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,9 +33,7 @@ #include #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "prot_fx_enc.h" #include "ivas_rom_com.h" @@ -44,7 +42,6 @@ #endif #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "prot_fx_enc.h" /*-------------------------------------------------------------------* @@ -248,27 +245,36 @@ ivas_error ivas_sce_enc_fx( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ + set16_fx( old_wsp_fx[0], 0, L_WSP ); q_old_wsp = Q15; move16(); Word16 q_fr_bands[2]; - error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0], - &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], - realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], - fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc, - st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0] -#ifdef DEBUG_MODE_INFO - , - st->id_element -#endif - ); - e_old_wsp[0] = sub( Q15, q_old_wsp ); - move16(); - IF( NE_32( error, IVAS_ERR_OK ) ) + Word16 front_vad_flag, force_front_vad, front_vad_dtx_flag; + IF( st_ivas->hSpar != NULL ) { - return error; + front_vad_flag = st_ivas->hSpar->front_vad_flag; + force_front_vad = st_ivas->hSpar->force_front_vad; + front_vad_dtx_flag = st_ivas->hSpar->front_vad_dtx_flag; + } + ELSE + { + front_vad_flag = 0; + force_front_vad = 0; + front_vad_dtx_flag = 0; } + move16(); + move16(); + move16(); + + pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0], + &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], + realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], + fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc, + front_vad_flag, force_front_vad, front_vad_dtx_flag, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0] ); + e_old_wsp[0] = sub( Q15, q_old_wsp ); + move16(); /* sanity check -> DTX not supported for more than one SCEs/CPEs */ IF( sub( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) > 0 ) @@ -346,8 +352,7 @@ ivas_error ivas_sce_enc_fx( move16(); /* modify the coder_type depending on the total_brate per channel */ - coder_type_modif_ivas_fx( st, relE_fx[0] ); - + coder_type_modif_fx( st, relE_fx[0] ); /*----------------------------------------------------------------* * Encoder *----------------------------------------------------------------*/ @@ -468,6 +473,8 @@ ivas_error create_sce_enc_fx( } st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st->element_brate = -1; + move32(); st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; move32(); move32(); diff --git a/lib_enc/ivas_sns_enc_fx.c b/lib_enc/ivas_sns_enc_fx.c index 0e3c0bd405c51fedc3cdc397b35271b23f445391..01ff6b24ee6e5e67ff3c5ac2c3668fbef659c9a8 100644 --- a/lib_enc/ivas_sns_enc_fx.c +++ b/lib_enc/ivas_sns_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,11 +33,8 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" #include "wmc_auto.h" diff --git a/lib_enc/ivas_spar_encoder_fx.c b/lib_enc/ivas_spar_encoder_fx.c index 9d5d48447ea698af47aef6754685c65616dac18c..3b65bc4389750420ec2a638fc222c3da263fcd24 100644 --- a/lib_enc/ivas_spar_encoder_fx.c +++ b/lib_enc/ivas_spar_encoder_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,7 +37,6 @@ #include "prot_fx.h" #include "ivas_rom_com.h" #include "ivas_stat_com.h" -#include "math.h" #include "wmc_auto.h" #include "prot_fx_enc.h" #ifdef DEBUGGING diff --git a/lib_enc/ivas_spar_md_enc_fx.c b/lib_enc/ivas_spar_md_enc_fx.c index be07b38cbc7a47018b4e88b3523129d0661bf154..2d68dc00b6cb70b2ade4e6498b9ece49c35041ee 100644 --- a/lib_enc/ivas_spar_md_enc_fx.c +++ b/lib_enc/ivas_spar_md_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,11 +35,11 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_fx.h" -#include "math.h" #include "ivas_rom_com.h" #include #include "wmc_auto.h" + /*------------------------------------------------------------------------------------------* * PreProcessor *------------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 7096198a92d2ebe676848e52bc9f52dd2de1e7e1..c984a5ea3e8cda6c2497881c073645de12cbf687 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/ivas_stereo_adapt_GR_enc_fx.c b/lib_enc/ivas_stereo_adapt_GR_enc_fx.c index 8e79b228875469ea0b56b50d505f7e59771346eb..bf54b690137c6f15191664fa0faca5e502bc125a 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc_fx.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,9 +32,8 @@ #include #include "options.h" -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" -#include "stat_enc.h" #include "wmc_auto.h" #include "ivas_rom_com.h" #include "ivas_prot_fx.h" diff --git a/lib_enc/ivas_stereo_classifier_fx.c b/lib_enc/ivas_stereo_classifier_fx.c index 2c1bc0317099125735d2d30683f03a2b4ff13592..9538302fab4ef171ab7b8c3aad90a2437f8a7733 100644 --- a/lib_enc/ivas_stereo_classifier_fx.c +++ b/lib_enc/ivas_stereo_classifier_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,13 +31,10 @@ *******************************************************************************************************/ #include -#include #include "options.h" #ifdef DEBUGGING #include "debug.h" #endif -#include "cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" @@ -45,33 +42,24 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define RC_FACT_UP 0.3f -#define RC_FACT_UP_Q31 644245094 -#define RC_FACT_DOWN 0.7f -#define RC_FACT_DOWN_Q31 1503238554 -#define UNCLR_SCORE_THR 4.0f -#define UNCLR_SCORE_THR_Q28 ( 1073741824 ) -#define XTALK_SCORE_THR_DFT 4.0f -#define XTALK_SCORE_THR_DFT_Q27 ( 1 << 29 ) -#define XTALK_SCORE_THR_TD_UP 3.0f -#define XTALK_SCORE_THR_TD_UP_Q28 ( 805306368 ) +#define RC_FACT_UP_Q31 644245094 /* 0.3f */ +#define RC_FACT_DOWN_Q31 1503238554 /* 0.7f */ +#define UNCLR_SCORE_THR_Q28 ( 1073741824 ) /* 4.0f */ +#define XTALK_SCORE_THR_DFT_Q27 ( 1 << 29 ) /* 4.0f */ +#define XTALK_SCORE_THR_TD_UP_Q28 ( 805306368 ) /* 3.0f */ #define ONE_BY_XTALK_SCORE_THR_TD_UP_Q31 ( 715827882 ) -#define XTALK_SCORE_THR_TD_DN 4.0f -#define XTALK_SCORE_THR_TD_DN_Q28 ( 1073741824 ) +#define XTALK_SCORE_THR_TD_DN_Q28 ( 1073741824 ) /* 4.0f */ #define ONE_BY_XTALK_SCORE_THR_TD_DN_Q31 ( 536870912 ) -#define UNCLR_INTERCEPT_TD 0.780313f -#define UNCLR_INTERCEPT_TD_Q28 ( 209463676 ) -#define UNCLR_INTERCEPT_DFT 1.226513f -#define UNCLR_INTERCEPT_DFT_Q30 1316958306 -#define XTALK_INTERCEPT_TD -1.770983f -#define XTALK_INTERCEPT_TD_Q28 ( -475394629 ) -#define XTALK_INTERCEPT_DFT -0.758556f -#define XTALK_INTERCEPT_DFT_Q31 -1628986606 +#define UNCLR_INTERCEPT_TD_Q28 ( 209463676 ) /* 0.780313f */ +#define UNCLR_INTERCEPT_DFT_Q30 1316958306 /* 1.226513f */ +#define XTALK_INTERCEPT_TD_Q28 ( -475394629 ) /* -1.770983f */ +#define XTALK_INTERCEPT_DFT_Q31 -1628986606 /*-0.758556f */ #define XTALK_INTERCEPT_DFT_Q27 -101811663 #define EDGE_MAX_LEN 30 /* maximum length of buffer for edge detection */ @@ -83,6 +71,7 @@ /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ + static void rc_filter_fx( const Word32 x, Word32 *y, const Word16 order, const Word32 tau ); static void edge_detect_fx( const Word32 *inp, const Word16 len, const Word32 inp_min, const Word32 inp_max, Word16 *edge_str, Word16 *edge_type ); diff --git a/lib_enc/ivas_stereo_cng_enc_fx.c b/lib_enc/ivas_stereo_cng_enc_fx.c index b73a57f4690c86d566eb94bd7dadab969789f193..c9f4fe9a1b5b06ff1510853bc0180f5a15c78699 100644 --- a/lib_enc/ivas_stereo_cng_enc_fx.c +++ b/lib_enc/ivas_stereo_cng_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,9 +32,6 @@ #include #include "options.h" -#include -#include "cnst.h" -#include "rom_enc.h" #include "rom_com.h" #include "prot_fx.h" #include "ivas_cnst.h" diff --git a/lib_enc/ivas_stereo_dft_enc_fx.c b/lib_enc/ivas_stereo_dft_enc_fx.c index e5522fb377bf0ab53db392a8fae7c58230c46efa..6aa9673f4ffa4be17f82d8a7855128a91d4806c4 100644 --- a/lib_enc/ivas_stereo_dft_enc_fx.c +++ b/lib_enc/ivas_stereo_dft_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,9 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" -#include "rom_enc.h" #include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" @@ -51,7 +48,7 @@ #define STEREO_DFT_NRG_PAST_MAX_BAND 9 #define STEREO_DFT_NRG_PAST_MAX_BAND_LB 4 -#define STEREO_DFT_DMX_CROSSOVER ( Word16 )( 132 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) + 0.5f ) /* crossover bin between binwise and bandwise DMX */ +#define STEREO_DFT_DMX_CROSSOVER 211 /* crossover bin between binwise and bandwise DMX, ( 132 * ( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) + 0.5f ) */ #define ITD_VAD_E_BAND_N_INIT 200000 #define ITD_SID_PREV_FRAMES 5 @@ -393,8 +390,7 @@ ivas_error stereo_dft_enc_create_fx( stereo_dft_enc_open_fx( hStereoDft_loc, input_Fs, max_bwidth ); - stereo_dft_hybrid_ITD_flag_fx( hStereoDft_loc->hConfig, input_Fs, - hStereoDft_loc->hItd->hybrid_itd_max ); + stereo_dft_hybrid_ITD_flag_fx( hStereoDft_loc->hConfig, input_Fs, hStereoDft_loc->hItd->hybrid_itd_max ); *hStereoDft = hStereoDft_loc; @@ -3853,6 +3849,15 @@ static void stereo_dft_enc_compute_prm_fx( hStereoDft->nrg_past_pos = ( pos + 1 ) % STEREO_DFT_NRG_PAST_LEN; move16(); + /* Replicate last band for remaining bands in case the bandwidth is higher after SID/NODATA is considered */ + FOR( i = hStereoDft->nbands; i < STEREO_DFT_BAND_MAX; i++ ) + { + pPredGain[i] = pPredGain[i - 1]; + move32(); + pSideGain[i] = pSideGain[i - 1]; + move32(); + } + /*------------------------------------------------------------------* * Compute IPDs @@ -3948,10 +3953,10 @@ static void stereo_dft_enc_compute_prm_fx( * Compute Side gains *-----------------------------------------------------------------*/ + Copy32( pSideGain, hStereoDft->sidSideGain_fx, STEREO_DFT_BAND_MAX ); /* Copy all sideGain values since BW change may be reverted during CNG */ + FOR( b = 0; b < hStereoDft->nbands; b++ ) { - hStereoDft->sidSideGain_fx[b] = *( pSideGain + b ); - move32(); /* Quantization */ IF( flag_quant ) diff --git a/lib_enc/ivas_stereo_dft_enc_itd_fx.c b/lib_enc/ivas_stereo_dft_enc_itd_fx.c index eb23e9d01862638d7789f34c293a2818b55ecdb9..b1f709bd9024c9d8b3a4f677b0bd8de5b8891c22 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd_fx.c +++ b/lib_enc/ivas_stereo_dft_enc_itd_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,9 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" -#include "rom_enc.h" #include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" @@ -49,10 +46,8 @@ * Local constants *------------------------------------------------------------------------*/ -#define LP_GCC_PHAT_UP 0.9f /* LP filter coefficient, going up */ -#define LP_GCC_PHAT_UP_Q31 1932735283 /* LP filter coefficient, going up */ -#define LP_GCC_PHAT_DOWN 0.1f /* LP filter coefficient, going down */ -#define LP_GCC_PHAT_DOWN_Q31 214748365 /* LP filter coefficient, going down */ +#define LP_GCC_PHAT_UP_Q31 1932735283 /* LP filter coefficient, going up, 0.9f */ +#define LP_GCC_PHAT_DOWN_Q31 214748365 /* LP filter coefficient, going down, 0.1f */ #define ITD_CNT_MAX 2 /* Minimum number of consecutive ITD estimates for ITD hangover */ #define ITD_HO_GCC_PHAT_MAX 0.6f /* LP GCC PHAT value which gives zero hangover */ #define ITD_HO_GCC_PHAT_MIN 0.3f /* LP GCC PHAT value which gives ITD_HO_MAX ITD hangover frames */ @@ -61,26 +56,20 @@ #define ITD_HO_GCC_PHAT_INCL_Q26 -1118481021 #define ITD_HO_GCC_PHAT_OFFS ( -ITD_HO_GCC_PHAT_INCL * ITD_HO_GCC_PHAT_MAX + 1 ) #define ITD_HO_GCC_PHAT_OFFS_Q26 738197504 -#define SFM_PROD_GRP 4 /*maximum grouping of products for calculating SFM in ITD estimation*/ -#define B_DENOM 0.083333333333333f -#define B_DENOM_Q31 178956971 +#define SFM_PROD_GRP 4 /*maximum grouping of products for calculating SFM in ITD estimation*/ +#define B_DENOM_Q31 178956971 /* 0.083333333333333f */ #define L_SAMPLES 20 #define SUBDIV ( 2 * STEREO_DFT_ITD_MAX_ANA / L_SAMPLES ) #define DENOM 0.05f #define DENOM_Q31 107374182 -#define XSPEC_ALPHA ( 1.f / 32 ) #define XSPEC_ALPHA_Q31 ONE_IN_Q26 -#define CORR_FILT 0.8f -#define CORR_FILT_Q31 1717986918 +#define CORR_FILT_Q31 1717986918 /* 0.8f */ #define CORR_RESET_FRAMES_MAX 20 #define ITD_VAD_NOISE_INIT_FRAMES 30 -#define ITD_VAD_THRSHOLD 0.001f #define ITD_VAD_THRSHOLD_Q31 INV_1000_Q31 -#define ITD_VAD_MS_SNR_UPDATE_THRESH 15.0f #define ITD_VAD_MS_SNR_UPDATE_THRESH_FX 15 -#define HIGHT_SNR_VOICE_TH 10000.0f #define HIGHT_SNR_VOICE_TH_FX 10000 #define MAX_ITD_VAD_HANGOVER 10 diff --git a/lib_enc/ivas_stereo_dft_td_itd_fx.c b/lib_enc/ivas_stereo_dft_td_itd_fx.c index 2c044625c9afe432e74c86ab81a9ddde7ce46d14..ac42b9679ffcd3cd12e216ddaa8561ae13b85b51 100644 --- a/lib_enc/ivas_stereo_dft_td_itd_fx.c +++ b/lib_enc/ivas_stereo_dft_td_itd_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,10 +33,7 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_stat_enc.h" #include "ivas_cnst.h" diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index 5df59343f8625610d636b551534d775d35dfcd9e..e7d359059daf2528a54fc74ca2c0e459458795e6 100644 --- a/lib_enc/ivas_stereo_dmx_evs_fx.c +++ b/lib_enc/ivas_stereo_dmx_evs_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,17 +31,13 @@ *******************************************************************************************************/ #include -#include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" -#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_eclvq_enc_fx.c b/lib_enc/ivas_stereo_eclvq_enc_fx.c index a09daffe033c27d824800c93d8e8855231389091..bdc9be253eec64a11e70e9f1a0df508d66af46e9 100644 --- a/lib_enc/ivas_stereo_eclvq_enc_fx.c +++ b/lib_enc/ivas_stereo_eclvq_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" diff --git a/lib_enc/ivas_stereo_ica_enc_fx.c b/lib_enc/ivas_stereo_ica_enc_fx.c index 924de4d6595451430d5ab5a91f8c5a96fbd444fa..c50ea4c0c8c457f8d6d660994b03571ac2e46da2 100644 --- a/lib_enc/ivas_stereo_ica_enc_fx.c +++ b/lib_enc/ivas_stereo_ica_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,12 +33,9 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" -#include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_prot_fx.h" diff --git a/lib_enc/ivas_stereo_icbwe_enc_fx.c b/lib_enc/ivas_stereo_icbwe_enc_fx.c index f6bf1a0999fecbf98301544fcca9ad8bb4e2f04d..1fbbd777ae53990ae7894a2a1b8d857e0ef8f4ec 100644 --- a/lib_enc/ivas_stereo_icbwe_enc_fx.c +++ b/lib_enc/ivas_stereo_icbwe_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,8 +32,6 @@ #include #include "options.h" -#include -#include "cnst.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" @@ -41,6 +39,7 @@ #include "ivas_rom_com.h" #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * ic_bwe_enc_reset() * @@ -92,21 +91,24 @@ static void ic_bwe_enc_reset_fx( return; } + /*--------------------------------------------------------------------------* * ic_bwe_specMapping() * * Encode and apply the spectral shape mapping of ref to the non-ref channel *---------------------------------------------------------------------------*/ -static Word16 ic_bwe_enc_specMapping_ivas_fx( - const Word32 *shb_frame_target_fx, /* i : target shb Q31-shb_frame_target_e*/ - Word16 shb_frame_target_e, - Word32 *shb_synth_nonref_fx, /* o : non-ref shb synth Q31-shb_synth_nonref_e*/ - Word16 *shb_synth_nonref_e, - Word32 *specMapping_fx, /* i/o: current frame's mapping Qx*/ - Word32 *memShbSpecMapping_fx, /* i/o: current frame's mapping Q31-memShbSpecMapping_e*/ - Word16 *memShbSpecMapping_e, - Word32 *memShbSpecXcorr_fx, /* i/o: ic bwe spec mapping scorr memory Q31-memShbSpecXcorr_e*/ - Word16 *memShbSpecXcorr_e ) + +static Word16 ic_bwe_enc_specMapping_fx( + const Word32 *shb_frame_target_fx, /* i : target shb Q31-shb_frame_target_e*/ + const Word16 shb_frame_target_e, /* i : Q value shb_frame_target_fx */ + Word32 *shb_synth_nonref_fx, /* o : non-ref shb synth Q31-shb_synth_nonref_e*/ + Word16 *shb_synth_nonref_e, /* i/o: Q value shb_synth_nonref_fx */ + Word32 *specMapping_fx, /* i/o: current frame's mapping Qx*/ + Word32 *memShbSpecMapping_fx, /* i/o: current frame's mapping Q31-memShbSpecMapping_e*/ + Word16 *memShbSpecMapping_e, /* i/o: Q value memShbSpecMapping_fx */ + Word32 *memShbSpecXcorr_fx, /* i/o: ic bwe spec mapping scorr memory Q31-memShbSpecXcorr_e*/ + Word16 *memShbSpecXcorr_e /* i/o: Q value memShbSpecMapping_fx */ +) { Word16 idx; Word16 max_exp; @@ -131,7 +133,6 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( move16(); /* Calculate rxx(1)/rxx(0) of the non ref target */ - temp00_fx = dotp_fx_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx, shb_frame_target_e, L_FRAME16k - 1, &temp00_exp ); /* Q31-temp0_exp */ temp11_fx = dotp_fx_ivas_fx( shb_frame_target_fx, shb_frame_target_e, shb_frame_target_fx + 1, shb_frame_target_e, L_FRAME16k - 1, &temp11_exp ); /* Q31-temp1_exp */ @@ -151,7 +152,6 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( temp3_fx = L_shr( temp3_fx, sub( exp, temp3_exp ) ); /* Smoothing */ - FOR( Word16 i = 0; i < 6; i++ ) { memShbSpecXcorr_fx[i] = L_shl( memShbSpecXcorr_fx[i], sub( *memShbSpecXcorr_e, exp ) ); @@ -177,7 +177,6 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( T_nonref_target_fx = BASOP_Util_Divide3232_Scale( temp11_fx, temp00_fx, &T_nonref_target_e ); } - memShbSpecXcorr_fx[0] = temp00_fx; move32(); memShbSpecXcorr_fx[1] = temp11_fx; @@ -191,7 +190,6 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( memShbSpecXcorr_fx[5] = temp3_fx; /* Q31-exp */ move32(); - IF( temp0_fx != 0 ) { Txx1_fx = BASOP_Util_Divide3232_Scale( temp1_fx, temp0_fx, &Txx1_e ); /* Q31-Txx1_e */ @@ -217,9 +215,7 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( u_fx = extract_l( *specMapping_fx ); - /* while performing (-32768)*(-32768), overflow occurs because the result comes out as 32768 after mult. This is the only case for mult where overflow happens. In order to avoid this scenario mult_sat is used */ - tmp = mult_sat( b_fx, b_fx ); // b_e + b_e; tmp1 = mult_sat( a_fx, c_fx ); // a_e + c_e + 2 @@ -316,14 +312,7 @@ static Word16 ic_bwe_enc_specMapping_ivas_fx( *-----------------------------------------------------------------------*/ /*! r: return quant. index value */ -/*----------------------------------------------------------------------* - * ic_bwe_gsMapping() - * - * Encode and apply the gain shape mapping of ref to the non-ref channel - *-----------------------------------------------------------------------*/ - -/*! r: return quant. index value */ -static Word16 ic_bwe_enc_gsMapping_ivas_fx( +static Word16 ic_bwe_enc_gsMapping_fx( const Word32 relG_targ_fx, /* i : gDes, rel gain target Q31-relG_targ_e*/ Word16 relG_targ_e, const Word16 *shbSynth_fx, /* i : ref synth signal Q15-shbSynth_e*/ @@ -418,8 +407,10 @@ static Word16 ic_bwe_enc_gsMapping_ivas_fx( move16(); idx = squant_fx( temp2_fx, &gsMapping_fx16, icbwe_gsMappingDFT_tbl_fx, ( 1 << STEREO_ICBWE_GSBITS_DFT ) ); // Q12 } + *gsMapping_fx = L_deposit_h( gsMapping_fx16 ); // Q28 move32(); + Word16 e; L_mult = Mult_32_16( *gsMapping_fx, 27213 /*=log2(10)*2^13*/ ); // Q28 + Q13 - Q15 -> Q26 *gsMapping_fx = BASOP_util_Pow2( L_mult, 5, &e ); /* Q31-e */ @@ -427,15 +418,18 @@ static Word16 ic_bwe_enc_gsMapping_ivas_fx( *gsMapping_e = e; // Q31 move16(); + return idx; } + /*----------------------------------------------------------------------* * icbwe_dft_stereo_param() * * Estimate ICBWE parameters in DFT stereo *-----------------------------------------------------------------------*/ -static void icbwe_dft_stereo_param_ivas_fx( + +static void icbwe_dft_stereo_param_fx( STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: */ STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i : */ Encoder_State *st, /* i/o: */ @@ -488,7 +482,6 @@ static void icbwe_dft_stereo_param_ivas_fx( move16(); /* refChanIndex_bwe refinement */ - test(); test(); test(); @@ -565,7 +558,6 @@ static void icbwe_dft_stereo_param_ivas_fx( } /* gsMapping estimate */ - Word16 exp; IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { @@ -594,7 +586,7 @@ static void icbwe_dft_stereo_param_ivas_fx( move32(); move16(); - gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); /* Q0 */ + gsIndx = ic_bwe_enc_gsMapping_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); /* Q0 */ hStereoICBWE->gDes_pastFrame_fx = L_deposit_h( gDes_fx ); /* Q31-exp */ hStereoICBWE->gDes_pastFrame_e = exp; @@ -613,13 +605,18 @@ static void icbwe_dft_stereo_param_ivas_fx( return; } -void stereo_icBWE_enc_ivas_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 shb_speech_ref_fx[], /* i : SHB speech ref channel Q31-shb_speech_ref_e*/ - const Word16 shb_speech_ref_e, /* i : SHB speech ref channel */ - Word32 shb_speech_nonref_fx[], /* i/o: SHB speech non-ref channel Q31-shb_speech_nonref_e*/ - Word16 shb_speech_nonref_e, /* i/o: SHB speech non-ref channel */ - const Word32 *voice_factors_fx /* i : voicing factors Q31 */ +/*-------------------------------------------------------------------* + * stereo_icBWE_enc() + * + * Encode the spatial mapping of reference to the non-reference channels in HB + *-------------------------------------------------------------------*/ + +void stereo_icBWE_enc_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word16 shb_speech_ref_fx16[], /* i : SHB speech ref channel Q0*/ + Word16 shb_speech_nonref_fx_16[], /* i/o: SHB speech non-ref channel shb_speech_nonref_e*/ + Word16 shb_speech_nonref_e, /* i/o: SHB speech non-ref channel */ + const Word16 *voice_factors_fx16 /* i : voicing factors Q15 */ ) { Word16 i, j, k, nbSubFr; @@ -643,6 +640,18 @@ void stereo_icBWE_enc_ivas_fx( Word32 temp1_fx, temp2_fx; Word16 temp1_e, temp2_e, shb_frame_ref_e, shb_frame_nonref_e, gDes_e, tmp, exp; + Word32 shb_speech_ref_fx[L_FRAME16k]; + Word16 shb_speech_ref_e; + Word32 shb_speech_nonref_fx[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word32 voice_factors_fx[NB_SUBFR16k]; + + shb_speech_ref_e = add( getScaleFactor16( shb_speech_ref_fx16, L_FRAME16k ), Q16 ); + Copy_Scale_sig_16_32_no_sat( shb_speech_ref_fx16, shb_speech_ref_fx, L_FRAME16k, shb_speech_ref_e ); + shb_speech_ref_e = Q31 - shb_speech_ref_e; + + shb_speech_nonref_e = Q15 - shb_speech_nonref_e; + Copy_Scale_sig_16_32_no_sat( shb_speech_nonref_fx_16, shb_speech_nonref_fx, L_FRAME48k + STEREO_DFT_OVL_MAX, Q16 ); // q_new_swb_speech_buffer+st->q_inp - 16 - > q_new_swb_speech_buffer+st->q_inp + Copy_Scale_sig_16_32_no_sat( voice_factors_fx16, voice_factors_fx, NB_SUBFR16k, Q16 ); // Q31 /* initialization */ hStereoDft = hCPE->hStereoDft; @@ -704,7 +713,6 @@ void stereo_icBWE_enc_ivas_fx( move32(); /* SHB frame buffer offsets for TBE processing << re-adjust check >>*/ - max_e = s_max( hStereoICBWE->mem_shb_speech_ref_e, shb_speech_ref_e ); Copy_Scale_sig( hStereoICBWE->mem_shb_speech_ref_fx, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) ); // mem_shb_speech_ref_e @@ -724,7 +732,6 @@ void stereo_icBWE_enc_ivas_fx( Copy_Scale_sig32( shb_speech_ref_fx, shb_frame_ref_fx + L_LOOK_16k - refMemLen, L_FRAME16k, negate( sub( max_e, shb_speech_ref_e ) ) ); /* shb_speech_ref_e */ Copy_Scale_sig_32_16( shb_frame_ref_fx + L_FRAME16k, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) - Q16 ); // mem_shb_speech_ref_e - test(); test(); IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) @@ -800,8 +807,8 @@ void stereo_icBWE_enc_ivas_fx( excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); /* Q31-max_e */ move32(); } - /* LP synthesis */ + /* LP synthesis */ Copy_Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( hStereoICBWE->mem_lpc_shbsynth_nonref_e, s_max( hStereoICBWE->mem_lpc_shbsynth_nonref_e, max_e ) ) ); /* Q31-tmp_e */ Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, sub( max_e, s_max( hStereoICBWE->mem_lpc_shbsynth_nonref_e, max_e ) ) ); /* Q31-tmp_e */ max_e = s_max( hStereoICBWE->mem_lpc_shbsynth_nonref_e, max_e ); @@ -822,11 +829,10 @@ void stereo_icBWE_enc_ivas_fx( move16(); } - icbwe_dft_stereo_param_ivas_fx( hStereoICBWE, hStereoDft, st, shb_synth_nonref_fx, &shb_synth_nonref_e ); + icbwe_dft_stereo_param_fx( hStereoICBWE, hStereoDft, st, shb_synth_nonref_fx, &shb_synth_nonref_e ); } ELSE { - max_e = s_max( hStereoICBWE->mem_shb_speech_ref_e, shb_speech_ref_e ); Copy_Scale_sig( hStereoICBWE->mem_shb_speech_ref_fx, hStereoICBWE->mem_shb_speech_ref_fx, L_LOOK_16k, negate( sub( max_e, hStereoICBWE->mem_shb_speech_ref_e ) ) ); // mem_shb_speech_ref_e @@ -902,7 +908,6 @@ void stereo_icBWE_enc_ivas_fx( /*temp1 = 0.8f*hStereoICBWE->prevNonRefEner + 0.2f*temp1;*/ /*temp2 = 0.8f*hStereoICBWE->prevRefEner + 0.2f*temp2;*/ - IF( temp2_fx == 0 ) { gDes_fx = 1073741824; /* 1.0 in Q30 */ @@ -1014,6 +1019,7 @@ void stereo_icBWE_enc_ivas_fx( excSHB_nonref_fx[j] = L_shr( excSHB_nonref_fx[j], sub( max_e, exp_buf[j] ) ); /* Q31-max_e */ move32(); } + /* LP synthesis */ Copy_Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( hStereoICBWE->mem_lpc_shbsynth_nonref_e, s_max( hStereoICBWE->mem_lpc_shbsynth_nonref_e, max_e ) ) ); /* Q31-tmp_e */ Copy_Scale_sig32( excSHB_nonref_fx, excSHB_nonref_fx, L_FRAME16k, sub( max_e, s_max( hStereoICBWE->mem_lpc_shbsynth_nonref_e, max_e ) ) ); /* Q31-tmp_e */ @@ -1041,7 +1047,7 @@ void stereo_icBWE_enc_ivas_fx( IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) { /* IC BWE spectral mapping */ - spIndx = ic_bwe_enc_specMapping_ivas_fx( shb_frame_nonref_fx, shb_frame_nonref_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_e ), hStereoICBWE->memShbSpecXcorr_fx, &( hStereoICBWE->memShbSpecXcorr_e ) ); /* Q0 */ + spIndx = ic_bwe_enc_specMapping_fx( shb_frame_nonref_fx, shb_frame_nonref_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_fx ), &( hStereoICBWE->memShbSpecMapping_e ), hStereoICBWE->memShbSpecXcorr_fx, &( hStereoICBWE->memShbSpecXcorr_e ) ); /* Q0 */ } ELSE { @@ -1065,7 +1071,7 @@ void stereo_icBWE_enc_ivas_fx( /* IC BWE GS mapping */ - gsIndx = ic_bwe_enc_gsMapping_ivas_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); /* Q0 */ + gsIndx = ic_bwe_enc_gsMapping_fx( hStereoICBWE->gDes_pastFrame_fx, hStereoICBWE->gDes_pastFrame_e, hStereoICBWE->shbSynthRef_fx, hStereoICBWE->shbSynthRef_e, shb_synth_nonref_fx, &shb_synth_nonref_e, &( hStereoICBWE->prevgsMapping_fx ), &( hStereoICBWE->prevgsMapping_e ), hStereoICBWE->memGsEnerMap_fx, &hStereoICBWE->memGsEnerMap_e, st->element_mode ); /* Q0 */ hStereoICBWE->gDes_pastFrame_fx = gDes_fx; /* Q31-hStereoICBWE->gDes_pastFrame_e */ hStereoICBWE->gDes_pastFrame_e = gDes_e; @@ -1087,6 +1093,7 @@ void stereo_icBWE_enc_ivas_fx( * * Stereo (inter-channel) BWE mapping - encoder initialization *-------------------------------------------------------------------*/ + void stereo_icBWE_init_enc_fx( STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ) @@ -1175,11 +1182,14 @@ void stereo_icBWE_init_enc_fx( return; } + + /*-------------------------------------------------------------------* * findRefChanBWE() * * Inter-channel BWE pre-proc of the non-ref channel *-------------------------------------------------------------------*/ + static void findRefChanBWE_fx( const Word16 *input0_fx, /* i/o : input 0 Qx q_dataChan_fx*/ const Word16 *input1_fx, /* i/o : input 1 Qx q_dataChan_fx*/ @@ -1221,6 +1231,7 @@ static void findRefChanBWE_fx( * * Inter-channel BWE pre-proc of the non-ref channel *-------------------------------------------------------------------*/ + void stereo_icBWE_preproc_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const Word16 input_frame, /* i : input frame length Q0*/ diff --git a/lib_enc/ivas_stereo_mdct_core_enc_fx.c b/lib_enc/ivas_stereo_mdct_core_enc_fx.c index 6bb6af1b3e249e69e1fa681a5250b752bf1095ac..705635d887e22490a1c1272d93d120d28835caec 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_core_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,20 +33,20 @@ #include #include #include "options.h" -#include -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" -#include "rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "prot_fx_enc.h" + /*-------------------------------------------------------------------* * sync_tcx_mode() * * Synchronize under certain conditions the tcx modes and set overlap * windows accordingly *-------------------------------------------------------------------*/ + static void sync_tcx_mode_fx( Encoder_State **st /* i/o: Encoder state */ ) diff --git a/lib_enc/ivas_stereo_mdct_igf_enc_fx.c b/lib_enc/ivas_stereo_mdct_igf_enc_fx.c index d22e1b885b7791d5cdadd3e62de61d00262b0588..397d72c32386b2ac36c5e0bcf153e19e3b0e0106 100644 --- a/lib_enc/ivas_stereo_mdct_igf_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_igf_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,14 +33,13 @@ #include #include #include "options.h" -#include #include "prot_fx.h" -#include "cnst.h" -#include "stat_enc.h" +#include "ivas_cnst.h" #include "ivas_stat_enc.h" #include "ivas_prot_fx.h" #include "wmc_auto.h" + /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c index d53eb365d3dcca44ca72231143fec4127c002df0..31f33752132e875ed91d924dc5080ef5f9d3f911 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,15 +33,12 @@ #include #include #include "options.h" -#include #include "ivas_cnst.h" #include "ivas_prot_fx.h" #include "prot_fx.h" -#include "prot_fx_enc.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" -#include "stat_enc.h" /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index c6fc59283718c838d40673904eceecad903811ad..32d54deb69bf7dcc990a679c8f9fa530e35f56fc 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,8 +32,7 @@ #include #include "options.h" -#include "cnst.h" -#include "rom_com.h" +#include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include "assert.h" @@ -94,7 +93,11 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } +#ifndef FIX_2405_HARM_SMC_INIT speech_music_clas_init_ivas_fx( st->hSpMusClas ); +#else + speech_music_clas_init_fx( st->element_mode, st->hSpMusClas ); +#endif } return IVAS_ERR_OK; @@ -386,7 +389,7 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_enc_init_ivas_fx( hCPE->hCoreCoder[0]->hTdCngEnc, hCPE->hCoreCoder[0]->Opt_DTX_ON, hCPE->hCoreCoder[0]->max_bwidth ); + td_cng_enc_init_fx( hCPE->hCoreCoder[0]->hTdCngEnc, hCPE->hCoreCoder[0]->Opt_DTX_ON, hCPE->hCoreCoder[0]->max_bwidth ); } /* allocate TCA data structure */ @@ -435,7 +438,11 @@ ivas_error stereo_memory_enc_fx( } } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); +#else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/ivas_stereo_td_analysis_fx.c b/lib_enc/ivas_stereo_td_analysis_fx.c index ab28f7f7e4e64c63a8d86c43f1751a5cbc9dd921..e9a6cd843f63d886af9abbbd18b9c1e704845808 100644 --- a/lib_enc/ivas_stereo_td_analysis_fx.c +++ b/lib_enc/ivas_stereo_td_analysis_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,9 +32,6 @@ #include #include "options.h" -#include -#include "cnst.h" -#include "rom_com.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index bad9370b4c7ec575732abc5572af095b14e87bd3..4e3b5fdd1528b01b8ad3d7f45e1963da9559f6b1 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,10 +31,8 @@ *******************************************************************************************************/ #include -#include #include "options.h" -#include "cnst.h" -#include "rom_com.h" +#include "ivas_cnst.h" #include "prot_fx.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -327,7 +325,11 @@ ivas_error stereo_set_tdm_fx( return error; } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); +#else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) @@ -398,9 +400,9 @@ void tdm_configure_enc_fx( hStereoTD->tdm_use_IAWB_Ave_lpc = 0; /* Flag initialisation */ move16(); - sts[0]->hSpMusClas->tdm_lt_Etot_fx = add( mult( 3277 /*0.1f in Q15*/, Etot_last_fx[0] ), mult( 29491 /* 0.9f*/, sts[0]->hSpMusClas->tdm_lt_Etot_fx ) ); + sts[0]->hSpMusClas->tdm_lt_Etot_fx = mac_r( L_mult( 3277 /*0.1f in Q15*/, Etot_last_fx[0] ), 29491 /* 0.9f*/, sts[0]->hSpMusClas->tdm_lt_Etot_fx ); move16(); - sts[1]->hSpMusClas->tdm_lt_Etot_fx = add( mult( 3277 /*0.1f in Q15*/, Etot_last_fx[1] ), mult( 29491 /* 0.9f*/, sts[1]->hSpMusClas->tdm_lt_Etot_fx ) ); + sts[1]->hSpMusClas->tdm_lt_Etot_fx = mac_r( L_mult( 3277 /*0.1f in Q15*/, Etot_last_fx[1] ), 29491 /* 0.9f*/, sts[1]->hSpMusClas->tdm_lt_Etot_fx ); move16(); test(); @@ -797,11 +799,14 @@ static void tdm_downmix_plain_ivas_fx( ) { Word16 i; + Word16 One_m_Ratio_fx16, ratio_L_fx16; + One_m_Ratio_fx16 = extract_h( One_m_Ratio_fx ); + ratio_L_fx16 = extract_h( ratio_L_fx ); FOR( i = start_index; i < end_index; i++ ) { - FR_Y_fx[i] = add( mult( Right_in_fx[i], extract_h( One_m_Ratio_fx ) ), mult( Left_in_fx[i], extract_h( ratio_L_fx ) ) ); - LR_X_fx[i] = sub( mult( Left_in_fx[i], extract_h( One_m_Ratio_fx ) ), mult( Right_in_fx[i], extract_h( ratio_L_fx ) ) ); + FR_Y_fx[i] = mac_r( L_mult( Right_in_fx[i], One_m_Ratio_fx16 ), Left_in_fx[i], ratio_L_fx16 ); + LR_X_fx[i] = msu_r( L_mult( Left_in_fx[i], One_m_Ratio_fx16 ), Right_in_fx[i], ratio_L_fx16 ); move16(); move16(); } diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index 8538f95d1c00e395975a3e95c2a409751952e513..db24fbd35ce16f4260f22824b4a50b7b8b180d4b 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,15 +33,14 @@ #include #include #include "options.h" -#include -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" #include "rom_com.h" #include "basop_proto_func.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "prot_fx_enc.h" -#include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * stereo_tcx_init_enc() @@ -135,7 +134,11 @@ void stereo_tcx_init_enc_fx( test(); IF( !prev_IsTNSAllowed && st->hTcxCfg->fIsTNSAllowed && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) /* may happen in unified stereo when switching stereo technologies */ { +#ifdef FIX_2388_INITTNSCONFIGURATION + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); +#else InitTnsConfigs_ivas_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); +#endif SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, 0 ); } @@ -421,8 +424,8 @@ void stereo_tcx_core_enc( move16(); } - lpc_quantization_ivas_fx( st, lsp_new_fx, lsp_mid_fx, lsp_q_fx, lsf_q_fx, lspmid_q_fx, AUDIO, 0, /*No acelp->no need to compute any mid-LPC*/ - param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, Q_ener ); + lpc_quantization_fx( st, lsp_new_fx, lsp_mid_fx, lsp_q_fx, lsf_q_fx, lspmid_q_fx, NULL, st->clip_var_fx, AUDIO, 0, /*No acelp->no need to compute any mid-LPC*/ + param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, Q_ener ); /*--------------------------------------------------------------* * Rate switching @@ -630,17 +633,15 @@ void stereo_tcx_core_enc( E_LPC_a_lsp_conversion( A_fx, lsptmp_fx, lsp_new_fx, M ); Residu3_fx( A_fx, buf_fx + L_LP - L_FRAME, res_fx, L_FRAME, 0 ); - cng_params_upd_ivas_fx( lsptmp_fx, res_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, - st->hTdCngEnc->ho_lsp_circ_fx, Q_r, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, - st->hFdCngEnc->hFdCngCom->CngBandwidth ); + cng_params_upd_fx( lsptmp_fx, res_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, + Q_r, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); Q_exc = Q_r; move16(); } ELSE { - cng_params_upd_ivas_fx( lsp_new_fx, st->hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, - st->hTdCngEnc->ho_lsp_circ_fx, st->hLPDmem->q_lpd_old_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, - st->hFdCngEnc->hFdCngCom->CngBandwidth ); + cng_params_upd_fx( lsp_new_fx, st->hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, + st->hLPDmem->q_lpd_old_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); } IF( EQ_16( st->L_frame, L_FRAME ) ) diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 21fa7131243fcfef33162a6c624179eb68126900..b14a2d27d890283d1c19c59e2f72cc13f00153a7 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,8 +32,6 @@ #include #include "options.h" -#include "cnst.h" -#include "stat_enc.h" #include "rom_com.h" #include "ivas_rom_com.h" #include "ivas_cnst.h" @@ -49,20 +47,20 @@ * Encode secondary channel of TD Stereo with a low-bitrate encoder *-------------------------------------------------------------------*/ -void tdm_low_rate_enc( - Encoder_State *st, /* i/o: State structure */ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *synth, /* i/o: core synthesis Q_new*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *pitch_buf, - /* i/o: floating pitch values for each subframe */ // Q6 - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - const Word16 attack_flag, /* i : GSC attack flag Q0*/ - const Word16 *lsf_new, /* i : current frame ISF vector Qx2.56*/ - Word16 *tmp_noise, /* o : long-term noise energy Q11*/ - Word16 Q_new ) +void tdm_low_rate_enc_fx( + Encoder_State *st, /* i/o: State structure */ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + Word16 *synth, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ + const Word16 attack_flag, /* i : GSC attack flag Q0*/ + const Word16 *lsf_new, /* i : current frame ISF vector Qx2.56*/ + Word16 *tmp_noise, /* o : long-term noise energy Q11*/ + const Word16 Q_new /* i : Scaling factor */ +) { const Word16 *p_Aq; Word16 i_subfr, nb_subfr, last_pit_bin; @@ -114,7 +112,12 @@ void tdm_low_rate_enc( Word16 Q_exc = Q_new; move16(); + +#ifdef FIX_1904_HARM_GSC_ENC + gsc_enc_fx( st, dct_res_fx, dct_epit_fx, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf_fx, tmp_noise, &Q_exc ); +#else gsc_enc_ivas_fx( st, dct_res_fx, dct_epit_fx, last_pit_bin, tmp_nb_bits_tot, nb_subfr, lsf_new, exc_wo_nf_fx, tmp_noise, &Q_exc ); +#endif /*--------------------------------------------------------------------------------------* * iDCT transform @@ -128,7 +131,11 @@ void tdm_low_rate_enc( * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ +#ifdef FIX_1904_HARM_GSC_ENC + pre_echo_att_fx( &st->hGSCEnc->Last_frame_ener_fx, exc_fx, attack_flag, Q_exc, st->last_coder_type, st->L_frame, st->element_mode ); +#else pre_echo_att_ivas_fx( &st->hGSCEnc->Last_frame_ener_fx, exc_fx, attack_flag, Q_exc, st->last_coder_type, st->L_frame ); +#endif /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -176,8 +183,8 @@ void tdm_low_rate_enc( * Encode GC, 2 subframes mode *-------------------------------------------------------------------*/ -void encod_gen_2sbfr( - Encoder_State *st, /* i/o: state structure */ +void encod_gen_2sbfr_fx( + Encoder_State *st, /* i/o: state structure */ const Word16 speech[], /* i : input speech Q_new-1 */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes e(norm_s(Aw[0]+1)*/ const Word16 Aq[], /* i : LP coefficients e(norm_s(Aw[0]+1)*/ @@ -188,10 +195,11 @@ void encod_gen_2sbfr( Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ Word16 *voice_factors, /* o : voicing factors Q15 */ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : pitch values for primary channel Q4 */ - Word16 Q_new, - Word16 shift ) + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +) { Word16 xn[2 * L_SUBFR]; /* Target vector for pitch search */ Word16 xn2[2 * L_SUBFR]; /* Target vector for codebook search */ @@ -281,7 +289,7 @@ void encod_gen_2sbfr( Scale_sig( h1, 2 * L_SUBFR, sub( 13, q_h1 ) ); // Q13 - tbe_celp_exc_ivas( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, st->tdm_LRTD_flag ); + tbe_celp_exc_fx( st->element_mode, st->idchan, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, bwe_exc, st->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Find adaptive exitation @@ -304,21 +312,20 @@ void encod_gen_2sbfr( lp_filt_exc_enc_fx( MODE1, coder_type, i_subfr, exc, h1, xn, y1, xn2, 2 * L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &st->acelp_cfg.ltf_mode ); /* update long-term pitch gain for speech/music classifier */ - st->hSpMusClas->lowrate_pitchGain = add( mult( 29491, st->hSpMusClas->lowrate_pitchGain ), mult( 3277 /*Q15*/, gain_pit ) ); // Q14 + st->hSpMusClas->lowrate_pitchGain = mac_r( L_mult( 29491, st->hSpMusClas->lowrate_pitchGain ), 3277 /*Q15*/, gain_pit ); // Q14 move16(); /*-----------------------------------------------------------------* * Innovation encoding *-----------------------------------------------------------------*/ - inov_encode_ivas_fx( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, st->sharpFlag, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &i, 2 * L_SUBFR, shift, Q_new ); + inov_encode_fx( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, st->sharpFlag, i_subfr, -1, p_Aq, gain_pit, cn, exc, h2, hLPDmem->tilt_code, *pt_pitch, xn2, code, y2, &i, 2 * L_SUBFR, shift, Q_new ); /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - gain_enc_lbr_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, - st->element_mode ); + gain_enc_lbr_fx( st->hBstr, st->acelp_cfg.gains_mode, coder_type, i_subfr, xn, y1, add( sub( Q_new, 1 ), shift ), y2, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gc_mem, gp_mem, clip_gain, 2 * L_SUBFR, st->element_mode ); IF( st->Opt_SC_VBR ) { @@ -336,9 +343,10 @@ void encod_gen_2sbfr( gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); - Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_sat( Lgcode ); /*Q0*/ - hLPDmem->tilt_code = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR, 0 ); /* Q15 */ + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); /*Q0*/ + + hLPDmem->tilt_code = est_tilt_fx( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, Q_new, 2 * L_SUBFR ); /* Q15 */ move16(); /*-----------------------------------------------------------------* diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 8cf6be1cd0e6ca1385d5c7ec3588583ea115ac20..c5f124e57f154024c33b7688f7cc47e7529ab49c 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index e2a63c4c750f8af41d2e61844ee06342de5d529f..3c6baff395c7e4df02b65aa2ba3dff41244226c0 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,7 +30,6 @@ *******************************************************************************************************/ -#include #include #include #include @@ -45,6 +44,7 @@ #include "wmc_auto.h" #include "ivas_rom_enc.h" + /*---------------------------------------------------------------------* * Local struct *---------------------------------------------------------------------*/ diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index 0228b6cbeacab739bc3cc11f9ae6a6f67cfc300e..46e455617ff6f55a18575767f80f4300671c1f13 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -145,9 +145,6 @@ void ivas_long_enr_fx( move32(); } - /*-----------------------------------------------------------------* - * Initialize parameters for energy tracking and signal dynamics - *-----------------------------------------------------------------*/ return; } @@ -168,52 +165,50 @@ void long_enr_fx( * and total active speech energy *-----------------------------------------------------------------*/ + IF( LT_16( st_fx->ini_frame, 4 ) ) { - IF( LT_16( st_fx->ini_frame, 4 ) ) + st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; /* Q8 */ + move16(); + tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ + st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); /* Q8 */ + move16(); + } + ELSE + { + /* if ( st->ini_frame < 150 ) { + st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; + } else { + st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; + } */ + alpha = 655; /* 0.02 Q15 */ + move16(); + if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ { - st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; /* Q8 */ - move16(); - tmp = add( st_fx->lp_noise_fx, 2560 ); /*10.0 in Q8*/ - st_fx->lp_speech_fx = s_max( st_fx->lp_speech_fx, tmp ); /* Q8 */ + alpha = 1638; /* 0.05 Q15 */ move16(); } - ELSE + st_fx->lp_noise_fx = noise_est_AR1_Qx( hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx, alpha ); /* Q8 state, alpha in Q15 */ + move16(); + + test(); + IF( ( localVAD_HE_SAD != 0 ) && ( high_lpn_flag == 0 ) ) { - /* if ( st->ini_frame < 150 ) { - st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; - } else { - st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; - } */ - alpha = 655; /* 0.02 Q15 */ - move16(); - if ( LT_16( st_fx->ini_frame, 150 ) ) /* should match HE_LT_CNT_INIT_FX */ + IF( LT_16( sub( st_fx->lp_speech_fx, Etot ), 10 * 256 ) ) /* 10.0 in Q8 */ { - alpha = 1638; /* 0.05 Q15 */ + /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ + st_fx->lp_speech_fx = noise_est_AR1_Qx( Etot, st_fx->lp_speech_fx, 655 ); /* Q8 state, 0.02 in Q15 */ move16(); } - st_fx->lp_noise_fx = noise_est_AR1_Qx( hNoiseEst->totalNoise_fx, st_fx->lp_noise_fx, alpha ); /* Q8 state, alpha in Q15 */ - move16(); - - test(); - IF( ( localVAD_HE_SAD != 0 ) && ( high_lpn_flag == 0 ) ) + ELSE { - IF( LT_16( sub( st_fx->lp_speech_fx, Etot ), 10 * 256 ) ) /* 10.0 in Q8 */ - { - /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ - st_fx->lp_speech_fx = noise_est_AR1_Qx( Etot, st_fx->lp_speech_fx, 655 ); /* Q8 state, 0.02 in Q15 */ - move16(); - } - ELSE - { - st_fx->lp_speech_fx = sub( st_fx->lp_speech_fx, 13 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ - move16(); - } + st_fx->lp_speech_fx = sub( st_fx->lp_speech_fx, 13 ); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ + move16(); } } } - /*-----------------------------------------------------------------* - * Initialize parameters for energy tracking and signal dynamics - *-----------------------------------------------------------------*/ + /* Update */ + st_fx->hNoiseEst->Etot_last_fx = Etot; + return; } diff --git a/lib_enc/lp_exc_e_fx.c b/lib_enc/lp_exc_e_fx.c index fca0200f0bd3e05bd6c9160b6bfd35c1204fb704..81c9b43a6e2efb1dc91b2515e33e829771e51f42 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -389,7 +389,7 @@ Word16 corr_xy1_fx( /* Note: shl works as shl or shr. */ exp_xx = sub( exp_xx, 1 ); BASOP_SATURATE_WARNING_OFF_EVS - gain_p_snr = round_fx_sat( L_shl_sat( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_xx ) ); + gain_p_snr = round_fx_sat( L_shl_sat( Mpy_32_16_1( ACELP_GAINS_CONST_Q31, tmp ), exp_xx ) ); BASOP_SATURATE_WARNING_ON_EVS gain = s_min( gain, gain_p_snr ); // Q14 diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index d62b97f1db7151d0069de760c28b827077d2d2d5..bc1f4cb3a979d6ec7b864bbe8a8505f500d48877 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -24,15 +24,13 @@ * Local function prototypes *---------------------------------------------------------------------*/ -static void lsfq_CNG_fx( BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ); +static void lsfq_CNG_fx( const Word16 element_mode, BSTR_ENC_HANDLE hBstr, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ); static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word32 p_offset_scale1[][MAX_NO_SCALES + 1], Word32 p_offset_scale2[][MAX_NO_SCALES + 1], Word16 p_no_scales[][2], Word16 *resq, Word16 *lsfq ); static Word32 vq_lvq_lsf_enc_ivas_fx( Word16 pred_flag, Word16 mode, Word16 u[], Word16 *levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 *lsf, const Word16 *pred, Word16 *resq, Word16 *lsfq ); -static void lsf_mid_enc_fx( BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); - -static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word32 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); +static void lsf_mid_enc_fx( const Word16 element_mode, BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Word16 int_fs, const Word16 qlsp0[], const Word16 qlsp1[], Word16 lsp[], const Word16 coder_type, const Word16 bwidth, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); /*===========================================================================*/ @@ -62,15 +60,16 @@ static void lsf_mid_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 nb_bits, const Wo /* RETURN ARGUMENTS : */ /* _ None */ /*===========================================================================*/ + void lsf_enc_fx( - Encoder_State *st_fx, /* i/o: state structure */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - const Word16 Nb_ACELP_frames, + Encoder_State *st_fx, /* i/o: state structure */ + Word16 *lsf_new, /* o : quantized LSF vector */ + Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ + Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ + Word16 *Aq, /* o : quantized A(z) for 4 subframes */ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const Word16 Q_new ) { Word16 nBits = 0; @@ -78,6 +77,8 @@ void lsf_enc_fx( Word16 int_fs; Word16 force_sf = 0; move16(); + Word16 no_param_lpc; + Word16 param_lpc[NPRM_LPC_NEW]; Word16 fec_lsf[M], stab, i; Word32 L_tmp; Word16 coder_type, ppp_mode, nelp_mode; @@ -101,6 +102,7 @@ void lsf_enc_fx( move16(); } + no_param_lpc = 0; move16(); IF( st_fx->Opt_SC_VBR ) @@ -122,11 +124,20 @@ void lsf_enc_fx( assert( st_fx->sr_core <= 32000 ); int_fs = extract_l( st_fx->sr_core ); move32(); + /* convert LSPs to LSFs */ lsp2lsf_fx( lsp_new, lsf_new, M, int_fs ); /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); + IF( st_fx->element_mode == EVS_MONO ) + { + gp_clip_test_lsf_fx( st_fx->element_mode, lsf_new, st_fx->clip_var_fx, 0 ); + } + ELSE + { + gp_clip_test_lsf_ivas_fx( st_fx->element_mode, st_fx->core_brate, lsf_new, st_fx->clip_var_fx, 0 ); + } + /* Find the number of bits for LSF quantization */ nBits = 0; @@ -161,12 +172,13 @@ void lsf_enc_fx( move16(); } } + force_sf = 0; move16(); - /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ test(); - if ( LT_16( Nb_ACELP_frames, 3 ) && NE_32( st_fx->core_brate, SID_2k40 ) ) + if ( LT_16( st_fx->Nb_ACELP_frames, 3 ) && NE_32( st_fx->core_brate, SID_2k40 ) ) { + /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ force_sf = 1; move16(); } @@ -185,7 +197,7 @@ void lsf_enc_fx( *-------------------------------------------------------------------------------------*/ lsf_end_enc_fx( st_fx, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, - force_sf, NULL, NULL, NULL, st_fx->coder_type_raw ); + force_sf, param_lpc, &no_param_lpc, NULL, st_fx->coder_type_raw, tdm_lsfQ_PCh ); /* convert quantized LSFs back to LSPs */ lsf2lsp_fx( lsf_new, lsp_new, M, int_fs ); @@ -196,7 +208,21 @@ void lsf_enc_fx( /* don't use old LSF values if this is the first ACELP frame after HQ frames */ Copy( lsf_new, st_fx->lsf_old_fx, M ); } + /* set seed_acelp used in UC mode */ + test(); + IF( EQ_16( coder_type, UNVOICED ) && ( st_fx->element_mode > EVS_MONO ) ) + { + st_fx->seed_acelp = 0; + move16(); + FOR( i = no_param_lpc - 1; i >= 0; i-- ) + { + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + st_fx->seed_acelp = add( i_mult( add( shr( st_fx->seed_acelp, 1 ), param_lpc[i] ), 31821 ), 13849 ); + move16(); + } + } + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* return if SID frame (conversion to A(z) done in the calling function) */ @@ -218,7 +244,14 @@ void lsf_enc_fx( FEC_lsf_estim_enc_fx( st_fx, fec_lsf ); /* in case of FEC in decoder - calculate LSF stability */ - stab = lsf_stab_fx( lsf_new, fec_lsf, 0, st_fx->L_frame ); // Q15 + IF( st_fx->element_mode == EVS_MONO ) + { + stab = lsf_stab_fx( lsf_new, fec_lsf, 0, st_fx->L_frame ); // Q15 + } + ELSE + { + stab = lsf_stab_ivas_fx( lsf_new, fec_lsf, 0, st_fx->L_frame ); // Q15 + } test(); test(); @@ -249,19 +282,20 @@ void lsf_enc_fx( Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M ); Copy( lsf_new, st_fx->lsfoldbfi0_fx, M ); - /*-------------------------------------------------------------------------------------* * Mid-frame LSF encoding * LSP interpolation and conversion of LSPs to A(z) *-------------------------------------------------------------------------------------*/ - if ( st_fx->rate_switching_reset ) + + IF( st_fx->rate_switching_reset ) { /*extrapolation in case of unstable LSF convert*/ Copy( lsp_new, st_fx->lsp_old_fx, M ); // Q15 Copy( lsf_new, st_fx->lsf_old_fx, M ); // Q15 } + /* Mid-frame LSF encoding */ - lsf_mid_enc_fx( st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); + lsf_mid_enc_fx( st_fx->element_mode, st_fx->hBstr, st_fx->acelp_cfg.mid_lsf_bits, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); test(); IF( EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) ) @@ -296,265 +330,20 @@ void lsf_enc_fx( IF( NE_32( st_fx->core_brate, SID_2k40 ) ) { - st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); - } - - return; -} - -void lsf_enc_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Word16 *lsf_new, /* o : quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized Q15*/ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector Q15*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const Word16 Q_new ) -{ - Word16 nBits; - Word16 force_sf; - Word16 fec_lsf[M], stab, i; - Word16 no_param_lpc; - - Word16 param_lpc[NPRM_LPC_NEW]; - Word32 L_tmp; - Word16 coder_type, ppp_mode, nelp_mode; - - nBits = 0; - force_sf = 0; - move16(); - move16(); - - test(); - IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) ) - { - coder_type = INACTIVE; - move16(); - } - ELSE - { - coder_type = st->coder_type; - move16(); - } - - test(); - if ( EQ_16( coder_type, AUDIO ) && GSC_IVAS_mode > 0 ) - { - coder_type = GENERIC; - move16(); - } - - no_param_lpc = 0; - move16(); - - IF( st->Opt_SC_VBR ) - { - ppp_mode = st->hSC_VBR->ppp_mode; - nelp_mode = st->hSC_VBR->nelp_mode; - move16(); - move16(); - } - ELSE - { - ppp_mode = 0; - nelp_mode = 0; - move16(); - move16(); - } - - /* convert LSPs to LSFs */ - lsp2lsf_fx( lsp_new, lsf_new, M, st->sr_core ); - - /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_ivas_fx( st->element_mode, st->core_brate, lsf_new, st->clip_var_fx, 0 ); - - /* Find the number of bits for LSF quantization */ - nBits = 0; - move16(); - IF( EQ_32( st->core_brate, SID_2k40 ) ) - { - nBits = LSF_BITS_CNG; - move16(); - } - ELSE - { - test(); - IF( ( nelp_mode == 0 ) && ( ppp_mode == 0 ) ) - { - nBits = st->acelp_cfg.lsf_bits; - move16(); - } - ELSE IF( EQ_16( nelp_mode, 1 ) ) - { - IF( st->bwidth == NB ) - { - nBits = 32; - move16(); - } - ELSE IF( EQ_16( st->bwidth, WB ) ) - { - nBits = 30; - move16(); - } - } - ELSE IF( EQ_16( ppp_mode, 1 ) ) + IF( st_fx->element_mode == EVS_MONO ) { - nBits = 26; - move16(); + st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); } - } - force_sf = 0; - move16(); - /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ - test(); - if ( LT_16( st->Nb_ACELP_frames, 3 ) && NE_32( st->core_brate, SID_2k40 ) ) - { - force_sf = 1; - move16(); - } - - /* in case of unstable filter in decoder FEC, choose safety-net to help FEC */ - IF( EQ_16( st->next_force_safety_net, 1 ) ) - { - force_sf = 1; - move16(); - st->next_force_safety_net = 0; - move16(); - } - - /*-------------------------------------------------------------------------------------* - * Frame end LSF quantization - *-------------------------------------------------------------------------------------*/ - lsf_end_enc_ivas_fx( st, lsf_new, lsf_new, nBits, coder_type, Q_new + QSCALE - 2, - force_sf, param_lpc, &no_param_lpc, NULL, st->coder_type_raw, tdm_lsfQ_PCh ); - - /* convert quantized LSFs back to LSPs */ - lsf2lsp_fx( lsf_new, lsp_new, M, st->sr_core ); - - test(); - IF( EQ_16( st->last_core, HQ_CORE ) && ( st->core == ACELP_CORE ) ) - { - /* don't use old LSF values if this is the first ACELP frame after HQ frames */ - Copy( lsf_new, st->lsf_old_fx, M ); - } - /* set seed_acelp used in UC mode */ - - test(); - IF( EQ_16( coder_type, UNVOICED ) && ( st->element_mode > EVS_MONO ) ) - { - st->seed_acelp = 0; - move16(); - FOR( i = no_param_lpc - 1; i >= 0; i-- ) + ELSE { - /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st->seed_acelp = add( i_mult( add( shr( st->seed_acelp, 1 ), param_lpc[i] ), 31821 ), 13849 ); - move16(); + st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); // Q15 } } - IF( EQ_32( st->core_brate, SID_2k40 ) ) - { - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-------------------------------------------------------------------------------------* - * FEC - enforce safety-net in the next frame in case of unstable filter - *-------------------------------------------------------------------------------------*/ - - IF( NE_16( st->last_L_frame, st->L_frame ) ) - { - /* FEC - in case of core switching, use old LSFs */ - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); // Q15 - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); // Q15 - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); // Q15 - } - - FEC_lsf_estim_enc_fx( st, fec_lsf ); - - /* in case of FEC in decoder - calculate LSF stability */ - stab = lsf_stab_ivas_fx( lsf_new, fec_lsf, 0, st->L_frame ); // Q15 - - test(); - test(); - test(); - /* If decoder FEC frame may be unstable force safety-net usage */ - IF( ( EQ_16( st->L_frame, L_FRAME16k ) ) && ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( coder_type, GENERIC ) ) ) - { - st->next_force_safety_net = 1; - move16(); - } - ELSE IF( ( LT_16( stab, STAB_FAC_LIMIT_FX ) ) && ( EQ_16( st->clas, VOICED_CLAS ) || ( LT_16( st->clas, VOICED_CLAS ) && EQ_16( coder_type, AUDIO ) ) ) ) - { - st->next_force_safety_net = 1; - move16(); - } - - - /* FEC - update adaptive LSF mean vector */ - FOR( i = 0; i < M; i++ ) - { - L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ - L_tmp = L_mac( L_tmp, st->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ - L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ - st->lsf_adaptive_mean_fx[i] = extract_h( L_tmp ); /*Q(x2.56)*/ - } - - /* FEC - update LSF memories */ - Copy( st->lsfoldbfi0_fx, st->lsfoldbfi1_fx, M ); - Copy( lsf_new, st->lsfoldbfi0_fx, M ); - - - /*-------------------------------------------------------------------------------------* - * Mid-frame LSF encoding - * LSP interpolation and conversion of LSPs to A(z) - *-------------------------------------------------------------------------------------*/ - IF( st->rate_switching_reset ) - { - /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st->lsp_old_fx, M ); // Q15 - Copy( lsf_new, st->lsf_old_fx, M ); // Q15 - } - /* Mid-frame LSF encoding */ - lsf_mid_enc_ivas_fx( st->hBstr, st->acelp_cfg.mid_lsf_bits, st->sr_core, st->lsp_old_fx, lsp_new, lsp_mid, coder_type, st->bwidth, st->Bin_E_old_fx, Q_new + QSCALE - 2, ppp_mode, nelp_mode ); - - test(); - IF( EQ_16( st->last_core, HQ_CORE ) && EQ_16( st->core, ACELP_CORE ) ) - { - /* don't use old LSP/LSF values if this is the first ACELP frame after HQ frames */ - Copy( lsp_mid, st->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st->lsf_old_fx, M, st->sr_core ); - } - - /* LSP interpolation and conversion of LSPs to A(z) */ - test(); - IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) - { - IF( EQ_16( st->active_cnt, 1 ) ) - { - Copy( lsp_mid, st->lsp_old_fx, M ); // Q15 - lsp2lsf_fx( lsp_mid, st->lsf_old_fx, M, st->sr_core ); - Copy( lsp_new, lsp_mid, M ); // Q15 - } - - /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); - } - ELSE - { - int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); - } - /*------------------------------------------------------------------* - * Check LSF stability (distance between old LSFs and current LSFs) - *------------------------------------------------------------------*/ - IF( NE_32( st->core_brate, SID_2k40 ) ) - { - st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st->lsf_old_fx, 0, st->L_frame ); // Q15 - } return; } + + /*-------------------------------------------------------------------* * lsfq_CNG_fx() * @@ -567,10 +356,11 @@ void lsf_enc_ivas_fx( *-------------------------------------------------------------------*/ static void lsfq_CNG_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *lsf, /*x2.56 unquantized LSF vector */ - const Word16 *wghts, /*Q10 LSF weights */ - Word16 *qlsf, /*x2.56 quantized LSF vecotor */ + const Word16 element_mode, /* i : element mode */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ + const Word16 *lsf, /*x2.56 unquantized LSF vector */ + const Word16 *wghts, /*Q10 LSF weights */ + Word16 *qlsf, /*x2.56 quantized LSF vecotor */ Word32 *p_offset_scale1, Word32 *p_offset_scale2, Word16 *p_no_scales ) @@ -610,7 +400,6 @@ static void lsfq_CNG_fx( move16(); } - min_dist = L_add( MAXINT32, 0 ); FOR( i = first_cb; i < last_cb; i++ ) { @@ -643,10 +432,20 @@ static void lsfq_CNG_fx( /* quantize the difference with LVQ */ /* MSVQ_ROM to be updated */ - mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts, p_no_scales ); + IF( element_mode == EVS_MONO ) + { + mslvq_cng_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts, p_no_scales ); + + index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, + p_offset_scale1, p_offset_scale2, p_no_scales ); + } + ELSE + { + mslvq_cng_ivas_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts ); + + index_lvq_ivas_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG_IVAS + idx_cv, idx_lvq, 0 ); + } - index_lvq_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG + idx_cv, idx_lvq, - p_offset_scale1, p_offset_scale2, p_no_scales ); Vr_add( qlsf, &CNG_SN1_fx[idx_cv * M], qlsf, M ); /* write the VQ index to the bitstream */ @@ -659,113 +458,24 @@ static void lsfq_CNG_fx( return; } -static void lsfq_CNG_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *lsf, /*x2.56 unquantized LSF vector */ - const Word16 *wghts, /*Q10 LSF weights */ - Word16 *qlsf /*x2.56 quantized LSF vecotor */ + +/*-------------------------------------------------------------------* + * qlsf_Mode_Select_fx() + * + * Mode selection for LSF quantizer + *-------------------------------------------------------------------*/ + +static Word16 qlsf_Mode_Select_fx( + const Word16 *w, /* i : weighting vector Q8 */ + const Word16 *pred1, /* i : prediction vector x2.56 */ + const Word16 streaklimit, /* i : predictive streak limit Q15 */ + const Word32 op_loop_thr /* i : Open-loop Threshold */ ) { - Word16 i, j, idx_cv, idx_lvq[3]; - Word32 min_dist, dist; - Word16 dd[M], ddq[M]; - const Word16 *p_cb; - Word16 first_cb, last_cb; - Word16 idx_lead_cng[2], idx_scale_cng[2]; - Word16 tmp; - - idx_cv = 0; - move16(); - - /* quantize first stage with 4 bits - The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF - coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 - the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains - either NB or WB LSF data. */ - IF( GT_16( lsf[M - 1], WB_LIMIT_LSF_FX ) ) /* 16kHz sampled LSF vector*/ - { - p_cb = &CNG_SN1_fx[0]; - move16(); - first_cb = 0; - move16(); - last_cb = 6; - move16(); - } - ELSE /* 12.8kHz sampled LSF vector*/ - { - p_cb = &CNG_SN1_fx[6 * M]; - move16(); - first_cb = 6; - move16(); - last_cb = M; - move16(); - } - - - min_dist = L_add( MAXINT32, 0 ); - FOR( i = first_cb; i < last_cb; i++ ) - { - tmp = sub( *p_cb, shl( lsf[0], 1 ) ); /*x2.56 */ - dist = Mult_32_16( L_mult0( wghts[0], *p_cb ), tmp ); /*Q8 + x2.56 -Q15 + x2.56 = Q-7 + x2.56+x.256 */ - p_cb++; - FOR( j = 1; j < M; j++ ) - { - tmp = sub( *p_cb, lsf[j] ); - tmp = sub( tmp, lsf[j] ); - - dist = L_add( dist, Mult_32_16( L_mult0( wghts[j], *p_cb ), tmp ) ); - p_cb++; - } - IF( LT_32( dist, min_dist ) ) - { - min_dist = dist; - move16(); /*Q-4 */ - idx_cv = i; - move16(); - } - } - - /* calculate difference */ - FOR( i = 0; i < M; i++ ) - { - dd[i] = sub( lsf[i], CNG_SN1_fx[idx_cv * M + i] ); /*x2.56 */ - move16(); - } - - /* quantize the difference with LVQ */ - /* MSVQ_ROM to be updated */ - mslvq_cng_ivas_fx( idx_cv, dd, qlsf, ddq, idx_lead_cng, idx_scale_cng, wghts ); - - index_lvq_ivas_fx( ddq, idx_lead_cng, idx_scale_cng, START_CNG_IVAS + idx_cv, idx_lvq, 0 ); - Vr_add( qlsf, &CNG_SN1_fx[idx_cv * M], qlsf, M ); - - /* write the VQ index to the bitstream */ - push_indice( hBstr, IND_ISF_0_0, idx_cv, 4 ); - - /* write the LVQ index to the bitstream */ - push_indice( hBstr, IND_ISF_0_1, idx_lvq[0], LEN_INDICE ); - push_indice( hBstr, IND_ISF_0_1, idx_lvq[1], LSF_BITS_CNG - 4 - LEN_INDICE ); - - return; -} -/*-------------------------------------------------------------------* - * qlsf_Mode_Select_fx() - * - * Mode selection for LSF quantizer - *-------------------------------------------------------------------*/ - - -static Word16 qlsf_Mode_Select_fx( - const Word16 *w, /* i : weighting vector Q8 */ - const Word16 *pred1, /* i : prediction vector x2.56 */ - const Word16 streaklimit, /* i : predictive streak limit Q15 */ - const Word32 op_loop_thr /* i : Open-loop Threshold */ -) -{ - Word16 pred_pow2[M]; - Word32 temp32, En = 0; - Word16 safety_net; - Word16 i, cs, cl; + Word16 pred_pow2[M]; + Word32 temp32, En = 0; + Word16 safety_net; + Word16 i, cs, cl; /* calculate the prediction residual */ cl = 0; @@ -801,579 +511,73 @@ static Word16 qlsf_Mode_Select_fx( safety_net = 0; move16(); } - return safety_net; -} - - -/*========================================================================*/ -/* FUNCTION : lsf_end_enc_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Quantization of LSF parameters */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) lsf : LSF in the frequency domain (0..6400) x2.56 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) bwidth : input signal bandwidth */ -/* _ (Word16) nBits : number of bits used for ISF quantization */ -/* _ (Word16*) stable_isp : most recent stable ISP (can be */ -/* removed after passing to LSF) Q15 */ -/* _ (Word16*) stable_lsp : most recent stable LSP Q15 */ -/* _ (Word32*) grid : Table of 100 grid points for evaluating */ -/* Chebyshev polynomials Q31 */ -/* _ (Word16) int_fs : sampling frequency */ -/* _ (Word32) core_brate : Coding Bit Rate */ -/* _ (Word16) force_sf : Force safety-net usage if possible */ -/* _ (Word32*) Bin_Ener : FFT Bin energy 128 *2 sets Q_ener */ -/* _ (Word16) Q_ener : Q format of Bin_Ener */ -/* _ (Word32*) offset_scale1: offsets for LSF LVQ structure 1st */ -/* 8-dim subvector Q0 */ -/* _ (Word32*) offset_scale2: offsets for LSF LVQ structure 2nd */ -/* 8-dim subvector Q0 */ -/* _ (Word32*) offset_scale1_p: offsets for LSF LVQ structure, pred. */ -/* case, 1st 8-dim subvector Q0 */ -/* _ (Word32*) offset_scale2_p: offsets for LSF LVQ structure, */ -/* pred. case, 2nd 8-dim subvector Q0 */ -/* _ (Word16*) no_scales : LSF LVQ structure Q0 */ -/* _ (Word16*) no_scales_p : LSF LVQ structure Q0 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) mem_AR : quantizer memory for AR model x2.56 */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) qlsf : quantized LSFs in the cosine domain x2.56 */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void lsf_end_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) x2.56*/ - Word16 *qlsf, /* o : quantized LSF x2.56*/ - const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ - Word16 *lpc_param, - Word16 *no_indices, - Word16 *bits_param_lpc, - Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ -) -{ - Word16 i; - Word16 Idx0[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for safety-net quantizer */ - Word16 Idx1[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for predictive quantizer */ - Word16 indice[MAX_VQ_STAGES + 3]; /* Temp. array of indice for vector de-quantizer */ - Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ - Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; - const Word16 *Bit_alloc1 = NULL; - Word32 Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ - Word16 Tmp[M]; /* Temporary target vector (mean and prediction removed) */ - Word16 pred0[M]; /* Prediction for the safety-net quantizer (usually mean) */ - Word16 pred1[M]; /* Prediction for the predictive quantizer */ - Word16 pred2[M]; /* Prediction for the predictive quantizer */ - Word16 wghts[M]; /* Weighting used for quantizer (currently GSM based) */ - Word16 stages0; /* Amount of stages used by safety-net quantizer */ - Word16 stages1; /* Amount of stages used by predictive quantizer */ - Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer */ - Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer */ - Word16 predmode; /* 0: safety-net only, 1: predictive only, 2: best of the two */ - Word16 safety_net, cumleft, num_bits; - Word16 *Idx, stages, *bits; - Word16 Tmp2[M], Tmp1[M]; - Word32 abs_threshold; /* Absolute threshold depending on signal bandwidth, that indicates - very good perceptual LSF quantization performance */ - Word16 lsfq[M * 2], resq[M * 2]; - Word16 coder_type; /* coder type (from LSF quantizer point of view) */ - Word16 nBits; /* Number of bits */ - Word16 TCQIdx0[M + 2]; /* Optimal codebook indices for VQ-TCQ quantizer */ - Word16 *TCQIdx; - Word16 tmp; - Word16 flag_1bit_gran; - BSTR_ENC_HANDLE hBstr = st->hBstr; - - flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); - - nBits = nBits_in; - move16(); - /* Update LSF coder_type for LSF quantizer for some special cases */ - test(); - test(); - test(); - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) ) - { - IF( EQ_16( coder_type_raw, VOICED ) ) - { - coder_type = VOICED; - move16(); /* Reflect Inactive mode */ - if ( EQ_16( flag_1bit_gran, 1 ) ) - { - nBits = sub( nBits, 1 ); /* This is for real Generic*/ - } - } - ELSE - { - nBits = sub( nBits, 1 ); /* This is for real Generic*/ - coder_type = coder_type_org; - move16(); - } - } - ELSE - { - coder_type = coder_type_org; - move16(); - } - - /*----------------------------------------------------------------------------------- -* - * Calculate the number of stages and levels for each stage based on allowed bit budget - * Set absolute threshold for codebook-type decision logic depending on signal bandwidth - *------------------------------------------------------------------------------------ -*/ - IF( EQ_16( st->bwidth, NB ) ) - { - abs_threshold = L_add( SFNETLOWLIMIT_NB, 0 ); - } - ELSE - { - abs_threshold = L_add( SFNETLOWLIMIT_WB, 0 ); - } - /* Calculate LSF weighting coefficients */ - Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], Q_ener, lsf, wghts, (Word16) EQ_16( st->bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), st->sr_core, M ); - - /*--------------------------------------------------------------------------------* - * LSF quantization of SID frames - *--------------------------------------------------------------------------------*/ - IF( EQ_32( st->core_brate, SID_2k40 ) ) - { - lsfq_CNG_fx( hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); - sort_fx( qlsf, 0, M - 1 ); - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); - - return; - } - /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ - find_pred_mode( &predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); - - /*----------------------------------------------------------------* - * Calculate number of stages and levels for each stage based on the allowed bit allocation - * (subtract one bit for LSF predictor selection) - *----------------------------------------------------------------*/ - lsf_allocate_fx( sub( nBits, shr( predmode, 1 ) ), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); - - - /*--------------------------------------------------------------------------------* - * LSF quantization of all other frames but SID frames - * Select safety-net or predictive mode - *--------------------------------------------------------------------------------*/ - - Err[0] = MAXINT32; - move32(); - Err[1] = MAXINT32; - move32(); - /* for mem_MA update */ - FOR( i = 0; i < M; i++ ) - { - pred1[i] = add( ModeMeans_fx[mode_lvq][i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); - move16(); - } - - IF( predmode == 0 ) - { - /* Subtract only mean */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - Vr_subt( lsf, pred0, Tmp, M ); - - /* LVQ quantization (safety-net only) */ - Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, - st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); - safety_net = 1; - move16(); - st->pstreaklen = 0; - move16(); /* predictive LSF quantizer streak is ended with safety-net */ - } - ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ - { - Vr_subt( lsf, pred1, Tmp1, M ); - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); - - safety_net = 0; - move16(); - } - ELSE - { - /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in - case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ - test(); - test(); - test(); - IF( ( ( GT_16( st->pstreaklen, ( STREAKLEN + 3 ) ) ) && ( EQ_16( coder_type, VOICED ) ) ) || ( ( GT_16( st->pstreaklen, ( STREAKLEN ) ) ) && ( NE_16( coder_type, VOICED ) ) ) ) - { - /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ - st->streaklimit_fx = mult( st->streaklimit_fx, STREAKMULT_FX ); // Q15 - move16(); - } - - IF( st->pstreaklen == 0 ) - { - /* reset the consecutive AR-predictor multiplier */ - st->streaklimit_fx = 32767; /*1.0 in Q15 */ - move16(); - } - - /* VOICED_WB@16kHz */ - test(); - IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, VOICED ) && flag_1bit_gran == 0 ) - { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt( lsf, pred0, Tmp, M ); - - FOR( i = 0; i < M; i++ ) - { - /* subtract mean and AR prediction */ - pred2[i] = mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ); - Tmp2[i] = sub( Tmp[i], pred2[i] ); - pred2[i] = add( pred2[i], pred0[i] ); - } - - /* select safety_net or predictive */ - safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, st->streaklimit_fx, OP_LOOP_THR_HVO ); - IF( EQ_16( force_sf, 1 ) ) - { - safety_net = 1; - move16(); - } - - IF( safety_net ) - { - /* Safety-net - BC-TCQ quantization : SN */ - Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); - st->pstreaklen = 0; - move16(); - } - ELSE - { - /* predictive - BC-TCQ quantization : AR */ - Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub( nBits, 1 ), safety_net ); - st->pstreaklen = add( st->pstreaklen, 1 ); - } - } - /* all other frames (not VOICED@16kHz) */ - ELSE - { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt( lsf, pred0, Tmp, M ); - - FOR( i = 0; i < M; i++ ) - { - /* subtract mean and AR prediction */ - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_AR_fx[i], pred0[i] ) ) ); - Tmp2[i] = sub( lsf[i], pred2[i] ); - } - - /* safety-net */ - Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); - /* Predictive quantizer is calculated only if it can be selected */ - test(); - IF( !force_sf || GT_32( Err[0], abs_threshold ) ) - { - Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); - } - test(); - test(); - /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: - if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected - or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. - or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ - IF( force_sf || LT_32( Mult_32_16( Err[0], ( st->streaklimit_fx ) ), L_add( Err[1], Mult_32_16( Err[1], PREFERSFNET_FX ) ) ) || LT_32( Err[0], abs_threshold ) ) - { - safety_net = 1; - move16(); - st->pstreaklen = 0; - move16(); /* Reset the consecutive predictive frame counter */ - } - ELSE - { - safety_net = 0; - move16(); /* Increase the consecutive predictive frame counter by one */ - st->pstreaklen = add( st->pstreaklen, 1 ); - } - } - } - - /*--------------------------------------------------------------------------* \ - * Write indices to array \ - *--------------------------------------------------------------------------*/ - - IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->core, ACELP_CORE ) ) - { - /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ - test(); - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) ) - { - /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ - push_indice( hBstr, IND_LSF_PREDICTOR_SELECT_BIT, sub( coder_type, 2 ), 1 ); - } - - /* write predictor selection bit */ - IF( EQ_16( predmode, 2 ) ) - { - push_indice( st->hBstr, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); - } - - test(); - IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) - { - /* BC-TCVQ (only for VOICED@16kHz) */ - TCQIdx = &TCQIdx0[1]; - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - FOR( i = 0; i < ( M / 2 ) + 3; i++ ) - { - push_indice( hBstr, IND_LSF, TCQIdx[i], Bit_alloc1[i] ); - } - } - ELSE - { - cumleft = nBits; - move16(); - IF( EQ_16( predmode, 2 ) ) - { - /* subtract predictor selection bit */ - cumleft = sub( nBits, 1 ); - } - - IF( safety_net ) - { - stages = stages0; - move16(); - Idx = Idx0; - move16(); - bits = bits0; - move16(); - } - ELSE - { - stages = stages1; - move16(); - Idx = Idx1; - move16(); - bits = bits1; - move16(); - } - - tmp = sub( stages, 1 ); - FOR( i = 0; i < tmp; i++ ) - { - indice[i] = Idx[i]; - move16(); - num_bits = bits[i]; - move16(); - cumleft -= num_bits; - move16(); - push_indice( hBstr, IND_LSF, indice[i], num_bits ); - } - - WHILE( cumleft > 0 ) - { - indice[i] = Idx[i]; - move16(); - - IF( GT_16( cumleft, LEN_INDICE ) ) - { - num_bits = LEN_INDICE; - move16(); - } - ELSE - { - num_bits = cumleft; - move16(); - } - - cumleft = sub( cumleft, num_bits ); - push_indice( hBstr, IND_LSF, indice[i], num_bits ); - i = add( i, 1 ); - } - } - } - ELSE - { - test(); - IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) ) - { - /* BC-TCVQ (only for VOICED@16kHz) */ - /* Number of quantization indices */ - *no_indices = 10; - move16(); - FOR( i = 0; i < *no_indices; i++ ) - { - lpc_param[i] = TCQIdx0[i]; - move16(); - bits_param_lpc[i] = BC_TCVQ_BIT_ALLOC_40B[i]; // Q0 - move16(); - } - } - ELSE - { - /* Number of quantization indices */ - - /* there are 31 bits */ - IF( EQ_16( safety_net, 1 ) ) - { - Idx = Idx0; - move16(); - *no_indices = add( stages0, 1 ); - FOR( i = 0; i < stages0; i++ ) - { - lpc_param[i] = Idx[i]; - move16(); - indice[i] = Idx[i]; - move16(); - bits_param_lpc[i] = bits0[i]; - move16(); - } - lpc_param[stages0] = Idx[stages0]; - move16(); - indice[stages0] = Idx[stages0]; - move16(); - tmp = sub( stages0, 1 ); - bits_param_lpc[tmp] = LEN_INDICE; - move16(); - bits_param_lpc[stages0] = sub( bits0[tmp], LEN_INDICE ); - } - ELSE - { - *no_indices = add( stages1, 1 ); - Idx = Idx1; - move16(); - FOR( i = 0; i < stages1; i++ ) - { - lpc_param[i] = ( Idx[i] ); - move16(); - indice[i] = Idx[i]; - move16(); - bits_param_lpc[i] = bits1[i]; - move16(); - } - lpc_param[stages1] = ( Idx[stages1] ); - move16(); - indice[stages1] = Idx[stages1]; - move16(); - tmp = sub( stages1, 1 ); - bits_param_lpc[tmp] = LEN_INDICE; - move16(); - bits_param_lpc[stages1] = sub( bits1[tmp], LEN_INDICE ); - } - IF( EQ_16( predmode, 2 ) ) - { - FOR( i = *no_indices; i > 0; i-- ) - { - tmp = sub( i, 1 ); - lpc_param[i] = lpc_param[tmp]; - move16(); - bits_param_lpc[i] = bits_param_lpc[tmp]; - move16(); - } - lpc_param[0] = safety_net; - move16(); /* put the safety net info on the last param */ - bits_param_lpc[0] = 1; - move16(); - *no_indices = add( *no_indices, 1 ); - } - } - } - - - /*--------------------------------------------------------------------------* - * De-quantize encoded LSF vector - *--------------------------------------------------------------------------*/ - - IF( safety_net ) - { - /* Safety-net */ - test(); - IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) - { - /* BC-TCQ */ - Copy( lsfq, st->mem_MA_fx, M ); - Vr_add( lsfq, pred0, qlsf, M ); - } - ELSE - { - { - vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); - Vr_add( qlsf, pred0, qlsf, M ); - Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); - } - } - } - ELSE - { - test(); - IF( EQ_16( coder_type, VOICED ) && EQ_32( st->sr_core, INT_FS_16k ) && flag_1bit_gran == 0 ) - { - /* BC-TCVQ */ - Copy( lsfq, st->mem_MA_fx, M ); - Vr_add( lsfq, pred2, qlsf, M ); - } - ELSE - { - /* LVQ */ - vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], - &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); - IF( EQ_16( predmode, 1 ) ) - { - Copy( qlsf, st->mem_MA_fx, M ); - Vr_add( qlsf, pred1, qlsf, M ); - } - ELSE - { - Vr_add( qlsf, pred2, qlsf, M ); - Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); - } - } - } - - /* Sort the quantized vector to ascending order */ - sort_fx( qlsf, 0, M - 1 ); - - /* Verify stability by adding minimum separation */ - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); + return safety_net; +} - /* Update AR-predictor memories */ - Copy( qlsf, st->mem_AR_fx, M ); - return; -} +/*========================================================================*/ +/* FUNCTION : lsf_end_enc_fx() */ +/*------------------------------------------------------------------------*/ +/* PURPOSE : Quantization of LSF parameters */ +/*------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16*) lsf : LSF in the frequency domain (0..6400) x2.56 */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) bwidth : input signal bandwidth */ +/* _ (Word16) nBits : number of bits used for ISF quantization */ +/* _ (Word16*) stable_isp : most recent stable ISP (can be */ +/* removed after passing to LSF) Q15 */ +/* _ (Word16*) stable_lsp : most recent stable LSP Q15 */ +/* _ (Word32*) grid : Table of 100 grid points for evaluating */ +/* Chebyshev polynomials Q31 */ +/* _ (Word16) int_fs : sampling frequency */ +/* _ (Word32) core_brate : Coding Bit Rate */ +/* _ (Word16) force_sf : Force safety-net usage if possible */ +/* _ (Word32*) Bin_Ener : FFT Bin energy 128 *2 sets Q_ener */ +/* _ (Word16) Q_ener : Q format of Bin_Ener */ +/* _ (Word32*) offset_scale1: offsets for LSF LVQ structure 1st */ +/* 8-dim subvector Q0 */ +/* _ (Word32*) offset_scale2: offsets for LSF LVQ structure 2nd */ +/* 8-dim subvector Q0 */ +/* _ (Word32*) offset_scale1_p: offsets for LSF LVQ structure, pred. */ +/* case, 1st 8-dim subvector Q0 */ +/* _ (Word32*) offset_scale2_p: offsets for LSF LVQ structure, */ +/* pred. case, 2nd 8-dim subvector Q0 */ +/* _ (Word16*) no_scales : LSF LVQ structure Q0 */ +/* _ (Word16*) no_scales_p : LSF LVQ structure Q0 */ +/*------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16*) mem_AR : quantizer memory for AR model x2.56 */ +/*------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) qlsf : quantized LSFs in the cosine domain x2.56 */ +/*------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*========================================================================*/ -void lsf_end_enc_ivas_fx( +void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) x2.56*/ - Word16 *qlsf, /* o : quantized LSF x2.56*/ + const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) x2.56*/ + Word16 *qlsf, /* o : quantized LSF x2.56*/ const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + const Word16 coder_type_org, /* i : coding type */ + const Word16 Q_ener, /* i : Q value for Bin_Ener */ + const Word16 force_sf, /* i : Force safety-net usage if coding type supports */ Word16 *lpc_param, Word16 *no_indices, Word16 *bits_param_lpc, - Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases)*/ - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases) */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ) { Word16 i; Word16 Idx0[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for safety-net quantizer */ Word16 Idx1[MAX_VQ_STAGES + 3]; /* Optimal codebook indices for predictive quantizer */ Word16 indice[MAX_VQ_STAGES + 3]; /* Temp. array of indice for vector de-quantizer */ - Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ + Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; const Word16 *Bit_alloc1 = NULL; Word32 Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ @@ -1403,15 +607,21 @@ void lsf_end_enc_ivas_fx( Word16 pred3[M]; Word16 dummy, dummy_v[5]; - flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + flag_1bit_gran = 0; + move16(); + if ( GT_16( st->element_mode, EVS_MONO ) ) + { + flag_1bit_gran = 1; + move16(); + } nBits = nBits_in; move16(); + /* Update LSF coder_type for LSF quantizer for some special cases */ test(); test(); test(); - IF( EQ_16( coder_type_org, GENERIC ) && EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->codec_mode, MODE1 ) && ( st->idchan == 0 ) ) /* this bit is used only for primary channel or mono */ { IF( EQ_16( coder_type_raw, VOICED ) ) @@ -1443,14 +653,13 @@ void lsf_end_enc_ivas_fx( IF( st->bwidth == NB ) { - abs_threshold = SFNETLOWLIMIT_NB / 2; - move32(); + abs_threshold = L_add( SFNETLOWLIMIT_NB, 0 ); } ELSE { - abs_threshold = SFNETLOWLIMIT_WB / 2; - move32(); + abs_threshold = L_add( SFNETLOWLIMIT_WB, 0 ); } + /* Calculate LSF weighting coefficients */ Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], Q_ener, lsf, wghts, (Word16) EQ_16( st->bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), st->sr_core, M ); @@ -1460,12 +669,13 @@ void lsf_end_enc_ivas_fx( IF( EQ_32( st->core_brate, SID_2k40 ) ) { - lsfq_CNG_ivas_fx( hBstr, lsf, wghts, qlsf ); + lsfq_CNG_fx( st->element_mode, hBstr, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); sort_fx( qlsf, 0, M - 1 ); reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); return; } + /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ find_pred_mode( &predmode, coder_type, st->bwidth, st->sr_core, &mode_lvq, &mode_lvq_p, st->total_brate ); @@ -1510,7 +720,16 @@ void lsf_end_enc_ivas_fx( Vr_subt( lsf, pred0, Tmp, M ); /* LVQ quantization (safety-net only) */ - Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); + IF( flag_1bit_gran == 0 ) + { + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, + st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + } + ELSE + { + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); + } + safety_net = 1; move16(); st->pstreaklen = 0; @@ -1519,12 +738,21 @@ void lsf_end_enc_ivas_fx( ELSE IF( EQ_16( predmode, 1 ) ) /* only MA prediction */ { Vr_subt( lsf, pred1, Tmp1, M ); - Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); + + IF( flag_1bit_gran == 0 ) + { + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, resq, lsfq ); + } + ELSE + { + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, resq, lsfq ); + } safety_net = 0; move16(); } - ELSE + ELSE /* Switched Safety-Net/AR prediction */ { IF( EQ_16( predmode, 2 ) ) { @@ -1590,15 +818,31 @@ void lsf_end_enc_ivas_fx( /* all other frames (not VOICED@16kHz) */ ELSE { - /* safety-net */ + /* Switched Safety-Net/AR prediction */ + IF( flag_1bit_gran == 0 ) + { + Err[0] = vq_lvq_lsf_enc( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, st->offset_scale1_fx, st->offset_scale2_fx, st->no_scales_fx, resq, lsfq ); + } + ELSE + { + Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); + } - Err[0] = vq_lvq_lsf_enc_ivas_fx( 0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, resq, lsfq ); /* Predictive quantizer is calculated only if it can be selected */ test(); IF( !force_sf || GT_32( Err[0], abs_threshold ) ) { - Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); + IF( flag_1bit_gran == 0 ) + { + Err[1] = vq_lvq_lsf_enc( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M] ); + } + ELSE + { + Err[1] = vq_lvq_lsf_enc_ivas_fx( 2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, &resq[M], &lsfq[M] ); + } } + test(); test(); /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: @@ -1899,7 +1143,17 @@ void lsf_end_enc_ivas_fx( } ELSE { - vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); + IF( flag_1bit_gran == 0 ) + { + vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + } + ELSE + { + vq_dec_lvq_ivas_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0 - 1] ); + } + Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } @@ -1917,7 +1171,17 @@ void lsf_end_enc_ivas_fx( ELSE { /* LVQ */ - vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + IF( flag_1bit_gran == 0 ) + { + vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1], + &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], + &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); + } + ELSE + { + vq_dec_lvq_ivas_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + } + IF( EQ_16( predmode, 1 ) ) { Copy( qlsf, st->mem_MA_fx, M ); @@ -2419,12 +1683,12 @@ static Word32 vq_lvq_lsf_enc( diff[j] = shl_sat( diff[j], 4 ); move16(); } - L_tmp = L_mult( mult( diff[0], shl_sat( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ + L_tmp = L_mult( mult( diff[0], shl_sat( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ FOR( j = 1; j < M; j++ ) { - L_tmp = L_mac( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ + L_tmp = L_mac( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ } - e[i] = L_tmp; /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ + e[i] = L_tmp; /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ move32(); } @@ -2476,14 +1740,13 @@ static Word32 vq_lvq_lsf_enc_ivas_fx( IF( pred_flag == 0 ) /* safety net*/ { cb = &Quantizers_fx[CB_lsf[mode]]; + move16(); IF( LT_16( mode, 6 ) ) { - move16(); mode_glb = add( offset_lvq_modes_SN[mode], offset_in_lvq_mode_SN[mode][( levels[stagesVQ] - min_lat_bits_SN[mode] )] ); } ELSE { - move16(); mode_glb = add( offset_lvq_modes_SN[mode], levels[stagesVQ] - min_lat_bits_SN[mode] ); } } @@ -2539,10 +1802,10 @@ static Word32 vq_lvq_lsf_enc_ivas_fx( diff[j] = shl_sat( diff[j], 4 ); move16(); } - L_tmp = L_mult( mult( diff[0], shl_sat( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ + L_tmp = L_mult( mult( diff[0], shl_sat( w[0], 1 ) ), diff[0] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ FOR( j = 1; j < M; j++ ) { - L_tmp = L_mac_sat( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ + L_tmp = L_mac_sat( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q4 */ } e[i] = L_tmp; move32(); @@ -3460,17 +2723,18 @@ static void FFT_Mid_Interpol_16k_fx( static void lsf_mid_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 nb_bits, /* i : number of bits */ - const Word16 int_fs, /* i : internal (ACELP) sampling frequency*/ - const Word16 qlsp0[], /* i : quantized LSPs from frame beginning*/ - const Word16 qlsp1[], /* i : quantized LSPs from frame end */ - Word16 lsp[], /* i/o: mid-frame LSP */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word32 Bin_Ener_old[], /* i/o: per bin old log energy spectrum */ - Word32 Bin_Ener[], /* i : per bin log energy spectrum */ - Word16 Q_ener, /* i : Q value of Bin_ener */ + const Word16 element_mode, /* i : element mode */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 nb_bits, /* i : number of bits */ + const Word16 int_fs, /* i : internal (ACELP) sampling frequency*/ + const Word16 qlsp0[], /* i : quantized LSPs from frame beginning*/ + const Word16 qlsp1[], /* i : quantized LSPs from frame end */ + Word16 lsp[], /* i/o: mid-frame LSP */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + Word32 Bin_Ener_old[], /* i/o: per bin old log energy spectrum */ + Word32 Bin_Ener[], /* i : per bin log energy spectrum */ + Word16 Q_ener, /* i : Q value of Bin_ener */ Word16 ppp_mode, Word16 nelp_mode ) { @@ -3487,183 +2751,21 @@ static void lsf_mid_enc_fx( lsp2lsf_fx( qlsp0, qlsf0, M, int_fs ); lsp2lsf_fx( qlsp1, qlsf1, M, int_fs ); - /* calculate weights */ - FFT_Mid_Interpol_16k_fx( Bin_Ener_old, &Bin_Ener[L_FFT / 2], Bin_Ener_mid ); - - /* LSF weighting */ - Unified_weighting_fx( Bin_Ener_mid, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); - move16(); - /* codebook selection, number of bits, size of the codebook */ - test(); - IF( ppp_mode == 0 && nelp_mode == 0 ) + IF( element_mode == EVS_MONO ) { - /* codebook selection */ - IF( EQ_16( coder_type, VOICED ) ) - { - SWITCH( nb_bits ) - { - case 5: - { - ratio = tbl_mid_voi_wb_5b_fx; - move16(); - BREAK; - } - case 4: - { - ratio = tbl_mid_voi_wb_4b_fx; - move16(); - BREAK; - } - } - } - ELSE IF( EQ_16( coder_type, UNVOICED ) ) - { - ratio = tbl_mid_unv_wb_5b_fx; - } - ELSE - { - /* GENERIC, TRANSITION, AUDIO and INACTIVE */ - SWITCH( nb_bits ) - { - case 5: - { - ratio = tbl_mid_gen_wb_5b_fx; - move16(); - BREAK; - } - case 2: - { - ratio = tbl_mid_gen_wb_2b_fx; - move16(); - BREAK; - } - } - } + /* calculate weights */ + FFT_Mid_Interpol_16k_fx( Bin_Ener_old, &Bin_Ener[L_FFT / 2], Bin_Ener_mid ); - size = (Word16) pow2[nb_bits]; - move16(); - } - ELSE IF( EQ_16( ppp_mode, 1 ) ) - { - ratio = tbl_mid_voi_wb_1b_fx; - move16(); - nb_bits = 1; - move16(); - size = 2; - move16(); - } - ELSE IF( EQ_16( nelp_mode, 1 ) ) - { - ratio = tbl_mid_unv_wb_4b_fx; - move16(); - nb_bits = 4; - move16(); - size = 16; + /* LSF weighting */ + Unified_weighting_fx( Bin_Ener_mid, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); move16(); } - - /* loop over codevectors */ - err_min = MAXINT32; - move16(); - idx = 0; - move16(); - k1 = 0; - move16(); - FOR( k = 0; k < size; k++ ) + ELSE { - err = L_deposit_l( 0 ); - - FOR( j = 0; j < M; j++ ) - { - /* qlsf[j] = (1.0f - ratio[k*M+j]) * qlsf0[j] + ratio[k*M+j] * qlsf1[j]; */ - L_tmp = L_mult( sub( 0x2000, ratio[k1 + j] ), qlsf0[j] ); - L_tmp = L_mac( L_tmp, ratio[k1 + j], qlsf1[j] ); - qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); - - test(); - test(); - IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) - { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); - move16(); - } - - tmp = sub( lsf[j], qlsf[j] ); - /* err += wghts[j] * ftemp * ftemp; */ - /* tmp is usually very small, we can have some extra precision with very rare saturation */ - tmp = shl_sat( tmp, 4 ); - tmp = mult_r_sat( tmp, tmp ); - err = L_mac_sat( err, tmp, shl_sat( wghts[j], 2 ) ); - } - /* err = L_shl(err,Wscale); */ - err = Mult_32_16( err, LSF_1_OVER_256SQ ); - /* err = Mult_32_16(err,Wmult); */ - - IF( LT_32( err, err_min ) ) - { - err_min = L_add( err, 0 ); - idx = k; - move16(); - } - k1 += M; + Unified_weighting_fx( Bin_Ener_old, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); move16(); } - /* calculate the quantized LSF vector */ - FOR( j = 0; j < M; j++ ) - { - /* qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; */ - L_tmp = L_mult( sub( 0x2000, ratio[idx * M + j] ), qlsf0[j] ); - L_tmp = L_mac( L_tmp, ratio[idx * M + j], qlsf1[j] ); - qlsf[j] = round_fx( L_shl( L_tmp, 2 ) ); - - test(); - test(); - IF( j > 0 && LT_16( j, M ) && LT_16( qlsf[j], add( qlsf[j - 1], LSF_GAP_MID_FX ) ) ) - { - qlsf[j] = add( qlsf[j - 1], LSF_GAP_MID_FX ); - move16(); - } - } - - reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); - - /* convert LSFs back to LSPs */ - lsf2lsp_fx( qlsf, lsp, M, int_fs ); - push_indice( hBstr, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); - - return; -} - -static void lsf_mid_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 nb_bits, /* i : number of bits */ - const Word32 int_fs, /* i : internal (ACELP) sampling frequency*/ - const Word16 qlsp0[], /* i : quantized LSPs from frame beginning Q15*/ - const Word16 qlsp1[], /* i : quantized LSPs from frame end Q15*/ - Word16 lsp[], /* i/o: mid-frame LSP Q15*/ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word32 Bin_Ener[], /* i : per bin log energy spectrum Q_ener*/ - Word16 Q_ener, /* i : Q value of Bin_ener */ - Word16 ppp_mode, - Word16 nelp_mode ) -{ - Word16 lsf[M], qlsf[M], qlsf1[M], qlsf0[M], wghts[M]; - Word32 err, err_min; - Word16 j, k, idx, size = 0; - Word32 L_tmp; - Word16 tmp, k1; - const Word16 *ratio = NULL; - - /* convert LSPs to LSFs */ - lsp2lsf_fx( lsp, lsf, M, int_fs ); - lsp2lsf_fx( qlsp0, qlsf0, M, int_fs ); - lsp2lsf_fx( qlsp1, qlsf1, M, int_fs ); - - /* LSF weighting */ - Unified_weighting_fx( Bin_Ener, Q_ener, lsf, wghts, (Word16) EQ_16( bwidth, NB ), (Word16) EQ_16( coder_type, UNVOICED ), int_fs, M ); - move16(); /* codebook selection, number of bits, size of the codebook */ test(); IF( ppp_mode == 0 && nelp_mode == 0 ) @@ -3675,13 +2777,13 @@ static void lsf_mid_enc_ivas_fx( { case 5: { - ratio = tbl_mid_voi_wb_5b_fx; // Q13 + ratio = tbl_mid_voi_wb_5b_fx; move16(); BREAK; } case 4: { - ratio = tbl_mid_voi_wb_4b_fx; // Q13 + ratio = tbl_mid_voi_wb_4b_fx; move16(); BREAK; } @@ -3695,7 +2797,7 @@ static void lsf_mid_enc_ivas_fx( } ELSE IF( EQ_16( coder_type, UNVOICED ) ) { - ratio = tbl_mid_unv_wb_5b_fx; // Q13 + ratio = tbl_mid_unv_wb_5b_fx; } ELSE { @@ -3704,7 +2806,7 @@ static void lsf_mid_enc_ivas_fx( { case 5: { - ratio = tbl_mid_gen_wb_5b_fx; // Q13 + ratio = tbl_mid_gen_wb_5b_fx; move16(); BREAK; } @@ -3716,7 +2818,7 @@ static void lsf_mid_enc_ivas_fx( } case 2: { - ratio = tbl_mid_gen_wb_2b_fx; // Q13 + ratio = tbl_mid_gen_wb_2b_fx; move16(); BREAK; } @@ -3728,7 +2830,7 @@ static void lsf_mid_enc_ivas_fx( } ELSE IF( EQ_16( ppp_mode, 1 ) ) { - ratio = tbl_mid_voi_wb_1b_fx; // Q13 + ratio = tbl_mid_voi_wb_1b_fx; move16(); nb_bits = 1; move16(); @@ -3737,7 +2839,7 @@ static void lsf_mid_enc_ivas_fx( } ELSE IF( EQ_16( nelp_mode, 1 ) ) { - ratio = tbl_mid_unv_wb_4b_fx; // Q13 + ratio = tbl_mid_unv_wb_4b_fx; move16(); nb_bits = 4; move16(); diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index b7909991136d965b27a7104cc959f05dad605dc7..2f9f2b7c7a87fe1557a842fd5001e1c9eda70836 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -1466,7 +1466,6 @@ excludes the waveform contributions at pos 21,22,23 to the MSE, important to kee /*mvi2i (indices[1]+c2*stages, Idx, stages);*/ Copy( indices[1] + c2 * stages, Idx, stages ); - return; } @@ -1478,45 +1477,6 @@ excludes the waveform contributions at pos 21,22,23 to the MSE, important to kee *--------------------------------------------------------------------------*/ Word16 lsf_msvq_ma_encprm_fx( - BSTR_ENC_HANDLE hBstr, - Word16 *param_lpc, // Q0 - Word16 core, - Word16 acelp_mode, - Word16 acelp_midLpc, - Word16 *bits_param_lpc, - Word16 no_indices ) -{ - Word16 i, nbits_lpc; - Word16 bits_midlpc; - - bits_midlpc = MIDLSF_NBITS; - move16(); - nbits_lpc = 0; - move16(); - - FOR( i = 0; i < no_indices; i++ ) - { - - push_next_indice( hBstr, *param_lpc, bits_param_lpc[i] ); - param_lpc++; - nbits_lpc = add( nbits_lpc, bits_param_lpc[i] ); - } - IF( NE_16( acelp_mode, VOICED ) ) - { - test(); - IF( ( core == ACELP_CORE ) && acelp_midLpc ) - { - - push_next_indice( hBstr, *param_lpc, bits_midlpc ); - nbits_lpc = add( nbits_lpc, bits_midlpc ); - } - } - - return nbits_lpc; -} - - -Word16 lsf_msvq_ma_encprm_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 *param_lpc, // Q0 const Word16 core, @@ -1535,7 +1495,6 @@ Word16 lsf_msvq_ma_encprm_ivas_fx( FOR( i = 0; i < no_indices; i++ ) { - push_next_indice( hBstr, *param_lpc, bits_param_lpc[i] ); param_lpc++; nbits_lpc = add( nbits_lpc, bits_param_lpc[i] ); @@ -1545,7 +1504,6 @@ Word16 lsf_msvq_ma_encprm_ivas_fx( test(); IF( ( core == ACELP_CORE ) && acelp_midLpc ) { - push_next_indice( hBstr, *param_lpc, bits_midlpc ); nbits_lpc = add( nbits_lpc, bits_midlpc ); } @@ -1962,42 +1920,7 @@ Word16 Q_lsf_tcxlpc_ivas_fx( *--------------------------------------------------------------------------*/ Word16 enc_lsf_tcxlpc_fx( - Word16 **indices, /* i : Ptr to VQ indices */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -) -{ - Word16 i, NumBits; - - Word16 flag; - - /* Read flag */ - flag = ( *indices )[0]; - move16(); - ++*indices; - - NumBits = TCXLPC_NUMBITS; - move16(); - FOR( i = 0; i < TCXLPC_NUMSTAGES; ++i ) - { - push_next_indice( hBstr, **indices, lsf_numbits[i] ); - ++*indices; - } - - IF( flag ) - { - NumBits = add( NumBits, TCXLPC_IND_NUMBITS ); - FOR( i = 0; i < TCXLPC_IND_NUMSTAGES; ++i ) - { - push_next_indice( hBstr, **indices, lsf_ind_numbits[i] ); - ++*indices; - } - } - return NumBits; -} - - -Word16 enc_lsf_tcxlpc_ivas_fx( - const Word16 **indices, /* i : Ptr to VQ indices */ + const Word16 **indices, /* i : Ptr to VQ indices */ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { @@ -2038,27 +1961,6 @@ Word16 enc_lsf_tcxlpc_ivas_fx( *--------------------------------------------------------------------------*/ Word16 lsf_bctcvq_encprm_fx( - BSTR_ENC_HANDLE hBstr, - Word16 *param_lpc, // Q0 - Word16 *bits_param_lpc, - Word16 no_indices ) -{ - Word16 i, nbits_lpc; - - nbits_lpc = 0; - - FOR( i = 0; i < no_indices; i++ ) - { - push_next_indice( hBstr, *param_lpc, bits_param_lpc[i] ); - param_lpc++; - nbits_lpc = add( nbits_lpc, bits_param_lpc[i] ); - } - - return nbits_lpc; -} - - -Word16 lsf_bctcvq_encprm_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 *param_lpc, // Q0 const Word16 *bits_param_lpc, @@ -2067,7 +1969,6 @@ Word16 lsf_bctcvq_encprm_ivas_fx( Word16 i, nbits_lpc; nbits_lpc = 0; - move16(); FOR( i = 0; i < no_indices; i++ ) { diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 76b465777b13d649fd7d2be99e7eb48933a1085b..6c0ef3f094856d397141a4ec99d2093c200bb43b 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -9,11 +9,17 @@ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + #define THR_CORR_FX ( 56 << 15 ) /* 56 in Q15 starting threshold of multi-harm. correlation */ #define THR_CORR_MAX_FX 30720 /* 60 in Q9 upper threshold of multi-harm. correlation */ #define THR_CORR_MIN_FX 25088 /* 49 in Q9 lower threshold of multi-harm. correlation */ #define THR_CORR_STEP_FX 102 /* 0.2 in Q9 step for the threshold of multi-harm. correlation */ + /*---------------------------------------------------------------------* * multi_harm() * @@ -22,19 +28,19 @@ /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_fx( - - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ - Word16 *sp_floor, /* o: noise floor estimate Q7 */ - Word16 S_map[] /* o : short-term correlation map Q7 */ + const Word16 element_mode, /* i : IVAS element_mode Q0 */ + const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ + Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ + Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ + Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ + const Word32 total_brate, /* i : total bitrate Q0 */ + const Word16 bwidth, /* i : input signal bandwidth Q0 */ + Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ + Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ + Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ + Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ + Word16 *sp_floor, /* o: noise floor estimate Q7 */ + Word16 S_map[] /* o : short-term correlation map Q7 */ ) { Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT / 4], *pt_mins, harm; @@ -43,6 +49,7 @@ Word16 multi_harm_fx( Word32 L_acc; Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; Word16 mean_dyn; + Word32 tmp2_32; /*------------------------------------------------------------------* * initialization @@ -121,34 +128,63 @@ Word16 multi_harm_fx( step = 0; move16(); - FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) + IF( element_mode != EVS_MONO ) { - /* we are at the end of the next minimum */ - IF( EQ_16( i, *pt_mins ) ) + FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) { - pt_mins++; - flor = Bin_E[i]; - move16(); /*Q7*/ - /* calculate the new step */ - /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ - tmp16 = sub( *pt_mins, i ); - tmpdB = sub( Bin_E[*pt_mins], Bin_E[i] ); - sign_fx = shr( tmpdB, 15 ); /* 0 if positive else -1 */ - ExpdB = sub( norm_s( tmpdB ), 1 ); - tmpdB = abs_s( shl( tmpdB, ExpdB ) ); - ExpInd = norm_s( tmp16 ); - tmp16 = shl( tmp16, ExpInd ); - tmp16 = div_s( tmpdB, tmp16 ); - tmp16 = sub( s_xor( tmp16, sign_fx ), sign_fx ); - step = shr( tmp16, add( sub( ExpdB, ExpInd ), 15 ) ); /* Q7 */ + /* we are at the end of the next minimum */ + IF( EQ_16( i, *pt_mins ) ) + { + pt_mins++; + flor = Bin_E[i]; + move16(); /*Q7*/ + + /* calculate the new step */ + /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ + + tmp16 = div_s( 1, sub( *pt_mins, i ) ); // Q15 + step = msu_r( L_mult( Bin_E[*pt_mins], tmp16 ), Bin_E[i], tmp16 ); // Q7 (15+7+1-16) + } + + /* subtract the floor */ + S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); + move16(); + + /* update the floor */ + flor = add( flor, step ); /*Q7*/ } + } + ELSE + { + FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) + { + /* we are at the end of the next minimum */ + IF( EQ_16( i, *pt_mins ) ) + { + pt_mins++; + flor = Bin_E[i]; + move16(); /*Q7*/ + /* calculate the new step */ + /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ + tmp16 = sub( *pt_mins, i ); + tmpdB = sub( Bin_E[*pt_mins], Bin_E[i] ); + sign_fx = shr( tmpdB, 15 ); /* 0 if positive else -1 */ + ExpdB = sub( norm_s( tmpdB ), 1 ); + tmpdB = abs_s( shl( tmpdB, ExpdB ) ); + ExpInd = norm_s( tmp16 ); + tmp16 = shl( tmp16, ExpInd ); + tmp16 = div_s( tmpdB, tmp16 ); + tmp16 = sub( s_xor( tmp16, sign_fx ), sign_fx ); + step = shr( tmp16, add( sub( ExpdB, ExpInd ), 15 ) ); /* Q7 */ + } - /* subtract the floor */ - S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); - move16(); + /* subtract the floor */ + S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); + move16(); - /* update the floor */ - flor = add( flor, step ); /*Q7*/ + /* update the floor */ + flor = add( flor, step ); /*Q7*/ + } } } @@ -180,6 +216,7 @@ Word16 multi_harm_fx( *cor_strong_limit = 1; move16(); } + test(); if ( LT_32( total_brate, ACELP_9k60 ) || GT_32( total_brate, ACELP_16k40 ) ) { @@ -285,370 +322,64 @@ Word16 multi_harm_fx( Lcor_map_LT_sum = L_deposit_l( 0 ); tmp2 = 0; move16(); - + tmp2_32 = 0; + move32(); cor_strong = 0; move16(); pt1 = cor_map_LT; // Q15 move16(); pt2 = cor_map; move16(); - FOR( i = 0; i < L; i++ ) - { - /* tmp2 += S[i]; */ - tmp2 = add( tmp2, shl( S[i], 1 ) ); /* tmp2 in Q8; max value is 128) */ - - /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ - *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); - move16(); - - /* cor_map_LT_sum += *pt1 */ - Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ - - if ( GT_16( *pt1, 31130 ) /*0.95f.Q15*/ ) - { - cor_strong = 1; - move16(); - } - - pt1++; - pt2++; - } - - IF( ( bwidth == NB ) ) - { - /* cor_map_LT_sum *= 1.53f; */ - /* tmp2 *= 1.53f; */ - Lcor_map_LT_sum = L_shl( Mult_32_16( Lcor_map_LT_sum, 25068 /* 1.53f in Q14 */ ), 1 ); - tmp2 = round_fx( L_mac( L_mult( tmp2, 32767 ), tmp2, 17367 /* 0.53 in Q15 */ ) ); - } - *cor_map_sum = tmp2; - move16(); - - /* final decision about multi-harmonicity */ - harm = 0; - move16(); - test(); - if ( ( L_msu0( Lcor_map_LT_sum, *multi_harm_limit, 64 ) > 0 ) || ( cor_strong != 0 ) ) - { - harm = 1; - move16(); - } - - /*------------------------------------------------------------------* - * updating of the decision threshold - *------------------------------------------------------------------*/ - stemp = add( *multi_harm_limit, THR_CORR_STEP_FX ); - if ( GT_32( Lcor_map_LT_sum, THR_CORR_FX ) ) /* Q15 */ + IF( element_mode != EVS_MONO ) { - /* *multi_harm_limit -= THR_CORR_STEP_FX */ - stemp = sub( *multi_harm_limit, THR_CORR_STEP_FX ); - } - - stemp = s_min( stemp, THR_CORR_MAX_FX ); - *multi_harm_limit = s_max( stemp, THR_CORR_MIN_FX ); - move16(); - - IF( N_mins <= 0 ) - { - set16_fx( old_S, 0, L ); - } - IF( S_map != NULL ) - { - Copy( S, S_map, L ); - } - return harm; -} - - -/* o : frame multi-harmonicity (1-harmonic, 0-not) */ -Word16 multi_harm_ivas_fx( - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ - Word16 *sp_floor, /* o: noise floor estimate Q7 */ - Word16 S_map[] /* o : short-term correlation map Q7 */ -) -{ - Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT / 4], *pt_mins, harm; - Word16 S[L_FFT / 2], flor, step, tmp16, tmp2, Expx2, Expy2; - Word32 tmp2_32; - Word16 corx2, cory2, corxy, cor, cor_map[L_FFT / 2], *pt1, *pt2, cor_strong; - Word32 L_acc; - Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; - Word16 mean_dyn; - - /*------------------------------------------------------------------* - * initialization - *------------------------------------------------------------------*/ - - /* length of the useful part of the spectrum (up to 6.4kHz) */ - L = L_FFT / 2; - move16(); - if ( ( bwidth == NB ) ) - { - /* length of the useful part of the spectrum (up to 3.6kHz) */ - L = 76; - move16(); - } - - Copy( Bin_E, S, L ); - - /*------------------------------------------------------------------* - * searching of spectral maxima and minima - *------------------------------------------------------------------*/ - - pt_mins = ind_mins; - - /* index of the first minimum */ - if ( LT_16( Bin_E[0], Bin_E[1] ) ) - { - *pt_mins++ = 0; - move16(); - } - - FOR( i = 1; i < L - 1; i++ ) - { - /* minimum found */ - test(); - if ( LT_16( Bin_E[i], Bin_E[i - 1] ) && LT_16( Bin_E[i], Bin_E[i + 1] ) ) - { - *pt_mins++ = i; - move16(); - } - } - - /* index of the last minimum */ - IF( LT_16( Bin_E[L - 1], Bin_E[L - 2] ) ) - { - *pt_mins++ = sub( L, 1 ); - move16(); - } - - /* total number of minimas found */ - N_mins = (Word16) ( pt_mins - ind_mins - 1 ); - move16(); - - /*------------------------------------------------------------------* - * calculation of the spectral floor - * subtraction of the spectral floor - *------------------------------------------------------------------*/ - - set16_fx( S, 0, L ); - - IF( N_mins > 0 ) - { - L_acc = L_deposit_l( 0 ); - FOR( i = 0; i < N_mins; ++i ) + FOR( i = 0; i < L; i++ ) { - L_acc = L_mac0( L_acc, Bin_E[ind_mins[i]], 1 ); - } - *sp_floor = extract_l( Mult_32_16( L_acc, div_s( 1, N_mins ) ) ); - move16(); + /* tmp2 += S[i]; */ + tmp2_32 = L_add( tmp2_32, cor_map[i] ); /* tmp2_32 in Q15; max value is 128) */ - set16_fx( S, 0, ind_mins[0] ); - set16_fx( &S[ind_mins[N_mins]], 0, sub( shr( L_FFT, 1 ), ind_mins[N_mins] ) ); + /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ + *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); + move16(); - pt_mins = ind_mins; - flor = 0; - move16(); - step = 0; - move16(); + /* cor_map_LT_sum += *pt1 */ + Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ - FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ ) - { - /* we are at the end of the next minimum */ - IF( EQ_16( i, *pt_mins ) ) + if ( GT_16( *pt1, 31130 ) /*0.95f*/ ) { - pt_mins++; - flor = Bin_E[i]; - move16(); /*Q7*/ - - /* calculate the new step */ - /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/ - - tmp16 = div_s( 1, sub( *pt_mins, i ) ); // Q15 - step = msu_r( L_mult( Bin_E[*pt_mins], tmp16 ), Bin_E[i], tmp16 ); // Q7 (15+7+1-16) + cor_strong = 1; + move16(); } - /* subtract the floor */ - S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 ); - move16(); - - /* update the floor */ - flor = add( flor, step ); /*Q7*/ + pt1++; + pt2++; } + tmp2 = extract_l( L_shr_sat( tmp2_32, 7 ) ); // q15-> q8 } - - /* Calculate the maximum dynamic per band */ - /* since we are processing 40 bins we will use 1/40 in Q15 to find the mean */ - /* mean_dyn = mean(&S[L-40], 40);*/ - L_acc = L_deposit_l( 0 ); - FOR( i = L - 40; i < L; i++ ) - { - L_acc = L_mac( L_acc, S[i], 819 /* 1 / 40 in Q15 */ ); - } - mean_dyn = round_fx( L_acc ); /*Q7*/ - - /*mean_dyn = 0.6f * *st_mean_avr_dyn + 0.4f * mean_dyn;*/ - L_acc = L_mult( 13107 /*0.4f*/, mean_dyn ); /*Q23*/ - L_acc = L_mac( L_acc, 19661 /*0.6f*/, *st_mean_avr_dyn ); /*Q23*/ - mean_dyn = round_fx( L_acc ); /*Q7*/ - - test(); - IF( LT_16( mean_dyn, 1229 ) /*9.6f*/ && *cor_strong_limit != 0 ) - { - *cor_strong_limit = 0; - move16(); - *st_last_sw_dyn = mean_dyn; - move16(); - } - ELSE IF( GT_16( sub( mean_dyn, *st_last_sw_dyn ), 576 ) /*4.5f*/ ) - { - *cor_strong_limit = 1; - move16(); - } - test(); - if ( LT_32( total_brate, ACELP_9k60 ) || GT_32( total_brate, ACELP_16k40 ) ) - { - *cor_strong_limit = 1; - move16(); - } - - *st_mean_avr_dyn = mean_dyn; - move16(); - - /*------------------------------------------------------------------* - * calculation of the correlation map - *------------------------------------------------------------------*/ - - set16_fx( cor_map, 0, L ); - IF( N_mins > 0 ) + ELSE { - Lcorx2 = L_deposit_l( 0 ); - Lcorxy = L_deposit_l( 0 ); - stemp = ind_mins[0]; - move16(); - Lcory2 = L_mult( old_S[stemp], old_S[stemp] ); - k = 1; - move16(); - - FOR( i = add( stemp, 1 ); i <= ind_mins[N_mins]; i++ ) + FOR( i = 0; i < L; i++ ) { - IF( EQ_16( i, ind_mins[k] ) ) - { - /* include the last peak point (new minimum) to the corr. sum */ - Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] ); - - /* calculation of the norm. peak correlation */ - test(); - IF( Lcorx2 != 0 && Lcory2 != 0 ) - { - /* corxy * corxy*/ - tmp16 = sub( norm_l( Lcorxy ), 1 ); - corxy = extract_h( L_shl( Lcorxy, tmp16 ) ); - corxy = mult_r( corxy, corxy ); - /* (corx2 * cory2) */ - Expx2 = norm_l( Lcorx2 ); - Expy2 = norm_l( Lcory2 ); - corx2 = extract_h( L_shl( Lcorx2, Expx2 ) ); - cory2 = extract_h( L_shl( Lcory2, Expy2 ) ); - corx2 = mult_r( corx2, cory2 ); - Expx2 = add( Expy2, Expx2 ); - /* Validate num < den */ - cor = sub( corx2, corxy ); - cor = shr( cor, 15 ); - /* Add 1 to tmp16 & shr by 2 if corxy > corx2 */ - tmp16 = sub( tmp16, cor ); - corxy = shl( corxy, cor ); - corxy = shl( corxy, cor ); - /* cor = corxy * corxy / (corx2 * cory2) */ - corxy = div_s( corxy, corx2 ); - cor = shr_sat( corxy, sub( shl( tmp16, 1 ), Expx2 ) ); /* Q15 */ - } - ELSE - { - cor = 0; - move16(); - } + /* tmp2 += S[i]; */ + tmp2 = add( tmp2, shl( S[i], 1 ) ); /* tmp2 in Q8; max value is 128) */ - /* save the norm. peak correlation in the correlation map */ - FOR( j = ind_mins[k - 1]; j < ind_mins[k]; j++ ) - { - old_S[j] = S[j]; - move16(); - S[j] = shr( cor, 8 ); - move16(); - cor_map[j] = cor; - move16(); - } + /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ + *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); + move16(); - Lcorx2 = L_deposit_l( 0 ); - Lcory2 = L_deposit_l( 0 ); - Lcorxy = L_deposit_l( 0 ); + /* cor_map_LT_sum += *pt1 */ + Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ - k++; + if ( GT_16( *pt1, 31130 ) /*0.95f.Q15*/ ) + { + cor_strong = 1; + move16(); } - Lcorx2 = L_mac_sat( Lcorx2, S[i], S[i] ); - Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] ); - Lcorxy = L_mac_sat( Lcorxy, S[i], old_S[i] ); - } - - Copy( S, old_S, ind_mins[0] ); - Copy( &S[ind_mins[N_mins]], &old_S[ind_mins[N_mins]], sub( L, ind_mins[N_mins] ) ); - } - ELSE - { - *sp_floor = Bin_E[0]; - move16(); - } - *sp_floor = mult( *sp_floor, 14231 /* 1.0f / logf( 10.0f ) in Q15 */ ); - move16(); /* Convert to log10() */ - - /*------------------------------------------------------------------* - * updating of the long-term correlation map - * summation of the long-term correlation map - *------------------------------------------------------------------*/ - - Lcor_map_LT_sum = L_deposit_l( 0 ); - tmp2_32 = 0; - move16(); - cor_strong = 0; - move16(); - pt1 = cor_map_LT; - move16(); - pt2 = cor_map; - move16(); - FOR( i = 0; i < L; i++ ) - { - /* tmp2 += S[i]; */ - tmp2_32 = L_add( tmp2_32, cor_map[i] ); /* tmp2_32 in Q15; max value is 128) */ - - /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */ - *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 ); - move16(); - - /* cor_map_LT_sum += *pt1 */ - Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */ - - if ( GT_16( *pt1, 31130 ) /*0.95f*/ ) - { - cor_strong = 1; - move16(); + pt1++; + pt2++; } - - pt1++; - pt2++; } - tmp2 = extract_l( L_shr_sat( tmp2_32, 7 ) ); // q15-> q8 IF( ( bwidth == NB ) ) { @@ -693,5 +424,6 @@ Word16 multi_harm_ivas_fx( { Copy( S, S_map, L ); } + return harm; } diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 9122be431e58c675afd23259c8c2f78f30d5892e..45e132898b21a395c22f71a0631eb12eb1443a66 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -1032,737 +1032,3 @@ void nelp_encoder_fx( return; } - -void nelp_encoder_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state */ - Word16 *in_fx, /* i : residual signal */ - Word16 *exc_fx, /* o : NELP quantized excitation signal */ - Word16 *qIn1, - Word16 reduce_gains ) -{ - Word16 i, j; - Word16 *ptr_fx = exc_fx; - Word16 lag = 25; /* to cover 25*9 + 31 */ - move16(); - Word16 sqrt_inv_lag = 6554; /* sqrt(1/lag) in Q15 */ - move16(); - Word16 sqrt_inv_lframe_lag = 5885; /* sqrt(1/(L_FRAME-lag*9)) */ - move16(); - Word16 Gains_fx[10], gain_fac_fx; - Word16 iG1_fx, iG2_fx[2]; - Word16 fid; - Word16 fdbck_fx; - Word32 var_dB_fx; - Word32 E1_fx = 0, EL1_fx = 0, EH1_fx = 0, E2_fx = 0, E3_fx = 0, EL2_fx = 0, EH2_fx = 0; - move32(); - move32(); - move32(); - move32(); - move32(); - move32(); - move32(); - Word32 RL_fx = 0, RH_fx = 0; - move32(); - move32(); - Word16 R_fx = 0; - move16(); - Word16 filtRes_fx[L_FRAME]; - Word16 ptr_tmp_fx[L_FRAME]; - - Word16 qE1 = 0, qE2 = 0, qE3 = 0, qEL1 = 0, qEL2 = 0, qEH1 = 0, qEH2 = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - Word16 qIn = 0, qGain = 0, qf = 0, qf1 = 0, qNelpGain = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - Word16 exp1, exp2, tmp1, tmp2; - Word16 f_Noise, etmp, e_Noise; - Word16 max1 = 0; - move16(); - Word32 l_nelp_gain_mem; - Word32 Ltemp = 0, Ltemp1 = 0, L_tmp = 0, L_const_1; - move32(); - move32(); - move32(); - Word16 BP1_ORDER; - Word16 rf_flag; - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - RF_ENC_HANDLE hRF = st_fx->hRF; - - rf_flag = st_fx->rf_mode; - move16(); - - test(); - if ( EQ_16( hSC_VBR->last_nelp_mode, 1 ) && NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - hSC_VBR->last_nelp_mode = 0; - move16(); - } - - qIn = *qIn1; - move16(); - test(); - IF( EQ_16( st_fx->bwidth, NB ) ) - { - IF( hSC_VBR->last_nelp_mode != 1 ) - { - BP1_ORDER = 7; - move16(); - set32_fx( hSC_VBR->bp1_filt_mem_nb_fx, 0, BP1_ORDER * 2 ); - hSC_VBR->qprevGain_fx = 0; - move16(); - } - } - ELSE IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) - { - IF( hSC_VBR->last_nelp_mode != 1 ) - { - BP1_ORDER = 4; - move16(); - set16_fx( hSC_VBR->bp1_filt_mem_wb_fx, 0, i_mult( BP1_ORDER, 2 ) ); - } - } - - IF( NE_16( hSC_VBR->last_nelp_mode, 1 ) ) - { - test(); - IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) - { - set16_fx( hSC_VBR->shape1_filt_mem_fx, 0, 10 ); - set16_fx( hSC_VBR->shape2_filt_mem_fx, 0, 10 ); - set16_fx( hSC_VBR->shape3_filt_mem_fx, 0, 10 ); - set16_fx( hSC_VBR->txlpf1_filt1_mem_fx, 0, 10 ); - set16_fx( hSC_VBR->txlpf1_filt2_mem_fx, 0, 10 ); - set16_fx( hSC_VBR->txhpf1_filt1_mem_fx, 0, 10 ); - set16_fx( hSC_VBR->txhpf1_filt2_mem_fx, 0, 10 ); - hSC_VBR->qprevIn_fx = 0; - move16(); - hSC_VBR->qprevGain_fx = 0; - move16(); - } - } - - /* Start Unvoiced/NELP Processing */ - test(); - IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) - { - qE1 = qIn; - move16(); - E1_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - E1_fx = L_mac0_sat( E1_fx, in_fx[i], in_fx[i] ); /*Q(qE1+qE1) */ - } - - qE1 = shl( qE1, 1 ); - - qf = qIn; - move16(); - Scale_sig( hSC_VBR->txlpf1_filt1_mem_fx, 10, ( qf - hSC_VBR->qprevIn_fx ) ); - pz_filter_sp_fx( txlpf1_num_coef_fx, txlpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txlpf1_filt1_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ - - qEL1 = qf; - move16(); - EL1_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - EL1_fx = L_mac0_sat( EL1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qIn) */ - } - qEL1 = shl( qEL1, 1 ); - - qf = qIn; - move16(); - Scale_sig( hSC_VBR->txhpf1_filt1_mem_fx, 10, qf - hSC_VBR->qprevIn_fx ); - pz_filter_sp_fx( txhpf1_num_coef_fx, txhpf1_den_coef_fx, in_fx, filtRes_fx, hSC_VBR->txhpf1_filt1_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ - hSC_VBR->qprevIn_fx = qf; - move16(); - - qEH1 = qf; - move16(); - EH1_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - EH1_fx = L_mac0_sat( EH1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH1) */ - } - qEH1 = shl( qEH1, 1 ); - move16(); - } - - qGain = qIn; - move16(); - qGain = shl( qGain, 1 ); - - FOR( i = 0; i < 9; i++ ) - { - Ltemp = L_deposit_l( 0 ); - FOR( j = (Word16) ( i * lag ); j < (Word16) ( ( i + 1 ) * lag ); j++ ) - { - Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ - } - - /*Gains[i] = (float) sqrt(Gains[i]/lag); */ - IF( Ltemp != 0 ) - { - exp1 = norm_l( Ltemp ); - tmp1 = extract_h( L_shl( Ltemp, exp1 ) ); /*2*qGain+exp1-16 */ - exp1 = sub( exp1, 30 - qGain ); /* */ - - tmp1 = div_s( 16384, tmp1 ); /*14-2*qGain-exp1+16 */ - L_tmp = L_deposit_h( tmp1 ); - L_tmp = Isqrt_lc( L_tmp, &exp1 ); - L_tmp = Mult_32_16( L_tmp, sqrt_inv_lag ); - Ltemp = L_shl_sat( L_tmp, sub( exp1, 12 ) ); /*Q3 */ - } - Gains_fx[i] = round_fx_sat( Ltemp ); - move16(); - } - - - Ltemp = L_deposit_l( 0 ); - FOR( j = i_mult( i, lag ); j < L_FRAME; j++ ) - { - Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ - } - - /*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */ - IF( Ltemp != 0 ) - { - exp1 = norm_l( Ltemp ); - tmp1 = extract_h( L_shl( Ltemp, exp1 ) ); - exp1 = sub( exp1, 30 - qGain ); /* */ - - tmp1 = div_s( 16384, tmp1 ); - L_tmp = L_deposit_h( tmp1 ); - L_tmp = Isqrt_lc( L_tmp, &exp1 ); - L_tmp = Mult_32_16( L_tmp, sqrt_inv_lframe_lag ); - Ltemp = L_shl_sat( L_tmp, sub( exp1, 12 ) ); - } - - Gains_fx[i] = round_fx_sat( Ltemp ); - move16(); - - IF( EQ_16( reduce_gains, 1 ) ) - { - FOR( i = 0; i < 10; i++ ) - { - Gains_fx[i] = mult( Gains_fx[i], 19661 ); - move16(); - } - } - - - qGain = 3; - move16(); - IF( NE_16( hSC_VBR->last_nelp_mode, 1 ) ) /* if prev frame was not NELP then init mem*/ - { - hSC_VBR->nelp_gain_mem_fx = Gains_fx[0]; - move16(); - qNelpGain = qGain; - move16(); - } - - /* tmp = (float) (20.0 * (log10 (Gains[0]) - log10 (st->nelp_gain_mem) ) ); */ - /* var_dB = tmp * tmp; */ - L_tmp = L_deposit_l( Gains_fx[0] ); - L_tmp = L_max( L_tmp, 1 ); - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ - exp2 = sub( sub( 30, exp2 ), qGain ); - tmp1 = Log2_norm_lc( L_tmp ); - Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*log(2) in Q13 format = Q0 format */ - /*tmp1 = round_fx(L_shl(Ltemp,12)); Q12 */ - - L_tmp = L_deposit_l( hSC_VBR->nelp_gain_mem_fx ); /*Q0 */ - L_tmp = L_max( L_tmp, 1 ); - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ - exp2 = sub( sub( 30, exp2 ), qNelpGain ); - tmp2 = Log2_norm_lc( L_tmp ); - Ltemp1 = Mpy_32_16( exp2, tmp2, 9864 ); /*log(2) in Q13 format = Q0 format */ - Ltemp1 = L_sub( Ltemp, Ltemp1 ); /*Q16 */ - Ltemp = Mult_32_16( Ltemp1, 20480 ); /*Q11 (20 in Q10) */ - L_tmp = L_shl( Ltemp, 12 ); /*Q23 */ - var_dB_fx = Mult_32_32( L_tmp, L_tmp ); /*Q15 */ - - FOR( i = 1; i < 10; i++ ) - { - L_tmp = L_deposit_l( Gains_fx[i] ); - L_tmp = L_max( L_tmp, 1 ); - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ - exp2 = sub( sub( 30, exp2 ), qGain ); - tmp1 = Log2_norm_lc( L_tmp ); - Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*log(2) in Q13 format = Q0 format */ - - L_tmp = L_deposit_l( Gains_fx[i - 1] ); /*Q0 */ - L_tmp = L_max( L_tmp, 1 ); - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ - exp2 = sub( sub( 30, exp2 ), qGain ); - tmp2 = Log2_norm_lc( L_tmp ); - Ltemp1 = Mpy_32_16( exp2, tmp2, 9864 ); /*log(2) in Q13 format = Q0 format */ - Ltemp1 = L_sub( Ltemp, Ltemp1 ); /*Q16 */ - Ltemp = Mult_32_16( Ltemp1, 20480 ); /*Q11 (20 in Q10) */ - L_tmp = L_shl( Ltemp, 12 ); /*Q23 */ - L_tmp = Mult_32_32( L_tmp, L_tmp ); /*Q15 */ - var_dB_fx = L_add( L_tmp, var_dB_fx ); /*Q15 */ - } - - IF( NE_16( hSC_VBR->last_nelp_mode, 1 ) ) - { - /*var_dB *= 0.111f; */ - var_dB_fx = Mult_32_16( var_dB_fx, 3637 ); /*0.111 in Q15 */ - } - ELSE - { - /*var_dB *= 0.1f; */ - var_dB_fx = Mult_32_16( var_dB_fx, 3277 ); /*0.1 in Q15 */ - } - - max1 = 0; - move16(); - FOR( i = 0; i < 10; i++ ) - { - max1 = s_max( max1, abs_s( Gains_fx[i] ) ); - } - - qf = norm_s( max1 ); - test(); - IF( ( qf == 0 ) && ( max1 == 0 ) ) - { - qf = 15; - move16(); - } - qf = sub( qf, 1 ); - qGain = add( qGain, qf ); - - Scale_sig( Gains_fx, 10, qf ); - - L_tmp = L_sub( var_dB_fx, 655360 ); /* 20 in Q15 */ - Ltemp = L_shr_r( L_tmp, 2 ); /*Q15 */ - { - /*exp = pow(2, x*log2(e)) */ - L_tmp = Mult_32_16( Ltemp, 23637 ); /*15 + 14 -15 ->Q14 */ - L_tmp = L_shl( L_tmp, 2 ); /*Q16 */ - f_Noise = L_Extract_lc( L_tmp, &e_Noise ); /*Q16 */ - etmp = extract_l( Pow2( 14, f_Noise ) ); /* Put 14 as exponent */ - e_Noise = sub( e_Noise, 14 ); /* Retreive exponent of etmp */ - - - IF( e_Noise > 0 ) - { - L_tmp = L_shl_sat( etmp, e_Noise ); /* Result in Q30 */ - L_tmp = L_add_sat( 1, L_tmp ); - - - exp1 = norm_l( L_tmp ); - tmp1 = extract_h( L_shl( L_tmp, exp1 ) ); /*exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(exp1-16)-> 30+15-exp1 */ - fdbck_fx = mult( 26870, tmp1 ); /*45-exp1+15-15=>45-exp1 */ - fdbck_fx = shr_r( fdbck_fx, 14 ); - exp1 = sub( 31, exp1 ); - } - ELSE - { - L_tmp = L_shl( etmp, add( e_Noise, 14 ) ); /* Result in Q30 */ - L_tmp = L_add( 16384, L_tmp ); - - exp1 = norm_l( L_tmp ); - tmp1 = extract_h( L_shl( L_tmp, exp1 ) ); /*14+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(14+exp1-16)-> 16+15-exp1 */ - fdbck_fx = mult( 26870, tmp1 ); /*31-exp1+15-15=>31-exp1 */ - exp1 = sub( 31, exp1 ); - } - } - - IF( EQ_16( exp1, 31 ) ) - { - L_const_1 = 0x7fffffff; - move32(); - } - ELSE - { - L_const_1 = L_shl( 1, exp1 ); - } - - l_nelp_gain_mem = L_deposit_l( hSC_VBR->nelp_gain_mem_fx ); - IF( NE_16( qNelpGain, qGain ) ) - { - l_nelp_gain_mem = L_shl( l_nelp_gain_mem, sub( qGain, qNelpGain ) ); - } - - FOR( i = 0; i < 10; i++ ) - { - /*Gains[i] = (float)((1.0f - fdbck) * Gains[i] + fdbck * st->nelp_gain_mem); */ - L_tmp = L_sub( L_const_1, L_deposit_l( fdbck_fx ) ); /*31-exp1 */ - L_tmp = Mult_32_16( L_tmp, Gains_fx[i] ); /*exp1+qGain-15=>exp1-15+qGain */ - Ltemp1 = Mult_32_16( l_nelp_gain_mem, fdbck_fx ); /*exp1+qGain-15 */ - L_tmp = L_add( L_tmp, Ltemp1 ); - L_tmp = L_shr_r( L_tmp, ( exp1 - 15 ) ); - Gains_fx[i] = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); - move16(); - l_nelp_gain_mem = L_tmp; - } - - hSC_VBR->nelp_gain_mem_fx = round_fx( L_shl( l_nelp_gain_mem, 16 ) ); - move16(); - - Scale_sig( &hSC_VBR->nelp_gain_mem_fx, 1, -qGain ); - Scale_sig( Gains_fx, 10, -qGain ); - qGain = 0; - move16(); - - quantize_uvg_fx( Gains_fx, &iG1_fx, iG2_fx, Gains_fx, st_fx->bwidth ); - - IF( EQ_16( rf_flag, 1 ) ) - { - hRF->rf_indx_nelp_iG1[0] = iG1_fx; - move16(); - hRF->rf_indx_nelp_iG2[0][0] = iG2_fx[0]; - move16(); - hRF->rf_indx_nelp_iG2[0][1] = iG2_fx[1]; - move16(); - } - ELSE - { - push_indice( hBstr, IND_IG1, iG1_fx, 5 ); - push_indice( hBstr, IND_IG2A, iG2_fx[0], 6 ); - push_indice( hBstr, IND_IG2B, iG2_fx[1], 6 ); - } - - test(); - IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) - { - gain_fac_fx = 19005; - move16(); /* 1.16f in Q14 */ - } - ELSE - { - gain_fac_fx = 22446; - move16(); /* 1.37f in Q14 */ - } - - /* Normalize Gains_fx[10] with headroom 4 */ - /* This fills up qGain with some new value */ - normalize_arr( Gains_fx, &qGain, 10, 4 ); - - generate_nelp_excitation_fx( &( hSC_VBR->nelp_enc_seed ), Gains_fx, ptr_fx, gain_fac_fx ); - test(); - IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) - { - BP1_ORDER = 4; - move16(); - Scale_sig( hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER * 2, qGain - hSC_VBR->qprevGain_fx ); /*qf-qAdj */ - pz_filter_sp_fx( bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_wb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, 2 ); - Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); - } - ELSE IF( EQ_16( st_fx->bwidth, NB ) ) - { - BP1_ORDER = 7; - move16(); - Scale_sig32( hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER * 2, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_dp_fx( bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr_fx, ptr_tmp_fx, hSC_VBR->bp1_filt_mem_nb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, ( sub( 16, BP1_COEF_NB_QF_ORDER7 ) ) ); - Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); - - Scale_sig( ptr_fx, L_FRAME, -1 ); /* bring exc to qgain-1 */ - *qIn1 = sub( qGain, 1 ); /* use this temp only in the parent */ - } - - E3_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - E3_fx = L_mac_sat( E3_fx, ptr_fx[i], ptr_fx[i] ); /*Q1 */ - } - qE3 = add( shl( qGain, 1 ), 1 ); - - test(); - IF( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) - { - Scale_sig( hSC_VBR->shape1_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape1_num_coef_fx, shape1_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape1_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); - - qf = qGain; - move16(); - E2_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - Ltemp = L_mult0( ptr_fx[i], ptr_fx[i] ); /*Q(2*qE2+1) */ - Ltemp = L_shr_r( Ltemp, 4 ); - E2_fx = L_add( E2_fx, Ltemp ); - } - qE2 = sub( shl( qf, 1 ), 4 ); - - test(); - IF( E1_fx == 0 ) - { - R_fx = 0; - move16(); - } - ELSE IF( ( E2_fx == 0 ) && ( E1_fx != 0 ) ) - { - exp1 = norm_l( E1_fx ); - tmp1 = extract_h( L_shl( E1_fx, exp1 ) ); /*qE1+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(qE1+exp1-16)-> 30-qE1-exp1 */ - exp1 = sub( exp1, 30 - qE1 ); - - L_tmp = L_deposit_h( tmp1 ); - L_tmp = Isqrt_lc( L_tmp, &exp1 ); - Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); - R_fx = round_fx( Ltemp ); - } - ELSE - { - exp1 = norm_l( E1_fx ); - tmp1 = extract_h( L_shl( E1_fx, exp1 ) ); /*qE1+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(qE1+exp1-16)-> 30-qE1-exp1 */ - L_tmp = Mult_32_16( E2_fx, tmp1 ); /*qE2+30-qE1-exp1-15=>15+qE2-qE1-exp1 */ - - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qE2-qE1-exp1+exp2 */ - exp2 = add( 15, add( sub( sub( qE2, qE1 ), exp1 ), exp2 ) ); - L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31+exp2) */ - R_fx = round_fx( L_tmp ); - exp1 = sub( 8, exp2 ); - } - - FOR( i = 0; i < L_FRAME; i++ ) - { - Ltemp = L_mult0( R_fx, ptr_fx[i] ); - Ltemp = L_shr_r( Ltemp, exp1 ); - filtRes_fx[i] = round_fx_sat( L_shl_sat( Ltemp, 16 ) ); - move16(); - } - - qf1 = qGain; - move16(); - Scale_sig( hSC_VBR->txlpf1_filt2_mem_fx, 10, ( qf1 - hSC_VBR->qprevGain_fx ) ); - - pz_filter_sp_fx( txlpf1_num_coef_fx, txlpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txlpf1_filt2_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ - Copy( ptr_tmp_fx, filtRes_fx, L_FRAME ); - - qEL2 = qf1; - move16(); - EL2_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - EL2_fx = L_mac0_sat( EL2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEL2) */ - } - qEL2 = shl( qEL2, 1 ); - - FOR( i = 0; i < L_FRAME; i++ ) - { - Ltemp = L_mult0( R_fx, ptr_fx[i] ); - Ltemp = L_shr_r( Ltemp, exp1 ); - filtRes_fx[i] = round_fx_sat( L_shl_sat( Ltemp, 16 ) ); - move16(); - } - - qf = qGain; - move16(); - Scale_sig( hSC_VBR->txhpf1_filt2_mem_fx, 10, ( qf - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( txhpf1_num_coef_fx, txhpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, hSC_VBR->txhpf1_filt2_mem_fx, 10, 10, L_FRAME, 3 ); /*1 = (16-qformat of shape1 cofficient) */ - - Copy( ptr_tmp_fx, filtRes_fx, L_FRAME ); - - qEH2 = qf; - move16(); - EH2_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - EH2_fx = L_mac0_sat( EH2_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH2) */ - } - qEH2 = shl( qEH2, 1 ); - IF( EL2_fx == 0 ) - { - exp2 = norm_l( EL1_fx ); - L_tmp = L_shl( EL1_fx, exp2 ); - exp2 = sub( sub( 30, exp2 ), qEL1 ); - tmp1 = Log2_norm_lc( L_tmp ); - Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q15 format = Q0 format */ - tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ - RL_fx = L_mult0( tmp1, 10 ); - } - ELSE - { - exp1 = norm_l( EL2_fx ); - tmp1 = extract_h( L_shl( EL2_fx, exp1 ) ); /*qEL2+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(qEL2+exp1-16)-> 30-qEL2-exp1 */ - L_tmp = Mult_32_16( EL1_fx, tmp1 ); /*qEL1+30-qEL2-exp1-15=>15+qE1-qEL2-exp1 */ - - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qEL1-qEL2-exp1+exp2 */ - exp2 = sub( 30, add( sub( sub( add( 30, qEL1 ), qEL2 ), exp1 ), exp2 ) ); - tmp1 = Log2_norm_lc( L_tmp ); - Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q15 format = Q0 format */ - tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ - RL_fx = L_mult0( tmp1, 10 ); - } - - IF( EH2_fx == 0 ) - { - exp2 = norm_l( EH2_fx ); - L_tmp = L_shl( EH2_fx, exp2 ); - exp2 = sub( sub( 30, exp2 ), qEH2 ); - tmp1 = Log2_norm_lc( L_tmp ); - Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q13 format = Q0 format */ - tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ - RH_fx = L_mult0( tmp1, 10 ); - } - ELSE - { - exp1 = norm_l( EH2_fx ); - tmp1 = extract_h( L_shl( EH2_fx, exp1 ) ); /*qEH2+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(qEH2+exp1-16)-> 30-qEH2-exp1 */ - L_tmp = Mult_32_16( EH1_fx, tmp1 ); /*15+qEH1-qEH2-exp1 */ - - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qEH1-qEH2-exp1+exp2 */ - exp2 = sub( 30, add( 30, add( sub( sub( qEH1, qEH2 ), exp1 ), exp2 ) ) ); - tmp1 = Log2_norm_lc( L_tmp ); - Ltemp = Mpy_32_16( exp2, tmp1, 9864 ); /*10*log(2) in Q13 format = Q0 format */ - tmp1 = round_fx_sat( L_shl_sat( Ltemp, 12 ) ); /* Q12 */ - RH_fx = L_mult0( tmp1, 10 ); - } - - fid = 0; - move16(); - IF( LT_32( RL_fx, -12288 ) ) /* -3 in Q12 */ - { - fid = 1; - move16(); - } - ELSE IF( LT_32( RH_fx, -12288 ) ) /* -3 in Q12 */ - { - fid = 2; - move16(); - } - - IF( rf_flag == 0 ) - { - - SWITCH( fid ) - { - case 1: - /* Update other filter memory */ - Scale_sig( hSC_VBR->shape3_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - - /* filter the residual to desired shape */ - Scale_sig( hSC_VBR->shape2_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); - - BREAK; - case 2: - /* Update other filter memory */ - Scale_sig( hSC_VBR->shape2_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - - /* filter the residual to desired shape */ - Scale_sig( hSC_VBR->shape3_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, ptr_tmp_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - - Copy( ptr_tmp_fx, ptr_fx, L_FRAME ); - - BREAK; - default: - Scale_sig( hSC_VBR->shape2_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape2_num_coef_fx, shape2_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape2_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - - Scale_sig( hSC_VBR->shape3_filt_mem_fx, 10, ( qGain - hSC_VBR->qprevGain_fx ) ); - pz_filter_sp_fx( shape3_num_coef_fx, shape3_den_coef_fx, ptr_fx, filtRes_fx, hSC_VBR->shape3_filt_mem_fx, 10, 10, L_FRAME, 1 ); /*1 = (16-qformat of shape1 cofficient) */ - - BREAK; - } - - qE2 = qGain; - move16(); - - E2_fx = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - Ltemp = L_mult0( ptr_fx[i], ptr_fx[i] ); /*Q(2*qE2+1) */ - Ltemp = L_shr_r( Ltemp, 4 ); - E2_fx = L_add( E2_fx, Ltemp ); - } - qE2 = sub( shl( qE2, 1 ), 4 ); - - test(); - IF( E3_fx == 0 ) - { - R_fx = 0; - move16(); - } - ELSE IF( ( E2_fx == 0 ) && ( E3_fx != 0 ) ) - { - exp1 = norm_l( E3_fx ); - tmp1 = extract_h( L_shl( E3_fx, exp1 ) ); /*qE3+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(qE3+exp1-16)-> 30-qE3-exp1 */ - exp1 = sub( exp1, 30 - qE3 ); - - L_tmp = L_deposit_h( tmp1 ); - L_tmp = Isqrt_lc( L_tmp, &exp1 ); - Ltemp = L_shl( L_tmp, sub( exp1, 12 ) ); - R_fx = round_fx( Ltemp ); - } - ELSE - { - exp1 = norm_l( E3_fx ); - tmp1 = extract_h( L_shl( E3_fx, exp1 ) ); /*qE3+exp1-16 */ - tmp1 = div_s( 16384, tmp1 ); /*14-(qE3+exp1-16)-> 30-qE3-exp1 */ - L_tmp = Mult_32_16( E2_fx, tmp1 ); /*qE2+30-qE3-exp1-15=>15+qE2-qE3-exp1 */ - - exp2 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp2 ); /*15+qE2-qE3-exp1+exp2 */ - exp2 = sub( 30, add( sub( sub( add( 15, qE2 ), qE3 ), exp1 ), exp2 ) ); - L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31+exp2) */ - R_fx = round_fx( L_tmp ); - exp1 = sub( sub( sub( 31, exp2 ), 16 ), 7 ); - } - - FOR( i = 0; i < L_FRAME; i++ ) - { - L_tmp = L_mult0( R_fx, ptr_fx[i] ); - L_tmp = L_shr_r( L_tmp, exp1 + 1 ); - ptr_fx[i] = round_fx( L_shl( L_tmp, 16 ) ); - move16(); - } - *qIn1 = sub( qGain, 1 ); - move16(); - } - - IF( EQ_16( rf_flag, 1 ) ) - { - hRF->rf_indx_nelp_fid[0] = fid; - move16(); - } - ELSE - { - push_indice( hBstr, IND_NELP_FID, fid, 2 ); - } - } - - hSC_VBR->qprevGain_fx = qGain; - move16(); - - IF( rf_flag == 0 ) - { - FOR( i = 0; i < L_FRAME; i++ ) - { - exc_fx[i] = ptr_fx[i]; - move16(); - } - } - - return; -} diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 41078054cea37891352a3551c8538cc8db507a13..ff6784c4e17bd0de3ca5515a6fe7d561510f36e1 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -62,10 +62,11 @@ * y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) *-----------------------------------------------------------------*/ -Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ - Word16 x, /* i : Qx x(n) */ - Word16 y, /* i : Qx y(n-1) */ - Word16 alpha /*i : Q15 scaling of driving x(n) */ +/* o : Qx y(n) */ +Word16 noise_est_AR1_Qx( + Word16 x, /* i : Qx x(n) */ + Word16 y, /* i : Qx y(n-1) */ + Word16 alpha /*i : Q15 scaling of driving x(n) */ ) { Word16 alpham1; @@ -75,10 +76,11 @@ Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ return mac_r( L_mult( y, alpham1 ), x, alpha ); } -Word32 noise_est_AR1_Qx_32( /* o : Qx y(n) */ - Word32 x, /* i : Qx x(n) */ - Word32 y, /* i : Qx y(n-1) */ - Word32 alpha /*i : Q15 scaling of driving x(n) */ +/* o : Qx y(n) */ +Word32 noise_est_AR1_Qx_32( + Word32 x, /* i : Qx x(n) */ + Word32 y, /* i : Qx y(n-1) */ + Word32 alpha /*i : Q15 scaling of driving x(n) */ ) { Word32 alpham1; @@ -89,6 +91,7 @@ Word32 noise_est_AR1_Qx_32( /* o : Qx y(n) */ return Madd_32_32( Mpy_32_32( y, alpham1 ), x, alpha ); } + /*-----------------------------------------------------------------* * noise_est_ln_q8_fx() * @@ -126,12 +129,13 @@ static Word16 noise_est_ln_q8_fx( * *-----------------------------------------------------------------*/ -static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ - Word16 eps_num_h, /* num high ,*/ - Word16 eps_num_l, /* num low (signed) ,*/ - Word16 eps_den_h, /* den low */ - Word16 eps_den_l, /* den low (signed),*/ - Word16 q_out /* range 15...0 , tested with 11 and 12 */ +/* o: eps_num/eps_den in q_out */ +static Word32 eps_quota_fx( + Word16 eps_num_h, /* num high ,*/ + Word16 eps_num_l, /* num low (signed) ,*/ + Word16 eps_den_h, /* den low */ + Word16 eps_den_l, /* den low (signed),*/ + Word16 q_out /* range 15...0 , tested with 11 and 12 */ ) { Word32 L_tmp_num, L_tmp_den; @@ -139,7 +143,6 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out Word16 m_num, m_den; Word16 num_shift; - L_tmp_num = L_Comp( eps_num_h, eps_num_l ); L_tmp_den = L_Comp( eps_den_h, eps_den_l ); @@ -166,11 +169,13 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out return L_shr( m_num, num_shift ); } + /*-----------------------------------------------------------------* * noise_est_init_fx() * * Initialization of Noise estimator *-----------------------------------------------------------------*/ + void noise_est_init_fx( NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */ ) @@ -385,6 +390,8 @@ void noise_est_init_ivas_fx( return; } + + /*-----------------------------------------------------------------* * noise_est_pre_fx() * @@ -432,7 +439,6 @@ void noise_est_pre_fx( hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 ); move16(); /* 20 = .08 in Q8 */ - /* Could even be higher but it also delays first entry to DTX */ IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) ) { @@ -611,6 +617,8 @@ void noise_est_pre_32fx( return; } + + /*==================================================================================*/ /* FUNCTION : noise_est_down_fx() */ /*----------------------------------------------------------------------------------*/ @@ -638,7 +646,6 @@ void noise_est_pre_32fx( /* _ (Word32[]) tmpN_he1 : temporary noise update 1 Q_new+QSCALE */ /*----------------------------------------------------------------------------------*/ - void noise_est_down_fx( const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ Word32 bckr[], /* i/o: per band background noise energy estimate */ @@ -650,7 +657,7 @@ void noise_est_down_fx( Word16 Etot, /* i : Energy of current frame */ Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, + const Word16 Q_new, const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ ) @@ -689,6 +696,7 @@ void noise_est_down_fx( Ltmp = Mpy_32_16( e_Noise, f_Noise, LG10 ); *totalNoise = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/ move16(); + /*-----------------------------------------------------------------* * Average energy per frame for each frequency band *-----------------------------------------------------------------*/ @@ -836,6 +844,7 @@ void noise_est_down_ivas_fx( /*-----------------------------------------------------------------* * Background noise energy update *-----------------------------------------------------------------*/ + FOR( i = 0; i < NB_BANDS; i++ ) { /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */ @@ -896,9 +905,11 @@ void noise_est_down_ivas_fx( move16(); move16(); move16(); + /*------------------------------------------------------------------* * Energy variation update *------------------------------------------------------------------*/ + /*Etot_v = (float) fabs(*Etot_last - Etot);*/ L_Etot_v = L_abs( L_sub( L_Etot_last, L_Etot ) ); /* Q24 */ @@ -914,11 +925,13 @@ void noise_est_down_ivas_fx( return; } + /*-----------------------------------------------------------------* * noise_est_fx() * * Noise energy estimation (noise energy is updated in case of noise-only frame) *-----------------------------------------------------------------*/ + void noise_est_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ @@ -995,6 +1008,7 @@ void noise_est_fx( /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ + vad_bwidth_fx = st_fx->input_bwidth; move16(); @@ -1105,7 +1119,8 @@ void noise_est_fx( { i = 0; move16(); - *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, + test(); + *loc_harm = multi_harm_fx( EVS_MONO, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); move16(); } @@ -1157,7 +1172,6 @@ void noise_est_fx( } Lsum_den = L_shr( Lsum_den, tmpExp ); - /* calculation of spectral diversity */ /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ spec_div = 0; @@ -1219,7 +1233,6 @@ void noise_est_fx( /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp ); - nchar_thr = THR_NCHAR_WB_FX; move16(); /* 1.0 Q11 */ if ( vad_bwidth_fx == NB ) @@ -1258,6 +1271,7 @@ void noise_est_fx( /*if( alpha > 0.999f { alpha = 0.999f;} */ alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */ + /*--------------------------------------------------------------* * during significant attacks, replace the LT energy by the * current energy this will cause non_sta2 failures to occur in @@ -1369,6 +1383,7 @@ void noise_est_fx( move16(); } } + test(); IF( GE_16( i, 2 ) && LE_16( i, 16 ) ) { @@ -1437,11 +1452,15 @@ void noise_est_fx( test(); *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); move16(); + + test(); + test(); if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) ) { *st_harm_cor_cnt = 0; move16(); } + test(); test(); test(); @@ -1452,6 +1471,7 @@ void noise_est_fx( { *st_harm_cor_cnt = 1; } + test(); test(); if ( GT_16( *st_harm_cor_cnt, 1 ) && @@ -1465,10 +1485,10 @@ void noise_est_fx( move16(); } - /*-----------------------------------------------------------------* * Energy based pause length counter *-----------------------------------------------------------------*/ + test(); IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) ) { @@ -1486,6 +1506,7 @@ void noise_est_fx( move16(); } } + if ( *bg_cnt >= 0 ) { *bg_cnt = add( *bg_cnt, 1 ); @@ -1506,7 +1527,6 @@ void noise_est_fx( epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ - /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ alpha = 4915; move16(); /*0.15 in Q15 */ @@ -1531,7 +1551,6 @@ void noise_est_fx( /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */ - /*-----------------------------------------------------------------* * Linear predition efficiency 2 to 16 order *-----------------------------------------------------------------*/ @@ -1546,7 +1565,6 @@ void noise_est_fx( epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ - /* if (epsP_2_16 > st->epsP_2_16_lp){ st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp; } else { @@ -1568,7 +1586,6 @@ void noise_est_fx( move16(); epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx ); - /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2; } else { @@ -1639,7 +1656,6 @@ void noise_est_fx( hNoiseEst->low_tn_track_cnt = tmp; move16(); - /* update of the long-term non-stationarity measure (between 0 and 1) */ /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) { st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1; @@ -1657,10 +1673,10 @@ void noise_est_fx( hNoiseEst->act_pred_fx = tmp; move16(); - /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ + Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); cor_tmp = mac_r_sat( Ltmp, corr_shift, MAX_16 ); @@ -1724,17 +1740,14 @@ void noise_est_fx( } hNoiseEst->aEn = add( hNoiseEst->aEn, tmp ); - hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 ); hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 ); /* Additional NNE detectors */ - /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */ - /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ /* Q15 Q12 Q12 */ comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */ @@ -1788,7 +1801,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); @@ -1798,7 +1810,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); @@ -1817,7 +1828,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */ SD_1 = 0; move16(); @@ -1917,7 +1927,6 @@ void noise_est_fx( tmp = s_and( tmp, SD_1_inv ); PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) ); - /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */ NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 ); @@ -1931,7 +1940,6 @@ void noise_est_fx( move16(); } - /* When the signal dynamics is high and the energy is close to the background estimate */ /* sd1_bgd = (st->sign_dyn_lp > 15) && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 @@ -2182,11 +2190,13 @@ void noise_est_fx( return; } + /*-----------------------------------------------------------------* * noise_est_fx() * * Noise energy estimation (noise energy is updated in case of noise-only frame) *-----------------------------------------------------------------*/ + void noise_est_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 old_pitch1, /* i : previous frame OL pitch[1] */ @@ -2279,10 +2289,10 @@ void noise_est_ivas_fx( /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ + vad_bwidth_fx = st_fx->input_bwidth; move16(); - /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ temp = 0; move64(); @@ -2336,6 +2346,7 @@ void noise_est_ivas_fx( } } } + /*-----------------------------------------------------------------* * Set the threshold for eps & non_sta based on input sampling rate * The reason is that in case of 8kHz sampling input, there is nothing @@ -2389,25 +2400,26 @@ void noise_est_ivas_fx( move16(); /* low correlation -> probably inactive signal */ } - /* Update */ - /*-----------------------------------------------------------------* * Multi-harmonic analysis *-----------------------------------------------------------------*/ + IF( hFrontVad == NULL ) { IF( st_fx->hSpMusClas != NULL ) { i = 0; move16(); - *loc_harm = multi_harm_ivas_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, - st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); + *loc_harm = multi_harm_fx( st_fx->element_mode, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate, + st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map ); move16(); } } + /*-----------------------------------------------------------------* * Detection of frames with non-stationary spectral content *-----------------------------------------------------------------*/ + /* weighted sum of spectral changes per critical bands */ w_sum_num = 0; move64(); @@ -2419,6 +2431,7 @@ void noise_est_ivas_fx( Word16 exp, exp2; w_sum_den = 0; move64(); + FOR( i = 10; i <= st_fx->max_band; i++ ) { Lnum = L_max( *pt1, *pt2 ); @@ -2431,7 +2444,6 @@ void noise_est_ivas_fx( num = extract_h( Mpy_32_32( Lnum, Lnum ) ); // 2*(q_fr_bands+exp)-31-16 ExpNum = add( sub( shl( q_fr_bands, 1 ), 47 ), shl( exp, 1 ) ); - den = E_MIN_FXQ31 >> 8; // 29360, 0.0035f in Q23 ExpDen = Q23; move32(); @@ -2596,6 +2608,7 @@ void noise_est_ivas_fx( /*if( alpha > 0.999f { alpha = 0.999f;} */ alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha */ + /*--------------------------------------------------------------* * during significant attacks, replace the LT energy by the * current energy this will cause non_sta2 failures to occur in @@ -2770,7 +2783,8 @@ void noise_est_ivas_fx( } } - } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ + } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */ + *non_staX = L_shl( *non_staX, 12 ); // Q20 move32(); IF( LT_16( Etot, -1280 /* -5.0f in Q8 */ ) ) @@ -2804,6 +2818,7 @@ void noise_est_ivas_fx( Word16 exp_tmp; st_E_var_est_fx = BASOP_Util_Add_Mant32Exp( hNoiseEst->L_Etot_sq_st_est_fx, Q15, L_negate( Mpy_32_32( hNoiseEst->L_Etot_st_est_fx, hNoiseEst->L_Etot_st_est_fx ) ), Q16, &exp_tmp ); // exp(exp_tmp) + /*-----------------------------------------------------------------* * Count frames since last correlation or harmonic event *-----------------------------------------------------------------*/ @@ -2813,6 +2828,7 @@ void noise_est_ivas_fx( *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 ); move16(); + test(); test(); if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_32( Ltmp, 1825361101 /* 0.85 in Q31 */ ) ) ) ) @@ -2831,6 +2847,7 @@ void noise_est_ivas_fx( *st_harm_cor_cnt = 1; move16(); } + test(); test(); IF( GT_16( *st_harm_cor_cnt, 1 ) && GT_16( Etot, 7680 /* 30.0f in Q8 */ ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( st_E_var_est_fx, exp_tmp, 524288 /* 8.0f in Q16 */, Q15 ), 1 ) ) @@ -2840,7 +2857,6 @@ void noise_est_ivas_fx( move16(); } - /*-----------------------------------------------------------------* * Energy based pause length counter *-----------------------------------------------------------------*/ @@ -2993,7 +3009,6 @@ void noise_est_ivas_fx( hNoiseEst->lt_Ellp_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_Ellp_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8 move16(); - /* if (st->harm_cor_cnt == 0) { st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev; } else { @@ -3047,6 +3062,7 @@ void noise_est_ivas_fx( /*-----------------------------------------------------------------* * Background noise adaptation enable flag *-----------------------------------------------------------------*/ + /* if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) && ( ( non_sta > th_sta ) || @@ -3078,7 +3094,6 @@ void noise_est_ivas_fx( LepsP = extract_l( div_s( num, den ) ); // Q15+exp-exp2 LepsP = L_shr( LepsP, add( sub( exp, exp2 ), 4 ) ); // Q11 - test(); test(); test(); @@ -3118,9 +3133,11 @@ void noise_est_ivas_fx( move16(); move16(); } + /*-----------------------------------------------------------------* * Stereo classifier - save raw aEn *-----------------------------------------------------------------*/ + IF( hStereoClassif != NULL ) { /* @@ -3151,14 +3168,11 @@ void noise_est_ivas_fx( move16(); } - /* Additional NNE detectors */ - /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ /* Q15 Q15 Q12 */ comb_ahc_epsP = s_max( shr( s_max( hNoiseEst->act_pred_fx, hNoiseEst->lt_haco_ev_fx ), 15 - 12 ), epsP_2_16_dlp ); /* Q12 */ - /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ /* Q15 Q12 Q12 */ comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */ @@ -3212,7 +3226,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); @@ -3222,7 +3235,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); @@ -3241,7 +3253,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */ SD_1 = 0; move16(); @@ -3578,6 +3589,7 @@ void noise_est_ivas_fx( } } } + /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/ /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */ L_tmp = 0; diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index b812bd6fc2c3bdc2edbffdd8fd7ccb77e203c857..1fff579055698c31cf92d70aabf0511db6b6e993 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -762,6 +762,7 @@ Word16 pitch_fr4_fx( Word16 corr_v[15 + 2 * L_INTERPOL1 + 1]; /* Total length = t0_max-t0_min+1+2*L_inter */ Word16 pit_min; Word16 cor_max; + Word16 corr_off; /* initialization */ IF( limit_flag == 0 ) @@ -805,34 +806,38 @@ Word16 pitch_fr4_fx( t_min = sub( t0_min, L_INTERPOL1 ); t_max = add( t0_max, L_INTERPOL1 ); - corr = &corr_v[-t_min]; + + corr = corr_v; + corr_off = -t_min; + move16(); + /* corr[t_min..t_max] */ if ( element_mode > EVS_MONO ) { - norm_corr_ivas_fx( exc, xn, h, t_min, t_max, corr, L_subfr, Q_new ); + norm_corr_ivas_fx( exc, xn, h, t_min, t_max, corr + corr_off, L_subfr, Q_new ); } else { - norm_corr_fx( exc, xn, h, t_min, t_max, corr, L_subfr ); + norm_corr_fx( exc, xn, h, t_min, t_max, corr + corr_off, L_subfr ); } /*-----------------------------------------------------------------* * Find integer pitch *-----------------------------------------------------------------*/ - max_val = corr[t0_min]; + max_val = corr[t0_min + corr_off]; move16(); t0 = t0_min; move16(); FOR( i = t0_min + 1; i <= t0_max; i++ ) { - if ( GE_16( corr[i], max_val ) ) + if ( GE_16( corr[i + corr_off], max_val ) ) { t0 = i; move16(); } - max_val = s_max( corr[i], max_val ); + max_val = s_max( corr[i + corr_off], max_val ); } IF( EQ_16( t0_fr1, pit_min ) ) @@ -846,7 +851,7 @@ Word16 pitch_fr4_fx( { i = sub( i, 2 ); } - IF( GT_16( corr[i], corr[i + 2] ) ) + IF( GT_16( corr[i + corr_off], corr[i + 2 + corr_off] ) ) { t0 = i; move16(); @@ -897,15 +902,15 @@ Word16 pitch_fr4_fx( { fraction = 0; move16(); - cor_max = Interpol_4( &corr[t0], fraction ); + cor_max = Interpol_4( &corr[t0 + corr_off], fraction ); } ELSE { t0 = sub( t0, 1 ); - cor_max = Interpol_4( &corr[t0], fraction ); + cor_max = Interpol_4( &corr[t0 + corr_off], fraction ); FOR( i = fraction + step; i <= 3; i = ( i + step ) ) { - temp = Interpol_4( &corr[t0], i ); + temp = Interpol_4( &corr[t0 + corr_off], i ); IF( GT_16( temp, cor_max ) ) { cor_max = temp; @@ -918,7 +923,7 @@ Word16 pitch_fr4_fx( FOR( i = 0; i <= 3; i = ( i + step ) ) { - temp = Interpol_4( &corr[t1], i ); + temp = Interpol_4( &corr[t1 + corr_off], i ); IF( GT_16( temp, cor_max ) ) { cor_max = temp; diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index c28c4c5aa6507323e306d9875822eca570a98663..ff9a2ab647e30dc356085c49b1001c88d7bcf716 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -26,6 +26,7 @@ * The pitch is searched in the interval hLPDmem; FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD; - /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ + signal_in = st->input_fx; vad_flag_dtx = 0; @@ -209,16 +210,17 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); + /*------------------------------------------------------------------* * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ /* rf_mode: first time Q_new is computed here inside Preemph_scaled() for primary copy these are the same memories used in partial frame assembly as well */ - headroom = 1; move16(); test(); @@ -282,7 +284,7 @@ void pre_proc_fx( } /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst ); + vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), cldfb_addition, vad_hover_flag, hVAD, hNoiseEst, NULL ); /*----------------------------------------------------------------* * NB/WB/SWB/FB bandwidth detector @@ -325,17 +327,19 @@ void pre_proc_fx( *----------------------------------------------------------------*/ resetFdCngEnc_fx( st ); + perform_noise_estimation_enc_fx( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc ); /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ - dtx_fx( st, vad_flag_dtx, inp_12k8, *Q_new ); + dtx_fx( st, -1, -1, vad_flag_dtx, inp_12k8, *Q_new ); /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ + test(); IF( ( NE_32( st->last_total_brate, st->total_brate ) ) || ( NE_16( st->last_bwidth, st->bwidth ) ) ) { @@ -349,6 +353,7 @@ void pre_proc_fx( } configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, L_tmp ); } + test(); IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { @@ -447,7 +452,7 @@ void pre_proc_fx( move16(); /* Detection of very short stable st->pitch period (MODE1 bit-rates) */ - StableHighPitchDetect_fx( &flag_spitch, st->pitch, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, + StableHighPitchDetect_fx( EVS_MONO, &flag_spitch, st->pitch, st->voicing_fx, wsp, st->localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, &st->LF_EnergyRatio_sm_fx, &st->predecision_flag, &st->diff_sm_fx, &st->energy_sm_fx, *Q_new, st->lgBin_E_fx ); /* 1/4 pitch precision improvement */ @@ -480,7 +485,6 @@ void pre_proc_fx( move16(); } - /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ @@ -493,6 +497,7 @@ void pre_proc_fx( /*------------------------------------------------------------------* * Update parameters used in the VAD and DTX *-----------------------------------------------------------------*/ + vad_param_updt_fx( st, old_pitch1, corr_shift, corr_shift, A, NULL, 1 ); /*-----------------------------------------------------------------* @@ -503,12 +508,13 @@ void pre_proc_fx( find_tilt_fx( fr_bands, hNoiseEst->bckr_fx, ee, st->pitch, st->voicing_fx, lf_E, corr_shift, st->input_bwidth, st->max_band, hp_E, st->codec_mode, *Q_new, &( st->bckr_tilt_lt ), st->Opt_SC_VBR ); - st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, - corr_shift, relE, *Etot, hp_E, *Q_new, &flag_spitch, *shift, last_core_orig ); + st->coder_type = find_uv_fx( st, pitch_fr, voicing_fr, inp_12k8, ee, 0L, corr_shift, relE, *Etot, hp_E, + &flag_spitch, last_core_orig, NULL, *Q_new, *shift, 31 ); // Q0 - /*----------------------------------------------------------------* + /*-----------------------------------------------------------------* * channel aware mode configuration * *-----------------------------------------------------------------*/ + test(); test(); IF( !st->Opt_RF_ON ) @@ -562,6 +568,7 @@ void pre_proc_fx( hSC_VBR->Local_VAD = st->localVAD; move16(); } + /*----------------------------------------------------------------* * Speech/music classification * AC frame selection @@ -769,6 +776,7 @@ void pre_proc_fx( /*---------------------------------------------------------------------* * Decision matrix (selection of technologies) *---------------------------------------------------------------------*/ + IF( EQ_16( st->codec_mode, MODE1 ) ) { @@ -1329,5 +1337,12 @@ void pre_proc_fx( } } +#ifdef HARMONIZE_ACELP_ENC + epsP[0] = L_Comp( epsP_h[2], epsP_l[2] ); + move32(); + epsP[1] = L_Comp( epsP_h[M], epsP_l[M] ); + move32(); + +#endif return; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index feaefcf5399277180f1e07c3029227c91596e173..4310137b040c22d4cba43eed431f95a65af86a7d 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -41,6 +41,7 @@ #include "ivas_stat_enc.h" +#ifndef HARMONIZE_ACELP_ENC ivas_error acelp_core_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/ @@ -61,7 +62,7 @@ ivas_error acelp_core_enc_fx( STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ const Word16 Q_new, const Word16 shift ); - +#endif void analy_lp_fx( const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ const Word16 L_frame, /* i :(q0) length of the frame */ @@ -78,7 +79,7 @@ void analy_lp_fx( const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ const Word16 element_mode, /* i : element mode */ const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /* i : stores Q for speech */ + const Word16 Q_new, /* i : stores Q for speech */ Word16 *Q_r /*stores q for ener*/ ); @@ -118,16 +119,18 @@ void core_switching_post_enc_fx( const Word16 inp12k8[], /* i : i signal @12.8 kHz Qinp*/ const Word16 inp16k[], /* i : i signal @16 kHz Qinp*/ const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, + const Word16 Qshift, + const Word16 Q_new, const Word16 Qsp, /* i/o : Q from acelp synthsis */ Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ); void core_switching_pre_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old i signal @12.8kHz Qx*/ + const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz Qx*/ + const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ const Word16 *old_inp_16k, /* i : old i signal @16kHz Qx*/ + const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ const Word16 active_cnt, /* i : active frame counter Q0*/ const Word16 last_element_mode /* i : last_element_mode Q0*/ ); @@ -138,32 +141,15 @@ Word16 correlation_shift_fx( ); void dtx_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag Q0*/ - const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ - Word16 Q_speech /* i : Q factor for speech */ -); - -void dtx_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate Q0*/ const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ const Word16 vad, /* i : vad flag for DTX Q0*/ const Word16 speech[], /* i : Pointer to the speech frame Q_speech*/ - Word16 Q_speech /* i : Q factor for speech */ + const Word16 Q_speech /* i : Q factor for speech */ ); Word16 dtx_hangover_addition_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ - Word16 *vad_hover_flag_ptr, - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ -); - -Word16 ivas_dtx_hangover_addition_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ @@ -174,17 +160,19 @@ Word16 ivas_dtx_hangover_addition_fx( Word16 *rem_dtx_ho ); void fb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc ); + const Word16 Q_fb_exc ); void fb_tbe_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ - const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ - Word16 Q_fb_exc, - Word16 Q_new_input ); +#endif + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ + const Word16 Q_fb_exc, + const Word16 Q_new_input ); void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], @@ -232,8 +220,8 @@ void find_tilt_fx( Word16 Opt_vbr_mode /* Q0 */ ); -/* o : coding type */ -Word16 find_uv_ivas_fx( +/*! r: coder type */ +Word16 find_uv_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ @@ -248,24 +236,8 @@ Word16 find_uv_ivas_fx( const Word16 last_core_orig, /* i : original last core Q0*/ STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const Word16 Q_new, - const Word16 q_hp_E ); - -/* o : coding type */ -Word16 find_uv_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6*/ - const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15*/ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6*/ - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15*/ - const Word16 relE, /* i : relative frame energy Q8*/ - const Word16 Etot, /* i : total energy Q8*/ - const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE*/ - const Word16 Q_new, - Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation Q0*/ const Word16 shift, - const Word16 last_core_orig /* i : original last core Q0*/ -); + const Word16 q_hp_E ); void fine_gain_quant_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -322,7 +294,7 @@ void noise_est_down_fx( Word16 Etot, /* i : Energy of current frame */ Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, + const Word16 Q_new, const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ ); @@ -539,7 +511,7 @@ Word16 signal_clas_fx( const Word16 L_look, /* i : look-ahead */ Word16 *uc_clas /* o : temporary classification used in music/speech class*/ ); - +#ifndef FIX_2404_HARM_SIGNAL_CLAS /* o : classification for current frames */ Word16 signal_clas_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ @@ -549,6 +521,7 @@ Word16 signal_clas_ivas_fx( const Word16 L_look, /* i : look-ahead */ Word16 *uc_clas /* o : temporary classification used in music/speech class*/ ); +#endif void speech_music_classif_fx( Encoder_State *st, /* i/o: state structure */ @@ -571,10 +544,11 @@ void speech_music_classif_fx( ); void StableHighPitchDetect_fx( - Word16 *flag_spitch, /* o : flag to indicate very short stable pitch*/ - Word16 pitch[], /* i/o: OL pitch buffer */ - const Word16 voicing[], /* i : OL pitch gains */ - const Word16 wsp[], /* i : weighted speech */ + const Word16 element_mode, /* i : element mode */ + Word16 *flag_spitch, /* o : flag to indicate very short stable pitch*/ + Word16 pitch[], /* i/o: OL pitch buffer */ + const Word16 voicing[], /* i : OL pitch gains */ + const Word16 wsp[], /* i : weighted speech */ const Word16 localVAD, Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ @@ -585,22 +559,6 @@ void StableHighPitchDetect_fx( Word16 Q_new, Word16 EspecdB[] ); -void StableHighPitchDetect_ivas_fx( - Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ - Word16 pitch[], /* i/o: OL pitch buffer Q0 */ - const Word16 voicing[], /* i : OL pitch gains Q15 */ - const Word16 wsp[], /* i : weighted speech Qx */ - const Word16 localVAD, - Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains Q15 */ - Word16 *voicing0_sm, /* i/o: smoothed high pitch gains Q15 */ - Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy Q7 */ - Word16 *predecision_flag, /* i/o: predecision flag */ - Word32 *diff_sm, /* i/o: smoothed pitch frequency difference Q7 */ - Word32 *energy_sm, /* i/o: smoothed energy around pitch frequency Q7 */ - Word16 Q_new, - Word16 EspecdB[] /* Q7 */ -); - void swb_bwe_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *old_input_12k8_fx, /* i : i signal @12.8kHz for SWB BWE */ @@ -620,20 +578,13 @@ void swb_bwe_enc_ivas_fx( const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ const Word16 Q_new_swb_speech, /* i : Q for new_swb_speech_fx */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - Word16 Q_shb_speech, - Word16 Q_slb_speech ); + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + const Word16 Q_slb_speech ); void swb_CNG_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz */ -); - -void swb_CNG_enc_ivas_fx( - Encoder_State *st, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Q0 */ + Encoder_State *st_fx, /* i/o: State structure */ + const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ + const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz */ ); void swb_pre_proc_fx( @@ -669,7 +620,7 @@ void swb_tbe_enc_fx( void swb_tbe_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ @@ -744,6 +695,7 @@ void wb_pre_proc_ivas_fx( ); void wb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ @@ -755,6 +707,7 @@ void wb_tbe_enc_fx( ); void wb_tbe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ @@ -812,7 +765,6 @@ void sc_vbr_enc_init_fx( void updt_enc_common_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 Etot, /* i : total energy */ const Word16 Q_new /* i : CUrrent frame scaling */ ); @@ -859,11 +811,21 @@ void gsc_enc_fx( const Word16 Diff_len, const Word16 bits_used, const Word16 nb_subfr, - Word16 *lsf_new, /* i : ISFs at the end of the frame */ +#ifndef FIX_1904_HARM_GSC_ENC + Word16 *lsf_new, /* i : ISFs at the end of the frame */ +#else + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ +#endif Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ Word16 *tmp_noise, /* o : noise energy */ - Word16 Q_exc ); +#ifndef FIX_1904_HARM_GSC_ENC + Word16 Q_exc +#else + Word16 *Q_exc +#endif +); +#ifndef FIX_1904_HARM_GSC_ENC void gsc_enc_ivas_fx( Encoder_State *st, /* i/o: State structure */ Word16 res_dct_in_fx[], /* i : dct of residual signal */ @@ -875,7 +837,7 @@ void gsc_enc_ivas_fx( Word16 *exc_wo_nf_fx, /* o : excitation (in f domain) without noisefill */ Word16 *tmp_noise_fx, /* o : long-term noise energy */ Word16 *Q_exc ); - +#endif void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); @@ -886,26 +848,12 @@ void lsf_end_enc_fx( Word16 *qlsf, /* o : quantized LSF */ const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ - Word16 *lpc_param, - Word16 *no_indices, - Word16 *bits_param_lpc, - Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ -); - -void lsf_end_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ - Word16 *qlsf, /* o : quantized LSF */ - const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org, /* i : coding type */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ + const Word16 Q_ener, /* i : Q value for Bin_Ener */ + const Word16 force_sf, /* i : Force safety-net usage if coding type supports */ Word16 *lpc_param, Word16 *no_indices, Word16 *bits_param_lpc, - Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases)*/ + const Word16 coder_type_raw, /* i : Coder type (LSF coder_type have some special cases)*/ const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ); @@ -1161,12 +1109,6 @@ void td_cng_enc_init_fx( const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ ); -void td_cng_enc_init_ivas_fx( - TD_CNG_ENC_HANDLE hTdCngEnc, /* i/o: DTX/TD CNG data handle */ - const Word16 Opt_DTX_ON, /* i : flag indicating DTX operation Q0*/ - const Word16 max_bwidth /* i : maximum encoded bandwidth Q0*/ -); - void dtx_enc_init_fx( Encoder_State *st, /* i : Encoder state handle */ const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate Q0*/ @@ -1184,18 +1126,18 @@ void coder_type_modif_fx( const Word16 relE /* i : frame relative E to the long term average */ ); -void coder_type_modif_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 relE /* i : frame relative E to the long term average */ -); - void speech_music_clas_init_fx( +#ifdef FIX_2405_HARM_SMC_INIT + const Word16 element_mode, /* i : element mode */ +#endif SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); +#ifndef FIX_2405_HARM_SMC_INIT void speech_music_clas_init_ivas_fx( SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); +#endif void pitchDoubling_det_fx( Word16 *wspeech, @@ -1520,21 +1462,6 @@ void lpc_quantization_fx( Word16 *no_param_lpc, /* Q0 */ const Word16 Q_ener ); -void lpc_quantization_ivas_fx( - Encoder_State *st, - const Word16 lsp[], /* Q15 */ - const Word16 lspmid[], /* Q15 */ - Word16 lsp_q[], /* Q15 */ - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], /* Q15 */ - const Word16 coder_type, /* Q0 */ - const Word16 acelp_midLpc, /* Q0 */ - Word16 param_lpc[], /* Q0 */ - Word16 nbits_lpc[], /* Q0 */ - Word16 *bits_param_lpc, /* Q0 */ - Word16 *no_param_lpc, /* Q0 */ - const Word16 Q_ener ); - void Mode2_pit_encode_fx( const Word16 coder_type, /* i : coding model */ const Word16 i_subfr, /* i : subframe index */ @@ -1748,23 +1675,9 @@ void reset_rf_indices_fx( ); void CNG_enc_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ - Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ - const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ - Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ - Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 Q_new, /* i : Q value of speech */ - Word32 *q_env, - Word16 *sid_bw ); - -void CNG_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ - // Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ + Encoder_State *st_fx, /* i/o: State structure */ + Word16 Aq[], /* o : LP coefficients Q12 */ + const Word16 *speech, /* i : pointer to current frame i speech buffer Q_new */ const Word16 *lsp_mid, /* i : mid frame LSPs Q15 */ Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ @@ -1805,25 +1718,14 @@ void CNG_reset_enc_fx( ); void lsf_enc_fx( - Encoder_State *st_fx, /* i/o: state structure */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - const Word16 Nb_ACELP_frames, - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ - const Word16 Q_new ); - -void lsf_enc_ivas_fx( - Encoder_State *st, /* i/o: state structure */ + Encoder_State *st_fx, /* i/o: state structure */ Word16 *lsf_new, /* o : quantized LSF vector */ Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ Word16 *Aq, /* o : quantized A(z) for 4 subframes */ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ + const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const Word16 Q_new ); void Es_pred_enc_fx( @@ -1853,22 +1755,6 @@ void encod_nelp_fx( Word16 Q_new, Word16 shift ); -void encod_nelp_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : input speech Q_new-1 */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes exp(norm_s(Aw_fx[0])+1)*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient exp(norm_s(Aw_fx[0])+1)*/ - Word16 *res_fx, /* o : residual signal Q_new */ - Word16 *synth_fx, /* o : core synthesis Q_new */ - Word16 *tmp_noise_fx, /* o : long-term noise energy Q8 */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new */ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q_new */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */ - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new */ - Word16 Q_new, - Word16 shift ); - Word16 encod_tran_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ @@ -1889,26 +1775,6 @@ Word16 encod_tran_fx( const Word16 Q_new /* i : Input scaling */ ); -Word16 encod_tran_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Q0*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* i/o: core synthesis Q_new*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q0*/ - Word16 tc_subfr, /* i/o: TC subframe classification Q0*/ - Word16 position, /* i : maximum of residual signal index Q0*/ - Word16 *unbits, /* i/o: number of unused bits Q0*/ - const Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 Q_new /* i : Input scaling */ -); - void coder_acelp_rf_fx( ACELP_config *acelp_cfg_rf, /*i/o : configuration of the ACELP coding */ const Word16 coder_type, /* input: coding type Q0*/ @@ -1997,26 +1863,10 @@ void encod_unvoiced_fx( Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ - const Word16 Q_new, - const Word16 shift ); - -void encod_unvoiced_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ - const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ - const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* o : core synthesis Q_new - 1*/ - Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ - const Word16 Q_new, - const Word16 shift ); + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +); void enc_acelp_tcx_main_fx( const Word16 new_samples[], /* i : new samples Q15*/ @@ -2037,50 +1887,17 @@ ivas_error encod_ppp_fx( const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q14*/ Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ + Word16 *synth_fx, /* o : core synthesis Q-1*/ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, - Word16 shift ); - -ivas_error encod_ppp_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o : current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, - Word16 shift ); + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +); void encod_gen_voic_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : i speech Q0*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *syn_fx, /* i/o: core synthesis Q_new*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ - Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ - Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 shift, - Word16 Q_new ); - -void encod_gen_voic_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Q0*/ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ @@ -2094,31 +1911,13 @@ void encod_gen_voic_ivas_fx( Word16 *voice_factors_fx, /* o : voicing factors Q15*/ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 shift, - Word16 Q_new ); + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ + const Word16 shift, /* i : Shift needed to obtain 12 bits vectors */ + const Word16 Q_new /* i : Scaling factor */ +); void encod_audio_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 speech[], /* i : i speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC)*/ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ - Word16 Q_new, - Word16 shift ); - -void encod_audio_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 speech[], /* i : input speech Q_new */ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ @@ -2128,14 +1927,15 @@ void encod_audio_ivas_fx( Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC)*/ Word16 *lsf_new, /* i : current frame ISF vector */ Word16 *tmp_noise, /* o : noise energy */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ - Word16 Q_new, - Word16 shift ); + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift needed to obtain 12 bits vectors */ +); void stat_noise_uv_enc_fx( Encoder_State *st_fx, /* i/o: state structure */ @@ -2548,8 +2348,8 @@ void coder_tcx_post_fx( const Word16 *A, const Word16 *Ai, Word16 *wsig, - Word16 Q_new, - Word16 shift ); + const Word16 Q_new, + const Word16 shift ); void coder_tcx_post_ivas_fx( Encoder_State *st, @@ -2562,14 +2362,14 @@ void coder_tcx_post_ivas_fx( Word16 Q_new ); void enc_prm_fx( - const Word16 coder_type, /* i : coding type */ - Word16 param[], /* i : parameters */ - Word16 param_lpc[], /* i : LPC parameters */ - Encoder_State *st, /* i/o: quantization Analysis values */ - Word16 L_Frame, + const Word16 coder_type, /* i : coding type */ + Word16 param[], /* i : parameters */ + const Word16 param_lpc[], /* i : LPC parameters */ + Encoder_State *st, /* i/o: quantization Analysis values */ + const Word16 L_Frame, CONTEXT_HM_CONFIG hm_cfg[], Word16 *bits_param_lpc, - Word16 no_param_lpc ); + const Word16 no_param_lpc ); void IGFEncSetMode_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ @@ -2755,11 +2555,6 @@ void enc_prm_rf_fx( const Word16 rf_frame_type, const Word16 fec_offset ); -void enc_prm_rf_ivas_fx( - Encoder_State *st, - const Word16 rf_frame_type, - const Word16 fec_offset ); - void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, @@ -2866,14 +2661,8 @@ void enc_prm_side_Info_fx( /* Returns: number of bits written */ Word16 enc_lsf_tcxlpc_fx( - Word16 **indices, /* i : Ptr to VQ indices */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -); - -/* Returns: number of bits written */ -Word16 enc_lsf_tcxlpc_ivas_fx( - const Word16 **indices, /* i : Ptr to VQ indices */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ + const Word16 **indices, /* i : Ptr to VQ indices */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); Word16 encode_lpc_avq_fx( @@ -2884,36 +2673,13 @@ Word16 encode_lpc_avq_fx( const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ ); -Word16 encode_lpc_avq_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc Q0*/ - const Word16 *param_lpc, /* i : lpc parameters Q0*/ - const Word16 core, /* i : core Q0*/ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ -); - Word16 lsf_bctcvq_encprm_fx( - BSTR_ENC_HANDLE hBstr, - Word16 *param_lpc, - Word16 *bits_param_lpc, - Word16 no_indices ); - -Word16 lsf_bctcvq_encprm_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 *param_lpc, const Word16 *bits_param_lpc, const Word16 no_indices ); Word16 lsf_msvq_ma_encprm_fx( - BSTR_ENC_HANDLE hBstr, - Word16 *param_lpc, - Word16 core, - Word16 acelp_mode, - Word16 acelp_midLpc, - Word16 *bits_param_lpc, - Word16 no_indices ); - -Word16 lsf_msvq_ma_encprm_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 *param_lpc, const Word16 core, @@ -2956,10 +2722,6 @@ void signaling_enc_rf_fx( Encoder_State *st /* i : encoder state structure */ ); -void signalling_enc_rf_fx( - Encoder_State *st /* i : encoder state structure */ -); - void IGFEncResetTCX10BitCounter_fx( const IGF_ENC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Encoder */ ); @@ -3503,31 +3265,6 @@ Word16 lp_filt_exc_enc_fx( ); Word16 inov_encode_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter i response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ - const Word16 L_subfr, /* i : subframe length */ - Word16 shift ); - -Word16 inov_encode_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -3550,7 +3287,7 @@ Word16 inov_encode_ivas_fx( Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ Word16 *unbits, /* o : number of unused bits for PI */ const Word16 L_subfr, /* i : subframe length */ - Word16 shift, + const Word16 shift, Word16 Q_new ); void gain_enc_mless_fx( @@ -3598,7 +3335,7 @@ void analy_lp_AMR_WB_fx( Word16 isf_new[], /* o : current frame ISPs Q15*/ Word16 Top, /* i : open loop pitch lag Q0*/ Word16 Tnc, /* i : open loop pitch gain Qx*/ - Word16 Q_new, + const Word16 Q_new, Word16 *Q_r ); void encod_amr_wb_fx( @@ -3613,8 +3350,8 @@ void encod_amr_wb_fx( Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6*/ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain Q0*/ const Word16 *speech16k_fx, /* i : i speech @16kHz Qx*/ - Word16 shift, - Word16 Q_new ); + const Word16 shift, + const Word16 Q_new ); void re8_cod_fx( Word16 x[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ @@ -3634,16 +3371,8 @@ void acelp_core_switch_enc_fx( const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ const Word16 inp16k[], /* i : i signal @16 kHz Q0 */ const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12 */ - Word16 shift, - Word16 Q_new ); - -void acelp_core_switch_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : i signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : i signal @16 kHz Q0 */ - const Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12 */ - Word16 shift, - Word16 Q_new ); + const Word16 shift, + const Word16 Q_new ); void gain_enc_amr_wb_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -3704,31 +3433,6 @@ void transf_cdbk_enc_fx( const Word16 shift /* i : shifting applied to y1, xn,... */ ); -void transf_cdbk_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ - const Word16 i_subfr, /* i : subframe index Q0*/ - Word16 cn[], /* i/o: target vector in residual domain Q_new*/ - Word16 exc[], /* i/o: pointer to excitation signal frame Q_new*/ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ - const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ - const Word16 h1[], /* i : weighted filter input response Q15*/ - Word16 xn[], /* i/o: target vector Q_new + shift -1*/ - Word16 xn2[], /* i/o: target vector for innovation search Q_new + shift -1*/ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation Q_new + shift -1*/ - const Word16 y2[], /* i : zero-memory filtered innovative excitation Q9*/ - const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ - Word16 *gain_pit, /* i/o: adaptive excitation gain Q14*/ - const Word32 gain_code, /* i : innovative excitation gain Q16*/ - Word16 g_corr[], /* o : ACELP correlation values Q15*/ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0*/ - Word16 *gain_preQ, /* o : prequantizer excitation gain Q2*/ - Word16 code_preQ[], /* o : prequantizer excitation Q_AVQ_OUT_DEC*/ - Word16 *unbits, /* o : number of AVQ unused bits Q0*/ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ -); - void gain_enc_lbr_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits Q0*/ @@ -3838,32 +3542,6 @@ void transition_enc_fx( Word16 shift /* i : downscaling needs for 12 bits convolutions */ ); -void transition_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - Word16 *unbits_ACELP, /* i/o: unused bits */ - Word16 Q_new, /* i : Current scaling */ - Word16 shift /* i : downscaling needs for 12 bits convolutions */ -); - void gain_enc_tc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits Q0*/ @@ -3879,21 +3557,6 @@ void gain_enc_tc_fx( const Word16 Q_xn /* i : xn and y1 scaling */ ); -void gain_enc_tc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits Q0*/ - const Word16 i_subfr, /* i : subframe index Q0*/ - const Word16 xn_fx[], /* i : target vector Q_xn*/ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation Q_xn*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy Q8*/ - Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : innovation gain Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q6*/ - const Word16 Q_xn /* i : xn and y1 scaling */ -); - Word16 gaus_encode_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 i_subfr, /* i : subframe index Q0*/ @@ -3914,26 +3577,6 @@ Word16 gaus_encode_fx( Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16*/ ); -Word16 gaus_encode_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index Q0*/ - const Word16 *h1, /* i : weighted filter input response Q14*/ - const Word16 *xn, /* i : target vector Q12*/ - Word16 *exc, /* o : pointer to excitation signal frame Q_new*/ - Word16 *mem_w0, /* o : weighting filter denominator memory Q_new*/ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word32 *gain_code, /* o : Code gain. Q16*/ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9*/ - Word16 *gain_inov, /* o : innovation gain Q12*/ - Word16 *voice_fac, /* o : voicing factor Q15*/ - Word16 *gain_pit, /* o : adaptive excitation gain Q14*/ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code /* o : normalized innovative cb. gain Q16*/ -); - void pre_proc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 input_frame, /* i : frame length */ @@ -3948,11 +3591,13 @@ void pre_proc_fx( #endif Word16 A[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes */ - Word16 epsP_h[M + 1], /* o : LP prediction errors */ - Word16 epsP_l[M + 1], /* o : LP prediction errors */ - Word32 epsP[M + 1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ +#ifndef HARMONIZE_ACELP_ENC + Word16 epsP_h[M + 1], /* o : LP prediction errors */ + Word16 epsP_l[M + 1], /* o : LP prediction errors */ +#endif + Word32 epsP[M + 1], /* o : LP prediction errors */ + Word16 lsp_new[M], /* o : LSPs at the end of the frame */ + Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ Word16 *vad_hover_flag, Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ Word16 *new_inp_resamp16k, /* o : new i signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ @@ -4000,9 +3645,9 @@ void enc_pit_exc_fx( Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ - Word16 Q_new, - Word16 shift ); - + const Word16 Q_new, + const Word16 shift ); +#ifndef FIX_1904_HARM_GSC_ENC void enc_pit_exc_ivas_fx( Encoder_State *st_fx, /* i/o: State structure */ const Word16 *speech, /* i : Input speech Q_new-1*/ @@ -4022,6 +3667,7 @@ void enc_pit_exc_ivas_fx( const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 Q_new, Word16 shift ); +#endif /* o : bin where pitch contribution is significant */ Word16 Pit_exc_contribution_len_fx( @@ -4032,18 +3678,16 @@ Word16 Pit_exc_contribution_len_fx( const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ); - +#ifndef FIX_1904_HARM_GSC_ENC /* o : bin where pitch contribution is significant */ Word16 Pit_exc_contribution_len_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 *dct_res, /* i : DCT of residual Qnew*/ Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/ Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ -#ifndef FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ -#endif - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ); +#endif Word16 pvq_core_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -4093,14 +3737,6 @@ void hq_lr_enc_fx( const Word16 is_transient_fx /* i : Q0 : transient flag */ ); -void hq_lr_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: : encoder state structure */ - Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ - const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ - Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ - const Word16 is_transient_fx /* i : Q0 : transient flag */ -); - void hq_hr_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure fx */ Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ @@ -4276,26 +3912,6 @@ ivas_error tcq_core_LR_enc_fx( const Word16 adjustFlag, const Word16 is_transient ); -ivas_error tcq_core_LR_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word32 inp_vector[], - const Word32 coefs_norm_fx[], - Word32 coefs_quant_fx[], - const Word16 bit_budget, /* number of bits */ - const Word16 BANDS, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 is_transient ); - /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ Word16 encode_envelope_indices_fx( BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ @@ -4357,13 +3973,17 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); +#ifndef HARMONIZE_TBE void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); - +#endif void ResetSHBbuffer_Enc_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); @@ -4489,35 +4109,21 @@ Word32 mslvq_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ Word16 multi_harm_fx( - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : i signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ - Word16 *sp_floor, /* o: noise floor estimate Q7 */ - Word16 S_map[] /* o : short-term correlation map Q7 */ + const Word16 element_mode, /* i : IVAS element_mode Q0 */ + const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ + Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ + Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ + Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ + const Word32 total_brate, /* i : total bitrate Q0 */ + const Word16 bwidth, /* i : i signal bandwidth Q0 */ + Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ + Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ + Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ + Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ + Word16 *sp_floor, /* o: noise floor estimate Q7 */ + Word16 S_map[] /* o : short-term correlation map Q7 */ ); -/* o : frame multi-harmonicity (1-harmonic, 0-not) */ -Word16 multi_harm_ivas_fx( - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : i signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum, /* i : sum of correlation map Q8 */ - Word16 *sp_floor, /* o: noise floor estimate Q7 */ - Word16 S_map[] /* o : short-term correlation map Q7 */ -); void pvq_encode_frame_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ diff --git a/lib_enc/qlpc_avq_fx.c b/lib_enc/qlpc_avq_fx.c index 67b481ea03c203f6a55ab87978a5ed64efc7ae08..5d4d93fdfaf6d1aa6859cb40eb5f9a3835058d7c 100644 --- a/lib_enc/qlpc_avq_fx.c +++ b/lib_enc/qlpc_avq_fx.c @@ -123,36 +123,14 @@ void qlpc_avq_fx( return; } + /*-------------------------------------------------------------------* * unary_code() * * *--------------------------------------------------------------------*/ -static Word16 unary_code( - Word16 ind, /* Q0 */ - BSTR_ENC_HANDLE hBstr ) -{ - Word16 nb_bits; - - move16(); - nb_bits = 1; - - /* Index bits */ - ind = sub( ind, 1 ); - - FOR( ; ind > 0; ind-- ) - { - push_next_indice( hBstr, 1, 1 ); - nb_bits = add( nb_bits, 1 ); // Q0 - } - - /* Stop bit */ - push_next_indice( hBstr, 0, 1 ); - - return ( nb_bits ); -} -static Word16 unary_code_ivas_fx( +static Word16 unary_code_fx( Word16 ind, /* Q0 */ BSTR_ENC_HANDLE hBstr ) { @@ -181,41 +159,14 @@ static Word16 unary_code_ivas_fx( return ( nb_bits ); } + /*-------------------------------------------------------------------* * unpack4bits() * * *--------------------------------------------------------------------*/ -static Word16 unpack4bits( - Word16 nbits, /* Q0 */ - const Word16 *prm, /* Q0 */ - BSTR_ENC_HANDLE hBstr ) -{ - Word16 i; - - IF( nbits == 0 ) - { - push_next_indice( hBstr, 0, 0 ); - i = 1; - move16(); - } - ELSE - { - move16(); - i = 0; - - FOR( ; nbits > 4; nbits -= 4 ) - { - push_next_indice( hBstr, prm[i], 4 ); - i = add( i, 1 ); - } - push_next_indice( hBstr, prm[i], nbits ); - i = add( i, 1 ); - } - return ( i ); -} -static Word16 unpack4bits_ivas_fx( +static Word16 unpack4bits_fx( Word16 nbits, /* Q0 */ const Word16 *prm, /* Q0 */ BSTR_ENC_HANDLE hBstr ) @@ -251,7 +202,7 @@ static Word16 unpack4bits_ivas_fx( *--------------------------------------------------------------------*/ Word16 encode_lpc_avq_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 numlpc, /* i : Number of sets of lpc Q0*/ const Word16 *param_lpc, /* i : lpc parameters Q0*/ const Word16 core, /* i : core Q0*/ @@ -284,215 +235,6 @@ Word16 encode_lpc_avq_fx( FOR( k = 0; k < numlpc; k++ ) { /* Retrieve quantizer type */ - - - move16(); - q_type = 0; - if ( k != 0 ) - { - move16(); - q_type = param_lpc[j]; // Q0 - j = add( j, 1 ); - } - test(); - if ( EQ_16( element_mode, IVAS_CPE_MDCT ) && k == 0 ) - { - stereo_mode = param_lpc[j]; // Q0 - move16(); - j = add( j, 1 ); - } - /* Determine number of AVQ indices */ - move16(); - nb_ind = 0; - - if ( q_type == 0 ) - { - move16(); - st1 = param_lpc[j++]; // Q0 - } - move16(); - move16(); - qn1 = param_lpc[j++]; // Q0 - qn2 = param_lpc[j++]; // Q0 - IF( EQ_16( qn1, SNS_LOW_BR_MODE ) ) - { - nb_ind = add( qn1, qn2 ); - } - - test(); - test(); - IF( k == 0 || ( EQ_16( k, 1 ) && NE_16( core, TCX_20_CORE ) ) ) - { - /* Encode quantizer type */ - move16(); - nb = 0; - IF( k != 0 ) - { - nb = 1; - move16(); - push_next_indice( hBstr, q_type, nb ); - } - nb_bits = add( nb_bits, nb ); // Q0 - - /* Encode quantizer data */ - test(); - test(); - test(); - test(); - IF( ( ( q_type == 0 ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) || ( ( q_type == 0 ) && ( GE_16( st1, 0 ) ) && EQ_16( element_mode, IVAS_CPE_MDCT ) ) ) - { - /* Absolute quantizer with 1st stage stochastic codebook */ - push_next_indice( hBstr, st1, bits_for_abs_quant ); - nb_bits = add( nb_bits, bits_for_abs_quant ); // Q0 - } - - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_MDCT ) && EQ_16( stereo_mode, 3 ) && st1 < 0 ) - { - push_next_indice( hBstr, add( st1, 2 ), 1 ); - nb_bits = add( nb_bits, 1 ); // Q0 - } - - test(); - test(); - IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( NE_16( st1, -2 ) && NE_16( qn1, SNS_LOW_BR_MODE ) ) ) - { - - /* 2 bits to specify Q2,Q3,Q4,ext */ - nb_bits = add( nb_bits, 4 ); // Q0 - i = sub( qn1, 2 ); - - if ( s_or( i < 0, (Word16) GT_16( i, 3 ) ) ) - { - move16(); - i = 3; - } - push_next_indice( hBstr, i, 2 ); - - i = sub( qn2, 2 ); - - if ( s_or( i < 0, (Word16) GT_16( i, 3 ) ) ) - { - move16(); - i = 3; - } - push_next_indice( hBstr, i, 2 ); - - /* Unary code for abs and rel LPC0/LPC2 */ - /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ - move16(); - nb = qn1; - - IF( GT_16( nb, 6 ) ) - { - nb = sub( nb, 3 ); - } - ELSE IF( GT_16( nb, 4 ) ) - { - nb = sub( nb, 4 ); - } - ELSE IF( nb == 0 ) - { - move16(); - nb = 3; - } - ELSE - { - move16(); - nb = 0; - } - - IF( nb > 0 ) - { - unary_code( nb, hBstr ); - } - nb_bits = add( nb_bits, nb ); // Q0 - - move16(); - nb = qn2; - - IF( GT_16( nb, 6 ) ) - { - nb = sub( nb, 3 ); // Q0 - } - ELSE IF( GT_16( nb, 4 ) ) - { - nb = sub( nb, 4 ); // Q0 - } - ELSE IF( nb == 0 ) - { - move16(); - nb = 3; - } - ELSE - { - move16(); - nb = 0; - } - - IF( nb > 0 ) - { - unary_code( nb, hBstr ); - } - nb_bits = add( nb_bits, nb ); // Q0 - - avqBits = shl( qn1, 2 ); - unpack4bits( avqBits, ¶m_lpc[j], hBstr ); - j = add( j, qn1 ); - nb_bits = add( nb_bits, avqBits ); // Q0 - - avqBits = shl( qn2, 2 ); - unpack4bits( avqBits, ¶m_lpc[j], hBstr ); - j = add( j, qn2 ); - nb_bits = add( nb_bits, avqBits ); // Q0 - } - } - ELSE - { - j = add( j, nb_ind ); - } - } - - return ( nb_bits ); -} - -Word16 encode_lpc_avq_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 numlpc, /* i : Number of sets of lpc Q0*/ - const Word16 *param_lpc, /* i : lpc parameters Q0*/ - const Word16 core, /* i : core Q0*/ - const Word16 element_mode /* i : element mode - decides between SNS and LPC coding Q0*/ -) -{ - Word16 k, j; - Word16 q_type, nb_ind; - Word16 i, qn1, qn2, nb, avqBits, st1; - Word16 nb_bits; - Word16 stereo_mode, bits_for_abs_quant; - - stereo_mode = 0; - move16(); - bits_for_abs_quant = LPC_ABS_QUANT_BITS; - move16(); - if ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) - { - bits_for_abs_quant = SNS_ABS_QUANT_BITS; - move16(); - } - - move16(); - move16(); - move16(); - st1 = 0; - j = 0; - nb_bits = 0; - - FOR( k = 0; k < numlpc; k++ ) - { - /* Retrieve quantizer type */ - - move16(); q_type = 0; IF( k != 0 ) @@ -508,6 +250,7 @@ Word16 encode_lpc_avq_ivas_fx( move16(); j = add( j, 1 ); } + /* Determine number of AVQ indices */ move16(); nb_ind = 0; @@ -615,7 +358,7 @@ Word16 encode_lpc_avq_ivas_fx( IF( nb > 0 ) { - unary_code_ivas_fx( nb, hBstr ); + unary_code_fx( nb, hBstr ); } nb_bits = add( nb_bits, nb ); @@ -643,17 +386,17 @@ Word16 encode_lpc_avq_ivas_fx( IF( nb > 0 ) { - unary_code_ivas_fx( nb, hBstr ); + unary_code_fx( nb, hBstr ); } nb_bits = add( nb_bits, nb ); avqBits = shl( qn1, 2 ); - unpack4bits_ivas_fx( avqBits, ¶m_lpc[j], hBstr ); + unpack4bits_fx( avqBits, ¶m_lpc[j], hBstr ); j = add( j, qn1 ); nb_bits = add( nb_bits, avqBits ); // Q0 avqBits = shl( qn2, 2 ); - unpack4bits_ivas_fx( avqBits, ¶m_lpc[j], hBstr ); + unpack4bits_fx( avqBits, ¶m_lpc[j], hBstr ); j = add( j, qn2 ); nb_bits = add( nb_bits, avqBits ); // Q0 } diff --git a/lib_enc/qlpc_stoch_fx.c b/lib_enc/qlpc_stoch_fx.c index 0964d7421b26fa9036127c67b2dc4e23b6cf6094..0d02d4742be1a1f2e475fe14e829aec7fb01ae32 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -25,6 +25,7 @@ * * *--------------------------------------------------------------------*/ + void lpc_quantization_fx( Encoder_State *st, const Word16 lsp[], /* Q15 */ @@ -117,7 +118,7 @@ void lpc_quantization_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) ) { lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, - force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); + force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); nb_indices = *no_param_lpc; // Q0 move16(); @@ -125,19 +126,17 @@ void lpc_quantization_fx( ELSE { lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, - force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); + force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); nb_indices = *no_param_lpc; // Q0 move16(); } - FEC_lsf_estim_enc_fx( st, fec_lsf ); /* FEC - calculate LSF stability */ stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/ - test(); test(); test(); @@ -172,11 +171,9 @@ void lpc_quantization_fx( } /* Mid-frame LPC quantization */ - test(); IF( st->lpcQuantization && acelp_midLpc ) { - IF( st->rate_switching_reset == 0 ) { lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) ); @@ -196,169 +193,6 @@ void lpc_quantization_fx( } } - - return; -} - -void lpc_quantization_ivas_fx( - Encoder_State *st, - const Word16 lsp[], /* Q15 */ - const Word16 lspmid[], /* Q15 */ - Word16 lsp_q[], /* Q15 */ - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], /* Q15 */ - const Word16 coder_type, /* Q0 */ - const Word16 acelp_midLpc, /* Q0 */ - Word16 param_lpc[], /* Q0 */ - Word16 nbits_lpc[], /* Q0 */ - Word16 *bits_param_lpc, /* Q0 */ - Word16 *no_param_lpc, /* Q0 */ - const Word16 Q_ener ) -{ - Word16 nb_indices; - Word16 lsfmid_q[M]; /* 14Q1*1.28 */ - Word16 lsfmid_idx; - Word16 i, force_sf; - Word16 lsf[M], lsfmid[M]; - Word16 fec_lsf[M], stab; - - nb_indices = 0; - move16(); - - /****** High-rate LPC quantizer *******/ - - IF( st->lpcQuantization == 0 ) - { - E_LPC_lsp_lsf_conversion( lsp, lsf, M ); - - IF( ( EQ_16( st->core, TCX_10_CORE ) ) ) - { - E_LPC_lsp_lsf_conversion( lspmid, lsfmid, M ); - } - - /* LPC quantizer */ - qlpc_avq_fx( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core ); - - E_LPC_lsf_lsp_conversion( lsf_q, lsp_q, M ); - - IF( EQ_16( st->core, TCX_10_CORE ) ) - { - E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M ); - } - - assert( nb_indices <= NPRM_LPC_NEW ); - } - - /****** Low-rate LPC quantizer *******/ - - ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) - { - - lsp2lsf_fx( lsp, lsf, M, extract_l( st->sr_core ) ); - - force_sf = 0; - move16(); - /*Force safety net when possible in case of transitions*/ - test(); - test(); - IF( GE_32( st->tc_cnt, 1 ) || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) ) - { - force_sf = 1; - move16(); - st->next_force_safety_net = 0; - move16(); - } - - test(); - IF( EQ_16( st->next_force_safety_net, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) ) - { - force_sf = 1; - st->next_force_safety_net = 0; - move16(); - move16(); - } - - test(); - IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) ) - { - lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener, - force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL ); - - nb_indices = *no_param_lpc; // Q0 - move16(); - } - ELSE - { - lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener, - force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL ); - - nb_indices = *no_param_lpc; // Q0 - move16(); - } - - - FEC_lsf_estim_enc_fx( st, fec_lsf ); - - /* FEC - calculate LSF stability */ - stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/ - - - test(); - test(); - test(); - IF( LT_16( stab, add( STAB_FAC_LIMIT_FX, 6553 /* =0.2 in Q15*/ ) ) && - ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) ) - { - st->next_force_safety_net = 1; - move16(); - } - - lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core ); - - *nbits_lpc = ENDLSF_NBITS; - move16(); - } - ELSE - { - assert( 0 ); - } - - st->seed_acelp = 0; - move16(); - FOR( i = nb_indices - 1; i >= 0; i-- ) - { - st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0 - move16(); - } - - /* Mid-frame LPC quantization */ - - test(); - IF( st->lpcQuantization && acelp_midLpc ) - { - - IF( st->rate_switching_reset == 0 ) - { - lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) ); - - midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type ); - param_lpc[nb_indices] = lsfmid_idx; // Q0 - move16(); - nb_indices = add( nb_indices, 1 ); - midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 ); - - reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx( lsfmid_q, lspmid_q, M, st->sr_core ); - } - ELSE - { - param_lpc[nb_indices] = 0; - move16(); - nb_indices = add( nb_indices, 1 ); // Q0 - } - } - - return; } diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index f92243a5ab15987662be04399979d1d03fb820c9..526136e698c0d952e185dbb9bee1d919ac0adff6 100644 --- a/lib_enc/rom_enc.h +++ b/lib_enc/rom_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/rom_enc_fx.c b/lib_enc/rom_enc_fx.c index 4af957800648f7314f145808d5cb17dd1c888e60..9c7f3f53e02b6a5358e89469fcc57a30f494fef0 100644 --- a/lib_enc/rom_enc_fx.c +++ b/lib_enc/rom_enc_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 990fad0db6851a9f6e6b3358c594b1c1058ffcd9..19c17e404f2d9255ec0649673b5fceb0b79e198f 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -31,9 +31,9 @@ #define K_SNR_FX 3541 /* Q15 .1111 */ #define C_SNR_FX -10921 /* Q15 -0.3333f */ - #define THRES_EEN 514206 /* 251.077 => (10^(1/(K_EE*10))) Q11*/ + /*-------------------------------------------------------------------* * signal_clas_fx() * @@ -41,13 +41,14 @@ * TC frames selection *-------------------------------------------------------------------*/ -Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *speech, /* i : pointer to speech signal for E computation in Qx */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames in Q6 */ - const Word16 relE, /* i : frame relative E to the long term average in Q8 */ - const Word16 L_look, /* i : look-ahead */ - Word16 *clas_mod /* o : class flag for NOOP detection */ +/* o : classification for current frames */ +Word16 signal_clas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *speech, /* i : pointer to speech signal for E computation in Qx */ + const Word32 *ee, /* i : lf/hf E ration for 2 half-frames in Q6 */ + const Word16 relE, /* i : frame relative E to the long term average in Q8 */ + const Word16 L_look, /* i : look-ahead */ + Word16 *clas_mod /* o : class flag for NOOP detection */ ) { Word32 Ltmp; @@ -55,6 +56,9 @@ Word16 signal_clas_fx( /* o : classification for current Word16 i, clas, pc, zc, lo, lo2, hi, hi2, exp_ee, frac_ee; Word16 tmp16, tmpS; const Word16 *pt1; +#ifdef FIX_2404_HARM_SIGNAL_CLAS + Word64 tmp64; +#endif Flag Overflow = 0; move32(); @@ -69,34 +73,61 @@ Word16 signal_clas_fx( /* o : classification for current Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */ mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 ); - /* average spectral tilt in dB */ - lo = L_Extract_lc( ee[0], &hi ); - lo2 = L_Extract_lc( ee[1], &hi2 ); - Ltmp = L_mult( lo, lo2 ); /* Q5*Q5->Q11 */ - - test(); - test(); - IF( LT_32( Ltmp, 2048 ) ) - { - een = 0; - move16(); - } - ELSE IF( GT_32( Ltmp, THRES_EEN ) || hi > 0 || hi2 > 0 ) +#ifdef FIX_2404_HARM_SIGNAL_CLAS + IF( st->element_mode != EVS_MONO ) { - een = 512; - move16(); + tmp64 = W_mult0_32_32( ee[0], ee[1] ); + exp_ee = W_norm( tmp64 ); + Ltmp = W_extract_h( W_shl( tmp64, exp_ee ) ); // Q = Q6+Q6 + exp_ee - 32 + exp_ee = sub( 31, sub( add( Q12, exp_ee ), 32 ) ); + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( Ltmp, exp_ee, ONE_IN_Q31, 0 ), -1 ) ) + { + een = 0; + move16(); + } + ELSE + { + /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */ + /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ + Ltmp = BASOP_Util_Log10( Ltmp, exp_ee ); // Q25 + Ltmp = Mpy_32_32( Ltmp, 671088640 /*20.f in Q25*/ ); // Q25 + Q25 -Q31 = Q19 * 0.5 = Q20 + een = extract_l( L_shl( Mpy_32_16_1( Ltmp, K_EE_FX ), Q9 - Q20 ) ); // Q9 + een = s_min( s_max( een, 0 ), 512 ); + } } ELSE +#endif { - /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */ - /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ - exp_ee = norm_l( Ltmp ); - frac_ee = Log2_norm_lc( L_shl( Ltmp, exp_ee ) ); - exp_ee = sub( 30 - 11, exp_ee ); - Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* Ltmp Q14 */ - een = round_fx( L_shl( Ltmp, 16 - 5 ) ); /* Q14 -> Q9 */ - een = mac_r( C_EE_FX, een, K_EE_FX ); + /* average spectral tilt in dB */ + lo = L_Extract_lc( ee[0], &hi ); + lo2 = L_Extract_lc( ee[1], &hi2 ); + Ltmp = L_mult( lo, lo2 ); /* Q5*Q5->Q11 */ + + test(); + test(); + IF( LT_32( Ltmp, 2048 ) ) + { + een = 0; + move16(); + } + ELSE IF( GT_32( Ltmp, THRES_EEN ) || hi > 0 || hi2 > 0 ) + { + een = 512; + move16(); + } + ELSE + { + /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */ + /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ + exp_ee = norm_l( Ltmp ); + frac_ee = Log2_norm_lc( L_shl( Ltmp, exp_ee ) ); + exp_ee = sub( 30 - 11, exp_ee ); + Ltmp = Mpy_32_16( exp_ee, frac_ee, LG10 ); /* Ltmp Q14 */ + een = round_fx( L_shl( Ltmp, 16 - 5 ) ); /* Q14 -> Q9 */ + een = mac_r( C_EE_FX, een, K_EE_FX ); + } } + /* compute zero crossing rate */ pt1 = speech + sub( L_look, 1 ); tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */ @@ -114,6 +145,7 @@ Word16 signal_clas_fx( /* o : classification for current pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) ); st->tdm_pc = pc; move16(); + /*-----------------------------------------------------------------* * Transform parameters to the range <0:1> * Compute the merit function @@ -241,8 +273,8 @@ Word16 signal_clas_fx( /* o : classification for current BREAK; } } - /* Onset classification */ + /* Onset classification */ /* tc_cnt == -1: frame after TC frame in continuous block of GC/VC frames */ /* tc_cnt == 0: UC frame */ /* tc_cnt == 1: onset/transition frame, coded by GC coder type */ @@ -266,9 +298,11 @@ Word16 signal_clas_fx( /* o : classification for current st->tc_cnt = -1; move16(); } + return clas; } +#ifndef FIX_2404_HARM_SIGNAL_CLAS Word16 signal_clas_ivas_fx( /* o : classification for current frames */ Encoder_State *st, /* i/o: encoder state structure */ const Word16 *speech, /* i : pointer to speech signal for E computation in Qx */ @@ -498,6 +532,7 @@ Word16 signal_clas_ivas_fx( /* o : classification for cur } return clas; } +#endif /*-------------------------------------------------------------------* * select_TC_fx() @@ -519,6 +554,7 @@ void select_TC_fx( * Select TC coder type for appropriate frames which is in general VOICED_TRANSITION, * VOICED_CLAS or ONSET frames following UNVOICED_CLAS frames *---------------------------------------------------------------------*/ + test(); IF( localVAD != 0 && GE_16( tc_cnt, 1 ) ) { @@ -540,6 +576,7 @@ void select_TC_fx( return; } + /*-------------------------------------------------------------------* * coder_type_modif_fx() * @@ -548,14 +585,12 @@ void select_TC_fx( void coder_type_modif_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 relE /* i : frame relative E to the long term average Q8*/ + const Word16 relE /* i : frame relative E to the long term average */ ) { Word16 unmod_coder_type, vbr_generic_ho; - SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - IF( st->Opt_SC_VBR ) { vbr_generic_ho = hSC_VBR->vbr_generic_ho; @@ -583,8 +618,8 @@ void coder_type_modif_fx( test(); test(); test(); - if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || - ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) + if ( ( st->element_mode == EVS_MONO && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || + ( st->element_mode > EVS_MONO && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) { st->coder_type = GENERIC; move16(); @@ -610,8 +645,7 @@ void coder_type_modif_fx( test(); test(); test(); - if ( st->localVAD == 0 && ( ( - EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) || + if ( st->localVAD == 0 && ( ( EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) || EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) ) ) @@ -620,9 +654,7 @@ void coder_type_modif_fx( move16(); } - test(); - test(); - IF( EQ_16( st->Opt_SC_VBR, 1 ) ) + if ( EQ_16( st->Opt_SC_VBR, 1 ) ) { test(); if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) ) @@ -636,145 +668,20 @@ void coder_type_modif_fx( hSC_VBR->vbr_generic_ho = 0; move16(); } - } - hSC_VBR->last_7k2_coder_type = st->coder_type; - move16(); - test(); - if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) ) - { - hSC_VBR->last_7k2_coder_type = GENERIC; - move16(); - } - - IF( st->element_mode == 0 ) - { - /* At higher rates and with 16kHz core, allow only GC and TC coder type */ - test(); - test(); - // test(); - if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) ) + IF( NE_16( st->element_mode, EVS_MONO ) ) { - /* onset/transition frame is always coded using GC mode */ - st->coder_type = GENERIC; - move16(); - } - } - ELSE /*IVAS*/ - { - /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */ - test(); - test(); - test(); - if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) || - ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) - { - st->coder_type = GENERIC; + hSC_VBR->last_7k2_coder_type = st->coder_type; move16(); + test(); + if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) ) + { + hSC_VBR->last_7k2_coder_type = GENERIC; + move16(); + } } } - - /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */ - test(); - test(); - test(); - if ( EQ_16( st->coder_type, VOICED ) && st->input_bwidth == 0 && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) ) - { - st->coder_type = GENERIC; - move16(); - } - } - - return; -} -void coder_type_modif_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 relE /* i : frame relative E to the long term average */ -) -{ - Word16 unmod_coder_type, vbr_generic_ho; - - SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - - - IF( st->Opt_SC_VBR ) - { - vbr_generic_ho = hSC_VBR->vbr_generic_ho; - move16(); - } - ELSE - { - vbr_generic_ho = -1; - move16(); - } - - IF( EQ_16( st->codec_mode, MODE1 ) ) - { - /*---------------------------------------------------------------------* - * Coder type modification - * - * Prevent UC coder type in certain conditions - * Prevent VC coder type in certain conditions - * Select TC coder type in appropriate frames - *---------------------------------------------------------------------*/ - - /* At higher rates, use GC coding instead of UC coding to improve quality */ - test(); - test(); - test(); - test(); - test(); - if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || - ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) - { - st->coder_type = GENERIC; - move16(); - } - - /* Prevent UC coding on mixed content at 9.6 kb/s */ - test(); - test(); - if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - st->coder_type = GENERIC; - move16(); - } - - unmod_coder_type = st->coder_type; - move16(); - - /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( st->localVAD == 0 && ( ( - EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) || - EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) ) - - ) - { - st->coder_type = GENERIC; - move16(); - } - - if ( EQ_16( st->Opt_SC_VBR, 1 ) ) - { - test(); - if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) ) - { - hSC_VBR->vbr_generic_ho = 1; - move16(); - } - - if ( GT_16( st->coder_type, UNVOICED ) ) - { - hSC_VBR->vbr_generic_ho = 0; - move16(); - } - hSC_VBR->last_7k2_coder_type = st->coder_type; move16(); test(); @@ -785,7 +692,7 @@ void coder_type_modif_ivas_fx( } } - IF( st->element_mode == 0 ) + IF( st->element_mode == EVS_MONO ) { /* At higher rates and with 16kHz core, allow only GC and TC coder type */ test(); diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index d3cc666f6b30b81aaff7b4330c35b046776f99fc..9db4b6b042077b0d2bd22d0098e95ae72354eefa 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -14,7 +14,6 @@ #ifdef DEBUGGING #include "debug.h" #endif -#include #include "ivas_prot_fx.h" @@ -37,6 +36,18 @@ #define THR_MASS_STEP_UP_FX 41943 /* 0.01f in Q22 */ #define THR_MASS_STEP_DN_FX 83886 /* 0.02f in Q22 */ +// Q18 +static Word32 log_weights_speech_compute[N_SMC_MIXTURES] = { + -578045, -483403, -473370, -468152, -379470, -473234 +}; +static Word32 log_weights_music_compute[N_SMC_MIXTURES] = { + -486797, -522830, -315523, -429999, -775981, -477255 +}; +static Word32 log_weights_noise_compute[N_SMC_MIXTURES] = { + -439941, -576743, -269243, -645452, -529228, -542196 +}; + + /*---------------------------------------------------------------------* * Local functions *---------------------------------------------------------------------*/ @@ -56,22 +67,15 @@ static Word16 attack_det_fx( const Word16 *inp, const Word16 Qx, const Word16 la static void order_spectrum_fx( Word16 *vec, Word16 len ); static void detect_sparseness_fx( Encoder_State *st_fx, const Word16 localVAD_HE_SAD, const Word16 voi_fv ); -// Q18 -Word32 log_weights_speech_compute[N_SMC_MIXTURES] = { - -578045, -483403, -473370, -468152, -379470, -473234 -}; -Word32 log_weights_music_compute[N_SMC_MIXTURES] = { - -486797, -522830, -315523, -429999, -775981, -477255 -}; -Word32 log_weights_noise_compute[N_SMC_MIXTURES] = { - -439941, -576743, -269243, -645452, -529228, -542196 -}; + + /*---------------------------------------------------------------------* * speech_music_clas_init_fx() * * Initialization of speech/music classifier *---------------------------------------------------------------------*/ +#ifndef FIX_2405_HARM_SMC_INIT void speech_music_clas_init_fx( SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ) @@ -224,67 +228,40 @@ void speech_music_clas_init_fx( } void speech_music_clas_init_ivas_fx( - SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ +#else +void speech_music_clas_init_fx( + const Word16 element_mode, /* i : element mode */ +#endif + SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ + ) { Word16 i; - set32_fx( hSpMusClas->FV_st_fx, 0, N_SMC_FEATURES ); - hSpMusClas->inact_cnt = 0; move16(); set16_fx( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); - set32_fx( hSpMusClas->past_dlp_mean_ST_fx, 0, HANG_LEN - 1 ); - hSpMusClas->dlp_mean_ST_fx = 0; - move32(); - hSpMusClas->dlp_mean_LT_fx = 0; - move32(); - hSpMusClas->dlp_var_LT_fx = 0; - move32(); - - FOR( i = 0; i < N_SMC_FEATURES; i++ ) - { - hSpMusClas->prev_FV_fx[i] = L_add( L_shr( hout_intervals_fx[2 * i], 1 ), L_shr( hout_intervals_fx[2 * i + 1], 1 ) ); - move32(); - } - - FOR( i = 0; i < NB_BANDS_SPMUS; i++ ) - { - hSpMusClas->past_log_enr_fx[i] = -1448; /* log(E_MIN) in Q8 */ - move16(); - } + set16_fx( hSpMusClas->past_log_enr_fx, -1448, NB_BANDS_SPMUS ); /* log(E_MIN) in Q8 */ hSpMusClas->sp_mus_state = -8; move16(); - hSpMusClas->wdrop_32fx = 0; - move32(); - hSpMusClas->wrise_fx = 0; + hSpMusClas->wdrop_fx = 0; move16(); + hSpMusClas->wdlp_0_95_sp_fx = 0; move16(); - hSpMusClas->wdlp_0_95_sp_32fx = 0; - move32(); - hSpMusClas->wdlp_xtalk_fx = 0; - move16(); set16_fx( hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS ); hSpMusClas->last_cor_map_sum_fx = 0; move16(); hSpMusClas->last_non_sta_fx = 0; move16(); set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); - hSpMusClas->past_PS_Q = Q31; - move16(); hSpMusClas->past_ps_diff_fx = 0; move16(); hSpMusClas->past_epsP2_fx = 1024; /* 1.0f in Q10 */ move16(); - hSpMusClas->past_epsP_fx = 0; - move16(); - hSpMusClas->flag_spitch_cnt = 0; - move16(); - hSpMusClas->gsc_thres_fx[0] = TH_0_MIN_FX; move16(); @@ -310,19 +287,6 @@ void speech_music_clas_init_ivas_fx( hSpMusClas->last_sw_dyn_fx = 2560; /* 10.0f in Q7 */ move16(); - hSpMusClas->relE_attack_cnt = 0; - move16(); - hSpMusClas->prev_relE_fx = 0; - move16(); - hSpMusClas->prev_Etot_fx = 0; - move16(); - hSpMusClas->prev_vad = 0; - move16(); - hSpMusClas->vad_0_1_cnt = 0; - move16(); - hSpMusClas->relE_attack_sum_fx = 0; - move16(); - /* speech/music classifier improvement */ FOR( i = 0; i < BUF_LEN; i++ ) { @@ -352,8 +316,6 @@ void speech_music_clas_init_ivas_fx( move16(); hSpMusClas->gsc_cnt = 0; move16(); - hSpMusClas->last_vad_spa = 0; - move16(); set16_fx( hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E ); set16_fx( hSpMusClas->buf_etot_fx, 0, 4 ); @@ -378,30 +340,18 @@ void speech_music_clas_init_ivas_fx( hSpMusClas->old_lt_diff_fx[1] = 0; move16(); - set32_fx( hSpMusClas->finc_prev_fx, 0, ATT_NSEG ); - hSpMusClas->q_finc_prev = Q31; - move16(); - hSpMusClas->lt_finc_fx = 0; - move32(); - hSpMusClas->Q_lt_finc = Q31; - move16(); - - hSpMusClas->last_strong_attack = 0; + /* GSC - pitch excitation parameters */ + hSpMusClas->high_stable_cor = 0; move16(); - hSpMusClas->tdm_lt_Etot_fx = 3; /* 0.01f in Q8 */ + set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); + hSpMusClas->lps_fx = 0; move16(); - set32_fx( hSpMusClas->tod_lt_Bin_E_fx, 0, TOD_NSPEC ); - hSpMusClas->Q_tod_lt_Bin_E = Q31; + hSpMusClas->lpm_fx = 0; move16(); - set32_fx( hSpMusClas->tod_S_map_lt_fx, 0, TOD_NSPEC ); - hSpMusClas->tod_thr_lt_fx = TOD_THR_MASS_FX_Q22; - move32(); - hSpMusClas->tod_weight_fx = 0; + hSpMusClas->lt_dec_thres_fx = 5120; + move16(); /*10 in Q9 */ + hSpMusClas->ener_RAT_fx = 0; move16(); - hSpMusClas->tod_S_mass_prev_fx = 0; - move32(); - hSpMusClas->tod_S_mass_lt_fx = 0; - move32(); /* speech/music classification */ set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); @@ -429,25 +379,84 @@ void speech_music_clas_init_ivas_fx( hSpMusClas->lt_speech_hangover = 0; move16(); - hSpMusClas->lt_dec_thres_fx = 5120; /* 10.0f in Q9 */ - move16(); - hSpMusClas->ener_RAT_fx = 0; - move16(); +#ifdef FIX_2405_HARM_SMC_INIT + IF( element_mode > EVS_MONO ) + { + set32_fx( hSpMusClas->FV_st_fx, 0, N_SMC_FEATURES ); + set32_fx( hSpMusClas->past_dlp_mean_ST_fx, 0, HANG_LEN - 1 ); + hSpMusClas->dlp_mean_ST_fx = 0; + move32(); + hSpMusClas->dlp_mean_LT_fx = 0; + move32(); + hSpMusClas->dlp_var_LT_fx = 0; + move32(); - hSpMusClas->high_stable_cor = 0; - move16(); - set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); + FOR( i = 0; i < N_SMC_FEATURES; i++ ) + { + hSpMusClas->prev_FV_fx[i] = L_add( L_shr( hout_intervals_fx[2 * i], 1 ), L_shr( hout_intervals_fx[2 * i + 1], 1 ) ); + move32(); + } + hSpMusClas->wdrop_32fx = 0; + move32(); + hSpMusClas->wrise_fx = 0; + move16(); + hSpMusClas->wdlp_0_95_sp_32fx = 0; + move32(); + hSpMusClas->wdlp_xtalk_fx = 0; + move16(); + hSpMusClas->past_PS_Q = Q31; + move16(); + hSpMusClas->past_epsP_fx = 0; + move16(); + hSpMusClas->flag_spitch_cnt = 0; + move16(); + hSpMusClas->relE_attack_cnt = 0; + move16(); + hSpMusClas->prev_relE_fx = 0; + move16(); + hSpMusClas->prev_Etot_fx = 0; + move16(); + hSpMusClas->prev_vad = 0; + move16(); + hSpMusClas->vad_0_1_cnt = 0; + move16(); + hSpMusClas->relE_attack_sum_fx = 0; + move16(); + hSpMusClas->last_vad_spa = 0; + move16(); + set32_fx( hSpMusClas->finc_prev_fx, 0, ATT_NSEG ); + hSpMusClas->q_finc_prev = Q31; + move16(); + hSpMusClas->lt_finc_fx = 0; + move32(); + hSpMusClas->Q_lt_finc = Q31; + move16(); - hSpMusClas->lps_fx = 0; - move16(); - hSpMusClas->lpm_fx = 0; - move16(); - hSpMusClas->lpn_fx = 0; - move16(); + hSpMusClas->last_strong_attack = 0; + move16(); + hSpMusClas->tdm_lt_Etot_fx = 3; /* 0.01f in Q8 */ + move16(); + set32_fx( hSpMusClas->tod_lt_Bin_E_fx, 0, TOD_NSPEC ); + hSpMusClas->Q_tod_lt_Bin_E = Q31; + move16(); + set32_fx( hSpMusClas->tod_S_map_lt_fx, 0, TOD_NSPEC ); + hSpMusClas->tod_thr_lt_fx = TOD_THR_MASS_FX_Q22; + move32(); + hSpMusClas->tod_weight_fx = 0; + move16(); + hSpMusClas->tod_S_mass_prev_fx = 0; + move32(); + hSpMusClas->tod_S_mass_lt_fx = 0; + move32(); + hSpMusClas->lpn_fx = 0; + move16(); + } +#endif return; } + /*---------------------------------------------------------------------* * speech_music_classif() * @@ -492,8 +501,6 @@ void speech_music_classif_fx( test(); IF( EQ_16( st->codec_mode, MODE1 ) || EQ_32( st->sr_core, INT_FS_12k8 ) ) { - - /* Improvement of the 1st stage decision on mixed/music content */ test(); IF( st->Opt_SC_VBR == 0 && NE_32( st->total_brate, ACELP_24k40 ) ) @@ -523,7 +530,6 @@ void speech_music_classif_fx( } } - /* Context-based improvement of 1st and 2nd stage decision on stable tonal signals */ test(); IF( st->Opt_SC_VBR == 0 && NE_32( st->total_brate, ACELP_24k40 ) ) @@ -596,26 +602,28 @@ void speech_music_classif_fx( return; } + /*---------------------------------------------------------------------* * sp_mus_classif_gmm_fx() * * Speech/music classification based on GMM model *---------------------------------------------------------------------*/ -static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech or noise) */ - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 localVAD_HE_SAD, /* i : local VAD HE flag */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ - const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp */ - const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 *voi_fv, /* o : scaled voicing feature */ - Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ - Word16 *LPCErr, /* o : scaled LP prediction error feature */ - Word16 Q_esp, /* i : scaling of epsP */ - Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ +/* o : decision flag (1-music, 0-speech or noise) */ +static Word16 sp_mus_classif_gmm_fx( + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 localVAD_HE_SAD, /* i : local VAD HE flag */ + const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ + const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ + const Word32 epsP[M + 1], /* i : LP prediciton error Q_esp */ + const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ + Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ + Word16 relE, /* i : relative frame energy */ + Word16 *voi_fv, /* o : scaled voicing feature */ + Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ + Word16 *LPCErr, /* o : scaled LP prediction error feature */ + Word16 Q_esp, /* i : scaling of epsP */ + Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ ) { Word16 i, k, p, dec, vad; @@ -929,7 +937,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis *LPCErr = FV[9]; move16(); - /*------------------------------------------------------------------* * Calculation of posterior probability * Log-probability @@ -940,7 +947,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /* pyn = 1e-5f;*/ max_n = L_add( MIN_32, 0 ); - FOR( k = 0; k < N_MIXTURES; k++ ) { /* for each mixture, calculate the probability of speech or noise and the probability of music */ @@ -957,7 +963,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis py_s = L_add( lvm_speech_fx[k], L_tmp ); /*Q10 */ max_s = L_max( py_s, max_s ); - /* pys += (float)exp(py); */ /* inactive frames - calculate the probability of noise */ @@ -1013,7 +1018,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis move16(); } - IF( !vad ) { /* increase log-probability of noise */ @@ -1154,7 +1158,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /*wrelE = 1.0f + relE/15;*/ wrelE = add( 2048, mult_r( relE, 17476 ) ); /* 1/15 in Q18 -> 17476 result in Q11 */ - wrelE = s_min( wrelE, 2048 ); wrelE = s_max( wrelE, 20 ); @@ -1256,7 +1259,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis } } - /*------------------------------------------------------------------* * Updates *------------------------------------------------------------------*/ @@ -1441,13 +1443,14 @@ static void var_cor_calc_fx( * Attack detection *---------------------------------------------------------------------*/ -static Word16 attack_det_fx( /* o : attack flag */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 last_clas, /* i : last signal clas */ - const Word16 localVAD, /* i : local VAD flag */ - const Word16 coder_type, /* i : coder type */ - const Word32 total_brate /* i : total bitrate */ +/* o : attack flag */ +static Word16 attack_det_fx( + const Word16 *inp, /* i : input signal */ + const Word16 Qx, + const Word16 last_clas, /* i : last signal clas */ + const Word16 localVAD, /* i : local VAD flag */ + const Word16 coder_type, /* i : coder type */ + const Word32 total_brate /* i : total bitrate */ ) { Word16 i, j, tmp, tmp1, attack, exp1; @@ -1563,11 +1566,13 @@ static Word16 attack_det_fx( /* o : attack flag return attack; } -/* -------------------------------------------------------------------- - * + +/* --------------------------------------------------------------------- * *ivas_smc_gmm() * *1st stage of the speech / music classification(based on the GMM model) - * -------------------------------------------------------------------- - */ + * --------------------------------------------------------------------- */ + /*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ Word16 ivas_smc_gmm_fx( Encoder_State *st, /* i/o: state structure */ @@ -1615,12 +1620,9 @@ Word16 ivas_smc_gmm_fx( Word16 temp16; Word16 dotp_exp = 0; move16(); - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; Word32 temp_sqrt, temp_acos; + /*------------------------------------------------------------------* * State machine (sp_mus_state: -8 = INACTIVE, -7:-1 = UNSTABLE, 0:7 = ENTRY, 8 = STABLE ) *------------------------------------------------------------------*/ @@ -1850,7 +1852,6 @@ Word16 ivas_smc_gmm_fx( temp16 = lsp_new_fx[6]; move16(); - temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 temp_sqrt = Sqrt32( temp32, &temp_exp ); temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); @@ -2004,7 +2005,7 @@ Word16 ivas_smc_gmm_fx( temp32_log = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ *pFV_fx++ = L_shr( temp32_log, Q5 ); // logf( ps_sta + 1e-5f ); move32(); - MVR2R_WORD32( &PS_norm_fx[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN - LOWEST_FBIN ); + Copy32( &PS_norm_fx[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN - LOWEST_FBIN ); /* save ps_diff and ps_sta features for XTALK and UNCLR classifier */ IF( hStereoClassif != NULL ) @@ -2032,6 +2033,7 @@ Word16 ivas_smc_gmm_fx( /*------------------------------------------------------------------* * Outlier detection based on feature histograms *------------------------------------------------------------------*/ + flag_odv = 0; move16(); IF( localVAD_HE_SAD ) @@ -2071,6 +2073,7 @@ Word16 ivas_smc_gmm_fx( /*------------------------------------------------------------------* * Adaptive short-term mean filter on feature vector *------------------------------------------------------------------*/ + Qfact_FV = 20; move16(); pFV_fx = FV_fx; @@ -2109,10 +2112,12 @@ Word16 ivas_smc_gmm_fx( } /* update */ - MVR2R_WORD32( FV_fx, hSpMusClas->prev_FV_fx, N_SMC_FEATURES ); + Copy32( FV_fx, hSpMusClas->prev_FV_fx, N_SMC_FEATURES ); + /*------------------------------------------------------------------* * Non-linear power transformation (boxcox) on certain features *------------------------------------------------------------------*/ + pFV_fx = FV_fx; FOR( i = 0; i < N_SMC_FEATURES; i++ ) { @@ -2235,6 +2240,7 @@ Word16 ivas_smc_gmm_fx( * Decision without hangover * Weighted decision *------------------------------------------------------------------*/ + test(); test(); test(); @@ -2314,7 +2320,6 @@ Word16 ivas_smc_gmm_fx( move16(); } - wrise_fx = lin_interp32_fx( L_deposit_h( hSpMusClas->wrise_fx ), 167772160, 2040109466 /* 0.95 in Q31 */, 0, ONE_IN_Q31 /* 1.0f in Q31 */, 1 ); /* Q31 */ /* combine weights into one */ // wght = wrelE * wdrop * wrise; @@ -2497,6 +2502,7 @@ Word16 ivas_smc_gmm_fx( /*------------------------------------------------------------------* * raw S/M decision based on smoothed GMM score *------------------------------------------------------------------*/ + test(); IF( dec == 0 || st->hSpMusClas->wdlp_0_95_sp_32fx <= 0 ) { @@ -2510,6 +2516,7 @@ Word16 ivas_smc_gmm_fx( } move16(); move16(); + /*------------------------------------------------------------------* * Updates *------------------------------------------------------------------*/ @@ -2534,6 +2541,7 @@ Word16 ivas_smc_gmm_fx( return dec; } + /*---------------------------------------------------------------------* * var_cor_calc_ivas_fx() * @@ -2583,20 +2591,21 @@ static void var_cor_calc_ivas_fx( * Attack detection *---------------------------------------------------------------------*/ -static Word16 attack_det_ivas_fx( /* o : attack flag */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 last_clas, /* i : last signal clas */ - const Word16 localVAD, /* i : local VAD flag */ - const Word16 coder_type, /* i : coder type */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 clas, /* i : signal class */ - Word32 finc_prev[], /* i/o: previous finc, (q_finc_prev) */ - Word16 *q_finc_prev, /* i/o: Q of previous finc */ - Word32 *lt_finc, /* i/o: long-term mean finc, (q_lt_finc) */ - Word16 *q_lt_finc, /* i/o: Q of lt_finc */ - Word16 *last_strong_attack /* i/o: last strong attack flag */ +/* o : attack flag */ +static Word16 attack_det_ivas_fx( + const Word16 *inp, /* i : input signal */ + const Word16 Qx, + const Word16 last_clas, /* i : last signal clas */ + const Word16 localVAD, /* i : local VAD flag */ + const Word16 coder_type, /* i : coder type */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 clas, /* i : signal class */ + Word32 finc_prev[], /* i/o: previous finc, (q_finc_prev) */ + Word16 *q_finc_prev, /* i/o: Q of previous finc */ + Word32 *lt_finc, /* i/o: long-term mean finc, (q_lt_finc) */ + Word16 *q_lt_finc, /* i/o: Q of lt_finc */ + Word16 *last_strong_attack /* i/o: last strong attack flag */ ) { Word16 i, j, tmp, tmp1, attack, exp1, etmp_e, etmp2_e, s; @@ -2635,6 +2644,7 @@ static Word16 attack_det_ivas_fx( /* o : attack flag *q_finc_prev = shl( Qx, 1 ); // Q of finc move16(); q_diff = sub( *q_finc_prev, *q_lt_finc ); + test(); IF( EQ_16( localVAD, 1 ) && EQ_16( coder_type, GENERIC ) ) { @@ -2661,7 +2671,6 @@ static Word16 attack_det_ivas_fx( /* o : attack flag move32(); etmp_e = sub( 31, add( *q_finc_prev, sub( s, add( exp1, 18 ) ) ) ); - tmp1 = sub( ATT_NSEG, attack ); exp1 = norm_s( tmp1 ); tmp = div_s( shl( 1, sub( 14, exp1 ) ), tmp1 ); /*Q(29-exp1) */ @@ -2798,6 +2807,7 @@ static Word16 attack_det_ivas_fx( /* o : attack flag return attack; } + /*---------------------------------------------------------------------* * tonal_det() * @@ -2904,12 +2914,12 @@ void ivas_smc_mode_selection_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word32 element_brate, /* i : element bitrate */ Word16 smc_dec, /* i : raw decision of the 1st stage classifier*/ - const Word16 relE, /* i : relative frame energy, Q8 */ - const Word16 Etot, /* i : total frame energy, Q8 */ + const Word16 relE, /* i : relative frame energy, Q8 */ + const Word16 Etot, /* i : total frame energy, Q8 */ Word16 *attack_flag, /* i/o: attack flag (GSC or TC) */ const Word16 *inp, /* i : input signal */ - const Word16 Q_new, /* i : Q of input signal */ - const Word16 S_map[], /* i : short-term correlation map, Q7 */ + const Word16 Q_new, /* i : Q of input signal */ + const Word16 S_map[], /* i : short-term correlation map, Q7 */ const Word16 flag_spitch /* i : flag to indicate very short stable pitch*/ ) { @@ -3133,8 +3143,8 @@ void ivas_smc_mode_selection_fx( st->sp_aud_decision2 = 1; } } -#endif +#endif /* set GSC noisy speech flag on unvoiced SWB segments */ st->GSC_noisy_speech = 0; move16(); @@ -3199,6 +3209,7 @@ void ivas_smc_mode_selection_fx( return; } + /*---------------------------------------------------------------------* * mode_decision_fx() * @@ -3235,7 +3246,6 @@ static Word16 mode_decision_fx( Word16 M_flux10; SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; - mode = *dec_mov > 16384; logic16(); move16(); @@ -3476,6 +3486,7 @@ static Word16 mode_decision_fx( return ( mode ); } + /*---------------------------------------------------------------------* * tonal_dist_fx() * @@ -3496,7 +3507,6 @@ static void tonal_dist_fx( Word16 Ntonal2; Word16 Ntonal_lf; - /* find number of tonals, number of tonals at low-band, spectral peakiness at high-band */ pk = L_deposit_l( 0 ); @@ -3560,6 +3570,7 @@ static void tonal_dist_fx( return; } + /*---------------------------------------------------------------------* * flux_fx() * @@ -3645,6 +3656,7 @@ static void flux_fx( return; } + /*---------------------------------------------------------------------* * spec_analysis_fx() * @@ -3761,8 +3773,17 @@ static void spec_analysis_fx( p2v_map[peak_idx[i]] = p2v[i]; move16(); } + + return; } + +/*---------------------------------------------------------------------* + * music_mixed_classif_improv_fx() + * + * + *---------------------------------------------------------------------*/ + static void music_mixed_classif_improv_fx( Encoder_State *st, /* i : encoder state structure */ const Word16 *new_inp, /* i : new input signal */ @@ -4135,9 +4156,9 @@ static void music_mixed_classif_improv_fx( static void tonal_context_improv_fx( Encoder_State *st_fx, /* i/o: Encoder state structure */ const Word32 PS[], /* i : energy spectrum */ - const Word16 voi_fv, /* i : scaled voicing feature */ - const Word16 cor_map_sum_fv, /* i : scaled correlation map feature */ - const Word16 LPCErr, /* i : scaled LP prediction error feature */ + const Word16 voi_fv, /* i : scaled voicing feature */ + const Word16 cor_map_sum_fv, /* i : scaled correlation map feature */ + const Word16 LPCErr, /* i : scaled LP prediction error feature */ const Word16 Qx ) { Word16 t2_fx, t3_fx, tL_fx, err_fx, cor_fx, dft_fx; @@ -4500,11 +4521,13 @@ static void tonal_context_improv_fx( return; } + /*----------------------------------------------------------------------------------* * detect_sparseness_fx() * * *----------------------------------------------------------------------------------*/ + static void detect_sparseness_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ @@ -4862,6 +4885,7 @@ static void detect_sparseness_fx( * * *---------------------------------------------------------------------*/ + static void order_spectrum_fx( Word16 *vec, Word16 len ) @@ -4924,4 +4948,6 @@ static void order_spectrum_fx( vec[imin] = tmp; move16(); } + + return; } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index bcd7ed72cc1b9ced61ed6a65a5d2497184c9bea9..be38f731c6a0473550fe1f3e774f5b23c7851c85 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 6e4e8b391b18c386157accd005f101464f2bfe68..8dfd67076144aedb036372781aa67da3cd9a71b9 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -262,6 +262,7 @@ void wb_bwe_enc_ivas_fx( * * SWB BWE encoder (only for 32kHz signals) *-------------------------------------------------------------------*/ + void swb_bwe_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 last_element_mode, /* i : last element mode */ @@ -270,9 +271,8 @@ void swb_bwe_enc_ivas_fx( const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ const Word16 Q_new_swb_speech, /* i : Q for new_swb_speech_fx */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - Word16 Q_shb_speech, - Word16 Q_slb_speech ) + Word16 *shb_speech_fx_Q0, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + const Word16 Q_slb_speech ) { Word16 i; Word16 *new_input_fx; @@ -304,14 +304,19 @@ void swb_bwe_enc_ivas_fx( move16(); Word16 fb_band_begin; Word16 q_new_input_hp; + Word16 shb_speech_fx[L_FRAME16k]; + Word16 Q_shb_speech; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + Q_shb_speech = getScaleFactor16( shb_speech_fx_Q0, L_FRAME16k ); + Copy_Scale_sig( shb_speech_fx_Q0, shb_speech_fx, L_FRAME16k, Q_shb_speech ); // Q0 -> Q_shb_spch /*---------------------------------------------------------------------* * Delay the original input signal to be synchronized with ACELP core synthesis *---------------------------------------------------------------------*/ + IF( EQ_16( st_fx->extl, FB_BWE ) ) { inner_frame = L_FRAME48k; diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 7d31b853227d173efe2dc852d87cb0d33b3d8369..843efcf49bbea3b798e082f1cba583ae184e685d 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -1024,203 +1024,7 @@ static void EncodeSWBSubbands_fx( return; } -static void EncodeSWBSubbands_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value for L_spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 nBands_search_fx, /* i : number of subbands to be searched for BWE */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : Subband offset for BWE */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 BANDS_fx, /* i : noise estimate from WB part */ - const Word16 *band_start_fx, /* i : Number subbands/Frame */ - const Word16 *band_end_fx, /* i : Band Start of each SB */ - Word32 *L_band_energy, /* i : Band end of each SB, :Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - const Word16 *p2a_flags_fx, /* i : BAnd energy of each SB */ - const Word16 hqswb_clas_fx, /* i : lowband synthesis */ - Word16 *prev_frm_index_fx, /* i : clas information */ - const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ - const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band width */ - const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ - Word16 *ni_seed_fx /* i/o: random seed */ -) -{ - Word16 i, k; - Word16 sspectra_fx[L_FRAME32k]; - Word16 sspectra_ni_fx[L_FRAME32k]; - Word16 sspectra_diff_fx[L_FRAME32k]; - Word16 Qss; /* Q value of Smoothed Spectrum low-subband */ - Word32 L_be_tonal[SWB_HAR_RAN1]; /* Q */ - Word16 ss_min_fx; /* Qss */ - Word32 L_th_g[NB_SWB_SUBBANDS]; - Word16 QbeL; - GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8]; - Word16 pul_res_fx[NB_SWB_SUBBANDS]; - - GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH]; - - Word32 L_xSynth_har[L_FRAME32k]; /* Qs */ - - Word16 lagGains_fx[NB_SWB_SUBBANDS]; - Word16 QlagGains[NB_SWB_SUBBANDS]; - Word16 har_freq_est1, har_freq_est2; - Word16 flag_dis; - Word16 pos_max_hfe2; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - flag_dis = 1; - move16(); - pos_max_hfe2 = 0; - move16(); - - set16_fx( sspectra_fx, 0, fLenLow_fx ); - set16_fx( sspectra_ni_fx, 0, fLenLow_fx ); - set32_fx( L_xSynth_har, 0, L_FRAME32k ); - set16_fx( pul_res_fx, 0, NB_SWB_SUBBANDS ); - - - IF( EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) - { - pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2 ); - noise_extr_corcod_fx( L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &hHQ_core->prev_ni_ratio_fx, &Qss ); - /* Find best indices for each group */ - getswbindices_har_fx( - L_spectra, - QsL, sspectra_ni_fx, - nBands_search_fx, lagIndices_fx, prev_frm_index_fx, fLenLow_fx, subband_offsets_fx, sbWidth_fx, subband_search_offset_fx ); - - /* Write the indices into the bitstream */ - FOR( k = 0; k < nBands_search_fx; k++ ) - { - push_indice( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har[k] ); - } - - IF( flag_dis == 0 ) - { - test(); - IF( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) - { - har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] ); - move16(); - } - } - - gethar_noisegn_fx( st_fx->hBstr, L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har, - sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx, - subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx, - L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx, - har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx ); - - - Gettonl_scalfact_fx( L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, - p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx, Qss, pul_res_fx ); - - IF( flag_dis == 0 ) - { - *prev_frm_hfe2 = 0; - move16(); - } - ELSE - { - *prev_frm_hfe2 = har_freq_est2; - move16(); - } - - FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; - move32(); /* QsL */ - } - } - } - ELSE - { - ss_min_fx = spectrumsmooth_noiseton_fx( L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx ); - - /* Get lag indices */ - GetSWBIndices_fx( sspectra_fx, /*Qss,*/ L_spectra + fLenLow_fx, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, - Nbiggest_fx, subband_offsets_fx, sspectra_fx ); - - /* Bitstream operations */ - FOR( k = 0; k < nBands_fx; k++ ) - { - IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) - { - lagIndices_fx[k] = 0; - move16(); - lagGains_fx[k] = 0; - move16(); - QlagGains[k] = 15; - move16(); - } - ELSE - { - push_indice( st_fx->hBstr, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_modeNormal[k] ); - } - } - - convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); - - GetlagGains_fx( sspectra_ni_fx, Qss, &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, lagGains_fx, QlagGains ); - FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) - { - lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ - move16(); - } - - FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) - { - L_th_g[k] = L_deposit_l( 0 ); - move32(); - IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) - { - L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> QsL */ - move32(); - } - } - - GetSynthesizedSpecThinOut_fx( sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, lagGains_fx, QlagGains, fLenLow_fx ); - - /*Level adjustment for the missing bands*/ - noiseinj_hf_fx( L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, hHQ_core->prev_En_sb_fx, p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx ); - - - FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) - { - IF( p2a_flags_fx[k] == 0 ) - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; - move32(); /* Qob */ - } - } - ELSE - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_spectra_ni[i]; - move32(); - } - } - } - } - - return; -} /*--------------------------------------------------------------------------* * swb_bwe_enc_lr() * @@ -1309,87 +1113,3 @@ void swb_bwe_enc_lr_fx( return; } - -void swb_bwe_enc_lr_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, /* i : Q value */ - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ -) -{ - Word16 k; - Word16 nBands_fx; - Word16 nBands_search_fx; - Word16 wBands_fx[NB_SWB_SUBBANDS]; - Word16 lagIndices_fx[NB_SWB_SUBBANDS]; - Word16 swb_lowband_fx, swb_highband_fx, allband_fx; - - const Word16 *subband_offsets_fx; - const Word16 *subband_search_offset_fx; - - Word32 *p_L_m; - - subband_search_offset_fx = subband_search_offsets_13p2kbps_Har; - subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har; - - hf_parinitiz_fx( L_total_brate, hqswb_clas_fx, lowlength_fx, highlength_fx, wBands_fx, &subband_search_offset_fx, &subband_offsets_fx, &nBands_fx, &nBands_search_fx, &swb_lowband_fx, &swb_highband_fx ); - allband_fx = add( swb_lowband_fx, swb_highband_fx ); - move16(); - - /* Prepare m[], low part from WB core, high part from 32k input */ - Copy32( L_m_core, L_m, swb_lowband_fx ); - Copy32( &L_m_orig[swb_lowband_fx], &L_m[swb_lowband_fx], swb_highband_fx ); - - EncodeSWBSubbands_ivas_fx( - st_fx, - L_m, QsL, - swb_lowband_fx, swb_highband_fx, nBands_fx, nBands_search_fx, wBands_fx, subband_offsets_fx, - lagIndices_fx, - BANDS_fx, band_start_fx, band_end_fx, - L_band_energy, Qbe, - p2a_flags_fx, - hqswb_clas_fx, prev_frm_index_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2, prev_stab_hfe2, - band_width_fx, L_y2_ni, ni_seed_fx ); - - p_L_m = &L_m[sub( allband_fx, 1 )]; - *p_L_m = Mult_32_16( *p_L_m, 2028 ); - move32(); - p_L_m--; /* 0.0625 = 2028 (Q15) */ - *p_L_m = Mult_32_16( *p_L_m, 4096 ); - move32(); - p_L_m--; /* 0.125 = 4096 (Q15) */ - *p_L_m = Mult_32_16( *p_L_m, 8192 ); - move32(); - p_L_m--; /* 0.25 = 8192 (Q15) */ - *p_L_m = Mult_32_16( *p_L_m, 16384 ); - move32(); - p_L_m--; /* 0.5 = 16384 (Q15) */ - - /* set low frequencies to zero */ - FOR( k = 0; k < swb_lowband_fx; k++ ) - { - L_m[k] = L_deposit_l( 0 ); - move32(); - } - - return; -} diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index a966f70cc61a085e6badc5da51a6e3695af3eccf..a5683b82960b11a21a50ec4a1dc2ee5381a757cb 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -449,7 +449,11 @@ void wb_pre_proc_ivas_fx( test(); test(); test(); +#ifdef FIX_2408_FD_BWE_UPDATE + IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->extl_brate, 0 ) ) ) && !ppp_mode ) +#else IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->total_brate, 0 ) ) ) && !ppp_mode ) +#endif { Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); @@ -771,17 +775,14 @@ void swb_pre_proc_fx( * - Common SWB TBE and SWB BWE pre-processing *-------------------------------------------------------------------*/ -/*full implementation pending*/ void swb_pre_proc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 *new_swb_speech, /* o : original input signal at 32kHz - st->q_inp */ - Word32 *new_swb_speech_fx, /* o : original input signal at 32kHz - Q - q_reImBuffer */ - Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */ - Word16 *Q_shb_spch, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ - Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ - CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 *new_swb_speech, /* o : original input signal at 32kHz - st->q_inp */ + Word16 *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz - Q0 */ + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer Q - q_reImbuffer */ + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer Q - q_reImbuffer */ + Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers */ + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ) { Word16 Sample_Delay_SWB_BWE, inner_frame, delay; @@ -1063,6 +1064,10 @@ void swb_pre_proc_ivas_fx( ELSE /* IVAS_CPE_DFT */ { Word16 out_start_ind, out_end_ind; + Word32 new_swb_speech_buffer_fx[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word32 *new_swb_speech_fx; + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, add( st->q_inp, add( q_reImBuffer, 1 ) ) ); // st->q_inp @@ -1125,6 +1130,7 @@ void swb_pre_proc_ivas_fx( CldfbHB_fx = EPSILON_FX; move32(); } + exp = norm_l( CldfbHB_fx ); CldfbHB_fx = L_shl( CldfbHB_fx, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) ); @@ -1271,9 +1277,7 @@ void swb_pre_proc_ivas_fx( regV = icbwe_regressionValuesTDM_fx; cldfbSynthesis_ivas_fx( realBufferFlipped, imagBufferFlipped, shb_speech_fx_32, -1, 0, 0, st->cldfbSynTd ); - Copy_Scale_sig_32_16( shb_speech_fx_32, shb_speech, L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) ); - *Q_shb_spch = 0; - move16(); + Copy_Scale_sig_32_16( shb_speech_fx_32, shb_speech, L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) ); // Q0 } IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index e2e66dd5f0d1fa10fcc1f91600433f240696412d..d6fe953257eac236750b68945cad5c705ddada2e 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -8,7 +8,6 @@ #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#include "stl.h" #include "ivas_prot_fx.h" @@ -19,6 +18,7 @@ #define ENVSHBRES_ACORR_MIN 40 /* minimum lag for calculating autocorrelation function on SHB residual TD envelope */ #define ENVSHBRES_ACORR_MAX 80 /* maximum lag for calculating autocorrelation function on SHB residual TD envelope */ + /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ @@ -30,34 +30,43 @@ static void singlevectortest_gain_fx( const Word32 *inp, const Word16 dimen, con static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, const Word16 dims ); static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); - +#ifndef HARMONIZE_TBE static void QuantizeSHBsubgains_ivas_fx( Encoder_State *st_fx, Word16 subgains[], const Word16 extl ); +#endif +#ifdef HARMONIZE_TBE +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); +#else static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind ); static void QuantizeSHBframegain_ivas_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); +#endif static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length ); static Word16 closest_centroid_lc_fx( const Word16 *data, const Word16 *quantizer, const Word16 centroids ); +#ifdef HARMONIZE_TBE +static void EstimateSHBFrameGain_fx( const Word16 element_mode, const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +#else static void EstimateSHBFrameGain_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); static void EstimateSHBFrameGain_ivas_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +#endif static void EstimateSHBGainShape_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, const Word16 *subwin, Word16 *n_subfr_saturation, const Flag limit_min_gain ); -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ); +static Word32 pow_off_pk_fx( const Word16 a[], const Word16 len, const Word16 step ); -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ); +static Word32 pow_off_pk_corrected_fx( const Word16 a[], const Word16 len, const Word16 step ); static void find_max_mem_enc( Encoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2 ); -static void rescale_genSHB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, const Word16 sf ); static void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ); -static void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void rescale_genWB_mem_enc( Encoder_State *st_fx, const Word16 sf ); static void Quant_lower_LSF_fx( const Word16 lsf[], Word16 lsf_q[], Word16 lsf_idx[] ); @@ -65,6 +74,15 @@ static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], W static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], const Word16 m ); +#ifdef HARMONIZE_TBE +static void Quant_BWE_LSF_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); + +static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, const Word16 Q_ener ); + +static void Quant_shb_res_gshape_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); + +static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); +#else static void Quant_BWE_LSF_fx( Encoder_State *st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[] ); static void Quant_BWE_LSF_ivas_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); @@ -80,6 +98,7 @@ static void Quant_shb_res_gshape_ivas_fx( Encoder_State *st, Word16 shb_res_gsha static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, const Word16 *lsp_shb_fx, Word16 *MA_lsp_shb_spacing, Word16 *frGainAttenuate, Word16 *frGainSmoothEn ); static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); +#endif /*-------------------------------------------------------------------* @@ -204,9 +223,9 @@ void find_max_mem_enc( * Rescale genSHB memories *-------------------------------------------------------------------*/ -void rescale_genSHB_mem_enc( +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, - Word16 sf ) + const Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -246,9 +265,14 @@ void rescale_genSHB_mem_enc( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) + +static void find_max_mem_wb_enc( + Encoder_State *st_fx, + Word16 *n_mem ) { Word16 i; Word16 n_mem_32; @@ -323,9 +347,14 @@ void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) move16(); *n_mem = s_max( *n_mem, 0 ); move16(); + + return; } -void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) + +static void rescale_genWB_mem_enc( + Encoder_State *st_fx, + const Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -371,6 +400,8 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } + + return; } @@ -381,8 +412,12 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) *-------------------------------------------------------------------*/ void InitSWBencBuffer_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) +#ifndef HARMONIZE_TBE { Word16 i; @@ -480,6 +515,7 @@ void InitSWBencBuffer_fx( void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) +#endif { Word16 i; @@ -561,10 +597,23 @@ void InitSWBencBuffer_ivas_fx( hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - hBWE_TD->prev_Q_bwe_exc = 15; - move16(); - hBWE_TD->prev_Q_bwe_syn = 15; - move16(); +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) + { + hBWE_TD->prev_Q_bwe_exc = 31; + move16(); + hBWE_TD->prev_Q_bwe_syn = 31; + move16(); + } + ELSE +#endif + { + hBWE_TD->prev_Q_bwe_exc = 15; + move16(); + hBWE_TD->prev_Q_bwe_syn = 15; + move16(); + } + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); @@ -644,6 +693,7 @@ void ResetSHBbuffer_Enc_fx( #define WBTBE_LPCWIN_LENGTH ( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16 - 1 void wb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ @@ -986,7 +1036,7 @@ void wb_tbe_enc_fx( GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified_fx, uv_flag, st_fx->igf ); curr_pow = 0; @@ -1122,8 +1172,13 @@ void wb_tbe_enc_fx( p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#else EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1196,7 +1251,11 @@ void wb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); +#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ @@ -1235,6 +1294,7 @@ void wb_tbe_enc_fx( /*==========================================================================*/ void wb_tbe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ @@ -1264,10 +1324,7 @@ void wb_tbe_enc_ivas_fx( Word32 LepsP[LPC_SHB_ORDER_WB + 1]; Word32 prev_pow, curr_pow, Lscale; - /* Word16 scale; */ - /*Word16 ramp_flag;*/ Word32 p2m_in, p2m_out; - /*Word16 cnt, max =0;*/ Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out, Q_cur_pow, Q_prev_pow; /* Q_hb_frame; */ Word32 L_tmp, Lmax; Word16 tmp, exp, Q_out, sc; @@ -1287,7 +1344,6 @@ void wb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; move16(); - /*Word16 att = 32767;*/ set16_fx( bwe_exc_extended_16, 0, L_FRAME32k + NL_BUFF_OFFSET ); hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; @@ -1312,34 +1368,73 @@ void wb_tbe_enc_ivas_fx( k = 0; move16(); - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; - k++; + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + } + } + ELSE +#endif + { + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + k++; + } } } - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); + } + ELSE +#endif + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); - /* Ensure R[0] isn't zero when entering Levinson-Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); + /* Ensure R[0] isn't zero when entering Levinson-Durbin */ + R_l[0] = s_max( R_l[0], 1 ); + move16(); + } E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 - move32(); - } + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); + move32(); + } - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } + ELSE +#endif + { + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 + move32(); + } + lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { @@ -1347,20 +1442,11 @@ void wb_tbe_enc_ivas_fx( move16(); } - /* lsp_spacing_fx = 16384; move16(); */ lsp_spacing_fx = lsp_wb_temp_fx[0]; move16(); FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) { - /*if ( i == 0 ) - { - tmp = lsp_wb_temp_fx[0]; move16(); - } - else - {*/ tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - /*} */ - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); } @@ -1465,7 +1551,17 @@ void wb_tbe_enc_ivas_fx( /* Quantization of LSFs */ i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ - push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); +#ifdef HARMONIZE_TBE + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + hBWE_TD->lsf_WB = i; + move16(); + } + ELSE +#endif + { + push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); + } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); @@ -1543,43 +1639,63 @@ void wb_tbe_enc_ivas_fx( prev_pow = 0; move32(); - Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_prev_pow, 3 ) ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); - move16(); + prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ } - Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); - move16(); + + Q_prev_pow = 0; + move32(); } ELSE +#endif { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_prev_pow, 3 ) ) + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); + move16(); + } + Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); + move16(); + } + ELSE { - shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + move16(); + } + Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); move16(); } - Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); - move16(); - } - IF( st_fx->element_mode > EVS_MONO ) - { tmp = sub( Q_prev_pow, 31 + 16 ); prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + } } rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } +#endif + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) { @@ -1587,69 +1703,117 @@ void wb_tbe_enc_ivas_fx( move16(); } +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } +#endif Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag, st_fx->igf ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); + } + ELSE +#endif + { + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); + } curr_pow = 0; move32(); - Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_cur_pow, 3 ) ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + } + + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + } + + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + { + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } - Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); + + Lscale = root_a_fx( Lscale, 31 - exp, &exp ); + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } ELSE +#endif { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_cur_pow, 3 ) ) { - shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + move16(); + } + Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); move16(); } - Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); - move16(); - } - IF( st_fx->element_mode > EVS_MONO ) - { + ELSE + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + move16(); + } + Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); + move16(); + } + tmp = sub( Q_cur_pow, 31 + 16 ); curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(Q_cur_pow)*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ - } - IF( GT_16( voice_factors[0], 24576 ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ - } + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ + } + + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ + } - Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); + Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) - { - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + { + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + move16(); + } + + Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } - Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - move16(); - /* Update WB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); @@ -1675,6 +1839,7 @@ void wb_tbe_enc_ivas_fx( temp_wb_fac_fx = 0; move16(); } + L_feedback = L_mult0( temp_wb_fac_fx, temp_wb_fac_fx ); FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -1753,7 +1918,11 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); /* Quantization of the subframe gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl ); +#else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape, st_fx->extl ); +#endif } /* Compute the power of gains away from the peak gain after quantization */ @@ -1767,9 +1936,13 @@ void wb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#else EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); - +#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1777,7 +1950,16 @@ void wb_tbe_enc_ivas_fx( IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) { L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); - GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } } pitBufAvg_fx = 0; @@ -1806,11 +1988,29 @@ void wb_tbe_enc_ivas_fx( } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ + } IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { - GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ + } } /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ @@ -1826,33 +2026,70 @@ void wb_tbe_enc_ivas_fx( IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 16384 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 16384 ); + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 16384 ); + } } ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ { /*GainFrame *= 0.75f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 24576 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 24576 ); + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 24576 ); + } } /* Quantization of the frame gain parameter */ IF( st_fx->rf_mode ) { +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); +#endif } ELSE { +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); +#else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); +#endif } /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ - scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); - scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); - Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); + scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); + Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); + } + ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); - Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); + } hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); @@ -1860,6 +2097,12 @@ void wb_tbe_enc_ivas_fx( } +/*-------------------------------------------------------------------* + * fb_tbe_reset_enc() + * + * Reset the extra parameters needed for FB TBE encoding + *-------------------------------------------------------------------*/ + void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], Word32 *prev_fb_energy_fx, @@ -2098,7 +2341,11 @@ void swb_tbe_enc_fx( ELSE { /* LSF quantization (21 bits) */ +#ifdef HARMONIZE_TBE + Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); +#else Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); +#endif } /* space the lsfs to assert a minimum distance */ @@ -2393,7 +2640,7 @@ void swb_tbe_enc_fx( GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, + coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); @@ -2634,8 +2881,13 @@ void swb_tbe_enc_fx( p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#else EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -2744,7 +2996,11 @@ void swb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind ); +#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation */ @@ -2823,9 +3079,9 @@ void swb_tbe_enc_fx( /*======================================================================================*/ void swb_tbe_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ + Encoder_State *st_fx, /* i/o: encoder state structure */ STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ @@ -2933,7 +3189,9 @@ void swb_tbe_enc_ivas_fx( move16(); TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifndef HARMONIZE_TBE RF_ENC_HANDLE hRF = st_fx->hRF; +#endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; /* init and buffers set up */ @@ -3104,7 +3362,11 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ +#ifdef HARMONIZE_TBE + gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); +#else gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); +#endif test(); test(); @@ -3138,7 +3400,11 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ +#ifdef HARMONIZE_TBE + Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#else Quant_BWE_LSF_ivas_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#endif } /* space the lsfs to assert a minimum distance */ @@ -3312,7 +3578,11 @@ void swb_tbe_enc_ivas_fx( } shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); +#ifdef HARMONIZE_TBE + Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); +#else Quant_shb_ener_sf_ivas_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); +#endif /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ set16_fx( shb_res_fx, 0, L_FRAME16k ); @@ -3359,7 +3629,11 @@ void swb_tbe_enc_ivas_fx( move16(); } +#ifdef HARMONIZE_TBE + Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); +#else Quant_shb_res_gshape_ivas_fx( st_fx, shb_res_gshape_fx ); +#endif } ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { @@ -3986,7 +4260,7 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { // GainShape[i] = ( 1 - feedback ) * GainShape[i] + feedback * GainShape_Interp[i]; - GainShape_fx[i] = extract_h( L_add( L_mult( sub( MAX16B, feedback ), GainShape_fx[i] ), L_mult( feedback, GainShape_Interp_fx[i] ) ) ); + GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i] ), feedback, GainShape_Interp_fx[i] ) ); move16(); } } @@ -4067,7 +4341,11 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the gain shape parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); +#else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); +#endif /* Compute the power of gains away from the peak gain after quantization */ IF( st_fx->element_mode > EVS_MONO ) @@ -4100,7 +4378,7 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { // GainShape[i] = ( 1 - feedback ) * GainShape[i * NUM_SHB_SUBGAINS] + feedback * GainShape_Interp[i]; - GainShape_fx[i] = extract_h( L_add( L_mult( sub( MAX16B, feedback ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), L_mult( feedback, GainShape_Interp_fx[i] ) ) ); // Q15 + GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), feedback, GainShape_Interp_fx[i] ) ); // Q15 move16(); } @@ -4113,8 +4391,13 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ +#ifdef HARMONIZE_TBE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#else EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -4359,6 +4642,9 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARMONIZE_TBE + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); +#else IF( st_fx->rf_mode ) { QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); @@ -4367,6 +4653,7 @@ void swb_tbe_enc_ivas_fx( { QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); } +#endif IF( hStereoICBWE != NULL ) { @@ -4462,7 +4749,11 @@ void swb_tbe_enc_ivas_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ + static void EstimateSHBFrameGain_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif const Word16 length, /* i : SHB overlap length */ const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ const Word16 Q_oriSHB, /* i : Q of arget original SHB frame */ @@ -4474,6 +4765,7 @@ static void EstimateSHBFrameGain_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) +#ifndef HARMONIZE_TBE { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4658,6 +4950,7 @@ static void EstimateSHBFrameGain_ivas_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) +#endif { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4697,34 +4990,70 @@ static void EstimateSHBFrameGain_ivas_fx( move16(); j = skip[0]; move16(); - FOR( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ - mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); - move32(); /* Q(16+Q_synSHB) */ - } - FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) { - j = skip[i]; - move16(); - FOR( k = 0; k < length; k++ ) + FOR( k = 0; k < length / 2; k++ ) { - L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ - mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_shl( L_mult( sum_gain, synSHB[j + k] ), 1 ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); move32(); /* Q(16+Q_synSHB) */ } } - FOR( k = 0; k < length / 2; k++ ) + ELSE +#endif { - j = skip[i]; - move16(); - sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ - mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ + FOR( k = 0; k < length / 2; k++ ) + { + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + } } } ELSE @@ -4734,45 +5063,93 @@ static void EstimateSHBFrameGain_ivas_fx( join_length = i_mult2( num_join, length ); j = 0; move16(); - FOR( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ - mod_syn[j] = L_mult0( synSHB[j], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) { - FOR( k = 0; k < join_length - length; k++ ) + FOR( k = 0; k < length; k++ ) { - mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult( synSHB[j], sum_gain ); move32(); /* Q(16+Q_synSHB) */ j++; } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_shl( L_mult( tmp, synSHB[j] ), 1 ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j++; + } FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); - tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ mod_syn[j] = L_mult( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB) */ + move32(); /* Q(16+Q_synSHB ) */ j++; } } - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); - move32(); /* Q(16+Q_synSHB)*/ - j++; - } - FOR( k = 0; k < length; k++ ) + ELSE +#endif { - tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ - mod_syn[j] = L_mult0( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB ) */ - j++; + FOR( k = 0; k < length; k++ ) + { + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult0( synSHB[j], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_mult( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j++; + } + FOR( k = 0; k < length; k++ ) + { + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ + mod_syn[j] = L_mult0( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB ) */ + j++; + } } } + /* adjust frame energy */ oriNrg = L_deposit_l( 0 ); synNrg = L_deposit_l( 0 ); @@ -4782,14 +5159,14 @@ static void EstimateSHBFrameGain_ivas_fx( sig = mult_r_sat( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_orisHB*/ sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_synSHB - 2*/ } FOR( ; i < l_frame; i++ ) { oriNrg = L_mac0_sat( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ sig = round_fx_sat( mod_syn[i] ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_oriSHB - 2*/ } tmp = add( l_frame, l_shb_lahead ); @@ -4798,7 +5175,7 @@ static void EstimateSHBFrameGain_ivas_fx( sig = mult_r_sat( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB */ sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_oriSHB - 2*/ } IF( EQ_32( oriNrg, MAX_32 ) ) { @@ -4821,7 +5198,17 @@ static void EstimateSHBFrameGain_ivas_fx( oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ } } - L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) + { + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &exp_out ); + } + ELSE +#endif + { + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + } exp_out = sub( exp_out, scaling ); frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ *GainFrame = frame_gain; @@ -4831,7 +5218,10 @@ static void EstimateSHBFrameGain_ivas_fx( } -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) +static Word32 pow_off_pk_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) { Word16 i, j; Word32 sum, L_tmp; @@ -4857,7 +5247,10 @@ static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) } -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ) +static Word32 pow_off_pk_corrected_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) { Word16 i, j; Word32 sum, L_tmp; @@ -5169,6 +5562,7 @@ static void EstimateSHBGainShape_fx( /* RETURN ARGUMENTS : */ /* _ Word16 : index Q0 */ /*--------------------------------------------------------------------------*/ + static Word16 closest_centroid_fx( const Word16 *data, /* i : input data Qx*/ const Word16 *weights, /* i : weights */ @@ -5214,6 +5608,7 @@ static Word16 closest_centroid_fx( /* PURPOSE : Determine a set of closest VQ centroids for a given input */ /* Gain shape is 4 dimensional */ /*--------------------------------------------------------------------------*/ + static Word16 closest_centroid_lc_fx( const Word16 *data, /* i : input data Qx*/ const Word16 *quantizer, /* i : quantizer table Qx*/ @@ -5393,7 +5788,7 @@ static void QuantizeSHBsubgains_fx( return; } - +#ifndef HARMONIZE_TBE /*============================================================*/ /* FUNCTION : static void QuantizeSHBsubgains_ivas_fx() */ /*------------------------------------------------------------*/ @@ -5530,7 +5925,7 @@ static void QuantizeSHBsubgains_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------* * Quant_shb_ener_sf_fx_fx() @@ -5539,6 +5934,7 @@ static void QuantizeSHBsubgains_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ Word16 Q_ener ) @@ -5595,9 +5991,10 @@ static void Quant_shb_ener_sf_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies Q_ener */ - Word16 Q_ener ) + const Word16 Q_ener ) { Word16 idxSubEner_fx; Word16 temp_shb_ener_sf_fx; @@ -5605,6 +6002,9 @@ static void Quant_shb_ener_sf_ivas_fx( Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; +#ifdef HARMONIZE_TBE + Word16 Q_fac; +#endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ @@ -5613,21 +6013,48 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); - exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ + exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ - temp_shb_ener_sf_fx = 0; - move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q11 */ + temp_shb_ener_sf_fx = 0; + move16(); + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q12 */ + + Q_fac = -Q10; + move16(); + } + ELSE +#endif + { + L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ + + tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + + temp_shb_ener_sf_fx = 0; + move16(); + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q11 */ +#ifdef HARMONIZE_TBE + Q_fac = -Q9; + move16(); +#endif + } /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q11+Q13+1 = Q25 */ - L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12/Q11+Q13+1 = Q26/Q25 */ +#ifdef HARMONIZE_TBE + L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ +#else + L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ +#endif + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ move32(); @@ -5650,6 +6077,7 @@ static void Quant_shb_ener_sf_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -5677,7 +6105,6 @@ static void Quant_shb_res_gshape_fx( return; } - /*-------------------------------------------------------------------* * Quant_shb_res_gshape_ivas_fx() * @@ -5685,6 +6112,7 @@ static void Quant_shb_res_gshape_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -5737,6 +6165,7 @@ static void Quant_shb_res_gshape_ivas_fx( /*==========================================================================*/ static void QuantizeSHBframegain_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5904,6 +6333,7 @@ return; /*==========================================================================*/ static void QuantizeSHBframegain_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5932,11 +6362,25 @@ static void QuantizeSHBframegain_ivas_fx( singlevectortest_gain_fx( GainFrame, 1, 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain16_fx ); - test(); - IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) { - idxFrameGain--; - Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + } + } + ELSE +#endif + { + test(); + IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + } } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) @@ -6142,6 +6586,7 @@ return; /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------*/ + static void determine_gain_weights_fx( const Word32 *gain, /* i : Gain parameter Q18 */ Word16 *weights, /* o : gain weights Q12/Q6*/ @@ -6206,6 +6651,7 @@ static void determine_gain_weights_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ + static void singlevectortest_gain_fx( const Word32 *inp, /* i : input gain vector Q18*/ const Word16 dimen, /* i : dimension of the input vector */ @@ -6274,6 +6720,7 @@ static void singlevectortest_gain_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ + static void return_M_Least_fx_GainFrame( const Word32 *inp, /* i: input Q18*/ const Word32 *codebook, /* i: codebook Q18*/ @@ -6510,6 +6957,7 @@ static Word16 Find_LSF_grid_fx( * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ +#ifndef HARMONIZE_TBE static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, @@ -6632,13 +7080,20 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ -static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, - Word16 *shb_frame_fx /* Q_in */, - const Word16 *lpc_shb_fx /* Q12 */, - const Word16 *lsp_shb_fx /* Q15 */, - Word16 *MA_lsp_shb_spacing /* Q15 */, - Word16 *frGainAttenuate /* Q0 */, - Word16 *frGainSmoothEn /* Q0 */ ) +#endif + +#ifdef HARMONIZE_TBE +static void gainFrSmooth_En_fx( +#else +static void gainFrSmooth_En_ivas_fx( +#endif + Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ) { Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; @@ -6686,8 +7141,18 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); - lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); - lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO ) + { + lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); + lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); + } + ELSE +#endif + { + lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); + lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); + } /* update the slow and fast interpolation lsps for next frame */ tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 /* 0.7f in Q15 */ ); @@ -6746,12 +7211,25 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, } test(); - if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) +#ifdef HARMONIZE_TBE + IF( st_fx->element_mode == EVS_MONO && LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; move16(); } + ELSE IF( st_fx->element_mode > EVS_MONO ) +#endif + { + test(); + if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) + { + *frGainSmoothEn = 1; + move16(); + } + } } + + return; } #define MAXINT32 MAX_32 @@ -7123,7 +7601,7 @@ static void LVQQuant_BWE_LSF_fx( * * Quantize super highband spectral envolope *-------------------------------------------------------------------*/ - +#ifndef HARMONIZE_TBE static void Quant_BWE_LSF_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -7187,9 +7665,14 @@ static void Quant_BWE_LSF_fx( return; } +#endif +#ifdef HARMONIZE_TBE +static void Quant_BWE_LSF_fx( +#else static void Quant_BWE_LSF_ivas_fx( +#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 codec_mode, /* i : codec mode */ @@ -7273,10 +7756,11 @@ static void Quant_BWE_LSF_ivas_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc ) + const Word16 Q_fb_exc ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7305,10 +7789,7 @@ void fb_tbe_enc_fx( Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; IF( NE_16( st->last_extl, FB_TBE ) ) @@ -7397,11 +7878,12 @@ void fb_tbe_enc_fx( } void fb_tbe_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q_new_input */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ - Word16 Q_fb_exc, - Word16 Q_new_input ) + const Word16 Q_fb_exc, + const Word16 Q_new_input ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7416,13 +7898,30 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; Word16 q_diff, q_input_fhb; Word64 temp1, temp2; +#ifdef HARMONIZE_TBE + Word16 offset; + + offset = 0; + move16(); + if ( st->element_mode > EVS_MONO ) + { + offset = NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); + } +#endif s_max_value = 0; move16(); +#ifdef HARMONIZE_TBE + FOR( i = 0; i < add( L_FRAME48k, offset ); i++ ) + { + s_max_value = s_max( s_max_value, abs_s( new_input[i - offset] ) ); + } +#else FOR( i = 0; i < L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); i++ ) { s_max_value = s_max( s_max_value, abs_s( new_input[i - NS2SA( 48000, DELAY_FIR_RESAMPL_NS )] ) ); } +#endif exp_temp = norm_s( s_max_value ); if ( s_max_value == 0 ) { @@ -7430,27 +7929,36 @@ void fb_tbe_enc_ivas_fx( move16(); } +#ifdef HARMONIZE_TBE + if ( st->element_mode == EVS_MONO ) + { + exp_temp = sub( exp_temp, 1 ); + } +#endif + +#ifdef HARMONIZE_TBE + Copy_Scale_sig( new_input - offset, input_fhb_new, add( L_FRAME48k, offset ), exp_temp ); +#else Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); +#endif exp_temp = add( exp_temp, Q_new_input ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); } ELSE { - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#ifdef HARMONIZE_TBE + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + offset, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#else + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#endif } test(); IF( GT_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_SCE ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) { Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ) - L_FRAME48k / 2; @@ -7473,71 +7981,144 @@ void fb_tbe_enc_ivas_fx( set16_fx( tmp_vec, 0, L_FRAME16k ); } - q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); - Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q - Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp - IF( q_diff > 0 ) +#ifdef HARMONIZE_TBE + IF( st->element_mode == EVS_MONO ) { - scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q - q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; + Word32 L_tmp, temp32, fb_exc_energy32; + Word16 tmp1; + + Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ) ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); + Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k - Sample_Delay_HP ); + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); + temp32 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ + temp32 = L_add_sat( temp32, L_shl_sat( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); /* Q11 */ + hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ + hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 6 ); + fb_exc_energy32 = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ + + /*ratio = (float) sqrt( temp32 / fb_exc_energy );*/ + L_tmp = L_max( 1, temp32 ); /*Q6*/ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( sub( 31, sub( add( exp_temp, exp_temp ), 8 ) ), exp ); /* in Q15 (L_tmp in Q6)*/ + + exp2 = norm_l( fb_exc_energy32 ); + tmp2 = extract_h( L_shl( fb_exc_energy32, exp2 ) ); + tmp1 = sub( add( Q_fb_exc, Q_fb_exc ), 8 ); /*1 - 9*/ + exp2 = sub( sub( 31, tmp1 ), exp2 ); /* in Q15 (L_tmp in Q6)*/ + + exp = sub( exp2, exp ); /* Denormalize and substract */ + IF( GT_16( tmp2, tmp ) ) + { + tmp2 = shr( tmp2, 1 ); + exp = add( exp, 1 ); + } + IF( 0 != tmp ) + { + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ + L_tmp = L_max( L_shr_sat( L_tmp, sub( 31, exp ) ), 0x1 ); /* Q0 */ + } + ELSE + { + L_tmp = 0; + } + + /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + idxGain = max( 0, min(15,idxGain) ); */ + ratio = 0; move16(); + IF( GE_32( L_tmp, 32768 ) ) + { + idxGain = 15; + move16(); + } + ELSE + { + ratio = extract_l( L_tmp ); + idxGain = sub( 14, norm_s( ratio ) ); + idxGain = s_max( 0, idxGain ); + } + + test(); + test(); + IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) + { + idxGain = add( idxGain, 1 ); + } } ELSE +#endif { - scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp - q_input_fhb = exp_temp; + q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q + Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp + IF( q_diff > 0 ) + { + scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q + q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; + move16(); + } + ELSE + { + scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp + q_input_fhb = exp_temp; + move16(); + } + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; move16(); - } - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - hBWE_TD->old_input_fhb_fx_Q = exp_temp; - move16(); - temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ - temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb + temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ + temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb - temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb - exp = W_norm( temp1 ); - temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp - hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 - move32(); - hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); - move16(); + temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb + exp = W_norm( temp1 ); + temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp + hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 + move32(); + hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); + move16(); - fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc + fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - exp = sub( W_norm( temp2 ), 1 ); - tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 - exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) + /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ + exp = sub( W_norm( temp2 ), 1 ); + tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 + exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) - exp2 = W_norm( fb_exc_energy ); - tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 - exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) + exp2 = W_norm( fb_exc_energy ); + tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 + exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) - ratio = 0; - idxGain = 0; - move16(); - move16(); - test(); - IF( tmp != 0 && tmp2 != 0 ) - { - ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 - exp = sub( exp, exp2 ); - /* ratio = (float) sqrt( temp2 / fb_exc_energy ); - idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + ratio = 0; + idxGain = 0; + move16(); + move16(); + test(); + IF( tmp != 0 && tmp2 != 0 ) + { + ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 + exp = sub( exp, exp2 ); + /* ratio = (float) sqrt( temp2 / fb_exc_energy ); + idxGain = (short)( log2_f ((float)ratio) + 0.5f ); - => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) - = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) - = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) - increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt - */ - exp = add( exp, 1 ); - ratio = Sqrt16( ratio, &exp ); - /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ - idxGain = sub( exp, 1 ); // 14 - (15-exp) + => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) + = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) + = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) + increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt + */ + exp = add( exp, 1 ); + ratio = Sqrt16( ratio, &exp ); + /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ + idxGain = sub( exp, 1 ); // 14 - (15-exp) - /* idxGain = max( 0, min( 15, idxGain ) ); */ - idxGain = s_max( 0, s_min( 15, idxGain ) ); + /* idxGain = max( 0, min( 15, idxGain ) ); */ + idxGain = s_max( 0, s_min( 15, idxGain ) ); + } } /* ratio = (float)(1 << idxGain);*/ @@ -7550,8 +8131,17 @@ void fb_tbe_enc_ivas_fx( { push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); } + return; } + + +/*---------------------------------------------------------------------* + * tbe_write_bitstream() + * + * Write TBE bitstream. + *---------------------------------------------------------------------*/ + void tbe_write_bitstream_fx( Encoder_State *st_fx /* i/o: encoder state structure */ ) @@ -7578,7 +8168,6 @@ void tbe_write_bitstream_fx( ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) { /* LSF coefficients */ - test(); IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { @@ -7635,6 +8224,12 @@ void tbe_write_bitstream_fx( } +/*---------------------------------------------------------------------* + * TBEreset_enc() + * + * + *---------------------------------------------------------------------*/ + void TBEreset_enc_fx( TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 last_core, /* i : last core */ diff --git a/lib_enc/tcq_core_enc_fx.c b/lib_enc/tcq_core_enc_fx.c index a3d355a2da492724869d59daabca37cbac2ba4db..517c1c0b49400fc77ded750bf8cb4924be12033e 100644 --- a/lib_enc/tcq_core_enc_fx.c +++ b/lib_enc/tcq_core_enc_fx.c @@ -491,489 +491,5 @@ ivas_error tcq_core_LR_enc_fx( } - return error; -} - -ivas_error tcq_core_LR_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word32 inp_vector_fx[], /* x5 */ - const Word32 coefs_norm_fx[], /* Q12 */ - Word32 coefs_quant_fx[], /* Q12 */ - const Word16 bit_budget, /* number of bits */ - const Word16 BANDS, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word32 *R_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 is_transient ) -{ - Word16 i, j, k, size, nb_bytes; - - Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ - Word16 coefs_norm_dec_fx[L_FRAME32k]; /* New output buffer (TCQ+USQ)*/ - Word32 savedstates[TCQ_MAX_BAND_SIZE]; - ARCODEC arenc_fx, *parenc_fx; - TCQ_BITSTREAM bs_fx, *pbs_fx; - Word16 k_num[2]; - Word32 bit_surplus_fx[2]; - - Word16 flag_wbnb = 0; - Word16 lsbtcq_bits = TCQ_AMP; - Word16 tcq_arbits = 2; - Word16 nzb = 0; - Word16 nzbands = 0; - Word16 bcount = 0; - Word32 bsub_fx = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move32(); - Word32 abuffer_fx[MAX_PULSES]; - Word16 mbuffer_fx[MAX_PULSES]; - Word32 sbuffer_fx[MAX_PULSES]; - Word16 dpath[280]; - Word32 Rk_sort_fx[NB_SFM]; - Word32 step_scale_fx[NB_SFM]; - Word16 pulses_fx, nzp_fx; - - Word32 gain_fx, crosscorr_fx, selfcorr_fx; - Word16 hi, lo, exp; - Word32 surplus_fx, delta_fx, est_frame_bits_fx; - - Word32 leftbits = 0; - Word32 sepbits = 0; - Word32 divider = 0; - move32(); - move32(); - move32(); - ivas_error error; - - error = IVAS_ERR_OK; - move16(); - set16_fx( dpath, 0, 280 ); - set32_fx( abuffer_fx, 0, MAX_PULSES ); - set32_fx( sbuffer_fx, 0, MAX_PULSES ); - set16_fx( mbuffer_fx, 0, MAX_PULSES ); - /* initialization */ - set32_fx( Rk_sort_fx, 0, NB_SFM ); - set16_fx( USQ_TCQ, 0, NB_SFM ); - set16_fx( coefs_norm_dec_fx, 0, L_FRAME32k ); - - InitLSBTCQ_fx( &bcount ); - - test(); - test(); - IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && is_transient == 0 ) - { - flag_wbnb = 1; - move16(); - lsbtcq_bits = 0; - move16(); - tcq_arbits = 0; - move16(); - } - - /* TCQ Index initialize */ - parenc_fx = &arenc_fx; - pbs_fx = &bs_fx; - - pbs_fx->curPos = 7; - move16(); - pbs_fx->numbits = L_deposit_l( 0 ); - pbs_fx->numByte = L_deposit_l( 0 ); - move32(); - move32(); - FOR( i = 0; i < MAX_SIZEBUF_PBITSTREAM; i++ ) - { - pbs_fx->buf[i] = 0; - move16(); - } - ar_encoder_start_fx( parenc_fx, pbs_fx, L_deposit_l( bit_budget ) ); - - /* Bits distribution analysis */ - FOR( i = 0; i < BANDS; i++ ) - { - IF( GE_32( ar_div( R_fx[i], sfmsize[i] ), 49152 ) ) - { - /* USQ used for high importance bands*/ - USQ_TCQ[i] = 1; - move16(); - } - ELSE - { - /* TCQ used for usual bands */ - USQ_TCQ[i] = 0; - move16(); - } - - IF( R_fx[i] > 0 ) - { - /* nzbands++; */ - nzbands = add( nzbands, 1 ); - } - } - - FOR( j = 0; j < BANDS; j++ ) - { - IF( R_fx[j] > 0 ) - { - nzb = add( nzb, 1 ); - } - } - - bsub_fx = L_shl( add( tcq_arbits, lsbtcq_bits ), 16 ); /* Q16 */ - IF( bsub_fx > 0 ) - { - bsub_fx = L_add( bsub_fx, 2048 ); - } - FOR( j = BANDS - 1; j >= 0; j-- ) - { - IF( R_fx[j] > 0 ) - { - R_fx[j] = L_sub( R_fx[j], ar_div( bsub_fx, nzb ) ); - move32(); - - IF( R_fx[j] < 0 ) - { - bsub_fx = L_sub( bsub_fx, L_add( ar_div( bsub_fx, nzb ), R_fx[j] ) ); - R_fx[j] = L_deposit_l( 0 ); - move32(); - } - ELSE - { - bsub_fx = L_sub( bsub_fx, ar_div( bsub_fx, nzb ) ); - } - /* nzb--; */ - nzb = sub( nzb, 1 ); - } - } - - /* Sort the bit allocation table (R) in ascending order, figure out number of pulses per band */ - srt_vec_ind_fx( R_fx, Rk_sort_fx, k_sort, BANDS ); - - /* Quantize spectral band shapes using TCQ */ - /* Select ISC */ - set32_fx( coefs_quant_fx, 0, add( sfm_end[BANDS - 1], 1 ) ); - Copy32( coefs_norm_fx, coefs_quant_fx, add( sfm_end[BANDS - 1], 1 ) ); - - delta_fx = L_deposit_l( 0 ); - est_frame_bits_fx = L_deposit_l( 0 ); - - test(); - test(); - IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && is_transient == 0 ) - { - surplus_fx = -131072; - move32(); - bit_allocation_second_fx( R_fx, Rk_sort_fx, BANDS, sfmsize, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); - - nzbands = 0; - move16(); - FOR( j = 0; j < BANDS; j++ ) - { - test(); - IF( NE_16( j, k_num[0] ) && NE_16( j, k_num[1] ) ) - { - leftbits = L_add( leftbits, R_fx[k_sort[j]] ); - IF( R_fx[k_sort[j]] > 0 ) - { - nzbands = add( nzbands, 1 ); - } - } - ELSE - { - sepbits = L_add( sepbits, R_fx[k_sort[j]] ); - } - } - /* Separate the position information from the input signal(coefs_norm) */ - /* Gather the NZ coefficients*/ - FOR( k = 0; k < BANDS; k++ ) /* Loop through non-zero blocks */ - { - test(); - IF( NE_16( k, k_num[0] ) && NE_16( k, k_num[1] ) ) - { - test(); - test(); - IF( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ - { - /* Encode Position Info, NZ Info, Signs */ - size = sfmsize[k_sort[k]]; - move16(); - - /* Determine scale step, ISC and TCQ quantizer */ - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, - L_add( R_fx[k_sort[k]], delta_fx ), - /* R_fx[k_sort[k]], */ - &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx, 0, 0, 0, 0 ); - leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx ) ); - npulses[k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - nzbands = sub( nzbands, 1 ); - } - /* Have USQ coded band */ - ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) - { - size = sfmsize[k_sort[k]]; - move16(); - - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, - L_add( R_fx[k_sort[k]], delta_fx ), - /* R_fx[k_sort[k]], */ - &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, 0, 0, 0, 0 ); - leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx ) ); - npulses[k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - nzbands = sub( nzbands, 1 ); - } - ELSE /* Then have zero block */ - { - npulses[k_sort[k]] = 0; - move16(); - size = sfmsize[k_sort[k]]; - move16(); - } - - delta_fx = L_deposit_l( 0 ); - test(); - IF( R_fx[k_sort[k]] > 0 && surplus_fx < 0 ) - { - /* delta_fx = L_deposit_h( div_l( surplus_fx, nzbands ) ); */ - IF( LE_16( nzbands, 1 ) ) - { - divider = 0; - move32(); - } - ELSE - { - divider = 2; - move32(); - } - - IF( L_add( L_add( surplus_fx, sepbits ), ar_div( leftbits, divider ) ) < 0 ) - { - /* Overflow possible => start to distribute negative surplus */ - delta_fx = ar_div( surplus_fx + sepbits, nzbands ); - } - ELSE - { - delta_fx = 0; - move32(); - } - surplus_fx = L_sub( surplus_fx, delta_fx ); - } - } - } - - test(); - test(); - test(); - IF( ( GT_32( surplus_fx, 524288 ) && EQ_16( input_frame, L_FRAME8k ) ) || ( GT_32( surplus_fx, 786432 ) && EQ_16( input_frame, L_FRAME16k ) ) ) - { - bit_surplus_fx[0] = Mult_32_16( surplus_fx, 24576 ); /* Q16 */ - move32(); - bit_surplus_fx[1] = Mult_32_16( surplus_fx, 8192 ); /* Q16 */ - move32(); - } - ELSE - { - bit_surplus_fx[0] = surplus_fx; - move32(); - bit_surplus_fx[1] = L_deposit_l( 0 ); - move32(); - } - - FOR( k = 0; k < BANDS; k++ ) - { - FOR( j = 0; j < 2; j++ ) - { - IF( EQ_16( k, k_num[j] ) ) - { - R_fx[k_sort[k]] = L_add( R_fx[k_sort[k]], bit_surplus_fx[j] ); - move32(); - - test(); - test(); - IF( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ - { - /* Encode Position Info, NZ Info, Signs */ - size = sfmsize[k_sort[k]]; - move16(); - - /* Determine scale step, ISC and TCQ quantizer */ - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx, 0, 0, 0, 0 ); - - npulses[k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - } - /* Have USQ coded band */ - ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) - { - size = sfmsize[k_sort[k]]; - move16(); - - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, 0, 0, 0, 0 ); - - npulses[k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - } - ELSE /* Then have zero block */ - { - npulses[k_sort[k]] = 0; - move16(); - size = sfmsize[k_sort[k]]; - move16(); - } - } - } - } - } - ELSE - { - surplus_fx = L_deposit_l( 0 ); - - /* Separate the position information from the input signal(coefs_norm) */ - /* Gather the NZ coefficients*/ - FOR( k = 0; k < BANDS; k++ ) /* Loop through non-zero blocks */ - { - IF( R_fx[k_sort[k]] > 0 ) - { - size = sfmsize[k_sort[k]]; - move16(); - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]] + delta_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, &bcount, abuffer_fx, mbuffer_fx, sbuffer_fx ); - - npulses[k_sort[k]] = pulses_fx; - move16(); - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - - /* nzbands--; */ - nzbands = sub( nzbands, 1 ); - } - ELSE /* Then have zero block */ - { - npulses[k_sort[k]] = 0; - move16(); - size = sfmsize[k_sort[k]]; - move16(); - } - - /* Surplus distribution */ - /* if( surplus > 0.0f && nzbands > 0 ) */ - test(); - IF( surplus_fx > 0 && nzbands > 0 ) - { - /* delta = surplus / nzbands; - surplus -= delta; */ - - delta_fx = ar_div( surplus_fx, nzbands ); - surplus_fx = L_sub( surplus_fx, delta_fx ); - } - } - } - - TCQLSB_fx( bcount, /*abuffer, */ abuffer_fx, /*mbuffer, */ mbuffer_fx, /*sbuffer, */ sbuffer_fx, dpath ); - - /* Save TCQ path to bitstream */ - SaveTCQdata_fx( parenc_fx, dpath, lsbtcq_bits ); - - /* Add tcq sequence to decoding buffer */ - InitLSBTCQ_fx( &bcount ); - - ar_encoder_done_fx( parenc_fx ); - - /* Loop through non-zero blocks */ - FOR( i = 0; i < L_FRAME32k; i++ ) - { - coefs_norm_dec_fx[i] = extract_l( L_mult0( coefs_norm_dec_fx[i], 5 ) ); - move16(); - } - - IF( !flag_wbnb ) - { - FOR( k = 0; k < BANDS; k++ ) - { - IF( R_fx[k_sort[k]] > 0 ) - { - size = sfmsize[k_sort[k]]; - move16(); - RestoreTCQ_fx( &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &bcount, mbuffer_fx ); - } - } - } - - nb_bytes = shr( bit_budget, 3 ); - - j = sub( bit_budget, shl( nb_bytes, 3 ) ); - FOR( i = 0; i < nb_bytes; i++ ) - { - push_indice( hBstr, IND_HQ2_SUBBAND_TCQ, pbs_fx->buf[i], 8 ); - } - IF( j > 0 ) - { - push_indice( hBstr, IND_HQ2_SUBBAND_TCQ, shr( pbs_fx->buf[nb_bytes], sub( 8, j ) ), j ); - } - /* Clear decoding buffer */ - set32_fx( coefs_quant_fx, 0, sfm_end[BANDS - 1] + 1 ); - - /* New analysis of decoded frame */ - FOR( i = 0; i < BANDS; i++ ) - { - IF( R_fx[k_sort[i]] > 0 ) - { - gain_fx = L_deposit_l( 0 ); - - crosscorr_fx = L_deposit_l( 0 ); - selfcorr_fx = L_deposit_l( 0 ); - - FOR( j = 0; j < sfmsize[k_sort[i]]; j++ ) - { - crosscorr_fx = L_add( crosscorr_fx, Mult_32_16( coefs_norm_fx[sfm_start[k_sort[i]] + j], shl( coefs_norm_dec_fx[sfm_start[k_sort[i]] + j], 2 ) ) ); /*1 */ - selfcorr_fx = L_mac0( selfcorr_fx, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j], coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ); - } - - exp = sub( norm_l( crosscorr_fx ), 1 ); - gain_fx = ar_div( L_shl( crosscorr_fx, exp ), selfcorr_fx ); /* 1 + exp */ - gain_fx = L_shl_sat( gain_fx, sub( 16, 1 + exp ) + 2 ); /* 0.2 * Q16 */ - lo = L_Extract_lc( gain_fx, &hi ); - /* Use optimal gain */ - FOR( j = 0; j < sfmsize[k_sort[i]]; j++ ) - { - inp_vector_fx[sfm_start[k_sort[i]] + j] = coefs_norm_dec_fx[sfm_start[k_sort[i]] + j]; - move32(); - coefs_quant_fx[sfm_start[k_sort[i]] + j] = L_add( L_shl( L_mult0( hi, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ), 12 ), - L_shr( L_mult0( lo, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ), 3 ) ); /* Q12 */ - move32(); - } - } - } - - return error; } diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 012d6fa0260cd2cc1886c848bf04930652dd80df..7650516cb3898086ace272f3966f4e47db1a2d00 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "stl.h" #include "cnst.h" #include "basop_util.h" @@ -89,6 +89,7 @@ static void tcx_ltp_pitch_search( Word16 pitres ) { Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; + Word16 cor_idx_ini, cor_idx; Word32 cor_max, cor[256], *pt_cor, temp; Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; @@ -203,7 +204,7 @@ static void tcx_ltp_pitch_search( * the interpolated normalized correlation. *-----------------------------------------------------------------*/ - pt_cor = cor + sub( L_INTERPOL1, t0_min ); + cor_idx_ini = sub( L_INTERPOL1, t0_min ); t0 = t1; move16(); @@ -219,18 +220,20 @@ static void tcx_ltp_pitch_search( IF( EQ_16( t0, t0_min ) ) /* Limit case */ { + cor_idx = add( cor_idx_ini, t0 ); fraction = 0; move16(); - cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); } ELSE /* Process negative fractions */ { t0 = sub( t0, 1 ); - cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); + cor_idx = add( cor_idx_ini, t0 ); + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); FOR( i = fraction + step; i < pitres; i += step ) { - temp = interpolate_corr( &pt_cor[t0], i, pitres ); + temp = interpolate_corr( &cor[cor_idx], i, pitres ); IF( GT_32( temp, cor_max ) ) { @@ -241,11 +244,10 @@ static void tcx_ltp_pitch_search( } } - i = 0; - move16(); + cor_idx = add( cor_idx_ini, t1 ); FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { - temp = interpolate_corr( &pt_cor[t1], i, pitres ); + temp = interpolate_corr( &cor[cor_idx], i, pitres ); IF( GT_32( temp, cor_max ) ) { @@ -293,6 +295,7 @@ static void tcx_ltp_pitch_search_ivas_fx( Word16 *border_case ) { Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; + Word16 cor_idx_ini, cor_idx; Word32 cor_max, cor[256], *pt_cor, temp; Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; @@ -418,8 +421,7 @@ static void tcx_ltp_pitch_search_ivas_fx( * search the fractions around t0 and choose the one which maximizes * the interpolated normalized correlation. *-----------------------------------------------------------------*/ - - pt_cor = cor + sub( L_INTERPOL1, t0_min ); + cor_idx_ini = sub( L_INTERPOL1, t0_min ); t0 = t1; move16(); @@ -435,18 +437,20 @@ static void tcx_ltp_pitch_search_ivas_fx( IF( EQ_16( t0, t0_min ) ) /* Limit case */ { + cor_idx = add( cor_idx_ini, t0 ); fraction = 0; move16(); - cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); } ELSE /* Process negative fractions */ { t0 = sub( t0, 1 ); - cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); + cor_idx = add( cor_idx_ini, t0 ); + cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres ); FOR( i = fraction + step; i < pitres; i += step ) { - temp = interpolate_corr( &pt_cor[t0], i, pitres ); + temp = interpolate_corr( &cor[cor_idx], i, pitres ); IF( GT_32( temp, cor_max ) ) { @@ -457,9 +461,10 @@ static void tcx_ltp_pitch_search_ivas_fx( } } + cor_idx = add( cor_idx_ini, t1 ); FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { - temp = interpolate_corr( &pt_cor[t1], i, pitres ); + temp = interpolate_corr( &cor[cor_idx], i, pitres ); IF( GT_32( temp, cor_max ) ) { diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index d8e5899da1124e8c1744c354533115af3d07153e..30def3e2ef7f2e707de6626f9913ed4d92b69d89 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -791,32 +791,33 @@ Word16 WriteTnsData_ivas_fx( STnsConfig const *pTnsConfig, Word16 const *stream, { IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - WriteToBitstream_ivas_fx( &tnsEnabledOnWhiteSWBTCX10BitMap, 1, &stream, pnSize, hBstr, pnBits ); + WriteToBitstream_fx( &tnsEnabledOnWhiteSWBTCX10BitMap, 1, &stream, pnSize, hBstr, pnBits ); } ELSE { - WriteToBitstream_ivas_fx( &tnsEnabledOnWhiteSWBTCX20BitMap, 1, &stream, pnSize, hBstr, pnBits ); + WriteToBitstream_fx( &tnsEnabledOnWhiteSWBTCX20BitMap, 1, &stream, pnSize, hBstr, pnBits ); } } ELSE { IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) { - WriteToBitstream_ivas_fx( &tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, hBstr, pnBits ); + WriteToBitstream_fx( &tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, hBstr, pnBits ); } ELSE { - WriteToBitstream_ivas_fx( &tnsEnabledSWBTCX20BitMap, 1, &stream, pnSize, hBstr, pnBits ); + WriteToBitstream_fx( &tnsEnabledSWBTCX20BitMap, 1, &stream, pnSize, hBstr, pnBits ); } } } ELSE { - WriteToBitstream_ivas_fx( &tnsEnabledWBTCX20BitMap, 1, &stream, pnSize, hBstr, pnBits ); + WriteToBitstream_fx( &tnsEnabledWBTCX20BitMap, 1, &stream, pnSize, hBstr, pnBits ); } return TNS_NO_ERROR; } + /*********************************************************************************************/ /* Definitions of functions used in the mapping between TNS parameters and a bitstream. */ /*********************************************************************************************/ diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 547502eab143cc2523cafebe01e169a2474fb28d..00e047e16e6bfbc4f53e4b7b1fa9dc03710ef5e4 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -16,7 +16,6 @@ static void gain_trans_enc_fx( Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new ); static void tc_enc_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); -static void tc_enc_ivas_fx( Encoder_State *st_fx, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new ); /*==========================================================================*/ @@ -163,14 +162,27 @@ void transition_enc_fx( move16(); *clip_gain = 0; move16(); - g_corr_fx[0] = 16384; - move16(); - g_corr_fx[1] = add( shl( sub( shift_wsp, 1 ), 1 ), 1 ); - move16(); - g_corr_fx[2] = -16384; - move16(); - g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); - move16(); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + g_corr_fx[0] = MAX16B /* 1.0f in Q15 */; + move16(); + g_corr_fx[1] = 0; + move16(); + g_corr_fx[2] = MAX16B /* 1.0f in Q15 */; + move16(); + g_corr_fx[3] = 0; + } + ELSE + { + g_corr_fx[0] = 16384; + move16(); + g_corr_fx[1] = add( shl( sub( shift_wsp, 1 ), 1 ), 1 ); + move16(); + g_corr_fx[2] = -16384; + move16(); + g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); + move16(); + } set16_fx( &exc_fx[i_subfr], 0, L_SUBFR ); /* set excitation for current subrame to 0 */ @@ -197,6 +209,7 @@ void transition_enc_fx( /*-----------------------------------------------------------------* * glottal codebook contribution construction *-----------------------------------------------------------------*/ + ELSE IF( EQ_16( *tc_subfr, i_subfr ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -395,7 +408,14 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -443,11 +463,17 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; @@ -508,7 +534,14 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -533,11 +566,17 @@ void transition_enc_fx( push_indice( hBstr, IND_PITCH, index, nBits ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; @@ -571,7 +610,14 @@ void transition_enc_fx( pit_Q_enc_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -807,10 +853,24 @@ void transition_enc_fx( move16(); *clip_gain = 0; move16(); - g_corr_fx[0] = 0; - move16(); - g_corr_fx[1] = 0; - move16(); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + g_corr_fx[0] = 328 /* 0.01f in Q15 */; + move16(); + g_corr_fx[1] = 0; + move16(); + g_corr_fx[2] = 328 /* 0.01f in Q15 */; + move16(); + g_corr_fx[3] = 0; + move16(); + } + ELSE + { + g_corr_fx[0] = 0; + move16(); + g_corr_fx[1] = 0; + move16(); + } *Jopt_flag = 0; move16(); @@ -824,7 +884,15 @@ void transition_enc_fx( ELSE { /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) + { + pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + ELSE + { + pred_lt4( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + } + offset = L_deposit_l( 0 ); tmp = extract_l( L_mult( *T0_frac, 32 ) ); /*Q8, 0.25 in Q7*/ @@ -889,939 +957,110 @@ void transition_enc_fx( return; } -void transition_enc_ivas_fx( + +/*-------------------------------------------------------------------------------------------* + * tc_enc() + * + * Principal function for transition coding (TC) in encoder. + * Glottal codebook contribution part: + * + * |----| |----| xn + * imp_pos->|| | imp_shape->| g1 | | + * | | | | g2 | ---- exc |---| y1 ---- | + * | | |-------------| |----|gain|-------| h |------|gain|----(-)---> xn2 + * | || | gn | ---- |---| ---- + * |----| |----| + * codebook excitation gain_trans h_orig gain_pit + * + *-------------------------------------------------------------------------------------------*/ + +static void tc_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - Word16 *unbits_ACELP, /* i/o: unused bits */ - Word16 Q_new, /* i : Current scaling */ - Word16 shift /* i : downscaling needs for 12 bits convolutions */ + const Word16 i_subfr, /* i : subrame index */ + Word16 *tc_subfr, /* i/o: TC subframe index */ + Word16 *position, /* i/o: index of the residual signal maximum */ + const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ + const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ + Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ + Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ + Word16 *T0_min, /* o : lower pitch limit Q0*/ + Word16 *T0_max, /* o : higher pitch limit Q0*/ + Word16 *T0, /* o : close loop integer pitch Q0*/ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ + Word16 g_corr_fx[], /* o : correlations and -2 */ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ + Word16 Q_new /* i : input scaling */ ) { - Word16 pit_flag, pit_start, pit_limit, index, nBits; - Word16 tmp, tmp1, i; - Word32 offset; - Word16 shift_wsp; - Word16 limit_flag, mult_Top, lp_select, lp_flag; - Word16 T_op[2]; /* values for two half-frames */ + Word16 i, imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; + Word16 pitch_index, pitch_sign_fx; + Word32 gain_trans32; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - /* set limit_flag to 0 for restrained limits, and 1 for extended limits */ - limit_flag = 0; - move16(); - pit_start = PIT_MIN; - move16(); - - /*----------------------------------------------------------------* - * convert pitch values to 16kHz domain - *----------------------------------------------------------------*/ - - IF( EQ_16( st_fx->L_frame, L_FRAME ) /*|| (tdm_Pri_pitch_buf != NULL && tdm_Pri_pitch_buf[0] < 0)*/ ) - { - Copy( st_fx->pitch, T_op, 2 ); - } - ELSE /* L_frame == L_FRAME16k */ + Flag Overflow = 0; + move32(); + imp_pos = sub( *position, i_subfr ); + FOR( i = 0; i < L_SUBFR; i++ ) { - /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); - T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ - T_op[0] = add( st_fx->pitch[0], mult_r( st_fx->pitch[0], 8192 /*0.25f Q15*/ ) ); - move16(); - T_op[1] = add( st_fx->pitch[1], mult_r( st_fx->pitch[1], 8192 /*0.25f Q15*/ ) ); + h1_tmp_fx[i] = h1_fx[i]; move16(); } - shift_wsp = add( Q_new, shift ); + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ - lp_flag = st_fx->acelp_cfg.ltf_mode; + nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; move16(); - /*-----------------------------------------------------------------* - * TC: subrame determination for glottal shape search - * ------------------------------------------------------- - * tc_subfr == 0 - TC in 1st subframe - * tc_subfr == TC_0_0 - TC in 1st subframe + information about T0 - * tc_subfr == L_SUBFR - TC in 2nd subframe - * tc_subfr == 2*L_SUBFR - TC in 3rd subframe - * tc_subfr == 3*L_SUBFR - TC in 4th subframe - *-----------------------------------------------------------------*/ + /*--------------------------------------------------------------* + * Closed loop pitch search + *--------------------------------------------------------------*/ - IF( i_subfr == 0 ) + *T0_frac = 0; + move16(); + + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - mult_Top = 1; - move16(); - IF( limit_flag == 0 ) + test(); + IF( ( LE_16( *T0_min, L_SUBFR ) ) || ( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) { - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME ) && LT_16( T_op[1], PIT_MIN ) ) + IF( EQ_16( nBits, 9 ) ) { - mult_Top = 2; + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } - test(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && LT_16( T_op[1], PIT16k_MIN ) ) + ELSE IF( EQ_16( nBits, 6 ) ) { - mult_Top = 2; + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); + move16(); + } + ELSE + { + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); move16(); } - } - - limit_T0_fx( st_fx->L_frame, 8, 0, limit_flag, mult_Top * T_op[1], 0, T0_min, T0_max ); - } - - /*-----------------------------------------------------------------* - * zero adaptive excitation signal construction - *-----------------------------------------------------------------*/ - - IF( GT_16( *tc_subfr, i_subfr ) ) - { - *gain_pit_fx = 0; - move16(); - *clip_gain = 0; - move16(); - g_corr_fx[0] = MAX16B /* 1.0f in Q15 */; - move16(); - g_corr_fx[1] = 0; - move16(); - g_corr_fx[2] = MAX16B /* 1.0f in Q15 */; - move16(); - g_corr_fx[3] = 0; - move16(); - - set16_fx( &exc_fx[i_subfr], 0, L_SUBFR ); /* set excitation for current subrame to 0 */ - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); /* set past excitation buffer to 0 */ } ELSE { - set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); /* set past excitation buffer to 0 */ + *T0 = L_SUBFR; + move16(); } - set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ - Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - - **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - move16(); /* save subframe pitch values Q6 */ + test(); + if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) + { + *T0 = L_SUBFR; + move16(); + } } - - /*-----------------------------------------------------------------* - * glottal codebook contribution construction - *-----------------------------------------------------------------*/ - - ELSE IF( EQ_16( *tc_subfr, i_subfr ) ) + ELSE /* st_fx->L_frame == L_FRAME16k */ { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( nBits, 10 ) ) { - set16_fx( bwe_exc_fx - PIT_MAX * HIBND_ACB_L_FAC, 0, PIT_MAX * HIBND_ACB_L_FAC ); /* set past excitation buffer to 0 */ + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); + move16(); } - ELSE - { - set16_fx( bwe_exc_fx - PIT16k_MAX * 2, 0, PIT16k_MAX * 2 ); /* set past excitation buffer to 0 */ - } - - tc_enc_ivas_fx( st_fx, i_subfr, tc_subfr, position, h1_fx, xn_fx, exc_fx, - y1_fx, T0_min, T0_max, T0, T0_frac, gain_pit_fx, g_corr_fx, bwe_exc_fx, Q_new ); - - IF( EQ_16( *tc_subfr, TC_0_0 ) ) - { - /* this is called only to compute unused bits */ - config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); - } - - *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); - move16(); - updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); - - **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - move16(); - *Jopt_flag = 1; - move16(); - } - - /*--------------------------------------------------------------* - * other subframes -> GENERIC encoding type, - * standard adaptive excitation contribution - * - exemption only in case when first glottal impulse is - * in the 1st subframe and the second one in 2nd subframe - * and later - *--------------------------------------------------------------*/ - - ELSE IF( LT_16( *tc_subfr, i_subfr ) ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - *Jopt_flag = 1; - move16(); - /* pit_flag for T0 bits number coding determination */ - test(); - IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR - TC_0_0 ) ) ) - { - pit_flag = 0; - move16(); - } - ELSE - { - pit_flag = L_SUBFR; - move16(); - } - - IF( EQ_16( *tc_subfr, TC_0_0 ) ) - { - IF( EQ_16( i_subfr, L_SUBFR ) ) - { - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); - } - pit_flag = 1; - move16(); - } - - /*----------------------------------------------------------* - * if tc_subfr==0, change tc_subfr corresponding to the - * second glot. impulse position - *----------------------------------------------------------*/ - - test(); - IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) - { - IF( GT_16( PIT_MIN, ( *position ) ) ) - { - pit_start = sub( L_SUBFR, ( *position ) ); - } - ELSE - { - pit_start = PIT_MIN; - move16(); - } - pit_start = s_max( pit_start, PIT_MIN ); - - pit_limit = add( shl( pit_start, 1 ), *position ); - - /* Find the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; - move16(); - } - - test(); - IF( GT_16( ( *T0 ), sub( 2 * L_SUBFR, ( *position ) ) ) ) - { - IF( GE_16( add( ( *T0 ), ( *position ) ), 3 * L_SUBFR ) ) - { - /* second glottal impulse is in the 4th subframe */ - *tc_subfr = TC_0_192; - move16(); - } - ELSE - { - /* second glottal impulse is in the 3rd subframe */ - *tc_subfr = TC_0_128; - move16(); - } - } - ELSE IF( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) - { - /* second glottal impulse is in the 2nd subframe */ - *tc_subfr = TC_0_64; - move16(); - } - } - - IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) - { - config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); - } - - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; - move16(); - - /*-----------------------------------------------------------------* - * Find adaptive part of excitation, encode pitch period - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - /* first glottal impulse is in the 1st subrame */ - IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( GE_16( *tc_subfr, TC_0_128 ) ) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 3rd or 4th subframe - * - build exc[] in 2nd subframe - *--------------------------------------------------------*/ - - *T0 = 2 * L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *Jopt_flag = 0; - move16(); - set16_fx( &exc_fx[i_subfr], 0, (Word16) ( L_SUBFR + 1 ) ); - set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); - } - ELSE IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_64 ) ) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 2nd subframe, - * - build exc[] in 2nd subframe - *--------------------------------------------------------*/ - - IF( LT_16( add( *T0, *position ), L_SUBFR ) ) - { - /* impulse must be in the 2nd subframe (not in 1st) */ - *T0 = sub( L_SUBFR, ( *position ) ); - move16(); - *T0_frac = 0; - move16(); - } - IF( GE_16( add( *T0, *position ), 2 * L_SUBFR ) ) - { - /* impulse must be in the 2nd subframe (not in 3rd) */ - *T0 = sub( 2 * L_SUBFR - 1, ( *position ) ); - move16(); - *T0_frac = 2; - move16(); - } - - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ - - /* 7bit ENCODER */ - /* index = (*T0-pit_start)*2 + *T0_frac/2;*/ - index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); - push_indice( hBstr, IND_PITCH, index, nBits ); - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; - move16(); - } - } - ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_128 ) ) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 3rd subframe - * - build exc[] in 3rd subframe - *--------------------------------------------------------*/ - - pit_start = sub( 2 * L_SUBFR, ( *position ) ); - pit_flag = 0; - move16(); - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - - IF( LT_16( add( ( *T0 ), ( *position ) ), 2 * L_SUBFR ) ) - { - /* impulse must be in the 3rd subframe (not in 2nd) */ - *T0 = sub( 2 * L_SUBFR, ( *position ) ); - move16(); - *T0_frac = 0; - move16(); - } - - IF( GE_16( add( ( *T0 ), ( *position ) ), 3 * L_SUBFR ) ) - { - /* impulse must be in the 3rd subframe (not in 4th) */ - *T0 = sub( 3 * L_SUBFR - 1, ( *position ) ); - move16(); - *T0_frac = 2; - move16(); - } - - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ - - index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); - push_indice( hBstr, IND_PITCH, index, nBits ); - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - - - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; - move16(); - } - } - ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_192 ) ) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 4th subframe - * - build exc[] in 3rd subframe - *--------------------------------------------------------*/ - - *T0 = 4 * L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *Jopt_flag = 0; - move16(); - set16_fx( &exc_fx[i_subfr], 0, (Word16) ( L_SUBFR + 1 ) ); - set16_fx( &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], 0, (Word16) ( L_SUBFR * HIBND_ACB_L_FAC ) ); - } - ELSE IF( ( EQ_16( i_subfr, 3 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_192 ) ) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 4th subframe - * - build exc[] in 4th subframe - *--------------------------------------------------------*/ - - /* always T0_frac = 0 */ - pit_flag = 0; - move16(); - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - - IF( LT_16( add( *T0, *position ), 3 * L_SUBFR ) ) - { - /* impulse must be in the 4th subframe (not in 3rd) */ - *T0 = sub( 3 * L_SUBFR, ( *position ) ); - move16(); - *T0_frac = 0; - move16(); - } - - pit_start = sub( 3 * L_SUBFR, ( *position ) ); - pit_limit = sub( 2 * L_FRAME - PIT_MAX - 2, shl( *position, 1 ) ); - - IF( LT_16( ( *T0 ), pit_limit ) ) - { - index = add( shl( sub( *T0, pit_start ), 1 ), shr( *T0_frac, 1 ) ); - } - ELSE - { - index = add( sub( *T0, pit_limit ), shl( sub( pit_limit, pit_start ), 1 ) ); - *T0_frac = 0; - move16(); - } - push_indice( hBstr, IND_PITCH, index, nBits ); - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; - move16(); - } - } - ELSE IF( ( EQ_16( i_subfr, 3 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_128 ) ) ) - { - /*--------------------------------------------------------* - * second glottal impulse in the 3rd subframe - * build exc[] in 4th subframe - *--------------------------------------------------------*/ - - pit_flag = L_SUBFR; - move16(); - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - index = delta_pit_enc_fx( 2, *T0, *T0_frac, *T0_min ); - push_indice( hBstr, IND_PITCH, index, nBits ); - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; - move16(); - } - } - - /*------------------------------------------------------------* - * first glottal impulse is NOT in the 1st subframe, - * or two impulses are in the 1st subframe - *------------------------------------------------------------*/ - - ELSE - { - test(); - IF( EQ_16( nBits, 8 ) || EQ_16( nBits, 5 ) ) - { - test(); - IF( !( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - } - ELSE - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - pit_Q_enc_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); - - FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; - move16(); - } - } - - /*-----------------------------------------------------------------* - * - gain clipping test to avoid unstable synthesis - * - LP filtering of the adaptive excitation (if non-zero) - * - codebook target computation - *-----------------------------------------------------------------*/ - - IF( *Jopt_flag == 0 ) - { - /* adaptive/TC excitation is zero */ - Copy( xn_fx, xn2_fx, L_SUBFR ); - g_corr_fx[0] = 0; - move16(); - g_corr_fx[1] = 0; - move16(); - g_corr_fx[2] = 0; - move16(); - g_corr_fx[3] = 0; - move16(); - *clip_gain = 0; - move16(); - } - ELSE - { - *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, ( Q_new + shift - 1 ) ); - move16(); - - lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); - IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) - { - push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); - } - } - - **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - move16(); - - /*---------------------------------------------------------------------* - * fill the pitch buffer - needed for post-processing - *---------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - IF( ( *tc_subfr >= 2 * L_SUBFR ) && ( i_subfr == 3 * L_SUBFR ) ) - { - tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - ( *pt_pitch_fx ) -= 3; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - } - ELSE IF( ( *tc_subfr == L_SUBFR ) && ( i_subfr == 2 * L_SUBFR ) ) - { - tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - ( *pt_pitch_fx ) -= 2; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - } - ELSE IF( ( *tc_subfr == TC_0_64 ) && ( i_subfr == L_SUBFR ) ) - { - tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - ( *pt_pitch_fx ) -= 1; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - } - ELSE IF( ( *tc_subfr == TC_0_128 ) && ( i_subfr == 2 * L_SUBFR ) ) - { - tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - ( *pt_pitch_fx ) -= 2; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - } - ELSE IF( ( *tc_subfr == TC_0_192 ) && ( i_subfr == 3 * L_SUBFR ) ) - { - tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - ( *pt_pitch_fx ) -= 3; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - if ( GE_16( i_subfr, 2 * L_SUBFR ) ) - { - limit_flag = 1; - move16(); - } - IF( LE_16( i_subfr, 2 * L_SUBFR ) ) - { - IF( LT_16( i_subfr, 2 * L_SUBFR ) ) - { - mult_Top = 1; - move16(); - if ( LT_16( T_op[0], PIT16k_MIN ) ) - { - mult_Top = 2; - move16(); - } - - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top * T_op[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ - } - ELSE - { - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ - } - } - - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; - move16(); - - /*-----------------------------------------------------------------* - * Find adaptive part of excitation, encode pitch period - *-----------------------------------------------------------------*/ - - IF( EQ_16( nBits, 10 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - pit16k_Q_enc_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE IF( EQ_16( nBits, 8 ) ) /* tc_subfr==0 && i_subfr==L_SUBFR */ - { - /*-----------------------------------------------------------------------------* - * The pitch range is encoded absolutely with 8 bits and is divided as follows: - * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) - *-----------------------------------------------------------------------------*/ - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - - IF( GT_16( *T0_max, 2 * L_SUBFR ) ) - { - *T0 = 2 * L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - } - - IF( LT_16( *T0, PIT16k_FR2_TC0_2SUBFR ) ) - { - /*index = (*T0)*4 + (*T0_frac) - (PIT16k_MIN*4);*/ - index = add( shl( *T0, 2 ), sub( *T0_frac, PIT16k_MIN * 4 ) ); - } - ELSE - { - /*index = (*T0)*2 + ((*T0_frac)>>1) - (PIT16k_FR2_TC0_2SUBFR*2) + ((PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4);*/ - index = add( sub( add( shl( *T0, 1 ), shr( *T0_frac, 1 ) ), ( PIT16k_FR2_TC0_2SUBFR * 2 ) ), ( PIT16k_FR2_TC0_2SUBFR - PIT16k_MIN ) * 4 ); - } - push_indice( hBstr, IND_PITCH, index, nBits ); - } - ELSE IF( EQ_16( nBits, 6 ) ) - { - /* delta search */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - - index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); - push_indice( hBstr, IND_PITCH, index, nBits ); - } - - IF( EQ_16( nBits, 6 ) ) - { - limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - - /*-----------------------------------------------------------------* - * - gain clipping test to avoid unstable synthesis - * - LP filtering of the adaptive excitation - * - codebook target computation - *-----------------------------------------------------------------*/ - test(); - IF( ( EQ_16( i_subfr, L_SUBFR ) ) && ( EQ_16( *T0, 2 * L_SUBFR ) ) ) - { - *gain_pit_fx = 0; - move16(); - *clip_gain = 0; - move16(); - g_corr_fx[0] = 328 /* 0.01f in Q15 */; - move16(); - g_corr_fx[1] = 0; - move16(); - g_corr_fx[2] = 328 /* 0.01f in Q15 */; - move16(); - g_corr_fx[3] = 0; - move16(); - *Jopt_flag = 0; - move16(); - - set16_fx( &exc_fx[i_subfr], 0, L_SUBFR + 1 ); /* set excitation for current subrame to 0 */ - push_indice( hBstr, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ - - Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ - set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ - set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); - } - ELSE - { - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4_ivas_fx( &exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - offset = L_deposit_l( 0 ); - - tmp = extract_l( L_mult( *T0_frac, 32 ) ); /*Q8, 0.25 in Q7*/ - tmp = add( 512, tmp ); /*Q8; 2 in Q8*/ - tmp = mult_r( tmp, 256 ); /*Q16->Q0; 2 in Q7*/ - - tmp1 = sub( *T0, 2 ); /*Q0*/ - tmp1 = shl( tmp1, 1 ); /*Q0 */ - - offset = add( tmp, tmp1 ); /*Q0*/ - FOR( i = 0; i < L_SUBFR * 2; i++ ) - { - /* bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - *T0 * 2 - (int) ((float) *T0_frac * 0.5f + 4 + 0.5f) + 4];move16();*/ - bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - offset + 4]; - move16(); - } - - *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, Q_new ); - move16(); - - lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); - IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) - { - push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - *Jopt_flag = 1; - move16(); - } - - /***pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch value */ - /***pt_pitch_fx = shl(add(*T0,shr(*T0_frac,2)),4); move16();*/ - tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); - **pt_pitch_fx = tmp; - move16(); - - /*---------------------------------------------------------------------* - * fill the pitch buffer - needed for post-processing - *---------------------------------------------------------------------*/ - test(); - test(); - IF( ( EQ_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) || ( *tc_subfr == 0 && EQ_16( i_subfr, 2 * L_SUBFR ) ) ) - { - index = shr( i_subfr, 6 ); - ( *pt_pitch_fx ) -= index; - move16(); - - FOR( i = 0; i < index; i++ ) - { - **pt_pitch_fx = tmp; - move16(); - ( *pt_pitch_fx )++; - move16(); - } - } - } - } - - return; -} - - -/*-------------------------------------------------------------------------------------------* - * tc_enc() - * - * Principal function for transition coding (TC) in encoder. - * Glottal codebook contribution part: - * - * |----| |----| xn - * imp_pos->|| | imp_shape->| g1 | | - * | | | | g2 | ---- exc |---| y1 ---- | - * | | |-------------| |----|gain|-------| h |------|gain|----(-)---> xn2 - * | || | gn | ---- |---| ---- - * |----| |----| - * codebook excitation gain_trans h_orig gain_pit - * - *-------------------------------------------------------------------------------------------*/ - -static void tc_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subrame index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *position, /* i/o: index of the residual signal maximum */ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ - Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ - Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ - Word16 *T0_min, /* o : lower pitch limit Q0*/ - Word16 *T0_max, /* o : higher pitch limit Q0*/ - Word16 *T0, /* o : close loop integer pitch Q0*/ - Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ - Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ - Word16 g_corr_fx[], /* o : correlations and -2 */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ - Word16 Q_new /* i : input scaling */ -) -{ - Word16 i, imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; - Word16 pitch_index, pitch_sign_fx; - Word32 gain_trans32; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - Flag Overflow = 0; - move32(); - imp_pos = sub( *position, i_subfr ); - FOR( i = 0; i < L_SUBFR; i++ ) - { - h1_tmp_fx[i] = h1_fx[i]; - move16(); - } - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; - move16(); - - /*--------------------------------------------------------------* - * Closed loop pitch search - *--------------------------------------------------------------*/ - - *T0_frac = 0; - move16(); - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - test(); - IF( ( LE_16( *T0_min, L_SUBFR ) ) || ( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) - { - IF( EQ_16( nBits, 9 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - ELSE IF( EQ_16( nBits, 6 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - ELSE - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - } - ELSE - { - *T0 = L_SUBFR; - move16(); - } - - test(); - if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) - { - *T0 = L_SUBFR; - move16(); - } - } - ELSE /* st_fx->L_frame == L_FRAME16k */ - { - IF( EQ_16( nBits, 10 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - ELSE IF( EQ_16( nBits, 6 ) ) + ELSE IF( EQ_16( nBits, 6 ) ) { /* T0_frac with 1/2 sample resolution */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); @@ -1960,228 +1199,6 @@ static void tc_enc_fx( } -static void tc_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subrame index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *position, /* i/o: index of the residual signal maximum */ - const Word16 *h1, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ - Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ - Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ - Word16 *T0_min, /* o : lower pitch limit Q0*/ - Word16 *T0_max, /* o : higher pitch limit Q0*/ - Word16 *T0, /* o : close loop integer pitch Q0*/ - Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ - Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ - Word16 g_corr_fx[], /* o : correlations and -2 */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ - Word16 Q_new /* i : input scaling */ -) -{ - - Word16 h1_fx[L_SUBFR + ( M + 1 )]; - Word16 imp_shape, imp_pos, index, nBits; - Word16 pitch_index, pitch_sign_fx; - Word32 gain_trans32; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - Flag Overflow = 0; - move32(); - imp_pos = sub( *position, i_subfr ); - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; - move16(); - - /*--------------------------------------------------------------* - * Closed loop pitch search - *--------------------------------------------------------------*/ - - *T0_frac = 0; - move16(); - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - test(); - IF( ( LE_16( *T0_min, L_SUBFR ) ) || ( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) - { - IF( EQ_16( nBits, 9 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - ELSE IF( EQ_16( nBits, 6 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - ELSE - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - } - ELSE - { - *T0 = L_SUBFR; - move16(); - } - - test(); - if ( EQ_16( *tc_subfr, L_SUBFR ) && LT_16( *T0, L_SUBFR ) ) - { - *T0 = L_SUBFR; - move16(); - } - } - ELSE /* st_fx->L_frame == L_FRAME16k */ - { - IF( EQ_16( nBits, 10 ) ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - } - ELSE IF( EQ_16( nBits, 6 ) ) - { - /* T0_frac with 1/2 sample resolution */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR, 0 /*st_fx->element_mode*/, Q_new ); - move16(); - - IF( *T0 > L_SUBFR ) - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - } - } - } - - /* set tc_subfr to TC_0_0 */ - test(); - test(); - test(); - if ( i_subfr == 0 && EQ_16( st_fx->L_frame, L_FRAME ) && ( LT_16( *T0, L_SUBFR ) || EQ_16( *tc_subfr, 3 * L_SUBFR ) ) ) - { - *tc_subfr = TC_0_0; - move16(); - } - - /*--------------------------------------------------------------* - * Builds glottal codebook contribution - *--------------------------------------------------------------*/ - - set_impulse_fx( xn_fx, h1, &exc_fx[i_subfr], yy1_fx, &imp_shape, &imp_pos, &gain_trans32, Q_new ); - - /*--------------------------------------------------------------* - * quantize gain_trans and scale glottal codebook contribution - *--------------------------------------------------------------*/ - - gain_trans_enc_fx( gain_trans32, &exc_fx[i_subfr], &pitch_index, &pitch_sign_fx, Q_new ); - - /* set past excitation buffer to zeros */ - set16_fx( exc_fx - L_EXC_MEM, 0, L_EXC_MEM ); - - /*--------------------------------------------------------------* - * adapt. search of the second impulse in the same subframe - * (when appears) - *--------------------------------------------------------------*/ - - pred_lt4_tc_fx( exc_fx, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - - IF( st_fx->hBWE_TD != NULL ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); - } - ELSE - { - interp_code_4over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR ); - } - } - - /*--------------------------------------------------------------* - * compute glottal-shape codebook excitation - *--------------------------------------------------------------*/ - - Copy( h1, h1_fx, L_SUBFR + ( M + 1 ) ); - /* create filtered glottal codebook contribution */ - conv_fx( &exc_fx[i_subfr], h1_fx, yy1_fx, L_SUBFR ); - - /* gain_pit computation */ - *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0, &Overflow ); - move16(); - - /*--------------------------------------------------------------* - * Encode parameters and write indices - *--------------------------------------------------------------*/ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - test(); - test(); - IF( ( ( i_subfr != 0 ) || ( EQ_16( *tc_subfr, TC_0_0 ) ) ) && ( NE_16( *tc_subfr, L_SUBFR ) ) ) - { - test(); - /* write pitch index */ - IF( ( GE_16( *T0, L_SUBFR ) ) && ( NE_16( *tc_subfr, 3 * L_SUBFR ) ) ) - { - push_indice( hBstr, IND_PITCH, 0, nBits ); - } - ELSE IF( EQ_16( *tc_subfr, 3 * L_SUBFR ) ) - { - IF( EQ_16( nBits, 9 ) ) - { - index = abs_pit_enc_fx( 4, 0, *T0, *T0_frac ); - } - ELSE - { - index = abs_pit_enc_fx( 2, 0, *T0, *T0_frac ); - } - push_indice( hBstr, IND_PITCH, index, nBits ); - - limit_T0_fx( L_FRAME, 8, 0, 0, *T0, 0, T0_min, T0_max ); - } - ELSE - { - IF( EQ_16( nBits, 6 ) ) - { - index = delta_pit_enc_fx( 2, *T0, *T0_frac, PIT_MIN - 1 ); - push_indice( hBstr, IND_PITCH, index, nBits ); - } - ELSE - { - index = delta_pit_enc_fx( 0, *T0, *T0_frac, PIT_MIN - 1 ); - push_indice( hBstr, IND_PITCH, index, nBits ); - } - } - } - } - ELSE /* st_fx->L_frame == L_FRAME16k */ - { - IF( EQ_16( nBits, 10 ) ) - { - pit16k_Q_enc_fx( hBstr, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE IF( EQ_16( nBits, 6 ) ) - { - index = add( shl( sub( *T0, PIT16k_MIN ), 1 ), shr( *T0_frac, 1 ) ); - push_indice( hBstr, IND_PITCH, index, nBits ); - } - } - push_indice( hBstr, IND_TC_IMP_SHAPE, imp_shape, 3 ); - push_indice( hBstr, IND_TC_IMP_POS, imp_pos, 6 ); - push_indice( hBstr, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); - push_indice( hBstr, IND_TC_IMP_GAIN, pitch_index, 3 ); - - *position = add( imp_pos, i_subfr ); - move16(); - return; -} - - /*-----------------------------------------------------------------* * gain_trans_enc() * diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index 62af228a0c75fac8ba24e23c64a406ec0c29b2d5..d0826c42953b0177216ddcdaf36b23e0abf1ab90 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -141,6 +141,7 @@ void updt_enc_fx( } /* core switching updates */ Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 ); + st->old_Es_pred_fx = Es_pred; move16(); @@ -193,11 +194,13 @@ void updt_IO_switch_enc_fx( hTdCngEnc->old_enr_index = s_min( mult( shl( hTdCngEnc->old_enr_index, 1 ), 32459 ), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ move16(); } + /* Perform preemphasis of the old input signal @16kHz */ st->mem_preemph16k_fx = 0; move16(); - PREEMPH_FX( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) ); + preemph_fx( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) ); Scale_sig( st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new ); + /* reset TD BWE buffers */ set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); @@ -295,6 +298,7 @@ void updt_IO_switch_enc_fx( return; } + /*-------------------------------------------------------------------* * updt_enc_common_fx() * @@ -302,230 +306,6 @@ void updt_IO_switch_enc_fx( *-------------------------------------------------------------------*/ void updt_enc_common_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 Etot, /* i : total energy */ - const Word16 Q_new /* i : CUrrent frame scaling */ -) -{ - /*---------------------------------------------------------------------* - * Updates - main main codec parameters - *---------------------------------------------------------------------*/ - - st->last_sr_core = st->sr_core; - move32(); - st->last_codec_mode = st->codec_mode; - move16(); - st->last_L_frame = st->L_frame; - move16(); - st->last_core = st->core; - move16(); - - st->last_core_brate = st->core_brate; - move32(); - st->last_total_brate = st->total_brate; - move32(); - st->last_extl = st->extl; - move16(); - st->last_input_bwidth = st->input_bwidth; - move16(); - st->last_bwidth = st->bwidth; - move16(); - IF( GT_16( st->element_mode, EVS_MONO ) ) - { - st->hNoiseEst->Etot_last_32fx = L_deposit_h( Etot ); - } - ELSE - { - st->hNoiseEst->Etot_last_fx = Etot; - } - move16(); - st->last_coder_type_raw = st->coder_type_raw; - move16(); - - st->prev_Q_new = Q_new; - move16(); - - test(); - IF( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL ) - { - st->hDtxEnc->last_active_brate = st->total_brate; - move32(); - } - - IF( st->hBWE_TD != NULL ) - { - st->hBWE_TD->prev_coder_type = st->coder_type; - move16(); - IF( EQ_16( st->core, HQ_CORE ) ) - { - /* in the HQ core, coder_type is not used so it could have been set to anything */ - st->hBWE_TD->prev_coder_type = GENERIC; - move16(); - } - } - - test(); - IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) - { - IF( GT_32( st->core_brate, SID_2k40 ) ) - { - IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) ) - { - IF( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) ) - { - st->hTdCngEnc->act_cnt = 0; - move16(); - } - st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 ); - move16(); - - test(); - IF( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 ) - { - st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 ); - move16(); - } - } - - test(); - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) - { - st->hTdCngEnc->act_cnt2 = add( st->hTdCngEnc->act_cnt2, 1 ); - st->hTdCngEnc->act_cnt2 = s_min( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ); - move16(); - move16(); - - test(); - test(); - test(); - IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) - { - } - } - } - - test(); - test(); - test(); - IF( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) ) - { - st->hDtxEnc->first_CNG = 1; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Increase the counter of initialization frames - * Limit the max number of init. frames - *-----------------------------------------------------------------*/ - - if ( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) ) - { - st->ini_frame = add( st->ini_frame, 1 ); - move16(); - } - - /* synchronisation of CNG seeds */ - test(); - test(); - test(); - IF( st->hTdCngEnc != NULL && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_16( st->core, AMR_WB_CORE ) ) - { - Random( &( st->hTdCngEnc->cng_seed ) ); - Random( &( st->hTdCngEnc->cng_ener_seed ) ); - } - - /*---------------------------------------------------------------------* - * Updates - MODE2 - *---------------------------------------------------------------------*/ - - IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) - { - st->codec_mode = MODE2; - move16(); - - st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 ); - move32(); - - // st->L_frame = extract_l(Mult_32_16(st->sr_core, INV_FRAME_PER_SEC_Q15)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/ - - IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) - { - st->preemph_fac = PREEMPH_FAC; - st->gamma = GAMMA1; - st->L_frame = L_FRAME; - move16(); - move16(); - move16(); - } - ELSE - { - st->preemph_fac = PREEMPH_FAC_16k; - st->gamma = GAMMA16k; - st->L_frame = L_FRAME16k; - move16(); - move16(); - move16(); - } - - st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode ); - move16(); - } - - /* update FER clas */ - IF( NE_16( st->core, AMR_WB_CORE ) ) - { - st->last_clas = st->clas; - move16(); - } - - /* Update Core */ - core_encode_update_fx( st ); - - /*---------------------------------------------------------------------* - * RF mode updates - *---------------------------------------------------------------------*/ - - IF( st->rf_mode ) - { - IF( st->hSC_VBR != NULL ) - { - st->hSC_VBR->last_nelp_mode = 0; - move16(); - IF( EQ_16( st->hRF->rf_frame_type, RF_NELP ) ) - { - st->hSC_VBR->last_nelp_mode = 1; - move16(); - } - } - } - - st->rf_mode_last = st->rf_mode; - move16(); - - IF( st->Opt_RF_ON ) - { - st->L_frame = L_FRAME; - st->rf_mode = 1; - move16(); - move16(); - } - - /*---------------------------------------------------------------------* - * Other updates - *---------------------------------------------------------------------*/ - - test(); - IF( GT_16( st->element_mode, EVS_MONO ) && st->hTcxEnc != NULL ) - { - } - return; -} - - -void updt_enc_common_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 Q_new /* i : CUrrent frame scaling */ ) @@ -703,7 +483,7 @@ void updt_enc_common_ivas_fx( } /* Update Core */ - core_encode_update_ivas_fx( st ); + core_encode_update_fx( st ); /*---------------------------------------------------------------------* * RF mode updates diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 4335225cac66e2b1e65e986785a76cbebd14ab0e..7c541478058975c0b623e303c7d9a8833b7e8a7f 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -229,202 +229,6 @@ static void sign_thr_snr_acc_fx( *-----------------------------------------------------------------*/ Word16 dtx_hangover_addition_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ - Word16 *vad_hover_flag_ptr, - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ -) -{ - Word16 hangover_short_dtx; /* Q0 */ - Word16 flag_dtx; /* Q0 */ - Word16 tmp; /* Q0 */ - if ( hNoiseEst == NULL ) - { - hNoiseEst = st_fx->hNoiseEst; - move16(); - } - - if ( hVAD == NULL ) - { - move16(); - hVAD = st_fx->hVAD; - } - - - flag_dtx = 0; - move16(); - - /* Determine initial hangover length */ - hangover_short_dtx = 2; - move16(); - - test(); - test(); - if ( ( ( LT_16( lp_snr, ( 16 * 256 ) ) ) && ( st_fx->input_bwidth != NB ) ) || ( GT_16( hVAD->prim_act_he_fx, 31130 ) ) ) /*.95*Q15*/ - { - hangover_short_dtx = 3; - move16(); - } - - /* Adjust hangover according to activity history */ - IF( GT_16( hVAD->vad_prim_cnt_16, 12 ) ) /* 12 requires roughly > 80% primary activity */ - { - hangover_short_dtx = add( hangover_short_dtx, 2 ); - } - - IF( GT_16( hVAD->vad_flag_cnt_50, 40 ) ) /* 40 requires roughtly > 80% flag activity */ - { - hangover_short_dtx = add( hangover_short_dtx, 5 ); - } - - /* Keep hangover_short lower than maximum hangover count */ - if ( GT_16( hangover_short_dtx, HANGOVER_LONG_FX - 1 ) ) - { - hangover_short_dtx = ( HANGOVER_LONG_FX - 1 ); - move16(); - } - - /* Only allow short HO if not sufficient active frames in clean speech*/ - - tmp = 3; - move16(); /* default for EVS*/ - if ( EQ_16( st_fx->core, AMR_WB_CORE ) ) - { - tmp = 2; - move16(); /* default for AMRWBIO*/ - } - - /* need to be a bit stricter with the DTXHO in very clean WB, SWB cond for EVS12k8VAD section */ - test(); - test(); - if ( ( NE_16( st_fx->input_bwidth, NB ) ) /* WB or SWB or FB */ - && ( NE_16( st_fx->core, AMR_WB_CORE ) ) && ( GT_16( lp_snr, 25 * 256 ) ) ) - { - tmp = 2; - move16(); - } - - /* limit dtx hangover addition up to "tmp" frames in clean cond */ - IF( tmp != 0 ) - { - test(); - test(); - test(); - if ( ( GT_16( hangover_short_dtx, tmp ) ) && ( ( LT_16( hVAD->vad_prim_cnt_16, 7 ) ) || ( ( GT_16( lp_snr, ( 16 * 256 ) ) ) && ( LT_16( hVAD->prim_act_he_fx, 27853 ) ) /*0.85f*2^15 */ - ) ) ) - { - hangover_short_dtx = tmp; - move16(); - } - } - - - /* hangover adjustment from combined FFT+CLDFBVAD */ - IF( NE_16( st_fx->core, AMR_WB_CORE ) ) - { - hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); /* Q0 */ - hangover_short_dtx = s_max( hangover_short_dtx, 0 ); - } - - IF( vad_flag != 0 ) /* Speech present */ - { - flag_dtx = 1; - move16(); - - /* Add hangover after sufficient # of active frames or sufficient activity during last second */ - test(); - if ( ( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) || ( GT_16( hVAD->vad_flag_cnt_50, 45 ) ) ) /* 45 requires roughly > 90% flag activity */ - { - hVAD->hangover_cnt_dtx = 0; - move16(); - } - - /* inside HO period */ - test(); - IF( ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) && ( hVAD->hangover_cnt_dtx != 0 ) ) - { - hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); /* Q0 */ - move16(); - } - hVAD->hangover_terminate_flag = 0; - move16(); /* float fix FIX_HO_TERMINATE */ - - /* Music hangover when music detected */ - test(); - test(); - test(); - if ( ( GT_16( hVAD->prim_act_he_fx, 31129 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ - { - hVAD->hangover_cnt_music = 0; - move16(); - } - - /* inside Music HO period */ - test(); - IF( ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) && ( hVAD->hangover_cnt_music != 0 ) ) - { - hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); - move16(); - } - } - ELSE - { - /* Reset the counter of speech frames necessary to start hangover algorithm */ - IF( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) /* inside HO period */ - { - hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); - move16(); - } - IF( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) /* inside HO period */ - { - hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); - move16(); - } - - /* fast terminate DTX hangover if st->hangover_terminate_flag is set */ - IF( hVAD->hangover_terminate_flag != 0 ) - { - hVAD->hangover_cnt = HANGOVER_LONG_FX; - move16(); - hVAD->hangover_cnt_dtx = HANGOVER_LONG_FX; - move16(); - hVAD->hangover_terminate_flag = 0; - move16(); - /* Only shorten music hangover when low energy frames */ - if ( LT_16( hNoiseEst->Etot_lp_fx, 20 * 256 ) ) - { - hVAD->hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; - move16(); - } - } - - if ( LE_16( hVAD->hangover_cnt_dtx, hangover_short_dtx ) ) /* "hard" hangover */ - { - flag_dtx = 1; - move16(); - } - - if ( LE_16( hVAD->hangover_cnt_music, 15 ) ) /* "hard" hangover music */ - { - flag_dtx = 1; - move16(); - } - } - - - test(); - if ( flag_dtx != 0 && st_fx->localVAD == 0 ) - { - *vad_hover_flag_ptr = 1; - move16(); - } - - return flag_dtx; -} -Word16 ivas_dtx_hangover_addition_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 vad_flag, /* i Q0 */ const Word16 lp_snr, /* i Q8 */ @@ -437,6 +241,7 @@ Word16 ivas_dtx_hangover_addition_fx( Word16 hangover_short_dtx; /* Q0 */ Word16 flag_dtx; /* Q0 */ Word16 tmp; /* Q0 */ + if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; @@ -449,7 +254,6 @@ Word16 ivas_dtx_hangover_addition_fx( hVAD = st_fx->hVAD; } - flag_dtx = 0; move16(); @@ -484,7 +288,6 @@ Word16 ivas_dtx_hangover_addition_fx( } /* Only allow short HO if not sufficient active frames in clean speech*/ - tmp = 3; move16(); /* default for EVS*/ if ( EQ_16( st_fx->core, AMR_WB_CORE ) ) @@ -503,7 +306,7 @@ Word16 ivas_dtx_hangover_addition_fx( move16(); } - /* limit dtx hangover addition up to "tmp" frames in clean cond */ + /* limit dtx hangover addition up to "tmp" frames in clean cond */ IF( tmp != 0 ) { test(); @@ -517,13 +320,13 @@ Word16 ivas_dtx_hangover_addition_fx( } } - /* hangover adjustment from combined FFT+CLDFBVAD */ IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); /*Q0*/ hangover_short_dtx = s_max( hangover_short_dtx, 0 ); } + IF( vad_flag != 0 ) /* Speech present */ { flag_dtx = 1; @@ -551,10 +354,24 @@ Word16 ivas_dtx_hangover_addition_fx( test(); test(); test(); - if ( ( GT_16( hVAD->prim_act_he_fx, 32113 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ + IF( st_fx->element_mode == EVS_MONO ) { - hVAD->hangover_cnt_music = 0; - move16(); + if ( ( GT_16( hVAD->prim_act_he_fx, 31129 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ + { + hVAD->hangover_cnt_music = 0; + move16(); + } + } + ELSE + { + test(); + test(); + test(); + if ( ( GT_16( hVAD->prim_act_he_fx, 32113 ) ) && ( GT_16( hNoiseEst->Etot_lp_fx, 40 * 256 ) ) && ( GT_16( hVAD->vad_prim_cnt_16, 14 ) ) && ( GT_16( hVAD->vad_flag_cnt_50, 48 ) ) ) /* 45 requires roughly > 95% flag activity */ + { + hVAD->hangover_cnt_music = 0; + move16(); + } } /* inside Music HO period */ @@ -609,9 +426,7 @@ Word16 ivas_dtx_hangover_addition_fx( } } - test(); - IF( flag_dtx != 0 && st_fx->localVAD == 0 ) { *vad_hover_flag_ptr = 1; @@ -625,6 +440,8 @@ Word16 ivas_dtx_hangover_addition_fx( return flag_dtx; } + + /*-----------------------------------------------------------------* * wb_vad() * @@ -745,8 +562,7 @@ Word16 wb_vad_fx( st_fx->max_band = 19; move16(); } - - IF( 1 ) // st_fx->Opt_SC_VBR ) /* this keep 26.444 BE */ + IF( st_fx->Opt_SC_VBR || ( !st_fx->Opt_SC_VBR && st_fx->element_mode == EVS_MONO ) ) /* this keep 26.444 BE */ { last_7k2_coder_type = st_fx->hSC_VBR->last_7k2_coder_type; move16(); diff --git a/lib_isar/isar_MSPred.c b/lib_isar/isar_MSPred.c index aaa26903b5bb6700c23542d1a0d2d9953a41dcc1..6698a12b35500a5ddd0c661119547186b1e8aa6f 100644 --- a/lib_isar/isar_MSPred.c +++ b/lib_isar/isar_MSPred.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_NoiseGen.c b/lib_isar/isar_NoiseGen.c deleted file mode 100644 index 363e758fffbdd642dc3aa4061bd3ee6ac13e2853..0000000000000000000000000000000000000000 --- a/lib_isar/isar_NoiseGen.c +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2025 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 -#include "options.h" -#include -#include "prot_fx.h" -#include "isar_lcld_prot.h" -#include "wmc_auto.h" - - -/*------------------------------------------------------------------------------------------* - * Function DeleteNoiseGen() - * - * - *------------------------------------------------------------------------------------------*/ - -void DeleteNoiseGen( NoiseGen *psNoiseGen ) -{ - free( psNoiseGen->pfNoiseBuffer ); - free( psNoiseGen ); - - return; -} - -extern Word32 GetNoise_fx( NoiseGen *psNoiseGen ); diff --git a/lib_isar/isar_PerceptualModel.c b/lib_isar/isar_PerceptualModel.c index 54265bc5ee5e06f9c14e79296fa5db35f42cb592..3ad12b9a42e6bb012fe8f9fe073246e53a2c0c6d 100644 --- a/lib_isar/isar_PerceptualModel.c +++ b/lib_isar/isar_PerceptualModel.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -84,35 +84,6 @@ static inline Word16 LogAdd_fx( } -/*------------------------------------------------------------------------------------------* - * Function LogAdd() - * - * - *------------------------------------------------------------------------------------------*/ - -static inline Word32 LogAdd( - const Word32 iVal1, - const Word32 iVal2 ) -{ - Word32 iRetVal; - - if ( iVal1 > iVal2 ) - { - iRetVal = iVal1 - iVal2; - iRetVal = ( iRetVal < ( LOG_ADD_TABLE_LENGTH - 1 ) ) ? iRetVal : ( LOG_ADD_TABLE_LENGTH - 1 ); - iRetVal = iVal1 + c_aiLogAddTable[iRetVal]; - } - else - { - iRetVal = iVal2 - iVal1; - iRetVal = ( iRetVal < ( LOG_ADD_TABLE_LENGTH - 1 ) ) ? iRetVal : ( LOG_ADD_TABLE_LENGTH - 1 ); - iRetVal = iVal2 + c_aiLogAddTable[iRetVal]; - } - - return iRetVal; -} - - /*------------------------------------------------------------------------------------------* * Function PerceptualModel() * @@ -175,62 +146,6 @@ void PerceptualModel_fx( return; } -/*------------------------------------------------------------------------------------------* - * Function PerceptualModel() - * - * - *------------------------------------------------------------------------------------------*/ - -void PerceptualModel( - const Word32 iMaxQuantBands, - const Word32 *piRMSEnvelope, - Word32 *piExcitation, - Word32 *piSMR ) -{ - Word32 n; - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - Word32 iSLOffset; - - piExcitation[n] = PERCEPTUAL_MODEL_SCALE * piRMSEnvelope[n] + c_aiBandwidthAdjust48[n]; - - /* Calculate sensation level offset */ - iSLOffset = c_aiDefaultTheta48[n] * ( piExcitation[n] - c_aiAbsoluteThresh48[n] ) >> PERCEPTUAL_MODEL_SLGAIN_SHIFT; - // iSLOffset = (iSLOffset > 0) ? iSLOffset : 0; - - /* Offset envelope by sensation level offset */ - piExcitation[n] -= iSLOffset; - - /* Convert to loudness domain (x^0.3) */ - piExcitation[n] = PERCEPTUAL_MODEL_ALPHA_SCALE * piExcitation[n] >> PERCEPTUAL_MODEL_ALPHA_SHIFT; - } - - /* Spread excitation function */ - for ( n = 0; n < iMaxQuantBands; n++ ) - { - Word32 k; - const Word32 *piSpread; - - piSpread = &c_aaiSpreadFunction48[n * MAX_BANDS_48]; - piSMR[n] = piExcitation[n] + piSpread[n]; - for ( k = 0; k < iMaxQuantBands; k++ ) - { - if ( k != n ) - { - piSMR[n] = LogAdd( piSMR[n], piExcitation[k] + piSpread[k] ); - } - } - } - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - piSMR[n] = PERCEPTUAL_MODEL_ALPHA_INV_SCALE * piSMR[n] >> PERCEPTUAL_MODEL_ALPHA_SHIFT; - piSMR[n] = PERCEPTUAL_MODEL_SCALE * piRMSEnvelope[n] + c_aiBandwidthAdjust48[n] - piSMR[n]; - } - - return; -} /*------------------------------------------------------------------------------------------* @@ -239,115 +154,7 @@ void PerceptualModel( * *------------------------------------------------------------------------------------------*/ -void PerceptualModelStereo( - const Word32 iMaxQuantBands, - const Word32 *piMSFlags, - const Word32 *piRMSEnvelope0, - const Word32 *piRMSEnvelope1, - Word32 *piExcitation0, - Word32 *piExcitation1, - Word32 *piSMR0, - Word32 *piSMR1 ) -{ - Word32 n; - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - Word32 iMaxRMSEnv; - Word32 iSLOffset; - - iMaxRMSEnv = piRMSEnvelope0[n]; - - piExcitation0[n] = PERCEPTUAL_MODEL_SCALE * iMaxRMSEnv + c_aiBandwidthAdjust48[n]; /* piRMSEnvelope0[n] */ - - /* Calculate sensation level offset */ - iSLOffset = c_aiDefaultTheta48[n] * ( piExcitation0[n] - c_aiAbsoluteThresh48[n] ) >> PERCEPTUAL_MODEL_SLGAIN_SHIFT; - // iSLOffset = (iSLOffset > 0) ? iSLOffset : 0; - /* Offset envelope by sensation level offset */ - piExcitation0[n] -= iSLOffset; - - /* Convert to loudness domain (x^0.3) */ - piExcitation0[n] = PERCEPTUAL_MODEL_ALPHA_SCALE * piExcitation0[n] >> PERCEPTUAL_MODEL_ALPHA_SHIFT; - } - - /* Spread excitation function */ - for ( n = 0; n < iMaxQuantBands; n++ ) - { - Word32 k; - const Word32 *piSpread; - - piSpread = &c_aaiSpreadFunction48[n * MAX_BANDS_48]; - piSMR0[n] = piExcitation0[n] + piSpread[n]; - for ( k = 0; k < iMaxQuantBands; k++ ) - { - if ( k != n ) - { - piSMR0[n] = LogAdd( piSMR0[n], piExcitation0[k] + piSpread[k] ); - } - } - } - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - Word32 iMaxRMSEnv; - Word32 iSLOffset; - - iMaxRMSEnv = piRMSEnvelope1[n]; - - piExcitation1[n] = PERCEPTUAL_MODEL_SCALE * iMaxRMSEnv + c_aiBandwidthAdjust48[n]; /* piRMSEnvelope1[n] */ - - /* Calculate sensation level offset */ - iSLOffset = c_aiDefaultTheta48[n] * ( piExcitation1[n] - c_aiAbsoluteThresh48[n] ) >> PERCEPTUAL_MODEL_SLGAIN_SHIFT; - // iSLOffset = (iSLOffset > 0) ? iSLOffset : 0; - - /* Offset envelope by sensation level offset */ - piExcitation1[n] -= iSLOffset; - - /* Convert to loudness domain (x^0.3) */ - piExcitation1[n] = PERCEPTUAL_MODEL_ALPHA_SCALE * piExcitation1[n] >> PERCEPTUAL_MODEL_ALPHA_SHIFT; - } - - /* Spread excitation function */ - for ( n = 0; n < iMaxQuantBands; n++ ) - { - Word32 k; - const Word32 *piSpread; - - piSpread = &c_aaiSpreadFunction48[n * MAX_BANDS_48]; - piSMR1[n] = piExcitation1[n] + piSpread[n]; - for ( k = 0; k < iMaxQuantBands; k++ ) - { - if ( k != n ) - { - piSMR1[n] = LogAdd( piSMR1[n], piExcitation1[k] + piSpread[k] ); - } - } - } - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - if ( piMSFlags[n] == 1 ) - { - piSMR0[n] = ( piSMR0[n] > piSMR1[n] ) ? piSMR0[n] : piSMR1[n]; - piSMR1[n] = piSMR0[n]; - } - } - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - piSMR0[n] = PERCEPTUAL_MODEL_ALPHA_INV_SCALE * piSMR0[n] >> PERCEPTUAL_MODEL_ALPHA_SHIFT; - piSMR0[n] = PERCEPTUAL_MODEL_SCALE * piRMSEnvelope0[n] + c_aiBandwidthAdjust48[n] - piSMR0[n]; - } - - for ( n = 0; n < iMaxQuantBands; n++ ) - { - piSMR1[n] = PERCEPTUAL_MODEL_ALPHA_INV_SCALE * piSMR1[n] >> PERCEPTUAL_MODEL_ALPHA_SHIFT; - piSMR1[n] = PERCEPTUAL_MODEL_SCALE * piRMSEnvelope1[n] + c_aiBandwidthAdjust48[n] - piSMR1[n]; - } - - return; -} void PerceptualModelStereo_fx( const Word32 iMaxQuantBands, const Word32 *piMSFlags, diff --git a/lib_isar/isar_PredDecoder.c b/lib_isar/isar_PredDecoder.c index f6e031e451b2619942131ef3c62dc3609f0c66b9..94d85f2ebe75f543c5ed58064141d7840052ee29 100644 --- a/lib_isar/isar_PredDecoder.c +++ b/lib_isar/isar_PredDecoder.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "prot_fx.h" #include "isar_prot.h" #include "isar_lcld_prot.h" @@ -361,24 +360,6 @@ Word16 ReadPredictors_fx( } -/* PLC_IMPROVEMENT */ -void SetDecodingPassed( - PredictionDecoder *psPredictionDecoder ) -{ - Word32 n, ch; - - for ( ch = 0; ch < psPredictionDecoder->iChannels; ch++ ) - { - for ( n = 0; n < psPredictionDecoder->iNumSubSets; n++ ) - { - psPredictionDecoder->ppiDecodingFailed[ch][n] = 0; - } - } - - return; -} - - Word32 AnyDecodingUnresolved( PredictionDecoder *psPredictionDecoder ) { diff --git a/lib_isar/isar_PredEncoder.c b/lib_isar/isar_PredEncoder.c index 769ae86a5f78418932da5d3d2224c92c1899a741..1cad13a8c85e3598d77135c4d097abe6ff30a741 100644 --- a/lib_isar/isar_PredEncoder.c +++ b/lib_isar/isar_PredEncoder.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "isar_lcld_prot.h" #include "isar_rom_lcld_tables.h" #include "prot_fx.h" @@ -465,7 +464,7 @@ void ComputePredictors_fx( Word16 w_norm3 = W_norm( W_temp2 ); W_temp2 = W_shr( W_temp2, 32 - w_norm3 ); pfRxxImag_fx[1] = W_extract_l( W_temp2 ); - Word16 final_w_norm = min( w_norm1, min( w_norm2, w_norm3 ) ); + Word16 final_w_norm = s_min( w_norm1, s_min( w_norm2, w_norm3 ) ); pfRxxReal_fx[0] = L_shr( pfRxxReal_fx[0], w_norm1 - final_w_norm ); // Q8 + final_w_norm pfRxxReal_fx[1] = L_shr( pfRxxReal_fx[1], w_norm2 - final_w_norm ); // Q8 + final_w_norm pfRxxImag_fx[1] = L_shr( pfRxxImag_fx[1], w_norm3 - final_w_norm ); // Q8 + final_w_norm @@ -542,7 +541,7 @@ void ComputePredictors_fx( // fGain_fx = sub(sub(32767, extract_h(Mpy_32_32(fA1Real_fx, fA1Real_fx))), extract_h(Mpy_32_32(fA1Imag_fx, fA1Imag_fx))); // fGain_fx = extract_l(L_shl(L_temp, 2*sf_r)); fGain_fx = extract_l( L_temp ); - fGain_fx = max( 1, fGain_fx ); + fGain_fx = L_max( 1, fGain_fx ); fGain_fx = Inv16( extract_l( fGain_fx ), &exp ); // Q15 - exp // fGain_fx = L_shl(fGain_fx, exp); //Q15 // fBitGain = 0.65f * log2f(fGain) * (float)(iNumBlocksPerPredCoef)-(float)(PRED_QUNAT_FILTER_MAG_BITS + PRED_QUANT_FILTER_PHASE_BITS); // Wrong fix (iNumBlocks-1) diff --git a/lib_isar/isar_RMSEnvGrouping.c b/lib_isar/isar_RMSEnvGrouping.c index 428cc66b3637aa064bcc8d7655080ce96400530d..ab6237a5395da32f9392ece1f9dec1de41285aab 100644 --- a/lib_isar/isar_RMSEnvGrouping.c +++ b/lib_isar/isar_RMSEnvGrouping.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,7 +34,6 @@ #include #include "options.h" -#include #include "prot_fx.h" #include "isar_lcld_prot.h" #include "isar_rom_lcld_tables.h" @@ -50,7 +49,7 @@ * *-------------------------------------------------------------------*/ -Word32 Inv_grp_length[17] = { +static const Word32 Inv_grp_length[17] = { // Q31 0, 2147483647, @@ -868,8 +867,8 @@ static void LimitRMSEnvelope( IF( GT_32( iDelta, iRMSDeltaMax ) ) { -#ifdef DEBUG_VERBOSE - printf( "WARNING RMS envelope delta limited\n" ); +#ifdef DEBUGGING + printf( "Warning: RMS envelope delta limited!\n" ); #endif piRMSEnvelope[iBand] = L_add( L_sub( iDelta, iRMSDeltaMax ), piRMSEnvelope[iBand] ); } @@ -888,8 +887,8 @@ static void LimitRMSEnvelope( IF( LT_32( iDelta, iRMSDeltaMin ) ) { -#ifdef DEBUG_VERBOSE - printf( "WARNING RMS envelope delta limited\n" ); +#ifdef DEBUGGING + printf( "Warning: RMS envelope delta limited!\n" ); #endif piRMSEnvelope[iBand] = L_add( piRMSEnvelope[iBand], L_sub( iRMSDeltaMin, iDelta ) ); } diff --git a/lib_isar/isar_cnst.h b/lib_isar/isar_cnst.h index 40d6c393857ee28145728999a52dfded680ec8db..449577f4374b17b1b64bbc5088af007af5b30c27 100644 --- a/lib_isar/isar_cnst.h +++ b/lib_isar/isar_cnst.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -41,6 +41,8 @@ * Split Binaural Rendering Constants *----------------------------------------------------------------------------------*/ +#define PI2_FX 1686629713 //Q28 + typedef enum { PCM_INT16, diff --git a/lib_isar/isar_lc3plus_common.c b/lib_isar/isar_lc3plus_common.c index f7fe0db32ebeba38eeec378a57c47154a8031046..68e160538c27e69f4db5a640a746eb8a6a273a2b 100644 --- a/lib_isar/isar_lc3plus_common.c +++ b/lib_isar/isar_lc3plus_common.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lc3plus_common.h b/lib_isar/isar_lc3plus_common.h index 3b52e5b3f15c0ce29c25f7d640140530db05afb6..5af4f80a81a1ac696ac05e97d2b963d9d18ca7b0 100644 --- a/lib_isar/isar_lc3plus_common.h +++ b/lib_isar/isar_lc3plus_common.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lc3plus_dec.c b/lib_isar/isar_lc3plus_dec.c index 2ac21e4d3670fa1542c9e0752ef448eefa0b8933..7f158cc04c686e2c9831bab394256461a9d7d7c5 100644 --- a/lib_isar/isar_lc3plus_dec.c +++ b/lib_isar/isar_lc3plus_dec.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lc3plus_dec.h b/lib_isar/isar_lc3plus_dec.h index 8328b1fa767274db5be43ed4a8bcdc64d4a79cee..461e15dc8cdfc24c55b7f45d2fe03ad566b286e5 100644 --- a/lib_isar/isar_lc3plus_dec.h +++ b/lib_isar/isar_lc3plus_dec.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lc3plus_enc.c b/lib_isar/isar_lc3plus_enc.c index 60121a11f7e96c8bbb219bfdf1897513d0f1575f..9795833a341296110660fef758086aaa4fc3556a 100644 --- a/lib_isar/isar_lc3plus_enc.c +++ b/lib_isar/isar_lc3plus_enc.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -48,11 +48,11 @@ static int32_t limit_per_channel_bitrate( LC3PLUS_CONFIG config, switch ( config.lc3plus_frame_duration_us ) { case 10000: - return min( per_channel_bitrate, 500000 ); + return L_min( per_channel_bitrate, 500000 ); case 5000: - return min( per_channel_bitrate, 600000 ); + return L_min( per_channel_bitrate, 600000 ); case 2500: - return min( per_channel_bitrate, 672000 ); + return L_min( per_channel_bitrate, 672000 ); default: assert( false && "unreachable" ); } @@ -62,13 +62,13 @@ static int32_t limit_per_channel_bitrate( LC3PLUS_CONFIG config, { case 48000: case 32000: - return min( per_channel_bitrate, 320000 ); + return L_min( per_channel_bitrate, 320000 ); case 24000: - return min( per_channel_bitrate, 314400 ); + return L_min( per_channel_bitrate, 314400 ); case 16000: - return min( per_channel_bitrate, 221600 ); + return L_min( per_channel_bitrate, 221600 ); case 8000: - return min( per_channel_bitrate, 114400 ); + return L_min( per_channel_bitrate, 114400 ); default: assert( false && "unreachable" ); } @@ -558,7 +558,7 @@ ivas_error ISAR_LC3PLUS_ENC_Encode( FOR( UWord32 iSampleInt16 = 0; iSampleInt16 < numSamplesPerLC3plusChannel; iSampleInt16++ ) { ivasSampleIndex = iSampleInt16 + iMediaTime * numSamplesPerLC3plusChannel; - handle->pcm_conversion_buffer[iSampleInt16] = (Word16) max( INT16_MIN, min( L_shr( pcm_in[iEnc][ivasSampleIndex], q_in[iEnc] ), INT16_MAX ) ); + handle->pcm_conversion_buffer[iSampleInt16] = (Word16) L_max( INT16_MIN, L_min( L_shr( pcm_in[iEnc][ivasSampleIndex], q_in[iEnc] ), INT16_MAX ) ); } ftdIndex = iMediaTime * handle->num_encs + iEnc; diff --git a/lib_isar/isar_lc3plus_enc.h b/lib_isar/isar_lc3plus_enc.h index 6dd08733fa2deeae01a83473ffa1854e65009713..793da7b9fba9404e05dfaec15cd1a8b85bd1b055 100644 --- a/lib_isar/isar_lc3plus_enc.h +++ b/lib_isar/isar_lc3plus_enc.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lc3plus_payload.c b/lib_isar/isar_lc3plus_payload.c index 2493aa6a30eb9ca3ab8f493dc1dad4e057666b98..0a201b0743e29d7120afce088699f244c882e8d4 100644 --- a/lib_isar/isar_lc3plus_payload.c +++ b/lib_isar/isar_lc3plus_payload.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lc3plus_payload.h b/lib_isar/isar_lc3plus_payload.h index 580a58ca651defe96eeb84229b8f07b3407a756c..7ebdb33426d0dbac4246e4c146703876e9404eb7 100644 --- a/lib_isar/isar_lc3plus_payload.h +++ b/lib_isar/isar_lc3plus_payload.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_lcld_decoder.c b/lib_isar/isar_lcld_decoder.c index 8bb931e3f7e6f23e1d26a6b8b2370691942ae692..d4d6074f8f9ac193e3ec122bc05d036a94cf5f27 100644 --- a/lib_isar/isar_lcld_decoder.c +++ b/lib_isar/isar_lcld_decoder.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -105,9 +105,6 @@ struct LCLD_DECODER Word32 ***pppiQLCLDImag; PredictionDecoder *psPredictionDecoder; - - - NoiseGen *psNoiseGen; }; static void CreateDecodeTable( LCLDDecoder *psLCLDDecoder, Word32 num, const UWord16 ( *ppuiEncTable )[2], Word32 iSize, Word32 iReadLength, UWord32 *iTables ); @@ -604,7 +601,6 @@ ivas_error CreateLCLDDecoder( { return error; } - psLCLDDecoder->psNoiseGen = NULL; /* CreateNoiseGen(); No noise fill for now*/ *psLCLDDecoder_out = psLCLDDecoder; return IVAS_ERR_OK; @@ -766,10 +762,6 @@ void DeleteLCLDDecoder( psLCLDDecoder->psPredictionDecoder = NULL; } - IF( psLCLDDecoder->psNoiseGen != NULL ) - { - DeleteNoiseGen( psLCLDDecoder->psNoiseGen ); - } free( psLCLDDecoder ); } @@ -788,7 +780,7 @@ static void ApplyRMSEnvelope_fx( const Word32 iNumBands, const Word32 *piBandwid static void ReplaceSign_fx( const Word32 iNumBlocks, const Word32 iNumLCLDBands, Word32 **ppiSignReal, Word32 **ppiSignImag, Word32 **ppfReal, Word32 **ppfImag, const Word32 *piBandwidths ); -static void InvQuantizeSpectrum_fx( const Word32 iNumGroups, const Word32 *piGroupLengths, const Word32 iNumBands, const Word32 *piBandwidths, Word32 **ppiAlloc, Word32 **ppiQReal, Word32 **ppiQImag, Word32 **ppfReal, Word32 **ppfImag, NoiseGen *psNoiseGen ); +static void InvQuantizeSpectrum_fx( const Word32 iNumGroups, const Word32 *piGroupLengths, const Word32 iNumBands, const Word32 *piBandwidths, Word32 **ppiAlloc, Word32 **ppiQReal, Word32 **ppiQImag, Word32 **ppfReal, Word32 **ppfImag ); static void InvMSCoding_fx( const Word32 iNumBlocks, const Word32 iNumBands, const Word32 *piBandwidths, const Word32 iMSMode, const Word32 *piMSFlags, const Word32 *piLRPhaseDiffs, const Word32 *piMSPredCoefs, Word32 ***pppfReal, Word32 ***pppfImag ); @@ -1010,8 +1002,7 @@ Word32 DecodeLCLDFrame( psLCLDDecoder->pppiAlloc[n], psLCLDDecoder->pppiQLCLDReal[n], psLCLDDecoder->pppiQLCLDImag[n], - pppfLCLDReal_fx[n], pppfLCLDImag_fx[n], - psLCLDDecoder->psNoiseGen ); + pppfLCLDReal_fx[n], pppfLCLDImag_fx[n] ); ReplaceSign_fx( psLCLDDecoder->iNumBlocks, psLCLDDecoder->iNumBands, psLCLDDecoder->pppiLCLDSignReal[n], @@ -1100,7 +1091,7 @@ Word32 DecodeLCLDFrame( } IF( NE_32( real_max, 0 ) || NE_32( imag_max, 0 ) ) { - exp = min( exp2, exp1 ); + exp = s_min( exp2, exp1 ); *Q_out = add( *Q_out, sub( exp, 3 ) ); FOR( n = 0; n < psLCLDDecoder->iChannels; n++ ) { @@ -1281,9 +1272,7 @@ static void InvQuantizeSpectrum_fx( Word32 **ppiQReal, Word32 **ppiQImag, Word32 **ppfReal, - Word32 **ppfImag, - NoiseGen *psNoiseGen /* Pass in NULL to switch off noise gen */ -) + Word32 **ppfImag ) { Word32 b, k, n; Word32 iBlockOffest, iFBOffset; @@ -1322,17 +1311,6 @@ static void InvQuantizeSpectrum_fx( iFBOffset++; } } - ELSE IF( psNoiseGen != NULL ) - { - FOR( m = 0; m < piBandwidths[b]; m++ ) - { - ppfReal[iBlockOffest][iFBOffset] = Mpy_32_16_1( GetNoise_fx( psNoiseGen ), 22938 ); // Q(14 + 15 -15 )=Q14 - move32(); - ppfImag[iBlockOffest][iFBOffset] = Mpy_32_16_1( GetNoise_fx( psNoiseGen ), 22938 ); // Q(14+ 15 -15 )=Q14 - move32(); - iFBOffset++; - } - } ELSE { iFBOffset = L_add( iFBOffset, piBandwidths[b] ); @@ -1585,7 +1563,7 @@ static Word32 ReadMSInformation( } ELSE { - printf( "ERROR UNSUPPORTED MS MODE\n" ); + printf( "Error in ReadMSInformation() - unsupported MS mode information!\n" ); } return iBitsRead; diff --git a/lib_isar/isar_lcld_encoder.c b/lib_isar/isar_lcld_encoder.c index 915e2a5e493fcba3e3ca3f860c64c9a937e6fcd3..9b33cc6537b7d3fe31df3a4e2ed1232b68b437dc 100644 --- a/lib_isar/isar_lcld_encoder.c +++ b/lib_isar/isar_lcld_encoder.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include #include "isar_lcld_prot.h" #include "isar_rom_lcld_tables.h" @@ -136,7 +135,8 @@ static Word32 UnQuantize_fx( } return fVal_fx; } -static void PackReal( + +static void PackReal_fx( const Word32 iChannels, const Word32 iNumBlocks, Word32 ***pppfReal, @@ -160,6 +160,7 @@ static void PackReal( } } } + /*------------------------------------------------------------------------------------------* * Function CreateLCLDEncoder() * @@ -590,7 +591,7 @@ Word32 EncodeLCLDFrame( assert( available_bits <= pBits->buf_len * 8 ); IF( EQ_32( psLCLDEncoder->iRealOnlyOut, 1 ) ) { - PackReal( psLCLDEncoder->iChannels, psLCLDEncoder->iNumBlocks * 2, pppfLCLDReal_fx, pppfLCLDImag_fx ); + PackReal_fx( psLCLDEncoder->iChannels, psLCLDEncoder->iNumBlocks * 2, pppfLCLDReal_fx, pppfLCLDImag_fx ); } /* Do MS calc here */ IF( EQ_32( psLCLDEncoder->iChannels, 2 ) ) @@ -771,17 +772,6 @@ Word32 EncodeLCLDFrame( return 0; } -/*------------------------------------------------------------------------------------------* - * Function GetNumGroups() - * - * - *------------------------------------------------------------------------------------------*/ - -Word32 GetNumGroups( LCLDEncoder *psLCLDEncoder ) -{ - return psLCLDEncoder->piNumGroups[0]; -} - /*------------------------------------------------------------------------------------------* * Local functions @@ -969,12 +959,12 @@ static Word32 MSModeCalculation_fx( iFBOffset++; } - Q_en_tmp = min( Q_en_tmp, W_norm( fLeftEnergy_fx64 ) ); - Q_en_tmp = min( Q_en_tmp, W_norm( fRightEnergy_fx64 ) ); - Q_en_tmp = min( Q_en_tmp, W_norm( fMidEnergy_fx64 ) ); - Q_en_tmp = min( Q_en_tmp, W_norm( fSideEnergy_fx64 ) ); - Q_en_tmp = min( Q_en_tmp, W_norm( fLRCovReal_fx64 ) ); - Q_en_tmp = min( Q_en_tmp, W_norm( fLRCovImag_fx64 ) ); + Q_en_tmp = s_min( Q_en_tmp, W_norm( fLeftEnergy_fx64 ) ); + Q_en_tmp = s_min( Q_en_tmp, W_norm( fRightEnergy_fx64 ) ); + Q_en_tmp = s_min( Q_en_tmp, W_norm( fMidEnergy_fx64 ) ); + Q_en_tmp = s_min( Q_en_tmp, W_norm( fSideEnergy_fx64 ) ); + Q_en_tmp = s_min( Q_en_tmp, W_norm( fLRCovReal_fx64 ) ); + Q_en_tmp = s_min( Q_en_tmp, W_norm( fLRCovImag_fx64 ) ); Q_en_tmp = sub( Q_en_tmp, 2 ); fLeftEnergy_fx = W_extract_h( W_shl( fLeftEnergy_fx64, Q_en_tmp ) ); fRightEnergy_fx = W_extract_h( W_shl( fRightEnergy_fx64, Q_en_tmp ) ); @@ -997,7 +987,7 @@ static Word32 MSModeCalculation_fx( fSideEnergyPred_fx = L_add( fSideEnergy_fx, L_sub( Mpy_32_32( Mpy_32_32( fPred_fx, fPred_fx ), fMidEnergy_fx ), L_shr( Mpy_32_32( fPred_fx, L_sub( fLeftEnergy_fx, fRightEnergy_fx ) ), 1 ) ) ); - fSideEnergyPred_fx = max( fSideEnergyPred_fx, 0 ); + fSideEnergyPred_fx = L_max( fSideEnergyPred_fx, 0 ); ppiMSPredCoefs[MS_PRED_ONLY][b] = iPred; move32(); @@ -1055,7 +1045,7 @@ static Word32 MSModeCalculation_fx( fSideEnergyPred_fx = L_add( fSideEnergyPred_fx, L_sub( Mpy_32_32( Mpy_32_32( fPred_fx, fPred_fx ), fMidEnergyPred_fx ), L_shr( Mpy_32_32( fPred_fx, L_sub( fLeftEnergy_fx, fRightEnergy_fx ) ), 1 ) ) ); - fSideEnergyPred_fx = max( fSideEnergyPred_fx, 0 ); + fSideEnergyPred_fx = L_max( fSideEnergyPred_fx, 0 ); /* -= fPred * fPred * fMidEnergyPred doesn't work because fPred is quantized and does not match MS/MM exactly */ ppiMSPredCoefs[MS_PHASE_AND_PRED][b] = iPred; move32(); @@ -1126,7 +1116,7 @@ static Word32 MSModeCalculation_fx( { piMsPredInfoBits[iMSPredType] = CountMSBits( iNumBands, MS_PRED, ppiMSPredFlags[iMSPredType], ppiMSPredPhase[iMSPredType], ppiMSPredCoefs[iMSPredType] ); // pfMSPredBitGain[iMSPredType] = max( pfMSPredBitGain[iMSPredType] - piMsPredInfoBits[iMSPredType], 0.0f ); - pfMSPredBitGain_fx[iMSPredType] = max( pfMSPredBitGain_fx[iMSPredType] - L_shl( piMsPredInfoBits[iMSPredType], q_pfMSPredBitGain_fx ), 0 ); + pfMSPredBitGain_fx[iMSPredType] = L_max( pfMSPredBitGain_fx[iMSPredType] - L_shl( piMsPredInfoBits[iMSPredType], q_pfMSPredBitGain_fx ), 0 ); } /* find the best M/S Pred type */ @@ -1851,7 +1841,7 @@ static Word32 WriteAllocInformation( IF( LT_32( iAllocOffset, MIN_ALLOC_OFFSET ) || GT_32( iAllocOffset, MAX_ALLOC_OFFSET ) ) { - printf( "Serious error\n" ); + printf( "Error in WriteAllocInformation() - iAllocOffset has incorrect value: %d!\n", iAllocOffset ); } ISAR_SPLIT_REND_BITStream_write_int32( pBits, L_sub( iAllocOffset, MIN_ALLOC_OFFSET ), ALLOC_OFFSET_BITS ); @@ -2091,10 +2081,7 @@ static Word32 ComputeAllocation( IF( LE_32( *piAllocOffset, MIN_ALLOC_OFFSET ) && GT_32( iBitsUsed, iAvailableBits ) ) { -#ifdef DEBUG_VERBOSE - printf( "Frame can not be coded with the number of bits available\n" ); -#endif - // iLastError = ENC_ERROR_STREAM_FAILURE; + printf( "Error in ComputeAllocation() - frame can not be coded with the number of bits available!\n" ); return -1; } ELSE IF( GE_32( *piAllocOffset, MAX_ALLOC_OFFSET ) && LT_32( iBitsUsed, iAvailableBits ) ) diff --git a/lib_isar/isar_lcld_prot.h b/lib_isar/isar_lcld_prot.h index 00c1859014ae7a13afb5017d758721c0b235eef8..aa9cd51071c8f6f45737e9a952c932cb5a601ced 100644 --- a/lib_isar/isar_lcld_prot.h +++ b/lib_isar/isar_lcld_prot.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -65,10 +65,6 @@ Word32 EncodeLCLDFrame( Word16 *q_final ); -Word32 GetNumGroups( - LCLDEncoder *psLCLDEncoder -); - typedef struct LCLD_DECODER LCLDDecoder; @@ -170,44 +166,11 @@ Word32 CountMSBits( ); -/*----------------------------------------------------------------------------------* - * NoiseGen prototypes - *----------------------------------------------------------------------------------*/ - -typedef struct NOISE_GEN -{ - Word32 iNoiseBufferLength; - Word32 iNoiseBufferMask; - Word32 iNoiseBufferIndex; - float *pfNoiseBuffer; -} NoiseGen; - -void DeleteNoiseGen( - NoiseGen *psNoiseGen -); - -inline Word32 GetNoise_fx( NoiseGen *psNoiseGen ) -{ - Word32 fNoiseSample; - - fNoiseSample = (Word32) (psNoiseGen->pfNoiseBuffer[psNoiseGen->iNoiseBufferIndex]* (1<<14)); - psNoiseGen->iNoiseBufferIndex++; - psNoiseGen->iNoiseBufferIndex &= psNoiseGen->iNoiseBufferMask; - - return fNoiseSample; -} - /*----------------------------------------------------------------------------------* * PereptualModel prototypes *----------------------------------------------------------------------------------*/ -extern void PerceptualModel( - const Word32 iMaxQuantBands, - const Word32 *piRMSEnvelope, - Word32 *piExcitation, - Word32 *piSMR -); extern void PerceptualModel_fx( const Word32 iMaxQuantBands, @@ -227,17 +190,6 @@ extern void PerceptualModelStereo_fx( Word32 *piSMR1 ); -extern void PerceptualModelStereo( - const Word32 iMaxQuantBands, - const Word32 *piMSFlags, - const Word32 *piRMSEnvelope0, - const Word32 *piRMSEnvelope1, - Word32 *piExcitation0, - Word32 *piExcitation1, - Word32 *piSMR0, - Word32 *piSMR1 -); - /*----------------------------------------------------------------------------------* * PredEncoder/PredDecoder prototypes @@ -369,9 +321,6 @@ Word32 **GetDecodingFailedPrevStatus( LCLDDecoder *psLCLDDecoder ); -void SetDecodingPassed( - PredictionDecoder *psPredictionDecoder -); void UpdateDecodingUnresolved( PredictionDecoder *psPredictionDecoder diff --git a/lib_isar/isar_prot.h b/lib_isar/isar_prot.h index 10aaa6db52cdb10e25a11801839c47542a38965e..43990c55ba68b7380d0745cc1eea957a41a2063f 100644 --- a/lib_isar/isar_prot.h +++ b/lib_isar/isar_prot.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -58,7 +58,7 @@ ivas_error split_renderer_open_lc3plus( SPLIT_REND_WRAPPER *hSplitRendWrapper, /* i/o: Split renderer pre-renderer handle */ const ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, /* i : Split renderer pre-renderer config */ const Word32 output_Fs, /* i : output sampling rate */ - const IVAS_RENDER_FRAMESIZE ivas_frame_size /* i : IVAS frame size */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes /* i : rendering number of subframes */ ); void isar_splitBinPreRendClose( @@ -370,8 +370,8 @@ Word32 isar_get_split_rend_md_target_brate( const Word16 pcm_out_flag /* i : flag to indicate PCM output */ ); -ivas_error isar_framesize_to_ms( - const IVAS_RENDER_FRAMESIZE frame_size, /* i : frame size enum */ +ivas_error isar_num_subfr_to_ms( + const IVAS_RENDER_NUM_SUBFR render_num_subframes, /* i : rendering number of subframes */ Word16 *ms /* o : frame size in ms */ ); diff --git a/lib_isar/isar_rom_lcld_tables.c b/lib_isar/isar_rom_lcld_tables.c index 5fd334447fa8e2aa60061ae8d0ef5a8add1eda91..d3b596b40ee3c8c9f212c463c372d96b53c9dc42 100644 --- a/lib_isar/isar_rom_lcld_tables.c +++ b/lib_isar/isar_rom_lcld_tables.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_rom_lcld_tables.h b/lib_isar/isar_rom_lcld_tables.h index a2cbe5f25c4888d9658a51c3e017332441981fa4..0b8a46bb630acef0a75efad1c0e88b05e38edc42 100644 --- a/lib_isar/isar_rom_lcld_tables.h +++ b/lib_isar/isar_rom_lcld_tables.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_rom_post_rend.c b/lib_isar/isar_rom_post_rend.c index 954d89f639892eb743b15adc3dc29aac4e70c91f..2e4bf8ab815ce0964fc5ad9e7bf4da4e138cd87c 100644 --- a/lib_isar/isar_rom_post_rend.c +++ b/lib_isar/isar_rom_post_rend.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,7 @@ #ifdef DEBUGGING #include "debug.h" #endif -#include "cnst.h" +#include "ivas_cnst.h" #include "isar_cnst.h" #include #include "wmc_auto.h" diff --git a/lib_isar/isar_rom_post_rend.h b/lib_isar/isar_rom_post_rend.h index a08bb174f70461578c389b55d40f63897084cb00..b7bca73bdbea2993f209032ed0014b12a412ccca 100644 --- a/lib_isar/isar_rom_post_rend.h +++ b/lib_isar/isar_rom_post_rend.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_splitRend_lcld_dec.c b/lib_isar/isar_splitRend_lcld_dec.c index 07017803ef8f5386e1d073717afa0add91e36581..b4047a750e6abc8e3907b19d5bbd0ec75475c1cb 100644 --- a/lib_isar/isar_splitRend_lcld_dec.c +++ b/lib_isar/isar_splitRend_lcld_dec.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_splitRend_lcld_enc.c b/lib_isar/isar_splitRend_lcld_enc.c index 567cec0a4ccfda2c2f66167b0ebf3eb3fc886e32..32346f887b8928acc9911550297ff7ab33c75f5b 100644 --- a/lib_isar/isar_splitRend_lcld_enc.c +++ b/lib_isar/isar_splitRend_lcld_enc.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/isar_splitRendererPLC.c b/lib_isar/isar_splitRendererPLC.c index d807a26e6ea2eebbd5a35efbadce5d281a56e74c..d29a5272298b5613e812762c05abfd16babd4a91 100644 --- a/lib_isar/isar_splitRendererPLC.c +++ b/lib_isar/isar_splitRendererPLC.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "ivas_prot_fx.h" #include "prot_fx.h" #include "isar_cnst.h" @@ -309,8 +308,8 @@ static void adaptive_polar_ext_plc_fx( fac_ph_real_fx = L_deposit_h( getCosWord16R2( dth16 ) ); fac_ph_imag_fx = L_deposit_h( getSineWord16R2( dth16 ) ); ///* calculate complex evolution factor */ - fac_real_fx = Mpy_32_32( min( L_shl( 1, drho_q ), drho_32 ), fac_ph_real_fx ); // Qdrho_exp - fac_imag_fx = Mpy_32_32( min( L_shl( 1, drho_q ), drho_32 ), fac_ph_imag_fx ); // Qdrho_exp + fac_real_fx = Mpy_32_32( L_min( L_shl( 1, drho_q ), drho_32 ), fac_ph_real_fx ); // Qdrho_exp + fac_imag_fx = Mpy_32_32( L_min( L_shl( 1, drho_q ), drho_32 ), fac_ph_imag_fx ); // Qdrho_exp #if START_VAL_AVG_LEN > 1 /* Calculate start value FOR evolution from last samples of previous frame */ fac_powj_real_fx = fac_real_fx; @@ -489,11 +488,11 @@ static void adaptive_polar_ext_plc_fx( IF( EQ_16( drho_q, 31 ) ) { - abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( min( ONE_IN_Q31, drho_32 ), max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e + abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( L_min( ONE_IN_Q31, drho_32 ), L_max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e } ELSE { - abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( min( L_shl( 1, drho_q ), drho_32 ), max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e + abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( L_min( L_shl( 1, drho_q ), drho_32 ), L_max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e } temp_16 = sub( add( drho_q, sqrt_exp ), tmp_e ); @@ -601,11 +600,11 @@ static void adaptive_polar_ext_plc_fx( IF( EQ_16( drho_q, 31 ) ) { - abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( min( ONE_IN_Q31, drho_32 ), max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e + abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( L_min( ONE_IN_Q31, drho_32 ), L_max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e } ELSE { - abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( min( L_shl( 1, drho_q ), drho_32 ), max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e + abs2inv_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( L_min( L_shl( 1, drho_q ), drho_32 ), L_max( 1, abs_temp_fx ), &tmp_e ) ); // +drho_q +sqrt_exp-tmp_e } temp_16 = sub( add( drho_q, sqrt_exp ), tmp_e ); rat_real_fx = W_mult_32_32( rat_real32_fx, abs2inv_fx ); diff --git a/lib_isar/isar_splitRendererPost.c b/lib_isar/isar_splitRendererPost.c index ce04691f1715b7fdd43b7c5d4253fed24e2a5701..380b9f976a7abcd28211fe800d9fbbdd9d889c7e 100644 --- a/lib_isar/isar_splitRendererPost.c +++ b/lib_isar/isar_splitRendererPost.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG #include #endif @@ -43,7 +42,6 @@ #ifdef DEBUGGING #include "debug.h" #endif -#include "prot_fx.h" #include "wmc_auto.h" #include "basop_util.h" #define Q31_BY_360 ( 5965232 ) // Q31 @@ -1110,7 +1108,7 @@ static Word32 get_interp_fact_fx( IF( LT_32( interp_fact_fx, 0 ) ) { - d_fx = max( -( MAX_EXTRAPOLATION_ANGLE_Q22 ), ( min( ( MAX_EXTRAPOLATION_ANGLE_Q22 ), d_fx ) ) ); + d_fx = L_max( -( MAX_EXTRAPOLATION_ANGLE_Q22 ), ( L_min( ( MAX_EXTRAPOLATION_ANGLE_Q22 ), d_fx ) ) ); move32(); n_fx = L_deposit_h( getSineWord16R2( extract_l( L_shr( Mpy_32_32( n_fx, Q31_BY_360 ), 7 ) ) ) ); move32(); @@ -1360,8 +1358,8 @@ static void interpolate_pred_matrix_fx( { FOR( Word16 j = 0; j < BINAURAL_CHANNELS; j++ ) { - max_exp_re = max( max_exp_re, buff_exp_re[i][j] ); - max_exp_im = max( max_exp_im, buff_exp_im[i][j] ); + max_exp_re = s_max( max_exp_re, buff_exp_re[i][j] ); + max_exp_im = s_max( max_exp_im, buff_exp_im[i][j] ); } } FOR( Word16 i = 0; i < BINAURAL_CHANNELS; i++ ) @@ -1502,7 +1500,7 @@ static void interpolate_rend_md_fx( Word16 exp_tmp1 = 0; Word32 tmp1 = BASOP_Util_Add_Mant32Exp( gd1_fx, 31 - Q25, L_negate( tmp ), 6 + 31 - Q_pitch, &exp_tmp1 ); pitch_gain_l_fx = tmp1; - pitch_gain_l_fx = max( 0, pitch_gain_l_fx ); + pitch_gain_l_fx = L_max( 0, pitch_gain_l_fx ); exp_pitch_gain_l = exp_tmp1; diff_fx = L_sub( gd3_fx, gd4_fx ); @@ -1514,7 +1512,7 @@ static void interpolate_rend_md_fx( exp_tmp1 = 0; tmp1 = BASOP_Util_Add_Mant32Exp( gd3_fx, 31 - Q25, L_negate( tmp ), 6 + 31 - Q_pitch, &exp_tmp1 ); pitch_gain_r_fx = tmp1; - pitch_gain_r_fx = max( 0, pitch_gain_r_fx ); + pitch_gain_r_fx = L_max( 0, pitch_gain_r_fx ); exp_pitch_gain_r = exp_tmp1; FOR( ch_idx1 = 0; ch_idx1 < BINAURAL_CHANNELS; ch_idx1++ ) @@ -1534,8 +1532,8 @@ static void interpolate_rend_md_fx( { FOR( Word16 j = 0; j < BINAURAL_CHANNELS; j++ ) { - max_exp_re = max( max_exp_re, exp_mat_re[i][j] ); - max_exp_im = max( max_exp_im, exp_mat_im[i][j] ); + max_exp_re = s_max( max_exp_re, exp_mat_re[i][j] ); + max_exp_im = s_max( max_exp_im, exp_mat_im[i][j] ); } } @@ -1657,7 +1655,7 @@ void isar_SplitRenderer_PostRenderer( { index_slot = slot_idx; /* TODO: can be cleaned up */ fade_fx = fade_table_fx[slot_idx]; - fade_fx = min( fade_fx, MAX_16 ); + fade_fx = s_min( fade_fx, MAX_16 ); FOR( b = 0; b < num_md_bands; b++ ) { FOR( ch_idx1 = 0; ch_idx1 < BINAURAL_CHANNELS; ch_idx1++ ) diff --git a/lib_isar/isar_splitRendererPre.c b/lib_isar/isar_splitRendererPre.c index c91a4d08fa6a88b0e78bcf6adefc931dae707cf9..f657e7d4b862a6ee51bae116964f8a1d5279ee59 100644 --- a/lib_isar/isar_splitRendererPre.c +++ b/lib_isar/isar_splitRendererPre.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG #include #endif @@ -350,7 +349,7 @@ static void ComputePredMat_fx( { FOR( j = 0; j < 2; j++ ) { - max_exp = max( max_exp, buff_exp[i][j] ); + max_exp = s_max( max_exp, buff_exp[i][j] ); } } @@ -638,8 +637,8 @@ static void ComputeBandedCrossCov_fx( { FOR( Word16 j = 0; j < num_chs; j++ ) { - max_cov_re = max( max_cov_re, exp_buff_re[i][j] ); - max_cov_im = max( max_cov_im, exp_buff_im[i][j] ); + max_cov_re = s_max( max_cov_re, exp_buff_re[i][j] ); + max_cov_im = s_max( max_cov_im, exp_buff_im[i][j] ); } } FOR( Word16 i = 0; i < num_chs; i++ ) @@ -790,8 +789,8 @@ static void ComputeBandedCov_fx( { FOR( Word16 j = 0; j < BINAURAL_CHANNELS; j++ ) { - exp_max_re = max( exp_max_re, exp_buff_re[i][j] ); - exp_max_im = max( exp_max_im, exp_buff_im[i][j] ); + exp_max_re = s_max( exp_max_re, exp_buff_re[i][j] ); + exp_max_im = s_max( exp_max_im, exp_buff_im[i][j] ); } } @@ -1102,7 +1101,7 @@ static void get_lr_gains( Word16 max_gd_exp = MIN16B; FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { - max_gd_exp = max( max_gd_exp, exp_gd_tmp_buf[i] ); + max_gd_exp = s_max( max_gd_exp, exp_gd_tmp_buf[i] ); } exp_gd_tmp = max_gd_exp; @@ -2706,17 +2705,18 @@ void isar_init_split_rend_handles( *------------------------------------------------------------------------*/ ivas_error split_renderer_open_lc3plus( - SPLIT_REND_WRAPPER *hSplitRendWrapper, - const ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, - const Word32 OutSampleRate, - const IVAS_RENDER_FRAMESIZE isar_frame_size ) + SPLIT_REND_WRAPPER *hSplitRendWrapper, /* i/o: Split renderer pre-renderer handle */ + const ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, /* i : Split renderer pre-renderer config */ + const Word32 OutSampleRate, /* i : output sampling rate */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes /* i : rendering number of subframes */ +) { ivas_error error; Word16 i, delayBufferLength; LC3PLUS_CONFIG config; Word16 isar_frame_size_ms; - IF( ( error = isar_framesize_to_ms( isar_frame_size, &isar_frame_size_ms ) ) != IVAS_ERR_OK ) + IF( ( error = isar_num_subfr_to_ms( render_num_subframes, &isar_frame_size_ms ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_isar/isar_splitRenderer_utils.c b/lib_isar/isar_splitRenderer_utils.c index 6f72ce6516262d58689f0dcccb78e689db370068..f8359c18f1f73c70e56c6d77a3428c405113817b 100644 --- a/lib_isar/isar_splitRenderer_utils.c +++ b/lib_isar/isar_splitRenderer_utils.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "ivas_prot_fx.h" #include "prot_fx.h" #include "cnst.h" @@ -1279,20 +1278,27 @@ void isar_init_multi_bin_pose_data_fx_enc( return; } -ivas_error isar_framesize_to_ms( - const IVAS_RENDER_FRAMESIZE frame_size, /* i : frame size enum */ - Word16 *ms /* o : frame size in ms */ + +/*------------------------------------------------------------------------- + * Function isar_num_subfr_to_ms() + * + * + *------------------------------------------------------------------------*/ + +ivas_error isar_num_subfr_to_ms( + const IVAS_RENDER_NUM_SUBFR render_num_subframes, /* i : rendering number of subframes */ + Word16 *ms /* o : frame size in ms */ ) { - switch ( frame_size ) + switch ( render_num_subframes ) { - case IVAS_RENDER_FRAMESIZE_5MS: + case IVAS_RENDER_NUM_SUBFR_5MS: *ms = 5; break; - case IVAS_RENDER_FRAMESIZE_10MS: + case IVAS_RENDER_NUM_SUBFR_10MS: *ms = 10; break; - case IVAS_RENDER_FRAMESIZE_20MS: + case IVAS_RENDER_NUM_SUBFR_20MS: *ms = 20; break; default: diff --git a/lib_isar/isar_stat.h b/lib_isar/isar_stat.h index e91184f4c542f79e4afb046a6abf8693f11e8acf..4849485880c01a761efc78414bf85ffc7436d430 100644 --- a/lib_isar/isar_stat.h +++ b/lib_isar/isar_stat.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_isar/lib_isar_post_rend.c b/lib_isar/lib_isar_post_rend.c index 2dcf72622e89ac12d0a4649654e56d8c1a7425d4..04e80dc619d2be05d03c5a5f913bd8b82d8c4a4d 100644 --- a/lib_isar/lib_isar_post_rend.c +++ b/lib_isar/lib_isar_post_rend.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,7 +38,6 @@ #include "ivas_prot_fx.h" #include "ivas_prot_rend_fx.h" #include -#include #include "wmc_auto.h" @@ -311,8 +310,7 @@ static Word32 limitRendererOutput_fx( /* Apply clipping to buffer in case the limiter let through some samples > 1.0f */ FOR( i = 0; i < output_frame * num_channels; ++i ) { - - output[i] = min( max( L_shl( INT16_MIN, q_factor ), output[i] ), L_shl( INT16_MAX, q_factor ) ); + output[i] = L_min( L_max( L_shl( INT16_MIN, q_factor ), output[i] ), L_shl( INT16_MAX, q_factor ) ); } return numClipping; @@ -491,7 +489,7 @@ static ivas_error updateSplitPostRendPanGains( IF( GT_16( hRendCfg->codec_frame_size_ms, 0 ) ) { iNumLCLDIterationsPerFrame = (Word16) config.isar_frame_duration_us / ( 1000 * hRendCfg->codec_frame_size_ms ); - iNumLCLDIterationsPerFrame = max( 1, iNumLCLDIterationsPerFrame ); + iNumLCLDIterationsPerFrame = s_max( 1, iNumLCLDIterationsPerFrame ); iNumBlocksPerFrame = CLDFB_NO_COL_MAX * hRendCfg->codec_frame_size_ms / 20; } ELSE @@ -775,7 +773,6 @@ ivas_error ISAR_POST_REND_SetInputGain( IF( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) { - printf( "Hoo\n" ); return error; } @@ -1004,7 +1001,7 @@ ivas_error ISAR_POST_REND_GetDelay( { latency_ns += IVAS_FB_DEC_DELAY_NS; } - max_latency_ns = max( max_latency_ns, latency_ns ); + max_latency_ns = L_max( max_latency_ns, latency_ns ); } } @@ -1064,7 +1061,6 @@ ivas_error ISAR_POST_REND_FeedInputAudio( IF( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) { - printf( "Foo\n" ); return error; } @@ -1187,7 +1183,6 @@ ivas_error ISAR_POST_REND_FeedSplitBinauralBitstream( IF( ( error = getInputById( hIvasRend, inputId, (void **) &inputBase ) ) != IVAS_ERR_OK ) { - printf( "Goo\n" ); return error; } diff --git a/lib_isar/lib_isar_post_rend.h b/lib_isar/lib_isar_post_rend.h index ba22fba6ab50ed2a8ae65a56477921c1e56f2f4e..d7f1cce841259ba8e34b0f3a685a3620cccbc800 100644 --- a/lib_isar/lib_isar_post_rend.h +++ b/lib_isar/lib_isar_post_rend.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -41,8 +41,7 @@ * ISAR post-renderer constants *---------------------------------------------------------------------*/ -#define RENDERER_MAX_ISAR_MD_INPUTS 1 -#define RENDERER_MAX_BIN_INPUTS 1 +#define RENDERER_MAX_BIN_INPUTS 1 /*---------------------------------------------------------------------* * ISAR post-renderer structures @@ -83,14 +82,6 @@ typedef struct ISAR_POST_REND const *ISAR_POST_REND_CONST_HANDLE; typedef UWord16 ISAR_POST_REND_InputId; -typedef enum _ISAR_POST_REND_COMPLEXITY_LEVEL -{ - ISAR_POST_REND_COMPLEXITY_LEVEL_ONE = 1, - ISAR_POST_REND_COMPLEXITY_LEVEL_TWO = 2, - ISAR_POST_REND_COMPLEXITY_LEVEL_THREE = 3 -} ISAR_POST_REND_COMPLEXITY_LEVEL; - - /* clang-format off */ /*----------------------------------------------------------------------------------* * ISAR post-renderer function prototypes diff --git a/lib_isar/lib_isar_pre_rend.c b/lib_isar/lib_isar_pre_rend.c index be7c3ff1f72b1666b4ef6bc92fd7787295071c9a..f9858f413029b12694e4c1794c21b0c992581815 100644 --- a/lib_isar/lib_isar_pre_rend.c +++ b/lib_isar/lib_isar_pre_rend.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "ivas_prot_fx.h" #include "prot_fx.h" #include "isar_cnst.h" @@ -52,13 +51,14 @@ *------------------------------------------------------------------------*/ ivas_error ISAR_PRE_REND_open( - SPLIT_REND_WRAPPER *hSplitRendWrapper, - ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, - const Word32 OutSampleRate, - const Word16 cldfb_in_flag, - const Word16 pcm_out_flag, - const IVAS_RENDER_FRAMESIZE ivas_frame_size, /* i: IVAS frame size */ - const Word16 mixed_td_cldfb_flag ) + SPLIT_REND_WRAPPER *hSplitRendWrapper, /* i/o: Split renderer pre-renderer handle */ + ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, /* i/o: Split renderer pre-renderer config */ + const Word32 OutSampleRate, /* i : output sampling rate */ + const Word16 cldfb_in_flag, /* i : Flag to indicate CLDFB or time doamin input */ + const Word16 pcm_out_flag, /* i : Flag to indicate PCM output */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes, /* i : rendering number of subframes */ + const Word16 mixed_td_cldfb_flag /* i : Flag to indicate combined TD and CLDFB input */ +) { ivas_error error, ch, num_ch; UWord8 isCldfbNeeded = 0; @@ -68,7 +68,7 @@ ivas_error ISAR_PRE_REND_open( &pSplitRendConfig->isar_frame_size_ms, &pSplitRendConfig->codec_frame_size_ms, cldfb_in_flag_local, - pcm_out_flag, (Word16) ivas_frame_size ) ) != IVAS_ERR_OK ) + pcm_out_flag, (Word16) render_num_subframes ) ) != IVAS_ERR_OK ) { return error; } @@ -151,7 +151,7 @@ ivas_error ISAR_PRE_REND_open( { IF( EQ_16( pSplitRendConfig->codec, ISAR_SPLIT_REND_CODEC_LC3PLUS ) ) { - IF( ( error = split_renderer_open_lc3plus( hSplitRendWrapper, pSplitRendConfig, OutSampleRate, ivas_frame_size ) ) != IVAS_ERR_OK ) + IF( ( error = split_renderer_open_lc3plus( hSplitRendWrapper, pSplitRendConfig, OutSampleRate, render_num_subframes ) ) != IVAS_ERR_OK ) { return error; } @@ -179,7 +179,7 @@ ivas_error ISAR_PRE_REND_open( *------------------------------------------------------------------------*/ void ISAR_PRE_REND_close( - SPLIT_REND_WRAPPER *hSplitBinRend, /* i/o: Split renderer pre-renerer handle */ + SPLIT_REND_WRAPPER *hSplitBinRend, /* i/o: Split renderer pre-renderer handle */ IVAS_REND_AudioBuffer *pSplitRendEncBuffer /* i/o: Split renderer data buffer */ ) { @@ -259,7 +259,7 @@ void ISAR_PRE_REND_close( *-------------------------------------------------------------------------*/ void ISAR_PRE_REND_GetMultiBinPoseData( - const ISAR_SPLIT_REND_CONFIG_DATA *pSplit_rend_config, /* i : Split renderer pre-renerer config */ + const ISAR_SPLIT_REND_CONFIG_DATA *pSplit_rend_config, /* i : Split renderer pre-renderer config */ MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ const ISAR_SPLIT_REND_ROT_AXIS rot_axis /* i : Rotation axis */ ) @@ -277,13 +277,13 @@ void ISAR_PRE_REND_GetMultiBinPoseData( *------------------------------------------------------------------------*/ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( - SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renerer handle */ - const IVAS_QUATERNION headPosition, /* i : head rotation QUATERNION */ - const Word32 SplitRendBitRate, /* i : Split renderer bitrate */ - ISAR_SPLIT_REND_CODEC splitCodec, /* i/o: Split renderer codec */ - const Word16 isar_frame_size_ms, /* i : ISAR framesize */ - Word16 codec_frame_size_ms, /* i/o: ISAR transport codec framesize */ - ISAR_SPLIT_REND_BITS_HANDLE pBits, + SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renderer handle */ + const IVAS_QUATERNION headPosition, /* i : head rotation QUATERNION */ + const Word32 SplitRendBitRate, /* i : Split renderer bitrate */ + ISAR_SPLIT_REND_CODEC splitCodec, /* i/o: Split renderer codec */ + const Word16 isar_frame_size_ms, /* i : ISAR framesize */ + Word16 codec_frame_size_ms, /* i/o: ISAR transport codec framesize */ + ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: ISAR bits handle */ Word32 *Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i/o: CLDFB real buffer */ Word32 *Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], /* i/o: CLDFB imag buffer */ const Word16 max_bands, /* i : CLDFB bands */ @@ -299,9 +299,10 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( Word32 bit_len, target_md_bits, available_bits, tmp_32; Word16 q1 = 31, q2 = 31, q_final, Q_cldfb, tmp, tmp_e; Word16 i, j; - error = IVAS_ERR_OK; Word16 Q_buff_re, Q_buff_im; + error = IVAS_ERR_OK; + move16(); push_wmops( "ISAR_PRE_REND_MultiBinToSplitBinaural" ); Q_buff_re = Q_buff; diff --git a/lib_isar/lib_isar_pre_rend.h b/lib_isar/lib_isar_pre_rend.h index 0e1ca56724bb72b0090cca75890fc39e93396eed..e085852d18327a1af45faa77faaf3fb9b698c9ff 100644 --- a/lib_isar/lib_isar_pre_rend.h +++ b/lib_isar/lib_isar_pre_rend.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -42,42 +42,42 @@ *----------------------------------------------------------------------------------*/ ivas_error ISAR_PRE_REND_open( - SPLIT_REND_WRAPPER *hSplitBinRend, /* i/o: Split renderer pre-renerer handle */ - ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, /* i/o: Split renderer pre-renerer config */ + SPLIT_REND_WRAPPER *hSplitBinRend, /* i/o: Split renderer pre-renderer handle */ + ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, /* i/o: Split renderer pre-renderer config */ const Word32 output_Fs, /* i : output sampling rate */ const Word16 cldfb_in_flag, /* i : Flag to indicate CLDFB or time doamin input */ const Word16 pcm_out_flag, /* i : Flag to indicate PCM output */ - const IVAS_RENDER_FRAMESIZE ivas_frame_size, /* i : IVAS frame size */ + const IVAS_RENDER_NUM_SUBFR render_num_subframes, /* i : rendering number of subframes */ const Word16 mixed_td_cldfb_flag /* i : Flag to indicate combined TD and CLDFB input */ ); void ISAR_PRE_REND_close( - SPLIT_REND_WRAPPER *hSplitBinRend, /* i/o: Split renderer pre-renerer handle */ + SPLIT_REND_WRAPPER *hSplitBinRend, /* i/o: Split renderer pre-renderer handle */ IVAS_REND_AudioBuffer *pSplitRendEncBuffer /* i/o: Split renderer data buffer */ ); void ISAR_PRE_REND_GetMultiBinPoseData( - const ISAR_SPLIT_REND_CONFIG_DATA *pSplit_rend_config, /* i : Split renderer pre-renerer config */ + const ISAR_SPLIT_REND_CONFIG_DATA *pSplit_rend_config, /* i : Split renderer pre-renderer config */ MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ const ISAR_SPLIT_REND_ROT_AXIS rot_axis /* i : Rotation axis */ ); ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( - SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renerer handle */ - const IVAS_QUATERNION headPosition, /* i : head rotation QUATERNION */ - const Word32 SplitRendBitRate, /* i : Split renderer bitrate */ - ISAR_SPLIT_REND_CODEC splitCodec, /* i/o: Split renderer codec */ - const Word16 isar_frame_size_ms, /* i : ISAR framesize */ - Word16 codec_frame_size_ms, /* i/o: Split renderer codec framesize */ - ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: Split renderer bitstream handle */ - Word32* Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i/o: CLDFB real buffer */ - Word32* Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], /* i/o: CLDFB imag buffer */ - const Word16 max_bands, /* i : CLDFB bands */ - Word32 *pOutput_fx[], /* i : low time resolution pre-renderer flag */ - const Word16 low_res_pre_rend_rot, /* i : low time resolution pre-renderer flag */ - const Word16 cldfb_in_flag, /* i : Flag to indicate CLDFB or time doamin input */ - const Word16 pcm_out_flag, /* i : Flag to indicate PCM output */ - const Word16 ro_md_flag, /* i : Flag to indicate real only metadata for yaw */ + SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renderer handle */ + const IVAS_QUATERNION headPosition, /* i : head rotation QUATERNION */ + const Word32 SplitRendBitRate, /* i : Split renderer bitrate */ + ISAR_SPLIT_REND_CODEC splitCodec, /* i/o: Split renderer codec */ + const Word16 isar_frame_size_ms, /* i : ISAR framesize */ + Word16 codec_frame_size_ms, /* i/o: Split renderer codec framesize */ + ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: ISAR bits handle */ + Word32* Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i/o: CLDFB real buffer */ + Word32* Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], /* i/o: CLDFB imag buffer */ + const Word16 max_bands, /* i : CLDFB bands */ + Word32 *pOutput_fx[], /* i : low time resolution pre-renderer flag */ + const Word16 low_res_pre_rend_rot, /* i : low time resolution pre-renderer flag */ + const Word16 cldfb_in_flag, /* i : Flag to indicate CLDFB or time doamin input */ + const Word16 pcm_out_flag, /* i : Flag to indicate PCM output */ + const Word16 ro_md_flag, /* i : Flag to indicate real only metadata for yaw */ Word16 Q_buff, Word16 *Q_out ); diff --git a/lib_rend/ivas_allrad_dec_fx.c b/lib_rend/ivas_allrad_dec_fx.c index 5023bee34db1aafdbf965096cbbc3722f62ec191..34563e8c39256ed5d7bf19a7e2bf126dbb8f8c93 100644 --- a/lib_rend/ivas_allrad_dec_fx.c +++ b/lib_rend/ivas_allrad_dec_fx.c @@ -1,7 +1,7 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include "options.h" -#include #include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" diff --git a/lib_dec/ivas_binRenderer_internal_fx.c b/lib_rend/ivas_binRenderer_internal_fx.c similarity index 99% rename from lib_dec/ivas_binRenderer_internal_fx.c rename to lib_rend/ivas_binRenderer_internal_fx.c index 3ed7f6d88b1fac9aec549423c74a0999115fcb0f..14818c7c399773573d38acb450f12b6f3c8a354b 100644 --- a/lib_dec/ivas_binRenderer_internal_fx.c +++ b/lib_rend/ivas_binRenderer_internal_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,10 +32,8 @@ #include #include "options.h" -#include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" -#include "cnst.h" #include "ivas_cnst.h" #include "ivas_rom_rend.h" #include "ivas_rom_dec.h" @@ -43,7 +41,9 @@ #include "ivas_rom_binauralRenderer.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#ifdef DEBUGGING #include "debug.h" +#endif /*----------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_cldfb_ring_buffer.c b/lib_rend/ivas_cldfb_ring_buffer.c index 10e4be26539c611deecf1fed1ae9ef45f93e7a96..e6de5e65d475a01194c75ac882a72b95ea413ff5 100644 --- a/lib_rend/ivas_cldfb_ring_buffer.c +++ b/lib_rend/ivas_cldfb_ring_buffer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,9 +32,9 @@ #include #include "options.h" -#include "cnst.h" +#include "ivas_cnst.h" #include "prot_fx.h" -#include "ivas_prot_fx.h" +#include "ivas_prot_rend_fx.h" #include #ifdef DEBUGGING #include "debug.h" diff --git a/lib_rend/ivas_crend_fx.c b/lib_rend/ivas_crend_fx.c index bb1c5519aaea764c817870d44136d01b92f756a9..b90b9deb8543083354c25a952de3a6fdb6d8db41 100644 --- a/lib_rend/ivas_crend_fx.c +++ b/lib_rend/ivas_crend_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" @@ -39,7 +38,6 @@ #include "ivas_rom_rend.h" #include "ivas_rom_binaural_crend_head.h" #include "ivas_stat_rend.h" -#include "lib_rend.h" #include "ivas_prot_fx.h" #include "wmc_auto.h" #ifdef DEBUGGING @@ -94,6 +92,9 @@ ivas_error ivas_Crend_hrtf_init_fx( hHrtf->pIndex_frequency_max[i][j] = NULL; hHrtf->pOut_to_bin_re_fx[i][j] = NULL; hHrtf->pOut_to_bin_im_fx[i][j] = NULL; + hHrtf->pOut_to_bin_re_dyn_fx[i][j] = NULL; + hHrtf->pOut_to_bin_im_dyn_fx[i][j] = NULL; + hHrtf->pIndex_frequency_max_dyn_fx[i][j] = NULL; } } @@ -102,9 +103,10 @@ ivas_error ivas_Crend_hrtf_init_fx( hHrtf->num_iterations_diffuse[j] = 0; move16(); hHrtf->pIndex_frequency_max_diffuse[j] = NULL; - hHrtf->pOut_to_bin_diffuse_re_fx[j] = NULL; hHrtf->pOut_to_bin_diffuse_im_fx[j] = NULL; + hHrtf->pOut_to_bin_diffuse_re_dyn_fx[j] = NULL; + hHrtf->pOut_to_bin_diffuse_im_dyn_fx[j] = NULL; } hHrtf->init_from_rom = 1; @@ -1810,8 +1812,8 @@ void ivas_rend_closeCldfbRend( pCldfbRend->hCldfbRend->hInputSetup = NULL; } + ivas_binRenderer_close_fx( &pCldfbRend->hCldfbRend ); - ivas_binaural_hrtf_close_fx( &pCldfbRend->hHrtfFastConv ); ivas_HRTF_fastconv_binary_close_fx( &pCldfbRend->hHrtfFastConv ); return; @@ -2044,7 +2046,7 @@ ivas_error ivas_rend_crendProcessSubframe_fx( const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ - DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ + DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: TC handle */ Word32 *input_f[], /* i : transport channels Qx */ Word32 *output[], /* i/o: input/output audio channels Qx */ const Word16 n_samples_to_render, /* i : output frame length per channel */ @@ -2267,15 +2269,15 @@ ivas_error ivas_rend_crendProcessSubframe_fx( *-----------------------------------------------------------------------------------------*/ ivas_error ivas_rend_crendProcessSubframesSplitBin( - const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */ - const AUDIO_CONFIG inConfig, /* i : input audio configuration */ - const AUDIO_CONFIG outConfig, /* i : output audio configuration */ - const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, + const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */ + const AUDIO_CONFIG inConfig, /* i : input audio configuration */ + const AUDIO_CONFIG outConfig, /* i : output audio configuration */ + const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : decoder config. structure */ const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ - DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ + DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: TC handle */ Word32 *input_f[], /* i : transport channels */ Word32 *output[], /* i/o: input/output audio channels */ const Word16 n_samples_to_render, /* i : output frame length per channel */ diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index 52bedea05801655c7a812900dfeb783bde16df88..9bdbc987ead1728915200fae0990c3b128ce3460 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index c3e301530bf39704633ab6ba092f5c50e05da20c..f20e58c42e1ed2395e7d333ced2cdb4805831736 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include "options.h" #include -#include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" @@ -42,15 +41,15 @@ #include "ivas_rom_rend.h" #include "ivas_rom_com.h" #include "ivas_prot_fx.h" - #include "wmc_auto.h" -Word16 slot_fx[4] = { 32767, 16384, 10922, 8192 }; /*------------------------------------------------------------------------- * Local constants *------------------------------------------------------------------------*/ +static Word16 slot_fx[4] = { 32767, 16384, 10922, 8192 }; + #define STEREO_PREPROCESS_IIR_FACTOR_Q15 ( 29491 ) // 0.9f in Q15 /* powf(0.95f, 4.0f) for sub-frame smoothing instead of CLDFB slot */ #define ADAPT_HTPROTO_ROT_LIM_0_FX 429496736 // 0.4f in Q30 @@ -118,9 +117,11 @@ static void ivas_masa_ext_rend_parambin_internal_fx( MASA_EXT_REND_HANDLE hMasaE static void formulate2x2MixingMatrix_fx( Word32 Ein1_fx /*q_Ein*/, Word32 Ein2_fx /*q_Ein*/, Word16 q_Ein, Word32 CinRe_fx /*q_Cin*/, Word32 CinIm_fx /*q_Cin*/, Word16 q_Cin, Word32 Eout1_fx /*q_Eout*/, Word32 Eout2_fx /*q_Eout*/, Word16 q_Eout, Word32 CoutRe_fx /*q_Cout*/, Word32 CoutIm_fx /*q_Cout*/, Word16 q_Cout, Word32 Q_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*Q31*/, Word32 Mre_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_M*/, Word32 Mim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_M*/, Word16 *q_M, const Word16 regularizationFactor_fx /*Q14*/ ); +static void matrixScale_fx( Word32 Are_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word32 Aim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word16 *q_A ); + static void matrixMul_fx( Word32 Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word32 Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word16 *q_A, Word32 Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_B*/, Word32 Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_B*/, Word16 *q_B, Word32 outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_out*/, Word32 outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_out*/, Word16 *q_out ); -static void matrixTransp2Mul_fx( Word32 Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word32 Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word16 *q_A, Word32 Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_B*/, Word32 Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_B*/, Word16 *q_B, Word32 Ascale, Word32 Bscale, Word32 outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_out*/, Word32 outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_out*/, Word16 *q_out ); +static void matrixTransp2Mul_fx( Word32 Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word32 Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_A*/, Word16 *q_A, Word32 Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_B*/, Word32 Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_B*/, Word16 *q_B, Word32 outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_out*/, Word32 outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] /*q_out*/, Word16 *q_out ); /*------------------------------------------------------------------------- @@ -387,9 +388,9 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( nchan_to_allocate = add( BINAURAL_CHANNELS, st_ivas->nchan_ism ); } - n_samples_granularity = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), output_Fs ); + n_samples_granularity = ivas_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), output_Fs ); - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_dec_get_num_tc_channels_fx( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -2228,11 +2229,13 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices_fx( } /* Make matrix multiplication M*Cx*M' to determine resulting covariance matrix of processing input with M */ + matrixScale_fx( Mre_fx, Mim_fx, &q_M ); + matrixScale_fx( CxRe_fx, CxIm_fx, &q_Cx ); matrixMul_fx( Mre_fx, Mim_fx, &q_M, CxRe_fx, CxIm_fx, &q_Cx, tmpMtxRe_fx, tmpMtxIm_fx, &q_tmp ); + matrixScale_fx( tmpMtxRe_fx, tmpMtxIm_fx, &q_tmp ); matrixTransp2Mul_fx( - tmpMtxRe_fx, tmpMtxIm_fx, &q_tmp, Mre_fx, Mim_fx, &q_M, - 1 /*int Ascale*/, - 0 /*int Bscale*/, + tmpMtxRe_fx, tmpMtxIm_fx, &q_tmp, + Mre_fx, Mim_fx, &q_M, resultMtxRe_fx, resultMtxIm_fx, &q_res ); /* When below the frequency limit where decorrelation is applied, we inject the decorrelated @@ -2912,14 +2915,13 @@ static void ivas_dirac_dec_binaural_process_output_fx( { Word16 gain; /* Mixing using the formulated processing matrix M */ - gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxRePrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxRe_fx[chA][chB][bin] ) ); // Q11 - - outSlotRe_fx[bin] = Madd_32_16( outSlotRe_fx[bin], inRe_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result - outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], inIm_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result + gain = mac_r( L_mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxRePrev_fx[chA][chB][bin] ), interpVal_fx, hDiracDecBin->processMtxRe_fx[chA][chB][bin] ); // Q11 + outSlotRe_fx[bin] = Madd_32_16( outSlotRe_fx[bin], inRe_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result + outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], inIm_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result move32(); move32(); - gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxImPrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxIm_fx[chA][chB][bin] ) ); // Q11 + gain = mac_r( L_mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxImPrev_fx[chA][chB][bin] ), interpVal_fx, hDiracDecBin->processMtxIm_fx[chA][chB][bin] ); // Q11 // interpVal * hDiracDecBin->processMtxIm[chA][chB][bin]; outSlotRe_fx[bin] = Msub_32_16( outSlotRe_fx[bin], inIm_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], inRe_fx[chB][slot][bin], gain ); // q_inp_mix-4//q_result @@ -2930,7 +2932,7 @@ static void ivas_dirac_dec_binaural_process_output_fx( test(); IF( LT_16( bin, max_band_decorr ) && LT_16( chB, 2 ) ) { - gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxDecRe_fx[chA][chB][bin] ) ); // Q11 + gain = mac_r( L_mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin] ), interpVal_fx, hDiracDecBin->processMtxDecRe_fx[chA][chB][bin] ); // Q11 // interpVal * hDiracDecBin->processMtxDecRe[chA][chB][bin]; outSlotRe_fx[bin] = Madd_32_16( outSlotRe_fx[bin], decSlotRePointer_fx[bin], gain ); // q_inp_mix-4//q_result @@ -2938,10 +2940,9 @@ static void ivas_dirac_dec_binaural_process_output_fx( move32(); move32(); - gain = add( mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin] ), mult( interpVal_fx, hDiracDecBin->processMtxDecIm_fx[chA][chB][bin] ) ); // Q11 - - outSlotRe_fx[bin] = Msub_32_16( outSlotRe_fx[bin], decSlotImPointer_fx[bin], gain ); // q_inp_mix-4//q_result - outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], decSlotRePointer_fx[bin], gain ); // q_inp_mix-4//q_result + gain = mac_r( L_mult( sub( 32767, interpVal_fx ), hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin] ), interpVal_fx, hDiracDecBin->processMtxDecIm_fx[chA][chB][bin] ); // Q11 + outSlotRe_fx[bin] = Msub_32_16( outSlotRe_fx[bin], decSlotImPointer_fx[bin], gain ); // q_inp_mix-4//q_result + outSlotIm_fx[bin] = Madd_32_16( outSlotIm_fx[bin], decSlotRePointer_fx[bin], gain ); // q_inp_mix-4//q_result move32(); move32(); } @@ -3462,6 +3463,16 @@ static void ivas_dirac_dec_binaural_check_and_switch_transports_headtracked_fx( return; } +static Word32 eig2x2_div_fx( Word32 num, Word32 den ); + +static Word32 eig2x2_div_fx( Word32 num, Word32 den ) +{ + IF( EQ_32( den, 0x40000000 ) ) + { + return num; + } + return div_w_newton( num, den ); +} static void eig2x2_fx( const Word32 E1_fx, /*q_E*/ @@ -3476,32 +3487,20 @@ static void eig2x2_fx( Word32 D_fx[BINAURAL_CHANNELS], /*q_D*/ Word16 *q_D ) { - Word16 chA, chB, ch; - Word32 s_fx, normVal_fx, crossSquare_fx, a_fx, pm_fx, add_fx; - Word32 tmp1, tmp2, tmp3, e1, e2, c_re, c_im; - Word16 q_crossSquare, q_tmp1, q_tmp2, exp_tmp3, exp, q_e, q_c, q_U_1, q_U_2; - Word32 epsilon_mant = 1180591621; - Word16 epsilon_exp = -39; + Word32 pm_fx, add_fx; + Word32 tmp1, tmp2, e1, e2, c_re, c_im, c0_im, c1_im; + Word32 s0_fx, s1_fx, nval0_fx, nval1_fx; + Word64 crossSquare_fx, tmp3, tmp4; + Word16 q_crossSquare, q_min, q_diff, q_tmp1, q_tmp2, exp, q_e, q_c; + Word16 nval0_q, nval1_q; + Word32 i01, i00, i11, i10; + Word64 eps_fx = ( (Word64) EPSILON_MANT ) << 32; + Word16 eps_q = 63 - EPSILON_EXP; move32(); move16(); - pm_fx = 0; - move32(); - add_fx = 0; - move32(); - q_tmp2 = 0; - move16(); - - FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) - { - FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) - { - Ure_fx[chA][chB] = 0; - move32(); - Uim_fx[chA][chB] = 0; - move32(); - } - } + set32_fx( (Word32 *) Ure_fx, 0, BINAURAL_CHANNELS * BINAURAL_CHANNELS ); + set32_fx( (Word32 *) Uim_fx, 0, BINAURAL_CHANNELS * BINAURAL_CHANNELS ); exp = sub( get_min_scalefactor( Cre_fx, Cim_fx ), 2 ); c_re = L_shl( Cre_fx, exp ); @@ -3513,336 +3512,292 @@ static void eig2x2_fx( e2 = L_shl( E2_fx, exp ); q_e = add( q_E, exp ); - /*crossSquare_fx = (c_re * c_re) + (c_im * c_im) - a_fx = (e1 + e2) * (e1 + e2) - 4.0f * ((e1 * e2) - crossSquare_fx) = (e1 - e2)^2 + 4 * crossSquare_fx - pm_fx = 0.5f * sqrtf(max(0.0f, a_fx)) - add_fx = 0.5f * (e1 + e2)*/ + // crossSquare_fx = (c_re * c_re) + (c_im * c_im) + // a_fx = (e1 + e2) * (e1 + e2) - 4.0f * ((e1 * e2) - crossSquare_fx) = (e1 - e2)^2 + 4 * crossSquare_fx + // pm_fx = 0.5f * sqrtf(max(0.0f, a_fx)) + // add_fx = 0.5f * (e1 + e2) - IF( L_and( c_re == 0, c_im == 0 ) ) + tmp1 = L_sub( e1, e2 ); + tmp3 = W_mult_32_32( tmp1, tmp1 ); + q_tmp1 = add( add( q_e, q_e ), 1 ); + if ( !tmp3 ) { - /* if c_re = 0 and c_im = 0, then crossSquare_fx = (c_re * c_re) + (c_im * c_im) = 0 - a_fx = (E1 - E2)^2 - pm_fx = 0.5 * sqrt(max(0, a_fx)) = 0.5 * max(0, (e1 - e2)) */ - crossSquare_fx = 0; - move32(); - q_crossSquare = Q31; - move16(); - pm_fx = L_shr( L_max( 0, L_abs( L_sub( e1, e2 ) ) ), 1 ); - q_tmp2 = q_e; + q_tmp1 = 63; move16(); } - ELSE + + crossSquare_fx = W_mac_32_32( W_mult_32_32( c_re, c_re ), c_im, c_im ); + q_crossSquare = add( add( q_c, q_c ), 1 ); + if ( !crossSquare_fx ) { - crossSquare_fx = Madd_32_32( Mpy_32_32( c_re, c_re ), c_im, c_im ); - q_crossSquare = sub( add( q_c, q_c ), 31 ); - IF( EQ_32( e1, e2 ) ) - { - /* if e1 - e2 = 0, then a_fx = 4 * crossSquare_fx - pm_fx = 0.5 * sqrt(max(0, 4 * crossSquare_fx)) = sqrt(0, crossSquare_fx)*/ - test(); - test(); - IF( EQ_32( c_re, 0 ) || LT_32( L_abs( c_re ), ONE_IN_Q15 ) ) - { - /* if c_re = 0, then crossSquare_fx = c_im^2 => pm_fx = max(0, c_im) */ - pm_fx = L_max( 0, L_abs( c_im ) ); - q_tmp2 = q_c; - move16(); - } - ELSE IF( c_im == 0 || LT_32( L_abs( c_im ), ONE_IN_Q15 ) ) - { - /* if c_im = 0, then crossSquare_fx = c_re^2 => pm_fx = max(0, c_re) */ - pm_fx = L_max( 0, L_abs( c_re ) ); - q_tmp2 = q_c; - move16(); - } - ELSE - { - exp = sub( 31, q_crossSquare ); - pm_fx = Sqrt32( L_max( 0, crossSquare_fx ), &exp ); - q_tmp2 = sub( 31, exp ); - } - } - ELSE - { - /* if e1, e2 >> c_re, c_im then (e1 - e2)^2 ~ (e1 - e2)^2 + 4 * crossSquare_fx - a_fx = (E1 - E2)^2 - pm_fx = 0.5 * sqrt(max(0, a_fx)) = 0.5 * max(0, (e1 - e2)) */ + q_crossSquare = 63; + move16(); + } - IF( GT_16( sub( q_c, q_e ), Q15 ) ) - { - pm_fx = L_shr( L_max( 0, L_abs( L_sub( e1, e2 ) ) ), 1 ); - q_tmp2 = q_e; - move16(); - } - ELSE - { - tmp2 = crossSquare_fx; - move32(); - q_tmp2 = sub( q_crossSquare, 2 ); // crossSquare_fx = 4 * crossSquare_fx; + tmp4 = crossSquare_fx; + move64(); + q_tmp2 = sub( q_crossSquare, 2 ); + if ( !tmp4 ) + { + q_tmp2 = 63; + move16(); + } - tmp1 = Mpy_32_32( L_sub( e1, e2 ), L_sub( e1, e2 ) ); - q_tmp1 = sub( add( q_e, q_e ), 31 ); + q_diff = sub( q_tmp1, q_tmp2 ); + q_tmp1 = s_min( q_tmp1, q_tmp2 ); + if ( q_diff > 0 ) + { + tmp3 = W_shr( tmp3, q_diff ); + } + if ( q_diff < 0 ) + { + tmp4 = W_shl( tmp4, q_diff ); + } + tmp3 = W_add( tmp3, tmp4 ); + q_diff = W_norm( tmp3 ); + tmp3 = W_shl( tmp3, q_diff ); + q_tmp1 = add( q_tmp1, q_diff ); - a_fx = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &q_tmp2 ); // (E1 - E2)^2 + 4 * crossSquare_fx - q_tmp2 = sub( 31, q_tmp2 ); + // pm_fx = 0.5f * sqrtf(max(0.0f, a_fx)) + exp = sub( 63, q_tmp1 ); + pm_fx = Sqrt32( L_max( 0, W_extract_h( tmp3 ) ), &exp ); + pm_fx = L_shr( pm_fx, 1 ); + q_tmp2 = sub( 31, exp ); - exp = sub( 31, q_tmp2 ); - pm_fx = Sqrt32( L_max( 0, L_sub( a_fx, 1 ) ), &exp ); - pm_fx = L_shr( pm_fx, 1 ); - q_tmp2 = sub( 31, exp ); - } - } - } // add_fx = 0.5 * (e1 + e2) add_fx = L_shr( L_add( e1, e2 ), 1 ); q_tmp1 = q_e; move16(); - IF( LT_16( q_tmp1, q_tmp2 ) ) + // D[0] = add + pm; + // D[1] = max( 0.0f, add - pm ); + + q_diff = sub( q_tmp1, q_tmp2 ); + + tmp1 = add_fx; + move32(); + if ( q_diff > 0 ) { - D_fx[0] = L_add( L_shr( add_fx, 1 ), L_shr( pm_fx, add( sub( q_tmp2, q_tmp1 ), 1 ) ) ); - move32(); - D_fx[1] = L_max( 0, L_sub( L_shr( add_fx, 1 ), L_shr( pm_fx, add( sub( q_tmp2, q_tmp1 ), 1 ) ) ) ); - move32(); - *q_D = sub( q_tmp1, 1 ); - move16(); + tmp1 = L_shr( tmp1, q_diff ); } - ELSE + + tmp2 = pm_fx; + move32(); + if ( q_diff < 0 ) + { + tmp2 = L_shl( tmp2, q_diff ); + } + + D_fx[0] = L_add( tmp1, tmp2 ); + move32(); + D_fx[1] = L_max( L_sub( tmp1, tmp2 ), 0 ); + move32(); + *q_D = s_min( q_tmp1, q_tmp2 ); + move32(); + + // Numeric case, when input is practically zeros + // if ( D_fx[0] < EPSILON_FX ) + + IF( LT_32( L_shl_sat( D_fx[0], sub( 31 - EPSILON_EXP, *q_D ) ), EPSILON_MANT ) ) { - D_fx[0] = L_add( L_shr( add_fx, add( sub( q_tmp1, q_tmp2 ), 1 ) ), L_shr( pm_fx, 1 ) ); + Ure_fx[0][0] = ONE_IN_Q30; move32(); - D_fx[1] = L_max( 0, L_sub( L_shr( add_fx, add( sub( q_tmp1, q_tmp2 ), 1 ) ), L_shr( pm_fx, 1 ) ) ); + Ure_fx[1][1] = ONE_IN_Q30; move32(); - *q_D = sub( q_tmp2, 1 ); + *q_U = Q30; move16(); + return; } - /* Numeric case, when input is practically zeros */ - // IF( D_fx[0] < EPSILON_FX ) + // Numeric case, when input is near an identity matrix with a gain + tmp1 = Mpy_32_32( INV_1000_Q31, add_fx ); + if ( q_diff > 0 ) + { + tmp1 = L_shr( tmp1, q_diff ); + } - IF( LT_32( L_shl_sat( D_fx[0], sub( sub( 31, *q_D ), EPSILON_EXP ) ), EPSILON_MANT ) ) + IF( LT_32( tmp2, tmp1 ) ) { - Ure_fx[0][0] = ONE_IN_Q31; + Ure_fx[0][0] = ONE_IN_Q30; move32(); - Ure_fx[1][1] = ONE_IN_Q31; + Ure_fx[1][1] = ONE_IN_Q30; move32(); - *q_U = Q31; + *q_U = Q30; move16(); - return; } - /* Numeric case, when input is near an identity matrix with a gain */ - tmp1 = Mpy_32_32( INV_1000_Q31, add_fx ); + // Eigenvectors - IF( LT_16( q_tmp1, q_tmp2 ) ) + q_diff = sub( *q_D, q_e ); + q_tmp1 = s_min( *q_D, q_e ); + + tmp1 = D_fx[0]; + move32(); + if ( q_diff > 0 ) { - IF( LT_32( L_shr( pm_fx, sub( q_tmp2, q_tmp1 ) ), tmp1 ) ) - { - Ure_fx[0][0] = ONE_IN_Q30; - move32(); - Ure_fx[1][1] = ONE_IN_Q30; - move32(); - *q_U = Q30; - move16(); + tmp1 = L_shr( tmp1, q_diff ); + } - return; - } + tmp2 = D_fx[1]; + move32(); + if ( q_diff > 0 ) + { + tmp2 = L_shr( tmp2, q_diff ); } - ELSE + + if ( q_diff < 0 ) { - IF( LT_32( pm_fx, L_shr( tmp1, sub( q_tmp1, q_tmp2 ) ) ) ) - { - Ure_fx[0][0] = ONE_IN_Q30; - move32(); - Ure_fx[1][1] = ONE_IN_Q30; - move32(); - *q_U = Q30; - move16(); + e1 = L_shl( e1, q_diff ); + } - return; - } + if ( q_diff < 0 ) + { + e2 = L_shl( e2, q_diff ); } - q_U_1 = 0; - q_U_2 = 0; - move16(); - move16(); + s0_fx = L_sub( tmp1, e1 ); // D_fx[0] - e1 + tmp1 = L_sub( tmp1, e2 ); // D_fx[0] - e2 + s1_fx = L_sub( tmp2, e1 ); // D_fx[1] - e1 + tmp2 = L_sub( tmp2, e2 ); // D_fx[1] - e2 - /* Eigenvectors */ - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + i01 = GT_32( L_abs( tmp1 ), L_abs( s0_fx ) ); // fabsf( D_fx[0] - e2 ) > fabsf( D_fx[0] - e1 ) + i11 = GT_32( L_abs( tmp2 ), L_abs( s1_fx ) ); // fabsf( D_fx[1] - e2 ) > fabsf( D_fx[1] - e1 ) + + if ( i01 ) { - Word16 q_diff = sub( q_e, *q_D ); - IF( q_diff > 0 ) - { - tmp1 = L_sub( D_fx[ch], L_shr( e1, q_diff ) ); - tmp2 = L_sub( D_fx[ch], L_shr( e2, q_diff ) ); - q_tmp1 = *q_D; - move16(); - } - ELSE - { - tmp1 = L_sub( L_shl( D_fx[ch], q_diff ), e1 ); - tmp2 = L_sub( L_shl( D_fx[ch], q_diff ), e2 ); - q_tmp1 = q_e; - move16(); - } + s0_fx = tmp1; + move32(); + } - IF( GT_32( L_abs( tmp2 ), L_abs( tmp1 ) ) ) - { - s_fx = tmp2; - move32(); - exp = sub( norm_l( s_fx ), 1 ); - tmp2 = Mpy_32_32( s_fx, s_fx ); - q_tmp2 = sub( add( q_tmp1, q_tmp1 ), 31 ); + if ( i11 ) + { + s1_fx = tmp2; + move32(); + } - tmp2 = BASOP_Util_Add_Mant32Exp( crossSquare_fx, sub( 31, q_crossSquare ), tmp2, sub( 31, q_tmp2 ), &q_tmp2 ); - q_tmp2 = sub( 31, q_tmp2 ); + // normVal = sqrtf( 1.0f / ( 1e-12f + crossSquare + s * s ) ); - tmp3 = BASOP_Util_Add_Mant32Exp( tmp2, sub( 31, q_tmp2 ), epsilon_mant, epsilon_exp, &exp_tmp3 ); + q_tmp2 = shl( q_tmp1, 1 ); + q_min = s_min( q_tmp2, q_crossSquare ); + q_min = s_min( q_min, eps_q ); - tmp2 = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q30, tmp3, &exp ); - exp = sub( exp, sub( Q30, sub( 31, exp_tmp3 ) ) ); - normVal_fx = Sqrt32( tmp2, &exp ); // q_tmp2 - q_tmp2 = sub( 31, exp ); + q_diff = sub( q_tmp2, q_min ); + tmp3 = W_shr( W_mult0_32_32( s0_fx, s0_fx ), q_diff ); + tmp4 = W_shr( W_mult0_32_32( s1_fx, s1_fx ), q_diff ); - q_diff = sub( q_c, q_tmp1 ); - IF( q_diff > 0 ) - { - c_re = L_shr( c_re, q_diff ); - c_im = L_shr( c_im, q_diff ); - q_c = q_tmp1; - move16(); - } - ELSE - { - s_fx = L_shl( s_fx, q_diff ); - q_tmp1 = q_c; - move16(); - } + q_diff = sub( q_crossSquare, q_min ); + crossSquare_fx = W_shr( crossSquare_fx, q_diff ); + tmp3 = W_add( tmp3, crossSquare_fx ); + tmp4 = W_add( tmp4, crossSquare_fx ); - Ure_fx[0][ch] = Mpy_32_32( s_fx, normVal_fx ); - move32(); - Ure_fx[1][ch] = Mpy_32_32( c_re, normVal_fx ); - move32(); - Uim_fx[1][ch] = Mpy_32_32( c_im, normVal_fx ); - move32(); - q_U_1 = sub( add( q_tmp1, q_tmp2 ), 31 ); + q_diff = sub( eps_q, q_min ); + eps_fx = W_shr( eps_fx, q_diff ); + tmp3 = W_add( tmp3, eps_fx ); + tmp4 = W_add( tmp4, eps_fx ); - IF( q_U_2 != 0 ) - { - q_diff = sub( q_U_2, q_U_1 ); - IF( q_diff > 0 ) - { - Ure_fx[1][ch - 1] = L_shr( Ure_fx[1][ch - 1], q_diff ); - Ure_fx[0][ch - 1] = L_shr( Ure_fx[0][ch - 1], q_diff ); - Uim_fx[0][ch - 1] = L_shr( Uim_fx[0][ch - 1], q_diff ); - q_U_2 = q_U_1; - move32(); - move32(); - move32(); - move16(); - } - ELSE IF( GT_16( q_U_1, q_U_2 ) ) - { - Ure_fx[1][ch] = L_shl( Ure_fx[1][ch], q_diff ); - Ure_fx[0][ch] = L_shl( Ure_fx[0][ch], q_diff ); - Uim_fx[1][ch] = L_shl( Uim_fx[1][ch], q_diff ); - q_U_1 = q_U_2; - move32(); - move32(); - move32(); - move16(); - } - } - q_U_2 = q_U_1; - move16(); - } - ELSE - { - s_fx = tmp1; - move32(); + q_diff = W_norm( tmp3 ); + tmp3 = W_shl( tmp3, q_diff ); + nval0_q = add( q_min, q_diff ); - exp = sub( norm_l( s_fx ), 1 ); - tmp2 = Mpy_32_32( s_fx, s_fx ); - q_tmp2 = sub( add( q_tmp1, q_tmp1 ), 31 ); + q_diff = W_norm( tmp4 ); + tmp4 = W_shl( tmp4, q_diff ); + nval1_q = add( q_min, q_diff ); - tmp2 = BASOP_Util_Add_Mant32Exp( crossSquare_fx, sub( 31, q_crossSquare ), tmp2, sub( 31, q_tmp2 ), &q_tmp2 ); - q_tmp2 = sub( 31, q_tmp2 ); + // nval0_fx = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q30, W_extract_h( tmp3 ), &exp ); + // exp = sub( exp, sub( 62, nval0_q ) ); + // + // is equivalent to: + // + // nval0_fx = div_w_newton( ONE_IN_Q30, W_extract_h( tmp3 ) ); + // exp = sub( nval0_q, 61 ); - tmp3 = BASOP_Util_Add_Mant32Exp( tmp2, sub( 31, q_tmp2 ), epsilon_mant, epsilon_exp, &exp_tmp3 ); + nval0_fx = eig2x2_div_fx( ONE_IN_Q30, W_extract_h( tmp3 ) ); + exp = sub( nval0_q, 61 ); + nval0_fx = Sqrt32( nval0_fx, &exp ); + nval0_q = sub( 31, exp ); - tmp2 = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q30, tmp3, &exp ); - exp = sub( exp, sub( Q30, sub( 31, exp_tmp3 ) ) ); - normVal_fx = Sqrt32( tmp2, &exp ); // q_tmp2 - q_tmp2 = sub( 31, exp ); + // nval1_fx = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q30, W_extract_h( tmp4 ), &exp ); + // exp = sub( exp, sub( 62, nval1_q ) ); + // + // is equivalent to: + // + // nval1_fx = div_w_newton( ONE_IN_Q30, W_extract_h( tmp4 ) ); + // exp = sub( nval1_q, 61 ); - q_diff = sub( q_c, q_tmp1 ); - IF( q_diff > 0 ) - { - c_re = L_shr( c_re, q_diff ); - c_im = L_shr( c_im, q_diff ); - q_c = q_tmp1; - move16(); - } - ELSE - { - s_fx = L_shl( s_fx, q_diff ); - q_tmp1 = q_c; - move16(); - } + nval1_fx = eig2x2_div_fx( ONE_IN_Q30, W_extract_h( tmp4 ) ); + exp = sub( nval1_q, 61 ); + nval1_fx = Sqrt32( nval1_fx, &exp ); + nval1_q = sub( 31, exp ); - Ure_fx[1][ch] = Mpy_32_32( s_fx, normVal_fx ); - move32(); - Ure_fx[0][ch] = Mpy_32_32( c_re, normVal_fx ); - move32(); - Uim_fx[0][ch] = Mpy_32_32( L_negate( c_im ), normVal_fx ); - move32(); - q_U_2 = sub( add( q_tmp1, q_tmp2 ), 31 ); + q_diff = sub( q_c, q_tmp1 ); + q_tmp1 = s_min( q_tmp1, q_c ); - IF( q_U_1 != 0 ) - { - q_diff = sub( q_U_2, q_U_1 ); - IF( q_diff > 0 ) - { - Ure_fx[1][ch] = L_shr( Ure_fx[1][ch], q_diff ); - Ure_fx[0][ch] = L_shr( Ure_fx[0][ch], q_diff ); - Uim_fx[0][ch] = L_shr( Uim_fx[0][ch], q_diff ); - q_U_2 = q_U_1; - move32(); - move32(); - move32(); - move16(); - } - ELSE IF( GT_16( q_U_1, q_U_2 ) ) - { - Ure_fx[1][ch - 1] = L_shl( Ure_fx[1][ch - 1], q_diff ); - Ure_fx[0][ch - 1] = L_shl( Ure_fx[0][ch - 1], q_diff ); - Uim_fx[1][ch - 1] = L_shl( Uim_fx[1][ch - 1], q_diff ); - q_U_1 = q_U_2; - move32(); - move32(); - move32(); - move16(); - } - } - q_U_1 = q_U_2; - move16(); - } + if ( q_diff > 0 ) + { + c_re = L_shr( c_re, q_diff ); } - if ( q_U_1 != 0 ) + if ( q_diff > 0 ) { - *q_U = q_U_1; - move16(); + c_im = L_shr( c_im, q_diff ); } - if ( q_U_1 == 0 ) + if ( q_diff < 0 ) { - *q_U = q_U_2; - move16(); + s0_fx = L_shl( s0_fx, q_diff ); } + if ( q_diff < 0 ) + { + s1_fx = L_shl( s1_fx, q_diff ); + } + + q_diff = sub( nval0_q, nval1_q ); + q_tmp2 = s_min( nval0_q, nval1_q ); + + if ( q_diff > 0 ) + { + nval0_fx = L_shr( nval0_fx, q_diff ); + } + + if ( q_diff < 0 ) + { + nval1_fx = L_shl( nval1_fx, q_diff ); + } + + *q_U = sub( add( q_tmp1, q_tmp2 ), 31 ); + + i00 = L_sub( 1, i01 ); + i10 = L_sub( 1, i11 ); + + c0_im = c_im; + move32(); + if ( i00 > 0 ) + { + c0_im = L_negate( c0_im ); + } + + c1_im = c_im; + move32(); + if ( i10 > 0 ) + { + c1_im = L_negate( c1_im ); + } + + Ure_fx[i00][0] = Mpy_32_32( s0_fx, nval0_fx ); + move32(); + Ure_fx[i01][0] = Mpy_32_32( c_re, nval0_fx ); + move32(); + Uim_fx[i01][0] = Mpy_32_32( c0_im, nval0_fx ); + move32(); + + Ure_fx[i10][1] = Mpy_32_32( s1_fx, nval1_fx ); + move32(); + Ure_fx[i11][1] = Mpy_32_32( c_re, nval1_fx ); + move32(); + Uim_fx[i11][1] = Mpy_32_32( c1_im, nval1_fx ); + move32(); return; } @@ -3857,7 +3812,8 @@ static void matrixDiagMul_fx( Word16 *q_Out ) { Word16 chA, chB; - Word16 size = i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ); + + Word32 not_zero = 0; FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { @@ -3867,21 +3823,37 @@ static void matrixDiagMul_fx( imOut_fx[chA][chB] = Mpy_32_32( imIn_fx[chA][chB], D_fx[chB] ); move32(); move32(); + not_zero = L_or( not_zero, reOut_fx[chA][chB] ); + not_zero = L_or( not_zero, imOut_fx[chA][chB] ); } } *q_Out = sub( add( q_In, q_D ), 31 ); move16(); - - if ( L_and( is_zero_arr( reOut_fx[0], size ), is_zero_arr( imOut_fx[0], size ) ) ) + if ( !not_zero ) { *q_Out = Q31; move16(); } + return; } +static void matrixScale_fx( + Word32 Are_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_A*/ + Word32 Aim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_A*/ + Word16 *q_A ) +{ + Word16 shift; + Word16 size = BINAURAL_CHANNELS * BINAURAL_CHANNELS; + shift = sub( s_min( L_norm_arr( Are_fx[0], size ), L_norm_arr( Aim_fx[0], size ) ), 1 ); + scale_sig32( Are_fx[0], size, shift ); + scale_sig32( Aim_fx[0], size, shift ); + *q_A = add( *q_A, shift ); + move16(); +} + static void matrixMul_fx( Word32 Are_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_A*/ Word32 Aim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_A*/ @@ -3894,21 +3866,7 @@ static void matrixMul_fx( Word16 *q_out ) { Word16 chA, chB; - Word16 min_q_shift1, min_q_shift2; - Word16 size = i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ); - - min_q_shift1 = sub( s_min( L_norm_arr( Are_fx[0], size ), L_norm_arr( Aim_fx[0], size ) ), 1 ); - min_q_shift2 = sub( s_min( L_norm_arr( Bre_fx[0], size ), L_norm_arr( Bim_fx[0], size ) ), 1 ); - - scale_sig32( Are_fx[0], size, min_q_shift1 ); - scale_sig32( Aim_fx[0], size, min_q_shift1 ); - scale_sig32( Bre_fx[0], size, min_q_shift2 ); - scale_sig32( Bim_fx[0], size, min_q_shift2 ); - - *q_A = add( *q_A, min_q_shift1 ); - *q_B = add( *q_B, min_q_shift2 ); - move16(); - move16(); + Word32 not_zero = 0; FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { @@ -3935,12 +3893,14 @@ static void matrixMul_fx( Are_fx[chA][1], Bim_fx[1][chB] ); move32(); #endif /* #ifdef IVAS_ENH64_CADENCE_CHANGES */ + not_zero = L_or( not_zero, outRe_fx[chA][chB] ); + not_zero = L_or( not_zero, outIm_fx[chA][chB] ); } } - *q_out = sub( add( *q_A, *q_B ), 31 ); + *q_out = sub( add( *q_A, *q_B ), 31 ); move16(); - if ( L_and( is_zero_arr( outRe_fx[0], size ), is_zero_arr( outIm_fx[0], size ) ) ) + if ( !not_zero ) { *q_out = Q31; move16(); @@ -3961,57 +3921,50 @@ static void matrixTransp1Mul_fx( Word16 *q_out ) { Word16 chA, chB; - Word16 size = i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ); Word64 tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; Word64 tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; - Word16 q_tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; - Word16 q_tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; - Word64 tmp64_1, tmp64_2; - Word16 tmp16, q_common = 63; + Word64 tmp64; + Word16 common_lsh, q; + q = add( add( q_A, q_B ), 1 ); + common_lsh = sub( 63, q ); move16(); FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) { - tmp64_1 = W_mac_32_32( W_mult_32_32( Are_fx[0][chA], Bre_fx[0][chB] ), Are_fx[1][chA], Bre_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) - tmp64_2 = W_mac_32_32( W_mult_32_32( Aim_fx[0][chA], Bim_fx[0][chB] ), Aim_fx[1][chA], Bim_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) - tmp_outRe_fx[chA][chB] = W_add( tmp64_1, tmp64_2 ); // Q: add( add( q_A, q_B ), 1 ) + tmp64 = W_mult_32_32( Are_fx[0][chA], Bre_fx[0][chB] ); + tmp64 = W_mac_32_32( tmp64, Are_fx[1][chA], Bre_fx[1][chB] ); + tmp64 = W_mac_32_32( tmp64, Aim_fx[0][chA], Bim_fx[0][chB] ); + tmp_outRe_fx[chA][chB] = W_mac_32_32( tmp64, Aim_fx[1][chA], Bim_fx[1][chB] ); move64(); - tmp16 = W_norm( tmp_outRe_fx[chA][chB] ); - tmp_outRe_fx[chA][chB] = W_shl( tmp_outRe_fx[chA][chB], tmp16 ); // Q:add( tmp16, add( add( q_A, q_B ), 1 ) ) - move64(); - q_tmp_outRe_fx[chA][chB] = add( tmp16, add( add( q_A, q_B ), 1 ) ); - move16(); - q_common = s_min( q_tmp_outRe_fx[chA][chB], q_common ); - + common_lsh = s_min( common_lsh, W_norm( tmp_outRe_fx[chA][chB] ) ); - tmp64_1 = W_mac_32_32( W_mult_32_32( Are_fx[0][chA], Bim_fx[0][chB] ), Are_fx[1][chA], Bim_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) - tmp64_2 = W_mac_32_32( W_mult_32_32( Aim_fx[0][chA], Bre_fx[0][chB] ), Aim_fx[1][chA], Bre_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) - tmp_outIm_fx[chA][chB] = W_sub( tmp64_1, tmp64_2 ); // Q: add( add( q_A, q_B ), 1 ) + tmp64 = W_mult_32_32( Aim_fx[0][chA], Bre_fx[0][chB] ); + tmp64 = W_mac_32_32( tmp64, Aim_fx[1][chA], Bre_fx[1][chB] ); + tmp64 = W_mac_32_32( W_neg( tmp64 ), Are_fx[0][chA], Bim_fx[0][chB] ); + tmp_outIm_fx[chA][chB] = W_mac_32_32( tmp64, Are_fx[1][chA], Bim_fx[1][chB] ); move64(); - tmp16 = W_norm( tmp_outIm_fx[chA][chB] ); - tmp_outIm_fx[chA][chB] = W_shl( tmp_outIm_fx[chA][chB], tmp16 ); // Q:add( tmp16, add( add( q_A, q_B ), 1 ) ) - move64(); - q_tmp_outIm_fx[chA][chB] = add( tmp16, add( add( q_A, q_B ), 1 ) ); - move16(); - q_common = s_min( q_tmp_outIm_fx[chA][chB], q_common ); + common_lsh = s_min( common_lsh, W_norm( tmp_outIm_fx[chA][chB] ) ); } } + Word32 not_zero = 0; FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) { - outRe_fx[chA][chB] = W_extract_h( W_shl( tmp_outRe_fx[chA][chB], s_max( -63, sub( q_common, q_tmp_outRe_fx[chA][chB] ) ) ) ); + outRe_fx[chA][chB] = W_extract_h( W_shl( tmp_outRe_fx[chA][chB], common_lsh ) ); move32(); - outIm_fx[chA][chB] = W_extract_h( W_shl( tmp_outIm_fx[chA][chB], s_max( -63, sub( q_common, q_tmp_outIm_fx[chA][chB] ) ) ) ); + outIm_fx[chA][chB] = W_extract_h( W_shl( tmp_outIm_fx[chA][chB], common_lsh ) ); move32(); + not_zero = L_or( not_zero, outRe_fx[chA][chB] ); + not_zero = L_or( not_zero, outIm_fx[chA][chB] ); } } - *q_out = sub( q_common, 32 ); + *q_out = sub( add( q, common_lsh ), 32 ); move16(); - if ( L_and( is_zero_arr( outRe_fx[0], size ), is_zero_arr( outIm_fx[0], size ) ) ) + if ( !not_zero ) { *q_out = Q31; move16(); @@ -4027,34 +3980,13 @@ static void matrixTransp2Mul_fx( Word32 Bre_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_B*/ Word32 Bim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_B*/ Word16 *q_B, - Word32 Ascale, - Word32 Bscale, Word32 outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_out*/ Word32 outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], /*q_out*/ Word16 *q_out ) { Word16 chA, chB; - Word16 min_q_shift; - Word16 size = BINAURAL_CHANNELS * BINAURAL_CHANNELS; - - IF( Ascale == 1 ) - { - min_q_shift = sub( s_min( L_norm_arr( Are_fx[0], size ), L_norm_arr( Aim_fx[0], size ) ), 1 ); - scale_sig32( Are_fx[0], size, min_q_shift ); - scale_sig32( Aim_fx[0], size, min_q_shift ); - *q_A = add( *q_A, min_q_shift ); - move16(); - } - - IF( Bscale == 1 ) - { - min_q_shift = sub( s_min( L_norm_arr( Bre_fx[0], size ), L_norm_arr( Bim_fx[0], size ) ), 1 ); - scale_sig32( Bre_fx[0], size, min_q_shift ); - scale_sig32( Bim_fx[0], size, min_q_shift ); - *q_B = add( *q_B, min_q_shift ); - move16(); - } - + // Word16 size = BINAURAL_CHANNELS * BINAURAL_CHANNELS; + Word32 not_zero = 0; FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) @@ -4080,16 +4012,19 @@ static void matrixTransp2Mul_fx( Are_fx[chA][1], Bim_fx[chB][1] ); move32(); #endif /* #ifdef IVAS_ENH64_CADENCE_CHANGES */ + not_zero = L_or( not_zero, outRe_fx[chA][chB] ); + not_zero = L_or( not_zero, outIm_fx[chA][chB] ); } } + *q_out = sub( add( *q_A, *q_B ), 31 ); move16(); - - if ( L_and( is_zero_arr( outRe_fx[0], size ), is_zero_arr( outIm_fx[0], size ) ) ) + if ( !not_zero ) { *q_out = Q31; move16(); } + return; } @@ -4591,6 +4526,8 @@ static void formulate2x2MixingMatrix_fx( q_temp = sub( add( q_ky, q_GhatQ ), 31 ); /* A = Ky' * G_hat * Q * Kx (see publication) */ + matrixScale_fx( tmpRe_fx, tmpIm_fx, &q_temp ); + matrixScale_fx( Kxre_fx, Kxim_fx, &q_Kx ); matrixMul_fx( tmpRe_fx, tmpIm_fx, &q_temp, Kxre_fx, Kxim_fx, &q_Kx, Are_fx, Aim_fx, &q_A ); /* Find nearest orthonormal matrix P to A = Ky' * G_hat * Q * Kx @@ -4648,6 +4585,8 @@ static void formulate2x2MixingMatrix_fx( div_fx[0] = L_min( div_fx[0], thresh ); // q_div div_fx[1] = L_min( div_fx[1], thresh ); // q_div + matrixScale_fx( Are_fx, Aim_fx, &q_A ); + matrixScale_fx( Ure_fx, Uim_fx, &q_U ); matrixMul_fx( Are_fx, Aim_fx, &q_A, Ure_fx, Uim_fx, &q_U, tmpRe_fx, tmpIm_fx, &q_temp ); exp = L_norm_arr( div_fx, BINAURAL_CHANNELS ); @@ -4711,10 +4650,10 @@ static void formulate2x2MixingMatrix_fx( } } - matrixTransp2Mul_fx( tmpRe_fx, tmpIm_fx, &q_temp, Ure_fx, Uim_fx, &q_U, - 0 /*int Ascale*/, - 0 /*int Bscale*/, - Pre_fx, Pim_fx, &q_P ); /* Nearest orthonormal matrix P to matrix A formulated */ + matrixTransp2Mul_fx( + tmpRe_fx, tmpIm_fx, &q_temp, + Ure_fx, Uim_fx, &q_U, + Pre_fx, Pim_fx, &q_P ); /* Nearest orthonormal matrix P to matrix A formulated */ /* These are the final formulas of the JAES publication M = Ky P Kx^(-1) */ #if ( BINAURAL_CHANNELS != 2 ) @@ -4845,12 +4784,15 @@ static void formulate2x2MixingMatrix_fx( } } + matrixScale_fx( KyRe_fx, KyIm_fx, &q_ky ); + matrixScale_fx( Pre_fx, Pim_fx, &q_P ); matrixMul_fx( KyRe_fx, KyIm_fx, &q_ky, Pre_fx, Pim_fx, &q_P, tmpRe_fx, tmpIm_fx, &q_temp ); + matrixScale_fx( tmpRe_fx, tmpIm_fx, &q_temp ); + matrixTransp2Mul_fx( + tmpRe_fx, tmpIm_fx, &q_temp, + Uxre_fx, Uxim_fx, &q_Ux, + Mre_fx, Mim_fx, q_M ); - matrixTransp2Mul_fx( tmpRe_fx, tmpIm_fx, &q_temp, Uxre_fx, Uxim_fx, &q_Ux, - 1 /*int Ascale*/, - 0 /*int Bscale*/, - Mre_fx, Mim_fx, q_M ); return; } @@ -6048,7 +5990,7 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( IF( GT_32( totalTargetEne, 0 ) ) { - tempDivisor = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q28, max( EPSILON_FX, totalTargetEne ), &temp_q ); + tempDivisor = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q28, L_max( EPSILON_FX, totalTargetEne ), &temp_q ); temp_q = sub( sub( Q31, temp_q ), sub( sub( Q31, Q28 ), sub( Q31, subQ ) ) ); @@ -6081,7 +6023,7 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( IF( enableCentering ) { temp1 = abs_s( sub( panEnesIn[ismDirIndex][0], panEnesOut[ismDirIndex][0] ) ); // 2*sub(enes) -> Q14 - centeringFactor = max( 0, sub( temp1, ONE_IN_Q14 ) ); // Q14 + centeringFactor = s_max( 0, sub( temp1, ONE_IN_Q14 ) ); // Q14 FOR( ch = 0; ch < 2; ch++ ) { diff --git a/lib_rend/ivas_dirac_decorr_dec_fx.c b/lib_rend/ivas_dirac_decorr_dec_fx.c index acbfb3bd2a5ca36e8b63b3ea9959d4c26272d66d..bd5585c088f1dc1c86f7f13130bf54bc688080c2 100644 --- a/lib_rend/ivas_dirac_decorr_dec_fx.c +++ b/lib_rend/ivas_dirac_decorr_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" @@ -42,6 +40,7 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*------------------------------------------------------------------------- * Local constants *------------------------------------------------------------------------*/ @@ -49,10 +48,8 @@ #define DIRAC_MAX_DECORR_CLDFB_BANDS_AMBI 22 #define DIRAC_MAX_DECORR_CLDFB_BANDS 15 -#define DIRAC_DUCK_ALPHA 0.8f -#define DIRAC_DUCK_GAMMA 1.5f -#define DIRAC_DUCK_GAMMA_FX 1610612736 /* Q30 */ -#define DIRAC_DUCK_ALPHA_FX 1717986944 /* Q31 */ +#define DIRAC_DUCK_GAMMA_FX 1610612736 /* 1.5f in Q30 */ +#define DIRAC_DUCK_ALPHA_FX 1717986944 /* 0.8f in Q31 */ #define ONE_M_DIRAC_DUCK_ALPHA 429496736 /* Q31 */ /* Maximal useful q-format, represents range of 2^-126 (float min) */ diff --git a/lib_rend/ivas_dirac_onsets_dec_fx.c b/lib_rend/ivas_dirac_onsets_dec_fx.c index 80adebfdd18661e0160e31f6c753bfd60cd6930a..5abc1f73e96b45ad8840b9b04505e5776aff5597 100644 --- a/lib_rend/ivas_dirac_onsets_dec_fx.c +++ b/lib_rend/ivas_dirac_onsets_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,7 +33,6 @@ #include #include #include "options.h" -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" diff --git a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c index 29184695ce35ebc52a47cfc9f626e504e1ca7f34..f2a225de365080d75c07b2260cb0691022d492ae 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_stat_dec.h" @@ -213,7 +211,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = imult1616( dirac_output_synthesis_params->max_band_decorr, hDirACRend->num_outputs_diff ); + dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = imult1616( dirac_output_synthesis_params->max_band_decorr, hDirACRend->num_outputs_diff ); move16(); } ELSE diff --git a/lib_rend/ivas_dirac_rend_fx.c b/lib_rend/ivas_dirac_rend_fx.c index bde35181ee7c12d7d3da54a92c1be9e4cb051725..4ca7b0c14aa7faae911657acd9c8b0fc6e4cdf20 100644 --- a/lib_rend/ivas_dirac_rend_fx.c +++ b/lib_rend/ivas_dirac_rend_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,8 +33,6 @@ #include #include #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" @@ -255,6 +253,8 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( move16(); hSpatParamRendCom->numIsmDirections = 0; move16(); + hSpatParamRendCom->q_diffuseness_vector = Q30; + move16(); } /*-----------------------------------------------------------------* @@ -858,6 +858,9 @@ ivas_error ivas_dirac_alloc_mem_fx( /* Prototypes */ hDirAC_mem->proto_direct_buffer_f_fx = NULL; hDirAC_mem->proto_diffuse_buffer_f_fx = NULL; + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len = 0; + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len = 0; + hDirAC_mem->proto_diffuse_buffer_f_len = 0; test(); test(); IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) diff --git a/lib_rend/ivas_efap_fx.c b/lib_rend/ivas_efap_fx.c index 23ffbe0bd17bffb0c2f17d128bac4ba46e9325d4..c5bbfb2ea3e5d6cbf55b4c2566eb2e9e58da93b1 100644 --- a/lib_rend/ivas_efap_fx.c +++ b/lib_rend/ivas_efap_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include #include #include #include "options.h" @@ -42,6 +41,7 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_hrtf_fx.c b/lib_rend/ivas_hrtf_fx.c index dee0fe052a902bb55841b54c10646c6ff79fcce7..537323af591737f9ad114e25139555b13a758d22 100644 --- a/lib_rend/ivas_hrtf_fx.c +++ b/lib_rend/ivas_hrtf_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,19 +33,18 @@ #include #include "options.h" #include "prot_fx.h" -#include "ivas_rom_binaural_crend_head.h" #include "ivas_prot_rend_fx.h" #include "ivas_error.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* - * ivas_HRTF_binary_open() + * ivas_HRTF_td_binary_open() * * Allocate HRTF binary handle for TD renderer *-----------------------------------------------------------------------*/ -ivas_error ivas_HRTF_binary_open_fx( +ivas_error ivas_HRTF_td_binary_open_fx( TDREND_HRFILT_FiltSet_t **hHrtfTD ) { /* Allocate HR filter set for headphones configuration */ @@ -60,14 +59,12 @@ ivas_error ivas_HRTF_binary_open_fx( return IVAS_ERR_OK; } - /*-------------------------------------------------------------------* - * ivas_HRTF_binary_close() + * ivas_HRTF_td_binary_close_fx() * * Close HRTF binary handle for TD renderer *-------------------------------------------------------------------*/ - -void ivas_HRTF_binary_close_fx( +void ivas_HRTF_td_binary_close_fx( TDREND_HRFILT_FiltSet_t **hHrtfTD ) { test(); @@ -76,6 +73,76 @@ void ivas_HRTF_binary_close_fx( return; } + Word16 i; + IF( ( *hHrtfTD )->ModelParams.modelROM ) + { + FOR( i = 0; i < ( *hHrtfTD )->ModelParams.num_unique_azim_splines; i++ ) + { + free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn_fx[i] ); + } + free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn_fx ); + free( (void *) ( *hHrtfTD )->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ + FOR( i = 0; i < ( *hHrtfTD )->ModelParams.elevDim3; i++ ) + { + free( ( *hHrtfTD )->ModelParams.azimKSeq_fx[i] ); + } + free( ( *hHrtfTD )->ModelParams.azimKSeq_fx ); + IF( ( *hHrtfTD )->ModelEval.hrfModR_fx != NULL ) + { + free( ( *hHrtfTD )->ModelEval.hrfModL_fx ); + } + IF( ( *hHrtfTD )->ModelEval.hrfModL_fx != NULL ) + { + free( ( *hHrtfTD )->ModelEval.hrfModR_fx ); + } + } + else + { + if ( ( *hHrtfTD )->ModelParams.UseItdModel ) + { + free( ( *hHrtfTD )->ModelParamsITD.elevKSeq_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.azimKSeq_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.W_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.azimBsShape_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.elevBsShape_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.azimBsLen_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.azimBsStart_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.elevBsLen_dyn_fx ); + free( ( *hHrtfTD )->ModelParamsITD.elevBsStart_dyn_fx ); + } + free( ( *hHrtfTD )->ModelParams.elevKSeq_dyn_fx ); + free( ( *hHrtfTD )->ModelParams.azim_start_idx_dyn ); + free( ( *hHrtfTD )->ModelParams.azimDim3_dyn ); + free( ( *hHrtfTD )->ModelParams.AlphaL_dyn_fx ); + free( ( *hHrtfTD )->ModelParams.AlphaR_dyn_fx ); + free( ( *hHrtfTD )->ModelParams.azimSegSamples_dyn ); + + free( ( *hHrtfTD )->ModelParams.azimShapeIdx_dyn ); + free( ( *hHrtfTD )->ModelParams.azimShapeSampFactor_dyn ); + free( ( *hHrtfTD )->ModelParams.elevBsLen_dyn ); + free( ( *hHrtfTD )->ModelParams.elevBsStart_dyn ); + free( ( *hHrtfTD )->ModelParams.elevBsShape_dyn_fx ); + + for ( i = 0; i < ( *hHrtfTD )->ModelParams.num_unique_azim_splines; i++ ) + { + free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn_fx[i] ); + } + free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn_fx ); + + free( (void *) ( *hHrtfTD )->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ + for ( i = 0; i < ( *hHrtfTD )->ModelParams.elevDim3; i++ ) + { + free( ( *hHrtfTD )->ModelParams.azimKSeq_fx[i] ); + } + free( ( *hHrtfTD )->ModelParams.azimKSeq_fx ); + + free( ( *hHrtfTD )->ModelParams.EL_dyn_fx ); + free( ( *hHrtfTD )->ModelParams.ER_dyn_fx ); + + free( ( *hHrtfTD )->ModelEval.hrfModL_fx ); + free( ( *hHrtfTD )->ModelEval.hrfModR_fx ); + } + free( *hHrtfTD ); *hHrtfTD = NULL; @@ -113,8 +180,7 @@ ivas_error ivas_HRTF_CRend_binary_open_fx( * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ - -ivas_error ivas_HRTF_CRend_binary_open_buffers_int16( +ivas_error ivas_HRTF_binary_open_buffers_int16( Word16 **buffer, /* o : buffer to allocate */ const UWord32 mem_size /* i : size of buffer */ ) @@ -129,6 +195,85 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_int16( return IVAS_ERR_OK; } +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_uint16() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_uint16( + UWord16 **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (UWord16 *) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_int32() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_int32( + Word32 **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (Word32 *) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_int32_ptr() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_int32_ptr( + Word32 ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (Word32 **) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_int32_ptr_const() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_int32_ptr_const( + const Word32 ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (const Word32 **) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} /*-------------------------------------------------------------------* * ivas_HRTF_CRend_binary_close() @@ -224,6 +369,9 @@ void ivas_HRTF_fastconv_binary_close_fx( return; } + /* Fastconv HRTF memories */ + ivas_binaural_hrtf_close_fx( hHrtfFastConv ); + free( *hHrtfFastConv ); *hHrtfFastConv = NULL; @@ -232,7 +380,7 @@ void ivas_HRTF_fastconv_binary_close_fx( /*-----------------------------------------------------------------------* - * ivas_HRTF_parambin_binary_open() + * ivas_HRTF_parambin_binary_open_fx() * * Allocate HRTF binary handle for parametric binauralizer *-----------------------------------------------------------------------*/ @@ -253,7 +401,7 @@ ivas_error ivas_HRTF_parambin_binary_open_fx( /*-----------------------------------------------------------------------* - * ivas_HRTF_parambin_binary_close() + * ivas_HRTF_parambin_binary_close_fx() * * Close HRTF binary handle for parametric binauralizer *-----------------------------------------------------------------------*/ @@ -288,139 +436,43 @@ ivas_error ivas_HRTF_statistics_binary_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); } + set_c( (Word8 *) ( *hHrtfStatistics ), 0, (Word32) sizeof( HRTFS_STATISTICS ) ); return IVAS_ERR_OK; } - -/*-----------------------------------------------------------------------* - * ivas_HRTF_statistics_close() +/*---------------------------------------------------------------------* + * ivas_HRTF_statistics_binary_close_fx() * - * Close HRTF binary handle for statistics handler - *-----------------------------------------------------------------------*/ - -void ivas_HRTF_statistics_close_fx( - HRTFS_STATISTICS **hHrtfStatistics ) + * Destroy the HRTF statistics set. + *---------------------------------------------------------------------*/ +void ivas_HRTF_statistics_binary_close_fx( + IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle */ +) { test(); IF( hHrtfStatistics == NULL || *hHrtfStatistics == NULL ) { return; } - - free( *hHrtfStatistics ); - *hHrtfStatistics = NULL; - - return; -} - - -/*-----------------------------------------------------------------------* - * ivas_HRTF_statistics_init() - * - * Allocates HRTF statistics handle and initializes from ROM - *-----------------------------------------------------------------------*/ - -ivas_error ivas_HRTF_statistics_init_fx( - HRTFS_STATISTICS_HANDLE *hHrtfStatistics, - const Word32 sampleRate ) -{ - HRTFS_STATISTICS *HrtfStatistics; - test(); - IF( hHrtfStatistics != NULL && *hHrtfStatistics != NULL ) - { - /* Tables already loaded from file */ - return IVAS_ERR_OK; - } - - /* Initialise tables from ROM */ - IF( ( HrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL ) + IF( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); - } - - HrtfStatistics->average_energy_l = NULL; - HrtfStatistics->average_energy_r = NULL; - HrtfStatistics->inter_aural_coherence = NULL; - - SWITCH( sampleRate ) - { - case 48000: - HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - IF( HrtfStatistics->average_energy_l_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - IF( HrtfStatistics->average_energy_r_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - IF( HrtfStatistics->inter_aural_coherence_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - Copy_Scale_sig_16_32_r( defaultHRIR_left_avg_power_48kHz_fx, HrtfStatistics->average_energy_l_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_48kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - Copy_Scale_sig_16_32_r( defaultHRIR_right_avg_power_48kHz_fx, HrtfStatistics->average_energy_r_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_48kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - Copy_Scale_sig_16_32_r( defaultHRIR_coherence_48kHz_fx, HrtfStatistics->inter_aural_coherence_dyn, LR_IAC_LENGTH_NR_FC, Q26 - defaultHRIR_Q_48kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - HrtfStatistics->average_energy_l = (const Word32 *) HrtfStatistics->average_energy_l_dyn; - HrtfStatistics->average_energy_r = (const Word32 *) HrtfStatistics->average_energy_r_dyn; - HrtfStatistics->inter_aural_coherence = (const Word32 *) HrtfStatistics->inter_aural_coherence_dyn; - BREAK; - case 32000: - HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - IF( HrtfStatistics->average_energy_l_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - IF( HrtfStatistics->average_energy_r_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - IF( HrtfStatistics->inter_aural_coherence_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - Copy_Scale_sig_16_32_r( defaultHRIR_left_avg_power_32kHz_fx, HrtfStatistics->average_energy_l_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_32kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - Copy_Scale_sig_16_32_r( defaultHRIR_right_avg_power_32kHz_fx, HrtfStatistics->average_energy_r_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_32kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - Copy_Scale_sig_16_32_r( defaultHRIR_coherence_32kHz_fx, HrtfStatistics->inter_aural_coherence_dyn, LR_IAC_LENGTH_NR_FC, Q26 - defaultHRIR_Q_32kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - HrtfStatistics->average_energy_l = (const Word32 *) HrtfStatistics->average_energy_l_dyn; - HrtfStatistics->average_energy_r = (const Word32 *) HrtfStatistics->average_energy_r_dyn; - HrtfStatistics->inter_aural_coherence = (const Word32 *) HrtfStatistics->inter_aural_coherence_dyn; - BREAK; - case 16000: - HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) ); - IF( HrtfStatistics->average_energy_l_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) ); - IF( HrtfStatistics->average_energy_r_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) ); - IF( HrtfStatistics->inter_aural_coherence_dyn == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); - } - Copy_Scale_sig_16_32_r( defaultHRIR_left_avg_power_16kHz_fx, HrtfStatistics->average_energy_l_dyn, LR_IAC_LENGTH_NR_FC_16KHZ, Q28 - defaultHRIR_Q_16kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - Copy_Scale_sig_16_32_r( defaultHRIR_right_avg_power_16kHz_fx, HrtfStatistics->average_energy_r_dyn, LR_IAC_LENGTH_NR_FC_16KHZ, Q28 - defaultHRIR_Q_16kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - Copy_Scale_sig_16_32_r( defaultHRIR_coherence_16kHz_fx, HrtfStatistics->inter_aural_coherence_dyn, LR_IAC_LENGTH_NR_FC_16KHZ, Q26 - defaultHRIR_Q_16kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ - HrtfStatistics->average_energy_l = (const Word32 *) HrtfStatistics->average_energy_l_dyn; - HrtfStatistics->average_energy_r = (const Word32 *) HrtfStatistics->average_energy_r_dyn; - HrtfStatistics->inter_aural_coherence = (const Word32 *) HrtfStatistics->inter_aural_coherence_dyn; - BREAK; + if ( ( *hHrtfStatistics )->average_energy_l_dyn != NULL ) + { + free( ( *hHrtfStatistics )->average_energy_l_dyn ); + } + if ( ( *hHrtfStatistics )->average_energy_r_dyn != NULL ) + { + free( ( *hHrtfStatistics )->average_energy_r_dyn ); + } + if ( ( *hHrtfStatistics )->inter_aural_coherence_dyn != NULL ) + { + free( ( *hHrtfStatistics )->inter_aural_coherence_dyn ); + } } - HrtfStatistics->fromROM = TRUE; -#ifdef FIX_1990_SANITIZER_IN_REVERB_LOAD - HrtfStatistics->fromROM = FALSE; // TODO: temporary hack until HRTF statistics ROM tables are converted from Word16 to Word32 -#endif - *hHrtfStatistics = HrtfStatistics; + free( *hHrtfStatistics ); + *hHrtfStatistics = NULL; - return IVAS_ERR_OK; + return; } diff --git a/lib_rend/ivas_masa_merge_fx.c b/lib_rend/ivas_masa_merge_fx.c index 6837a3e1ab982dc9031114b938ffdfe476dd82c4..b645be551d16619f0bf1e643ee0c5ca87241fadb 100644 --- a/lib_rend/ivas_masa_merge_fx.c +++ b/lib_rend/ivas_masa_merge_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,9 +30,7 @@ *******************************************************************************************************/ -#include #include "options.h" -#include "lib_rend.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" #include "prot_fx.h" @@ -40,6 +38,7 @@ #include "ivas_rom_com.h" #include "ivas_prot_fx.h" + #define INV_UINT8_MAX 8421505 /* 1/UINT8_MAX in Q31 */ /*---------------------------------------------------------------------* diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index a6d9968406ddb669983ddd5a487fd76a7e4d99f8..8f4149171fceb11c6109c2bbcc73f506ec4c8a65 100644 --- a/lib_rend/ivas_mcmasa_ana_fx.c +++ b/lib_rend/ivas_mcmasa_ana_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,7 +30,6 @@ *******************************************************************************************************/ -#include #include #include #include "ivas_cnst.h" @@ -47,10 +46,8 @@ * Local constants *------------------------------------------------------------------------*/ -#define NEAR_HORIZONTAL_PLANE_ELEVATION 17.5f -#define NEAR_HORIZONTAL_PLANE_ELEVATION_FX 73400320 /*Q22*/ -#define VERTICAL_ENERGY_RATIO_OFFSET 0.15f -#define VERTICAL_ENERGY_RATIO_OFFSET_FX 4915 /*Q15*/ +#define NEAR_HORIZONTAL_PLANE_ELEVATION_FX 73400320 /* 17.5f in Q22 */ +#define VERTICAL_ENERGY_RATIO_OFFSET_FX 4915 /* 0.15f in Q15 */ /*------------------------------------------------------------------------- @@ -426,14 +423,23 @@ void ivas_mcmasa_ana_close( ( *hMcMasa )->direction_vector_m_fx[i][j] = NULL; } + free( ( *hMcMasa )->direction_vector_m_fx[i] ); + ( *hMcMasa )->direction_vector_m_fx[i] = NULL; + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( ( *hMcMasa )->direction_vector_e[i][j] ); + ( *hMcMasa )->direction_vector_e[i][j] = NULL; + } + + free( ( *hMcMasa )->direction_vector_e[i] ); + ( *hMcMasa )->direction_vector_e[i] = NULL; + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { free( ( *hMcMasa )->buffer_intensity_real_fx[i][j] ); ( *hMcMasa )->buffer_intensity_real_fx[i][j] = NULL; } - - free( ( *hMcMasa )->direction_vector_m_fx[i] ); - ( *hMcMasa )->direction_vector_m_fx[i] = NULL; } FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) diff --git a/lib_rend/ivas_objectRenderer_fx.c b/lib_rend/ivas_objectRenderer_fx.c index 5c72bf87e5f387a05f1b90168ce33fe2cb7e9ed4..03b0afe82aae3f400074c3f108d0b6c938a91e11 100644 --- a/lib_rend/ivas_objectRenderer_fx.c +++ b/lib_rend/ivas_objectRenderer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,11 +35,12 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" -#include #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#ifdef DEBUGGING #include "debug.h" +#endif /*---------------------------------------------------------------------* @@ -433,9 +434,9 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( { Word16 i; - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < num_src; ++i ) { - scale_sig32( output_fx[i], L_FRAME48k, -4 ); // Q11 - 4 = Q7 + scale_sig32( output_fx[i], output_frame, -4 ); // Q11 - 4 = Q7 } IF( NE_32( ( error = ivas_reverb_process_fx( hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx ) ), IVAS_ERR_OK ) ) // Q p_reverb_signal_fx = Q output_fx - 2 = 5 @@ -443,9 +444,9 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( return error; } - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < num_src; ++i ) { - scale_sig32( output_fx[i], L_FRAME48k, 4 ); // Q7 + 4 = Q11 + scale_sig32( output_fx[i], output_frame, 4 ); // Q7 + 4 = Q11 } FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 2a67d7a39a5277407bf20b818de4324978ac5b66..d5abb8fcef15b24907d0a7b442b6131da552d8b5 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,12 +34,12 @@ #include #include "options.h" #include "prot_fx.h" -#include #include "ivas_prot_rend_fx.h" #include "ivas_rom_rend.h" #include "ivas_cnst.h" #include "wmc_auto.h" + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index 28ee13931346b1418d16bbc945f33fc3765e62a7..a0a57d0a2179bd51055513ff5ac2a66ebd62c4ef 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -151,30 +151,6 @@ void TDREND_MIX_Dealloc_fx( { BSplineModelEvalDealloc_fx( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); } - ELSE - { - IF( hBinRendererTd->HrFiltSet_p->Elev_p_fx != NULL ) - { - free( hBinRendererTd->HrFiltSet_p->Elev_p_fx ); - hBinRendererTd->HrFiltSet_p->Elev_p_fx = NULL; - } - IF( hBinRendererTd->HrFiltSet_p->Azim_p_fx != NULL ) - { - free( hBinRendererTd->HrFiltSet_p->Azim_p_fx ); - hBinRendererTd->HrFiltSet_p->Azim_p_fx = NULL; - } - IF( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx != NULL ) - { - free( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx ); - hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx = NULL; - } - IF( hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx != NULL ) - { - free( hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx ); - hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx = NULL; - } - } - IF( hBinRendererTd->HrFiltSet_p->ModelParams.modelROM ) { IF( hBinRendererTd->HrFiltSet_p->ModelParams.UseItdModel ) diff --git a/lib_rend/ivas_objectRenderer_sfx_fx.c b/lib_rend/ivas_objectRenderer_sfx_fx.c index 361cc403d19ccad22d98321d5b7c5da190877b9d..1c899f95ba696e8f9ed036b5b4169c2c57b6e4bc 100644 --- a/lib_rend/ivas_objectRenderer_sfx_fx.c +++ b/lib_rend/ivas_objectRenderer_sfx_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,18 +32,12 @@ #include #include "options.h" -#include #include "ivas_prot_rend_fx.h" #include "ivas_rom_rend.h" #include "prot_fx.h" #include "wmc_auto.h" -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ - - /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_objectRenderer_sources_fx.c b/lib_rend/ivas_objectRenderer_sources_fx.c index 33c519c8eb5f931bcb7f01f69f2e5ff463239ff1..f91ed65fa86bdb5b5a5cabf58e37001f47af83e3 100644 --- a/lib_rend/ivas_objectRenderer_sources_fx.c +++ b/lib_rend/ivas_objectRenderer_sources_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "wmc_auto.h" diff --git a/lib_rend/ivas_objectRenderer_vec_fx.c b/lib_rend/ivas_objectRenderer_vec_fx.c index 140861539307a16b008dcd1fc0a29922d844c8b6..81268e578e1e80b59cd60df7d4f8340bb432cc89 100644 --- a/lib_rend/ivas_objectRenderer_vec_fx.c +++ b/lib_rend/ivas_objectRenderer_vec_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "wmc_auto.h" diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index b95f5500df00136594444fc6f98909eb248c5c35..02af0f7fdb41a0beae11f7b2f41b25d0452c8cb2 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include "options.h" #include -#include #include "ivas_cnst.h" #include "ivas_prot_rend_fx.h" #include "ivas_prot_fx.h" @@ -41,6 +40,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" + /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ @@ -719,7 +719,7 @@ static void ivas_omasa_dmx_fx( } max_e = in_e[0]; move16(); - FOR( l = 1; l < L_FRAME48k; l++ ) + FOR( l = 1; l < input_frame; l++ ) { IF( LT_16( max_e, in_e[l] ) ) { @@ -728,7 +728,7 @@ static void ivas_omasa_dmx_fx( } } - FOR( l = 0; l < L_FRAME48k; l++ ) + FOR( l = 0; l < input_frame; l++ ) { data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); diff --git a/lib_rend/ivas_orient_trk_fx.c b/lib_rend/ivas_orient_trk_fx.c index ee91e7060e252c6d06e9827ba3f2e5d353710038..18fabc03252f67e43a4ee01e1fcfb9b8624b57b5 100644 --- a/lib_rend/ivas_orient_trk_fx.c +++ b/lib_rend/ivas_orient_trk_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,11 +36,11 @@ #include "ivas_prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" -#include #include #include "wmc_auto.h" #include "prot_fx.h" + /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ @@ -482,11 +482,21 @@ static Word32 VectorLength_fx( IVAS_VECTOR3 p, Word16 *q_fact ) { +#ifdef FIX_BASOP_2361_OTR + Word16 sqrt_e; + Word32 result_fx; + result_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p.x_fx, p.x_fx ), p.y_fx, p.y_fx ), p.z_fx, p.z_fx ); + sqrt_e = shl( sub( 31, p.q_fact ), 1 ); /* convert Q to E */ + + result_fx = Sqrt32( result_fx, &sqrt_e ); + *q_fact = sub( 31, sqrt_e ); /* back to Q again */ +#else Word32 result_fx = 0; move32(); result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); +#endif move16(); return result_fx; } @@ -702,7 +712,14 @@ ivas_error ivas_orient_trk_SetReferenceRotation_fx( Euler2Quat_fx( deg2rad_fx( refRot.x_fx ), deg2rad_fx( refRot.y_fx ), deg2rad_fx( refRot.z_fx ), &pOTR->refRot ); modify_Quat_q_fx( &pOTR->refRot, &pOTR->refRot, Q29 ); } - pOTR->refRot = refRot; +#ifdef FIX_BASOP_2361_OTR + ELSE + { +#endif + pOTR->refRot = refRot; +#ifdef FIX_BASOP_2361_OTR + } +#endif return IVAS_ERR_OK; } @@ -824,11 +841,16 @@ ivas_error ivas_orient_trk_SetReferenceVector_fx( return IVAS_ERR_WRONG_PARAMS; } +#ifdef FIX_BASOP_2361_OTR + Word16 tmp_q; + acousticFrontVectorLength = VectorLength_fx( acousticFrontVector, &tmp_q ); +#else Word16 accoustic_q = acousticFrontVector.q_fact; move16(); acousticFrontVectorLength = VectorLength_fx( acousticFrontVector, &acousticFrontVector.q_fact ); acousticFrontVector.q_fact = accoustic_q; move16(); +#endif /* if the length is zero, the user has entered insensible listener and reference positions */ IF( LE_32( acousticFrontVectorLength, 0 ) ) { @@ -889,6 +911,18 @@ ivas_error ivas_orient_trk_Process_fx( /* Reset average orientation */ pOTR->absAvgRot = absRot; +#ifdef FIX_BASOP_2361_OTR + Word16 scale_e; + Word16 tmp; + tmp = BASOP_Util_Divide3232_Scale( PI2_C_ADP_RATE_Q31, updateRate_fx, &scale_e ); + scale_e = add( scale_e, 23 - 31 ); /* updateRate_fx is hardcoded in caller to Q23 */ + + /* sin(x) is approx x for small x */ + pOTR->alpha_fx = L_deposit_h( tmp ); + move32(); + pOTR->Q_alpha = sub( Q31, scale_e ); + move16(); +#else Word16 scale_e; Word32 div; div = L_deposit_h( BASOP_Util_Divide3232_Scale( pOTR->centerAdaptationRate_fx, updateRate_fx, &scale_e ) ); @@ -897,6 +931,7 @@ ivas_error ivas_orient_trk_Process_fx( // here div value is less so we can use sandwitch rule of sine// pOTR->alpha_fx = div; move32(); +#endif /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse_fx( pOTR->refRot, &pOTR->trkRot ); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); @@ -950,6 +985,8 @@ ivas_error ivas_orient_trk_Process_fx( cutoff_prod = L_shl( cutoff_prod, temp_diff ); /* Compute adaptivity cutoff frequency: interpolate between minimum (center) and maximum (off-center) values */ cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); // Q31 + + /* Compute filter coefficient corresponding to desired cutoff frequency */ cutoff_prod = Mpy_32_32( cutoffFrequency_fx, PI2_C_Q28 ); q_cutoff_prod = ( ( 31 + 28 ) - 31 ); temp_result = BASOP_Util_Divide3232_Scale( cutoff_prod, updateRate_fx, &result_e ); diff --git a/lib_rend/ivas_output_init_fx.c b/lib_rend/ivas_output_init_fx.c index 053cb43c1e4ee0083dd07e708cd709cc14e3fd99..ec279e1686178635bcf3aa33f8030d71abe10913 100644 --- a/lib_rend/ivas_output_init_fx.c +++ b/lib_rend/ivas_output_init_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -387,7 +387,7 @@ Word16 ivas_get_nchan_buffers_dec_fx( } ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { - nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); + nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); IF( st_ivas->hOutSetup.separateChannelEnabled ) { @@ -408,7 +408,7 @@ Word16 ivas_get_nchan_buffers_dec_fx( test(); IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - nchan_out_buff = max( nchan_out_buff, st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS ); + nchan_out_buff = s_max( nchan_out_buff, st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS ); } return nchan_out_buff; @@ -446,7 +446,7 @@ ivas_error ivas_output_buff_dec_fx( if ( Opt_tsm ) { /* JBM decoding: output audio buffers are shared with audio buffers from 'hTcBuffer->tc[]' */ - nchan_tc_jbm = s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); + nchan_tc_jbm = s_max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); } test(); @@ -615,11 +615,11 @@ ivas_error get_channel_config( } ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) { - strcpy( (char *) str, "BINAURAL_SPLIT_CODED" ); + strcpy( (char *) str, "Binaural: split-rendering mode with encoded output in an intermediate format" ); } ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - strcpy( (char *) str, "Binaural_Split_PCM" ); + strcpy( (char *) str, "Binaural: split-rendering mode with separate PCM binaural output and metadata bitstream output" ); } ELSE IF( EQ_16( (Word16) config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { diff --git a/lib_rend/ivas_prot_rend_fx.h b/lib_rend/ivas_prot_rend_fx.h index df575fd3215118dd131621c418686f8ea6a28375..b393971b7bcbda183494ad2150363e12bce87520 100644 --- a/lib_rend/ivas_prot_rend_fx.h +++ b/lib_rend/ivas_prot_rend_fx.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -578,12 +578,11 @@ void ivas_masa_ext_dirac_render_fx( /*----------------------------------------------------------------------------------* * HRTF *----------------------------------------------------------------------------------*/ - -ivas_error ivas_HRTF_binary_open_fx( +ivas_error ivas_HRTF_td_binary_open_fx( TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ ); -void ivas_HRTF_binary_close_fx( +void ivas_HRTF_td_binary_close_fx( TDREND_HRFILT_FiltSet_t **hHrtfTD /* i/o: TD renderer HRTF handle */ ); @@ -607,24 +606,38 @@ ivas_error ivas_HRTF_CRend_binary_open_fx( HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ ); -ivas_error ivas_HRTF_CRend_binary_open_buffers_int16( - Word16 **buffer, /* o : buffer to allocate */ +ivas_error ivas_HRTF_binary_open_buffers_uint16( + uint16_t **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ); -void ivas_HRTF_CRend_binary_close_fx( - HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ +ivas_error ivas_HRTF_binary_open_buffers_int16( + int16_t **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ ); -ivas_error ivas_HRTF_statistics_init_fx( - HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* i/o: HRTF statistics structure */ - const Word32 sampleRate /* i : Sample rate */ +ivas_error ivas_HRTF_binary_open_buffers_int32( + int32_t **buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ ); -void ivas_HRTF_statistics_close_fx( - HRTFS_STATISTICS **hHrtfStatistics /* i/o: HRTF statistics structure */ +ivas_error ivas_HRTF_binary_open_buffers_int32_ptr( + int32_t ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); + +ivas_error ivas_HRTF_binary_open_buffers_int32_ptr_const( + const int32_t ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); + +void ivas_HRTF_CRend_binary_close_fx( + HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ ); +void ivas_HRTF_statistics_binary_close_fx( + HRTFS_STATISTICS **hHrtfStatistics ); /* i/o: HRTF statistics structure */ + ivas_error ivas_HRTF_statistics_binary_open_fx( HRTFS_STATISTICS **hHrtfStatistics /* i/o: HRTF statistics structure */ ); @@ -914,7 +927,7 @@ ivas_error ivas_rend_crendProcessSubframe_fx( const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ - DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ + DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: TC handle */ Word32 *input_f[], /* i : transport channels */ Word32 *output[], /* i/o: input/output audio channels */ const Word16 n_samples_to_render, /* i : output frame length per channel */ @@ -953,6 +966,11 @@ void ivas_binaural_reverb_processSubframe_fx( Word32 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ ); +ivas_error ivas_reverb_HRTF_statistics_open_fx( + HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* o : HRTF statistics handle */ + const Word32 output_Fs /* i : output sampling rate */ +); + ivas_error ivas_reverb_open_fx( REVERB_HANDLE *hReverb, /* i/o: Reverberator handle */ const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i : HRTF statistics handle */ @@ -1555,12 +1573,12 @@ ivas_error ivas_rend_crendProcessSubframesSplitBin( const CREND_WRAPPER *pCrend, /* i/o: Crend wrapper handle */ const AUDIO_CONFIG inConfig, /* i : input audio configuration */ const AUDIO_CONFIG outConfig, /* i : output audio configuration */ - const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, + const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : decoder config. structure */ const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ const IVAS_OUTPUT_SETUP_HANDLE hIntSetup, /* i : internal setup handle */ const EFAP_HANDLE hEFAPdata, /* i : EFAP handle */ - DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: JBM handle */ + DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: TC handle */ Word32 *input_f[], /* i : transport channels */ Word32 *output[], /* i/o: input/output audio channels */ const Word16 n_samples_to_render, /* i : output frame length per channel */ @@ -1648,6 +1666,40 @@ Word16 ivas_TD_RINGBUF_Size( const TD_RINGBUF_HANDLE h /* i : Ring buffer handle */ ); -/* clang-format on */ +/*---------------------------------------------------------------------------------* + * Multi-pose ring buffer Prototypes +*-----------------------------------------------------------------------------------*/ + +ivas_error ivas_CLDFB_RINGBUF_Open( + ISAR_CLDFB_RINGBUF_HANDLE *ph, + const Word16 capacity_columns +); + +void ivas_CLDFB_RINGBUF_Close( + ISAR_CLDFB_RINGBUF_HANDLE *ph +); -#endif /* IVAS_PROT_REND_H */ +void ivas_CLDFB_RINGBUF_Push( + ISAR_CLDFB_RINGBUF_HANDLE h, + const Word32 *real, + const Word32 *imag, + const Word16 num_bands +); + +void ivas_CLDFB_RINGBUF_Pop( + ISAR_CLDFB_RINGBUF_HANDLE h, + Word32 *real, + Word32 *imag, + const Word16 num_bands +); + +void ivas_CLDFB_RINGBUF_GetByIdx( + ISAR_CLDFB_RINGBUF_HANDLE h, + Word32 **p_real, + Word32 **p_imag, + const Word16 idx +); + +#endif + +/* clang-format on */ diff --git a/lib_rend/ivas_reflections_fx.c b/lib_rend/ivas_reflections_fx.c index 3bf9f71693b040f72bdd32bf21cdd60853a4b8f6..22a332ab1f5a91e4ccf2eff5695a9755726cf04a 100644 --- a/lib_rend/ivas_reflections_fx.c +++ b/lib_rend/ivas_reflections_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,16 +32,16 @@ #include "options.h" #include -#include #include "prot_fx.h" #include "rom_dec.h" -#include "lib_rend.h" #include "ivas_prot_rend_fx.h" #include "ivas_stat_rend.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef DEBUGGING #include "debug.h" +#endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_render_config_fx.c b/lib_rend/ivas_render_config_fx.c index 9a6f79fea2823261123f4e7e1beaa45f995f516b..81f66bf60af8e61e1eac8098d2204cde18c0265f 100644 --- a/lib_rend/ivas_render_config_fx.c +++ b/lib_rend/ivas_render_config_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_reverb_delay_line_fx.c b/lib_rend/ivas_reverb_delay_line_fx.c index d2a6a0c44e2c825c0e31dfb09dca6aeb337d502c..d3a0f5bb257ba069ab317abfd3a7841b330e1bbf 100644 --- a/lib_rend/ivas_reverb_delay_line_fx.c +++ b/lib_rend/ivas_reverb_delay_line_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,11 @@ #include "ivas_prot_rend_fx.h" #include "prot_fx.h" #include "wmc_auto.h" +#ifdef DEBUGGING #include "debug.h" +#endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_rev_delay_line_init() * diff --git a/lib_rend/ivas_reverb_fft_filter_fx.c b/lib_rend/ivas_reverb_fft_filter_fx.c index b7f890ec39673d50daea8655d5a4bad9462be7e3..dcf13c15345f125a0ee3f2fba9f8ca7f4c187e80 100644 --- a/lib_rend/ivas_reverb_fft_filter_fx.c +++ b/lib_rend/ivas_reverb_fft_filter_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,10 +34,10 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" -#include #include "wmc_auto.h" +#ifdef DEBUGGING #include "debug.h" - +#endif /*------------------------------------------------------------------------------------------* * Static functions declarations diff --git a/lib_rend/ivas_reverb_filter_design_fx.c b/lib_rend/ivas_reverb_filter_design_fx.c index e826596ba7b686df5683cee85499ded94bbf2265..6d23b0053af7223a7c745b64214f868deb3164b5 100644 --- a/lib_rend/ivas_reverb_filter_design_fx.c +++ b/lib_rend/ivas_reverb_filter_design_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include -#include #include #include "wmc_auto.h" diff --git a/lib_rend/ivas_reverb_fx.c b/lib_rend/ivas_reverb_fx.c index 6ab0c7a6355243b49f77be91ab4511707aec6c93..9ffd743227f9e0621bf4b8692f93b95634fa0e66 100644 --- a/lib_rend/ivas_reverb_fx.c +++ b/lib_rend/ivas_reverb_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,12 +34,14 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" +#include "ivas_rom_binaural_crend_head.h" #include "ivas_cnst.h" -#include "math.h" #include "ivas_rom_rend.h" #include #include "wmc_auto.h" +#ifdef DEBUGGING #include "debug.h" +#endif /* The reverberator structure implemented here is described in detail in: @@ -86,6 +88,7 @@ static const Word16 default_loop_delay_48k[IVAS_REV_MAX_NR_BRANCHES] = { 2309, 1 static const Word16 default_loop_delay_32k[IVAS_REV_MAX_NR_BRANCHES] = { 1531, 1237, 1013, 839, 709, 613, 541, 479 }; static const Word16 default_loop_delay_16k[IVAS_REV_MAX_NR_BRANCHES] = { 769, 619, 509, 421, 353, 307, 269, 239 }; +#define MATRIX_CONSTANT ( 759250113 ) /*------------------------------------------------------------------------------------------* * Local Struct definition @@ -129,6 +132,117 @@ typedef struct ivas_reverb_params_t static ivas_error calc_jot_t60_coeffs_fx( Word16 *pH_dB_fx, Word16 pH_dB_exp, const UWord16 nrFrequencies, Word16 *pFrequencies_fx, Word16 *pCoeffA_fx, Word16 *pCoeffB_fx, const Word16 fNyquist_fx ); +/*------------------------------------------------------------------------- + * ivas_reverb_HRTF_statistics_open() + * + * Open and initialize HRTF statistics handle from ROM tables + *------------------------------------------------------------------------*/ + +ivas_error ivas_reverb_HRTF_statistics_open_fx( + HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* o : HRTF statistics handle */ + const Word32 output_Fs /* i : output sampling rate */ +) +{ + if ( *hHrtfStatistics != NULL ) + { + if ( ( *hHrtfStatistics )->fromROM == TRUE ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF statistics allocated but not initialized from binary file!\n" ); + } + + /* HRTF statistics loaded from binary file */ + return IVAS_ERR_OK; + } + + if ( ( *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" ); + } + + SWITCH( output_Fs ) + { + case 48000: + ( *hHrtfStatistics )->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->average_energy_l_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + ( *hHrtfStatistics )->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->average_energy_r_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + ( *hHrtfStatistics )->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->inter_aural_coherence_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + Copy_Scale_sig_16_32_r( defaultHRIR_left_avg_power_48kHz_fx, ( *hHrtfStatistics )->average_energy_l_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_48kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + Copy_Scale_sig_16_32_r( defaultHRIR_right_avg_power_48kHz_fx, ( *hHrtfStatistics )->average_energy_r_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_48kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + Copy_Scale_sig_16_32_r( defaultHRIR_coherence_48kHz_fx, ( *hHrtfStatistics )->inter_aural_coherence_dyn, LR_IAC_LENGTH_NR_FC, Q26 - defaultHRIR_Q_48kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + ( *hHrtfStatistics )->average_energy_l = (const Word32 *) ( *hHrtfStatistics )->average_energy_l_dyn; + ( *hHrtfStatistics )->average_energy_r = (const Word32 *) ( *hHrtfStatistics )->average_energy_r_dyn; + ( *hHrtfStatistics )->inter_aural_coherence = (const Word32 *) ( *hHrtfStatistics )->inter_aural_coherence_dyn; + BREAK; + case 32000: + ( *hHrtfStatistics )->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->average_energy_l_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + ( *hHrtfStatistics )->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->average_energy_r_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + ( *hHrtfStatistics )->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->inter_aural_coherence_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + Copy_Scale_sig_16_32_r( defaultHRIR_left_avg_power_32kHz_fx, ( *hHrtfStatistics )->average_energy_l_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_32kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + Copy_Scale_sig_16_32_r( defaultHRIR_right_avg_power_32kHz_fx, ( *hHrtfStatistics )->average_energy_r_dyn, LR_IAC_LENGTH_NR_FC, Q28 - defaultHRIR_Q_32kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + Copy_Scale_sig_16_32_r( defaultHRIR_coherence_32kHz_fx, ( *hHrtfStatistics )->inter_aural_coherence_dyn, LR_IAC_LENGTH_NR_FC, Q26 - defaultHRIR_Q_32kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + ( *hHrtfStatistics )->average_energy_l = (const Word32 *) ( *hHrtfStatistics )->average_energy_l_dyn; + ( *hHrtfStatistics )->average_energy_r = (const Word32 *) ( *hHrtfStatistics )->average_energy_r_dyn; + ( *hHrtfStatistics )->inter_aural_coherence = (const Word32 *) ( *hHrtfStatistics )->inter_aural_coherence_dyn; + BREAK; + case 16000: + ( *hHrtfStatistics )->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->average_energy_l_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + ( *hHrtfStatistics )->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->average_energy_r_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + ( *hHrtfStatistics )->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC_16KHZ * sizeof( Word32 ) ); + IF( ( *hHrtfStatistics )->inter_aural_coherence_dyn == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + Copy_Scale_sig_16_32_r( defaultHRIR_left_avg_power_16kHz_fx, ( *hHrtfStatistics )->average_energy_l_dyn, LR_IAC_LENGTH_NR_FC_16KHZ, Q28 - defaultHRIR_Q_16kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + Copy_Scale_sig_16_32_r( defaultHRIR_right_avg_power_16kHz_fx, ( *hHrtfStatistics )->average_energy_r_dyn, LR_IAC_LENGTH_NR_FC_16KHZ, Q28 - defaultHRIR_Q_16kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + Copy_Scale_sig_16_32_r( defaultHRIR_coherence_16kHz_fx, ( *hHrtfStatistics )->inter_aural_coherence_dyn, LR_IAC_LENGTH_NR_FC_16KHZ, Q26 - defaultHRIR_Q_16kHz_fx ); /* tables from which lr_energy_and_iac is updated has Q27 for i=2 */ + ( *hHrtfStatistics )->average_energy_l = (const Word32 *) ( *hHrtfStatistics )->average_energy_l_dyn; + ( *hHrtfStatistics )->average_energy_r = (const Word32 *) ( *hHrtfStatistics )->average_energy_r_dyn; + ( *hHrtfStatistics )->inter_aural_coherence = (const Word32 *) ( *hHrtfStatistics )->inter_aural_coherence_dyn; + BREAK; + default: + ( *hHrtfStatistics )->average_energy_l = NULL; + ( *hHrtfStatistics )->average_energy_r = NULL; + ( *hHrtfStatistics )->inter_aural_coherence = NULL; + BREAK; + } + ( *hHrtfStatistics )->fromROM = TRUE; +#ifdef FIX_1990_SANITIZER_IN_REVERB_LOAD + ( *hHrtfStatistics )->fromROM = FALSE; // TODO: temporary hack until HRTF statistics ROM tables are converted from Word16 to Word32 +#endif + return IVAS_ERR_OK; +} + /*------------------------------------------------------------------------- * wrap_rad_fx() * diff --git a/lib_rend/ivas_reverb_iir_filter_fx.c b/lib_rend/ivas_reverb_iir_filter_fx.c index 981a40466474a3b428557c4682243db0234cb885..e4ce77b6583d25d6c49e000dcb134ed2a4536e5e 100644 --- a/lib_rend/ivas_reverb_iir_filter_fx.c +++ b/lib_rend/ivas_reverb_iir_filter_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,9 +35,14 @@ #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "wmc_auto.h" +#ifdef DEBUGGING #include "debug.h" +#endif + + #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) + /*-----------------------------------------------------------------------------------------* * Function ivas_reverb_iir_filt_init() * diff --git a/lib_rend/ivas_reverb_utils_fx.c b/lib_rend/ivas_reverb_utils_fx.c index 6433da8195e7deba7874d9b3b325bf6cc9b350f2..05b3f8af64bb6b5f0d96c1925dfb071c53f7b971 100644 --- a/lib_rend/ivas_reverb_utils_fx.c +++ b/lib_rend/ivas_reverb_utils_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_rom_rend.h" -#include #include "wmc_auto.h" diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.h b/lib_rend/ivas_rom_TdBinauralRenderer.h index ed4ece7b68432695c1a93c241c62a93bc2733b81..176dc1f3eb8864f7c1664fa9e4eb3fba54e83645 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.h +++ b/lib_rend/ivas_rom_TdBinauralRenderer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" /*------------------------------------------------------------------------- diff --git a/lib_rend/ivas_rom_TdBinauralRenderer_fx.c b/lib_rend/ivas_rom_TdBinauralRenderer_fx.c index 531c45f83ff655c5775f70eada06f56194777f4d..980b692420e95b8086049bf8b8ec8da55087e323 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer_fx.c +++ b/lib_rend/ivas_rom_TdBinauralRenderer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -34,7 +34,6 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "wmc_auto.h" diff --git a/lib_rend/ivas_rom_binauralRenderer.h b/lib_rend/ivas_rom_binauralRenderer.h index f7ecc3ddac87b8bdca88e061df55392e678b1d77..178a50b7ce0457a425a09a16061da83652569e3a 100644 --- a/lib_rend/ivas_rom_binauralRenderer.h +++ b/lib_rend/ivas_rom_binauralRenderer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,7 +35,6 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" /*------------------------------------------------------------------------- diff --git a/lib_rend/ivas_rom_binauralRenderer_fx.c b/lib_rend/ivas_rom_binauralRenderer_fx.c index 3357eaeb870713885171a0cf4246d69078168189..37b472fc976803e9070de012b6ed6bfbc3acd798 100644 --- a/lib_rend/ivas_rom_binauralRenderer_fx.c +++ b/lib_rend/ivas_rom_binauralRenderer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include #include "options.h" -#include "cnst.h" #include "ivas_cnst.h" #include "wmc_auto.h" diff --git a/lib_rend/ivas_rom_binaural_crend_head.h b/lib_rend/ivas_rom_binaural_crend_head.h index ae97fc0feddcb92e1aca13577804a22338f56bea..a0f13e471db22bf61998bf0f477181ba79a7e228 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.h +++ b/lib_rend/ivas_rom_binaural_crend_head.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_rom_binaural_crend_head_fx.c b/lib_rend/ivas_rom_binaural_crend_head_fx.c index 9be532b7961d4f3976de3633f36a96c16c48af75..28ebb28e09f481b09e20f0387583144a751eefaf 100644 --- a/lib_rend/ivas_rom_binaural_crend_head_fx.c +++ b/lib_rend/ivas_rom_binaural_crend_head_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index d52ade0dbc47dfa5e220319520e4e75035ce65a7..7a1cf897135fe1f2082df259e3369c33ddc2180d 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_rom_rend_fx.c b/lib_rend/ivas_rom_rend_fx.c index c8114e0be9ee3aa072c4274302da99623ea8adba..18c018f293a94db497482b3a2b3ad83502f1de83 100644 --- a/lib_rend/ivas_rom_rend_fx.c +++ b/lib_rend/ivas_rom_rend_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_rotation_fx.c b/lib_rend/ivas_rotation_fx.c index d363c3629870ba8d91b323f656918bbe32350ec9..50b0b0f84eb630ddcbf210679455ddda3b1a3eb3 100644 --- a/lib_rend/ivas_rotation_fx.c +++ b/lib_rend/ivas_rotation_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -35,14 +35,13 @@ #include "basop_util.h" #include "ivas_cnst.h" #include "options.h" -#include -#include "cnst.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "wmc_auto.h" -#include #include "ivas_prot_fx.h" +#ifdef DEBUGGING #include "debug.h" +#endif #include "ivas_rom_binaural_crend_head.h" @@ -720,7 +719,7 @@ void rotateFrame_shd( move32(); BREAK; case L_SUBFRAME_32k: - tmp = Q31_BY_NUM_SAMPLES_160; + tmp = Q31_BY_SUB_FRAME_160; move32(); BREAK; case L_SUBFRAME_16k: @@ -857,7 +856,7 @@ void rotateFrame_sd( move32(); BREAK; case L_SUBFRAME_32k: - tmp = Q31_BY_NUM_SAMPLES_160; + tmp = Q31_BY_SUB_FRAME_160; move32(); BREAK; case L_SUBFRAME_16k: diff --git a/lib_rend/ivas_sba_rendering_fx.c b/lib_rend/ivas_sba_rendering_fx.c index ff077e63ebe85d22865a09c14b7d8548f9826f49..f4fab9d6e8d82702d65e64d9db2e97f475816cc1 100644 --- a/lib_rend/ivas_sba_rendering_fx.c +++ b/lib_rend/ivas_sba_rendering_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,15 +36,16 @@ #include "ivas_prot_rend_fx.h" #include "ivas_stat_dec.h" #include "ivas_cnst.h" -#include #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * ivas_sba_prototype_renderer() * * Render prototype audio signals using SBA mixing matrices *-------------------------------------------------------------------*/ + void ivas_sba_prototype_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real Q(q_cldfb[][])*/ diff --git a/lib_rend/ivas_shoebox_fx.c b/lib_rend/ivas_shoebox_fx.c index 36af55838b6dcbb024b46d75b7bfaf320a90ebc8..e6def409e649a8272bf31a719eaa4e159dbed0a3 100644 --- a/lib_rend/ivas_shoebox_fx.c +++ b/lib_rend/ivas_shoebox_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -32,7 +32,6 @@ #include "options.h" #include -#include #include "ivas_prot_rend_fx.h" #include "ivas_stat_rend.h" #include "ivas_prot_fx.h" diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index d84a00a1b9f3b9fb2dd2b5b3c9784d24fecd0043..1a6e33e728359c5acd5aa526c8bf20e07e22f034 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -37,8 +37,6 @@ #include #include "options.h" #include "ivas_cnst.h" -#include "ivas_stat_com.h" // note: needed for DIRAC_DEC_BIN_HANDLE until #156 is solved -#include "stat_com.h" /* Note: Currently needed for CLDFB. */ #include "common_api_types.h" #include "isar_stat.h" @@ -1165,16 +1163,7 @@ typedef struct typedef struct ivas_hrtf_TDREND_HRFILT_FiltSet_struct { Word32 SampleRate; /* Sample rate of the HR filter */ - Word16 NumPos; - Word16 NumElev; - Word32 Dist_fx; - Word32 *ItdSet_p_fx; Word16 FiltLength; - Word16 *Azim_p_fx; - Word16 *Elev_p_fx; - Word16 *ItdSetNominal_p_fx; - Word16 *LeftFiltSet_p_fx; - Word16 *RightFiltSet_p_fx; ModelParams_t ModelParams; ModelEval_t ModelEval; ModelParamsITD_t ModelParamsITD; diff --git a/lib_rend/ivas_td_decorr_fx.c b/lib_rend/ivas_td_decorr_fx.c index 14795da41b11854851fec67f7a8b67321ef0c517..d2ebd34d8086ef1b8d4c8f726115341f04d4a0f5 100644 --- a/lib_rend/ivas_td_decorr_fx.c +++ b/lib_rend/ivas_td_decorr_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,43 +36,48 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_prot_rend_fx.h" -#include "math.h" #include "wmc_auto.h" #ifdef DEBUGGING #include "debug.h" #endif + /*------------------------------------------------------------------------------------------* * Local constants *------------------------------------------------------------------------------------------*/ -static const Word16 ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = { /* Q15 */ - { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107 }, - { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107 }, - { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107 }, - { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107 }, - { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107 }, - { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107 }, - { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107 }, - { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107 }, - { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107 }, - { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107 }, - { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107 }, - { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107 }, - { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107 }, - { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107 }, - { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107 }, - { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107 } + +static const Word16 ivas_hadamard_decorr_APD_coeff[IVAS_APD_16_SECT][IVAS_APD_16_SECT] = { + /* Q15 */ + { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107 }, + { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107 }, + { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107 }, + { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107 }, + { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107 }, + { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107 }, + { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107 }, + { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107 }, + { 13107, 13107, 13107, 13107, 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107 }, + { 13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107 }, + { 13107, 13107, -13107, -13107, 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107 }, + { 13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107 }, + { 13107, 13107, 13107, 13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, -13107, 13107, 13107, 13107, 13107 }, + { 13107, -13107, 13107, -13107, -13107, 13107, -13107, 13107, -13107, 13107, -13107, 13107, 13107, -13107, 13107, -13107 }, + { 13107, 13107, -13107, -13107, -13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, 13107, 13107, -13107, -13107 }, + { 13107, -13107, -13107, 13107, -13107, 13107, 13107, -13107, -13107, 13107, 13107, -13107, 13107, -13107, -13107, 13107 } }; /* For R = 3.^([0:obj.parm_APD_nSections-1]/4); Q22 */ -static const Word32 ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { /* Q22 */ - 4194304, 5520015, 7264748, 9560946, 12582912, 16560043, 21794242, - 28682836, 37748736, 49680132, 65382728, 86048512, 113246208, - 149040384, 196148192, 258145536 +static const Word32 ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { + /* Q22 */ + 4194304, 5520015, 7264748, 9560946, 12582912, 16560043, 21794242, + 28682836, 37748736, 49680132, 65382728, 86048512, 113246208, + 149040384, 196148192, 258145536 }; #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 1073741824 ) // Q29 #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 1610612736 ) // Q29 + + /*------------------------------------------------------------------------------------------* * Local functions declaration *------------------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_td_ring_buffer_fx.c b/lib_rend/ivas_td_ring_buffer_fx.c index 78fde65d8e18a4dc4bd87f38bb1cd586236b7046..98905d25e328f543dd958fd8ac51e98db3645df1 100644 --- a/lib_rend/ivas_td_ring_buffer_fx.c +++ b/lib_rend/ivas_td_ring_buffer_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_rend/ivas_vbap_fx.c b/lib_rend/ivas_vbap_fx.c index ec24a33628bdabc5d80a5e854501304680790682..19b4b1f5631cdcfc39da35f29233850d9d695c67 100644 --- a/lib_rend/ivas_vbap_fx.c +++ b/lib_rend/ivas_vbap_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,13 +33,13 @@ #include #include "options.h" #include -#include #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 1d9ebafa6f82e48fd36750c07e9d65ba9c350d4b..1cb3077905f4367f6f36a5846511371779615585 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -58,7 +58,6 @@ * Renderer structures *---------------------------------------------------------------------*/ -typedef float IVAS_REND_LfePanMtx[RENDERER_MAX_INPUT_LFE_CHANNELS][RENDERER_MAX_OUTPUT_CHANNELS]; typedef Word32 IVAS_REND_LfePanMtx_fx[RENDERER_MAX_INPUT_LFE_CHANNELS][RENDERER_MAX_OUTPUT_CHANNELS]; typedef struct @@ -345,9 +344,6 @@ ivas_error IVAS_REND_SetReferenceVector( const IVAS_VECTOR3 refPos /* i : Reference position */ ); -ivas_error IVAS_REND_SetSplitRendBFI( - IVAS_REND_HANDLE hIvasRend, - const Word16 bfi); ivas_error IVAS_REND_SetExternalOrientation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index 1149440a9dfaf05b6e82a8ed1cbd1f2b420643d9..3a17884d4f92acb79dbcfb03507321560dc523e2 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -30,14 +30,13 @@ *******************************************************************************************************/ -#include "basop32.h" -#include "basop_util.h" +#include +#include #include "options.h" -#include "cnst.h" +#include "stl.h" +#include "basop_util.h" #include "common_api_types.h" -#include "enh32.h" #include "lib_rend.h" -#include "move.h" #include "prot_fx.h" #include "ivas_prot_fx.h" #include "ivas_prot_rend_fx.h" @@ -47,16 +46,12 @@ #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_rend.h" -#include "stl.h" -#include "typedef.h" -#include -#include -#include #include "wmc_auto.h" #ifdef DEBUGGING #include "debug.h" #endif + /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -99,7 +94,6 @@ typedef struct const EFAP_WRAPPER *pEfapOutWrapper; IVAS_REND_HeadRotData *pHeadRotData; // for now removing the const qualifier TODO: will modify later const RENDER_CONFIG_HANDLE *hhRendererConfig; - const Word16 *pSplitRendBFI; const SPLIT_REND_WRAPPER *pSplitRendWrapper; const COMBINED_ORIENTATION_HANDLE *pCombinedOrientationData; const IVAS_DefaultReverbSize *pSelectedRoomReverbSize; @@ -221,7 +215,6 @@ struct IVAS_REND EFAP_WRAPPER efapOutWrapper; IVAS_LSSETUP_CUSTOM_STRUCT customLsOut; - Word16 splitRendBFI; SPLIT_REND_WRAPPER *splitRendWrapper; IVAS_REND_AudioBuffer splitRendEncBuffer; IVAS_REND_HeadRotData headRotData; @@ -1370,7 +1363,6 @@ static rendering_context getRendCtx( ctx.pEfapOutWrapper = &hIvasRend->efapOutWrapper; ctx.pHeadRotData = &hIvasRend->headRotData; ctx.hhRendererConfig = &hIvasRend->hRendererConfig; - ctx.pSplitRendBFI = &hIvasRend->splitRendBFI; ctx.pSplitRendWrapper = hIvasRend->splitRendWrapper; ctx.pCombinedOrientationData = &hIvasRend->hCombinedOrientationData; ctx.pSelectedRoomReverbSize = &hIvasRend->selectedRoomReverbSize; @@ -1397,10 +1389,17 @@ static bool isIoConfigPairSupported( const AUDIO_CONFIG inConfig, const AUDIO_CONFIG outConfig ) { - /* Rendering mono or stereo to binaural is not supported */ + /* input config cannot be binaural */ test(); test(); - IF( ( EQ_32( inConfig, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_STEREO ) ) && EQ_32( getAudioConfigType( outConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) ) + IF( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) && + NE_32( inConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( inConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + return false; + } + + /* output config cannot be object based */ + IF( EQ_32( getAudioConfigType( outConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED ) ) { return false; } @@ -2568,15 +2567,45 @@ static ivas_error updateMcPanGainsForAmbiOut( { Word16 ch_in, ch_out, lfeIdx, i; Word16 numNonLfeInChannels, outAmbiOrder; + AUDIO_CONFIG inConfig; const Word32 *spkAzi_fx, *spkEle_fx; /* Q22 */ ivas_error error; + inConfig = inputMc->base.inConfig; + move32(); + IF( NE_32( ( error = getAmbisonicsOrder_fx( outConfig, &outAmbiOrder ) ), IVAS_ERR_OK ) ) { return error; } - IF( NE_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + test(); + IF( EQ_32( inConfig, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_STEREO ) ) + { + setZeroPanMatrix_fx( inputMc->panGains_fx ); + IF( EQ_32( inConfig, IVAS_AUDIO_CONFIG_MONO ) ) + { + /* W = Mono */ + inputMc->panGains_fx[0][0] = ONE_IN_Q31; + move32(); + } + ELSE + { + /* W = 0.5 * ( L + R ) */ + inputMc->panGains_fx[0][0] = ONE_IN_Q30 /* 0.5f in Q31 */; + inputMc->panGains_fx[0][1] = ONE_IN_Q30 /* 0.5f in Q31 */; + move32(); + move32(); + /* Y = 0.5 * ( L - R ) */ + inputMc->panGains_fx[1][0] = ONE_IN_Q30 /* 0.5f in Q31 */; + inputMc->panGains_fx[1][1] = -ONE_IN_Q30 /* -0.5f in Q31 */; + move32(); + move32(); + } + + return IVAS_ERR_OK; + } + ELSE IF( NE_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { IF( NE_32( ( error = getNumNonLfeChannelsInSpeakerLayout( inputMc->base.inConfig, &numNonLfeInChannels ) ), IVAS_ERR_OK ) ) { @@ -2687,6 +2716,37 @@ static ivas_error updateMcPanGainsForAmbiOut( return IVAS_ERR_OK; } + +static ivas_error updateMcPanGainsForBinauralOut( + input_mc *inputMc ) +{ + setZeroPanMatrix_fx( inputMc->panGains_fx ); + IF( inputMc->base.inConfig == IVAS_AUDIO_CONFIG_MONO ) + { + IF( EQ_32( inputMc->nonDiegeticPanGain_fx, ONE_IN_Q31 ) ) + { + inputMc->panGains_fx[0][0] = ONE_IN_Q31; + } + ELSE + { + inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 /* 0.5f in Q31 */ ); /* Q31 */ + } + move32(); + inputMc->panGains_fx[0][1] = L_sub( ONE_IN_Q31, inputMc->panGains_fx[0][0] ); + move32(); + } + ELSE + { + /* stereo passthrough */ + inputMc->panGains_fx[0][0] = ONE_IN_Q31; + inputMc->panGains_fx[1][1] = ONE_IN_Q31; + move32(); + move32(); + } + + return IVAS_ERR_OK; +} + static ivas_error updateMcPanGains( input_mc *inputMc, const AUDIO_CONFIG outConfig ) @@ -2708,6 +2768,14 @@ static ivas_error updateMcPanGains( error = updateMcPanGainsForAmbiOut( inputMc, outConfig ); BREAK; case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: + test(); + IF( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_STEREO ) ) + { + error = updateMcPanGainsForBinauralOut( inputMc ); + BREAK; + } + + /* not mono or stereo */ SWITCH( outConfig ) { case IVAS_AUDIO_CONFIG_BINAURAL: @@ -2766,6 +2834,12 @@ static ivas_error initMcBinauralRendering( Word8 useTDRend; Word16 i; + test(); + IF( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_STEREO ) ) + { + return IVAS_ERR_OK; + } + /* Allocate TD binaural renderer for custom loudspeaker layouts (regardless of headrotation) or planar MC layouts with headrotation, CREND for the rest */ useTDRend = FALSE; @@ -3791,7 +3865,7 @@ ivas_error IVAS_REND_Open( IF( asHrtfBinary ) { - IF( NE_32( ( error = ivas_HRTF_binary_open_fx( &( hIvasRend->hHrtfs.hHrtfTD ) ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_HRTF_td_binary_open_fx( &( hIvasRend->hHrtfs.hHrtfTD ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -3815,7 +3889,14 @@ ivas_error IVAS_REND_Open( IF( EQ_32( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( NE_32( ( error = ivas_HRTF_statistics_init_fx( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ), IVAS_ERR_OK ) ) + if ( hIvasRend->hHrtfs.hHrtfStatistics == NULL ) + { + /* Allocate and init HRTF statistics */ + IF( NE_32( ( error = ivas_reverb_HRTF_statistics_open_fx( &( hIvasRend->hHrtfs.hHrtfStatistics ), hIvasRend->sampleRateOut ) ), IVAS_ERR_OK ) ) + { + return error; + } + } { return error; } @@ -5640,23 +5721,6 @@ ivas_error IVAS_REND_DisableHeadRotation( } -/*-------------------------------------------------------------------* - * IVAS_REND_SetSplitRendBFI() - * - * - *-------------------------------------------------------------------*/ - -ivas_error IVAS_REND_SetSplitRendBFI( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const Word16 bfi /* i : Bad Frame Indicator */ -) -{ - hIvasRend->splitRendBFI = bfi; - - return IVAS_ERR_OK; -} - - /*-------------------------------------------------------------------* * IVAS_REND_SetOrientationTrackingMode() * @@ -5909,6 +5973,17 @@ ivas_error IVAS_REND_SetReverbRoomSize( This function takes 2 gain vectors - one for the beginning and one for the end of the buffer. Gain values are lineraly interpolated for all samples in between. */ +#define NUM_SAMPLES_960 ( 960 ) +#define NUM_SAMPLES_720 ( 720 ) +#define NUM_SAMPLES_640 ( 640 ) +#define NUM_SAMPLES_320 ( 320 ) +#define NUM_SAMPLES_160 ( 160 ) +#define Q31_BY_NUM_SAMPLES_960 ( 2239294 ) /* 1/959 in Q31 */ +#define Q31_BY_NUM_SAMPLES_720 ( 2986764 ) /* 1/719 in Q31 */ +#define Q31_BY_NUM_SAMPLES_640 ( 3360694 ) /* 1/639 in Q31 */ +#define Q31_BY_NUM_SAMPLES_320 ( 6731924 ) /* 1/319 in Q31 */ +#define Q31_BY_NUM_SAMPLES_160 ( 13506186 ) /* 1/159 in Q31 */ + static void renderBufferChannelLerp_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, @@ -6255,7 +6330,7 @@ static ivas_error rotateFrameMc_fx( /* move gains to gains_prev */ FOR( i = 0; i < nchan; i++ ) { - MVR2R_WORD32( gains[i], gains_prev[i], nchan ); + Copy32( gains[i], gains_prev[i], nchan ); } } @@ -6412,9 +6487,9 @@ static ivas_error renderIsmToBinaural( ism_md_subframe_update_ext = extract_l( Mpy_32_32( ismInput->ism_metadata_delay_ms_fx, ONE_BY_SUBFRAME_LEN_MS_Q31 ) ); copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpTDRendBuffer ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < ismInput->base.inputBuffer.config.numChannels; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ + Scale_sig32( tmpTDRendBuffer[i], ismInput->base.inputBuffer.config.numSamplesPerChannel, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, @@ -6424,9 +6499,9 @@ static ivas_error renderIsmToBinaural( return error; } - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < outAudio.config.numChannels; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ + Scale_sig32( tmpTDRendBuffer[i], outAudio.config.numSamplesPerChannel, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -6689,9 +6764,9 @@ static ivas_error renderIsmToBinauralReverb( ism_md_subframe_update_ext = extract_l( Mpy_32_32( ismInput->ism_metadata_delay_ms_fx, ONE_BY_SUBFRAME_LEN_MS_Q31 ) ); copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpRendBuffer_fx ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < ismInput->base.inputBuffer.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ + Scale_sig32( tmpRendBuffer_fx[i], ismInput->base.inputBuffer.config.numSamplesPerChannel, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ), IVAS_ERR_OK ) ) @@ -6699,9 +6774,9 @@ static ivas_error renderIsmToBinauralReverb( return error; } - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < outAudio.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); /* Q(exp) */ + Scale_sig32( tmpRendBuffer_fx[i], outAudio.config.numSamplesPerChannel, negate( sub( 11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -6853,6 +6928,8 @@ static ivas_error renderIsmToSba( error = IVAS_ERR_OK; move32(); + set32_fx( currentPanGains_fx, 0, MAX_OUTPUT_CHANNELS ); + ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); ismInput->previousPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->previousPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); @@ -7000,9 +7077,9 @@ static ivas_error renderIsmToSplitBinaural( } - FOR( i = 0; i < MAX_NUM_OBJECTS; ++i ) + FOR( i = 0; i < ismInput->base.inputBuffer.config.numChannels; ++i ) { - Scale_sig32( tmpProcessing[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ + Scale_sig32( tmpProcessing[i], ismInput->base.inputBuffer.config.numSamplesPerChannel, sub( Q11, exp ) ); /* Q11 */ } /* Render */ @@ -7014,7 +7091,7 @@ static ivas_error renderIsmToSplitBinaural( FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) { - Scale_sig32( tmpProcessing[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ + Scale_sig32( tmpProcessing[i], output_frame, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -7252,6 +7329,27 @@ static ivas_error renderActiveInputsIsm( return IVAS_ERR_OK; } +static void renderMonoStereoToBinaural( + const input_mc *mcInput, + IVAS_REND_AudioBuffer outAudio ) +{ + Word16 i; + IVAS_REND_AudioBuffer inAudio; + + push_wmops( "renderMonoStereoToBinaural" ); + inAudio = mcInput->base.inputBuffer; + + FOR( i = 0; i < inAudio.config.numChannels; ++i ) + { + renderBufferChannel_fx( inAudio, i, mcInput->panGains_fx[i], outAudio ); + } + + pop_wmops(); + + return; +} + + static ivas_error renderLfeToBinaural_fx( const input_mc *mcInput, const AUDIO_CONFIG outConfig, @@ -7309,7 +7407,7 @@ static ivas_error renderLfeToBinaural_fx( v_multc_fx( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); /* Qx - 1 */ /* Save remaining LFE samples of current frame for next frame */ - MVR2R_WORD32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); + Copy32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); r_shift = sub( sub( in_q, 1 ), out_q ); IF( r_shift != 0 ) @@ -7396,9 +7494,9 @@ static ivas_error renderMcToBinaural( { copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer_fx ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < mcInput->base.inputBuffer.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ + Scale_sig32( tmpRendBuffer_fx[i], mcInput->base.inputBuffer.config.numSamplesPerChannel, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ), @@ -7407,9 +7505,9 @@ static ivas_error renderMcToBinaural( return error; } - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < outAudio.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ + Scale_sig32( tmpRendBuffer_fx[i], outAudio.config.numSamplesPerChannel, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } } ELSE @@ -7519,9 +7617,9 @@ static ivas_error renderMcToBinauralRoom( { copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < mcInput->base.inputBuffer.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ + Scale_sig32( tmpRendBuffer[i], mcInput->base.inputBuffer.config.numSamplesPerChannel, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, @@ -7531,9 +7629,9 @@ static ivas_error renderMcToBinauralRoom( return error; } - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < outAudio.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ + Scale_sig32( tmpRendBuffer[i], outAudio.config.numSamplesPerChannel, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } } ELSE @@ -7876,9 +7974,9 @@ static ivas_error renderMcToSplitBinaural( /* perform rotation in source format to tmpRotBuffer */ pCombinedOrientationDataLocal = &combinedOrientationDataLocal; - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + FOR( i = 0; i < mcInput->base.inputBuffer.config.numChannels; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ + Scale_sig32( tmpRendBuffer[i], mcInput->base.inputBuffer.config.numSamplesPerChannel, sub( Q11, exp ) ); /* Q11 */ } /* Render */ IF( ( error = ivas_td_binaural_renderer_ext_fx( ( pos_idx == 0 ) ? &mcInput->tdRendWrapper : &mcInput->splitTdRendWrappers[pos_idx - 1], mcInput->base.inConfig, &mcInput->customLsInput, &pCombinedOrientationDataLocal, NULL, mcInput->hReverb, 0, /* Ism Audio Metadata Delay Sync in ms for External Renderer */ *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer, &exp ) ) != IVAS_ERR_OK ) @@ -7887,7 +7985,7 @@ static ivas_error renderMcToSplitBinaural( } FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ + Scale_sig32( tmpRendBuffer[i], mcInput->base.inputBuffer.config.numSamplesPerChannel, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } /* Copy rendered audio to tmp storage buffer. Copying directly to output would @@ -8005,6 +8103,14 @@ static ivas_error renderInputMc( renderMcToSba( mcInput, outAudio ); BREAK; case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: + test(); + IF( EQ_32( mcInput->base.inConfig, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( mcInput->base.inConfig, IVAS_AUDIO_CONFIG_STEREO ) ) + { + renderMonoStereoToBinaural( mcInput, outAudio ); + BREAK; + } + + /* not mono or stereo */ SWITCH( outConfig ) { case IVAS_AUDIO_CONFIG_BINAURAL: @@ -8979,8 +9085,10 @@ static ivas_error renderInputMasa( } copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); - Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ - Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + FOR( ch = 0; ch < inAudio.config.numChannels; ch++ ) + { + Scale_sig32( tmpBuffer_buff_fx[ch], inAudio.config.numSamplesPerChannel, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + } // scale_sig32( outAudio.data_fx, i_mult( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ), sub( Q11, *outAudio.pq_fact ) ); ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes, masaInput->base.ctx.pSplitRendWrapper, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural ); @@ -9004,9 +9112,9 @@ static ivas_error renderInputMasa( masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; move16(); } - FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + FOR( ch = 0; ch < inAudio.config.numChannels; ch++ ) { - Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + Scale_sig32( tmpBuffer_buff_fx[ch], inAudio.config.numSamplesPerChannel, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ } scale_sig32( outAudio.data_fx, i_mult( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ), sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ @@ -9031,8 +9139,10 @@ static ivas_error renderInputMasa( copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); - Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ - Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + FOR( ch = 0; ch < inAudio.config.numChannels; ch++ ) + { + Scale_sig32( tmpBuffer_buff_fx[ch], inAudio.config.numSamplesPerChannel, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + } scale_sig32( outAudio.data_fx, i_mult( outAudio.config.numChannels, outAudio.config.numSamplesPerChannel ), sub( Q11, *outAudio.pq_fact ) ); @@ -9800,15 +9910,13 @@ void IVAS_REND_Close( ivas_external_orientation_close_fx( &hIvasRend->hExternalOrientationData ); ivas_combined_orientation_close_fx( &hIvasRend->hCombinedOrientationData ); - /* Fastconv HRTF memories */ - ivas_binaural_hrtf_close_fx( &hIvasRend->hHrtfs.hHrtfFastConv ); /* Parametric binauralizer HRTF filters */ - ivas_HRTF_binary_close_fx( &( hIvasRend->hHrtfs.hHrtfTD ) ); + ivas_HRTF_td_binary_close_fx( &( hIvasRend->hHrtfs.hHrtfTD ) ); ivas_HRTF_CRend_binary_close_fx( &( hIvasRend->hHrtfs.hHrtfCrend ) ); ivas_HRTF_fastconv_binary_close_fx( &( hIvasRend->hHrtfs.hHrtfFastConv ) ); ivas_HRTF_parambin_binary_close_fx( &( hIvasRend->hHrtfs.hHrtfParambin ) ); - ivas_HRTF_statistics_close_fx( &( hIvasRend->hHrtfs.hHrtfStatistics ) ); + ivas_HRTF_statistics_binary_close_fx( &( hIvasRend->hHrtfs.hHrtfStatistics ) ); free( hIvasRend ); *phIvasRend = NULL; @@ -11001,24 +11109,15 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ) ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, shift ); move16(); } - Word16 num_channels_dir = hDirACRend->num_outputs_dir; - move16(); - - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) - { - num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; - move16(); - } - IF( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { - tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); /* Q(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + tmp) */ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp ); move16(); @@ -11040,7 +11139,7 @@ static void intermidiate_ext_dirac_render( move16(); IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); move16(); @@ -11054,7 +11153,7 @@ static void intermidiate_ext_dirac_render( move16(); } - IF( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len > 0 ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx ) { Word16 shift, norm1, norm2; Word32 tmp1, tmp2; @@ -11099,8 +11198,6 @@ static void intermidiate_ext_dirac_render( move16(); } } - hDirACRend->proto_frame_dec_f_q = sub( 31, hDirACRend->proto_frame_dec_f_q ); - move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) { @@ -11197,7 +11294,7 @@ static ivas_error printConfigInfo_rend( ) { ivas_error error; - Word8 config_str[50]; + Word8 config_str[200]; /*-----------------------------------------------------------------* * Print output audio configuration @@ -11231,7 +11328,7 @@ static ivas_error printConfigInfo_rend( EQ_16( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( hIvasRend->outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - fprintf( stdout, "Render framesize: %dms\n", i_mult( hIvasRend->num_subframes, 5 ) ); + fprintf( stdout, "Render framesize: %dms\n", i_mult( hIvasRend->num_subframes, BINAURAL_RENDERING_FRAME_SIZE_MS ) ); } return IVAS_ERR_OK; @@ -11248,7 +11345,7 @@ void IVAS_REND_PrintInputConfig( const IVAS_AUDIO_CONFIG inputConfig /* i : input audio configuration */ ) { - Word8 config_str[50]; + Word8 config_str[200]; get_channel_config( inputConfig, &config_str[0] ); fprintf( stdout, "Input configuration: %s\n", config_str ); diff --git a/lib_util/aeid_file_reader.c b/lib_util/aeid_file_reader.c index 6f877452e5c1021124bfeb16e88b1f91dc84d562..4433ced8de4b580336d1b76eaba2184f19935c0b 100644 --- a/lib_util/aeid_file_reader.c +++ b/lib_util/aeid_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/aeid_file_reader.h b/lib_util/aeid_file_reader.h index 55a141284c4f202bc7c9426e9036f2b6475a7d83..789b166f49e6536800a69df9aee14b3321a3aa8a 100644 --- a/lib_util/aeid_file_reader.h +++ b/lib_util/aeid_file_reader.h @@ -1,7 +1,7 @@ #pragma once /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 6b506e7edaeaaa4b559701d065c904e2e48d42a4..08572b883c62d28098c28d13d54beff7006daab9 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -59,6 +59,9 @@ #define INV_SQRT_8_OVER_5_Q29 424433728l /* 1.0f/INV_SQRT_8_OVER_5_Q29 */ #define INV_SQRT_45_OVER_32_Q29 452729280l /* 1.0f/SQRT_45_OVER_32_Q29 */ +#define MAX16B 32767 +#define MIN16B ( -32768 ) + /* -------------------------------- normalization conversion tables @@ -425,7 +428,7 @@ AMBI_CONVERT_ERROR renormalize_channels( Word64 tmp; tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); /* tmp = W_add( tmp, ONE_OVER_2_Q29); */ /* rounding up */ - outval = W_extract_l( W_shr( tmp, Q29 ) ); + outval = W_extract_l( W_shr( tmp, 29 ) ); minval = L_min( minval, outval ); maxval = L_min( maxval, outval ); outval = L_min( MAX16B, L_max( MIN16B, outval ) ); /* saturation */ diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index cbb50af3fb2f999074cf067aadbc7c959b821bb5..eb8d094f8416cca6893582c0a7d2e74c194ffb54 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -33,11 +33,10 @@ #ifndef AMBI_CONVERT_H #define AMBI_CONVERT_H -#include "options.h" +#include "common_api_types.h" #include "stl.h" -#include "cnst.h" -#define AMBI_MAX_FRAME_LENGTH 960 /* 20ms at 48 kHz Sampling rate */ +#define AMBI_MAX_FRAME_LENGTH IVAS_MAX_FRAME_SIZE /* = 960 == 20ms at 48 kHz Sampling rate */ #define AMBI_MAX_CHANNELS 16 typedef enum diff --git a/lib_util/audio_file_reader.c b/lib_util/audio_file_reader.c index 0b6e44660de1d29b008868b1d847522f052bc56a..f342c64c41474c94748e41fdf78dc7d8811d77cd 100644 --- a/lib_util/audio_file_reader.c +++ b/lib_util/audio_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/audio_file_reader.h b/lib_util/audio_file_reader.h index 571c1e765637e1cb30ac9afa9cb49b45127886b7..376b649b8b6c36d47e0caa661cfe3e5496c69d1b 100644 --- a/lib_util/audio_file_reader.h +++ b/lib_util/audio_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/audio_file_writer.c b/lib_util/audio_file_writer.c index eb93018341780d232df13483268f295577e21cae..e008aa88699f8a6910b64fabb899349505ce1a62 100644 --- a/lib_util/audio_file_writer.c +++ b/lib_util/audio_file_writer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/audio_file_writer.h b/lib_util/audio_file_writer.h index 2622992cecbbb4875a6aa5d7440492bc0d9ccb86..62c74f1a883d2d6b20e9f197e7e80b8878570896 100644 --- a/lib_util/audio_file_writer.h +++ b/lib_util/audio_file_writer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/bitstream_reader.c b/lib_util/bitstream_reader.c index 6d40260b56dc5b21d8834c16f6e988175d89892a..2a452abb6a70ec1b4d4c74b3a6308014ea8c51f5 100644 --- a/lib_util/bitstream_reader.c +++ b/lib_util/bitstream_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/bitstream_reader.h b/lib_util/bitstream_reader.h index fb6f9f9b9dac7304cd1bf029cdf2c2822991f62c..51159dd5b870d24b95ebf359a0e73f50be50fb76 100644 --- a/lib_util/bitstream_reader.h +++ b/lib_util/bitstream_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/bitstream_writer.c b/lib_util/bitstream_writer.c index bff9f461b15992ed3c953a83a19f2c22cc496ed6..13981bd0102637680a8ce589099000be602d309e 100644 --- a/lib_util/bitstream_writer.c +++ b/lib_util/bitstream_writer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/bitstream_writer.h b/lib_util/bitstream_writer.h index f3efd4ddf2ec85beea05af186ffa68cbed225b2f..0d7d4747251067e35473effbc933327b632698bb 100644 --- a/lib_util/bitstream_writer.h +++ b/lib_util/bitstream_writer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/cmdl_tools.c b/lib_util/cmdl_tools.c index 945bda07de0918d6784d1edfddfa415040029485..504228a7338761147bbba887c7c3b66e95f782b9 100644 --- a/lib_util/cmdl_tools.c +++ b/lib_util/cmdl_tools.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -226,3 +226,28 @@ bool isEmptyString( { return str[0] == '\0'; } + + +/*---------------------------------------------------------------------* + * strLength() + * + * Get the length of a string up to a maximum length. + * + * Equivalent to strnlen, which is not part of the C standard and only provided by POSIX. + * + *---------------------------------------------------------------------*/ + +int32_t strLength( + const char *str, + int32_t maxlen ) +{ + int32_t len; + + len = 0; + while ( len < maxlen && str[len] != '\0' ) + { + len++; + } + + return len; +} diff --git a/lib_util/cmdl_tools.h b/lib_util/cmdl_tools.h index 327acb93d0b1d528874de8ef018a36686379b778..605c06d07c937c85b94f755977fe325271c20107 100644 --- a/lib_util/cmdl_tools.h +++ b/lib_util/cmdl_tools.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -50,4 +50,6 @@ void clearString( char *str ); bool isEmptyString( const char *str ); +int32_t strLength( const char *str, int32_t maxlen ); + #endif /* CMDL_TOOLS_H */ diff --git a/lib_util/cmdln_parser.c b/lib_util/cmdln_parser.c index 1b9eb7a92899f1b62df0e925fc7f3882c2512012..6df8cacde7c72bf8842d02bc39f45dbf18800237 100644 --- a/lib_util/cmdln_parser.c +++ b/lib_util/cmdln_parser.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -36,19 +36,30 @@ #include #include #include +#include +#include -#define MAX_SUPPORTED_OPTS ( 1024 ) -#define MAX_OPTION_LENGTH ( 1024 ) +#define MAX_SUPPORTED_OPTS ( 1024 ) +#define MAX_OPTION_MATCH_LENGTH ( 30 ) +#define MAX_OPTION_LENGTH ( MAX_OPTION_MATCH_LENGTH + 2 ) typedef CmdLnParser_Option OptionProps; typedef struct { OptionProps props; - int8_t hasBeenParsed; + bool hasBeenParsed; } Option; -static int16_t validateNoDuplicateIds( +/* Error enum for internal use */ +typedef enum +{ + CMDLN_PARSER_ERR_OK = 0, + CMDLN_PARSER_ERR_FAILED_PARSING = -1, + CMDLN_PARSER_ERR_MISCONFIGURED = -2, +} CmdLnParserError; + +static CmdLnParserError validateNoDuplicateIds( const OptionProps *props, int32_t numOpts ) { @@ -59,121 +70,136 @@ static int16_t validateNoDuplicateIds( if ( props[i].id == props[j].id ) { fprintf( stderr, "[dev] Duplicate ID == %d between options %s and %s\n", props[i].id, props[i].match, props[j].match ); - return -1; + return CMDLN_PARSER_ERR_MISCONFIGURED; } } } - return 0; + return CMDLN_PARSER_ERR_OK; } -static int16_t validateOptionProps( +static CmdLnParserError validateOptionProps( OptionProps props ) { /* Check required properties */ if ( props.match == NULL ) { - /* TODO(sgi): Don't print out usage after this - props.match is used there */ - fprintf( stderr, "[dev] Option with ID == %d - missing required property \"match\"\n", props.id ); - return -1; + fprintf( stderr, "[dev] Option with ID %d - missing required property \"match\"\n", props.id ); + return CMDLN_PARSER_ERR_MISCONFIGURED; } if ( props.id == 0 ) { fprintf( stderr, "[dev] Invalid ID for option %s. ID == %d is reserved.\n", props.match, props.id ); - return -1; + return CMDLN_PARSER_ERR_MISCONFIGURED; } - return 0; + /* Check match string length */ + if ( strLength( props.match, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) + { + fprintf( stderr, "[dev] Option with ID %d - match string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); + return CMDLN_PARSER_ERR_MISCONFIGURED; + } + if ( props.matchShort != NULL && strLength( props.matchShort, MAX_OPTION_MATCH_LENGTH + 1 ) > MAX_OPTION_MATCH_LENGTH ) + { + fprintf( stderr, "[dev] Option with ID %d - matchShort string exceeds limit of %d characters.\n", props.id, MAX_OPTION_MATCH_LENGTH ); + return CMDLN_PARSER_ERR_MISCONFIGURED; + } + + return CMDLN_PARSER_ERR_OK; } /* Validate given OptionProps and use them to initialize array of Options */ -static int16_t initOpts( +static CmdLnParserError initOpts( const OptionProps *options, const int32_t numOpts, Option *opts ) { + CmdLnParserError error; + + if ( numOpts > MAX_SUPPORTED_OPTS ) + { + fprintf( stderr, "[dev] Number of defined options (%d) exceeds limit (%d).\n", numOpts, MAX_SUPPORTED_OPTS ); + return CMDLN_PARSER_ERR_MISCONFIGURED; + } + + /* Check for duplicate IDs */ + if ( ( error = validateNoDuplicateIds( options, numOpts ) ) != 0 ) + { + return error; + } + for ( int32_t i = 0; i < numOpts; ++i ) { - if ( validateOptionProps( options[i] ) != 0 ) + if ( ( error = validateOptionProps( options[i] ) ) != CMDLN_PARSER_ERR_OK ) { - return -1; + return error; } Option tmp = { - .hasBeenParsed = 0 + .hasBeenParsed = false }; tmp.props = options[i]; /* Cannot assign in aggregate initializer above - causes Visual Studio warning */ opts[i] = tmp; } - /* Check for duplicate IDs */ - if ( validateNoDuplicateIds( options, numOpts ) != 0 ) - { - return -1; - } - - return 0; -} - -static int8_t stringLooksLikeOption( - const char *str ) -{ - if ( ( str[0] == '-' ) && is_number( str ) == false ) - { - return 1; - } - return 0; } -static const char *stringToOptionName( +static bool stringLooksLikeOption( const char *str ) { - while ( ( *str == '-' ) && ( ( str[1] != '0' ) || ( str[1] != '1' ) ) ) + if ( ( str[0] == '-' ) && !is_number( str ) ) { - ++str; + return true; } - return str; + return false; } -static int8_t optionMatchesString( +static bool optionMatchesString( Option opt, const char *str ) { if ( !stringLooksLikeOption( str ) ) { - return 0; + return false; } - const char *optionName = stringToOptionName( str ); + if ( strLength( str, MAX_OPTION_LENGTH + 1 ) > MAX_OPTION_LENGTH ) + { + /* String longer than longest possible option - not a match */ + return false; + } - char optionName_to_upper[FILENAME_MAX]; - strncpy( optionName_to_upper, optionName, sizeof( optionName_to_upper ) - 1 ); - optionName_to_upper[sizeof( optionName_to_upper ) - 1] = '\0'; - to_upper( optionName_to_upper ); + char str_to_upper[MAX_OPTION_LENGTH + 1]; + snprintf( str_to_upper, sizeof( str_to_upper ), "%s", str ); + to_upper( str_to_upper ); - char match_to_upper[FILENAME_MAX]; - strncpy( match_to_upper, opt.props.match, sizeof( match_to_upper ) - 1 ); - optionName_to_upper[sizeof( match_to_upper ) - 1] = '\0'; + char match_to_upper[MAX_OPTION_LENGTH + 1]; + snprintf( match_to_upper, sizeof( match_to_upper ), "--%s", opt.props.match ); to_upper( match_to_upper ); + if ( strcmp( str_to_upper, match_to_upper ) == 0 ) + { + return true; + } - char matchShort_to_upper[FILENAME_MAX]; - strncpy( matchShort_to_upper, opt.props.matchShort, sizeof( matchShort_to_upper ) - 1 ); - optionName_to_upper[sizeof( matchShort_to_upper ) - 1] = '\0'; - to_upper( matchShort_to_upper ); - - if ( strncmp( optionName_to_upper, match_to_upper, MAX_OPTION_LENGTH ) == 0 || strncmp( optionName_to_upper, matchShort_to_upper, MAX_OPTION_LENGTH ) == 0 ) + if ( opt.props.matchShort != NULL ) { - return 1; + snprintf( match_to_upper, sizeof( match_to_upper ), "-%s", opt.props.matchShort ); + to_upper( match_to_upper ); + + if ( strcmp( str_to_upper, match_to_upper ) == 0 ) + { + return true; + } } - return 0; + return false; } -static int16_t parseOpts( +static CmdLnParserError parseOpts( int32_t argc, char **argv, Option *opts, @@ -202,8 +228,14 @@ static int16_t parseOpts( /* Check if already parsed */ if ( optToMatch->hasBeenParsed ) { - fprintf( stderr, "Duplicate option: %s (%s)\n", optToMatch->props.match, optToMatch->props.matchShort ); - return -1; + fprintf( stderr, "Duplicate option provided: --%s", optToMatch->props.match ); + if ( optToMatch->props.matchShort != NULL ) + { + fprintf( stderr, "/-%s", optToMatch->props.matchShort ); + } + fprintf( stderr, "\n" ); + + return CMDLN_PARSER_ERR_FAILED_PARSING; } break; @@ -216,8 +248,8 @@ static int16_t parseOpts( /* Invalid option */ if ( stringLooksLikeOption( argv[argIdx] ) ) { - fprintf( stderr, "Unknown option `%s`\n", stringToOptionName( argv[argIdx] ) ); - return -1; + fprintf( stderr, "Unknown option `%s`\n", argv[argIdx] ); + return CMDLN_PARSER_ERR_FAILED_PARSING; } /* Otherwise, value following current option. @@ -229,7 +261,7 @@ static int16_t parseOpts( else { fprintf( stderr, "Unexpected token `%s`\n", argv[argIdx] ); - return -1; + return CMDLN_PARSER_ERR_FAILED_PARSING; } } @@ -238,8 +270,11 @@ static int16_t parseOpts( { if ( currOpt != NULL ) { - parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ); - currOpt->hasBeenParsed = 1; + if ( parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ) != 0 ) + { + return CMDLN_PARSER_ERR_FAILED_PARSING; + } + currOpt->hasBeenParsed = true; } currOpt = nextOpt; @@ -253,11 +288,37 @@ static int16_t parseOpts( /* Parse last option */ if ( currOpt != NULL ) { - parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ); - currOpt->hasBeenParsed = 1; + if ( parseOption( currOpt->props.id, &argv[currOptIdx + 1], numValues, pOutputStruct ) != 0 ) + { + return CMDLN_PARSER_ERR_FAILED_PARSING; + } + currOpt->hasBeenParsed = true; } - return 0; + /* Check mandatory options */ + bool missingMandatory = false; + for ( int32_t optIdx = 0; optIdx < numOpts; ++optIdx ) + { + Option opt = opts[optIdx]; + + if ( opt.props.isMandatory && !opt.hasBeenParsed ) + { + fprintf( stderr, "Missing mandatory parameter: --%s", opt.props.match ); + if ( opt.props.matchShort != NULL ) + { + fprintf( stderr, "/-%s", opt.props.matchShort ); + } + fprintf( stderr, "\n" ); + + missingMandatory = true; + } + } + if ( missingMandatory ) + { + return CMDLN_PARSER_ERR_FAILED_PARSING; + } + + return CMDLN_PARSER_ERR_OK; } static const char *getBasename( @@ -281,19 +342,22 @@ static const char *getBasename( return path; } -static int32_t totalOptionNameLength( +static int32_t totalNumOptChars( const OptionProps opt ) { - return (int32_t) ( strlen( opt.match ) + strlen( opt.matchShort ) ); -} + int32_t len = (int32_t) strlen( opt.match ); -static void printWhitespace( - const int32_t n ) -{ - for ( int32_t i = 0; i < n; ++i ) + if ( opt.matchShort != NULL ) + { + len += (int32_t) strlen( opt.matchShort ); + } + + if ( opt.placeholder != NULL ) { - fprintf( stderr, " " ); + len += (int32_t) strlen( opt.placeholder ); } + + return len; } static void printOptDescriptionAligned( @@ -317,7 +381,7 @@ static void printOptDescriptionAligned( fprintf( stderr, "%c", *descPtr ); if ( *descPtr == '\n' ) { - printWhitespace( descriptionColumnIdx ); + fprintf( stderr, "%*s", descriptionColumnIdx, "" ); } ++descPtr; } @@ -325,41 +389,114 @@ static void printOptDescriptionAligned( return; } +static void printOptions( + const OptionProps *optionProps, + const int32_t numOptions, + const bool mandatory, + const int32_t maxNumOptChars ) +{ + const int32_t descriptionColumnIdx = maxNumOptChars + 11 /* Additional chars we will print in the options column */; + int32_t numOptChars; + + for ( int32_t i = 0; i < numOptions; ++i ) + { + OptionProps opt = optionProps[i]; + + if ( opt.isMandatory != mandatory ) + { + continue; + } + + numOptChars = totalNumOptChars( optionProps[i] ); + + fprintf( stderr, " --%s", opt.match ); + numOptChars += 4; + + if ( opt.matchShort != NULL ) + { + fprintf( stderr, ", -%s", opt.matchShort ); + numOptChars += 3; + } + + if ( opt.placeholder != NULL ) + { + fprintf( stderr, " %s", opt.placeholder ); + numOptChars += 1; + } + + if ( opt.description != NULL ) + { + /* Done printing options column, fill with whitespace until description column */ + fprintf( stderr, "%*s", descriptionColumnIdx - numOptChars, ": " ); + printOptDescriptionAligned( opt.description, descriptionColumnIdx ); + } + else + { + fprintf( stderr, "\n" ); + } + } +} + static void printUsage( const char *argv0, const OptionProps *optionProps, const int32_t numOptions ) { - fprintf( stderr, "\n" ); - fprintf( stderr, "Usage: %s [options]\n", getBasename( argv0 ) ); - fprintf( stderr, "\n" ); - fprintf( stderr, "Valid options:\n" ); - - /* Find option with longest name, used for pretty formatting */ - int32_t maxOptNameLength = 0; + int32_t numOptChars; + int32_t maxNumOptChars = 0; + bool hasMandatoryOptions = false; for ( int32_t i = 0; i < numOptions; ++i ) { - const int32_t optNameLength = totalOptionNameLength( optionProps[i] ); - if ( maxOptNameLength < optNameLength ) + /* Find option with most characters when printed, used for pretty formatting */ + numOptChars = totalNumOptChars( optionProps[i] ); + if ( maxNumOptChars < numOptChars ) { - maxOptNameLength = optNameLength; + maxNumOptChars = numOptChars; + } + + /* Check if mandatory parameters should be printed separately */ + if ( optionProps[i].isMandatory ) + { + hasMandatoryOptions = true; } } - const int32_t preDescriptionWhitespace = 8; - const int32_t leftColumnAdditionalChars = 7; + fprintf( stderr, "\n" ); + fprintf( stderr, "Usage: %s [options]", getBasename( argv0 ) ); for ( int32_t i = 0; i < numOptions; ++i ) { OptionProps opt = optionProps[i]; - const int32_t optNameLength = totalOptionNameLength( optionProps[i] ); - /* TODO(sgi): make matchShort optional */ - fprintf( stderr, " --%s, -%s", opt.match, opt.matchShort ); + if ( opt.isMandatory ) + { + if ( opt.matchShort != NULL ) + { + fprintf( stderr, " -%s", opt.matchShort ); + } + else + { + fprintf( stderr, " --%s", opt.match ); + } + + if ( opt.placeholder != NULL ) + { + fprintf( stderr, " %s", opt.placeholder ); + } + } + } - printWhitespace( maxOptNameLength - optNameLength + preDescriptionWhitespace ); - printOptDescriptionAligned( opt.description, maxOptNameLength + preDescriptionWhitespace + leftColumnAdditionalChars ); + fprintf( stderr, "\n\n" ); + + if ( hasMandatoryOptions ) + { + fprintf( stderr, "Mandatory parameters:\n---------------------\n" ); + printOptions( optionProps, numOptions, true, maxNumOptChars ); + fprintf( stderr, "\n" ); } + fprintf( stderr, "Options:\n--------\n" ); + printOptions( optionProps, numOptions, false, maxNumOptChars ); + return; } @@ -371,34 +508,64 @@ int16_t CmdLnParser_parseArgs( void *pOutputStruct, CmdLnParser_FnPtr_ParseOption parseOption ) { - assert( numOptions <= MAX_SUPPORTED_OPTS ); + CmdLnParserError error; /* Prepare option array */ Option opts[MAX_SUPPORTED_OPTS]; - if ( initOpts( optionProps, numOptions, opts ) != 0 ) + if ( ( error = initOpts( optionProps, numOptions, opts ) ) != CMDLN_PARSER_ERR_OK ) { goto fail; } /* Iterate over argv and parse */ - if ( parseOpts( argc, argv, opts, numOptions, pOutputStruct, parseOption ) != 0 ) + if ( ( error = parseOpts( argc, argv, opts, numOptions, pOutputStruct, parseOption ) ) != CMDLN_PARSER_ERR_OK ) { goto fail; } - return 0; - fail: - printUsage( argv[0], optionProps, numOptions ); - return -1; + switch ( error ) + { + case CMDLN_PARSER_ERR_OK: + break; + case CMDLN_PARSER_ERR_MISCONFIGURED: + fprintf( stderr, "CmdLnParser is misconfigured.\n" ); + break; + case CMDLN_PARSER_ERR_FAILED_PARSING: + printUsage( argv[0], optionProps, numOptions ); + break; + } + + return error; } -void CmdLnParser_printUsage( +int16_t CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions ) { + CmdLnParserError error; + + /* Re-use initOpts for validation only */ + Option opts[MAX_SUPPORTED_OPTS]; + if ( ( error = initOpts( options, numOptions, opts ) ) != CMDLN_PARSER_ERR_OK ) + { + goto fail; + } + printUsage( executableName, options, numOptions ); - return; +fail: + switch ( error ) + { + case CMDLN_PARSER_ERR_OK: + break; + case CMDLN_PARSER_ERR_MISCONFIGURED: + fprintf( stderr, "CmdLnParser is misconfigured.\n" ); + break; + case CMDLN_PARSER_ERR_FAILED_PARSING: + break; + } + + return error; } diff --git a/lib_util/cmdln_parser.h b/lib_util/cmdln_parser.h index 2627d556624dc0de59ca01a5f342d684d066d277..446831526a9e080a40ea864354b39523f98fd966 100644 --- a/lib_util/cmdln_parser.h +++ b/lib_util/cmdln_parser.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -38,17 +38,21 @@ typedef struct { - int32_t id; - const char *match; - const char *matchShort; - const char *description; + int32_t id; /* Unique ID for the option */ + const char *match; /* String to match, e.g. "input" here will match "--input" on CLI */ + + /* Struct members below are optional and can be omitted in option definition. If omitted, C will implicitly set them to 0. */ + const char *matchShort; /* Short version of the string to match, e.g. "i" here will match "-i" on CLI */ + const char *placeholder; /* If not NULL, this will follow the match string in the usage printout, e.g. "" here will print "--input " on CLI */ + const char *description; /* Description of the option for the usage printout. May contain '\n' for line breaks. */ + bool isMandatory; /* Parsing will fail if an option with `isMandatory == true` is not given */ } CmdLnParser_Option; /* Function for parsing option values into an output struct, to be implemented by the user */ -typedef void ( *CmdLnParser_FnPtr_ParseOption )( int32_t optionId, char **optionValues, int16_t numOptionValues, void *pOutputStruct ); +typedef int16_t ( *CmdLnParser_FnPtr_ParseOption )( int32_t optionId, char **optionValues, int16_t numOptionValues, void *pOutputStruct ); int16_t CmdLnParser_parseArgs( int32_t argc, char **argv, const CmdLnParser_Option *options, const int32_t numOptions, void *pOutputStruct, CmdLnParser_FnPtr_ParseOption parseOption ); -void CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions ); +int16_t CmdLnParser_printUsage( char *executableName, const CmdLnParser_Option *options, const int32_t numOptions ); #endif /* CMDLN_PARSER_H */ diff --git a/lib_util/evs_rtp_payload.c b/lib_util/evs_rtp_payload.c index 280ddb32391916df6d569af77ee059f8eb70516d..fef44d646afb8367e90ee5e6f5953fc9614bb26d 100644 --- a/lib_util/evs_rtp_payload.c +++ b/lib_util/evs_rtp_payload.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/evs_rtp_payload.h b/lib_util/evs_rtp_payload.h index f97d9b7a6f662d5aad6c45f96380316683837689..00f634574d49f84eff9428f7f88075512f2d9030 100644 --- a/lib_util/evs_rtp_payload.h +++ b/lib_util/evs_rtp_payload.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/g192.c b/lib_util/g192.c index 5a8ed10658bc67787e972b424c516d46214137b2..3779b417fa99f40a5cfb5a536aaf9574f82b91e1 100644 --- a/lib_util/g192.c +++ b/lib_util/g192.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/g192.h b/lib_util/g192.h index e6ad2b4ee9e6781c91e378df68bad36855e78374..93ba57c8e6cb478e468c7e3c9ad3b35373abc675 100644 --- a/lib_util/g192.h +++ b/lib_util/g192.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index db7d42d7c264e78ba1414281cd8416e0428a67ec..3742459f87722595da30c69cf2e24a944169f8b4 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -51,9 +51,9 @@ struct hrtfFileReader typedef struct ivas_hrtfs_file_header_t { char identifier[8]; - int32_t file_size; - int16_t nb_hrtf; - int32_t max_data_size; + Word32 file_size; + Word16 nb_hrtf; + Word32 max_data_size; } ivas_hrtfs_file_header_t; @@ -129,7 +129,7 @@ static ivas_error read_and_check_hrtf_binary_file_header( ivas_hrtfs_file_header_t *hrtf_file_header, FILE *f_hrtf ) { - int32_t file_size; + Word32 file_size; if ( hrtf_file_header == NULL || f_hrtf == NULL ) { @@ -146,7 +146,7 @@ static ivas_error read_and_check_hrtf_binary_file_header( file_size = ftell( f_hrtf ); fseek( f_hrtf, 0, SEEK_SET ); - if ( file_size < (int32_t) sizeof( ivas_hrtfs_file_header_t ) ) + if ( file_size < (Word32) sizeof( ivas_hrtfs_file_header_t ) ) { return IVAS_ERROR( IVAS_ERR_END_OF_FILE, "HRTF binary file not compliant (size of file header)" ); } @@ -179,8 +179,11 @@ static ivas_error read_and_check_hrtf_binary_file_header( static ivas_error check_hrtf_binary_header( ivas_hrtfs_header_t *hrtf_header ) { + if ( hrtf_header == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } /* Check the renderer type */ - if ( ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_MIXER_CONV ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_MIXER_CONV_ROOM ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_FASTCONV ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && ( hrtf_header->rend_type != HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) && @@ -227,7 +230,7 @@ static ivas_error read_hrtf_binary_header( /* Sampling Frequency (4 bytes) */ /* Raw data size (4 bytes) */ - if ( ( fread( &( hrtf_header->rend_type ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->input_cfg ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->frequency ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->data_size ), sizeof( int32_t ), 1, f_hrtf ) == 1 ) ) + if ( ( fread( &( hrtf_header->rend_type ), sizeof( Word32 ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->input_cfg ), sizeof( Word32 ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->frequency ), sizeof( Word32 ), 1, f_hrtf ) == 1 ) && ( fread( &( hrtf_header->data_size ), sizeof( Word32 ), 1, f_hrtf ) == 1 ) ) { return IVAS_ERR_OK; } @@ -293,13 +296,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( } fread( &modelITD->elevDim3, sizeof( Word16 ), 1, f_hrtf ); - modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &modelITD->elevKSeq_dyn_fx, ( modelITD->elevDim3 - 2 ) * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( Word16 ) ); if ( modelITD->elevKSeq_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), modelITD->elevDim3 - 2, f_hrtf ); for ( j = 0; j < modelITD->elevDim3 - 2; j++ ) { @@ -308,13 +311,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); fread( &modelITD->azimDim3, sizeof( Word16 ), 1, f_hrtf ); - modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + ivas_HRTF_binary_open_buffers_int32( &modelITD->azimKSeq_dyn_fx, ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word16 ) ); if ( modelITD->azimKSeq_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); for ( j = 0; j < ( modelITD->azimDim3 + 1 ) / 2 - 2; j++ ) { @@ -323,13 +326,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); - modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &modelITD->W_dyn_fx, tmp * sizeof( Word32 ) ); if ( modelITD->W_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) ); if ( v_tmp16 == NULL ) { @@ -345,13 +348,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); /* azimuth */ - modelITD->azimBsLen_dyn_fx = (Word16 *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &modelITD->azimBsLen_dyn_fx, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( modelITD->azimBsLen_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( modelITD->azimBsLen_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); - modelITD->azimBsStart_dyn_fx = (Word16 *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &modelITD->azimBsStart_dyn_fx, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( modelITD->azimBsStart_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -359,13 +362,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( modelITD->azimBsStart_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); - modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &modelITD->azimBsShape_dyn_fx, tmp * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) ); if ( modelITD->azimBsShape_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), tmp, f_hrtf ); for ( j = 0; j < tmp; j++ ) { @@ -376,13 +379,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( &modelITD->azimSegSamples, sizeof( Word16 ), 1, f_hrtf ); /* elevation */ - modelITD->elevBsLen_dyn_fx = (Word16 *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &modelITD->elevBsLen_dyn_fx, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( modelITD->elevBsLen_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( modelITD->elevBsLen_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); - modelITD->elevBsStart_dyn_fx = (Word16 *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &modelITD->elevBsStart_dyn_fx, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( modelITD->elevBsStart_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -390,7 +393,7 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( modelITD->elevBsStart_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); - modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &modelITD->elevBsShape_dyn_fx, tmp * sizeof( Word32 ) ); if ( modelITD->elevBsShape_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -401,7 +404,7 @@ static ivas_error TDREND_LoadBSplineBinaryITD( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), tmp, f_hrtf ); for ( j = 0; j < tmp; j++ ) { @@ -446,9 +449,9 @@ static ivas_error TDREND_LoadBSplineBinary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); HrFiltSet_p->latency_s_Q_fx = Q31 - factor_Q; - fread( &HrFiltSet_p->latency_s_fx, 1, sizeof( Word32 ), f_hrtf ); + fread( &HrFiltSet_p->latency_s_fx, sizeof( Word32 ), 1, f_hrtf ); model = &( HrFiltSet_p->ModelParams ); /* Set ROM flag for correct deallocation */ @@ -486,23 +489,23 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &model->K, sizeof( Word16 ), 1, f_hrtf ); fread( &model->elevDim3, sizeof( Word16 ), 1, f_hrtf ); - model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->elevKSeq_dyn_fx, ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word16 ) ); if ( model->elevKSeq_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), model->elevDim3 - 2, f_hrtf ); for ( j = 0; j < model->elevDim3 - 2; j++ ) { model->elevKSeq_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q22 - factor_Q ); } free( v_tmp16 ); - model->azimDim3_dyn = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ); - model->azim_start_idx_dyn = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ); - model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azimDim3_dyn, model->elevDim3 * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azim_start_idx_dyn, model->elevDim3 * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int32_ptr( &model->azimKSeq_fx, model->elevDim3 * sizeof( float * ) ); if ( model->azimDim3_dyn == NULL || model->azim_start_idx_dyn == NULL || model->azimKSeq_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -512,14 +515,14 @@ static ivas_error TDREND_LoadBSplineBinary( { fread( &model->azimDim3_dyn[i], sizeof( Word16 ), 1, f_hrtf ); fread( &model->azim_start_idx_dyn[i], sizeof( Word16 ), 1, f_hrtf ); - model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->azimKSeq_fx[i], ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word16 ) ); if ( model->azimKSeq_fx[i] == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); for ( j = 0; j < model->azimDim3_dyn[i] + 1; j++ ) { @@ -528,15 +531,14 @@ static ivas_error TDREND_LoadBSplineBinary( free( v_tmp16 ); } fread( &model->AlphaN, sizeof( Word16 ), 1, f_hrtf ); - - model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->AlphaL_dyn_fx, model->AlphaN * model->K * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( model->AlphaN * model->K * sizeof( Word16 ) ); if ( model->AlphaL_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); model->AlphaL_e = Q15 - factor_Q; // model->AlphaL_dyn_e = 1; /* force to 6 to be corrected */ @@ -547,7 +549,7 @@ static ivas_error TDREND_LoadBSplineBinary( { model->AlphaL_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q30 - factor_Q ); } - model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->AlphaR_dyn_fx, model->AlphaN * model->K * sizeof( Word32 ) ); if ( model->AlphaR_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -563,9 +565,9 @@ static ivas_error TDREND_LoadBSplineBinary( /* azimuth */ fread( &model->num_unique_azim_splines, sizeof( Word16 ), 1, f_hrtf ); - model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ); - model->azimBsShape_dyn_fx = (Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ); - model->azimSegSamples_dyn = (Word16 *) malloc( model->num_unique_azim_splines * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int32_ptr_const( &model->azimBsShape_fx, model->num_unique_azim_splines * sizeof( float * ) ); + ivas_HRTF_binary_open_buffers_int32_ptr( &model->azimBsShape_dyn_fx, model->num_unique_azim_splines * sizeof( float * ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azimSegSamples_dyn, model->num_unique_azim_splines * sizeof( Word16 ) ); if ( model->azimBsShape_fx == NULL || model->azimBsShape_dyn_fx == NULL || model->azimSegSamples_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -574,12 +576,12 @@ static ivas_error TDREND_LoadBSplineBinary( for ( i = 0; i < model->num_unique_azim_splines; i++ ) { fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); - model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->azimBsShape_dyn_fx[i], tmp * sizeof( Word32 ) ); if ( model->azimBsShape_dyn_fx[i] == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) ); if ( v_tmp16 == NULL ) { @@ -594,14 +596,13 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &model->azimSegSamples_dyn[i], sizeof( Word16 ), 1, f_hrtf ); free( v_tmp16 ); } - - model->azimShapeIdx_dyn = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azimShapeIdx_dyn, model->elevDim3 * sizeof( Word16 ) ); if ( model->azimShapeIdx_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( model->azimShapeIdx_dyn, sizeof( Word16 ), model->elevDim3, f_hrtf ); - model->azimShapeSampFactor_dyn = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azimShapeSampFactor_dyn, model->elevDim3 * sizeof( Word16 ) ); if ( model->azimShapeSampFactor_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -609,13 +610,13 @@ static ivas_error TDREND_LoadBSplineBinary( fread( model->azimShapeSampFactor_dyn, sizeof( Word16 ), model->elevDim3, f_hrtf ); /* elevation */ - model->elevBsLen_dyn = (Word16 *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &model->elevBsLen_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( model->elevBsLen_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } fread( model->elevBsLen_dyn, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); - model->elevBsStart_dyn = (Word16 *) malloc( HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); + ivas_HRTF_binary_open_buffers_int16( &model->elevBsStart_dyn, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( model->elevBsStart_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -624,13 +625,13 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) ); - model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->elevBsShape_dyn_fx, tmp * sizeof( Word32 ) ); if ( model->elevBsShape_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); fread( v_tmp16, sizeof( Word16 ), tmp, f_hrtf ); for ( j = 0; j < tmp; j++ ) { @@ -640,19 +641,19 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &model->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); - model->EL_dyn_fx = (Word32 *) malloc( model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->EL_dyn_fx, model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( Word32 ) ); if ( model->EL_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } - fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); model->EL_e = Q31 - factor_Q; model->ER_e = model->EL_e; fread( (Word32 *) model->EL_dyn_fx, sizeof( Word32 ), model->AlphaN * HRTF_MODEL_N_SECTIONS, f_hrtf ); - model->ER_dyn_fx = (Word32 *) malloc( model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &model->ER_dyn_fx, model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( Word32 ) ); if ( model->ER_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -682,8 +683,8 @@ static ivas_error TDREND_LoadBSplineBinary( HRTF_model_precalc( model ); HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; - HrFiltSet_p->ModelEval.hrfModL_fx = (Word32 *) malloc( model->K * sizeof( Word32 ) ); - HrFiltSet_p->ModelEval.hrfModR_fx = (Word32 *) malloc( model->K * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &HrFiltSet_p->ModelEval.hrfModL_fx, model->K * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &HrFiltSet_p->ModelEval.hrfModR_fx, model->K * sizeof( Word32 ) ); if ( HrFiltSet_p->ModelEval.hrfModL_fx == NULL || HrFiltSet_p->ModelEval.hrfModR_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -716,12 +717,12 @@ static ivas_error load_reverb_from_binary( bool is_reverb; ivas_error header_check_result; ivas_hrtfs_file_header_t hrtfs_file_header; - int16_t hrtf_id; + Word16 hrtf_id; ivas_hrtfs_header_t hrtf_header; - int32_t hrtf_data_size_max; + Word32 hrtf_data_size_max; char *hrtf_data; - int16_t lr_iac_len; - int16_t ind; + Word16 lr_iac_len; + Word16 ind; Word16 factorQ; Word16 tmp16; @@ -787,7 +788,7 @@ static ivas_error load_reverb_from_binary( if ( hrtf_header.frequency != sampleRate ) { free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF invalid sampling rate" ); + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } } } @@ -796,10 +797,9 @@ static ivas_error load_reverb_from_binary( if ( is_reverb ) { - hHrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( lr_iac_len * sizeof( Word32 ) ); - hHrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( lr_iac_len * sizeof( Word32 ) ); - hHrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( lr_iac_len * sizeof( Word32 ) ); - + ivas_HRTF_binary_open_buffers_int32( &hHrtfStatistics->average_energy_l_dyn, lr_iac_len * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &hHrtfStatistics->average_energy_r_dyn, lr_iac_len * sizeof( Word32 ) ); + ivas_HRTF_binary_open_buffers_int32( &hHrtfStatistics->inter_aural_coherence_dyn, lr_iac_len * sizeof( Word32 ) ); if ( hHrtfStatistics->average_energy_l_dyn == NULL || hHrtfStatistics->average_energy_r_dyn == NULL || hHrtfStatistics->inter_aural_coherence_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -836,12 +836,12 @@ static ivas_error load_reverb_from_binary( } /*---------------------------------------------------------------------* - * load_reverb_binary() + * load_HrtfStatistics_from_binary() * * Load HRTF binary data into the HRTF handle for TD and Crend renderers *---------------------------------------------------------------------*/ -ivas_error load_reverb_binary( +ivas_error load_HrtfStatistics_from_binary( IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle */ const Word32 sampleRate, /* i : sample rate */ const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ @@ -870,13 +870,13 @@ static ivas_error TDREND_MIX_LoadHRTF( IVAS_DEC_HRTF_TD_HANDLE HrFiltSet_p /* o : Loaded HR filter set */ ) { - int16_t tmp; + Word16 tmp; bool is_tdrend; ivas_error header_check_result; ivas_hrtfs_file_header_t hrtfs_file_header; - int16_t hrtf_id; + Word16 hrtf_id; ivas_hrtfs_header_t hrtf_header; - int32_t hrtf_data_size_max; + Word32 hrtf_data_size_max; char *hrtf_data; if ( f_hrtf == NULL ) @@ -891,7 +891,7 @@ static ivas_error TDREND_MIX_LoadHRTF( /* try if it is old format for BE tests*/ fseek( f_hrtf, 0, SEEK_SET ); - if ( fread( &tmp, 1, sizeof( int16_t ), f_hrtf ) == 0 ) + if ( fread( &tmp, sizeof( Word16 ), 1, f_hrtf ) == 0 ) { header_check_result = IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } @@ -954,7 +954,7 @@ static ivas_error TDREND_MIX_LoadHRTF( if ( hrtf_header.frequency != sampleRate ) { free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF invalid sampling rate" ); + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } } } @@ -963,7 +963,7 @@ static ivas_error TDREND_MIX_LoadHRTF( if ( is_tdrend ) { - if ( fread( &tmp, 1, sizeof( int16_t ), f_hrtf ) == 0 ) + if ( fread( &tmp, sizeof( Word16 ), 1, f_hrtf ) == 0 ) { return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" ); } @@ -996,7 +996,7 @@ static ivas_error TDREND_MIX_LoadHRTF( ivas_error load_TDrend_HRTF_binary( IVAS_DEC_HRTF_TD_HANDLE hHrtf, /* i/o: TD rend. HRTF handle */ - const int32_t sampleRate, /* i : sample rate */ + const Word32 sampleRate, /* i : sample rate */ const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ) { @@ -1010,7 +1010,6 @@ ivas_error load_TDrend_HRTF_binary( return TDREND_MIX_LoadHRTF( hrtfReader->file, sampleRate, hHrtf ); } - /*---------------------------------------------------------------------* * destroy_td_hrtf() * @@ -1021,61 +1020,9 @@ void destroy_td_hrtf( IVAS_DEC_HRTF_TD_HANDLE *hHrtf /* i/o: TD rend. HRTF handle */ ) { - int16_t i; - - if ( ( hHrtf == NULL ) || ( *hHrtf == NULL ) ) - { - return; - } - - if ( !( *hHrtf )->ModelParams.modelROM ) - { - if ( ( *hHrtf )->ModelParams.UseItdModel ) - { - free( ( *hHrtf )->ModelParamsITD.elevKSeq_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.azimKSeq_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.W_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.azimBsShape_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.elevBsShape_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.azimBsLen_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.azimBsStart_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.elevBsLen_dyn_fx ); - free( ( *hHrtf )->ModelParamsITD.elevBsStart_dyn_fx ); - } - free( ( *hHrtf )->ModelParams.elevKSeq_dyn_fx ); - free( ( *hHrtf )->ModelParams.azim_start_idx_dyn ); - free( ( *hHrtf )->ModelParams.azimDim3_dyn ); - free( ( *hHrtf )->ModelParams.AlphaL_dyn_fx ); - free( ( *hHrtf )->ModelParams.AlphaR_dyn_fx ); - free( ( *hHrtf )->ModelParams.azimSegSamples_dyn ); - - free( ( *hHrtf )->ModelParams.azimShapeIdx_dyn ); - free( ( *hHrtf )->ModelParams.azimShapeSampFactor_dyn ); - free( ( *hHrtf )->ModelParams.elevBsLen_dyn ); - free( ( *hHrtf )->ModelParams.elevBsStart_dyn ); - free( ( *hHrtf )->ModelParams.elevBsShape_dyn_fx ); - - for ( i = 0; i < ( *hHrtf )->ModelParams.num_unique_azim_splines; i++ ) - { - free( ( *hHrtf )->ModelParams.azimBsShape_dyn_fx[i] ); - } - free( ( *hHrtf )->ModelParams.azimBsShape_dyn_fx ); - - free( (void *) ( *hHrtf )->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - for ( i = 0; i < ( *hHrtf )->ModelParams.elevDim3; i++ ) - { - free( ( *hHrtf )->ModelParams.azimKSeq_fx[i] ); - } - free( ( *hHrtf )->ModelParams.azimKSeq_fx ); - - free( ( *hHrtf )->ModelParams.EL_dyn_fx ); - free( ( *hHrtf )->ModelParams.ER_dyn_fx ); - free( ( *hHrtf )->ModelEval.hrfModL_fx ); - free( ( *hHrtf )->ModelEval.hrfModR_fx ); - } + ivas_HRTF_td_binary_close_fx( hHrtf ); - ivas_HRTF_binary_close_fx( hHrtf ); return; } @@ -1147,7 +1094,7 @@ static ivas_error create_Crend_HRTF_from_rawdata( { for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - if ( ( error = ivas_HRTF_CRend_binary_open_buffers_int16( &( *hHRTF )->pIndex_frequency_max_dyn_fx[i][j], mem_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_HRTF_binary_open_buffers_int16( &( *hHRTF )->pIndex_frequency_max_dyn_fx[i][j], mem_size ) ) != IVAS_ERR_OK ) { return error; } @@ -1173,8 +1120,8 @@ static ivas_error create_Crend_HRTF_from_rawdata( /* pIndex_frequency_max_diffuse (the size depends on num_iterations_diffuse) */ for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - mem_size = ( *hHRTF )->num_iterations_diffuse[j] * sizeof( uint16_t ); - if ( ( error = ivas_HRTF_CRend_binary_open_buffers_int16( &( *hHRTF )->pIndex_frequency_max_diffuse_dyn_fx[j], mem_size ) ) != IVAS_ERR_OK ) + mem_size = ( *hHRTF )->num_iterations_diffuse[j] * sizeof( UWord16 ); + if ( ( error = ivas_HRTF_binary_open_buffers_int16( &( *hHRTF )->pIndex_frequency_max_diffuse_dyn_fx[j], mem_size ) ) != IVAS_ERR_OK ) { return error; } @@ -1186,7 +1133,7 @@ static ivas_error create_Crend_HRTF_from_rawdata( /* index_frequency_max_diffuse */ ( *hHRTF )->index_frequency_max_diffuse = *( (Word16 *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( uint16_t ); + hrtf_data_rptr += sizeof( UWord16 ); /* inv_diffuse_weight Q factor*/ ( *hHRTF )->factor_Q_inv_diffuse_weight = Q15 - *( (Word16 *) ( hrtf_data_rptr ) ); @@ -1217,7 +1164,7 @@ static ivas_error create_Crend_HRTF_from_rawdata( { for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - if ( ( error = ivas_HRTF_CRend_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_re_dyn_fx[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_HRTF_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_re_dyn_fx[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) { return error; } @@ -1244,7 +1191,7 @@ static ivas_error create_Crend_HRTF_from_rawdata( { for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - if ( ( error = ivas_HRTF_CRend_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_im_dyn_fx[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_HRTF_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_im_dyn_fx[i][j], mem_size_buf ) ) != IVAS_ERR_OK ) { return error; } @@ -1267,8 +1214,8 @@ static ivas_error create_Crend_HRTF_from_rawdata( } /* max_total_num_fsamp_per_iteration_diff */ - max_total_num_fsamp_per_iteration_diff = *( (uint32_t *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( uint32_t ); + max_total_num_fsamp_per_iteration_diff = *( (UWord32 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( UWord32 ); mem_size_buf = max_total_num_fsamp_per_iteration_diff * sizeof( Word16 ); @@ -1279,7 +1226,7 @@ static ivas_error create_Crend_HRTF_from_rawdata( /* coeff_diffuse_re : The size depends on pIndex_frequency_max_diffuse */ for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - if ( ( error = ivas_HRTF_CRend_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_diffuse_re_dyn_fx[j], mem_size_buf ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_HRTF_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_diffuse_re_dyn_fx[j], mem_size_buf ) ) != IVAS_ERR_OK ) { return error; } @@ -1303,7 +1250,7 @@ static ivas_error create_Crend_HRTF_from_rawdata( /* coeff_diffuse_im : The size depends on pIndex_frequency_max_diffuse */ for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { - if ( ( error = ivas_HRTF_CRend_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_diffuse_im_dyn_fx[j], mem_size_buf ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_HRTF_binary_open_buffers_int16( &( *hHRTF )->pOut_to_bin_diffuse_im_dyn_fx[j], mem_size_buf ) ) != IVAS_ERR_OK ) { return error; } @@ -1367,17 +1314,17 @@ static ivas_error create_fastconv_HRTF_from_rawdata( latency_s = *( (Word32 *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( Word32 ); - if ( BINAURAL_CONVBANDS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + if ( BINAURAL_CONVBANDS != *( (UWord16 *) ( hrtf_data_rptr ) ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (BINAURAL_CONVBANDS)" ); } - hrtf_data_rptr += sizeof( uint16_t ); + hrtf_data_rptr += sizeof( UWord16 ); - nbchan = *( (uint16_t *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( uint16_t ); + nbchan = *( (UWord16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( UWord16 ); - ntaps = *( (uint16_t *) ( hrtf_data_rptr ) ); - hrtf_data_rptr += sizeof( uint16_t ); + ntaps = *( (UWord16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( UWord16 ); ( *hHRTF )->ntaps = ntaps; ( *hHRTF )->FASTCONV_latency_s_Q_fx = Q31 - factorQ; @@ -1543,11 +1490,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( char *hrtf_data /* i : pointer to binary file */ ) { - int16_t i, j, k; + Word16 i, j, k; char *hrtf_data_rptr; - uint32_t data_size_tmp; + UWord32 data_size_tmp; Word16 factorQ; - int16_t *ptW16; + Word16 *ptW16; if ( hrtf_data == NULL ) { @@ -1557,30 +1504,30 @@ static ivas_error create_parambin_HRTF_from_rawdata( hrtf_data_rptr = hrtf_data; /* HRTF_SH_CHANNELS */ - if ( HRTF_SH_CHANNELS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + if ( HRTF_SH_CHANNELS != *( (UWord16 *) ( hrtf_data_rptr ) ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_SH_CHANNELS)" ); } - hrtf_data_rptr += sizeof( uint16_t ); + hrtf_data_rptr += sizeof( UWord16 ); /* HRTF_NUM_BINS */ - if ( HRTF_NUM_BINS != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + if ( HRTF_NUM_BINS != *( (UWord16 *) ( hrtf_data_rptr ) ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_NUM_BINS)" ); } - hrtf_data_rptr += sizeof( uint16_t ); + hrtf_data_rptr += sizeof( UWord16 ); /* HRTF */ /* Q factor*/ factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( Word16 ); - data_size_tmp = HRTF_NUM_BINS * sizeof( int16_t ); + data_size_tmp = HRTF_NUM_BINS * sizeof( Word16 ); for ( i = 0; i < BINAURAL_CHANNELS; i++ ) { for ( j = 0; j < HRTF_SH_CHANNELS; j++ ) { - ptW16 = (int16_t *) hrtf_data_rptr; + ptW16 = (Word16 *) hrtf_data_rptr; for ( k = 0; k < HRTF_NUM_BINS; k++ ) { @@ -1593,7 +1540,7 @@ static ivas_error create_parambin_HRTF_from_rawdata( { for ( j = 0; j < HRTF_SH_CHANNELS; j++ ) { - ptW16 = (int16_t *) hrtf_data_rptr; + ptW16 = (Word16 *) hrtf_data_rptr; for ( k = 0; k < HRTF_NUM_BINS; k++ ) { ( *hHRTF )->hrtfShCoeffsIm_fx[i][j][k] = shl_r( ptW16[k], Q14 - factorQ ); @@ -1603,44 +1550,44 @@ static ivas_error create_parambin_HRTF_from_rawdata( } /* Reverb Parameters */ - if ( CLDFB_NO_CHANNELS_MAX != *( (uint16_t *) ( hrtf_data_rptr ) ) ) + if ( CLDFB_NO_CHANNELS_MAX != *( (UWord16 *) ( hrtf_data_rptr ) ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (CLDFB_NO_CHANNELS_MAX)" ); } - hrtf_data_rptr += sizeof( uint16_t ); + hrtf_data_rptr += sizeof( UWord16 ); /* Q factor*/ factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( Word16 ); - ptW16 = (int16_t *) hrtf_data_rptr; + ptW16 = (Word16 *) hrtf_data_rptr; for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { ( *hHRTF )->parametricReverberationTimes_fx[j] = L_shl_r( L_deposit_l( ptW16[j] ), Q26 - factorQ ); } - hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ); /* Q factor*/ factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( Word16 ); - ptW16 = (int16_t *) hrtf_data_rptr; + ptW16 = (Word16 *) hrtf_data_rptr; for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { ( *hHRTF )->parametricReverberationEneCorrections_fx[j] = L_shl_r( L_deposit_l( ptW16[j] ), Q31 - factorQ ); } - hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ); /* Q factor*/ factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( Word16 ); - ptW16 = (int16_t *) hrtf_data_rptr; + ptW16 = (Word16 *) hrtf_data_rptr; for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { ( *hHRTF )->parametricEarlyPartEneCorrection_fx[j] = L_shl_r( L_deposit_l( ptW16[j] ), Q28 - factorQ ); } - hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( int16_t ); + hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ); return IVAS_ERR_OK; } @@ -1660,13 +1607,13 @@ ivas_error load_fastconv_HRTF_from_binary( ) { FILE *f_hrtf; - int32_t hrtf_data_size_max; + Word32 hrtf_data_size_max; char *hrtf_data; ivas_hrtfs_header_t hrtf_header; ivas_error header_check_result; ivas_hrtfs_file_header_t hrtfs_file_header; - int16_t hrtf_id; - int16_t asFastconv = 0; + Word16 hrtf_id; + Word16 asFastconv = 0; bool load = false; BINAURAL_INPUT_AUDIO_CONFIG hrtf_set_binaural_cfg; @@ -1723,7 +1670,7 @@ ivas_error load_fastconv_HRTF_from_binary( if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ { free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF invalid sampling rate" ); + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) @@ -1772,13 +1719,13 @@ ivas_error load_parambin_HRTF_from_binary( ) { FILE *f_hrtf; - int32_t hrtf_data_size_max; + Word32 hrtf_data_size_max; char *hrtf_data; ivas_hrtfs_header_t hrtf_header; ivas_error header_check_result; ivas_hrtfs_file_header_t hrtfs_file_header; - int16_t hrtf_id; - int16_t asParam = 0; + Word16 hrtf_id; + Word16 asParam = 0; if ( hrtfReader == NULL || hrtfReader->file == NULL ) { @@ -1823,7 +1770,7 @@ ivas_error load_parambin_HRTF_from_binary( if ( hrtf_header.frequency != 48000 ) /* note: Parametric renderer data are always stored at 48 kHz */ { free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF invalid sampling rate" ); + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) @@ -1870,18 +1817,18 @@ ivas_error load_Crend_HRTF_from_binary( const hrtfFileReader *hrtfReader, /* i : pointer to hrtfFileReader handle */ const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg, /* i : HRTF set audio config. */ - const int32_t sampleRate /* i : sample rate */ + const Word32 sampleRate /* i : sample rate */ ) { FILE *f_hrtf; - int32_t hrtf_data_size_max; + Word32 hrtf_data_size_max; char *hrtf_data; ivas_hrtfs_header_t hrtf_header; ivas_error header_check_result; ivas_hrtfs_file_header_t hrtfs_file_header; - int16_t hrtf_id; + Word16 hrtf_id; bool load = false; - int16_t asCrend = 0; + Word16 asCrend = 0; BINAURAL_INPUT_AUDIO_CONFIG hrtf_set_binaural_cfg; /* convert audio config. to HRTF binaural config */ @@ -1943,7 +1890,7 @@ ivas_error load_Crend_HRTF_from_binary( if ( hrtf_header.frequency != sampleRate ) { free( hrtf_data ); - return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF invalid sampling rate" ); + return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) @@ -1989,83 +1936,12 @@ void destroy_crend_hrtf( IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend /* i/o: Crend HRTF handle */ ) { - uint16_t i, j; - - test(); - if ( *hHrtfCrend != NULL && hHrtfCrend != NULL ) - { - for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) - { - for ( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - if ( ( *hHrtfCrend )->pIndex_frequency_max[i][j] != NULL ) - { - free( ( *hHrtfCrend )->pIndex_frequency_max_dyn_fx[i][j] ); - } - if ( ( *hHrtfCrend )->pOut_to_bin_re_fx[i][j] != NULL ) - { - free( ( *hHrtfCrend )->pOut_to_bin_re_dyn_fx[i][j] ); - } - if ( ( *hHrtfCrend )->pOut_to_bin_im_fx[i][j] != NULL ) - { - free( ( *hHrtfCrend )->pOut_to_bin_im_dyn_fx[i][j] ); - } - } - } - for ( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - if ( ( *hHrtfCrend )->pIndex_frequency_max_diffuse[j] != NULL ) - { - free( ( *hHrtfCrend )->pIndex_frequency_max_diffuse_dyn_fx[j] ); - } - if ( ( *hHrtfCrend )->pOut_to_bin_diffuse_re_fx[j] != NULL ) - { - free( ( *hHrtfCrend )->pOut_to_bin_diffuse_re_dyn_fx[j] ); - } - if ( ( *hHrtfCrend )->pOut_to_bin_diffuse_im_fx[j] != NULL ) - { - free( ( *hHrtfCrend )->pOut_to_bin_diffuse_im_dyn_fx[j] ); - } - } - free( *hHrtfCrend ); - *hHrtfCrend = NULL; - } + ivas_HRTF_CRend_binary_close_fx( hHrtfCrend ); return; } -/*---------------------------------------------------------------------* - * destroy_hrtf_statistics() - * - * Destroy the HRTF statistics set. - *---------------------------------------------------------------------*/ - -void destroy_hrtf_statistics( - IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle */ -) -{ - if ( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) ) - { - if ( ( *hHrtfStatistics )->average_energy_l_dyn != NULL ) - { - free( ( *hHrtfStatistics )->average_energy_l_dyn ); - } - if ( ( *hHrtfStatistics )->average_energy_r_dyn != NULL ) - { - free( ( *hHrtfStatistics )->average_energy_r_dyn ); - } - if ( ( *hHrtfStatistics )->inter_aural_coherence_dyn != NULL ) - { - free( ( *hHrtfStatistics )->inter_aural_coherence_dyn ); - } - } - - ivas_HRTF_statistics_close_fx( hHrtfStatistics ); - - return; -} - /*---------------------------------------------------------------------* * destroy_fastconv_hrtf() * @@ -2076,9 +1952,6 @@ void destroy_fastconv_hrtf( IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv /* i/o: FastConv HRTF handle */ ) { - /* Fastconv HRTF memories */ - ivas_binaural_hrtf_close_fx( hHrtfFastConv ); - /* Fastconv HRTF filters */ ivas_HRTF_fastconv_binary_close_fx( hHrtfFastConv ); @@ -2100,3 +1973,18 @@ void destroy_parambin_hrtf( return; } + +/*---------------------------------------------------------------------* + * destroy_hrtf_statistics() + * + * Destroy the HRTF statistics set. + *---------------------------------------------------------------------*/ + +void destroy_hrtf_statistics( + IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle */ +) +{ + ivas_HRTF_statistics_binary_close_fx( hHrtfStatistics ); + + return; +} diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index 105ee0ace97155bbff8e9e8273cc41e25bbb29c2..d404395e0b9dbdf105590f5c3ee2069e5eb24b77 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -56,7 +56,7 @@ 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_HOA3, /* HOA3 */ BINAURAL_INPUT_AUDIO_CONFIG_HOA2, /* HOA2 */ BINAURAL_INPUT_AUDIO_CONFIG_FOA, /* FOA */ BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED /* Not used */ @@ -106,25 +106,25 @@ ivas_error load_TDrend_HRTF_binary( ); /*---------------------------------------------------------------------* - * load_reverb_binary() + * load_HrtfStatistics_from_binary() * * Load reverb binary data into the HRTF handle *---------------------------------------------------------------------*/ -ivas_error load_reverb_binary( +ivas_error load_HrtfStatistics_from_binary( IVAS_DEC_HRTF_STATISTICS_HANDLE hHrtfStatistics, /* i/o: HRTF statistics handle */ const Word32 sampleRate, /* i : sample rate */ const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ ); /*---------------------------------------------------------------------* - * create_SetOfHRTF_from_binary() + * load_Crend_HRTF_from_binary() * - * Create the HRTF data set from the binary file + * Create the Crend HRTF data set from the binary file *---------------------------------------------------------------------*/ ivas_error load_Crend_HRTF_from_binary( - IVAS_DEC_HRTF_CREND_HANDLE hSetOfHRTF, /* i/o: Set of HRTF CRend handle */ + IVAS_DEC_HRTF_CREND_HANDLE hHrtfCrend, /* i/o: HRTF CRend handle */ const hrtfFileReader *hrtfReader, /* i : pointer to hrtfFileReader handle */ const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg, /* i : HRTF set audio config. */ @@ -134,11 +134,11 @@ ivas_error load_Crend_HRTF_from_binary( /*---------------------------------------------------------------------* * destroy_crend_hrtf() * - * Destroy the HRTF data set. + * Destroy the Crend HRTF data set *---------------------------------------------------------------------*/ void destroy_crend_hrtf( - IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF /* i/o: Set of HRTF CRend handle */ + IVAS_DEC_HRTF_CREND_HANDLE *hHrtfCrend /* i/o: Crend HRTF handle */ ); /*---------------------------------------------------------------------* @@ -174,17 +174,6 @@ ivas_error load_parambin_HRTF_from_binary( IVAS_DEC_HRTF_PARAMBIN_HANDLE hHrtfParambin, /* i/o: Parambin HRTF handle */ const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ); - -/*---------------------------------------------------------------------* - * destroy_hrtf_statistics() - * - * free memory allocated for HRTF statistics binary data - *---------------------------------------------------------------------*/ - -void destroy_hrtf_statistics( - IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle */ -); - /*---------------------------------------------------------------------* * destroy_parambin_hrtf() * @@ -205,4 +194,14 @@ void destroy_td_hrtf( IVAS_DEC_HRTF_TD_HANDLE *hHRTF /* i/o: TD rend. HRTF handle */ ); +/*---------------------------------------------------------------------* + * destroy_hrtf_statistics() + * + * free memory allocated for HRTF statistics binary data + *---------------------------------------------------------------------*/ + +void destroy_hrtf_statistics( + IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics /* i/o: HRTF statistics handle */ +); + #endif /* IVAS_HRTF_FILE_READER_H */ diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index d0caaa889fa26cecebe2af98608f171e161f44ba..ce4b6fd3b2d1c27b8dfbc91bcc21e5bd2066d2cd 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ism_file_reader.h b/lib_util/ism_file_reader.h index c785cc294bde7cbd4c37e9bfb76856f9b172f5c8..561eba40f4797202c731247d1c83a329fb520ae2 100644 --- a/lib_util/ism_file_reader.h +++ b/lib_util/ism_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ism_file_writer.c b/lib_util/ism_file_writer.c index ed098c601cb1a861f47eb7b9c9cbc8ffc0632334..acbd7ec59352d39b82b60c2fdbd12762554233c6 100644 --- a/lib_util/ism_file_writer.c +++ b/lib_util/ism_file_writer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ism_file_writer.h b/lib_util/ism_file_writer.h index 6bf1a3e3171dc2f63a598554a88415a3335d425b..dbebe1bad134b7689367876e4af035686bc37bfd 100644 --- a/lib_util/ism_file_writer.h +++ b/lib_util/ism_file_writer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_bpool.c b/lib_util/ivas_bpool.c index 9db909f535e17a2911ab7e809c3a27caaf277edd..0ba94528f2830f2c6db3742f6326b49c242d3b78 100644 --- a/lib_util/ivas_bpool.c +++ b/lib_util/ivas_bpool.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_bpool.h b/lib_util/ivas_bpool.h index 30cf4962b5198fd2a22a522061e8ce4cff2be915..06281b453614a1929371064d6c4264a5c904f984 100644 --- a/lib_util/ivas_bpool.h +++ b/lib_util/ivas_bpool.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_queue.c b/lib_util/ivas_queue.c index b17cf3e21a6e0222b439ba0826780dd031551670..7c8be93af9f73d4434f9f59676e282860cbd8c33 100644 --- a/lib_util/ivas_queue.c +++ b/lib_util/ivas_queue.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_queue.h b/lib_util/ivas_queue.h index 1c6b77504e501b6f0ec680839cd52f3f10b04ca8..a1df80035ee90a53d0b4c5f1b4890693c948ee50 100644 --- a/lib_util/ivas_queue.h +++ b/lib_util/ivas_queue.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_rtp_api.h b/lib_util/ivas_rtp_api.h index a697087ab63fe887c9106cb3f456584add4ab404..f196539fbbb22c65adabdc2e3b609f89a60a7f7d 100644 --- a/lib_util/ivas_rtp_api.h +++ b/lib_util/ivas_rtp_api.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_rtp_file.c b/lib_util/ivas_rtp_file.c index 26af1e2016a7937c9d13c69b3b7c2292e5e365ee..37d03a385e2474a9d169c638609fb80b2ce63c2e 100644 --- a/lib_util/ivas_rtp_file.c +++ b/lib_util/ivas_rtp_file.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -152,9 +152,9 @@ static const char *const PiDataNames[IVAS_PI_MAX_ID] = { }; void IVAS_RTP_LogPiData( - FILE *f_piDataOut, /* i/o : Output json file handle to dump PI data for debug/test */ - const PIDATA_TS *piData, /* i : PI Data + Timestamp array containing all PI data in current packet */ - uint32_t nPiDataPresent /* i : Number of valid elements in the piData array */ + FILE *f_piDataOut, /* i/o : Output json file handle to dump PI data for debug/test */ + const IVAS_PIDATA_TS *piData, /* i : PI Data + Timestamp array containing all PI data in current packet */ + uint32_t nPiDataPresent /* i : Number of valid elements in the piData array */ ) { uint16_t n; @@ -175,7 +175,7 @@ void IVAS_RTP_LogPiData( while ( nPiDataPresent-- > 0 ) { - const PIDATA_TS *cur = piData++; + const IVAS_PIDATA_TS *cur = piData++; if ( timestamp != ( ~0u ) && timestamp != cur->timestamp ) { @@ -510,10 +510,10 @@ void IVAS_RTP_LogPiData( } void IVAS_RTP_WriteExtPiData( - FILE *f_piDataOut, /* i/o : Output csv file handle to dump PI data for external output */ - const PIDATA_TS *piData, /* i : PI Data + Timestamp array containing all PI data in current packet */ - uint32_t nPiDataPresent, /* i : Number of valid elements in the piData array */ - uint16_t numObj /* i : Number of objects */ + FILE *f_piDataOut, /* i/o : Output csv file handle to dump PI data for external output */ + const IVAS_PIDATA_TS *piData, /* i : PI Data + Timestamp array containing all PI data in current packet */ + uint32_t nPiDataPresent, /* i : Number of valid elements in the piData array */ + uint16_t numObj /* i : Number of objects */ ) { if ( f_piDataOut == NULL || piData == NULL || nPiDataPresent == 0 ) @@ -525,7 +525,7 @@ void IVAS_RTP_WriteExtPiData( while ( nPiDataPresent-- > 0 ) { - const PIDATA_TS *cur = piData++; + const IVAS_PIDATA_TS *cur = piData++; /* The writing follows the pattern of: timestamp, PI DATA TYPE, PI DATA */ @@ -992,7 +992,7 @@ ivas_error IVAS_RTP_WriteNextFrame( while ( rtp->nWrittenPiData > 0 ) { - PIDATA_TS *piDataTs = &rtp->piData[nProcPiData++]; + IVAS_PIDATA_TS *piDataTs = &rtp->piData[nProcPiData++]; if ( ( error = IVAS_RTP_PACK_PushPiData( rtp->hPack, (const IVAS_PIDATA_GENERIC *) &piDataTs->data ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError %s while pushing scene orientation\n", ivas_error_to_string( error ) ); @@ -1063,7 +1063,7 @@ ivas_error IVAS_RTP_ReadNextFrame( /* Pre-read all PI data */ while ( rtp->numPiDataInPacket != 0 ) { - PIDATA_TS *piData = &rtp->piData[rtp->nReadPiData]; + IVAS_PIDATA_TS *piData = &rtp->piData[rtp->nReadPiData]; if ( ( error = IVAS_RTP_UNPACK_PullNextPiData( rtp->hUnpack, (IVAS_PIDATA_GENERIC *) &piData->data, sizeof( piData->data ), &piData->timestamp ) ) != IVAS_ERR_OK ) { fprintf( stderr, "failed to pull PI Data, error = %s\n", ivas_error_to_string( error ) ); diff --git a/lib_util/ivas_rtp_file.h b/lib_util/ivas_rtp_file.h index ce2cc183d08775460bac3bf62cfa6040372eb134..a3742c6c81ad277a5d96f851a7bf6e660279f017 100644 --- a/lib_util/ivas_rtp_file.h +++ b/lib_util/ivas_rtp_file.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -42,7 +42,7 @@ typedef struct IVAS_RTP_FILE *IVAS_RTP_FILE_HANDLE; typedef struct { uint8_t packet[NOMINAL_BUFFER_SIZE( IVAS_MAX_FRAMES_PER_RTP_PACKET )]; - PIDATA_TS piData[IVAS_PI_MAX_ID * IVAS_MAX_FRAMES_PER_RTP_PACKET]; + IVAS_PIDATA_TS piData[IVAS_PI_MAX_ID * IVAS_MAX_FRAMES_PER_RTP_PACKET]; IVAS_RTP_FILE_HANDLE hRtpFile; FILE *f_piDataOut; @@ -73,8 +73,8 @@ ivas_error IVAS_RTP_READER_Init( IVAS_RTP *rtp, const char *inputBitstreamFilena void IVAS_RTP_Term( IVAS_RTP *rtp ); ivas_error IVAS_RTP_WriteNextFrame( IVAS_RTP *rtp, uint8_t *au, const IVAS_RTP_SR_INFO *srInfo, int16_t auSizeBits, bool isMono, bool forcePacket ); ivas_error IVAS_RTP_ReadNextFrame( IVAS_RTP *rtp, uint8_t *au, int16_t *auSizeBits, uint32_t *rtpTimeStamp, uint16_t *rtpSequenceNumber, uint32_t *nextPacketRcvTime_ms, IVAS_RTP_SR_INFO *srInfo, bool *qBit ); -void IVAS_RTP_LogPiData( FILE *f_piDataOut, const PIDATA_TS *piData, uint32_t nPiDataPresent ); -void IVAS_RTP_WriteExtPiData( FILE *f_piDataOut, const PIDATA_TS *piData, uint32_t nPiDataPresent, uint16_t numObj ); +void IVAS_RTP_LogPiData( FILE *f_piDataOut, const IVAS_PIDATA_TS *piData, uint32_t nPiDataPresent ); +void IVAS_RTP_WriteExtPiData( FILE *f_piDataOut, const IVAS_PIDATA_TS *piData, uint32_t nPiDataPresent, uint16_t numObj ); const char *IVAS_RTP_GetExtPiFilePath( IVAS_RTP *rtp ); uint16_t IVAS_RTP_OwnRandom( uint16_t *seed ); diff --git a/lib_util/ivas_rtp_internal.h b/lib_util/ivas_rtp_internal.h index c373304a83dfde52a5488ed3ed60b68494f48a41..afa4c3c6010ecbe95c9641949cf9ec6b601df2b7 100644 --- a/lib_util/ivas_rtp_internal.h +++ b/lib_util/ivas_rtp_internal.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ivas_rtp_payload.c b/lib_util/ivas_rtp_payload.c index 28e58fa6758a2430095450dd56448c2af2335aaf..137c44119e9caeb85127be5bc74a75ab9124051c 100644 --- a/lib_util/ivas_rtp_payload.c +++ b/lib_util/ivas_rtp_payload.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -131,7 +131,7 @@ typedef struct typedef struct PIDATA_NODE { struct PIDATA_NODE *next; /* next node is first element */ - PIDATA data; /* unpacked pi data per frame */ + IVAS_PIDATA data; /* unpacked pi data per frame */ uint32_t timestamp; /* rtp timestamp of this frame */ } PIDATA_NODE; @@ -979,7 +979,7 @@ ivas_error IVAS_RTP_PACK_PushPiData( if ( data == NULL || data->piDataType >= IVAS_PI_NO_DATA || /* NO_PI_DATA cannot be provided by user, it is generated in packing */ - data->size > sizeof( PIDATA ) ) + data->size > sizeof( IVAS_PIDATA ) ) { return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Wrong PI Data provided" ); } diff --git a/lib_util/ivas_rtp_pi_data.c b/lib_util/ivas_rtp_pi_data.c index c353997324ee6c508d48c871e44fde9a1431fdc3..b533d07c284194e88202dce64512ac06c86575af 100644 --- a/lib_util/ivas_rtp_pi_data.c +++ b/lib_util/ivas_rtp_pi_data.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -41,11 +41,6 @@ #define min( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) #endif -#ifndef max -#define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) -#endif - - /* Generic PI data packing/unpacking functions */ typedef ivas_error ( *PACK_PI_FN )( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ); typedef ivas_error ( *UNPACK_PI_FN )( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ); @@ -62,6 +57,10 @@ static __inline int16_t readInt16( const uint8_t *buffer ) return (int16_t) ( (uint16_t) buffer[0] << 8 ) | ( (uint16_t) buffer[1] ); } +#define ONE_IN_Q22 4194304 +#define ONE_IN_Q26 67108864 +#define ONE_IN_Q30 1073741824 + /*-----------------------------------------------------------------------* * ivasPayload_convertToQ15() * @@ -502,7 +501,7 @@ static ivas_error unpackAcousticEnvironment( const uint8_t *buffer, uint32_t num aeEnv->roomDimensions.x_fx = (Word32) ( aeEnv->roomDimensions.x * ONE_IN_Q22 ); /* Q22 */ aeEnv->roomDimensions.y_fx = (Word32) ( aeEnv->roomDimensions.y * ONE_IN_Q22 ); aeEnv->roomDimensions.z_fx = (Word32) ( aeEnv->roomDimensions.z * ONE_IN_Q22 ); - aeEnv->roomDimensions.q_fact = Q22; + aeEnv->roomDimensions.q_fact = 22; aeEnv->absorbCoeffs_fx[IVAS_PI_AE_FRONT] = (Word32) ( aeEnv->absorbCoeffs[IVAS_PI_AE_FRONT] * ONE_IN_Q30 ); /* Q30 */ aeEnv->absorbCoeffs_fx[IVAS_PI_AE_BACK] = (Word32) ( aeEnv->absorbCoeffs[IVAS_PI_AE_BACK] * ONE_IN_Q30 ); @@ -1761,7 +1760,7 @@ ivas_error PI_UnPackData( uint8_t piDataType, uint32_t piSize, const uint8_t *pi return IVAS_ERR_OK; } -/* PIDATA Tables */ +/* IVAS_PIDATA Tables */ const float mapRT60[1u << NBITS_RT60] = { 0.01f, 0.0126f, 0.0159f, 0.02f, 0.0252f, 0.0317f, 0.04f, 0.0504f, 0.0635f, 0.08f, 0.1008f, 0.1270f, 0.16f, 0.2016f, 0.2540f, 0.32f, diff --git a/lib_util/ivas_rtp_pi_data.h b/lib_util/ivas_rtp_pi_data.h index 9cbedc6a170afa45b7fef9161eb05fa6153c7917..4f156a9defe729157620134f738e1c7ec0649d3c 100644 --- a/lib_util/ivas_rtp_pi_data.h +++ b/lib_util/ivas_rtp_pi_data.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -43,439 +43,5 @@ #define REVERSE_ISM_DIRECTION_AZIMUTH_STEP_INV 1.4222222222f #define REVERSE_ISM_DIRECTION_ELEVATION_STEP_INV 0.7055555556f -/* IVAS PI Data Types */ -typedef enum -{ - /* Forward direction PI types */ - IVAS_PI_SCENE_ORIENTATION, /* orientation of audio scene in unit quaternions */ - IVAS_PI_DEVICE_ORIENTATION_COMPENSATED, /* orientation of device in unit quaternions (compensated) */ - IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED, /* orientation of device in unit quaternions (un-compensated) */ - IVAS_PI_ACOUSTIC_ENVIRONMENT, /* describe the acoustic environment */ - IVAS_PI_AUDIO_DESCRIPTION, /* audio content description (voice/music/ambiance) */ - IVAS_PI_ISM_NUM, /* Number of objects */ - IVAS_PI_ISM_ID, /* id of each object */ - IVAS_PI_ISM_GAIN, /* gain of each object */ - IVAS_PI_ISM_ORIENTATION, /* orientation of each object */ - IVAS_PI_ISM_POSITION, /* position of each object */ - IVAS_PI_ISM_POSITION_COMPACT, /* position of each object in compact representation */ - IVAS_PI_ISM_DISTANCE_ATTENUATION, /* distance attenuation for each object */ - IVAS_PI_ISM_DIRECTIVITY, /* directivity of each object */ - IVAS_PI_DIEGETIC_TYPE, /* digetic audio indication */ - IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION, /* audio suppression indication */ - IVAS_PI_AUDIO_FOCUS_INDICATION, /* audio focus indication (direction in Quaternions and/or level) */ - /* Reverse direction PI types */ - IVAS_PI_PLAYBACK_DEVICE_ORIENTATION, /* orientation of the playback device in quaternions */ - IVAS_PI_HEAD_ORIENTATION, /* head orientation of the listener in Quaternions */ - IVAS_PI_LISTENER_POSITION, /* position of the listener in 3D space */ - IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_REQUEST, /* receiver’s preference with respect to audio suppression */ - IVAS_PI_AUDIO_FOCUS_REQUEST, /* direction of interest for the listener in Quaternions and/or audio focus level */ - IVAS_PI_PI_LATENCY, /* round-trip latency for PI frames */ - IVAS_PI_R_ISM_ID, /* id of an object for editing */ - IVAS_PI_R_ISM_GAIN, /* editing request for gain factor for received object */ - IVAS_PI_R_ISM_ORIENTATION, /* editing request for orientation for received object */ - IVAS_PI_R_ISM_POSITION, /* editing request for position for received object */ - IVAS_PI_R_ISM_POSITION_COMPACT, /* editing request for position for received object in a compact representation*/ - IVAS_PI_R_ISM_DIRECTION, /* editing request for direction for received object */ - IVAS_PI_RESERVED27, /* reserved */ - IVAS_PI_RESERVED28, /* reserved */ - IVAS_PI_RESERVED29, /* reserved */ - IVAS_PI_NO_DATA = 31, /* Indicates an empty PI data frame */ - IVAS_PI_MAX_ID /* Max number of PI data IDs supprted */ -} IVAS_PI_TYPE; - -/* cartesian coordinates (X,Y,Z) in 3D space */ -typedef struct -{ - float x, y, z; -} IVAS_COORDINATE; - -/* orientation data corresponding to any of the following pi data types :- - * - IVAS_PI_SCENE_ORIENTATION - * - IVAS_PI_DEVICE_ORIENTATION_COMPENSATED - * - IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED - * - IVAS_PI_PLAYBACK_DEVICE_ORIENTATION - * - IVAS_PI_HEAD_ORIENTATION - * - IVAS_PI_R_ISM_ORIENTATION - * - * piDataType is used to identify the correct pi data type contained here - */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_SCENE_ORIENTATION) */ - uint32_t piDataType; /* one of supported orientation data types */ - IVAS_QUATERNION orientation; /* orientation data expressed as quartenions */ -} IVAS_PIDATA_ORIENTATION; - -/* Acoustic environment corresponding to IVAS_PI_ACOUSTIC_ENVIRONMENT - * - * acoustic environment ID - * late reverb parameters - * - RT60 – indicating the time that it takes for the reflections to reduce 60 dB in energy level, per frequency band - * - DSR – diffuse to source signal energy ratio, per frequency band - * - Pre-delay – delay at which the computation of DSR values was performed - * early reflections - * - 3D rectangular virtual room dimensions - * - Broadband energy absorption coefficient per wall surface - */ -typedef enum -{ - IVAS_PI_AE_LOW, /* center frequency 25 Hz */ - IVAS_PI_AE_MID, /* center frequency 250 Hz */ - IVAS_PI_AE_HIGH, /* center frequency 2.5 kHz */ - IVAS_PI_AE_NUM_BANDS /* number of ae bands */ -} IVAS_PI_AE_BANDS; - -typedef enum -{ - IVAS_PI_AE_LOW_FREQ = 25, - IVAS_PI_AE_MID_FREQ = 250, - IVAS_PI_AE_HIGH_FREQ = 2500 -} IVAS_PI_AE_BANDS_FREQ; - -typedef enum -{ - IVAS_PI_AE_FRONT, - IVAS_PI_AE_BACK, - IVAS_PI_AE_LEFT, - IVAS_PI_AE_RIGHT, - IVAS_PI_AE_CEILING, - IVAS_PI_AE_FLOOR, - IVAS_PI_AE_NUM_SURFACE -} IVAS_PI_AE_SURFACE; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ACOUSTIC_ENV) */ - uint32_t piDataType; /* IVAS_PI_ACOUSTIC_ENVIRONMENT */ - bool availLateReverb; /* AE contains only late reverb parameters */ - bool availEarlyReflections; /* AE containing late reverb and simplified early reflections */ - uint8_t aeid; /* seven-bit acoustic environment identifier */ - - /* only valid if availLateReverb==true or availEarlyReflections==true */ - float rt60[IVAS_PI_AE_NUM_BANDS]; /* time for the reflections to reduce 60 dB per band in seconds */ - float dsr[IVAS_PI_AE_NUM_BANDS]; /* diffuse to source signal energy ratio per band in dB */ - Word32 rt60_fx[IVAS_PI_AE_NUM_BANDS]; /* Q26: time for the reflections to reduce 60 dB per band in seconds */ - Word32 dsr_fx[IVAS_PI_AE_NUM_BANDS]; /* Q30: diffuse to source signal energy ratio per band in dB */ - - /* only valid if availEarlyReflections==true */ - IVAS_VECTOR3 roomDimensions; /* room dimensions in meters length (x), width (y), height (z) */ - float absorbCoeffs[IVAS_PI_AE_NUM_SURFACE]; /* absorption coefficients for all surfaces */ - Word32 absorbCoeffs_fx[IVAS_PI_AE_NUM_SURFACE]; /* Q30: absorption coefficients for all surfaces */ -} IVAS_PIDATA_ACOUSTIC_ENV; - -/* Audio Description corresponding to IVAS_PI_AUDIO_DESCRIPTION - * Describe the following audio decriptors per object/type :- - * - audio content type is speech/music/ambiance - * - if audio rendering is editable - * - if stereo audio is binaural - * - * number of valid entries decide on basis of audio format:- - * - Stereo/SBA/MASA = 1 entry - * - MultiChannel = 2 entries (1 for center channel + 1 for all other channels) - * - ISM = Number of Object entries ( 1 per object ) - * - OMASA/OSBA = 1 + Num Discrete Coded Objects - * - */ -typedef struct -{ - bool speech; /* audio has voice/speech */ - bool music; /* audio has music */ - bool ambiance; /* audio has background ambiance */ - bool editable; /* rendering audio metadata is editable */ - bool binaural; /* stereo stream is binaural */ -} IVAS_AUDIO_ID; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_AUDIO_DESC) */ - uint32_t piDataType; /* IVAS_PI_AUDIO_DESCRIPTION */ - uint32_t nValidEntries; /* Number of valid audio IDs */ - IVAS_AUDIO_ID audioId[1 + IVAS_MAX_NUM_OBJECTS]; /* audio id as per format */ -} IVAS_PIDATA_AUDIO_DESC; - -/* ISM specific PI data related to PI types : - - * - * - IVAS_PI_ISM_NUM - * - IVAS_PI_ISM_ID - * - IVAS_PI_ISM_GAIN - * - IVAS_PI_ISM_ORIENTATION - * - IVAS_PI_ISM_POSITION - * - IVAS_PI_ISM_DISTANCE_ATTENUATION - * - IVAS_PI_ISM_DIRECTIVITY - */ - -/* Number of ISMs */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_NUM) */ - uint32_t piDataType; /* IVAS_PI_ISM_NUM */ - uint32_t numObjects; /* Number of ISM */ -} IVAS_PIDATA_ISM_NUM; - -/* ISM ID */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_ID) */ - uint32_t piDataType; /* IVAS_PI_ISM_ID */ - uint16_t numObjects; /* number of objects */ - uint8_t id[IVAS_MAX_NUM_OBJECTS]; /* 8-bit ISM id of object */ -} IVAS_PIDATA_ISM_ID; - -/* ISM gain */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_GAIN) */ - uint32_t piDataType; /* IVAS_PI_ISM_GAIN */ - uint16_t numObjects; /* number of objects */ - int8_t dB[IVAS_MAX_NUM_OBJECTS]; /* ISM gain in dB per object [-96, +3] */ -} IVAS_PIDATA_ISM_GAIN; - -/* ISM orientation */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_ORIENTATION) */ - uint32_t piDataType; /* IVAS_PI_ISM_ORIENTATION */ - uint16_t numObjects; /* number of objects */ - IVAS_QUATERNION orientation[IVAS_MAX_NUM_OBJECTS]; /* Orientation of audio objects in ISM(s) */ -} IVAS_PIDATA_ISM_ORIENTATION; - -/* ISM position */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_POSITION) */ - uint32_t piDataType; /* IVAS_PI_ISM_POSITION */ - uint16_t numObjects; /* number of objects */ - IVAS_COORDINATE position[IVAS_MAX_NUM_OBJECTS]; /* Position of audio objects in ISM(s) */ -} IVAS_PIDATA_ISM_POSITION; - -/* ISM distance attenuation comprising of following gains per ISM - * - reference distance - * - maximum distance - * - roll-off factor - */ -typedef struct -{ - float ref_dist; /* reference distance in meters */ - float max_dist; /* maximum distance in meters */ - float roll; /* roll-off factor values */ -} IVAS_DIST_ATTEN; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_ATTENUATION) */ - uint32_t piDataType; /* IVAS_PI_ISM_DISTANCE_ATTENUATION */ - uint16_t numObjects; /* number of objects */ - IVAS_DIST_ATTEN distAtten[IVAS_MAX_NUM_OBJECTS]; /* Distance attenuation of audio objects */ -} IVAS_PIDATA_ISM_ATTENUATION; - -/* ISM Directivity comprising of following per ISM :- - * - inner cone angle determines the size of the main cone directed to the front of the object - * - outer cone angle determines the size of the outer (back) cone - * - outer attenuation gain determines the attenuation outside the outer cone - */ -typedef struct -{ - uint16_t innerConeAngle; /* inner cone angle in degrees (0 - 360) */ - uint16_t outerConeAngle; /* outer cone angle in degrees (0 - 360) */ - float outerAttenuationdB; /* attenuation outside the outer cone in dB */ -} IVAS_ISM_DIRECTIVITY; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_DIRECTIVITY) */ - uint32_t piDataType; /* IVAS_PI_ISM_DIRECTIVITY */ - uint16_t numObjects; /* number of objects */ - IVAS_ISM_DIRECTIVITY directivity[IVAS_MAX_NUM_OBJECTS]; /* Directivity of audio objects */ -} IVAS_PIDATA_ISM_DIRECTIVITY; - -/* Diegetic and non-diegetic indication flag as per audio format - * - * number of valid entries decided on basis of audio format:- - * - Stereo/SBA/MASA/MultiChannel = 1 entry - * - ISM = Number of Object entries ( 1 per object ) - * - OMASA/OSBA = 1 (last) + Num Discrete Coded Objects - */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_DIEGETIC) */ - uint32_t piDataType; /* IVAS_PI_DIEGETIC_TYPE */ - bool isDiegetic[1 + IVAS_MAX_NUM_OBJECTS]; /* diegetic indication as per audio format */ -} IVAS_PIDATA_DIEGETIC; - -/* Audio focus direction indicates a direction of interest. - * The audio focus level indicates the amount of suppression applied to the - * directions other than the audio focus direction. - */ -typedef enum -{ - IVAS_FLVL_NO_AUDIO_FOCUS = 0, /* Apply no audio focus */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_1, /* Audio focus level 1 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_2, /* Audio focus level 2 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_3, /* Audio focus level 3 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_4, /* Audio focus level 4 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_5, /* Audio focus level 5 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_6, /* Audio focus level 6 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_7, /* Audio focus level 7 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_8, /* Audio focus level 8 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_9, /* Audio focus level 9 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_10, /* Audio focus level 10 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_11, /* Audio focus level 11 */ - IVAS_FLVL_FOCUS_LEVEL_LEVEL_12, /* Audio focus level 12 */ - IVAS_FLVL_MAX_AUDIO_FOCUS, /* Apply max audio focus */ - IVAS_FLVL_DEFAULT_AUDIO_FOCUS, /* Default audio focus */ - IVAS_FLVL_NO_PREFERENCE, /* No preference / No indication */ -} IVAS_FLVL; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_AUDIO_FOCUS) */ - uint32_t piDataType; /* IVAS_PI_AUDIO_FOCUS_INDCATION or IVAS_PI_AUDIO_FOCUS_REQUEST */ - bool availDirection; /* audio focus contains direction */ - bool availLevel; /* audio focus contains level */ - IVAS_QUATERNION direction; /* direction data expressed as quarternions */ - IVAS_FLVL flvl; /* audio focus level */ -} IVAS_PIDATA_AUDIO_FOCUS; - -/* Position data corresponding to any of the following pi data types :- - * - IVAS_PI_LISTENER_POSITION - * - IVAS_PI_R_ISM_POSITION - * - * piDataType is used to identify the correct pi data type contained here - */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_POSITION) */ - uint32_t piDataType; /* one of supported position data types */ - IVAS_COORDINATE position; /* Position data */ -} IVAS_PIDATA_POSITION; - -/* Dynamic Audio Suppression describes receiver’s preference with respect to the - * type of audio content that should be enhanced and the amount of suppression to - * be applied to the background noise - */ -typedef enum -{ - IVAS_SLI_MIN_SUPPRESSION = 0, /* Apply min suppression */ - IVAS_SLI_SUPPRESSION_LEVEL_1, /* Suppression level 1 */ - IVAS_SLI_SUPPRESSION_LEVEL_2, /* Suppression level 2 */ - IVAS_SLI_SUPPRESSION_LEVEL_3, /* Suppression level 3 */ - IVAS_SLI_SUPPRESSION_LEVEL_4, /* Suppression level 4 */ - IVAS_SLI_SUPPRESSION_LEVEL_5, /* Suppression level 5 */ - IVAS_SLI_SUPPRESSION_LEVEL_6, /* Suppression level 6 */ - IVAS_SLI_SUPPRESSION_LEVEL_7, /* Suppression level 7 */ - IVAS_SLI_SUPPRESSION_LEVEL_8, /* Suppression level 8 */ - IVAS_SLI_SUPPRESSION_LEVEL_9, /* Suppression level 9 */ - IVAS_SLI_SUPPRESSION_LEVEL_10, /* Suppression level 10 */ - IVAS_SLI_SUPPRESSION_LEVEL_11, /* Suppression level 11 */ - IVAS_SLI_MAX_SUPPRESSION, /* Apply max suppression */ - IVAS_SLI_NO_SUPPRESSION, /* Apply no suppression */ - IVAS_SLI_DEFAULT_SUPPRESSION, /* Apply default suppression */ - IVAS_SLI_NO_PREFERENCE, /* No preference / No indication */ -} IVAS_SLI; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_DYNAMIC_SUPPRESSION) */ - uint32_t piDataType; /* IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_REQUEST or IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION */ - bool speech; /* receiver's preference is voice/speech */ - bool music; /* receiver's preference is music */ - bool ambiance; /* receiver's preference is background ambiance */ - IVAS_SLI sli; /* suppression level indicator [0, 15] */ -} IVAS_PIDATA_DYNAMIC_SUPPRESSION; - -/* Reverse PI latency calculated as the elapsed time between the sent reverse PI data - * and received forward PI data. It is based on the receiving device experiencing the - * result of its sent data by receiving the corresponding data in forward direction as - * forward PI data - */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_REVERSE_PI_LATENCY) */ - uint32_t piDataType; /* IVAS_PI_PI_LATENCY */ - IVAS_PI_TYPE type; /* Reverse PI used for computation of Latency */ - int32_t latency; /* Latency as 27-bit int on RTP Clock @ 16KHz */ -} IVAS_PIDATA_REVERSE_PI_LATENCY; - -/* ISM specific PI data editing requests */ - -/* ISM ID in editing requests */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_ID) */ - uint32_t piDataType; /* IVAS_PI_R_ISM_ID */ - uint8_t id; /* 8-bit ISM id of object to edit */ -} IVAS_PIDATA_ISM_EDIT_ID; - -/* Editing request for ISM gain */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_GAIN) */ - uint32_t piDataType; /* IVAS_PI_R_ISM_GAIN */ - int8_t dB; /* Preferred ISM gain in dB [-96, +3] */ -} IVAS_PIDATA_ISM_EDIT_GAIN; - -/* Editing request for ISM orientation */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_ORIENTATION) */ - uint32_t piDataType; /* IVAS_PI_R_ISM_ORIENTATION */ - IVAS_QUATERNION orientation; /* orientation editing request for received ISM */ -} IVAS_PIDATA_ISM_EDIT_ORIENTATION; - -/* Editing request for ISM direction */ -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_ISM_EDIT_DIRECTION) */ - uint32_t piDataType; /* IVAS_PI_R_ISM_DIRECTION */ - float azimuth; /* azimuth angle in degrees [-180, 180] */ - float elevation; /* elevation angle in degrees [-90°, 90°] */ -} IVAS_PIDATA_ISM_EDIT_DIRECTION; - -typedef struct -{ - size_t size; /* sizeof(IVAS_PIDATA_NO_DATA) */ - uint32_t piDataType; /* IVAS_PI_NO_DATA */ -} IVAS_PIDATA_NO_DATA; - - -typedef union -{ - IVAS_PIDATA_ORIENTATION scene; - IVAS_PIDATA_ORIENTATION deviceCompensated; - IVAS_PIDATA_ORIENTATION deviceUnCompensated; - IVAS_PIDATA_ACOUSTIC_ENV acousticEnv; - IVAS_PIDATA_AUDIO_DESC audioDesc; - IVAS_PIDATA_ISM_NUM ismNum; - IVAS_PIDATA_ISM_ID ismId; - IVAS_PIDATA_ISM_GAIN ismGain; - IVAS_PIDATA_ISM_ORIENTATION ismOrientation; - IVAS_PIDATA_ISM_POSITION ismPosition; - IVAS_PIDATA_ISM_POSITION ismPositionCompact; - IVAS_PIDATA_ISM_ATTENUATION ismAttenuation; - IVAS_PIDATA_ISM_DIRECTIVITY ismDirectivity; - IVAS_PIDATA_DIEGETIC digeticIndicator; - IVAS_PIDATA_DYNAMIC_SUPPRESSION dynSuppressionIndication; - IVAS_PIDATA_AUDIO_FOCUS focusIndication; - - IVAS_PIDATA_ORIENTATION playbackOrientation; - IVAS_PIDATA_ORIENTATION headOrientation; - IVAS_PIDATA_POSITION listnerPosition; - IVAS_PIDATA_DYNAMIC_SUPPRESSION dynSuppressionRequest; - IVAS_PIDATA_AUDIO_FOCUS focusRequest; - IVAS_PIDATA_REVERSE_PI_LATENCY piLatency; - IVAS_PIDATA_ISM_EDIT_ID ismEditId; - IVAS_PIDATA_ISM_EDIT_GAIN ismEditGain; - IVAS_PIDATA_ISM_EDIT_ORIENTATION ismEditOrientation; - IVAS_PIDATA_POSITION ismEditPosition; - IVAS_PIDATA_POSITION ismEditPositionCompact; - IVAS_PIDATA_ISM_EDIT_DIRECTION ismEditDirection; - IVAS_PIDATA_NO_DATA noPiData; -} PIDATA; - -typedef struct pidata_ts_struct -{ - PIDATA data; - uint32_t timestamp; -} PIDATA_TS; #endif /* IVAS_RTP_PI_DATA_H */ diff --git a/lib_util/jbm_file_reader.c b/lib_util/jbm_file_reader.c index 68caf5ae73fc93637fbe3f08d7a4b1513bd284bc..556d8cd674dba3f13d9f19d4e7b8c14698c0f45b 100644 --- a/lib_util/jbm_file_reader.c +++ b/lib_util/jbm_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/jbm_file_reader.h b/lib_util/jbm_file_reader.h index e824e1eee9f00bbb821664a0515a69f1ce987d38..f6ecee961bfb746ed0d8aa51b9349ec7ca653239 100644 --- a/lib_util/jbm_file_reader.h +++ b/lib_util/jbm_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/jbm_file_writer.c b/lib_util/jbm_file_writer.c index 9d11dad90490e74e44a1f8afc25e70e8fc196493..da27b218cf434050d7d883c98ecac099155959e9 100644 --- a/lib_util/jbm_file_writer.c +++ b/lib_util/jbm_file_writer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/jbm_file_writer.h b/lib_util/jbm_file_writer.h index aca768a1a0e75c88dd01910bf00854cabc0dc2f2..7dd339ad31156f08a377c1c616f0627b00a3c386 100644 --- a/lib_util/jbm_file_writer.h +++ b/lib_util/jbm_file_writer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ls_custom_file_reader.c b/lib_util/ls_custom_file_reader.c index 5c1ac6ae041709cb0c7f84642afab48efc2a8c7f..38e76642bc54b5aa15329c4d25d1aa35288a4f02 100644 --- a/lib_util/ls_custom_file_reader.c +++ b/lib_util/ls_custom_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/ls_custom_file_reader.h b/lib_util/ls_custom_file_reader.h index 46b20a4ff013827acf56198b2b6f917952f21201..d5ead2841fcacb0a7dfb6842ee4d6b14ad30d66e 100644 --- a/lib_util/ls_custom_file_reader.h +++ b/lib_util/ls_custom_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index d782cdfd06d5ec6d6fd7005dba134ad11d3ee210..a7253ecd2d1db5a1b29bc4cd745849378415cca4 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/masa_file_reader.h b/lib_util/masa_file_reader.h index 7510598c3bf16a9690be159e7da3fd1187fc6d1d..d430a9194b8e7a86fa9385007faa10657050112e 100644 --- a/lib_util/masa_file_reader.h +++ b/lib_util/masa_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index a1c4d7054757b068aa1dec5e8a6e9da35c11ce29..371fb201e66660273fc9296b7a8138b6120ef995 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/masa_file_writer.h b/lib_util/masa_file_writer.h index 74d098388c0e5acf03f777d75d6868f496bf3c6e..c2d51d3945783d65ddc34102e17c5adff968d89b 100644 --- a/lib_util/masa_file_writer.h +++ b/lib_util/masa_file_writer.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/mime_io.c b/lib_util/mime_io.c index 3e837ca45df96aeaae64cd5f344f72578e048699..9b20aaeb5c0c9fcbbcc1a83ab577f1727d894080 100644 --- a/lib_util/mime_io.c +++ b/lib_util/mime_io.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/mime_io.h b/lib_util/mime_io.h index dbd21c9c79d2fd67d834b4e3364b0f714546bc36..d3b0d7a58b0e15bb7e241794be73adbdb8601b57 100644 --- a/lib_util/mime_io.h +++ b/lib_util/mime_io.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/mutex.h b/lib_util/mutex.h index 82094b61c823e909f22282f982413abe037489f6..64f5d2c58397152ef66437b7955410ac00679070 100644 --- a/lib_util/mutex.h +++ b/lib_util/mutex.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/obj_edit_file_reader.c b/lib_util/obj_edit_file_reader.c index 2d9a2fd6e084f7e07daa8feda60efe4bb8a4386b..22163d23dbc35a912cc0b51a2f6bb88074fa3bc8 100644 --- a/lib_util/obj_edit_file_reader.c +++ b/lib_util/obj_edit_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** -(C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, +(C) 2022-2026 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 @@ -33,9 +33,16 @@ the United Nations Convention on Contracts on the International Sales of Goods. #include #include #include "obj_edit_file_reader.h" -#include "prot_fx.h" +#ifndef min +#define min( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) +#endif + +#ifndef max +#define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) +#endif + /*-----------------------------------------------------------------------* * ObjectEditFileReader_open() * diff --git a/lib_util/obj_edit_file_reader.h b/lib_util/obj_edit_file_reader.h index 016425c2ec704caf45dfe0a794ec49291cd77f57..352202ef56a7865bd2eba33c67f9ac76a83a00e3 100644 --- a/lib_util/obj_edit_file_reader.h +++ b/lib_util/obj_edit_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** -(C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, +(C) 2022-2026 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 diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index 89fd65058725495b633e47079c60dc3c4943cca0..318072fe8566da06ff6755c612e8f231b09868ed 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -87,14 +87,6 @@ #define FALSE 0 #endif -#ifndef min -#define min( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) -#endif - -#ifndef max -#define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) -#endif - /*------------------------------------------------------------------------------------------* * Local Type definitions @@ -661,8 +653,14 @@ static ivas_error read_bin_code_word( /* First read minLen bits, then add one bit per iteration to find the correct value */ for ( n = 0; n < size; n++ ) { - minLen = min( minLen, pLengths[n] ); - maxLen = max( maxLen, pLengths[n] ); + if ( minLen < pLengths[n] ) + { + minLen = pLengths[n]; + } + if ( pLengths[n] > maxLen ) + { + maxLen = pLengths[n]; + } } for ( len = minLen; len <= maxLen; len++ ) { @@ -1266,9 +1264,6 @@ ivas_error RenderConfigReader_checkValues( pRoom_acoustics = &hRenderConfig->roomAcoustics; tab_value_err_count = 0; int16_t wall_idx; -#ifndef FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK - int16_t i; -#endif /* Verify the number of frequency bands in the config input data */ if ( ( pRoom_acoustics->nBands > N_BANDS_MAX ) || ( pRoom_acoustics->nBands < N_BANDS_MIN ) ) @@ -1341,21 +1336,6 @@ ivas_error RenderConfigReader_checkValues( pRoom_acoustics->AbsCoeff_fx[wall_idx] = ER_MAX_ABS_COEFF_FX; } } -#ifndef FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK - /* Verify range of distance attenuation parameters: 0.1 <= distAtt[0] <= distAtt[1] */ - /* 0.0 <= distAtt[2] <= 10.0 */ - hRenderConfig->distAtt[0] = max( 0.1f, hRenderConfig->distAtt[0] ); - hRenderConfig->distAtt[1] = max( hRenderConfig->distAtt[0], hRenderConfig->distAtt[1] ); - hRenderConfig->distAtt[2] = max( 0.0f, min( 10.0f, hRenderConfig->distAtt[2] ) ); - - /* Verify range of directivity patterns */ - for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) - { - hRenderConfig->directivity[i * 3] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * 3] ) ); - hRenderConfig->directivity[i * 3 + 1] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * 3 + 1] ) ); - hRenderConfig->directivity[i * 3 + 2] = max( 0.0f, min( 1.0f, hRenderConfig->directivity[i * 3 + 2] ) ); - } -#endif } @@ -1999,7 +1979,9 @@ ivas_error RenderConfigReader_read( pTemp = (char *) calloc( file_size + 1, sizeof( char ) ); acIdx = 0; roomAcHasFgCount = roomAcHasAcEnvCount = FALSE; +#ifdef _MSC_VER setvbuf( pRenderConfigReader->pConfigFile, pConfig_str, _IONBF, sizeof( char ) ); /* Work-around for VS bug that gives incorrect ftell for UNIX-style line endings */ +#endif /* read file line by line */ while ( fgets( pConfig_str, file_size, pRenderConfigReader->pConfigFile ) != NULL ) diff --git a/lib_util/render_config_reader.h b/lib_util/render_config_reader.h index 3a7ee101744b2c7b1e5ec1868c661dd65d0de41d..c533f1393eec98edbb92fb304757515f37b7a61b 100644 --- a/lib_util/render_config_reader.h +++ b/lib_util/render_config_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index 4385a9f831cb63e632620295e765060f6e67afd3..5530371b090f41232163ea275c94296668c4c540 100644 --- a/lib_util/rotation_file_reader.c +++ b/lib_util/rotation_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/rotation_file_reader.h b/lib_util/rotation_file_reader.h index 8d6206bd6331744bb16e22a24ba0205c0a4ac4ca..4cb9e5f6a7814289e92e6bdea2b9da2d98e2d8b8 100644 --- a/lib_util/rotation_file_reader.h +++ b/lib_util/rotation_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/rtpdump.c b/lib_util/rtpdump.c index 0b818ee193ba0df8be3742b12f691f57255a2f6e..df51a197290b3bb0c86cac70e4ba61e41492fdb4 100644 --- a/lib_util/rtpdump.c +++ b/lib_util/rtpdump.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/rtpdump.h b/lib_util/rtpdump.h index 366f95d57dc5432b806e88119e7639fb51ee1bbc..8ddfde7504d18da1bda83ba84845c5bf196dfafc 100644 --- a/lib_util/rtpdump.h +++ b/lib_util/rtpdump.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/split_rend_bfi_file_reader.c b/lib_util/split_rend_bfi_file_reader.c index 6a86738e026d04149cf714d2b5b99e830a883b83..ec9755019be9ea60b262d09150b1f0a70bded0db 100644 --- a/lib_util/split_rend_bfi_file_reader.c +++ b/lib_util/split_rend_bfi_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/split_rend_bfi_file_reader.h b/lib_util/split_rend_bfi_file_reader.h index 0956b6b3ddcecc0b8fd58f0f13a26b15b8e4c5a0..57e6294f8f93202b3ca56b37fe840801d8e367e5 100644 --- a/lib_util/split_rend_bfi_file_reader.h +++ b/lib_util/split_rend_bfi_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/split_render_file_read_write.c b/lib_util/split_render_file_read_write.c index 75fd30d88a9ecc824d43afdb13ed99122e9645cc..2fcc70dfb4b9edfd280f595d1d24f1ef251d0889 100644 --- a/lib_util/split_render_file_read_write.c +++ b/lib_util/split_render_file_read_write.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -71,18 +71,19 @@ ivas_error split_rend_reader_open( { SplitFileReadWrite *hSplitRendFileReadWrite; size_t header_len, h; + int32_t tmp; char header[SPLIT_RENDERER_FRAME_HEADER_LEN] = "MAIN_SPLITH"; char header_read[SPLIT_RENDERER_FRAME_HEADER_LEN]; if ( ( hSplitRendFileReadWrite = (SplitFileReadWrite *) malloc( sizeof( SplitFileReadWrite ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split rendering writer\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for split rendering reader\n" ) ); } hSplitRendFileReadWrite->file = fopen( filename, "rb" ); if ( hSplitRendFileReadWrite->file == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nCould not open split rend metadata file %s\n", filename ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nCould not open file %s\n", filename ) ); } header_len = strlen( header ); @@ -98,22 +99,25 @@ ivas_error split_rend_reader_open( if ( strncmp( header_read, header, header_len ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nError split rend bitstream main header mismatch\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "\nSplit rendering bitstream main header mismatch\n" ) ); } fread( &hSplitRendFileReadWrite->delay_ns, sizeof( uint32_t ), 1, hSplitRendFileReadWrite->file ); /* read codec signalling */ - if ( fread( codec, sizeof( *codec ), 1, hSplitRendFileReadWrite->file ) != 1 ) + if ( fread( &tmp, sizeof( int32_t ), 1, hSplitRendFileReadWrite->file ) != 1 ) { return IVAS_ERR_FAILED_FILE_READ; } + *codec = (ISAR_SPLIT_REND_CODEC) tmp; /* read pose correction signalling */ - if ( fread( poseCorrection, sizeof( *poseCorrection ), 1, hSplitRendFileReadWrite->file ) != 1 ) + if ( fread( &tmp, sizeof( int32_t ), 1, hSplitRendFileReadWrite->file ) != 1 ) { return IVAS_ERR_FAILED_FILE_READ; } + *poseCorrection = (ISAR_SPLIT_REND_POSE_CORRECTION_MODE) tmp; + /* read transport codec frame size signalling */ if ( fread( codec_frame_size_ms, sizeof( *codec_frame_size_ms ), 1, hSplitRendFileReadWrite->file ) != 1 ) { @@ -161,6 +165,7 @@ ivas_error split_rend_writer_open( { SplitFileReadWrite *hSplitRendFileReadWrite; size_t header_len, h; + int32_t tmp; char header[SPLIT_RENDERER_FRAME_HEADER_LEN] = "MAIN_SPLITH"; if ( filename == NULL ) @@ -193,13 +198,15 @@ ivas_error split_rend_writer_open( fwrite( &hSplitRendFileReadWrite->delay_ns, sizeof( int32_t ), 1, hSplitRendFileReadWrite->file ); /* Write codec signalling */ - if ( fwrite( &codec, sizeof( codec ), 1, hSplitRendFileReadWrite->file ) != 1 ) + tmp = (int32_t) codec; + if ( fwrite( &tmp, sizeof( int32_t ), 1, hSplitRendFileReadWrite->file ) != 1 ) { return IVAS_ERR_FAILED_FILE_WRITE; } /* Write pose correction signalling */ - if ( fwrite( &poseCorrection, sizeof( poseCorrection ), 1, hSplitRendFileReadWrite->file ) != 1 ) + tmp = (int32_t) poseCorrection; + if ( fwrite( &tmp, sizeof( int32_t ), 1, hSplitRendFileReadWrite->file ) != 1 ) { return IVAS_ERR_FAILED_FILE_WRITE; } diff --git a/lib_util/split_render_file_read_write.h b/lib_util/split_render_file_read_write.h index 0ea113e899d9cf0920c7978c52d11ebfbe1c536b..bfb0a191c58fbd882b58ea30006ba152d97af473 100644 --- a/lib_util/split_render_file_read_write.h +++ b/lib_util/split_render_file_read_write.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/tinywavein_c.h b/lib_util/tinywavein_c.h index 1ff6f26bb78438b2fbb835e483f99c1d46128dce..6e0e69beb978d509b37c96a68d5bb47b09e90d8b 100644 --- a/lib_util/tinywavein_c.h +++ b/lib_util/tinywavein_c.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/tinywaveout_c.h b/lib_util/tinywaveout_c.h index a3982ba19cdda311fea397ad5fb6b139c8d83c0e..bbb97c6030e63f8a17269dbc7026f81281351798 100644 --- a/lib_util/tinywaveout_c.h +++ b/lib_util/tinywaveout_c.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/lib_util/vector3_pair_file_reader.c b/lib_util/vector3_pair_file_reader.c index 737ef91af135e8ad834d85a2d66a1a8dea0c3e8b..27a21d21e8904a62acf01681ec8da719f0ab268d 100644 --- a/lib_util/vector3_pair_file_reader.c +++ b/lib_util/vector3_pair_file_reader.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -114,8 +114,13 @@ ivas_error Vector3PairFileReader_read( pSecond->y = y2; pSecond->z = z2; +#ifdef FIX_BASOP_2361_OTR + pFirst->q_fact = 27; // Q27 + pSecond->q_fact = 27; // Q27 +#else pFirst->q_fact = 29; // Q29 pSecond->q_fact = 29; // Q29 +#endif pFirst->x_fx = floatToFixed_32( pFirst->x, pFirst->q_fact ); pFirst->y_fx = floatToFixed_32( pFirst->y, pFirst->q_fact ); pFirst->z_fx = floatToFixed_32( pFirst->z, pFirst->q_fact ); diff --git a/lib_util/vector3_pair_file_reader.h b/lib_util/vector3_pair_file_reader.h index 6515d32d58f68c5088204f7fa1aae667ad3140cb..af4a6c99106098651008243cb530de84268c6411 100644 --- a/lib_util/vector3_pair_file_reader.h +++ b/lib_util/vector3_pair_file_reader.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 diff --git a/readme.txt b/readme.txt index f2c21eab2eb7b32769a4efef8ed9394c4af6c4ff..1db279fc514619aba5a4329975b173c138b3b537 100644 --- a/readme.txt +++ b/readme.txt @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2026 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 @@ -242,7 +242,7 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -dtx D : Activate DTX mode, D = (0, 3-100) is the SID update rate where 0 = adaptive, 3-100 = fixed in number of frames, default is deactivated -dtx : Activate DTX mode with a SID update rate of 8 frames - Note: DTX is supported in EVS, stereo, ISM, MASA, and SBA up to 80kbps + Note: DTX is supported on all bitrates for EVS, stereo, ISM, and MASA, and up to 80 kbps for SBA. -rf p o : Activate channel-aware mode in EVS for WB and SWB signal at 13.2kbps, where FEC indicator, p: LO or HI, and FEC offset, o: 2, 3, 5, or 7 in number of frames. Alternatively p and o can be replaced by a rf configuration file with each line @@ -385,16 +385,26 @@ Options: The usage of the "ISAR_post_rend" program is as follows: -------------------------------------------------------- -Usage: ISAR_post_rend [options] - -Options: --------- --i File : Input File (input file is bitstream if format is BINAURAL_SPLIT_CODED, or PCM/WAV file if format is BINAURAL_SPLIT_PCM) --if Format : Input Format of input (BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM) --im File : Coded metadata File for BINAURAL_SPLIT_PCM input format --o File : Output Audio File in BINAURAL format --fs : Input sampling rate in kHz (48) --prbfi File : BFI File +Usage: ISAR_post_rend [options] -i -if -o + +Mandatory parameters: +--------------------- +-i File : Path to the input File (WAV or raw PCM for BINAURAL_SPLIT_PCM format, or encoded intermediate-format data for BINAURAL_SPLIT_CODED format) +-if Format : Audio format of input File (BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM or RTPDUMP) +-o File : Path to the output File + +Options : +------- - +-im File : Path to the coded metadata File (mandatory for BINAURAL_SPLIT_PCM format) +-fs : Input sampling rate in kHz (16, 32, 48) (mandatory for raw PCM input Files) +-T File : Head rotation trajectory File for simulation of head tracking +-prbfi File : Split rendering BFI (Bad Frame Indicator) File +-no_delay_cmp : Turn off delay compensation +-q : Quiet mode - limit printouts to terminal +-l : List supported audio formats of input File +-fr L : Render frame size in ms L=(5, 10, 20), default is 20 +-s File : Path to the split rendering SDP init params File (mandatory for RTPDUMP format) +-h : Show this help message and exit The usage of the "ambi_converter" program is as follows: