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/.gitlab-ci.yml b/.gitlab-ci.yml index 93d77386ff2b53032f5171485c8c33fa6e81c9ff..3f84bc99fb90bf5910a3e37bd0986770bbac48c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,10 +2,16 @@ variables: # note: GitLab cannot reference variables defined by users in the include ref:, we need to use a YAML anchor for this # see https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include for more information IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF main + # If you need to set some config variable only in a local branch, then add an overwrite here + # One example is DISABLE_HRTF - this will be set on a branch which is about to be merged and will be removed in a subsequent second MR + # this is more easily done directly here in the child repo + # these lines are suposed to stay commented out to serve as an example + # # set this to true to skip the external HRTF testcases in pytest calls + # DISABLE_HRTF: "true" + +# all CI code and config is included from https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec-ci include: - project: ivas-codec-pc/ivas-codec-ci ref: *IVAS_CODEC_CI_REF file: main-basop.yml - - local: .gitlab-ci/variables.yml - - local: .gitlab-ci/rules-basis.yml diff --git a/.gitlab-ci/rules-basis.yml b/.gitlab-ci/rules-basis.yml deleted file mode 100644 index c650f574a59d41dc67aaa32f7250fcf73f906848..0000000000000000000000000000000000000000 --- a/.gitlab-ci/rules-basis.yml +++ /dev/null @@ -1,53 +0,0 @@ -# overwrites the default rules in the IVAS CI repository -# should be refactored and unified -.rules-basis: - rules: - # see https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines - - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push" - when: never - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - variables: - IVAS_PIPELINE_NAME: 'MR pipeline: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME' - ### disabled for now because pipeline cd is redundant with MR pipeline with current workflow - # - if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Pushes to main - # variables: - # IVAS_PIPELINE_NAME: 'Push pipeline: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'default' # for testing - variables: - IVAS_PIPELINE_NAME: 'Web run pipeline: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare' - variables: - IVAS_PIPELINE_NAME: 'Run comparison tools against float ref: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-enc-dmx' - variables: - IVAS_PIPELINE_NAME: 'Run encoder dmx comparison against float ref: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-long' - variables: - IVAS_PIPELINE_NAME: 'Run comparison tools against float ref (long test vectors): $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-compare-to-input' - variables: - IVAS_PIPELINE_NAME: 'Run comparison tools against input (pass-through only): $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-saturation-smoke-test' - variables: - IVAS_PIPELINE_NAME: 'Run saturation smoke-test: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'evs-26444' - variables: - IVAS_PIPELINE_NAME: 'EVS 26.444 test: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'sanitizer' - variables: - IVAS_PIPELINE_NAME: 'Short testvectors sanitizers' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'pytest-renderer' - variables: - IVAS_PIPELINE_NAME: 'Renderer test: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'complexity' - variables: - IVAS_PIPELINE_NAME: 'Complexity Measurement on $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'voip-be-test' - variables: - IVAS_PIPELINE_NAME: 'Voip BE test on $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'web' && $MANUAL_PIPELINE_TYPE == 'peaq-enc-passthrough' - variables: - IVAS_PIPELINE_NAME: 'PEAQ encoder pass-through test: $CI_COMMIT_BRANCH' - - if: $CI_PIPELINE_SOURCE == 'schedule' # Scheduled in any branch - variables: - IVAS_PIPELINE_NAME: 'Scheduled pipeline: $CI_COMMIT_BRANCH' diff --git a/.gitlab-ci/variables.yml b/.gitlab-ci/variables.yml deleted file mode 100644 index 817be6f79192020444bed06f80489de19fdd3cf1..0000000000000000000000000000000000000000 --- a/.gitlab-ci/variables.yml +++ /dev/null @@ -1,107 +0,0 @@ -variables: - TESTV_DIR: "/usr/local/testv" - LTV_DIR: "/usr/local/ltv" - EVS_BE_TEST_DIR_BASOP: "/usr/local/be_2_evs_basop" - # TODO: cleanup and use global var defined in ivas-codec-ci - FLOAT_REF_BRANCH: "ivas-float-update" - FLOAT_REF_BRANCH_MERGE_SOURCE: "" - BUILD_OUTPUT: "build_output.txt" - SCRIPTS_DIR: "/usr/local/scripts" - EXIT_CODE_NON_BE: 123 - EXIT_CODE_FAIL: 1 - LONG_TEST_SUITE: "tests/codec_be_on_mr_nonselection tests/renderer --param_file scripts/config/self_test_ltv.prm --use_ltv" - LONG_TEST_SUITE_NO_RENDERER: "tests/codec_be_on_mr_nonselection --param_file scripts/config/self_test_ltv.prm --use_ltv" - SHORT_TEST_SUITE: "tests/codec_be_on_mr_nonselection" - SHORT_TEST_SUITE_ENCODER: "tests/codec_be_on_mr_nonselection/test_param_file.py --param_file scripts/config/self_test_basop_encoder.prm" - LONG_TEST_SUITE_ENCODER: "tests/codec_be_on_mr_nonselection/test_param_file.py --param_file scripts/config/self_test_ltv_basop_encoder.prm" - TEST_SUITE: "" - # These path variables are used by the pytest calls. - # They can be overwritten in the job templates to e.g. only test encoder or decoder in the chain - DUT_ENCODER_PATH: "./IVAS_cod_dut" - DUT_DECODER_PATH: "./IVAS_dec_dut" - DUT_RENDERER_PATH: "./IVAS_rend_dut" - DUT_POST_RENDERER_PATH: "./ISAR_post_rend_dut" - REF_ENCODER_PATH: "./IVAS_cod_ref" - REF_DECODER_PATH: "./IVAS_dec_ref" - REF_RENDERER_PATH: "./IVAS_rend_ref" - REF_POST_RENDERER_PATH: "./ISAR_post_rend_ref" - MERGE_TARGET_ENCODER_PATH: "./IVAS_cod_merge_target" - MERGE_TARGET_DECODER_PATH: "./IVAS_dec_merge_target" - MERGE_TARGET_RENDERER_PATH: "./IVAS_rend_merge_target" - MERGE_TARGET_POST_RENDERER_PATH: "./ISAR_post_rend_merge_target" - MERGE_SOURCE_FLOAT_REF_ENCODER_PATH: "./IVAS_cod_merge_source_float_ref" - MERGE_SOURCE_FLOAT_REF_DECODER_PATH: "./IVAS_dec_merge_source_float_ref" - MERGE_SOURCE_FLOAT_REF_RENDERER_PATH: "./IVAS_rend_merge_source_float_ref" - MERGE_SOURCE_FLOAT_REF_POST_RENDERER_PATH: "./ISAR_post_rend_merge_source_float_ref" - # These path variables are used for building the binaries - # They should never be overwritten! - DUT_ENCODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_cod_dut" - DUT_DECODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_dec_dut" - DUT_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_rend_dut" - DUT_POST_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./ISAR_post_rend_dut" - REF_ENCODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_cod_ref" - REF_DECODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_dec_ref" - REF_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_rend_ref" - REF_POST_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./ISAR_post_rend_ref" - MERGE_TARGET_ENCODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_cod_merge_target" - MERGE_TARGET_DECODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_dec_merge_target" - MERGE_TARGET_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_rend_merge_target" - MERGE_TARGET_POST_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./ISAR_post_rend_merge_target" - MERGE_SOURCE_FLOAT_REF_ENCODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_cod_merge_source_float_ref" - MERGE_SOURCE_FLOAT_REF_DECODER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_dec_merge_source_float_ref" - MERGE_SOURCE_FLOAT_REF_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./IVAS_rend_merge_source_float_ref" - MERGE_SOURCE_FLOAT_REF_POST_RENDERER_PATH_FOR_BUILD_DO_NOT_MODIFY: "./ISAR_post_rend_merge_source_float_ref" - LEVEL_SCALING: "1.0" - IVAS_PIPELINE_NAME: '' - PRM_FILES: "scripts/config/self_test.prm scripts/config/self_test_ltv.prm" - TESTCASE_TIMEOUT_STV: 900 - TESTCASE_TIMEOUT_LTV: 2400 - TESTCASE_TIMEOUT_LTV_SANITIZERS: 10800 - CI_REGRESSION_THRESH_MLD: "0.1" - CI_REGRESSION_THRESH_MAX_ABS_DIFF: "50" - CI_REGRESSION_THRESH_SSNR: "-1" - CI_REGRESSION_THRESH_ODG: "-0.05" - GIT_CLEAN_FLAGS: -ffdxq - INSTR_DIR: "scripts/c-code_instrument" - TESTS_DIR_CODEC_BE_ON_MR: "tests/codec_be_on_mr_nonselection" - BUILD_WITH_DEBUG_MODE_INFO: "" - ENCODER_TEST: "" - DELTA_ODG: "" - COMPARE_DMX: "" - SPLIT_COMPARISON: "" - SKIP_REGRESSION_CHECK: "" - FAILED_TESTCASES_LIST: "failed-testcases.txt" - ERRORS_TESTCASES_LIST: "errors-testcases.txt" - PYTEST_CACHE_ARTIFACT: "pytest_cache.zip" - MEASURES_FOR_REPORT: "MLD MAX_ABS_DIFF MIN_SSNR MIN_ODG" - FLOAT_REF_COMMIT_FILE: "float-ref-git-sha.txt" - CUT_COMMIT_FILE: "CuT-git-sha.txt" - MERGE_TARGET_COMMIT_FILE: "merge-target-git-sha.txt" - MERGE_SOURCE_FLOAT_REF_COMMIT_FILE: "merge-source-float-ref-git-sha.txt" - RUNNER_TAG: "ivas-basop-linux" - LOGS_BACKUP_SOURCE_DIR: "" - LOGS_BACKUP_TARGET_DIR: "" - # set this to true to skip the external HRTF testcases in pytest calls - DISABLE_HRTF: "false" - MANUAL_PIPELINE_TYPE: - description: "Type for the manual pipeline run. Use 'pytest-compare' to run comparison test against reference float codec." - value: 'default' - options: - - 'default' - - 'pytest-compare' - - 'pytest-compare-enc-dmx' - - 'pytest-compare-long' - - 'pytest-compare-long-fx-fx' - - 'pytest-compare-to-input' - - 'pytest-saturation-smoke-test' - - 'evs-26444' - - 'sanitizer' - - 'pytest-renderer' - - 'complexity' - - 'coverage' - - 'voip-be-test' - - 'renderer-framesize-be' - - 'peaq-enc-passthrough' - - 'long-term-logs' - - 'backup-long-term-logs' - - 'test-long-self-test' diff --git a/.gitlab/merge_request_templates/default.md b/.gitlab/merge_request_templates/default.md new file mode 100644 index 0000000000000000000000000000000000000000..23540da70df8aba62bda4073a7c580bddaa61b61 --- /dev/null +++ b/.gitlab/merge_request_templates/default.md @@ -0,0 +1,25 @@ + +- Related issues: +- Requested reviewers: + +### Reason why this change is needed + +* This may be a direct copy from the issue. + +### Description of the change + +* Describe what is done. + +### Affected operating points + +* Describe here as well as possible what operating points are affected and how +* In minimum, there should be a status for bitstream compatibility and output bit exactness +* For bitstream compatibility, the following levels are helpful for describing encoder + 1. Produced bitstream is BE compared to previous state. + 2. Produced bitstream is non-BE but it is fully backwards compatible for decoding. Decoded output may differ. + 3. Produced bitstream is non-BC. Old decoder cannot decode the produced bitstream correctly. +* For output difference, use BE or non-BE. Additionally, amount of difference can be presented. + + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index e975df2b90ac2707b861ba105e40ad57d93c17b3..9cb79ae4645011cc932e5180c8e2ef1d5477e292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -201,6 +201,12 @@ if(WIN32) target_link_libraries(IVAS_cod Ws2_32) endif() +add_executable(IVAS_cod_fmtsw apps/encoder_fmtsw.c) +target_link_libraries(IVAS_cod_fmtsw lib_enc lib_util) +if(WIN32) + target_link_libraries(IVAS_cod_fmtsw Ws2_32) +endif() + add_executable(IVAS_dec apps/decoder.c) target_link_libraries(IVAS_dec lib_dec lib_util) if(WIN32) @@ -225,6 +231,7 @@ target_include_directories(ambi_converter PRIVATE lib_basop lib_util lib_com lib if(COPY_EXECUTABLES_FROM_BUILD_DIR) # Optionally copy executables to the same place where Make puts them (useful for tests that expect executables in specific places) add_custom_command(TARGET IVAS_cod POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") + add_custom_command(TARGET IVAS_cod_fmtsw POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") add_custom_command(TARGET IVAS_dec POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") add_custom_command(TARGET IVAS_rend POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") add_custom_command(TARGET ISAR_post_rend POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") 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/Makefile b/Makefile index 3edbe9ca7bedc8be8fe197a4935c0005523eeff7..c9ae4493ddacc2edbd9bdbe7c874b7d48a768b75 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ SRC_DIRS = $(sort -u $(SRC_LIBBASOP) $(SRC_LIBCOM) $(SRC_LIBDEBUG) $(SRC_LIBDEC # Name of CLI binaries CLI_APIDEC ?= IVAS_dec CLI_APIENC ?= IVAS_cod +CLI_APIENC_FMTSW ?= IVAS_cod_fmtsw CLI_APIREND ?= IVAS_rend CLI_APIPOSTREND ?= ISAR_post_rend CLI_AMBICONVERT ?= ambi_converter @@ -75,6 +76,9 @@ LDLIBS += -lm # Clang sanitizer compiler options CCCLANG = clang +ifeq "$(CLANG)" "0" +CC = $(CCCLANG) +endif ifeq "$(CLANG)" "1" CC = $(CCCLANG) CFLAGS += -fsanitize=memory @@ -169,6 +173,7 @@ OBJS_LIBUTIL = $(addprefix $(OBJDIR)/,$(SRCS_LIBUTIL:.c=.o)) OBJS_AMBICONVERT = $(OBJDIR)/ambi_convert.o OBJS_CLI_APIDEC = $(OBJDIR)/decoder.o OBJS_CLI_APIENC = $(OBJDIR)/encoder.o +OBJS_CLI_APIENC_FMTSW = $(OBJDIR)/encoder_fmtsw.o OBJS_CLI_APPREND = $(OBJDIR)/renderer.o OBJS_CLI_APPPOSTREND = $(OBJDIR)/isar_post_rend.o OBJS_CLI_AMBICONVERT = $(OBJDIR)/ambi_converter.o @@ -181,7 +186,7 @@ DEPS = $(addprefix $(OBJDIR)/,$(SRCS_LIBBASOP:.c=.P) $(SRCS_LIBCOM:.c=.P) $(SRCS .PHONY: all clean -all: $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) +all: $(CLI_APIENC) $(CLI_APIENC_FMTSW) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(OBJDIR): $(QUIET)mkdir -p $(OBJDIR) @@ -217,6 +222,9 @@ $(LIB_LIBUTIL): $(OBJS_LIBUTIL) $(OBJS_LIBBASOP) $(OBJS_LIBCOM) $(CLI_APIENC): $(OBJS_CLI_APIENC) $(LIB_LIBBASOP) $(LIB_LIBENC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIENC) -L. -livasbasop -livasenc -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIENC) +$(CLI_APIENC_FMTSW): $(OBJS_CLI_APIENC_FMTSW) $(LIB_LIBBASOP) $(LIB_LIBENC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) + $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIENC_FMTSW) -L. -livasbasop -livasenc -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIENC_FMTSW) + $(CLI_APIDEC): $(OBJS_CLI_APIDEC) $(LIB_LIBBASOP) $(LIB_LIBDEC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) $(LIB_LIBISAR) $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIDEC) -L. -livasbasop -livasdec -livascom -livasutil -livasdebug -llc3plus $(LDLIBS) -o $(CLI_APIDEC) @@ -235,7 +243,7 @@ clean: $(QUIET)$(RM) $(OBJS_LIBENC) $(OBJS_LIBDEC) $(DEPS) $(QUIET)$(RM) $(DEPS:.P=.d) $(QUIET)test ! -d $(OBJDIR) || rm -rf $(OBJDIR) - $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(OBJS_LIBBASOP) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) + $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIENC_FMTSW) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(OBJS_LIBBASOP) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(OBJDIR)/%.o : %.c | $(OBJDIR) $(QUIET_CC)$(CC) $(CFLAGS) -c -MD -o $@ $< diff --git a/Workspace_msvc/Workspace_msvc.sln b/Workspace_msvc/Workspace_msvc.sln index abb9650fc7d5dda70bc0f21d8faaa5ae3b27526a..c9c1f0fde7302be2a5d9c0785a12d133320c85e5 100644 --- a/Workspace_msvc/Workspace_msvc.sln +++ b/Workspace_msvc/Workspace_msvc.sln @@ -24,6 +24,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encoder", "encoder.vcxproj" {63747FE7-94BA-410C-8D7F-EB47555DD994} = {63747FE7-94BA-410C-8D7F-EB47555DD994} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encoder_fmtsw", "encoder_fmtsw.vcxproj", "{CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}" + ProjectSection(ProjectDependencies) = postProject + {63747FE7-94BA-410C-8D7F-EB47555DD994} = {63747FE7-94BA-410C-8D7F-EB47555DD994} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "renderer", "renderer.vcxproj", "{12B4C8A5-1E06-4E30-B443-D1F916F52B47}" ProjectSection(ProjectDependencies) = postProject {63747FE7-94BA-410C-8D7F-EB47555DD994} = {63747FE7-94BA-410C-8D7F-EB47555DD994} @@ -106,6 +111,12 @@ Global {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Release|Win32.ActiveCfg = Release|Win32 {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Release|Win32.Build.0 = Release|Win32 {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Release|x64.ActiveCfg = Release|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Debug|Win32.Build.0 = Debug|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Debug|x64.ActiveCfg = Debug|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Release|Win32.ActiveCfg = Release|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Release|Win32.Build.0 = Release|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Release|x64.ActiveCfg = Release|Win32 {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Debug|Win32.ActiveCfg = Debug|Win32 {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Debug|Win32.Build.0 = Debug|Win32 {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Debug|x64.ActiveCfg = Debug|Win32 diff --git a/Workspace_msvc/encoder_fmtsw.vcxproj b/Workspace_msvc/encoder_fmtsw.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..7af057ae8f535255942da571f4c6085108c5faf1 --- /dev/null +++ b/Workspace_msvc/encoder_fmtsw.vcxproj @@ -0,0 +1,183 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + encoder_fmtsw + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B} + encoder_fmtsw + 10.0.17763.0 + + + + Application + v141 + false + MultiByte + + + Application + v141 + false + MultiByte + + + + + + + + + + + + + + + <_ProjectFileVersion>15.0.27428.2015 + + + ..\ + .\Debug_$(ProjectName)\ + false + false + IVAS_cod_fmtsw + + + ..\ + .\Release_$(ProjectName)\ + false + false + IVAS_cod_fmtsw + + + + + + + $(IntDir)$(ProjectName).tlb + + + + Disabled + ..\lib_basop;..\lib_enc;..\lib_com;..\lib_util;..\lib_debug;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions) + + EnableFastChecks + MultiThreadedDebug + false + + + $(IntDir)$(ProjectName).pdb + Level4 + true + OldStyle + Default + %(DisableSpecificWarnings) + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c0c + + + + $(OutDir)$(TargetName).exe + true + + false + true + $(IntDir)$(ProjectName).pdb + Console + + false + + MachineX86 + + + + + + + + + + + $(IntDir)$(ProjectName).tlb + + + + MaxSpeed + AnySuitable + false + Neither + false + false + ..\lib_basop;..\lib_enc;..\lib_com;..\lib_util;..\lib_debug;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions) + true + + Default + MultiThreaded + true + Precise + false + + + $(IntDir)$(ProjectName).pdb + Level4 + true + + Default + %(DisableSpecificWarnings) + false + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c0c + + + $(OutDir)$(TargetName).exe + true + + false + $(IntDir)$(ProjectName).pdb + Console + false + + MachineX86 + + + + + + + + {63747fe7-94ba-410c-8d7f-eb47555dd994} + + + {824da4cf-06f0-45c9-929a-8792f0e19c3e} + false + + + {2fa8f384-0775-f3b7-f8c3-85209222fc70} + false + + + + + + + + + + + \ No newline at end of file diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index ee67280d0dd1f64ad9424857fd969cdaebef2b63..702c6c1adf8b6c0a92e6a183f0c284961f2d7fd6 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -161,7 +161,6 @@ - diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index e8bbb17e9b0e6ab35342975185aa9d5a4fdfdeb8..37a179045ca136dbbd540c08d247454837167c5b 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -256,9 +256,6 @@ common_all_c - - common_all_c - common_all_c diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 9d98513e8525267717e9437c90abc1522d0129f1..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;.%(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;.%(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/Workspace_msvc/lib_rend.vcxproj.filters b/Workspace_msvc/lib_rend.vcxproj.filters index 0892a4dcb09d82b426c470d29851041668907dde..dfa1253eb5681d99f0a489d33757f1365762af8f 100644 --- a/Workspace_msvc/lib_rend.vcxproj.filters +++ b/Workspace_msvc/lib_rend.vcxproj.filters @@ -119,6 +119,9 @@ rend_c + + rend_c + diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index 7b793cc4c70b861dc4a0b0bfa0fa129c278f8926..bfbfa8d4cfcb5cde0cfbb9ee005bd22b7c228761 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -109,7 +109,13 @@ + + + + + + @@ -136,7 +142,15 @@ + + + + + + + + @@ -164,4 +178,4 @@ - + \ No newline at end of file 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 94bfab14d8ac1d80b3970bde8b0a5a2873d93dff..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 @@ -31,26 +31,25 @@ *******************************************************************************************************/ #include "lib_dec.h" +#include "options.h" #include #include "cmdl_tools.h" #include "audio_file_writer.h" #include "bitstream_reader.h" #include "evs_rtp_payload.h" #include "ism_file_writer.h" +#include "ivas_rtp_file.h" #include "jbm_file_writer.h" #include "hrtf_file_reader.h" #include "ls_custom_file_reader.h" #include "masa_file_writer.h" #include "render_config_reader.h" #include "rotation_file_reader.h" -#ifdef FIX_1053_REVERB_RECONFIGURATION #include "aeid_file_reader.h" -#endif #include "split_render_file_read_write.h" #include "obj_edit_file_reader.h" #include "vector3_pair_file_reader.h" #include "wmc_auto.h" -#include "options.h" #include "stl.h" @@ -65,6 +64,8 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#define RANDOM_INITSEED_DEC ( 0xFADE ) + #ifdef DEBUGGING #define MIN_NUM_BITS_ACTIVE_FRAME 56 #define NUM_BITS_SID_IVAS_5K2 104 @@ -123,12 +124,16 @@ 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]; bool objEditEnabled; char *objEditFileName; + bool applyPiData; + char *piOutputFilename; + bool rtpOutSR; + IVAS_ROOM_SIZE_T roomSize; } DecArguments; @@ -137,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; @@ -158,13 +160,10 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP -static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#else -static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#endif +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ); static ivas_error load_hrtf_from_file( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const IVAS_AUDIO_CONFIG OutputConfig, const int32_t output_Fs ); static void do_object_editing_fx( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader ); +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ); /*------------------------------------------------------------------------------------------* @@ -194,17 +193,17 @@ 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; + uint32_t aeCount = 0; + IVAS_RENDER_CONFIG_DATA renderConfig = { 0 }; #ifdef WMOPS reset_wmops(); 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; @@ -407,33 +406,21 @@ int main( * Configure the decoder *------------------------------------------------------------------------------------------*/ - asked_frame_size = arg.renderFramesize; - uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : 65535; + asked_num_subframes = arg.render_num_subframes; + uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : IVAS_DEFAULT_AEID; - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, - arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, - arg.non_diegetic_pan_enabled, arg.non_diegetic_pan_gain_fx, arg.dpidEnabled, aeID, arg.objEditEnabled, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) + 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 ) { fprintf( stderr, "\nConfigure 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 ( 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 ) @@ -441,14 +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; + } - arg.enableHeadRotation = true; + if ( !arg.renderConfigEnabled && ( arg.render_num_subframes != asked_num_subframes ) ) + { + fprintf( stderr, "\nChanged render framesize, only 20ms allowed!\n" ); } /*------------------------------------------------------------------------------------------* @@ -480,8 +470,6 @@ int main( if ( arg.renderConfigEnabled ) { - IVAS_RENDER_CONFIG_DATA renderConfig; - /* sanity check */ if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && @@ -509,6 +497,46 @@ int main( goto cleanup; } + aeCount = RenderConfigReader_getAcousticEnvironmentCount( renderConfigReader ); + if ( aeCount > 0 ) + { + uint32_t n; + + pAE = malloc( aeCount * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA * ) ); + + if ( pAE == NULL ) + { + fprintf( stderr, "\nError: cannot allocate memory for acoustic environment array\n\n" ); + goto cleanup; + } + + for ( n = 0; n < aeCount; n++ ) + { + pAE[n] = NULL; + + if ( NULL == ( pAE[n] = malloc( sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) ) ) ) + { + fprintf( stderr, "\nError: cannot allocate memory for acoustic environment\n\n" ); + goto cleanup; + } + } + + if ( ( error = RenderConfigReader_getAcousticEnvironments( renderConfigReader, pAE ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error while getting acoustic environments\n\n" ); + goto cleanup; + } + + for ( n = 0; n < aeCount; n++ ) + { + if ( ( error = IVAS_DEC_AddAcousticEnvironment( hIvasDec, *pAE[n] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Failed to add acoustic environments\n\n" ); + goto cleanup; + } + } + } + if ( ( error = RenderConfigReader_getDirectivity( renderConfigReader, arg.directivityPatternId, renderConfig.directivity_fx ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Failed to get directivity patterns for one or more of IDs: %d %d %d %d\n\n", arg.directivityPatternId[0], arg.directivityPatternId[1], arg.directivityPatternId[2], arg.directivityPatternId[3] ); @@ -522,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" ); } @@ -547,7 +575,7 @@ int main( if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) { if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK ) { @@ -564,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 ) { @@ -636,11 +664,7 @@ int main( if ( arg.voipMode ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, hIvasDec, pcmBuf ); -#else - error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, hIvasDec, pcmBuf ); -#endif + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, &renderConfig, &hIvasDec, pcmBuf ); } else { @@ -675,25 +699,24 @@ cleanup: free( pcmBuf ); + if ( pAE != NULL ) + { + uint16_t n; + + for ( n = 0; n < aeCount; n++ ) + { + free( pAE[n] ); + } + + free( pAE ); + } + if ( arg.aeSequence.count > 0 ) { free( arg.aeSequence.pID ); 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 ); @@ -848,6 +871,9 @@ static bool parseCmdlIVAS_dec( arg->referenceVectorTrajFileName = NULL; arg->enableExternalOrientation = false; arg->externalOrientationTrajFileName = NULL; + arg->applyPiData = false; + arg->piOutputFilename = NULL; + arg->rtpOutSR = false; #ifdef SUPPORT_JBM_TRACEFILE arg->jbmTraceFilename = NULL; @@ -872,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; @@ -886,6 +913,8 @@ static bool parseCmdlIVAS_dec( arg->objEditEnabled = false; arg->objEditFileName = NULL; + arg->roomSize = IVAS_ROOM_SIZE_AUTO; + /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ @@ -926,6 +955,28 @@ static bool parseCmdlIVAS_dec( arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF; i++; } + else if ( strcmp( argv_to_upper, "-PIDATAFILE" ) == 0 ) + { + i++; + if ( argc - i <= 3 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: PI Data Output file name not specified!\n\n" ); + usage_dec(); + return false; + } + + arg->piOutputFilename = argv[i++]; + } + else if ( strcmp( argv_to_upper, "-APPLYPIDATA" ) == 0 ) + { + arg->applyPiData = true; + i++; + } + else if ( strcmp( argv_to_upper, "-RTPOUTSR" ) == 0 ) + { + arg->rtpOutSR = true; + i++; + } #ifdef SUPPORT_JBM_TRACEFILE else if ( strcmp( argv_to_upper, "-TRACEFILE" ) == 0 ) { @@ -1016,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 ); @@ -1205,7 +1256,6 @@ static bool parseCmdlIVAS_dec( if ( !is_digits_only( argv[i] ) ) { -#ifdef FIX_1053_REVERB_RECONFIGURATION aeidFileReader *aeidReader = NULL; if ( aeidFileReader_open( argv[i], &aeidReader ) != IVAS_ERR_OK ) { @@ -1221,67 +1271,6 @@ static bool parseCmdlIVAS_dec( } aeidFileReader_close( &aeidReader ); i++; -#else - uint16_t k; - char *s = argv[i]; - char *token = argv[i]; - - for ( k = 0; s[k]; ) - { - s[k] == ',' ? k++ : *s++; - } - k++; - - if ( k == 0 ) - { - fprintf( stdout, "Error: Invalid acoustic environment sequence specified: %s\n\n", argv[i] ); - usage_dec(); - return false; - } - - if ( NULL == ( arg->aeSequence.pID = malloc( sizeof( uint16_t ) * k ) ) || - NULL == ( arg->aeSequence.pValidity = malloc( sizeof( uint16_t ) * k ) ) ) - { - fprintf( stdout, "Error: Unable to allocate memory for acoustic environment sequence: %s\n\n", argv[i] ); - usage_dec(); - return false; - } - - arg->aeSequence.count = k; - - k = 0; - token = strtok( argv[i++], ":" ); - - while ( token != NULL ) - { - if ( !is_number( token ) ) - { - fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, argv[i] ); - usage_dec(); - return false; - } - arg->aeSequence.pID[k] = (uint16_t) atoi( token ); - - token = strtok( NULL, "," ); - if ( !is_number( token ) ) - { - fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, argv[i] ); - usage_dec(); - return false; - } - arg->aeSequence.pValidity[k] = (uint16_t) atoi( token ); - - token = strtok( NULL, ":" ); - k++; - } - - if ( k != arg->aeSequence.count ) - { - fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", argv[i] ); - usage_dec(); - return false; - } -#endif } else { @@ -1360,6 +1349,48 @@ static bool parseCmdlIVAS_dec( } i++; } + else if ( strcmp( argv_to_upper, "-EVS" ) == 0 ) + { + arg->decMode = IVAS_DEC_MODE_EVS; + i++; + } + else if ( strcmp( argv_to_upper, "-ROOM_SIZE" ) == 0 ) + { + i++; + if ( argc - i <= 3 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Room size selector not specified!\n\n" ); + usage_dec(); + return false; + } + + if ( strlen( argv[i] ) != 1 ) + { + fprintf( stderr, "Error: Unsupported room size selector %s!\n\n", argv[i] ); + usage_dec(); + return false; + } + switch ( argv[i][0] ) + { + case 'S': + case 's': + arg->roomSize = IVAS_ROOM_SIZE_SMALL; + break; + case 'M': + case 'm': + arg->roomSize = IVAS_ROOM_SIZE_MEDIUM; + break; + case 'L': + case 'l': + arg->roomSize = IVAS_ROOM_SIZE_LARGE; + break; + default: + fprintf( stderr, "Error: Unsupported room size selector %s!\n\n", argv[i] ); + usage_dec(); + return false; + } + i++; + } /*-----------------------------------------------------------------* * Option not recognized @@ -1410,6 +1441,13 @@ static bool parseCmdlIVAS_dec( usage_dec(); return false; } + else if ( arg->non_diegetic_pan_enabled && arg->outputConfig == IVAS_AUDIO_CONFIG_STEREO && arg->decMode == IVAS_DEC_MODE_EVS ) + { + fprintf( stderr, "Error: Both non-diegetic panning and stereo output specified!\n\n" ); + usage_dec(); + return false; + } + if ( arg->outputMdFilename != NULL && arg->outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { fprintf( stderr, "Error: Output split rendering metadata file is supported for BINAURAL_SPLIT_PCM output config. only\n\n" ); @@ -1501,6 +1539,7 @@ static bool parseCmdlIVAS_dec( static void usage_dec( void ) { fprintf( stdout, "Usage for EVS: IVAS_dec.exe [Options] Fs bitstream_file output_file\n" ); + fprintf( stdout, " OR usage for IVAS (below) with -evs option and OutputConf\n" ); fprintf( stdout, "Usage for IVAS: IVAS_dec.exe [Options] OutputConf Fs bitstream_file output_file\n\n" ); fprintf( stdout, "Mandatory parameters:\n" ); @@ -1517,12 +1556,17 @@ static void usage_dec( void ) fprintf( stdout, "Options:\n" ); fprintf( stdout, "--------\n" ); + fprintf( stdout, "-evs : Specify that the supplied bitstream is an EVS bitstream\n" ); fprintf( stdout, "-VOIP : VoIP mode: RTP in G192\n" ); fprintf( stdout, "-VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump\n" ); - fprintf( stdout, "-VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump\n" ); + fprintf( stdout, "-VOIP_hf_only=1 : VoIP mode: EVS or IVAS RTP Payload Format hf_only=1 in rtpdump\n" ); fprintf( stdout, " The decoder may read rtpdump files containing TS26.445 Annex A.2.2\n" ); - fprintf( stdout, " EVS RTP Payload Format. The SDP parameter hf_only is required.\n" ); + fprintf( stdout, " EVS RTP Payload Format or rtpdump files containing TS26.253 Annex A\n" ); + fprintf( stdout, " IVAS RTP Payload Format. The SDP parameter hf_only is required.\n" ); fprintf( stdout, " Reading RFC4867 AMR/AMR-WB RTP payload format is not supported.\n" ); + fprintf( stdout, "-PiDataFile PF Log the timestampped PI data.\n" ); + fprintf( stdout, "-ApplyPiData Apply the PI data found in the rtp packet.\n" ); + fprintf( stdout, "-rtpOutSR : Split Rendering bitstream RTPDump output \n" ); #ifdef SUPPORT_JBM_TRACEFILE fprintf( stdout, "-Tracefile TF : VoIP mode: Generate trace file named TF. Requires -no_delay_cmp to\n" ); fprintf( stdout, " be enabled so that trace contents remain in sync with audio output.\n" ); @@ -1547,6 +1591,8 @@ static void usage_dec( void ) fprintf( stdout, "-rvf File : Reference vector specified by external trajectory File\n" ); fprintf( stdout, " works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes\n" ); fprintf( stdout, "-render_config File : Renderer configuration File\n" ); + fprintf( stdout, "-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large)\n" ); + fprintf( stdout, " for BINAURAL_ROOM_REVERB output configuration,\n" ); fprintf( stdout, "-om File : Metadata output File for BINAURAL_SPLIT_PCM OutputConf (only for Fs = 48 kHz)\n" ); fprintf( stdout, "-non_diegetic_pan P : panning mono non-diegetic sound to stereo with panning P, -90<= P <=90,\n" ); fprintf( stdout, " left or l or 90->left, right or r or -90->right, center or c or 0->middle\n" ); @@ -1556,13 +1602,10 @@ static void usage_dec( void ) fprintf( stdout, " output configuration. ID1, ID2, ID3, ID4 specify the directivity pattern IDs used for\n" ); fprintf( stdout, " ISMs 1,2,3 and 4 respectively. This options needs to be accompanied by a render_config file,\n" ); fprintf( stdout, " otherwise a default directivity pattern is used.\n" ); - fprintf( stdout, "-aeid ID : Acoustic environment ID (number > 0) or\n" ); - fprintf( stdout, " a sequence thereof in the format [ID1:duration1,ID2:duration2...]\n" ); - fprintf( stdout, " without braces and spaces, with ':' character separating ID from duration and ',' separating\n" ); - fprintf( stdout, " ID and duration pairs, where duration is specified in frames\n" ); + fprintf( stdout, "-aeid ID | File : Acoustic environment ID (number > 0)\n" ); + fprintf( stdout, " alternatively, it can be a text file where each line contains \"ID duration\"\n" ); fprintf( stdout, " for BINAURAL_ROOM_REVERB output configuration.\n" ); fprintf( stdout, "-obj_edit File : Object editing instructions file or NULL for built-in example\n" ); - fprintf( stdout, "-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. \n" ); fprintf( stdout, " Currently, all values default to level 3 (full functionality).\n" ); fprintf( stdout, "-q : Quiet mode, no frame counter\n" ); @@ -1594,6 +1637,7 @@ static ivas_error initOnFirstGoodFrame( IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o : */ int16_t *pNumOutChannels, /* o : */ uint16_t *pNumObj, /* o : */ + IVAS_RTP *srRtp, /* o : */ SplitFileReadWrite **splitRendWriter ) { int16_t isSplitRend, isSplitCoded; @@ -1646,6 +1690,13 @@ static ivas_error initOnFirstGoodFrame( int16_t splitRendIsarFrameSizeMs; int16_t lc3plusHighRes; + /* Ideally ssrc is negotiated via SDP and sequence number is radomized but we + use fixed seed for random num generator for regression based tests. Any realtime + application should implement this initialization seperately */ + uint16_t rtpDecSeed = RANDOM_INITSEED_DEC; + uint32_t ssrc = ( (uint32_t) IVAS_RTP_OwnRandom( &rtpDecSeed ) & 0x0000FFFF ) | ( (uint32_t) IVAS_RTP_OwnRandom( &rtpDecSeed ) << 16 ); + uint16_t seqNumInitVal = IVAS_RTP_OwnRandom( &rtpDecSeed ); + if ( ( error = IVAS_DEC_GetDelay( hIvasDec, delayNumSamples_temp, &delayTimeScale_temp ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to get delay of decoder: %s\n", ivas_error_to_string( error ) ); @@ -1658,7 +1709,36 @@ static ivas_error initOnFirstGoodFrame( return error; } - if ( isSplitCoded ) + /* Split Rendering RTPDump Output file */ + if ( arg.rtpOutSR && srRtp != NULL ) + { + FILE *fParamsSR = NULL; + 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" ); + if ( NULL != fParamsSR ) + { + fprintf( fParamsSR, "DOF = %d;\nLC3PLUS_HIGHRES = %d;\n", poseCorrection, lc3plusHighRes ); + fclose( fParamsSR ); + fParamsSR = NULL; + } + + + /* Split Rendering RTPDump Output file */ + if ( ( error = IVAS_RTP_WRITER_Init( srRtp, arg.outputWavFilename, 1000 / ( IVAS_NUM_FRAMES_PER_SEC * splitRendCodecFrameSizeMs ), ssrc, seqNumInitVal ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open SR output bitstream file for RTP output %s \n\n", arg.outputWavFilename ); + return error; + } + } + else if ( isSplitCoded ) { if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs, splitRendIsarFrameSizeMs, arg.output_Fs, lc3plusHighRes ) ) != IVAS_ERR_OK ) { @@ -1692,69 +1772,64 @@ static ivas_error initOnFirstGoodFrame( } } - int16_t pcmFrameSize; - if ( ( error = IVAS_DEC_GetOutputBufferSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nError in IVAS_DEC_GetOutputBufferSize, error code: %d\n", error ); - return error; - } - - /* Write zeros to the output audio buffer */ - int16_t *zeroBuf = calloc( pcmFrameSize, sizeof( int16_t ) ); - if ( zeroBuf == NULL ) + if ( !arg.rtpOutSR ) { - fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" ); - return IVAS_ERR_FAILED_ALLOC; - } - - for ( int16_t i = 0; i < numInitialBadFrames; ++i ) - { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( isSplitRend ) -#else - if ( *splitRendWriter != NULL ) -#endif + int16_t pcmFrameSize; + if ( ( error = IVAS_DEC_GetOutputBufferSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) { - ISAR_SPLIT_REND_BITS_DATA splitRendBitsZero; - splitRendBitsZero.bits_buf = NULL; - splitRendBitsZero.bits_read = 0; - splitRendBitsZero.bits_written = 0; - splitRendBitsZero.buf_len = 0; - splitRendBitsZero.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; - splitRendBitsZero.pose_correction = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; - splitRendBitsZero.codec_frame_size_ms = 0; - splitRendBitsZero.isar_frame_size_ms = 20; + fprintf( stderr, "\nError in IVAS_DEC_GetOutputBufferSize, error code: %d\n", error ); + return error; + } - if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nUnable to write to bitstream file!\n" ); - return error; - } + /* Write zeros to the output audio buffer */ + int16_t *zeroBuf = calloc( pcmFrameSize, sizeof( int16_t ) ); + if ( zeroBuf == NULL ) + { + fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" ); + return IVAS_ERR_FAILED_ALLOC; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - if ( !isSplitCoded ) -#else - else -#endif + for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { - if ( *pRemainingDelayNumSamples < *numOutSamples ) + if ( isSplitRend ) { - if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, *numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) + ISAR_SPLIT_REND_BITS_DATA splitRendBitsZero; + splitRendBitsZero.bits_buf = NULL; + splitRendBitsZero.bits_read = 0; + splitRendBitsZero.bits_written = 0; + splitRendBitsZero.buf_len = 0; + splitRendBitsZero.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; + splitRendBitsZero.pose_correction = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; + splitRendBitsZero.codec_frame_size_ms = 0; + splitRendBitsZero.isar_frame_size_ms = 20; + + if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nOutput audio file writer error\n" ); + fprintf( stderr, "\nUnable to write to bitstream file!\n" ); return error; } - *pRemainingDelayNumSamples = 0; } - else + + if ( !isSplitCoded ) { - *pRemainingDelayNumSamples -= *numOutSamples; + if ( *pRemainingDelayNumSamples < *numOutSamples ) + { + if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, *numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nOutput audio file writer error\n" ); + return error; + } + *pRemainingDelayNumSamples = 0; + } + else + { + *pRemainingDelayNumSamples -= *numOutSamples; + } } } - } - free( zeroBuf ); + free( zeroBuf ); + } /* Open other output files if EXT output config - now details about ISM or MASA are known */ if ( arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) @@ -1848,7 +1923,7 @@ static ivas_error initOnFirstGoodFrame( } } - if ( *splitRendWriter != NULL ) + if ( arg.rtpOutSR || *splitRendWriter != NULL ) { if ( numOutSamples == NULL || vec_pos_len == NULL ) { @@ -1912,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; @@ -1936,13 +2012,11 @@ static ivas_error decodeG192( return error; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( !isSplitRend ) { /* Ensure split rendering output struct is not used when not outputting to a split rendering output configuration */ splitRendBits = NULL; } -#endif if ( ( error = IVAS_DEC_is_split_rendering_coded_out( hIvasDec, &isSplitCoded ) ) != IVAS_ERR_OK ) { @@ -2054,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 */ - /* 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; @@ -2083,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 ) { @@ -2093,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 ) { @@ -2105,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 ) { @@ -2119,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 ) { @@ -2205,11 +2276,7 @@ static ivas_error decodeG192( } /* decode transport channels, do TSM and feed to renderer */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, splitRendBits ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -2303,7 +2370,7 @@ static ivas_error decodeG192( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, NULL, &splitRendWriter ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2456,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; @@ -2651,10 +2732,9 @@ static ivas_error decodeVoIP( RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ISAR_SPLIT_REND_BITS_DATA *splitRendBits, -#endif - IVAS_DEC_HANDLE hIvasDec, + IVAS_RENDER_CONFIG_DATA *renderConfig, + IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ) { bool decodingFailed = true; /* Assume failure until cleanup is reached without errors */ @@ -2686,16 +2766,19 @@ static ivas_error decodeVoIP( int16_t delayNumSamples = -1; int32_t delayTimeScale = -1; int16_t i; - FILE *f_rtpstream = NULL; - EVS_RTPDUMP_DEPACKER rtpdumpDepacker; - EVS_RTPDUMP_DEPACKER_ERROR rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_NO_ERROR; + IVAS_DEC_HANDLE hIvasDec = *phIvasDec; + + bool restartNeeded; + IVAS_RTP ivasRtp = { 0 }; + IVAS_RTP srRtp = { 0 }; + IVAS_RTP_SR_INFO srInfo = { true, false, 0, 20, IVAS_SR_TRANSPORT_LCLD }; + int32_t initialTsOffsetSystemAndRTP = 0; uint8_t *auPtr = NULL; - bool isAMRWB_IOmode; - uint16_t frameTypeIndex; bool qBit; 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; @@ -2703,7 +2786,6 @@ static ivas_error decodeVoIP( bool parametersAvailableForEditing = false; uint16_t nSamplesRendered; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP SplitFileReadWrite *splitRendWriter = NULL; int16_t isSplitRend, isSplitCoded; @@ -2724,7 +2806,6 @@ static ivas_error decodeVoIP( fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_coded_out, code: %d\n", error ); return error; } -#endif vec_pos_update = 0; if ( ( error = IVAS_DEC_GetRenderFramesizeMs( hIvasDec, &systemTimeInc_ms ) ) != IVAS_ERR_OK ) @@ -2750,23 +2831,13 @@ static ivas_error decodeVoIP( delayNumSamples_orig[0] = -1; - rtpdumpDepacker.rtpdump = NULL; switch ( arg.inputFormat ) { case IVAS_DEC_INPUT_FORMAT_RTPDUMP: case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF: - f_rtpstream = fopen( arg.inputBitstreamFilename, "r" ); - - if ( f_rtpstream == NULL ) - { - fprintf( stderr, "could not open: %s\n", arg.inputBitstreamFilename ); - goto cleanup; - } - - rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_open( &rtpdumpDepacker, f_rtpstream, arg.inputFormat == IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF ); - if ( rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR ) + if ( ( error = IVAS_RTP_READER_Init( &ivasRtp, arg.inputBitstreamFilename, arg.piOutputFilename, arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL, arg.outputWavFilename ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "error in EVS_RTPDUMP_DEPACKER_open(): %d\n", rtpdumpDepackerError ); + fprintf( stderr, "error in IVAS_RTP_READER_Init(): %d\n", error ); goto cleanup; } break; @@ -2778,7 +2849,6 @@ static ivas_error decodeVoIP( goto cleanup; } - #ifdef SUPPORT_JBM_TRACEFILE if ( arg.jbmTraceFilename != NULL ) { @@ -2810,12 +2880,15 @@ static ivas_error decodeVoIP( else { auPtr = au; /* might have been set to RTP packet in prev call */ - rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, &nextPacketRcvTime_ms, &isAMRWB_IOmode, &frameTypeIndex, &qBit, &auPtr, (uint16_t *) &auSize ); + + error = IVAS_RTP_ReadNextFrame( &ivasRtp, auPtr, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, NULL, &qBit ); + + initialTsOffsetSystemAndRTP = rtpTimeStamp - systemTime_ms * 16; /* For time mapping */ /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */ rtpTimeStamp = rtpTimeStamp / 16; } - if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR ) + if ( error != IVAS_ERR_OK ) { fprintf( stderr, "failed to read first RTP packet\n" ); goto cleanup; @@ -2844,6 +2917,26 @@ static ivas_error decodeVoIP( { nSamplesRendered = 0; + /* restart decoder in case of format switching */ + if ( ivasRtp.restartNeeded ) + { + IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + renderConfig, + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); + goto cleanup; + } + + *phIvasDec = hIvasDec; /* Update for main()' s free */ + ivasRtp.restartNeeded = false; + } + /* reference vector */ if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) { @@ -2877,22 +2970,20 @@ static ivas_error decodeVoIP( goto cleanup; } } - 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 */ - /* 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; @@ -2907,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 ) { @@ -2917,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 ) { @@ -2929,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 ) @@ -2945,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 ) { @@ -2986,19 +3076,18 @@ static ivas_error decodeVoIP( else { auPtr = au; /* might have been set to RTP packet in prev call */ - rtpdumpDepackerError = EVS_RTPDUMP_DEPACKER_readNextFrame( &rtpdumpDepacker, &rtpSequenceNumber, &rtpTimeStamp, - &nextPacketRcvTime_ms, - &isAMRWB_IOmode, &frameTypeIndex, &qBit, - &auPtr, (uint16_t *) &auSize ); - /* EVS RTP payload format has timescale 16000, JBM uses 1000 internally */ + + error = IVAS_RTP_ReadNextFrame( &ivasRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, NULL, &qBit ); + + /* IVAS RTP payload format has timescale 16000, JBM uses 1000 internally */ rtpTimeStamp = rtpTimeStamp / 16; } - if ( error == IVAS_ERR_END_OF_FILE || rtpdumpDepackerError == EVS_RTPDUMP_DEPACKER_EOF ) + if ( error == IVAS_ERR_END_OF_FILE ) { /* finished reading */ nextPacketRcvTime_ms = (uint32_t) -1; } - else if ( error != IVAS_ERR_OK || rtpdumpDepackerError != EVS_RTPDUMP_DEPACKER_NO_ERROR ) + else if ( error != IVAS_ERR_OK ) { fprintf( stderr, "\nError in BS_Reader_ReadVoipFrame_compact, error code: %d\n", error ); goto cleanup; @@ -3008,16 +3097,41 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + bool isEmpty; + if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) { break; } - /* decode and get samples */ while ( nSamplesRendered < nOutSamples ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + if ( arg.applyPiData ) + { + /* Rudimentry Time Mapping to map system time to rtp timestamp */ + uint32_t piTs = systemTime_ms * 16 + initialTsOffsetSystemAndRTP; + uint32_t numPiData = 0; + + while ( ivasRtp.nProcPiData + numPiData < ivasRtp.nReadPiData && + ivasRtp.piData[ivasRtp.nProcPiData + numPiData].timestamp <= piTs ) + { + numPiData++; + } + + if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + ivasRtp.nProcPiData += numPiData; + } + if ( isSplitRend ) { #ifdef SUPPORT_JBM_TRACEFILE @@ -3032,19 +3146,16 @@ static ivas_error decodeVoIP( } else { -#endif #ifdef SUPPORT_JBM_TRACEFILE if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, &bitstreamReadDone, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, &bitstreamReadDone, ¶metersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK ) #endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP } -#endif if ( bitstreamReadDone == true ) { @@ -3056,6 +3167,37 @@ static ivas_error decodeVoIP( return error; } + /* restart decoder in case of format switching */ + if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( restartNeeded ) + { + IVAS_DEC_BS_FORMAT tempBsFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); + goto cleanup; + } + + IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to restart decoder\n" ); + goto cleanup; + } + + *phIvasDec = hIvasDec; /* Update for main()' s free */ + } + /* Placeholder for memory reallocation */ /* ... */ @@ -3124,16 +3266,8 @@ static ivas_error decodeVoIP( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - SplitFileReadWrite *splitRendWriter = NULL; - -#endif -#ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, -#else - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, -#endif - &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &srRtp, &splitRendWriter ) ) != IVAS_ERR_OK ) { goto cleanup; } @@ -3145,9 +3279,8 @@ static ivas_error decodeVoIP( } /* Write current frame */ - if ( decodedGoodFrame ) + if ( !srRtp.hPack && decodedGoodFrame ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( isSplitRend ) { if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) @@ -3159,7 +3292,6 @@ static ivas_error decodeVoIP( if ( !isSplitCoded ) { -#endif if ( delayNumSamples < nOutSamples ) { if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) @@ -3173,9 +3305,7 @@ static ivas_error decodeVoIP( { delayNumSamples -= nOutSamples; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP } -#endif /* Write ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) @@ -3230,8 +3360,24 @@ static ivas_error decodeVoIP( goto cleanup; } } + + IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); } } + else if ( decodedGoodFrame ) + { + srInfo.bitrateKbps = splitRendBits->bits_written * 1000 / splitRendBits->codec_frame_size_ms; + srInfo.codec = ( splitRendBits->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) ? IVAS_SR_TRANSPORT_LC3PLUS : IVAS_SR_TRANSPORT_LCLD; + srInfo.codecFrameSizeMs = (uint32_t) splitRendBits->codec_frame_size_ms; + + if ( ( error = IVAS_RTP_WriteNextFrame( &srRtp, splitRendBits->bits_buf, &srInfo, (int16_t) splitRendBits->bits_written, false, false ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while pushing SR audio bitstream to RTP pack\n", ivas_error_to_string( error ) ); + goto cleanup; + } + splitRendBits->bits_written = 0; + splitRendBits->bits_read = 0; + } vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; if ( vec_pos_update == 0 ) @@ -3263,11 +3409,7 @@ static ivas_error decodeVoIP( goto cleanup; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( nSamplesFlushed && !isSplitCoded ) -#else - if ( nSamplesFlushed ) -#endif { /* Write current frame */ if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK ) @@ -3329,28 +3471,25 @@ static ivas_error decodeVoIP( goto cleanup; } } + + IVAS_RTP_WriteExtPiData( ivasRtp.f_piExtOut, ivasRtp.piData, ivasRtp.nReadPiData, numObj ); } } - /*------------------------------------------------------------------------------------------* * Add zeros at the end to have equal length of synthesized signals *------------------------------------------------------------------------------------------*/ memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( afWriter != NULL ) { -#endif if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); goto cleanup; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP } -#endif /*------------------------------------------------------------------------------------------* * Printouts after decoding has finished @@ -3383,6 +3522,8 @@ static ivas_error decodeVoIP( { fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } + + fprintf( stdout, "\nOutput PI data file: %s\n", IVAS_RTP_GetExtPiFilePath( &ivasRtp ) ); } /*------------------------------------------------------------------------------------------* @@ -3393,11 +3534,10 @@ static ivas_error decodeVoIP( cleanup: - EVS_RTPDUMP_DEPACKER_close( &rtpdumpDepacker ); + IVAS_RTP_Term( &srRtp ); + IVAS_RTP_Term( &ivasRtp ); AudioFileWriter_close( &afWriter ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP split_rend_reader_writer_close( &splitRendWriter ); -#endif JbmOffsetFileWriter_close( &jbmOffsetWriter ); #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriter_close( &jbmTraceWriter ); @@ -3448,11 +3588,7 @@ static void do_object_editing_fx( if ( readInfo->bg_gain_edited ) { -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->gain_bed_fx = (Word32) ( readInfo->bg_gain * 536870912 ); /* Q29 */ -#else - editableParameters->gain_bed_fx = (Word32) readInfo->bg_gain * 536870912; /* Q29 */ -#endif } for ( obj_idx = 0; obj_idx < editableParameters->num_obj; obj_idx++ ) @@ -3465,19 +3601,11 @@ static void do_object_editing_fx( if ( readInfo->obj_azi_relative[obj_idx] ) { /* azimuth: apply relative edit + wrap */ -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->ism_metadata[obj_idx].azimuth_fx = ( ( editableParameters->ism_metadata[obj_idx].azimuth_fx + (Word32) ( readInfo->obj_azi[obj_idx] * 4194304 ) + 2264924160 ) % 1509949440 ) - 754974720; /* Q22 */ -#else - editableParameters->ism_metadata[obj_idx].azimuth_fx = ( ( editableParameters->ism_metadata[obj_idx].azimuth_fx + (Word32) readInfo->obj_azi[obj_idx] * 4194304 + 2264924160 ) % 1509949440 ) - 754974720; /* Q22 */ -#endif } else { -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->ism_metadata[obj_idx].azimuth_fx = (Word32) ( readInfo->obj_azi[obj_idx] * 4194304 ); /* Q22 */ -#else - editableParameters->ism_metadata[obj_idx].azimuth_fx = (Word32) readInfo->obj_azi[obj_idx] * 4194304; /* Q22 */ -#endif } } if ( readInfo->obj_ele_edited[obj_idx] ) @@ -3485,19 +3613,57 @@ static void do_object_editing_fx( if ( readInfo->obj_ele_relative[obj_idx] ) { /* elevation: apply relative edit + saturation */ -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->ism_metadata[obj_idx].elevation_fx = L_max( L_min( editableParameters->ism_metadata[obj_idx].elevation_fx + (Word32) ( readInfo->obj_ele[obj_idx] * 4194304 ), 377487360 ), -377487360 ); /* Q22 */ -#else - editableParameters->ism_metadata[obj_idx].elevation_fx = L_max( L_min( editableParameters->ism_metadata[obj_idx].elevation_fx + (Word32) readInfo->obj_ele[obj_idx] * 4194304, 377487360 ), -377487360 ); /* Q22 */ -#endif } else { -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->ism_metadata[obj_idx].elevation_fx = (Word32) ( readInfo->obj_ele[obj_idx] * 4194304 ); /* Q22 */ -#else - editableParameters->ism_metadata[obj_idx].elevation_fx = (Word32) readInfo->obj_ele[obj_idx] * 4194304; /* Q22 */ -#endif + } + } + + /* object orientation editing only for diegetic objects */ + if ( readInfo->obj_yaw_edited[obj_idx] ) + { + if ( readInfo->obj_yaw_relative[obj_idx] ) + { + /* yaw: apply relative edit + wrap */ + editableParameters->ism_metadata[obj_idx].yaw_fx = ( ( editableParameters->ism_metadata[obj_idx].yaw_fx + (Word32) ( readInfo->obj_yaw[obj_idx] * 4194304 ) + 2264924160 ) % 1509949440 ) - 754974720; /* Q22 */ + } + else + { + editableParameters->ism_metadata[obj_idx].yaw_fx = (Word32) ( readInfo->obj_yaw[obj_idx] * 4194304 ); /* Q22 */ + } + } + if ( readInfo->obj_pitch_edited[obj_idx] ) + { + if ( readInfo->obj_pitch_relative[obj_idx] ) + { + /* pitch: apply relative edit + saturation */ + editableParameters->ism_metadata[obj_idx].pitch_fx = L_max( L_min( editableParameters->ism_metadata[obj_idx].pitch_fx + (Word32) ( readInfo->obj_pitch[obj_idx] * 4194304 ), 377487360 ), -377487360 ); /* Q22 */ + } + else + { + editableParameters->ism_metadata[obj_idx].pitch_fx = (Word32) ( readInfo->obj_pitch[obj_idx] * 4194304 ); /* Q22 */ + } + } + /* radius editing only for diegetic objects */ + if ( readInfo->obj_radius_edited[obj_idx] ) + { + if ( readInfo->obj_radius_relative[obj_idx] ) + { + /* radius: apply relative edit + saturation */ + Word32 L_tmp1 = L_mult( editableParameters->ism_metadata[obj_idx].radius_fx, (Word16) ( readInfo->obj_radius[obj_idx] * ( 1L << ( 9 ) ) ) ); /*SQ*SQ where SQ=9*/ + Word32 L_tmp2 = L_shl_sat( L_tmp1, ( 9 - ( 9 + 9 + 1 - 16 ) ) /* ^shift by 6 == mult by 2^6 = 64.0 */ ); /*shift back to Q(9+16)*/ + Word16 temp_radius = round_fx( L_tmp2 ); /* Q25 -> Q9 */ + temp_radius = s_max( s_min( temp_radius, OBJ_EDIT_RADIUS_MAX_FX ), 0 ); + + /* L_tmp2 is in S31Q25 stored in a signed Word32 + temp_radius is in S15Q9 stored in a signed Word16 + */ + } + else + { + editableParameters->ism_metadata[obj_idx].radius_fx = (Word16) ( readInfo->obj_radius[obj_idx] * 512 ); /* Q9 */ } } } @@ -3508,23 +3674,11 @@ static void do_object_editing_fx( if ( readInfo->obj_gain_relative[obj_idx] ) { /* gain: apply relative edit + saturation */ -#ifdef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->ism_metadata[obj_idx].gain_fx = L_max( L_min( L_shl_sat( Mpy_32_32( editableParameters->ism_metadata[obj_idx].gain_fx, (Word32) ( readInfo->obj_gain[obj_idx] * 536870912 ) ), 2 ), OBJ_EDIT_GAIN_MAX_FX ), OBJ_EDIT_GAIN_MIN_FX ); /* Q29*Q29 -> Q27 shift back to Q29 */ -#else - editableParameters->ism_metadata[obj_idx].gain_fx = L_max( L_min( L_shl_sat( Mpy_32_32( editableParameters->ism_metadata[obj_idx].gain_fx, (Word32) readInfo->obj_gain[obj_idx] * 536870912 ), 2 ), OBJ_EDIT_GAIN_MAX_FX ), OBJ_EDIT_GAIN_MIN_FX ); /* Q29*Q29 -> Q27 shift back to Q29 */ -#endif -#else - editableParameters->ism_metadata[obj_idx].gain_fx = L_max( L_min( editableParameters->ism_metadata[obj_idx].gain_fx * (Word32) readInfo->obj_gain[obj_idx] * 536870912, OBJ_EDIT_GAIN_MAX_FX ), OBJ_EDIT_GAIN_MIN_FX ); /* Q29 */ -#endif } else { -#ifdef FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE editableParameters->ism_metadata[obj_idx].gain_fx = (Word32) ( readInfo->obj_gain[obj_idx] * 536870912 ); /* Q29 */ -#else - editableParameters->ism_metadata[obj_idx].gain_fx = (Word32) readInfo->obj_gain[obj_idx] * 536870912; /* Q29 */ -#endif } } } @@ -3591,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; @@ -3618,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 ) { @@ -3633,7 +3783,7 @@ static ivas_error load_hrtf_from_file( } else { - destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + destroy_td_hrtf( hHrtfTD ); } } } @@ -3706,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 ); + } } } } @@ -3733,4 +3884,116 @@ static ivas_error load_hrtf_from_file( return IVAS_ERR_OK; } + +/*---------------------------------------------------------------------* + * restartDecoder() + * + * Restart decoder in case of IVAS format switching + *---------------------------------------------------------------------*/ + +static ivas_error restartDecoder( + IVAS_DEC_HANDLE *phIvasDec, + const IVAS_DEC_MODE decMode, + DecArguments *arg, + IVAS_RENDER_CONFIG_DATA *renderConfig, + IVAS_CUSTOM_LS_DATA *hLsCustomData ) +{ + ivas_error error = IVAS_ERR_OK; + IVAS_DEC_HANDLE hIvasDec; + + if ( phIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( NULL != *phIvasDec ) + { + IVAS_DEC_Close( phIvasDec ); + } + + if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + arg->decMode = decMode; + + hIvasDec = *phIvasDec; + + uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : IVAS_DEFAULT_AEID; + + 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->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 ) + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + 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 ) + { + 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; + } + + if ( arg->voipMode ) + { + if ( ( error = IVAS_DEC_EnableVoIP( hIvasDec, 60, arg->inputFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nCould not enable VOIP: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + /* ISAR frame size is set from command line, not renderer config file. + * 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->render_num_subframes * 5; + } + + if ( arg->renderConfigEnabled && renderConfig != NULL ) + { + if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, *renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( arg->customLsOutputEnabled && hLsCustomData != NULL ) + { + if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, *hLsCustomData ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + return IVAS_ERR_OK; + +cleanup: + IVAS_DEC_Close( phIvasDec ); + + return error; +} + #undef WMC_TOOL_SKIP diff --git a/apps/encoder.c b/apps/encoder.c index 2a8ef469f6161aea9111c1ff0f7d3d02eec51214..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 @@ -43,8 +43,11 @@ #include "ism_file_reader.h" #include "jbm_file_reader.h" #include "masa_file_reader.h" +#include "rotation_file_reader.h" +#include "ivas_rtp_file.h" #include "wmc_auto.h" + #ifdef DEBUG_FORCE_DIR /* Windows does not define the S_ISREG and S_ISDIR macros in stat.h, so we do. We have to define _CRT_INTERNAL_NONSTDC_NAMES 1 before #including sys/stat.h @@ -70,6 +73,8 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#define RANDOM_INITSEED_ENC ( 0xDEAF ) + #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ @@ -155,6 +160,10 @@ typedef struct #endif bool pca; bool ism_extended_metadata; + bool rtpdumpOutput; + uint32_t numFramesPerPacket; + char *sceneOrientationTrajFileName; + char *deviceOrientationTrajFileName; } EncArguments; @@ -198,6 +207,8 @@ int main( MasaFileReader *masaReader = NULL; IsmFileReader *ismReaders[IVAS_MAX_NUM_OBJECTS] = { NULL, NULL, NULL, NULL }; int16_t *pcmBuf = NULL; + RotFileReader *sceneOrientationFileReader = NULL; + RotFileReader *deviceOrientationFileReader = NULL; #ifdef DEBUGGING FILE *f_forcedModeProfile = NULL; #endif @@ -207,6 +218,16 @@ int main( reset_mem( USE_BYTES ); #endif + uint8_t au[IVAS_MAX_BITS_PER_FRAME / 8]; + IVAS_RTP ivasRtp = { 0 }; + + /* Ideally ssrc is negotiated via SDP and sequence number is radomized but we + use fixed seed for random num generator for regression based tests. Any realtime + application should implement this initialization seperately */ + uint16_t rtpEncSeed = RANDOM_INITSEED_ENC; + uint32_t ssrc = ( (uint32_t) IVAS_RTP_OwnRandom( &rtpEncSeed ) & 0x0000FFFF ) | ( (uint32_t) IVAS_RTP_OwnRandom( &rtpEncSeed ) << 16 ); + uint16_t seqNumInitVal = IVAS_RTP_OwnRandom( &rtpEncSeed ); + /*------------------------------------------------------------------------------------------* * Parse command-line arguments *------------------------------------------------------------------------------------------*/ @@ -233,7 +254,7 @@ int main( const BS_WRITER_FORMAT bsWriterFormat = arg.mimeOutput ? BS_WRITER_FORMAT_MIME : BS_WRITER_FORMAT_G192; - if ( BS_Writer_Open_filename( &hBsWriter, arg.outputBitstreamFilename, bsWriterFormat ) != IVAS_ERR_OK ) + if ( !arg.rtpdumpOutput && BS_Writer_Open_filename( &hBsWriter, arg.outputBitstreamFilename, bsWriterFormat ) != IVAS_ERR_OK ) { fprintf( stderr, "\nCan't open %s\n\n", arg.outputBitstreamFilename ); goto cleanup; @@ -432,14 +453,14 @@ int main( if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - exit( -1 ); + goto cleanup; } break; case IVAS_ENC_INPUT_MASA_ISM: if ( ( error = IVAS_ENC_ConfigureForMASAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masa_ism.numObjects, arg.inputFormatConfig.masa_ism.masaVariant ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForMASAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - exit( -1 ); + goto cleanup; } break; default: @@ -591,6 +612,49 @@ int main( } } + /*------------------------------------------------------------------------------------------* + * RTPDump + *------------------------------------------------------------------------------------------*/ + + if ( arg.rtpdumpOutput ) + { + if ( ( error = IVAS_RTP_WRITER_Init( &ivasRtp, arg.outputBitstreamFilename, arg.numFramesPerPacket, ssrc, seqNumInitVal ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open output bitstream file for RTP output %s \n\n", arg.outputBitstreamFilename ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Open scene orientation file + *------------------------------------------------------------------------------------------*/ + + if ( arg.sceneOrientationTrajFileName != NULL ) + { + if ( ( error = RotationFileReader_open( arg.sceneOrientationTrajFileName, &sceneOrientationFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open scene orientation file %s \n\n", arg.sceneOrientationTrajFileName ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Open device orientation file + *------------------------------------------------------------------------------------------*/ + + if ( arg.deviceOrientationTrajFileName != NULL ) + { + if ( ( error = RotationFileReader_open( arg.deviceOrientationTrajFileName, &deviceOrientationFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open device orientation file %s \n\n", arg.deviceOrientationTrajFileName ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Run the encoder + *------------------------------------------------------------------------------------------*/ + int16_t numSamplesRead = 0; uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; uint16_t numBits = 0; @@ -755,17 +819,73 @@ int main( } /* *** Encode one frame *** */ - if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, pcmBuf, pcmBufSize, bitStream, &numBits ) ) != IVAS_ERR_OK ) + if ( ivasRtp.hPack ) { - fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - goto cleanup; - } + bool isMono = ( arg.inputFormat == IVAS_ENC_INPUT_MONO ); + bool forcePacket = ( numSamplesRead < pcmBufSize ); /* If EoF force Packet generation */ + + ivasRtp.nWrittenPiData = 0; + + /* scene orientation */ + if ( sceneOrientationFileReader ) + { + IVAS_PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++]; + IVAS_PIDATA_ORIENTATION *scene = &piDataTs->data.scene; + + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); + scene->size = sizeof( IVAS_PIDATA_ORIENTATION ); + scene->piDataType = IVAS_PI_SCENE_ORIENTATION; + + if ( ( error = HeadRotationFileReading( sceneOrientationFileReader, &scene->orientation, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading scene orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( sceneOrientationFileReader ) ); + goto cleanup; + } + } - /* write bitstream */ - if ( ( error = BS_Writer_WriteFrame_short( hBsWriter, bitStream, numBits, totalBitrate ) ) != IVAS_ERR_OK ) + /* device orientation */ + if ( deviceOrientationFileReader ) + { + IVAS_PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++]; + IVAS_PIDATA_ORIENTATION *device = &piDataTs->data.deviceUnCompensated; + + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); + device->size = sizeof( IVAS_PIDATA_ORIENTATION ); + device->piDataType = IVAS_PI_DEVICE_ORIENTATION_COMPENSATED; + + if ( ( error = HeadRotationFileReading( deviceOrientationFileReader, &device->orientation, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading device orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( deviceOrientationFileReader ) ); + goto cleanup; + } + } + + if ( ( error = IVAS_ENC_EncodeFrameToCompact( hIvasEnc, pcmBuf, pcmBufSize, au, &numBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_RTP_WriteNextFrame( &ivasRtp, au, NULL, numBits, isMono, forcePacket ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while pushing audio frame to RTP pack\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + else { - fprintf( stderr, "\nBS_Writer_WriteFrame_short failed, error code %d\n\n", error ); - goto cleanup; + if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, pcmBuf, pcmBufSize, bitStream, &numBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + /* write bitstream */ + if ( ( error = BS_Writer_WriteFrame_short( hBsWriter, bitStream, numBits, totalBitrate ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nBS_Writer_WriteFrame_short failed, error code %d\n\n", error ); + goto cleanup; + } } frame++; @@ -835,6 +955,18 @@ cleanup: fclose( f_bitrateProfile ); } + if ( sceneOrientationFileReader ) + { + RotationFileReader_close( &sceneOrientationFileReader ); + } + + if ( deviceOrientationFileReader ) + { + RotationFileReader_close( &deviceOrientationFileReader ); + } + + IVAS_RTP_Term( &ivasRtp ); + IVAS_ENC_Close( &hIvasEnc ); #ifdef WMOPS @@ -890,6 +1022,9 @@ static bool parseCmdlIVAS_enc( arg->mimeOutput = false; arg->ism_extended_metadata = false; arg->complexityLevel = IVAS_ENC_COMPLEXITY_LEVEL_THREE; + arg->rtpdumpOutput = false; + arg->sceneOrientationTrajFileName = NULL; + arg->deviceOrientationTrajFileName = NULL; #ifdef DEBUGGING arg->forcedMode = IVAS_ENC_FORCE_UNFORCED; arg->forcedModeFile = NULL; @@ -1668,6 +1803,71 @@ static bool parseCmdlIVAS_enc( i++; } + /*-----------------------------------------------------------------* + * RTPDump output + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-RTPDUMP" ) == 0 ) + { + i++; + arg->rtpdumpOutput = true; + + if ( i < argc - 4 ) + { + if ( !is_digits_only( argv[i] ) ) + { + arg->numFramesPerPacket = 1; /* Default to 1 frame per packet */ + } + else + { + arg->numFramesPerPacket = atoi( argv[i++] ); + if ( arg->numFramesPerPacket > IVAS_MAX_FRAMES_PER_RTP_PACKET ) + { + fprintf( stderr, "numFramesPerPacket(%d) exceeds max frames per packet (%d) \n", arg->numFramesPerPacket, IVAS_MAX_FRAMES_PER_RTP_PACKET ); + arg->numFramesPerPacket = 1; + } + } + } + + fprintf( stdout, "Output format: RTPDump using %d frames/packet \n", arg->numFramesPerPacket ); + } + + /*-----------------------------------------------------------------* + * Scene orientation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-SCENE_ORIENTATION" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Scene orientation file name not specified!\n\n" ); + usage_enc(); + return false; + } + + arg->sceneOrientationTrajFileName = argv[i]; + i++; + } + + /*-----------------------------------------------------------------* + * Device orientation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-DEVICE_ORIENTATION" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Device orientation file name not specified!\n\n" ); + usage_enc(); + return false; + } + + arg->deviceOrientationTrajFileName = argv[i]; + i++; + } + /*-----------------------------------------------------------------* * Option not recognized *-----------------------------------------------------------------*/ @@ -1849,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" ); @@ -1880,6 +2080,12 @@ static void usage_enc( void ) #endif fprintf( stdout, "-q : Quiet mode, no frame counters\n" ); fprintf( stdout, " default is deactivated\n" ); + fprintf( stdout, "-rtpdump : RTPDump output, hf_only=1 by default. The encoder will packetize the \n" ); + fprintf( stdout, " bitstream frames into TS26.253 Annex A IVAS RTP Payload Format packets and \n" ); + fprintf( stdout, " writes those to the output file. In EVS mono operating mode, TS26.445 Annex A.2.2 \n" ); + fprintf( stdout, " EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet\n" ); + fprintf( stdout, "-scene_orientation : Scene orientation trajectory file. Only used with rtpdump output.\n" ); + fprintf( stdout, "-device_orientation : Device orientation trajectory file. Only used with rtpdump output.\n" ); fprintf( stdout, "\n" ); return; diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c new file mode 100644 index 0000000000000000000000000000000000000000..12cc57349ebfe62d144ffb4d9320d9cf3b68d86f --- /dev/null +++ b/apps/encoder_fmtsw.c @@ -0,0 +1,2449 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "stl.h" +#include "lib_enc.h" +#include "cmdl_tools.h" +#include "audio_file_reader.h" +#include "bitstream_writer.h" +#include "ism_file_reader.h" +#include "jbm_file_reader.h" +#include "masa_file_reader.h" +#include "rotation_file_reader.h" +#include "ivas_rtp_file.h" +#include "wmc_auto.h" + + +#ifdef DEBUG_FORCE_DIR +/* Windows does not define the S_ISREG and S_ISDIR macros in stat.h, so we do. + We have to define _CRT_INTERNAL_NONSTDC_NAMES 1 before #including sys/stat.h + in order for Microsoft's stat.h to define names like S_IFMT, S_IFREG, and S_IFDIR, + rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ +#include +#if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) +#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) +#endif +#if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) +#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) +#endif +#endif + +#define WMC_TOOL_SKIP + +/*------------------------------------------------------------------------------------------* + * Local constants, enums + *------------------------------------------------------------------------------------------*/ + +#define MAX_ARGV 20 /* maximum number of command line arguments that can be \ + in one line of the format switching file */ + +#if !defined( DEBUGGING ) && !defined( WMOPS ) +static +#endif + int32_t frame = 0; /* Counter of frames */ + +#define RANDOM_INITSEED_ENC ( 0xDEAF ) + +#define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ + +/* Additional config info for each input format */ +typedef union _EncInputFormatConfig +{ + /* MONO details */ + bool stereoToMonoDownmix; + +#ifdef DEBUGGING + /* STEREO details */ + IVAS_ENC_STEREO_MODE stereoMode; +#endif + + /* ISM details */ + struct EncIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + } ism; + + /* SBA details */ + struct EncSbaConfig + { + IVAS_ENC_SBA_ORDER order; + bool isPlanar; + } sba; + + /* MASA details */ + IVAS_ENC_MASA_VARIANT masaVariant; + + /* MC details */ + IVAS_ENC_MC_LAYOUT mcLayout; + + struct EncMasaIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + IVAS_ENC_MASA_VARIANT masaVariant; + } masa_ism; + + struct EncSbaIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + IVAS_ENC_SBA_ORDER order; + bool isPlanar; + } sba_ism; + +} EncInputFormatConfig; + + +/*------------------------------------------------------------------------------------------* + * Local structure for storing cmdln arguments + *------------------------------------------------------------------------------------------*/ + +typedef struct +{ + char *inputWavFilename; + char *outputBitstreamFilename; + int32_t inputFs; + IVAS_ENC_INPUT_FORMAT inputFormat; + bool is_binaural; + EncInputFormatConfig inputFormatConfig; + bool max_bwidth_user; + IVAS_ENC_BANDWIDTH maxBandwidth; + const char *bandwithProfileFile; + IVAS_ENC_DTX_CONFIG dtxConfig; + int32_t initBitrate; + const char *bitrateProfileFile; + bool quietModeEnabled; + bool delayCompensationEnabled; + const char *masaMetadataFile; + IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig; + const char *ca_config_file; + bool mimeOutput; + IVAS_ENC_COMPLEXITY_LEVEL complexityLevel; +#ifdef DEBUGGING + IVAS_ENC_FORCED_MODE forcedMode; + const char *forcedModeFile; +#ifdef DEBUG_FORCE_DIR + const char *forcedModeDir; +#endif +#endif + bool pca; + bool ism_extended_metadata; + bool rtpdumpOutput; + uint32_t numFramesPerPacket; + char *sceneOrientationTrajFileName; + char *deviceOrientationTrajFileName; + +} EncArguments; + + +/*------------------------------------------------------------------------------------------* + * Local functions prototypes + *------------------------------------------------------------------------------------------*/ + +static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg ); +static void usage_enc( void ); +static bool readBandwidth( FILE *file, IVAS_ENC_BANDWIDTH *bandwidth, int32_t *bandwidthFrameCounter ); +static bool readBitrate( FILE *file, int32_t *bitrate ); +#ifdef DEBUGGING +static ivas_error readForcedMode( FILE *file, IVAS_ENC_FORCED_MODE *forcedMode, int32_t *forceFrameCounter ); +static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar ); +#endif +static void str2arg( char *str, int *argc_local, char *argv_local[] ); +static int encoder_main( int argc, char *argv[], IVAS_RTP *ivasRtp, int init_RtpWriter ); + + +/*------------------------------------------------------------------------------------------* + * main() + * + * Main IVAS encoder function for command-line interface + * supporting IVAS format switching + *------------------------------------------------------------------------------------------*/ + +int main( + int argc, + char *argv[] ) +{ + bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ + FILE *FmtSWFile = NULL; + char line[2048]; + int argc_local = 0; + char *argv_local[MAX_ARGV] = { 0 }; + IVAS_RTP ivasRtp = { 0 }; + char prev_outputBitstreamFilename[2048] = { 0 }; + int rtp_term = 0; + + IVAS_ENC_PrintDisclaimer(); + + if ( argc != 2 ) + { + fprintf( stdout, "Usage: IVAS_cod_fmtsw.exe format_switching_file\n\n" ); + fprintf( stdout, "where format_switching_file is a text file containing a valid encoder command line in each line\n\n" ); + goto cleanup; + } + fprintf( stdout, "Input format switching file: %s\n", argv[1] ); + + if ( ( FmtSWFile = fopen( argv[1], "r" ) ) == NULL ) + { + fprintf( stdout, "error: cannot open format switching file %s\n", argv[1] ); + goto cleanup; + } + + while ( fgets( line, sizeof( line ), FmtSWFile ) ) + { + /* remove trimming newline */ + line[strcspn( line, "\r\n" )] = 0; + printf( "Processing format switching commandline: %s\n", line ); + str2arg( line, &argc_local, argv_local ); + + if ( strcmp( argv_local[argc_local - 1], (char *) prev_outputBitstreamFilename ) == 0 ) + { + /* append to last Rtp file */ + if ( encoder_main( argc_local, argv_local, &ivasRtp, 0 ) != 0 ) + { + goto cleanup; + } + } + else + { + if ( rtp_term == 1 ) + { + IVAS_RTP_Term( &ivasRtp ); + } + + /* write in separate Rtp file */ + if ( encoder_main( argc_local, argv_local, &ivasRtp, 1 ) != 0 ) + { + goto cleanup; + } + + rtp_term = 1; + } + strcpy( (char *) prev_outputBitstreamFilename, argv_local[argc_local - 1] ); + } + + /*------------------------------------------------------------------------------------------* + * Close files and deallocate resources + *------------------------------------------------------------------------------------------*/ + + mainFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ + +cleanup: + + IVAS_RTP_Term( &ivasRtp ); + + if ( FmtSWFile ) + { + fclose( FmtSWFile ); + } + + return mainFailed ? -1 : 0; +} + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +void str2arg( + char *str, /* input string */ + int *argc_local, /* number of argument */ + char *argv_local[] /* array of arguments */ +) +{ + int i = 0; + char *token = strtok( str, " " ); + while ( token && ( i < MAX_ARGV - 1 ) ) + { + argv_local[i++] = token; + token = strtok( 0, " " ); + } + argv_local[i] = 0; + *argc_local = i; + return; +} + +int encoder_main( + int argc, + char *argv[], + IVAS_RTP *ivasRtp, + int init_RtpWriter ) +{ + bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ + EncArguments arg; + int16_t i; + ivas_error error = IVAS_ERR_UNKNOWN; + + /* Any handles that require cleanup must be declared here and initialized to NULL */ + IVAS_ENC_HANDLE hIvasEnc = NULL; + BS_WRITER_HANDLE hBsWriter = NULL; + AudioFileReader *audioReader = NULL; + FILE *f_bitrateProfile = NULL; + FILE *f_bwProfile = NULL; + JbmFileReader *jbmReader = NULL; + MasaFileReader *masaReader = NULL; + IsmFileReader *ismReaders[IVAS_MAX_NUM_OBJECTS] = { NULL, NULL, NULL, NULL }; + int16_t *pcmBuf = NULL; + RotFileReader *sceneOrientationFileReader = NULL; + RotFileReader *deviceOrientationFileReader = NULL; +#ifdef DEBUGGING + FILE *f_forcedModeProfile = NULL; +#endif + +#ifdef WMOPS + reset_wmops(); + reset_mem( USE_BYTES ); +#endif + + uint8_t au[IVAS_MAX_BITS_PER_FRAME / 8]; + /* IVAS_RTP ivasRtp = { 0 }; */ + + /* Ideally ssrc is negotiated via SDP and sequence number is radomized but we + use fixed seed for random num generator for regression based tests. Any realtime + application should implement this initialization seperately */ + uint16_t rtpEncSeed = RANDOM_INITSEED_ENC; + uint32_t ssrc = ( (uint32_t) IVAS_RTP_OwnRandom( &rtpEncSeed ) & 0x0000FFFF ) | ( (uint32_t) IVAS_RTP_OwnRandom( &rtpEncSeed ) << 16 ); + uint16_t seqNumInitVal = IVAS_RTP_OwnRandom( &rtpEncSeed ); + + /*------------------------------------------------------------------------------------------* + * Parse command-line arguments + *------------------------------------------------------------------------------------------*/ + + if ( !parseCmdlIVAS_enc( (int16_t) argc, argv, &arg ) ) + { + /* Error printout done internally in parseCmdlIVAS_enc() */ + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open and initialize IVAS encoder + *------------------------------------------------------------------------------------------*/ + if ( ( error = IVAS_ENC_Open_fx( &hIvasEnc ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + /*------------------------------------------------------------------------------------------* + * Open output bitstream file + *------------------------------------------------------------------------------------------*/ + + const BS_WRITER_FORMAT bsWriterFormat = arg.mimeOutput ? BS_WRITER_FORMAT_MIME : BS_WRITER_FORMAT_G192; + + if ( !arg.rtpdumpOutput && BS_Writer_Open_filename( &hBsWriter, arg.outputBitstreamFilename, bsWriterFormat ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nCan't open %s\n\n", arg.outputBitstreamFilename ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Print out file names + *------------------------------------------------------------------------------------------*/ + + if ( arg.inputFormat == IVAS_ENC_INPUT_ISM || arg.inputFormat == IVAS_ENC_INPUT_SBA_ISM ) + { + for ( i = 0; i < arg.inputFormatConfig.ism.numObjects; i++ ) + { + fprintf( stdout, "Object %d input metadata: %s\n", i + 1, arg.inputFormatConfig.ism.metadataFiles[i] ); + } + } + + if ( arg.masaMetadataFile != NULL ) + { + fprintf( stdout, "MASA inp. metadata file: %s\n", arg.masaMetadataFile ); + } + + fprintf( stdout, "Input audio file: %s\n", arg.inputWavFilename ); + fprintf( stdout, "Output bitstream file: %s\n\n", arg.outputBitstreamFilename ); + + /*------------------------------------------------------------------------------------------* + * Open auxiliary input files + *------------------------------------------------------------------------------------------*/ + + int32_t totalBitrate = arg.initBitrate; + + if ( arg.bitrateProfileFile ) + { + if ( ( f_bitrateProfile = fopen( arg.bitrateProfileFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "Error: bitrate profile file %s could not be opened\n\n", arg.bitrateProfileFile ); + usage_enc(); + goto cleanup; + } + + if ( !readBitrate( f_bitrateProfile, &totalBitrate ) ) + { + fprintf( stderr, "Error: bitrate profile file %s could not be read\n\n", arg.bitrateProfileFile ); + goto cleanup; + } + rewind( f_bitrateProfile ); + + fprintf( stdout, "Bitrate switching file: %s\n", arg.bitrateProfileFile ); + } + + int32_t bandwidthFrameCounter = 0; + IVAS_ENC_BANDWIDTH bandwidth = arg.maxBandwidth; + + if ( arg.bandwithProfileFile ) + { + if ( ( f_bwProfile = fopen( arg.bandwithProfileFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "Error: incorrect bandwidth specification or the bandwidth profile file could not be opened: %s\n\n", arg.bandwithProfileFile ); + usage_enc(); + goto cleanup; + } + fprintf( stdout, "Bandwidth switching file: %s\n", arg.bandwithProfileFile ); + + if ( !readBandwidth( f_bwProfile, &bandwidth, &bandwidthFrameCounter ) ) + { + fprintf( stderr, "Error: bandwidth switching file %s could not be read\n\n", arg.bandwithProfileFile ); + goto cleanup; + } + rewind( f_bwProfile ); + bandwidthFrameCounter = 0; + } + else + { + if ( bandwidth == IVAS_ENC_BANDWIDTH_NB && arg.inputFormat != IVAS_ENC_INPUT_MONO ) + { + fprintf( stdout, "\nNB coding not supported in IVAS. Switching to WB.\n\n" ); + } + else + { + switch ( bandwidth ) + { + case IVAS_ENC_BANDWIDTH_UNDEFINED: + break; + case IVAS_ENC_BANDWIDTH_NB: + fprintf( stdout, "Max. encoded bandwidth: NB\n" ); + break; + case IVAS_ENC_BANDWIDTH_WB: + fprintf( stdout, "Max. encoded bandwidth: WB\n" ); + break; + case IVAS_ENC_BANDWIDTH_SWB: + fprintf( stdout, "Max. encoded bandwidth: SWB\n" ); + break; + case IVAS_ENC_BANDWIDTH_FB: + fprintf( stdout, "Max. encoded bandwidth: FB\n" ); + break; + default: + fprintf( stderr, "Error: Invalid bandwidth value\n" ); + usage_enc(); + goto cleanup; + } + } + } + + /*------------------------------------------------------------------------------------------* + * Handle Channel-aware mode + *------------------------------------------------------------------------------------------*/ + + IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig = arg.caConfig; + + if ( arg.ca_config_file ) + { + if ( ( jbmReader = JbmFileReader_open( arg.ca_config_file ) ) == NULL ) + { + fprintf( stderr, "\nError: Channel aware configuration file could not be opened: %s\n\n", arg.ca_config_file ); + usage_enc(); + goto cleanup; + } + + fprintf( stdout, "Channel-aware mode: ON, config file: %s \n", arg.ca_config_file ); + } + else if ( caConfig.channelAwareModeEnabled ) + { + fprintf( stdout, "Channel-aware mode: ON, FEC indicator : %s FEC offset: %d \n\n", ( caConfig.fec_indicator == IVAS_ENC_FEC_LO ) ? "LO" : "HI", caConfig.fec_offset ); + } + + if ( arg.inputFormat != IVAS_ENC_INPUT_MONO && ( caConfig.channelAwareModeEnabled || arg.ca_config_file ) ) + { + fprintf( stderr, "Channel-aware mode is not supported in IVAS.\n\n" ); + usage_enc(); + goto cleanup; + } + +#ifdef SUPPORT_FORCE_TCX10_TCX20 +#ifdef DEBUGGING + if ( arg.forcedMode == IVAS_ENC_FORCE_TCX10 && totalBitrate < 48000 ) + { + fprintf( stderr, "Warning: Enforcing the TCX10 mode is only supported for bitrates higher or equal than 48 kbps!\n\n" ); + } +#endif +#endif + + /*------------------------------------------------------------------------------------------* + * Configure and initialize (allocate memory for static variables) the encoder + *------------------------------------------------------------------------------------------*/ + + switch ( arg.inputFormat ) + { + case IVAS_ENC_INPUT_MONO: + if ( ( error = IVAS_ENC_ConfigureForMono( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, caConfig, arg.inputFormatConfig.stereoToMonoDownmix, arg.is_binaural ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMono failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_STEREO: +#ifdef DEBUGGING + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural, arg.inputFormatConfig.stereoMode ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForStereo failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_ISM: + if ( ( error = IVAS_ENC_ConfigureForObjects( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.ism.numObjects, arg.ism_extended_metadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_SBA: + if ( ( error = IVAS_ENC_ConfigureForAmbisonics( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba.order, arg.inputFormatConfig.sba.isPlanar, + arg.pca ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForAmbisonics failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_MASA: + if ( ( error = IVAS_ENC_ConfigureForMasa( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masaVariant ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMasa failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_MC: + if ( ( error = IVAS_ENC_ConfigureForMultichannel( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.mcLayout ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMultichannel failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_SBA_ISM: + if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_MASA_ISM: + if ( ( error = IVAS_ENC_ConfigureForMASAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masa_ism.numObjects, arg.inputFormatConfig.masa_ism.masaVariant ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMASAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + default: + fprintf( stderr, "\nInvalid input type\n\n" ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_PrintConfig( hIvasEnc, caConfig.channelAwareModeEnabled ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\n IVAS_ENC_PrintConfig failed %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open input audio file + *------------------------------------------------------------------------------------------*/ + + if ( AudioFileReader_open( &audioReader, arg.inputWavFilename ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nCan't open %s\n\n", arg.inputWavFilename ); + goto cleanup; + } + + /* Validate input sampling rate */ + int32_t inFileSampleRate = 0; + error = AudioFileReader_getSamplingRate( audioReader, &inFileSampleRate ); + switch ( error ) + { + case IVAS_ERR_OK: + if ( inFileSampleRate != arg.inputFs ) + { + fprintf( stderr, "\nSampling rate mismatch: %d Hz requested, but %d Hz found in file %s\n\n", arg.inputFs, inFileSampleRate, arg.inputWavFilename ); + goto cleanup; + } + break; + case IVAS_ERR_SAMPLING_RATE_UNKNOWN: + /* IVAS_ERR_SAMPLING_RATE_UNKNOWN will be returned for raw PCM files. + * Nothing to check here */ + break; + default: + fprintf( stderr, "\nError: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + + /* Validate number of channels */ + int16_t encInNumChannels = 0; + if ( ( error = IVAS_ENC_GetNumInChannels( hIvasEnc, &encInNumChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + + int16_t inFileNumChannels = 0; + error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels ); + switch ( error ) + { + case IVAS_ERR_OK: + if ( inFileNumChannels != encInNumChannels ) + { + fprintf( stderr, "\nNumber of input audio channels mismatch: %d accepted by encoder, but %d found in file %s\n\n", encInNumChannels, inFileNumChannels, arg.inputWavFilename ); + goto cleanup; + } + break; + case IVAS_ERR_NUM_CHANNELS_UNKNOWN: + /* IVAS_ERR_NUM_CHANNELS_UNKNOWN will be returned for raw PCM files. + * Nothing to check here */ + break; + default: + fprintf( stderr, "\nError: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open input metadata files + *------------------------------------------------------------------------------------------*/ + + if ( arg.masaMetadataFile ) + { + if ( ( masaReader = MasaFileReader_open( arg.masaMetadataFile ) ) == NULL ) + { + fprintf( stderr, "\nError: MASA input metadata file %s could not be opened\n\n", arg.masaMetadataFile ); + usage_enc(); + goto cleanup; + } + } + + const int16_t numIsmInputs = ( arg.inputFormat == IVAS_ENC_INPUT_ISM || arg.inputFormat == IVAS_ENC_INPUT_MASA_ISM || arg.inputFormat == IVAS_ENC_INPUT_SBA_ISM ) ? arg.inputFormatConfig.ism.numObjects : 0; + + for ( i = 0; i < numIsmInputs; ++i ) + { + if ( arg.inputFormatConfig.ism.metadataFiles[i] != NULL ) + { + if ( ( ismReaders[i] = IsmFileReader_open( arg.inputFormatConfig.ism.metadataFiles[i] ) ) == NULL ) + { + fprintf( stderr, "\nError: ISM input metadata file %s could not be opened\n\n", arg.inputFormatConfig.ism.metadataFiles[i] ); + usage_enc(); + goto cleanup; + } + } + } + +#ifdef DEBUGGING + IVAS_ENC_FORCED_MODE forcedMode = arg.forcedMode; + int32_t force_profile_cnt = 0; + + if ( arg.forcedModeFile ) + { + if ( ( f_forcedModeProfile = fopen( arg.forcedModeFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "\nError: Incorrect mode specification or the profile file could not be opened: %s\n\n", arg.forcedModeFile ); + usage_enc(); + goto cleanup; + } + } +#endif + + /*------------------------------------------------------------------------------------------* + * Allocate input data buffer + *------------------------------------------------------------------------------------------*/ + + int16_t pcmBufSize; + if ( ( error = IVAS_ENC_GetInputBufferSize( hIvasEnc, &pcmBufSize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetInputBufferSize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) ); + + /*------------------------------------------------------------------------------------------* + * Compensate for encoder delay (bitstream aligned with input signal) + *------------------------------------------------------------------------------------------*/ + + int16_t encDelayInSamples; + if ( ( error = IVAS_ENC_GetDelay( hIvasEnc, &encDelayInSamples ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetDelay failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( arg.delayCompensationEnabled && encDelayInSamples ) + { + /* read samples and throw them away */ + int16_t numSamplesRead = 0; + if ( ( error = AudioFileReader_read( audioReader, pcmBuf, encDelayInSamples, &numSamplesRead ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file %s\n%s\n", arg.inputWavFilename, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * RTPDump + *------------------------------------------------------------------------------------------*/ + + if ( arg.rtpdumpOutput && init_RtpWriter ) + { + if ( ( error = IVAS_RTP_WRITER_Init( ivasRtp, arg.outputBitstreamFilename, arg.numFramesPerPacket, ssrc, seqNumInitVal ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open output bitstream file for RTP output %s \n\n", arg.outputBitstreamFilename ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Open scene orientation file + *------------------------------------------------------------------------------------------*/ + + if ( arg.sceneOrientationTrajFileName != NULL ) + { + if ( ( error = RotationFileReader_open( arg.sceneOrientationTrajFileName, &sceneOrientationFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open scene orientation file %s \n\n", arg.sceneOrientationTrajFileName ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Open device orientation file + *------------------------------------------------------------------------------------------*/ + + if ( arg.deviceOrientationTrajFileName != NULL ) + { + if ( ( error = RotationFileReader_open( arg.deviceOrientationTrajFileName, &deviceOrientationFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open device orientation file %s \n\n", arg.deviceOrientationTrajFileName ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Run the encoder + *------------------------------------------------------------------------------------------*/ + + int16_t numSamplesRead = 0; + uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; + uint16_t numBits = 0; + + if ( !arg.quietModeEnabled ) + { + fprintf( stdout, "\n------ Running the encoder ------\n\n" ); + fprintf( stdout, "Frames processed: " ); + } + else + { + fprintf( stdout, "\n\n-- Start the encoder (quiet mode) --\n\n" ); + } + +#ifdef WMOPS + reset_stack(); + reset_wmops(); +#endif + + /*------------------------------------------------------------------------------------------* + * Loop for every frame of input data + * - Read the input data + * - Process switching files + * - Read input metadata + * - Run the encoder + * - Write the parameters into output bitstream file + *------------------------------------------------------------------------------------------*/ + + while ( 1 ) + { + /* Read the input data */ + if ( ( error = AudioFileReader_read( audioReader, pcmBuf, pcmBufSize, &numSamplesRead ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file %s\n%s\n", arg.inputWavFilename, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( numSamplesRead == 0 ) + { + /* end of input data */ + break; + } + + /* Zero-pad if not enough samples were read (expected in last frame) */ + if ( numSamplesRead < pcmBufSize ) + { + for ( i = numSamplesRead; i < pcmBufSize; ++i ) + { + pcmBuf[i] = 0; + } + } + + /* Process switching files */ + if ( f_bitrateProfile ) + { + if ( !readBitrate( f_bitrateProfile, &totalBitrate ) ) + { + fprintf( stderr, "Error: bitrate profile file %s could not be read\n\n", arg.bitrateProfileFile ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_SetBitrate( hIvasEnc, totalBitrate ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetBitrate failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( f_bwProfile ) + { + if ( !readBandwidth( f_bwProfile, &bandwidth, &bandwidthFrameCounter ) ) + { + fprintf( stderr, "Error: bandwidth switching file %s could not be read\n\n", arg.bandwithProfileFile ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_SetBandwidth( hIvasEnc, bandwidth ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetBandwidth failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( jbmReader ) + { + if ( ( error = JbmFileReader_readCAconfig( jbmReader, &caConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError (%s) while reading Channel-Aware Config. from: %s\n\n", IVAS_ENC_GetErrorMessage( error ), JbmFileReader_getFilePath( jbmReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_SetChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "IVAS_ENC_SetChannelAwareConfig failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + +#ifdef DEBUGGING + if ( f_forcedModeProfile ) + { + if ( ( error = readForcedMode( f_forcedModeProfile, &forcedMode, &force_profile_cnt ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file: %s\n%s\n", arg.forcedModeFile, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* Force mode not set when configuring, set in first frame even if not reading from file */ + if ( f_forcedModeProfile || frame == 0 ) + { + if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode +#ifdef DEBUG_FORCE_DIR + , + arg.forcedModeDir +#endif + ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetForcedMode failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif + + /* Read ISM input metadata */ + for ( i = 0; i < numIsmInputs; ++i ) + { + if ( ismReaders[i] == NULL ) + { + continue; + } + + IVAS_ISM_METADATA ismMetadata; + if ( ( error = IsmFileReader_readNextFrame( ismReaders[i], &ismMetadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError (%s) while reading ism metadata from: %s\n\n", IVAS_ENC_GetErrorMessage( error ), IsmFileReader_getFilePath( ismReaders[i] ) ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_FeedObjectMetadata( hIvasEnc, i, ismMetadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nfeed_ISM_metadata failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* Read MASA input metadata */ + if ( masaReader ) + { + if ( ( error = MasaFileReader_readNextFrame( masaReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError (%s) while reading masa metadata from: %s\n\n", IVAS_ENC_GetErrorMessage( error ), arg.masaMetadataFile ); + goto cleanup; + } + IVAS_MASA_METADATA_HANDLE hMetadata = MasaFileReader_getMetadataHandle( masaReader ); + + if ( ( error = IVAS_ENC_FeedMasaMetadata( hIvasEnc, hMetadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nfeed_MASA_frame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* *** Encode one frame *** */ + if ( ivasRtp->hPack ) + { + bool isMono = ( arg.inputFormat == IVAS_ENC_INPUT_MONO ); + bool forcePacket = ( numSamplesRead < pcmBufSize ); /* If EoF force Packet generation */ + + ivasRtp->nWrittenPiData = 0; + + /* scene orientation */ + if ( sceneOrientationFileReader ) + { + IVAS_PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; + IVAS_PIDATA_ORIENTATION *scene = &piDataTs->data.scene; + + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); + scene->size = sizeof( IVAS_PIDATA_ORIENTATION ); + scene->piDataType = IVAS_PI_SCENE_ORIENTATION; + + if ( ( error = HeadRotationFileReading( sceneOrientationFileReader, &scene->orientation, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading scene orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( sceneOrientationFileReader ) ); + goto cleanup; + } + } + + /* device orientation */ + if ( deviceOrientationFileReader ) + { + IVAS_PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; + IVAS_PIDATA_ORIENTATION *device = &piDataTs->data.deviceUnCompensated; + + memset( piDataTs, 0, sizeof( IVAS_PIDATA_TS ) ); + device->size = sizeof( IVAS_PIDATA_ORIENTATION ); + device->piDataType = IVAS_PI_DEVICE_ORIENTATION_COMPENSATED; + + if ( ( error = HeadRotationFileReading( deviceOrientationFileReader, &device->orientation, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading device orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( deviceOrientationFileReader ) ); + goto cleanup; + } + } + + if ( ( error = IVAS_ENC_EncodeFrameToCompact( hIvasEnc, pcmBuf, pcmBufSize, au, &numBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_RTP_WriteNextFrame( ivasRtp, au, NULL, numBits, isMono, forcePacket ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while pushing audio frame to RTP pack\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + else + { + if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, pcmBuf, pcmBufSize, bitStream, &numBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + /* write bitstream */ + if ( ( error = BS_Writer_WriteFrame_short( hBsWriter, bitStream, numBits, totalBitrate ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nBS_Writer_WriteFrame_short failed, error code %d\n\n", error ); + goto cleanup; + } + } + + frame++; + if ( !arg.quietModeEnabled ) + { + fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); + } + +#ifdef WMOPS + update_mem(); + update_wmops(); +#endif + } + + if ( arg.quietModeEnabled ) + { + fprintf( stdout, "Encoding finished\n" ); + } + else + { + fprintf( stdout, "\n\nEncoding of %d frames finished\n", frame ); + } + + /*------------------------------------------------------------------------------------------* + * Close files and deallocate resources + *------------------------------------------------------------------------------------------*/ + + mainFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ + +cleanup: + + free( pcmBuf ); + + if ( ( error = BS_Writer_Close( &hBsWriter ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Can't close bitstream writer, error code %d\n", error ); + mainFailed = true; + } + + AudioFileReader_close( &audioReader ); + + if ( jbmReader ) + { + JbmFileReader_close( &jbmReader ); + } + + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) + { + if ( ismReaders[i] != NULL ) + { + IsmFileReader_close( &ismReaders[i] ); + } + } + + if ( masaReader ) + { + MasaFileReader_close( &masaReader ); + } + + if ( f_bwProfile ) + { + fclose( f_bwProfile ); + } + + if ( f_bitrateProfile ) + { + fclose( f_bitrateProfile ); + } + + if ( sceneOrientationFileReader ) + { + RotationFileReader_close( &sceneOrientationFileReader ); + } + + if ( deviceOrientationFileReader ) + { + RotationFileReader_close( &deviceOrientationFileReader ); + } + + /* IVAS_RTP_Term( &ivasRtp ); */ + + IVAS_ENC_Close( &hIvasEnc ); + +#ifdef WMOPS + print_wmops(); + print_mem( NULL ); +#endif + + return mainFailed ? -1 : 0; +} + + +/*---------------------------------------------------------------------* + * parseCmdlIVAS_enc() + * + * Encoder command-line parsing + *---------------------------------------------------------------------*/ + +static bool parseCmdlIVAS_enc( + int16_t argc, + char *argv[], + EncArguments *arg ) +{ + int16_t i, j; + char argv_to_upper[FILENAME_MAX]; + char stmp[FILENAME_MAX]; + int32_t tmp; + + /*-----------------------------------------------------------------* + * Set default values + *-----------------------------------------------------------------*/ + + arg->inputWavFilename = NULL; + arg->outputBitstreamFilename = NULL; + arg->inputFs = 0; + arg->inputFormat = IVAS_ENC_INPUT_MONO; + arg->is_binaural = false; + arg->inputFormatConfig.stereoToMonoDownmix = false; + arg->max_bwidth_user = false; + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_UNDEFINED; + arg->bandwithProfileFile = NULL; + arg->dtxConfig = IVAS_ENC_GetDefaultDtxConfig(); + arg->initBitrate = 0; + arg->bitrateProfileFile = NULL; + arg->quietModeEnabled = false; + arg->delayCompensationEnabled = true; + arg->masaMetadataFile = NULL; + arg->caConfig = IVAS_ENC_GetDefaultChannelAwareConfig(); + arg->ca_config_file = NULL; + arg->mimeOutput = false; + arg->ism_extended_metadata = false; + arg->complexityLevel = IVAS_ENC_COMPLEXITY_LEVEL_THREE; + arg->rtpdumpOutput = false; + arg->sceneOrientationTrajFileName = NULL; + arg->deviceOrientationTrajFileName = NULL; +#ifdef DEBUGGING + arg->forcedMode = IVAS_ENC_FORCE_UNFORCED; + arg->forcedModeFile = NULL; +#ifdef DEBUG_FORCE_DIR + arg->forcedModeDir = NULL; +#endif +#endif + arg->pca = false; + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + if ( argc < 5 ) + { + fprintf( stderr, "Error: Not enough input parameters. Exiting!\n\n" ); + usage_enc(); + return false; + } + + /*-----------------------------------------------------------------* + * Optional input arguments + *-----------------------------------------------------------------*/ + + i = 1; + while ( i < argc - 4 ) + { + strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 ); + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; + to_upper( argv_to_upper ); + + /*-----------------------------------------------------------------* + * Bandwidth limitation + *-----------------------------------------------------------------*/ + + if ( strcmp( argv_to_upper, "-MAX_BAND" ) == 0 ) + { + arg->max_bwidth_user = true; + + strncpy( stmp, argv[i + 1], sizeof( stmp ) - 1 ); + stmp[sizeof( stmp ) - 1] = '\0'; + to_upper( stmp ); + + if ( strcmp( stmp, "-NB" ) == 0 || strcmp( stmp, "NB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_NB; + } + else if ( strcmp( stmp, "-WB" ) == 0 || strcmp( stmp, "WB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_WB; + } + else if ( strcmp( stmp, "-SWB" ) == 0 || strcmp( stmp, "SWB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_SWB; + } + else if ( strcmp( stmp, "-FB" ) == 0 || strcmp( stmp, "FB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_FB; + } + else + { + arg->bandwithProfileFile = argv[i + 1]; + } + + i += 2; + } + + /*-----------------------------------------------------------------* + * Quiet mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-Q" ) == 0 ) + { + i++; + arg->quietModeEnabled = true; + } + + /*-----------------------------------------------------------------* + * DTX/CNG + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-DTX" ) == 0 ) + { + i++; + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) <= 0 ) + { + tmp = DEFAULT_FIXED_SID_RATE; + } + else + { + i++; + } + } + else + { + tmp = DEFAULT_FIXED_SID_RATE; + } + + arg->dtxConfig.enabled = true; + + if ( tmp == 0 ) + { + arg->dtxConfig.variable_SID_rate = true; + arg->dtxConfig.SID_interval = 0; + } + else if ( tmp >= 3 && tmp <= 100 ) + { + arg->dtxConfig.variable_SID_rate = false; + arg->dtxConfig.SID_interval = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Incorrect SID update interval specified: %d (supported 3-100)\n\n", tmp ); + usage_enc(); + return false; + } + } +#ifdef DEBUGGING + /*-----------------------------------------------------------------* + * Force specific mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-FORCE" ) == 0 ) + { + strncpy( stmp, argv[i + 1], sizeof( stmp ) ); + + arg->forcedMode = parseForcedMode( stmp ); + +#ifdef DEBUG_FORCE_DIR + if ( arg->forcedMode < IVAS_ENC_FORCE_FILE ) + { + fprintf( stdout, "Forcing codec to: %s\n", argv[i + 1] ); + } + else if ( arg->forcedMode == IVAS_ENC_FORCE_FILE ) + { + arg->forcedModeFile = argv[i + 1]; + fprintf( stdout, "Force switching file: %s\n", argv[i + 1] ); + } + else if ( arg->forcedMode == IVAS_ENC_FORCE_DIR ) + { + arg->forcedModeDir = argv[i + 1]; + fprintf( stdout, "Forcing switching directory: %s\n", argv[i + 1] ); + } + else + { + fprintf( stderr, "\nError: The force switching profile file/dir %s does not exist or could not be opened!\n\n", argv[i + 1] ); + usage_enc(); + return false; + } +#else + if ( arg->forcedMode == IVAS_ENC_FORCE_UNDEFINED ) + { + arg->forcedModeFile = argv[i + 1]; + fprintf( stdout, "Force switching file: %s\n", argv[i + 1] ); + } + else + { +#ifdef SUPPORT_FORCE_TCX10_TCX20 + if ( arg->forcedMode == IVAS_ENC_FORCE_TCX10 ) + { + strcpy( stmp, "TCX10" ); + } + else if ( arg->forcedMode == IVAS_ENC_FORCE_TCX20 ) + { + strcpy( stmp, "TCX20" ); + } + else + { + strncpy( stmp, argv[i + 1], sizeof( stmp ) ); + } + + fprintf( stdout, "Forcing codec to: %s\n", stmp ); +#else + fprintf( stdout, "Forcing codec to: %s\n", argv[i + 1] ); +#endif + } +#endif + + i += 2; + } +#ifdef DEBUG_MODE_INFO +#ifdef DEBUG_MODE_INFO_TWEAK + /*-----------------------------------------------------------------* + * Define additional subfolder for debug info output in ./res + *-----------------------------------------------------------------*/ + else if ( strcmp( argv_to_upper, "-INFO" ) == 0 ) + { + extern char infoFolder[FILENAME_MAX]; + strncpy( infoFolder, argv[i + 1], sizeof( infoFolder ) ); + i += 2; + } +#endif /* #ifdef DEBUG_MODE_INFO_TWEAK */ +#endif /* #ifdef DEBUG_MODE_INFO */ +#endif /* #ifdef DEBUGGING */ + + /*-----------------------------------------------------------------* + * deactivate delay compensation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-NO_DELAY_CMP" ) == 0 ) + { + arg->delayCompensationEnabled = false; + i++; + } + + /*-----------------------------------------------------------------* + * Activate channel-aware mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-RF" ) == 0 ) + { + arg->caConfig.channelAwareModeEnabled = 1; + i++; + + if ( i < argc - 4 ) + { + strncpy( stmp, argv[i], sizeof( stmp ) ); + stmp[sizeof( stmp ) - 1] = '\0'; + to_upper( stmp ); + if ( strcmp( stmp, "LO" ) == 0 ) + { + arg->caConfig.fec_indicator = IVAS_ENC_FEC_LO; + } + else if ( strcmp( stmp, "HI" ) == 0 ) + { + arg->caConfig.fec_indicator = IVAS_ENC_FEC_HI; + } + else + { + arg->ca_config_file = argv[i]; + } + i++; + + if ( ( sscanf( argv[i], "%d", &tmp ) == 1 ) && ( i < argc - 4 ) ) + { + if ( tmp == 0 ) + { + arg->caConfig.channelAwareModeEnabled = 0; + arg->caConfig.fec_offset = 0; + i++; + } + else + { + arg->caConfig.fec_offset = (int16_t) tmp; + i++; + } + } + } + else + { + arg->caConfig.fec_indicator = IVAS_ENC_FEC_HI; + } + } + + /*-----------------------------------------------------------------* + * MIME output file format + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-MIME" ) == 0 ) + { + arg->mimeOutput = true; + fprintf( stdout, "Output bitstream file format: MIME\n" ); + ++i; + } + + + /*-----------------------------------------------------------------* + * Complexity Level + *-----------------------------------------------------------------*/ + + /* actual parsing of level will be implemented after characterization */ + else if ( strcmp( argv_to_upper, "-LEVEL" ) == 0 ) + { + int16_t level; + + ++i; + level = (int16_t) atoi( argv[i++] ); + if ( level < IVAS_ENC_COMPLEXITY_LEVEL_ONE || level > IVAS_ENC_COMPLEXITY_LEVEL_THREE ) + { + fprintf( stdout, "Invalid complexity level specified.\n" ); + usage_enc(); + return false; + } + else if ( level == IVAS_ENC_COMPLEXITY_LEVEL_ONE || level == IVAS_ENC_COMPLEXITY_LEVEL_TWO ) + { + fprintf( stdout, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" ); + } + } + + /*-----------------------------------------------------------------* + * IVAS Formats + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-STEREO" ) == 0 ) + { + i++; + arg->inputFormat = IVAS_ENC_INPUT_STEREO; + +#ifdef DEBUGGING + if ( ( i < argc - 4 ) && argv[i][0] != 45 ) /* note: 45 corresponds to "-" */ + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + if ( tmp == 1 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_DFT; + i++; + } + else if ( tmp == 2 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_TD; + i++; + } + else if ( tmp == 3 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_DECISION; +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + i++; + + /* force mdct stereo mode for debugging purposes */ + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + if ( tmp == 0 ) + { + /* keep "DECISION" */ + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_DECISION; + i++; + } + else if ( tmp == 1 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR; + i++; + } + else if ( tmp == 2 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS; + i++; + } + else + { + fprintf( stderr, "Error: Incorrect mdct stereo coding method (%d) specified\n\n", tmp ); + usage_enc(); + return false; + } + } + } +#endif + } + else + { + fprintf( stderr, "Error: Incorrect stereo mode (%d) specified\n\n", tmp ); + usage_enc(); + return false; + } + } + else + { + fprintf( stderr, "Error: Stereo mode not specified.\n\n" ); /* in the debugging stage */ + usage_enc(); + return false; + } + } + else + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_UNIFIED; + } +#endif /* DEBUGGING */ + } + else if ( strcmp( argv_to_upper, "-BINAURAL" ) == 0 ) + { + arg->is_binaural = true; + i++; + } + else if ( strcmp( argv_to_upper, "-ISM" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_ISM; + i++; + + if ( i < argc - 4 ) + { + if ( argv[i][0] == '+' ) + { + argv[i]++; + arg->ism_extended_metadata = true; + } + if ( !is_digits_only( argv[i] ) ) + { + fprintf( stderr, "Error: Number of ISM channels must be an integer number!\n\n" ); + usage_enc(); + return false; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else if ( tmp > IVAS_MAX_NUM_OBJECTS ) + { + fprintf( stderr, "Error: Too high number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else + { + arg->inputFormatConfig.ism.numObjects = (int16_t) tmp; + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + return false; + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough metadata arguments specified!\n\n" ); + usage_enc(); + return false; + } + } + } + else if ( strcmp( argv_to_upper, "-SBA" ) == 0 ) + { + i++; + arg->inputFormat = IVAS_ENC_INPUT_SBA; + + /* SBA configuration */ + if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + else + { + tmp = -1; /* this is to avoid a compilation warning */ + fprintf( stderr, "Error: SBA order must be specified, expecting a number!\n\n" ); + usage_enc(); + return false; + } + + arg->inputFormatConfig.sba.isPlanar = ( tmp < 0 ); + + tmp = abs( tmp ); + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.sba.order = IVAS_ENC_SBA_FOA; + break; + case 2: + arg->inputFormatConfig.sba.order = IVAS_ENC_SBA_HOA2; + break; + case 3: + arg->inputFormatConfig.sba.order = IVAS_ENC_SBA_HOA3; + break; + default: + fprintf( stderr, "Error: Wrong SBA order specified!\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( argv_to_upper, "-MASA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MASA; + i++; + + if ( i < argc - 4 ) + { + if ( !is_digits_only( argv[i] ) ) + { + fprintf( stderr, "Error: Number of MASA channels must be an integer number!\n\n" ); + usage_enc(); + return false; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.masaVariant = IVAS_ENC_MASA_1CH; + break; + case 2: + arg->inputFormatConfig.masaVariant = IVAS_ENC_MASA_2CH; + break; + default: + fprintf( stderr, "Error: MASA channels must be 1 or 2.\n\n" ); + usage_enc(); + return false; + } + } + + if ( i < argc - 4 ) + { + arg->masaMetadataFile = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: not enough MASA arguments\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( argv_to_upper, "-MC" ) == 0 ) + { + i++; + arg->inputFormat = IVAS_ENC_INPUT_MC; + + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "5_1" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1; + } + else if ( strcmp( argv[i], "7_1" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_7_1; + } + else if ( strcmp( argv[i], "5_1_2" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_2; + } + else if ( strcmp( argv[i], "5_1_4" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_4; + } + else if ( strcmp( argv[i], "7_1_4" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_7_1_4; + } + else + { + fprintf( stderr, "Error: Incorrect input configuration specified for Multi-channel\n\n" ); + usage_enc(); + return false; + } + i++; + } + else + { + fprintf( stderr, "Error: Multi-channel configuration not specified!\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( to_upper( argv[i] ), "-ISM_MASA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MASA_ISM; + i++; + + if ( i < argc - 5 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else + { + if ( tmp <= IVAS_MAX_NUM_OBJECTS ) /* number of ISM channels */ + { + arg->inputFormatConfig.masa_ism.numObjects = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Too high number of ISM channels!\n\n" ); + usage_enc(); + return false; + } + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + return false; + } + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.masa_ism.masaVariant = IVAS_ENC_MASA_1CH; + break; + case 2: + arg->inputFormatConfig.masa_ism.masaVariant = IVAS_ENC_MASA_2CH; + break; + default: + fprintf( stderr, "Error: MASA channels must be 1 or 2.\n\n" ); + usage_enc(); + return false; + } + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.masa_ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.masa_ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.masa_ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough arguments\n\n" ); + usage_enc(); + return false; + } + } + + if ( i < argc - 4 ) + { + arg->masaMetadataFile = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: not enough MASA arguments\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( to_upper( argv[i] ), "-ISM_SBA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_SBA_ISM; + i++; + + if ( i < argc - 5 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else + { + if ( tmp <= IVAS_MAX_NUM_OBJECTS ) /* number of ISM channels */ + { + arg->inputFormatConfig.sba_ism.numObjects = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Too high number of ISM channels!\n\n" ); + usage_enc(); + return false; + } + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + return false; + } + + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + arg->inputFormatConfig.sba_ism.isPlanar = ( tmp < 0 ); + + tmp = abs( tmp ); + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.sba_ism.order = IVAS_ENC_SBA_FOA; + break; + case 2: + arg->inputFormatConfig.sba_ism.order = IVAS_ENC_SBA_HOA2; + break; + case 3: + arg->inputFormatConfig.sba_ism.order = IVAS_ENC_SBA_HOA3; + break; + default: + fprintf( stderr, "Error: Wrong SBA order specified!\n\n" ); + usage_enc(); + return false; + } + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.sba_ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.sba_ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.sba_ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough arguments\n\n" ); + usage_enc(); + return false; + } + } + } + else if ( strcmp( argv_to_upper, "-STEREO_DMX_EVS" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MONO; + arg->inputFormatConfig.stereoToMonoDownmix = true; + + i++; + } + else if ( strcmp( argv_to_upper, "-PCA" ) == 0 ) + { + arg->pca = 1; + i++; + } + + /*-----------------------------------------------------------------* + * RTPDump output + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-RTPDUMP" ) == 0 ) + { + i++; + arg->rtpdumpOutput = true; + if ( i < argc - 4 ) + { + if ( !is_digits_only( argv[i] ) ) + { + arg->numFramesPerPacket = 1; /* Default to 1 frame per packet */ + } + else + { + arg->numFramesPerPacket = atoi( argv[i++] ); + if ( arg->numFramesPerPacket > IVAS_MAX_FRAMES_PER_RTP_PACKET ) + { + fprintf( stderr, "numFramesPerPacket(%d) exceeds max frames per packet (%d) \n", arg->numFramesPerPacket, IVAS_MAX_FRAMES_PER_RTP_PACKET ); + arg->numFramesPerPacket = 1; + } + } + } + fprintf( stdout, "Output format: RTPDump using %d frames/packet \n", arg->numFramesPerPacket ); + } + + /*-----------------------------------------------------------------* + * Scene orientation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-SCENE_ORIENTATION" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Scene orientation file name not specified!\n\n" ); + usage_enc(); + return false; + } + + arg->sceneOrientationTrajFileName = argv[i]; + i++; + } + + /*-----------------------------------------------------------------* + * Device orientation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-DEVICE_ORIENTATION" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Device orientation file name not specified!\n\n" ); + usage_enc(); + return false; + } + + arg->deviceOrientationTrajFileName = argv[i]; + i++; + } + + /*-----------------------------------------------------------------* + * Option not recognized + *-----------------------------------------------------------------*/ + else + { + fprintf( stderr, "Error: option not recognized, %s\n\n", argv[i] ); + usage_enc(); + return false; + } + } /* end of while */ + + /*-----------------------------------------------------------------* + * Mandatory input arguments + *-----------------------------------------------------------------*/ + + /*-----------------------------------------------------------------* + * Bitrate + *-----------------------------------------------------------------*/ + + if ( i < argc - 2 ) + { + /* check if profile file has been entered instead of a fixed bitrate */ + if ( !is_digits_only( argv[i] ) ) + { + arg->bitrateProfileFile = argv[i]; + } + else + { + arg->initBitrate = atoi( argv[i] ); + } + + i++; + } + else + { + fprintf( stderr, "Error: no bitrate specified\n\n" ); + usage_enc(); + return false; + } + + /*-----------------------------------------------------------------* + * Input sampling frequency + *-----------------------------------------------------------------*/ + + if ( i < argc - 2 ) + { + arg->inputFs = atoi( argv[i] ) * 1000; + i++; + } + else + { + fprintf( stderr, "Error: no input sampling frequency specified\n\n" ); + usage_enc(); + return false; + } + + /* for EVS mono, restore default behavior, i.e. SWB as default maxBandwidth if not set by the user otherwise */ + if ( arg->max_bwidth_user == false ) + { + arg->maxBandwidth = IVAS_ENC_GetDefaultBandwidth( ( arg->inputFormat == IVAS_ENC_INPUT_MONO ) ? true : false ); + } + + /* Prevent maxBandwidth from being higher than inputFs/2 */ + if ( arg->inputFs == 8000 && arg->maxBandwidth > IVAS_ENC_BANDWIDTH_NB ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_NB; + } + else if ( arg->inputFs == 16000 && arg->maxBandwidth > IVAS_ENC_BANDWIDTH_WB ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_WB; + } + else if ( arg->inputFs == 32000 && arg->maxBandwidth > IVAS_ENC_BANDWIDTH_SWB ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_SWB; + } + + /*-----------------------------------------------------------------* + * Input file + *-----------------------------------------------------------------*/ + + if ( i < argc - 1 ) + { + arg->inputWavFilename = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: no input file specified\n\n" ); + usage_enc(); + return false; + } + + /*-----------------------------------------------------------------* + * Output bitstream file + *-----------------------------------------------------------------*/ + + if ( i < argc ) + { + arg->outputBitstreamFilename = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: no output bitstream file specified\n\n" ); + usage_enc(); + return false; + } + + return true; +} + + +/*---------------------------------------------------------------------* + * usage_enc() + * + * Print the usage of the "ivas_cod" program + *---------------------------------------------------------------------*/ + +static void usage_enc( void ) +{ + fprintf( stdout, "Usage: IVAS_cod.exe [Options] R Fs input_file bitstream_file\n\n" ); + + fprintf( stdout, "Mandatory parameters:\n" ); + fprintf( stdout, "---------------------\n" ); + + fprintf( stdout, "R : Bitrate in bps, \n" ); + fprintf( stdout, " for EVS native modes R = (5900*, 7200, 8000, 9600, 13200, 16400,\n" ); + fprintf( stdout, " 24400, 32000, 48000, 64000, 96000, 128000) \n" ); + fprintf( stdout, " *VBR mode (average bitrate),\n" ); + fprintf( stdout, " for AMR-WB IO modes R = (6600, 8850, 12650, 14250, 15850, 18250,\n" ); + fprintf( stdout, " 19850, 23050, 23850) \n" ); + fprintf( stdout, " for IVAS stereo R = (13200, 16400, 24400, 32000, 48000, 64000, 80000, \n" ); + fprintf( stdout, " 96000, 128000, 160000, 192000, 256000) \n" ); + fprintf( stdout, " for IVAS ISM R = 13200 for 1 ISM, 16400 for 1 ISM and 2 ISM, \n" ); + fprintf( stdout, " (24400, 32000, 48000, 64000, 80000, 96000, 128000) \n" ); + fprintf( stdout, " for 2 ISM, 3 ISM and 4 ISM also 160000, 192000, 256000) \n" ); + fprintf( stdout, " for 3 ISM and 4 ISM also 384000 \n" ); + fprintf( stdout, " for 4 ISM also 512000 \n" ); + fprintf( stdout, " for IVAS SBA, MASA, MC, ISM-SBA, and ISM-MASA R=(13200, 16400, 24400, 32000, 48000, 64000,\n" ); + fprintf( stdout, " 80000, 96000, 128000, 160000, 192000, 256000, 384000, 512000) \n" ); + fprintf( stdout, " Alternatively, R can be a bitrate switching file which consists of R values\n" ); + fprintf( stdout, " indicating the bitrate for each frame in bps. These values are stored in\n" ); + fprintf( stdout, " binary format using 4 bytes per value\n" ); + fprintf( stdout, "Fs : Input sampling rate in kHz, Fs = (8, 16, 32 or 48) \n" ); + + fprintf( stdout, "input_file : Input audio filename \n" ); + fprintf( stdout, "bitstream_file : Output bitstream filename \n\n" ); + + fprintf( stdout, "Options:\n" ); + fprintf( stdout, "--------\n" ); + fprintf( stdout, "EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -masa, -mc, -ism_sba, -ism_masa\n" ); + fprintf( stdout, "-stereo : Stereo format \n" ); + fprintf( stdout, "-ism (+)Ch Files : ISM format \n" ); + fprintf( stdout, " where Ch specifies the number of ISMs (1-4)\n" ); + fprintf( stdout, " where positive (+) indicates extended metadata (only 64 kbps and up) \n" ); + fprintf( stdout, " and Files specify input files containing metadata, one file per object\n" ); + fprintf( stdout, " (use NULL for no input metadata)\n" ); + fprintf( stdout, "-sba +/-Order : Scene Based Audio input format (Ambisonics ACN/SN3D),\n" ); + fprintf( stdout, " where Order specifies the Ambisionics order (1-3),\n" ); + fprintf( stdout, " where positive (+) means full 3D and negative (-) only 2D/planar components to be coded\n" ); + fprintf( stdout, "-masa Ch File : MASA format \n" ); + fprintf( stdout, " where Ch specifies the number of MASA input/transport channels (1 or 2): \n" ); + fprintf( stdout, " and File specifies input file containing parametric MASA metadata \n" ); + fprintf( stdout, "-ism_sba IsmCh +/-Order IsmFiles : SBA and ISM combined format\n" ); + fprintf( stdout, " where IsmCh specifies the number of ISMs (1-4)\n" ); + fprintf( stdout, " and Order specifies the SBA order (1 to 3) \n" ); + fprintf( stdout, " and IsmFiles specify input files containing ISM metadata, one file per object \n" ); + fprintf( stdout, "-ism_masa IsmCh MasaCh IsmFiles MasaFile : MASA and ISM combined format \n" ); + fprintf( stdout, " where IsmCh specifies the number of ISMs (1-4),\n" ); + fprintf( stdout, " MasaCh specifies the number of MASA input/transport channels (1-2), \n" ); + fprintf( stdout, " IsmFiles specify input files containing ISM metadata, one file per object, \n" ); + fprintf( stdout, " and MasaFile specifies input file containing parametric MASA metadata \n" ); + fprintf( stdout, "-mc InputConf : Multi-channel format\n" ); + fprintf( stdout, " where InputConf specifies the channel configuration: 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4\n" ); + fprintf( stdout, " Loudspeaker positions are assumed to have azimuth and elevation as per \n" ); + fprintf( stdout, " ISO/IEC 23091-3:2018 Table 3. Channel order is as per ISO/IEC 23008-3:2015 Table 95.\n" ); + fprintf( stdout, " See readme.txt for details.\n" ); + fprintf( stdout, "-dtx D : Activate DTX mode, D = (0, 3-100) is the SID update rate\n" ); + 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 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" ); + fprintf( stdout, " contains the values of p and o separated by a space, \n" ); + fprintf( stdout, " default is deactivated \n" ); + fprintf( stdout, "-max_band B : Activate bandwidth limitation, B = (NB, WB, SWB or FB)\n" ); + fprintf( stdout, " alternatively, B can be a text file where each line contains \"nb_frames B\"\n" ); + fprintf( stdout, "-no_delay_cmp : Turn off delay compensation\n" ); + fprintf( stdout, "-stereo_dmx_evs : Activate stereo downmix function for EVS.\n" ); + fprintf( stdout, "-binaural : Optional indication that input is binaural audio (to be used with -stereo or -stereo_dmx_evs)\n" ); + fprintf( stdout, "-mime : Mime output bitstream file format\n" ); + fprintf( stdout, " The encoder produces TS26.445 Annex.2.6 Mime Storage Format, (not RFC4867 Mime Format).\n" ); + fprintf( stdout, " default output bitstream file format is G.192\n" ); + fprintf( stdout, "-pca : activate PCA in SBA format FOA at 256 kbps \n" ); + fprintf( stdout, "-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. \n" ); + fprintf( stdout, " Currently, all values default to level 3 (full functionality).\n" ); +#ifdef DEBUGGING + fprintf( stdout, "-force T : Force specific mode, T = (speech, music, ACELP, GSC, TCX, HQ),\n" ); + fprintf( stdout, " alternatively, T can be a text file where each line contains \"nb_frames T\"\n" ); +#ifdef DEBUG_FORCE_DIR + fprintf( stdout, " or T can be a directory containing external binary files for modes/parameters enforcement\n" ); +#endif +#endif +#ifdef DEBUG_MODE_INFO +#ifdef DEBUG_MODE_INFO_TWEAK + fprintf( stdout, "-info : specify subfolder name for debug output\n" ); +#endif +#endif + fprintf( stdout, "-q : Quiet mode, no frame counters\n" ); + fprintf( stdout, " default is deactivated\n" ); + fprintf( stdout, "-rtpdump : RTPDump output, hf_only=1 by default. The encoder will packetize the \n" ); + fprintf( stdout, " bitstream frames into TS26.253 Annex A IVAS RTP Payload Format packets and \n" ); + fprintf( stdout, " writes those to the output file. In EVS mono operating mode, TS26.445 Annex A.2.2 \n" ); + fprintf( stdout, " EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet\n" ); + fprintf( stdout, "-scene_orientation : Scene orientation trajectory file. Only used with rtpdump output.\n" ); + fprintf( stdout, "-device_orientation : Device orientation trajectory file. Only used with rtpdump output.\n" ); + fprintf( stdout, "\n" ); + + return; +} + + +/*---------------------------------------------------------------------* + * readBandwidth() + * + * + *---------------------------------------------------------------------*/ + +static bool readBandwidth( + FILE *file, + IVAS_ENC_BANDWIDTH *bandwidth, + int32_t *bandwidthFrameCounter ) +{ + int16_t res; + char stmp[4]; + + if ( *bandwidthFrameCounter == 0 ) + { + /* read next bandwidth value and number of frames from the profile file */ + while ( ( res = (int16_t) fscanf( file, "%d %3s", bandwidthFrameCounter, stmp ) ) != 2 && feof( file ) ) + { + rewind( file ); + } + + ( *bandwidthFrameCounter )--; + + to_upper( stmp ); + + if ( strcmp( stmp, "NB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_NB; + } + else if ( strcmp( stmp, "WB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_WB; + } + else if ( strcmp( stmp, "SWB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_SWB; + } + else if ( strcmp( stmp, "FB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_FB; + } + else + { + fprintf( stderr, "Error: incorrect bandwidth specified (only NB, WB, SWB and FB are supported)\n\n" ); + usage_enc(); + return false; + } + } + else + { + /* current profile still active, only decrease the counter */ + ( *bandwidthFrameCounter )--; + } + + return true; +} + + +/*---------------------------------------------------------------------* + * readBitrate() + * + * + *---------------------------------------------------------------------*/ + +static bool readBitrate( + FILE *file, + int32_t *bitrate ) +{ + for ( int32_t i = 0; i < 2; ++i ) + { + if ( fread( bitrate, sizeof( int32_t ), 1, file ) == 1 ) + { + return true; + } + + rewind( file ); + } + + fprintf( stderr, "Error: cannot read the bitrate profile file\n\n" ); + usage_enc(); + return false; +} + + +#ifdef DEBUGGING +/*---------------------------------------------------------------------* + * parseForcedMode() + * + * + *---------------------------------------------------------------------*/ + +static IVAS_ENC_FORCED_MODE parseForcedMode( + char *forcedModeChar ) +{ +#ifdef DEBUG_FORCE_DIR + struct stat path_stat; +#endif + + to_upper( forcedModeChar ); + +#ifdef DEBUG_FORCE_DIR + if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) || + ( strcmp( forcedModeChar, "0" ) == 0 ) ) + { + return IVAS_ENC_FORCE_SPEECH; + } + else if ( ( strcmp( forcedModeChar, "MUSIC" ) == 0 ) || ( strcmp( forcedModeChar, "'MUSIC'" ) == 0 ) || ( strcmp( forcedModeChar, "AUDIO" ) == 0 ) || ( strcmp( forcedModeChar, "'AUDIO'" ) == 0 ) || ( strcmp( forcedModeChar, "1" ) == 0 ) ) + { + return IVAS_ENC_FORCE_MUSIC; + } + else if ( ( strcmp( forcedModeChar, "ACELP" ) == 0 ) || ( strcmp( forcedModeChar, "'ACELP'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_ACELP; + } + else if ( ( strcmp( forcedModeChar, "GSC" ) == 0 ) || ( strcmp( forcedModeChar, "'GSC'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_GSC; + } + if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) +#ifdef SUPPORT_FORCE_TCX10_TCX20 + || ( strcmp( forcedModeChar, "TCX20" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX20'" ) == 0 ) +#endif + ) + { +#ifdef SUPPORT_FORCE_TCX10_TCX20 + return IVAS_ENC_FORCE_TCX20; +#else + return IVAS_ENC_FORCE_TCX; +#endif + } +#ifdef SUPPORT_FORCE_TCX10_TCX20 + if ( ( strcmp( forcedModeChar, "TCX10" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX10'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_TCX10; + } +#endif + else if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_HQ; + } + else + { + if ( stat( forcedModeChar, &path_stat ) != 0 ) + { + return IVAS_ENC_FORCE_UNDEFINED; + } + + /* check if the argument represents an existing file or directory */ + if ( S_ISDIR( path_stat.st_mode ) ) + { + /* it's a directory */ + return IVAS_ENC_FORCE_DIR; + } + else + { + /* it's a file */ + return IVAS_ENC_FORCE_FILE; + } + } +#else + if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) || + ( strcmp( forcedModeChar, "0" ) == 0 ) ) + { + return IVAS_ENC_FORCE_SPEECH; + } + if ( ( strcmp( forcedModeChar, "MUSIC" ) == 0 ) || ( strcmp( forcedModeChar, "'MUSIC'" ) == 0 ) || ( strcmp( forcedModeChar, "AUDIO" ) == 0 ) || ( strcmp( forcedModeChar, "'AUDIO'" ) == 0 ) || ( strcmp( forcedModeChar, "1" ) == 0 ) ) + { + return IVAS_ENC_FORCE_MUSIC; + } + if ( ( strcmp( forcedModeChar, "ACELP" ) == 0 ) || ( strcmp( forcedModeChar, "'ACELP'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_ACELP; + } + if ( ( strcmp( forcedModeChar, "GSC" ) == 0 ) || ( strcmp( forcedModeChar, "'GSC'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_GSC; + } + if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) +#ifdef SUPPORT_FORCE_TCX10_TCX20 + || ( strcmp( forcedModeChar, "TCX20" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX20'" ) == 0 ) +#endif + ) + { +#ifdef SUPPORT_FORCE_TCX10_TCX20 + return IVAS_ENC_FORCE_TCX20; +#else + return IVAS_ENC_FORCE_TCX; +#endif + } +#ifdef SUPPORT_FORCE_TCX10_TCX20 + if ( ( strcmp( forcedModeChar, "TCX10" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX10'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_TCX10; + } +#endif + if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_HQ; + } + + return IVAS_ENC_FORCE_UNDEFINED; +#endif +} + + +/*---------------------------------------------------------------------* + * readForcedMode() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error readForcedMode( + FILE *file, + IVAS_ENC_FORCED_MODE *forcedMode, + int32_t *forceFrameCounter ) +{ + int16_t res; + char stmp[8]; + + if ( *forceFrameCounter == 0 ) + { + /* read next force and number of frames from the profile file */ + while ( ( res = (int16_t) fscanf( file, "%d %7s", forceFrameCounter, stmp ) ) != 2 && feof( file ) ) + { + rewind( file ); + } + + *forcedMode = parseForcedMode( stmp ); + + if ( *forcedMode == IVAS_ENC_FORCE_UNDEFINED ) + { + fprintf( stderr, "Error: incorect mode specification or the force profile file could not be opened: %s\n\n", stmp ); + return IVAS_ERR_WRONG_PARAMS; + } + + if ( res != 2 && !feof( file ) ) + { + fprintf( stderr, "Error: incorrect format of the force profile file (please ensure that it does not contain any empty lines)\n\n" ); + return IVAS_ERR_WRONG_PARAMS; + } + } + + /* current profile still active, only decrease the counter */ + ( *forceFrameCounter )--; + + return IVAS_ERR_OK; +} +#endif + + +#undef WMC_TOOL_SKIP diff --git a/apps/isar_post_rend.c b/apps/isar_post_rend.c index 272d2b9c42d89391cb69372d589e491842cddfce..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 @@ -47,6 +47,7 @@ #endif #include "stl.h" #include "wmc_auto.h" +#include "ivas_rtp_file.h" #define WMC_TOOL_SKIP @@ -79,6 +80,7 @@ static typedef struct { + bool srRtp; IVAS_AUDIO_CONFIG audioConfig; int32_t inputChannelIndex; float gain_dB; @@ -100,18 +102,16 @@ typedef struct char executableName[POST_REND_MAX_CLI_ARG_LENGTH]; char inputFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; char outputFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; + char srParamsFilePath[POST_REND_MAX_CLI_ARG_LENGTH]; 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 @@ -121,14 +121,14 @@ typedef enum CmdLnOptionId_outputFile, CmdLnOptionId_sampleRate, CmdLnOptionId_trajFile, - CmdLnOptionId_orientationTracking, - CmdLnOptionId_complexityLevel, CmdLnOptionId_noDelayCmp, CmdLnOptionId_quietModeEnabled, CmdLnOptionId_inputMetadata, CmdLnOptionId_listFormats, CmdLnOptionId_SplitRendBFIFile, CmdLnOptionId_framing, + CmdLnOptionId_srParamsFile, + CmdLnOptionId_help, } CmdLnOptionId; static const CmdLnParser_Option cliOptions[] = { @@ -136,73 +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", + .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", }, }; @@ -215,10 +233,11 @@ static const int32_t numCliOptions = sizeof( cliOptions ) / sizeof( CmdLnParser_ static void printSupportedAudioConfigs( void ); -static IVAS_AUDIO_CONFIG parseAudioConfig( const char *configString ); +static IVAS_AUDIO_CONFIG parseAudioConfig( const char *configString, bool *srRtp ); static void convertOutputBuffer( const Word32 *fixedBuffer, Word16 q, const int16_t numSamplesPerChannel, const int16_t numChannels, int16_t *intBuffer ); + /*------------------------------------------------------------------------------------------* * Local functions *------------------------------------------------------------------------------------------*/ @@ -282,33 +301,21 @@ 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. */ - IVAS_AUDIO_CONFIG audioConfig = parseAudioConfig( inFormatStr ); + bool srRtp = false; + IVAS_AUDIO_CONFIG audioConfig = parseAudioConfig( inFormatStr, &srRtp ); switch ( audioConfig ) { case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED: case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM: inConfig->numBinBuses = 1; + inConfig->binBuses[0].srRtp = srRtp; inConfig->binBuses[0].audioConfig = audioConfig; inConfig->binBuses[0].inputChannelIndex = 0; inConfig->binBuses[0].gain_dB = 0.0f; @@ -318,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; } } @@ -327,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; @@ -342,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; @@ -359,11 +366,13 @@ static bool parseRenderFramesize( static IVAS_AUDIO_CONFIG parseAudioConfig( - const char *configString ) + const char *configString, + bool *srRtp ) { char charBuf[25]; charBuf[24] = '\0'; + *srRtp = false; strncpy( charBuf, configString, sizeof( charBuf ) - 1 ); charBuf[sizeof( charBuf ) - 1] = '\0'; to_upper( charBuf ); @@ -380,51 +389,13 @@ static IVAS_AUDIO_CONFIG parseAudioConfig( { return IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED; } - return IVAS_AUDIO_CONFIG_INVALID; -} - - -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 ) + if ( strcmp( charBuf, "RTPDUMP" ) == 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 ); + *srRtp = true; + return IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED; } - return !missingRequiredArg; + return IVAS_AUDIO_CONFIG_INVALID; } @@ -436,30 +407,32 @@ static CmdlnArgs defaultArgs( strncpy( args.executableName, executableName, POST_REND_MAX_CLI_ARG_LENGTH ); clearString( args.inputFilePath ); clearString( args.outputFilePath ); + clearString( args.srParamsFilePath ); + 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, @@ -470,85 +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 ) + { + 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 ) ) { - exit( -1 ); /* Error printout handled by failing function */ + /* 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, "Unknown or invalid option for frame size: %s\n", optionValues[0] ); - exit( -1 ); + fprintf( stderr, "Error: Incorrect audio rendering frame size!\n" ); + return -1; + } + else if ( numOptionValues > 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: + 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; } @@ -563,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; } @@ -576,12 +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] ); @@ -671,6 +709,116 @@ static void convertOutputBuffer( } +static void trim( char *str ) +{ + char c; + int r = 0, w = 0; + while ( ( c = str[r] ) != 0 && ( c == ' ' || c == '\t' || c == ';' ) ) + { + r++; + } + + while ( ( c = str[r] ) != 0 && ( c != ' ' && c != '\t' && c != ';' ) ) + { + str[w++] = c; + r++; + } + str[w] = 0; +} + + +static ivas_error parseSRParamsFile( + const char *srParamsFilePath, + const char *rtpFilePath, + ISAR_SPLIT_REND_CODEC *codec, + ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, + int16_t *codec_frame_size_ms, + int16_t *isar_frame_size_ms, + int16_t *lc3plusHighRes ) +{ + FILE *fParamSR = fopen( srParamsFilePath, "r" ); + if ( NULL == fParamSR ) + { + fprintf( stderr, "error in opening srParams File %s)\n", srParamsFilePath ); + return IVAS_ERR_FAILED_FILE_OPEN; + } + + *codec = ISAR_SPLIT_REND_CODEC_NONE; + *poseCorrection = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; + *codec_frame_size_ms = 5; + *lc3plusHighRes = 0; + + while ( !feof( fParamSR ) ) + { + char key[16], value[16]; + if ( 2 == fscanf( fParamSR, "%15s = %15s", key, value ) ) + { + trim( key ); + trim( value ); + + if ( 0 == strncmp( key, "DOF", 3 ) ) + { + int val = atoi( value ); + if ( val == 0 || val == 1 ) + { + *poseCorrection = ( val == 0 ) ? ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE : ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB; + } + } + else if ( 0 == strncmp( key, "LC3PLUS_HIGHRES", 15 ) ) + { + int val = atoi( value ); + if ( val == 0 || val == 1 ) + { + *lc3plusHighRes = (int16_t) val; + } + } + } + } + + fclose( fParamSR ); + + { + /* Peek the RTP stream to ascertain the codec and codec_frame_size */ + ivas_error error = IVAS_ERR_OK; + IVAS_RTP srRtp = { 0 }; + if ( ( error = IVAS_RTP_READER_Init( &srRtp, rtpFilePath, NULL, false, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "error in IVAS_RTP_READER_Init() for sr RTP peek: %d\n", error ); + return error; + } + + /* read a frame */ + while ( 1 ) + { + bool qBit = false; + IVAS_RTP_SR_INFO srInfo = { 0 }; + uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3]; + int16_t auSize = 0; + uint16_t rtpSequenceNumber = 0; + uint32_t rtpTimeStamp = 0, nextPacketRcvTime_ms = 0; + + error = IVAS_RTP_ReadNextFrame( &srRtp, au, &auSize, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &srInfo, &qBit ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_RTP_ReadNextFrame, error code: %d\n", error ); + return error; + } + + if ( srInfo.valid ) + { + *codec = ( srInfo.codec == IVAS_SR_TRANSPORT_LCLD ) ? ISAR_SPLIT_REND_CODEC_LCLD : ISAR_SPLIT_REND_CODEC_LC3PLUS; + *codec_frame_size_ms = (int16_t) srInfo.codecFrameSizeMs; + *isar_frame_size_ms = *codec_frame_size_ms; /* for rtp force codec framesize as isar renderer frame size */ + break; + } + } + IVAS_RTP_Term( &srRtp ); + } + + return IVAS_ERR_OK; +} + + /*------------------------------------------------------------------------------------------* * main() * @@ -710,6 +858,7 @@ int main( int16_t i, numChannels; ivas_error error = IVAS_ERR_OK; bool splitBinNeedsNewFrame = true; + IVAS_RTP srRTP = { 0 }; #ifdef WMOPS reset_wmops(); @@ -738,7 +887,7 @@ int main( convert_backslash( args.inputFilePath ); convert_backslash( args.outputFilePath ); - convert_backslash( args.headRotationFilePath ); + convert_backslash( args.srParamsFilePath ); /*------------------------------------------------------------------------------------------* * Open head-rotation file @@ -746,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 ); @@ -760,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; @@ -769,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, @@ -778,19 +932,52 @@ 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; } } + if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].srRtp ) ) + { + error = parseSRParamsFile( args.srParamsFilePath, + args.inputFilePath, + &bitsBuffer.config.codec, + &bitsBuffer.config.poseCorrection, + &bitsBuffer.config.codec_frame_size_ms, + &bitsBuffer.config.isar_frame_size_ms, + &bitsBuffer.config.lc3plusHighRes ); + if ( error != IVAS_ERR_OK ) + { + 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, "\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_num_subframes = bitsBuffer.config.isar_frame_size_ms / 5; + } /*if split renderer is running in post renderer mode*/ - if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) + else if ( ( args.inConfig.numBinBuses > 0 ) && ( args.inConfig.binBuses[0].audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) { error = split_rend_reader_open( &hSplitRendFileReadWrite, args.inputFilePath, @@ -802,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; @@ -828,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; @@ -850,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; } } @@ -859,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; @@ -997,7 +1184,50 @@ int main( num_in_channels = inBuffer.config.numChannels; numSamplesRead = 0; - if ( ( hSplitRendFileReadWrite != NULL ) && splitBinNeedsNewFrame ) + if ( srRTP.hRtpFile && splitBinNeedsNewFrame ) + { + IVAS_RTP_SR_INFO srInfo = { 0 }; + uint32_t rtpTimeStamp = 0, nextPacketRcvTime_ms = 0; + uint16_t rtpSequenceNumber = 0; + int16_t auSizeBits = 0; + bool qBit = false; + uint8_t *bitBuffer = bitsBuffer.bits; + int16_t frameMS = 0; + + numSamplesRead = (int16_t) inBufferSize; + bitsBuffer.config.bitsRead = 0; + bitsBuffer.config.bitsWritten = 0; + + while ( frameMS < bitsBuffer.config.isar_frame_size_ms ) + { + error = IVAS_RTP_ReadNextFrame( &srRTP, bitBuffer, &auSizeBits, &rtpTimeStamp, &rtpSequenceNumber, &nextPacketRcvTime_ms, &srInfo, &qBit ); + if ( error != IVAS_ERR_OK ) + { + if ( error == IVAS_ERR_END_OF_FILE ) + { + numSamplesRead = 0; + break; + } + else + { + fprintf( stderr, "\nUnable to read from bitstream file!\n" ); + goto cleanup; + } + } + /* Ensure a SR RTP stream was received */ + if ( !srInfo.valid ) + { + fprintf( stderr, "\nNon-SR RTP stream detected !\n" ); + goto cleanup; + } + + bitBuffer += ( auSizeBits + 7 ) / 8; + bitsBuffer.config.bitsWritten += auSizeBits; + bitsBuffer.config.codec = srInfo.codec == IVAS_SR_TRANSPORT_LC3PLUS ? ISAR_SPLIT_REND_CODEC_LC3PLUS : ISAR_SPLIT_REND_CODEC_LCLD; + frameMS += bitsBuffer.config.codec_frame_size_ms; + } + } + else if ( ( hSplitRendFileReadWrite != NULL ) && splitBinNeedsNewFrame ) { ivas_error error_tmp; numSamplesRead = (int16_t) inBufferSize; @@ -1035,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 */ @@ -1110,7 +1351,6 @@ int main( goto cleanup; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /* Set BFI if frame is empty */ int16_t frameEmpty = (int16_t) ( bitsBuffer.config.bitsWritten == 0 ); if ( frameEmpty ) @@ -1121,7 +1361,6 @@ int main( goto cleanup; } } -#endif } } diff --git a/apps/renderer.c b/apps/renderer.c index 1536613953582027d2c0ce08a85a8618eefacc5b..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 @@ -46,9 +46,7 @@ #include "masa_file_writer.h" #include "render_config_reader.h" #include "rotation_file_reader.h" -#ifdef FIX_1053_REVERB_RECONFIGURATION #include "aeid_file_reader.h" -#endif #include "split_render_file_read_write.h" #include "split_rend_bfi_file_reader.h" #include "vector3_pair_file_reader.h" @@ -76,9 +74,7 @@ #define IVAS_MAX16B_FX 32767 #define IVAS_MIN16B_FX ( -32768 ) -#ifdef NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS #define OMASA_TDREND_MATCHING_GAIN_DB ( -2.0f ) -#endif #if !defined( DEBUGGING ) && !defined( WMOPS ) static @@ -91,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; @@ -174,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]; @@ -197,9 +189,10 @@ 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; } CmdlnArgs; typedef enum @@ -224,13 +217,13 @@ typedef enum CmdLnOptionId_listFormats, CmdLnOptionId_inputGain, CmdLnOptionId_outputMetadata, - CmdLnOptionId_SplitRendBFIFile, CmdLnOptionId_referenceVectorFile, CmdLnOptionId_exteriorOrientationFile, CmdLnOptionId_framing, CmdLnOptionId_syncMdDelay, CmdLnOptionId_directivityPatternId, - CmdLnOptionId_acousticEnvironmentId + CmdLnOptionId_acousticEnvironmentId, + CmdLnOptionId_roomSize } CmdLnOptionId; static const CmdLnParser_Option cliOptions[] = { @@ -238,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)", }, { @@ -340,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.", }, { @@ -352,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", }, { @@ -364,42 +372,51 @@ 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", -#ifdef FIX_1053_REVERB_RECONFIGURATION + .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.", -#else - .description = "Acoustic environment ID( number > 0 ) or a sequence thereof in the format [ID1:duration1,ID2:duration2...] without braces and spaces, with ':' character separating ID from duration and ',' separating ID and duration pairs, where duration is specified in frames for BINAURAL_ROOM_REVERB output configuration.", -#endif }, + { + .id = CmdLnOptionId_roomSize, + .match = "room_size", + .matchShort = "rsz", + .placeholder = "", + .description = "Selects default reverb based on a room size (S - small |\nM - medium | L - large)", + } }; @@ -649,7 +666,6 @@ static void setupWithSingleFormatInput( positionProvider->numObjects = args.inConfig.numAudioObjects; for ( int16_t i = 0; i < positionProvider->numObjects; ++i ) { -#ifdef FIX_1376_MISSING_ISM_METADATA /* Check if path to metadata file was given */ if ( isEmptyString( args.inMetadataFilePaths[i] ) ) { @@ -658,18 +674,11 @@ static void setupWithSingleFormatInput( } /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string contains "NULL" */ -#else - /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string is empty or contains "NULL" */ -#endif 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 ); -#ifdef FIX_1376_MISSING_ISM_METADATA if ( strncmp( charBuf, "NULL", 4 ) == 0 ) -#else - if ( isEmptyString( args.inMetadataFilePaths[i] ) || strncmp( charBuf, "NULL", 4 ) == 0 ) -#endif { continue; } @@ -769,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; @@ -812,9 +820,7 @@ int main( int32_t delayTimeScale = 0; int16_t i, numChannels; uint16_t aeID; -#ifdef FIX_1053_REVERB_RECONFIGURATION IVAS_RENDER_CONFIG_DATA renderConfig; -#endif ivas_error error = IVAS_ERR_OK; #ifdef WMOPS @@ -901,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 ) @@ -1000,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; @@ -1110,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 ) { @@ -1177,11 +1178,6 @@ int main( if ( args.renderConfigFilePath[0] != '\0' ) { - -#ifndef FIX_1053_REVERB_RECONFIGURATION - IVAS_RENDER_CONFIG_DATA renderConfig; -#endif - /* sanity check */ if ( ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL ) && ( args.outConfig.audioConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) && @@ -1216,7 +1212,7 @@ int main( } if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - aeID = args.aeSequence.count > 0 ? args.aeSequence.pID[0] : 65535; + aeID = args.aeSequence.count > 0 ? args.aeSequence.pID[0] : IVAS_DEFAULT_AEID; if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) { if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK ) @@ -1234,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 ) { @@ -1252,11 +1248,21 @@ int main( goto cleanup; } + /* Set reverb room size if specified */ + if ( args.reverbRoomSize != IVAS_ROOM_SIZE_AUTO ) + { + if ( ( IVAS_REND_SetReverbRoomSize( hIvasRend, args.reverbRoomSize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError setting reverb room size\n" ); + goto cleanup; + } + } + /* 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 ) ); @@ -1275,30 +1281,22 @@ int main( } } -#ifndef NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS - /* Set the total number of objects */ -#endif if ( args.inConfig.numAudioObjects > 0 ) { -#ifdef NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS /* Set the total number of objects */ -#endif if ( ( error = IVAS_REND_SetTotalNumberOfObjects( hIvasRend, args.inConfig.numAudioObjects ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_REND_SetTotalNumberOfObjects(): %s\n", ivas_error_to_string( error ) ); goto cleanup; } -#ifdef NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS /* Set the metadata delay for objects */ -#endif IF( ( error = IVAS_REND_SetIsmMetadataDelay( hIvasRend, args.syncMdDelay ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_REND_SetIsmMetadataDelay(): %s\n", ivas_error_to_string( error ) ); goto cleanup; } -#ifdef NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS /* For OMASA input and BINAURAL output, apply a gain to objects to match the loudness with MASA part */ if ( args.inConfig.numMasaBuses > 0 && args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL ) @@ -1308,7 +1306,6 @@ int main( args.inConfig.audioObjects[i].gain_dB += OMASA_TDREND_MATCHING_GAIN_DB; } } -#endif } IVAS_REND_LfePanMtx lfePanMatrix; @@ -1344,17 +1341,12 @@ int main( { masaIds[i] = 0u; } -#ifdef NONBE_1377_REND_DIRATT_CONF -#ifdef FIX_1377_HANDLE_ERROR_CODE + if ( ( error = IVAS_REND_SetObjectIDs( hIvasRend ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_REND_SetObjectIDs: %s\n", ivas_error_to_string( error ) ); goto cleanup; } -#else - IVAS_REND_SetObjectIDs( hIvasRend ); -#endif -#endif for ( i = 0; i < args.inConfig.numMultiChannelBuses; ++i ) { @@ -1374,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 ) ); @@ -1548,7 +1540,7 @@ int main( audioWriter = NULL; } - if ( ( error = IVAS_REND_GetSplitRendBitstreamHeader( hIvasRend, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms, &bitsBuffer.config.isar_frame_size_ms ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_REND_GetSplitRendBitstreamHeader( hIvasRend, &bitsBuffer.config.codec, &bitsBuffer.config.poseCorrection, &bitsBuffer.config.codec_frame_size_ms, &bitsBuffer.config.isar_frame_size_ms, &bitsBuffer.config.lc3plus_highres ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_REND_GetSplitRendBitstreamHeader(): %s!\n", ivas_error_to_string( error ) ); goto cleanup; @@ -1562,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; } } @@ -1659,23 +1651,20 @@ int main( ObjectPositionBuffer mtdBuffer; outBuffer.pq_fact = &outBuffer.q_factor; - Word16 subframe_len = (Word16) ( args.sampleRate / ( 200 ) ); // sample rate /FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES + Word16 subframe_len = (Word16) ( args.sampleRate / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); Word16 gd_bits = find_guard_bits( subframe_len ); Word16 prev_q_fact = Q11; while ( 1 ) { 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 ) { if ( ++args.aeSequence.frameCounter >= args.aeSequence.pValidity[args.aeSequence.selected] ) { -#ifndef FIX_1053_REVERB_RECONFIGURATION - IVAS_RENDER_CONFIG_DATA renderConfig; -#endif if ( ++args.aeSequence.selected >= args.aeSequence.count ) { args.aeSequence.selected = 0; @@ -1733,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 ) { @@ -2199,7 +2188,6 @@ cleanup: } split_rend_reader_writer_close( &hSplitRendFileReadWrite ); - SplitRendBFIFileReader_close( &splitRendBFIReader ); for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { @@ -2212,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 ); @@ -2438,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; @@ -2453,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; @@ -2651,9 +2637,10 @@ static bool parseAcousticEnvironmentIds( const char *value, AcousticEnvironmentSequence *aeSequence ) { -#ifdef FIX_1053_REVERB_RECONFIGURATION char config_string[RENDERER_MAX_METADATA_LINE_LENGTH]; + strncpy( config_string, value, RENDERER_MAX_METADATA_LINE_LENGTH ); + if ( !is_digits_only( config_string ) ) { aeidFileReader *aeidReader = NULL; @@ -2669,72 +2656,6 @@ static bool parseAcousticEnvironmentIds( } aeidFileReader_close( &aeidReader ); } -#else - uint16_t k; - char config_string[RENDERER_MAX_METADATA_LINE_LENGTH]; - char *s; - char *token; - - strncpy( config_string, value, RENDERER_MAX_METADATA_LINE_LENGTH ); - s = config_string; - token = config_string; - - if ( !is_digits_only( config_string ) ) - { - - for ( k = 0; s[k]; ) - { - s[k] == ',' ? k++ : *s++; - } - k++; - - if ( k == 0 ) - { - fprintf( stdout, "Error: Invalid acoustic environment sequence specified: %s\n\n", config_string ); - return false; - } - - if ( NULL == ( aeSequence->pID = malloc( sizeof( uint16_t ) * k ) ) || - NULL == ( aeSequence->pValidity = malloc( sizeof( uint16_t ) * k ) ) ) - { - fprintf( stdout, "Error: Unable to allocate memory for acoustic environment sequence: %s\n\n", config_string ); - return false; - } - - aeSequence->count = k; - - k = 0; - - token = strtok( config_string, ":" ); - - while ( token != NULL ) - { - if ( !is_number( token ) ) - { - fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, config_string ); - return false; - } - aeSequence->pID[k] = (uint16_t) atoi( token ); - - token = strtok( NULL, "," ); - if ( !is_number( token ) ) - { - fprintf( stdout, "Error: Invalid token %s found in acoustic environment sequence: %s\n\n", token, config_string ); - return false; - } - aeSequence->pValidity[k] = (uint16_t) atoi( token ); - - token = strtok( NULL, ":" ); - k++; - } - - if ( k != aeSequence->count ) - { - fprintf( stdout, "Error while parsing acoustic environment sequence: %s\n\n", config_string ); - return false; - } - } -#endif else { /* A single acoustic environment */ @@ -2753,50 +2674,34 @@ static bool parseAcousticEnvironmentIds( } -static bool checkRequiredArgs( - CmdlnArgs args ) +static bool parseReverbRoomSize( + char *value, + IVAS_ROOM_SIZE_T *reverbRoomSize ) { - const CmdLnParser_Option *tmpOption; - - /* Check required arguments */ - bool missingRequiredArg = false; - if ( isEmptyString( args.inputFilePath ) ) + if ( strlen( value ) != 1 ) { - tmpOption = findOptionById( CmdLnOptionId_inputFile ); - fprintf( stderr, "Missing required argument: %s (%s)\n", tmpOption->match, tmpOption->matchShort ); - missingRequiredArg = true; + fprintf( stderr, "Error: Unsupported room size selector %s!\n\n", value ); + return false; } - 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 ) + to_upper( value ); + switch ( value[0] ) { - CmdLnParser_printUsage( args.executableName, cliOptions, numCliOptions ); + case 'S': + *reverbRoomSize = IVAS_ROOM_SIZE_SMALL; + break; + case 'M': + *reverbRoomSize = IVAS_ROOM_SIZE_MEDIUM; + break; + case 'L': + *reverbRoomSize = IVAS_ROOM_SIZE_LARGE; + break; + default: + fprintf( stderr, "Error: Unsupported room size selector %s!\n\n", value ); + return false; } - return !missingRequiredArg; + return true; } static CmdlnArgs defaultArgs( @@ -2812,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; @@ -2820,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; @@ -2833,7 +2752,6 @@ static CmdlnArgs defaultArgs( clearString( args.headRotationFilePath ); clearString( args.outMetadataFilePath ); - clearString( args.splitRendBFIFilePath ); clearString( args.referenceVectorFilePath ); clearString( args.referenceRotationFilePath ); clearString( args.customHrtfFilePath ); @@ -2860,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 ) { @@ -2873,10 +2791,12 @@ static CmdlnArgs defaultArgs( args.aeSequence.selected = 0; args.aeSequence.frameCounter = 0; + args.reverbRoomSize = IVAS_ROOM_SIZE_AUTO; + return args; } -static void parseOption( +static int16_t parseOption( const int32_t optionId, char **optionValues, const int16_t numOptionValues, @@ -2938,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 ); @@ -3027,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 ); @@ -3053,12 +2969,20 @@ static void parseOption( /* Metadata Delay to sync with audio delay in ms */ args->syncMdDelay = (int16_t) strtol( optionValues[0], NULL, 10 ); break; + case CmdLnOptionId_roomSize: + assert( numOptionValues == 1 ); + if ( !parseReverbRoomSize( optionValues[0], &args->reverbRoomSize ) ) + { + fprintf( stderr, "Error: Unsupported room size selector %s!\n\n", optionValues[0] ); + exit( -1 ); + } + break; default: assert( 0 && "This should be unreachable - all command line options should be explicitly handled." ); break; } - return; + return 0; } static CmdlnArgs parseCmdlnArgs( @@ -3072,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; @@ -3147,25 +3066,12 @@ void getMetadataFromFileReader( fprintf( stderr, "\nError (%s) while reading ISM metadata from: %s\n\n", ivas_error_to_string( error ), IsmFileReader_getFilePath( ismReader ) ); exit( -1 ); } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS + objectMetadataBuffer->positions[objIdx].azimuth_fx = ismMetadata.azimuth_fx; objectMetadataBuffer->positions[objIdx].elevation_fx = ismMetadata.elevation_fx; objectMetadataBuffer->positions[objIdx].radius_fx = ismMetadata.radius_fx; objectMetadataBuffer->positions[objIdx].yaw_fx = ismMetadata.yaw_fx; objectMetadataBuffer->positions[objIdx].pitch_fx = ismMetadata.pitch_fx; -#else - objectMetadataBuffer->positions[objIdx].azimuth_fx = (Word32) ( ismMetadata.azimuth * ( 1 << 22 ) ); - objectMetadataBuffer->positions[objIdx].elevation_fx = (Word32) ( ismMetadata.elevation * ( 1 << 22 ) ); - objectMetadataBuffer->positions[objIdx].radius_fx = (Word16) ( ismMetadata.radius * ( 1 << 9 ) ); - objectMetadataBuffer->positions[objIdx].yaw_fx = (Word32) ( ismMetadata.yaw * ( 1 << 22 ) ); - objectMetadataBuffer->positions[objIdx].pitch_fx = (Word32) ( ismMetadata.pitch * ( 1 << 22 ) ); - - objectMetadataBuffer->positions[objIdx].azimuth = ismMetadata.azimuth; - objectMetadataBuffer->positions[objIdx].elevation = ismMetadata.elevation; - objectMetadataBuffer->positions[objIdx].radius = ismMetadata.radius; - objectMetadataBuffer->positions[objIdx].yaw = ismMetadata.yaw; - objectMetadataBuffer->positions[objIdx].pitch = ismMetadata.pitch; -#endif objectMetadataBuffer->positions[objIdx].non_diegetic_flag = ismMetadata.non_diegetic_flag; return; @@ -3219,25 +3125,15 @@ static void IsmPositionProvider_getNextFrame( /* Otherwise fall back to default position */ else { -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS objectMetadataBuffer->positions[objIdx].azimuth_fx = 0; objectMetadataBuffer->positions[objIdx].elevation_fx = 0; objectMetadataBuffer->positions[objIdx].radius_fx = 512; // 1.f in Q9 objectMetadataBuffer->positions[objIdx].yaw_fx = 0; objectMetadataBuffer->positions[objIdx].pitch_fx = 0; objectMetadataBuffer->positions[objIdx].non_diegetic_flag = 0; -#else - objectMetadataBuffer->positions[objIdx].azimuth = 0.0f; - objectMetadataBuffer->positions[objIdx].elevation = 0.0f; - objectMetadataBuffer->positions[objIdx].radius = 1.0f; - objectMetadataBuffer->positions[objIdx].yaw = 0.0f; - objectMetadataBuffer->positions[objIdx].pitch = 0.0f; - objectMetadataBuffer->positions[objIdx].non_diegetic_flag = 0; -#endif } /* Wrap azimuth to lie within (-180, 180] range */ -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS while ( LT_32( objectMetadataBuffer->positions[objIdx].azimuth_fx, 0 ) ) { objectMetadataBuffer->positions[objIdx].azimuth_fx = L_add( objectMetadataBuffer->positions[objIdx].azimuth_fx, DEG_360_IN_Q22 ); @@ -3262,35 +3158,6 @@ static void IsmPositionProvider_getNextFrame( /* Clamp pitch to lie within [-90, 90] range (can't be wrapped easily) */ objectMetadataBuffer->positions[objIdx].pitch_fx = L_min( L_max( objectMetadataBuffer->positions[objIdx].pitch_fx, -DEG_90_IN_Q22 ), DEG_90_IN_Q22 ); -#else - while ( objectMetadataBuffer->positions[objIdx].azimuth < 0.0f ) - { - objectMetadataBuffer->positions[objIdx].azimuth += 360.0f; - } - while ( objectMetadataBuffer->positions[objIdx].azimuth >= 360.0f ) - { - objectMetadataBuffer->positions[objIdx].azimuth -= 360.0f; - } - - /* Clamp elevation to lie within [-90, 90] range (can't be wrapped easily) */ - objectMetadataBuffer->positions[objIdx].elevation = min( max( objectMetadataBuffer->positions[objIdx].elevation, -90 ), 90 ); - objectMetadataBuffer->positions[objIdx].azimuth_fx = (Word32) ( objectMetadataBuffer->positions[objIdx].azimuth * ( 1 << 22 ) ); - objectMetadataBuffer->positions[objIdx].elevation_fx = (Word32) ( objectMetadataBuffer->positions[objIdx].elevation * ( 1 << 22 ) ); - /* Wrap yaw to lie within (-180, 180] range */ - while ( objectMetadataBuffer->positions[objIdx].yaw < 0.0f ) - { - objectMetadataBuffer->positions[objIdx].yaw += 360.0f; - } - while ( objectMetadataBuffer->positions[objIdx].yaw >= 360.0f ) - { - objectMetadataBuffer->positions[objIdx].yaw -= 360.0f; - } - - /* Clamp pitch to lie within [-90, 90] range (can't be wrapped easily) */ - objectMetadataBuffer->positions[objIdx].pitch = min( max( objectMetadataBuffer->positions[objIdx].pitch, -90 ), 90 ); - objectMetadataBuffer->positions[objIdx].yaw_fx = (Word32) ( ( objectMetadataBuffer->positions[objIdx].yaw ) * ( 1 << Q22 ) ); - objectMetadataBuffer->positions[objIdx].pitch_fx = (Word32) ( ( objectMetadataBuffer->positions[objIdx].pitch ) * ( 1 << Q22 ) ); -#endif } ++positionProvider->frameCounter; @@ -3596,23 +3463,12 @@ static void parseObjectPosition( exit( -1 ); } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS position->azimuth_fx = (Word32) ( meta_prm[0] * ( 1 << Q22 ) ); /* Q22 */ position->elevation_fx = (Word32) ( meta_prm[1] * ( 1 << Q22 ) ); /* Q22 */ position->radius_fx = (Word16) ( meta_prm[2] * ( 1 << Q9 ) ); /* Q9 */ position->yaw_fx = (Word32) ( meta_prm[5] * ( 1 << Q22 ) ); /* Q22 */ position->pitch_fx = (Word32) ( meta_prm[6] * ( 1 << Q22 ) ); /* Q22 */ position->non_diegetic_flag = (Word16) meta_prm[7]; -#else - position->azimuth = meta_prm[0]; - position->elevation = meta_prm[1]; - position->azimuth_fx = (Word32) ( meta_prm[0] * ( 1 << 22 ) ); - position->elevation_fx = (Word32) ( meta_prm[1] * ( 1 << 22 ) ); - position->radius = meta_prm[2]; - position->yaw = meta_prm[5]; - position->pitch = meta_prm[6]; - position->non_diegetic_flag = (int16_t) meta_prm[7]; -#endif return; } @@ -3808,20 +3664,10 @@ static void parseCombinedFormatInput( inConfig->numAmbisonicsBuses = 1; inConfig->ambisonicsBuses[0].audioConfig = audioConfig; inConfig->ambisonicsBuses[0].inputChannelIndex = inConfig->numAudioObjects; -#ifdef NONBE_1352_HARMONIZE_OSBA_LOUDNESS inConfig->ambisonicsBuses[0].gain_dB = 0.f; -#else - inConfig->ambisonicsBuses[0].gain_dB = -6.f; -#endif *configString += 4; /* Modify input gain for objects too */ -#ifndef NONBE_1352_HARMONIZE_OSBA_LOUDNESS - for ( int16_t i = 0; i < inConfig->numAudioObjects; ++i ) - { - inConfig->audioObjects[i].gain_dB = -6.f; - } -#endif } else if ( audioConfig == IVAS_AUDIO_CONFIG_MASA1 || audioConfig == IVAS_AUDIO_CONFIG_MASA2 ) { 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/enh32.c b/lib_basop/enh32.c index cf40bbec972f96c6858e957dfe8509f9907b4e40..d2931dd5da697b0410a425adf4163018800cd5bf 100644 --- a/lib_basop/enh32.c +++ b/lib_basop/enh32.c @@ -71,9 +71,7 @@ Word32 Mpy_32_32( Word32 L_var1, Word32 L_var2 ) { Word32 L_var_out; Word64 L64_var1; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif L64_var1 = ( (Word64) L_var1 * L_var2 ); L64_var1 = W_shl_o( L64_var1, 1, &Overflow ); @@ -105,9 +103,7 @@ Word32 Mpy_32_32_r( Word32 L_var1, Word32 L_var2 ) Word32 Madd_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ) { Word32 L_var_out; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif L_var_out = Mpy_32_16_1( L_var1, var2 ); L_var_out = L_add_o( L_var3, L_var_out, &Overflow ); @@ -138,9 +134,7 @@ Word32 Madd_32_16_r( Word32 L_var3, Word32 L_var1, Word16 var2 ) Word32 Msub_32_16( Word32 L_var3, Word32 L_var1, Word16 var2 ) { Word32 L_var_out; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif L_var_out = Mpy_32_16_1( L_var1, var2 ); L_var_out = L_sub_o( L_var3, L_var_out, &Overflow ); 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 8f97ad49ec895c1f8425dc8f53ab79eded6c45c3..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef _MOVE_H diff --git a/lib_basop/stl.h b/lib_basop/stl.h index f27c6892a65f6380f6c53fd86ba80a6638d5590b..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /* =========================================================================== diff --git a/lib_basop/typedef.h b/lib_basop/typedef.h index 867ed71ca77cf51afff82dccb5fdeb671c6085bb..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /* diff --git a/lib_com/ACcontextMapping_fx.c b/lib_com/ACcontextMapping_fx.c index 3fecfd2af54c3a4a3c56334eb58c5ce59e240872..19cbea1a4b8f9b74cbbbd4a9310bc43b86dff046 100644 --- a/lib_com/ACcontextMapping_fx.c +++ b/lib_com/ACcontextMapping_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -11,10 +11,10 @@ /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes Q0*/ - Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ - Word16 *idx, /* o : index in unmapped domain Q0*/ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { Word16 p; @@ -41,10 +41,10 @@ Word16 get_next_coeff_mapped( /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes Q0*/ - Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ - Word16 *idx, /* o : index in unmapped domain Q0*/ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { (void) pp; @@ -57,7 +57,7 @@ Word16 get_next_coeff_unmapped( return *idx; } -Word16 update_mixed_context( +Word16 update_mixed_context_fx( Word16 ctx, /* Q0 */ Word16 a /* Q0 */ ) @@ -78,7 +78,7 @@ Word16 update_mixed_context( return add( shl( s_and( ctx, 0xf ), 4 ), add( t, 13 ) ); } -Word32 update_mixed_context_ivas_fx( +Word32 update_mixed_context_fx_32( Word32 ctx, /* Q0 */ Word16 a /* Q0 */ ) @@ -104,10 +104,10 @@ Word32 update_mixed_context_ivas_fx( /*! r: index of next coefficient */ Word16 get_next_coeff_mapped_ivas_fx( - Word16 ii[2], /* i/o: coefficient indexes Q0*/ - Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ - Word16 *idx, /* o : index in unmapped domain Q0*/ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { UWord32 p; diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index aef9a6635e32836e7b3a52f505db4cb9c05584a4..70fe3d3d03776de94bcb2afab7c345bf88599439 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 46f8ecea1e78f01164d1acc083f29d3c26b145b6..e35416e5ff223ad28cf3713e3fac1f745df2aee0 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -1,8 +1,7 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + 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/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 09e2b7f4f8bece9a488773de92a3d1912b751a3d..173e4faf3583ca941cc5cfe36f852c36f4a9947b 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -427,13 +427,13 @@ void tcx_arith_scale_envelope( * and decoder remain synchronized. *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ - const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ const Word16 L_spec, /* Q0 */ - const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ - Word32 env[] /* o: shaped signal envelope Q16*/ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ) { Word16 k; diff --git a/lib_com/basop_com_lpc.c b/lib_com/basop_com_lpc.c index 0c6754371ae8eae03fe70b1ed256835b2977e6e0..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/basop_lsf_tools.c b/lib_com/basop_lsf_tools.c index 74f35bb0a1a37921398f37b099e518f18fe02902..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/basop_proto_func.h b/lib_com/basop_proto_func.h index 0e2fc5ad757ee775ed1de3a0ebe9cf2b2dfdbeb0..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef BASOP_PROTO_FUNC_H @@ -43,10 +43,6 @@ #include "basop_util.h" -/* tcx_lpc_cdk.h */ -#define LSF_GAP_VAL( x ) ( Word16 )( (x) *2.0f * 1.28f ) -#define LSFM( x ) FL2WORD16_SCALE( x * 1.28, 15 - 1 ) /* 14Q1*1.28 */ - /* cnst.h */ #define GAMMA1_INV 17809 /* weighting factor (numerator) default:0.92 (1Q14format) */ #define GAMMA16k_INV 17430 /* weighting factor (numerator) default:0.94 (1Q14format) */ diff --git a/lib_com/basop_settings.h b/lib_com/basop_settings.h index a23491a2635dbf9792836a176efe1ba432c19bdf..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef __BASOP_SETTINGS_H diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index 7c3ec835625dd45cd3f4a188c1c3623bfb9a37ad..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index bd55e59b689079f8ddb9241bee234173229763b4..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -987,61 +987,7 @@ Word32 div_w( Word32 L_num, Word32 L_den ) } } -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence -Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) -{ - Word32 z; - Word16 sx; - Word16 sy; - Word32 sign; - - /* assert (x >= (Word32)0); */ - assert( y != (Word32) 0 ); - - sign = 0; - move16(); - - IF( x < 0 ) - { - x = L_negate( x ); - sign = L_xor( sign, 1 ); - } - IF( y < 0 ) - { - y = L_negate( y ); - sign = L_xor( sign, 1 ); - } - - IF( x == (Word32) 0 ) - { - *s = 0; - return ( (Word32) 0 ); - } - - sx = norm_l( x ); - x = L_shl( x, sx ); - x = L_shr( x, 1 ); - move16(); - *s = sub( 1, sx ); - - sy = norm_l( y ); - y = L_shl( y, sy ); - move16(); - *s = add( *s, sy ); - - z = div_w( x, y ); - - if ( sign != 0 ) - { - z = L_negate( z ); - } - - return z; -} -#endif - -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. @@ -2565,7 +2511,6 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ headroom is introduced into acc */ -#ifdef OPT_2146_BASOP_UTIL_ADD_MANT32EXP Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ ( Word32 a_m, /* i : Mantissa of 1st operand a */ Word16 a_e, /* i : Exponent of 1st operand a */ @@ -2629,65 +2574,6 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ return ( a_m ); } -#else -Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ - ( Word32 a_m, /* i : Mantissa of 1st operand a */ - Word16 a_e, /* i : Exponent of 1st operand a */ - Word32 b_m, /* i : Mantissa of 2nd operand b */ - Word16 b_e, /* i : Exponent of 2nd operand b */ - Word16 *ptr_e ) /* o : exponent of result */ -{ - Word32 L_tmp; - Word16 shift; - - /* Compare exponents: the difference is limited to +/- 30 - The Word32 mantissa of the operand with lower exponent is shifted right by the exponent difference. - Then, the unshifted mantissa of the operand with the higher exponent is added. The addition result - is normalized and the result represents the mantissa to return. The returned exponent takes into - account all shift operations. - */ - if ( !a_m ) - { - a_e = b_e; - move16(); - } - - if ( !b_m ) - { - b_e = a_e; - move16(); - } - - shift = sub( a_e, b_e ); - shift = s_max( -31, shift ); - shift = s_min( 31, shift ); - if ( shift < 0 ) - { - /* exponent of b is greater than exponent of a, shr a_m */ - a_m = L_shl( a_m, shift ); - } - if ( shift > 0 ) - { - /* exponent of a is greater than exponent of b */ - b_m = L_shr( b_m, shift ); - } - a_e = add( s_max( a_e, b_e ), 1 ); - L_tmp = L_add( L_shr( a_m, 1 ), L_shr( b_m, 1 ) ); - shift = norm_l( L_tmp ); - if ( shift ) - L_tmp = L_shl( L_tmp, shift ); - if ( L_tmp == 0 ) - { - a_e = 0; - move16(); - } - if ( L_tmp != 0 ) - a_e = sub( a_e, shift ); - *ptr_e = a_e; - - return ( L_tmp ); -} -#endif static const Word16 shift_lc[] = { 9, 10 }; @@ -3071,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 bfafdfacbe7f6390b2b2b319a99196850ac1105c..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef __BASOP_UTIL_H__ @@ -328,12 +328,8 @@ Word16 BASOP_Util_Divide3232_Scale( Word32 x, /*!< i : Numerator*/ Word32 y, /*!< i : Denominator*/ Word16 *s ); /*!< o : Additional scalefactor difference*/ -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence -Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, /*!< i : Numerator*/ - Word32 y, /*!< i : Denominator*/ - Word16 *s ); /*!< o : Additional scalefactor difference*/ -#endif - +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*/ @@ -434,7 +430,7 @@ Word16 BASOP_util_norm_s_bands2shift( Word16 x ); /***********************************************************************/ /*! - \brief Calculate the headroom of the complex data in a 2 dimensional array + \brief Calculate the headroom of the complex data in a 2 dimensional array \return number of headroom bits */ @@ -913,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/bitalloc_fx.c b/lib_com/bitalloc_fx.c index 4d9c587994ed297a34d8b739e1658dca1805e154..2791e36ea99092f6d625608fefa0ece20289bc2d 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/bitallocsum_fx.c b/lib_com/bitallocsum_fx.c index fa71c92f88fc5ed4ba28841385395be2a1b3e37f..d052b81875e95c665b9a6beda28420995760f882 100644 --- a/lib_com/bitallocsum_fx.c +++ b/lib_com/bitallocsum_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 9909f413da13f5b33d3d7ba6306817a812e1c5f5..1045f7495bdbdea4cbeadd08d22fbbb6ba72b6f4 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include @@ -420,7 +420,6 @@ static Word16 fcb_table( const Word16 L_subfr ) { Word16 out; - // PMT("Not floating point computation, but fixed point operator are still missing ") out = PulseConfTable[n].bits; move16(); @@ -454,7 +453,6 @@ static ivas_error acelp_FCB_allocator_fx( Word16 *p_fixed_cdk_index; Word16 max_n; ivas_error error; - // PMT("Not floating point computation, but fixed point operator are still missing ") error = IVAS_ERR_OK; move32(); @@ -1693,7 +1691,6 @@ static Word16 allocate_unused( Word16 max_bit_per_pos = 0, bit_added = 0; move16(); move16(); - // PMT("Not floating point computation, but fixed point operator are still missing ") IF( prm_type == GAINSPRM ) { @@ -1797,7 +1794,6 @@ Word16 set_ACELP_flag( const Word16 cng_type /* i : CNG type */ ) { - // PMT("Not floating point computation, but fixed point operator are still missing ") test(); test(); test(); diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index d2f3a61f6e6acba27e341a8037e60605126b1333..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -3841,6 +3841,66 @@ ivas_error write_indices_ivas_fx( } +/*---------------------------------------------------------------------* + * convertSerialToBytestream( ) + * + * convert 16-bit short serial streams with 0x0000 and 0x0001 to a bytstream + *---------------------------------------------------------------------*/ + +void convertSerialToBytestream_fx( + const UWord16 *const serial, /* i : input serial bitstream with values 0 and 1 */ + const UWord16 num_bits, /* i : number of bits in the input bitstream */ + UWord8 *const bytestream /* o : output compact bitstream (bytestream) */ +) +{ + Word16 i, ia7, isr3; + UWord8 bit, bitinbyte; +#ifdef DEBUGGING + UWord8 bitinbyte2, bytestream_tmp; + assert( num_bits <= MAX_16 ); /* 512 kbps = 10240 bits, num_bits should always fits Word16 */ +#endif + + FOR( i = 0; i < num_bits; ++i ) + { + IF( EQ_32( serial[i], 0x0001 ) ) + { + bit = 1; + move16(); + } + ELSE + { + bit = 0; + move16(); + } + /*bitinbyte = bit << ( 7 - ( i & 0x7 ) );*/ + ia7 = s_and( i, 0x7 ); + isr3 = shr( i, 3 ); + bitinbyte = (UWord8) shl( (Word16) bit, sub( 7, ia7 ) ); +#ifdef DEBUGGING + bitinbyte2 = bit << ( 7 - ( i & 0x7 ) ); + assert( bitinbyte2 == bitinbyte ); +#endif + IF( !( ia7 ) ) + { + bytestream[isr3] = 0; + move16(); + } + /*bytestream[i >> 3] |= bitinbyte;*/ +#ifdef DEBUGGING + bytestream_tmp = bytestream[isr3]; + bytestream_tmp |= bitinbyte2; +#endif + bytestream[isr3] = (Word8) s_or( bytestream[isr3], bitinbyte ); +#ifdef DEBUGGING + assert( bytestream_tmp == bytestream[isr3] ); +#endif + move16(); + } + + return; +} + + /*-------------------------------------------------------------------* * decoder_selectCodec() * @@ -5234,23 +5294,3 @@ void evs_dec_previewFrame( return; } - -#ifndef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG -void dtx_read_padding_bits_fx( - DEC_CORE_HANDLE st, - const Word16 num_bits ) -{ - /* TODO: temporary hack, need to decide what to do with core-coder bitrate */ - Word32 tmp; - - tmp = st->total_brate; - move32(); - st->total_brate = L_add( st->total_brate, L_mult0( num_bits, FRAMES_PER_SEC ) ); - move32(); - get_next_indice_fx( st, num_bits ); - st->total_brate = tmp; - move32(); - - return; -} -#endif diff --git a/lib_com/cb_shape_fx.c b/lib_com/cb_shape_fx.c index 56d645ce087d5b54b9eef1509cc3a0009abc43d5..c300589941303e3df0c5b0b1dd7610363245b92e 100644 --- a/lib_com/cb_shape_fx.c +++ b/lib_com/cb_shape_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_com/cldfb_evs_fx.c b/lib_com/cldfb_evs_fx.c index 368ce7923e560606c84f1fb665c82d573abab039..a5f9da62a1941472a7aa615ad6b1820304a8f7ce 100644 --- a/lib_com/cldfb_evs_fx.c +++ b/lib_com/cldfb_evs_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! \file @@ -48,8 +48,9 @@ #define N40 ( 20 ) #define N60 ( 30 ) -static void -cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); +static Word16 CLDFB_getNumChannels( const Word32 sampleRate ); + +static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); #define cplxMpyS( yr, yi, xr, xi, cr, ci, syr, syi, sxr, sxi, CL_x, CL_z, C_c ) \ CL_x = CL_form( *xr, *xi ); \ @@ -722,7 +723,7 @@ void cldfbSynthesis_fx( scaleLB = limitScale32( sub( scale, scaleFactor->lb_scale ) ); scaleHB = limitScale32( sub( scale, scaleFactor->hb_scale ) ); - outScale = cldfbBank->synFilterHeadroom; + outScale = SYN_FILTER_HEADROOM_2_5MS; move16(); scaleMod = sub( add( scale, cldfbBank->outScalefactor ), outScale ); @@ -811,7 +812,6 @@ void cldfbSynthesis_fx( &iBuffer[0], &iBuffer[1], &iAnalysisS[0], &iAnalysisS[m - 1], 2, 2, 2, -2, rRotVctr, iRotVctr, m ); - /* FFT of DST IV */ scale = 0; move16(); @@ -909,25 +909,29 @@ void cldfbSynthesis_fx( /* move filter states */ Copy( &cldfbBank->FilterStates[nTimeSlots * L2], cldfbBank->FilterStates, statesSizeM2 ); set16_fx( &cldfbBank->FilterStates[statesSizeM2], 0, L2 ); + + return; } /*-------------------------------------------------------------------* - * configureClfdb() + * configureCldfb() * * configures a CLDFB handle *--------------------------------------------------------------------*/ -void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ - const Word16 no_channels, /*!< Number of channels (bands) */ - const Word16 frameSize /*!< FrameSize */ +void configureCldfb( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: Returns handle */ + const Word32 sampling_rate /* i : sampling rate */ ) { + Word16 no_channels; + no_channels = CLDFB_getNumChannels( sampling_rate ); - h_cldfb->no_channels = no_channels; + h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); move16(); assert( h_cldfb->no_channels >= 10 ); - h_cldfb->no_col = div_l( frameSize, shr( h_cldfb->no_channels, 1 ) ); + h_cldfb->no_col = CLDFB_NO_COL_MAX; move16(); /* was cldfbInitFilterBank()*/ @@ -937,8 +941,6 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ move16(); h_cldfb->bandsToZero = 0; move16(); - h_cldfb->filtermode = 0; - move16(); h_cldfb->memory = 0; move16(); h_cldfb->memory_length = 0; @@ -954,14 +956,13 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ h_cldfb->zeros = 0; move16(); - h_cldfb->synFilterHeadroom = SYN_FILTER_HEADROOM_2_5MS; - move16(); cldfb_init_proto_and_twiddles( h_cldfb ); + /* the following is related to the EVS implentation only */ h_cldfb->lsb = no_channels; move16(); - h_cldfb->usb = s_min( no_channels, h_cldfb->no_channels ); /* Does this make any sense? in the previous implemenatation lsb, usb and no_channels are all maxCldfbBands */ + h_cldfb->usb = s_min( no_channels, h_cldfb->no_channels ); move16(); h_cldfb->FilterStates = (void *) h_cldfb->FilterStates; @@ -971,19 +972,23 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ return; } + /*-------------------------------------------------------------------* * openClfdb() * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ + ivas_error openCldfb( - HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: Returns handle */ + const Word16 type, /* i : analysis or synthesis */ + const Word32 sampling_rate /* i : sampling rate */ ) { HANDLE_CLDFB_FILTER_BANK hs; + Word16 buf_len, maxCldfbBands; + + maxCldfbBands = CLDFB_getNumChannels( sampling_rate ); hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ); IF( hs == NULL ) @@ -991,26 +996,37 @@ ivas_error openCldfb( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } + hs->flags = 0; + move16(); + hs->type = type; move16(); + configureCldfb( hs, sampling_rate ); + IF( type == CLDFB_ANALYSIS ) { - hs->FilterStates = (Word16 *) malloc( STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); + // buf_len = sub( hs->p_filter_length, hs->no_channels ); + buf_len = STATE_BUFFER_SIZE * maxCldfbBands; } ELSE { - hs->FilterStates = (Word16 *) malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); + // buf_len = hs->p_filter_length; + buf_len = 2 * STATE_BUFFER_SIZE * maxCldfbBands; + move16(); } - if ( hs->FilterStates == NULL ) + + IF( ( hs->FilterStates = (Word16 *) malloc( buf_len * sizeof( Word16 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } + hs->flags = s_and( hs->flags, ~CLDFB_FLAG_KEEP_STATES ); move16(); - configureCldfb( hs, maxCldfbBands, frameSize ); hs->memory = NULL; + hs->memory32 = NULL; + hs->cldfb_state_fx = NULL; hs->memory_length = 0; move16(); @@ -1019,7 +1035,7 @@ ivas_error openCldfb( test(); IF( ( s_and( hs->flags, CLDFB_FLAG_KEEP_STATES ) == 0 ) && ( hs->FilterStates != 0 ) ) { - set16_fx( hs->FilterStates, 0, i_mult( STATE_BUFFER_SIZE, hs->no_channels ) ); + set16_fx( hs->FilterStates, 0, buf_len ); set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); hs->FilterStates_eg = 0; @@ -1032,7 +1048,7 @@ ivas_error openCldfb( { IF( s_and( hs->flags, CLDFB_FLAG_KEEP_STATES ) == 0 ) { - set16_fx( hs->FilterStates, 0, i_mult( shl( STATE_BUFFER_SIZE, 1 ), hs->no_channels ) ); + set16_fx( hs->FilterStates, 0, buf_len ); } } hs->FilterStates_eg = 0; @@ -1053,10 +1069,12 @@ ivas_error openCldfb( * * Change sample rate of filter bank *--------------------------------------------------------------------*/ -void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, - const Word16 newCldfbBands, - const Word16 frameSize, - const Word8 firstFrame ) + +void resampleCldfb( + HANDLE_CLDFB_FILTER_BANK hs, + const Word32 sampling_rate, /* i : sampling rate */ + const Word16 frameSize, + const Word8 firstFrame ) { Word16 timeOffset; @@ -1072,7 +1090,7 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, move16(); /* new settings */ - configureCldfb( hs, newCldfbBands, frameSize ); + configureCldfb( hs, sampling_rate ); /* resample cldfb state buffer */ timeOffset = sub( sub( hs->p_filter_length, hs->no_channels ), hs->zeros ); @@ -1104,20 +1122,20 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, Returns: headroom */ -Word16 -AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ - Word32 **rSubband32, /*!< Real bands Q(cldfbSacle)*/ - Word32 **iSubband32, /*!< Imaginary bands Q(cldfbSacle)*/ - Word16 **rSubband16, /*!< Real bands Q(cldfbSacle)*/ - Word16 **iSubband16, /*!< Imaginary bands Q(cldfbScale)*/ - Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ + +Word16 AnalysisPostSpectrumScaling_Fx( + HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ + Word32 **rSubband32, /*!< Real bands Q(cldfbSacle)*/ + Word32 **iSubband32, /*!< Imaginary bands Q(cldfbSacle)*/ + Word16 **rSubband16, /*!< Real bands Q(cldfbSacle)*/ + Word16 **iSubband16, /*!< Imaginary bands Q(cldfbScale)*/ + Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ ) { Word16 i; Word16 j; Word16 headRoom; - headRoom = BASOP_util_norm_l_dim2_cplx( (const Word32 *const *) rSubband32, (const Word32 *const *) iSubband32, @@ -1215,19 +1233,21 @@ void analysisCldfbEncoder_fx( return; } -void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTecEnc ) + +void GetEnergyCldfb( + Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ) { Word16 j; Word16 k; @@ -1374,14 +1394,12 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } -Word16 -CLDFB_getNumChannels( Word32 sampleRate ) +static Word16 CLDFB_getNumChannels( + const Word32 sampleRate ) { - Word16 nChannels = 0; move16(); - SWITCH( sampleRate ) { case 48000: @@ -1413,13 +1431,15 @@ CLDFB_getNumChannels( Word32 sampleRate ) return ( nChannels ); } + /*-------------------------------------------------------------------* * cldfb_get_memory_length() * * Return length of filter state for recovery *--------------------------------------------------------------------*/ -static Word16 -cldfb_get_memory_length( HANDLE_CLDFB_FILTER_BANK hs ) + +static Word16 cldfb_get_memory_length( + HANDLE_CLDFB_FILTER_BANK hs ) { IF( EQ_16( hs->type, CLDFB_ANALYSIS ) ) { @@ -1431,39 +1451,21 @@ cldfb_get_memory_length( HANDLE_CLDFB_FILTER_BANK hs ) } } -/*-------------------------------------------------------------------* - * GetEnergyCldfb() - * - * Remove handle - *--------------------------------------------------------------------*/ -void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ) /* i: cldfb handle */ -{ - IF( *h_cldfb != NULL ) - { - IF( ( *h_cldfb )->FilterStates != NULL ) - { - free( ( *h_cldfb )->FilterStates ); - } - free( *h_cldfb ); - } - *h_cldfb = NULL; -} - /*-------------------------------------------------------------------* * cldfb_init_proto_and_twiddles() * * Initializes rom pointer *--------------------------------------------------------------------*/ -static void -cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ -{ +static void cldfb_init_proto_and_twiddles( + HANDLE_CLDFB_FILTER_BANK hs /* i: cldfb handle */ +) +{ /*find appropriate set of rotVecs*/ SWITCH( hs->no_channels ) { case 10: - hs->rRotVctr = rRotVectr_10; hs->iRotVctr = iRotVectr_10; hs->synGain = cldfb_synGain[0]; @@ -1571,6 +1573,8 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle } BREAK; } + + return; } @@ -1581,8 +1585,10 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle * * Save the memory of filter; to be restored with cldfb_restore_memory() *--------------------------------------------------------------------*/ -ivas_error -cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ + +ivas_error cldfb_save_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i: cldfb handle */ +) { test(); IF( hs->memory != NULL || hs->memory_length != 0 ) @@ -1603,6 +1609,7 @@ cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } + return IVAS_ERR_OK; } @@ -1612,12 +1619,14 @@ cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ * * Restores the memory of filter; memory to be save by cldfb_save_memory() *--------------------------------------------------------------------*/ -void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ + +void cldfb_restore_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { Word16 size; - size = cldfb_get_memory_length( hs ); /* read the memory */ @@ -1626,7 +1635,6 @@ void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ hs->FilterStates_eg = hs->memory[hs->memory_length + CLDFB_MEM_EXPONENTS]; move16(); - /* adjust sample rate if it was changed in the meanwhile */ IF( NE_16( hs->memory_length, size ) ) { @@ -1640,12 +1648,16 @@ void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ return; } + /*-------------------------------------------------------------------* * cldfb_reset_memory() * * Resets the memory of filter. *--------------------------------------------------------------------*/ -void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ + +void cldfb_reset_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { Word16 length; @@ -1655,5 +1667,6 @@ void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); hs->FilterStates_eg = 0; move16(); + return; } diff --git a/lib_com/cldfb_fx.c b/lib_com/cldfb_fx.c index 2ef540fe398c4983a22694bd310117c13c5b4319..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 @@ -31,13 +31,12 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include #include "options.h" -#include #include "stat_dec.h" #include "prot_fx.h" #include "rom_com.h" @@ -56,8 +55,6 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); -static void cldfb_init_proto_and_twiddles_enc_fx( HANDLE_CLDFB_FILTER_BANK hs ); - static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ @@ -72,17 +69,13 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ TEC_ENC_HANDLE hTecEnc ); -/*-------------------------------------------------------------------* - * cplxMult() - * - * Conduct complex multiplication - *--------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * cldfbAnalysis_ivas() * * Conduct multiple overlap complex low delay MDCT *--------------------------------------------------------------------*/ + void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ Word32 **realBuffer_fx, /* o : real value buffer Qx - 5*/ @@ -602,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 ) ); @@ -1327,38 +1321,22 @@ void cldfbSynthesis_ivas_fx( return; } -void configureCldfb_ivas_enc_fx( - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const Word32 sampling_rate /* i : sampling rate */ -) -{ - h_cldfb->no_col = CLDFB_NO_COL_MAX; - h_cldfb->bandsToZero = 0; - h_cldfb->nab = 0; - - h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); - h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); - h_cldfb->zeros = 0; - h_cldfb->anaScalefactor = 0; - h_cldfb->synScalefactor = 0; - h_cldfb->filterScale = 1; - cldfb_init_proto_and_twiddles_enc_fx( h_cldfb ); +/*-------------------------------------------------------------------* + * configureCldfb() + * + * configures a CLDFB handle + *--------------------------------------------------------------------*/ - return; -} void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ const Word32 sampling_rate /* i : sampling rate */ ) { - h_cldfb->no_col = CLDFB_NO_COL_MAX; move16(); h_cldfb->bandsToZero = 0; move16(); - h_cldfb->nab = 0; - move16(); // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); @@ -1369,6 +1347,8 @@ void configureCldfb_ivas_fx( move16(); h_cldfb->synScalefactor = 0; move16(); + h_cldfb->filterScale = 1; + move16(); h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); move16(); @@ -1376,17 +1356,20 @@ void configureCldfb_ivas_fx( return; } + + /*-------------------------------------------------------------------* * openClfdb() * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ + ivas_error openCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype, /* i : CLDFB version (1.25ms/5ms delay) */ - const Word16 enc_dec ) /* i : encoder/decoder flag */ + const Word16 enc_dec ) /* i : encoder/decoder flag */ { HANDLE_CLDFB_FILTER_BANK hs; Word16 buf_len; @@ -1400,17 +1383,19 @@ ivas_error openCldfb_ivas_fx( move32(); hs->prototype = prototype; move32(); + + configureCldfb_ivas_fx( hs, sampling_rate ); + IF( enc_dec == ENC ) { - configureCldfb_ivas_enc_fx( hs, sampling_rate ); hs->Q_cldfb_state = 0; } ELSE { - configureCldfb_ivas_fx( hs, sampling_rate ); hs->Q_cldfb_state = Q11; } move16(); + hs->memory32 = NULL; hs->FilterStates = NULL; hs->memory_length = 0; @@ -1443,11 +1428,13 @@ ivas_error openCldfb_ivas_fx( return IVAS_ERR_OK; } + /*-------------------------------------------------------------------* * resampleCldfb_ivas() * * Change sample rate of filter bank *--------------------------------------------------------------------*/ + void resampleCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const Word32 newSamplerate ) @@ -1468,19 +1455,21 @@ void resampleCldfb_ivas_fx( return; } -static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTecEnc ) + +static void GetEnergyCldfb_ivas_fx( + Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ) { Word16 j; Word16 k; @@ -1692,7 +1681,14 @@ void analysisCldfbEncoder_ivas_fx( return; } -void deleteCldfb_ivas_fx( + +/*-------------------------------------------------------------------* + * deleteCldfb() + * + * Remove and deallcoate handle + *--------------------------------------------------------------------*/ + +void deleteCldfb_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ) { @@ -1945,351 +1941,13 @@ static void cldfb_init_proto_and_twiddles( return; } -static void cldfb_init_proto_and_twiddles_enc_fx( - HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ -) -{ - /*find appropriate set of rotVecs*/ - SWITCH( hs->no_channels ) - { - case 10: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L10_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L10_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L10_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L10_fx; - hs->rRotVctr = rRotVectr_10; - hs->iRotVctr = iRotVectr_10; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 10; - hs->da = 10; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->scale = cldfb_scale_2_5ms[0]; - move16(); - move16(); - hs->p_filter_32 = CLDFB80_10_fx; - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 40; - hs->da = -20; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_10_fx; - hs->scale = cldfb_scale_5_0ms[0]; - move16(); - move16(); - } - BREAK; - - case 16: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L16_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L16_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L16_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L16_fx; - hs->rRotVctr = rRotVectr_16; - hs->iRotVctr = iRotVectr_16; - { - hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 20; - hs->da = 20; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_16_fx; - hs->scale = cldfb_scale_2_5ms[1]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 80; - hs->da = -40; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_16_fx; - hs->scale = cldfb_scale_5_0ms[1]; - move16(); - move16(); - } - BREAK; - - case 20: - hs->rRotVctr = rRotVectr_20; - hs->iRotVctr = iRotVectr_20; - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L20_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L20_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L20_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L20_fx; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 20; - hs->da = 20; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_20_fx; - hs->scale = cldfb_scale_2_5ms[2]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 80; - hs->da = -40; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_20_fx; - hs->scale = cldfb_scale_5_0ms[2]; - move16(); - move16(); - } - BREAK; - - case 30: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L30_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L30_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L30_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L30_fx; - hs->rRotVctr = rRotVectr_30; - hs->iRotVctr = iRotVectr_30; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[6], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[6], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 30; - hs->da = 30; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->scale = cldfb_scale_2_5ms[6]; - hs->p_filter_32 = CLDFB80_30_fx; - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 120; - hs->da = -60; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->scale = cldfb_scale_5_0ms[6]; - hs->p_filter_32 = LDQMF_30_fx; - move16(); - move16(); - } - BREAK; - - case 32: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L32_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L32_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L32_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L32_fx; - hs->rRotVctr = rRotVectr_32; - hs->iRotVctr = iRotVectr_32; - { - hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 32; - hs->da = 32; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_32_fx; - hs->scale = cldfb_scale_2_5ms[3]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 160; - hs->da = -80; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->scale = cldfb_scale_5_0ms[3]; - hs->p_filter_32 = LDQMF_32_fx; - move16(); - move16(); - } - BREAK; - - case 40: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L40_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L40_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L40_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L40_fx; - hs->rRotVctr = rRotVectr_40; - hs->iRotVctr = iRotVectr_40; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 40; - hs->da = 40; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->scale = cldfb_scale_2_5ms[4]; - hs->p_filter_32 = CLDFB80_40_fx; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 160; - hs->da = -80; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_40_fx; - hs->scale = cldfb_scale_5_0ms[4]; - move16(); - move16(); - } - BREAK; - - case 60: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L60_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L60_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L60_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L60_fx; - hs->rRotVctr = rRotVectr_60; - hs->iRotVctr = iRotVectr_60; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 60; - hs->da = 60; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_60_fx; - hs->scale = cldfb_scale_2_5ms[5]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 240; - hs->da = -120; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_60_fx; - hs->scale = cldfb_scale_5_0ms[5]; - move16(); - move16(); - } - break; - } - - return; -} /*-------------------------------------------------------------------* * cldfb_save_memory_ivas() * * Save the memory of filter; to be restored with cldfb_restore_memory_ivas() *--------------------------------------------------------------------*/ + ivas_error cldfb_save_memory_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index f23ef505c946ff2e687a3c0243b48488754f0e7e..14ddc27d1f309404c5089da6fd422ad579d1b491 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -180,12 +180,14 @@ IF( GT_16( element_mode, IVAS_SCE ) ) { return; } + /*---------------------------------------------------------------------* * Generate white noise vector *---------------------------------------------------------------------*/ /*for ( i=0; i> 1) #define INV_FRAME_PER_SEC_Q15 656 -#define INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 164 #define FRAME_SIZE_NS 20000000L #define ACELP_LOOK_NS 8750000L @@ -626,7 +511,7 @@ enum #define N_WS2N_FRAMES 40 /* number of frames for attenuation during the band-width switching */ #define N_NS2W_FRAMES 20 /* number of frames for attenuation during the band-width switching */ -#define ONE_BY_N_NS2W_FRAMES_Q15 ( 1638 ) +#define ONE_BY_N_NS2W_FRAMES_Q15 ( 1638 ) /*----------------------------------------------------------------------------------* * Coder types (only for ACELP core when not running in AMR-WB IO mode) @@ -668,9 +553,7 @@ enum #define ACELP_TCX_TRANS_NS 1250000 /* Duration of the ACELP->TCX overlap - 1.25 ms */ #define L_FRAME_MAX L_FRAME48k /* Max 20ms frame size @48kHz */ #define L_FRAME_PLUS 1200 /* Max frame size (long TCX frame) */ -#ifdef FIX_1320_STACK_CPE_DECODER #define L_FRAME_PLUS_INTERNAL 800 /* Max frame size (long TCX frame) at maximum internal sampling rate */ -#endif #define L_MDCT_OVLP_MAX NS2SA( 48000, ACELP_LOOK_NS ) /* = Max mdct overlap */ #define N_TCX10_MAX 480 /* Max size of TCX10 MDCT spectrum */ #define BITS_TEC 1 /* number of bits for TEC */ @@ -710,14 +593,14 @@ enum #define AUTO_REGRESSIVE 2 #define INT_FS_12k8 12800 /* internal sampling frequency */ -#define ONE_BY_INT_FS_12k8_Q42 343597384 /* internal sampling frequency */ +#define ONE_BY_INT_FS_12k8_Q42 343597384 /* internal sampling frequency */ #define M 16 /* order of the LP filter @ 12.8kHz */ #define L_FRAME 256 /* frame size at 12.8kHz */ #define NB_SUBFR 4 /* number of subframes per frame */ #define L_SUBFR ( L_FRAME / NB_SUBFR ) /* subframe size */ #define L_SUBFR_LOG2 6 /* To be used for shift operation instead of division */ -#define L_SUBFR_Q6 ((L_FRAME/NB_SUBFR)*64) /* subframe size */ -#define L_SUBFR_Q16 ((L_FRAME/NB_SUBFR)*65536) /* subframe size */ +#define L_SUBFR_Q6 ((L_FRAME/NB_SUBFR)*64) /* subframe size */ +#define L_SUBFR_Q16 ((L_FRAME/NB_SUBFR)*65536) /* subframe size */ #define L_INP_MEM ( L_LOOK_16k + ( ( L_LP_16k - ( NS2SA( INT_FS_16k, ACELP_LOOK_NS ) + L_SUBFR16k / 2 ) ) - 3 * L_SUBFR16k / 2 ) ) /*=240 samples length of memory of input signal, given by the Look-Ahead + the past memory (max needed for the LP window at 16 kHz) */ #define L_INP_12k8 ( L_INP_MEM + L_FRAME ) /* length of input signal buffer @12.8kHz */ @@ -738,8 +621,7 @@ enum #define OLD_SYNTH_SIZE_ENC L_FRAME32k + L_FRAME32k / 4 /* encoder synth memory */ #define OLD_EXC_SIZE_DEC ( 3 * L_FRAME_MAX / 2 + 2 * L_FIR_FER2 ) /*old excitation needed for decoder for PLC*/ -#define TILT_CODE_FLT 0.3f /* ACELP code preemphasis factor */ -#define TILT_CODE 9830 /* ACELP code preemphasis factor ~=0.3f (0Q15) (=0.299987792968750) */ +#define TILT_CODE 9830 /* ACELP code preemphasis factor ~=0.3f (0Q15) (=0.299987792968750) */ #define L_SUBFR16k ( L_FRAME16k / NB_SUBFR ) /* subframe size at 16kHz */ #define L_HALFR16k ( 2 * L_SUBFR16k ) /* half-frame size at 16kHz */ @@ -747,34 +629,27 @@ enum #define MAX_LP_FILTER_ORDER 20 /* Max order of an LP filter */ #define L_INTERPOL2 16 /* Length of filter for interpolation */ #define L_INTERPOL ( L_INTERPOL2 + 1 ) /* Length of filter for interpolation */ -#define TILT_FAC 0.68f /* tilt factor (denominator) */ -#define TILT_FAC_FX 22282 /* tilt factor (denominator) fixed-point*/ +#define TILT_FAC_FX 22282 /* tilt factor (denominator) fixed-point, 0.68f */ #define M16k 20 /* order of the LP filter @ 16kHz */ -#define PIT_SHARP 0.85f /* pitch sharpening factor */ -#define PIT_SHARP_fx 27853 /* pitch sharpening factor */ +#define PIT_SHARP_fx 27853 /* pitch sharpening factor, 0.85f */ #define PIT_UP_SAMP 4 /* upsampling factor for 1/4 interpolation filter */ -#define UP_SAMP 4 /* upsampling factor for 1/4 interpolation filter */ +#define UP_SAMP 4 /* upsampling factor for 1/4 interpolation filter */ #define PIT_L_INTERPOL2 16 #define PIT_FIR_SIZE2 ( PIT_UP_SAMP * PIT_L_INTERPOL2 + 1 ) #define PIT_UP_SAMP6 6 #define PIT_L_INTERPOL6_2 17 #define PIT_FIR_SIZE6_2 ( PIT_UP_SAMP6 * PIT_L_INTERPOL6_2 + 1 ) -#define E_MIN 0.0035f /* minimum allowable energy */ -#define E_MIN_Q11_FX 7 /* minimum allowable energy in Q11*/ -#define E_MIN_Q27_FX 469762 /* minimum allowable energy in Q27*/ -#define STEP_DELTA 0.0625f /* quantization step for tilt compensation of gaussian cb. excitation */ -#define GAMMA_EV 0.92f /* weighting factor for core synthesis error weighting */ -#define FORMANT_SHARPENING_NOISE_THRESHOLD 21.0f /* lp_noise level above which formant sharpening is deactivated */ -#define E_MIN_FX 1 /* QSCALE (Q7)*/ -#define E_MIN_IVAS_FX 1835 /* (Q19) (E12) */ -#define E_MIN_IVAS_FX_Q31 7516193 /* (Q31) (0.0035f) */ - -#define STEP_DELTA_FX 11 -#define FORMANT_SHARPENING_NOISE_THRESHOLD_FX 5376 /* 21 (!8)lp_noise level above which formant sharpening is deactivated - at this level most of 20 dB SNR office noisy speech still uses sharpening */ - -#define LP_NOISE_THRESH_FLT 20.f -#define LP_NOISE_THRESH 167772160l/*20.f Q23*/ -#define LFAC 160 /* FAC maximum frame length */ +#define E_MIN_Q11_FX 7 /* minimum allowable energy, 0.0035f in Q11 */ +#define E_MIN_Q27_FX 469762 /* minimum allowable energy, 0.0035f in Q27 */ +#define E_MIN_FX 1 /* QSCALE (Q7)*/ +#define E_MIN_IVAS_FX 1835 /* (Q19) (E12) */ +#define E_MIN_IVAS_FX_Q31 7516193 /* (Q31) (0.0035f) */ + +#define STEP_DELTA_FX 11 /* quantization step for tilt compensation of gaussian cb. excitation, 0.0625f */ +#define FORMANT_SHARPENING_NOISE_THRESHOLD_FX 5376 /* 21.f (!8)lp_noise level above which formant sharpening is deactivated - at this level most of 20 dB SNR office noisy speech still uses sharpening */ + +#define LP_NOISE_THRESH 167772160l /* 20.f Q23 */ +#define LFAC 160 /* FAC maximum frame length */ #define L_FILT_UP8k 24 /* Resampling - delay of filter for 8 kHz output signals (at 12.8 kHz sampling rate) */ #define LEN_WIN_SSS 120 @@ -820,36 +695,22 @@ typedef enum } CLDFB_PROTOTYPE; /* pre-calculated scale values for the cldfb filter prototypes - values are calculated like this: sqrt( 6400 / no_cldfb_channels * sum(filter[k]**2)) */ -#define CLDFB80_10_SCALE 88.293854f -#define CLDFB80_16_SCALE 88.299622f -#define CLDFB80_20_SCALE 88.300926f -#define CLDFB80_30_SCALE 88.234489f -#define CLDFB80_32_SCALE 88.303848f -#define CLDFB80_40_SCALE 88.304726f -#define CLDFB80_60_SCALE 88.028412f -#define CLDFB80_10_SCALE_FX_Q8 ( 22603 ) -#define CLDFB80_16_SCALE_FX_Q8 ( 22605 ) -#define CLDFB80_20_SCALE_FX_Q8 ( 22605 ) -#define CLDFB80_30_SCALE_FX_Q8 ( 22588 ) -#define CLDFB80_32_SCALE_FX_Q8 ( 22606 ) -#define CLDFB80_40_SCALE_FX_Q8 ( 22606 ) -#define CLDFB80_60_SCALE_FX_Q8 ( 22535 ) - -#define LDQMF_10_SCALE 84.567841f -#define LDQMF_16_SCALE 84.567932f -#define LDQMF_20_SCALE 84.567963f -#define LDQMF_30_SCALE 84.501907f -#define LDQMF_32_SCALE 84.568001f -#define LDQMF_40_SCALE 84.567986f -#define LDQMF_60_SCALE 84.303284f -#define LDQMF_10_SCALE_FX_Q8 ( 21649 ) -#define LDQMF_16_SCALE_FX_Q8 ( 21649 ) -#define LDQMF_20_SCALE_FX_Q8 ( 21649 ) -#define LDQMF_30_SCALE_FX_Q8 ( 21632 ) -#define LDQMF_32_SCALE_FX_Q8 ( 21649 ) -#define LDQMF_40_SCALE_FX_Q8 ( 21649 ) -#define LDQMF_60_SCALE_FX_Q8 ( 21582 ) + values are calculated like this: sqrt( 6400 / no_cldfb_channels * sum(filter[k]**2)) */ +#define CLDFB80_10_SCALE_FX_Q8 ( 22603 ) /* 88.293854f */ +#define CLDFB80_16_SCALE_FX_Q8 ( 22605 ) /* 88.299622f */ +#define CLDFB80_20_SCALE_FX_Q8 ( 22605 ) /* 88.300926f */ +#define CLDFB80_30_SCALE_FX_Q8 ( 22588 ) /* 88.234489f */ +#define CLDFB80_32_SCALE_FX_Q8 ( 22606 ) /* 88.303848f */ +#define CLDFB80_40_SCALE_FX_Q8 ( 22606 ) /* 88.304726f */ +#define CLDFB80_60_SCALE_FX_Q8 ( 22535 ) /* 88.028412f */ + +#define LDQMF_10_SCALE_FX_Q8 ( 21649 ) /* 84.567841f */ +#define LDQMF_16_SCALE_FX_Q8 ( 21649 ) /* 84.567932f */ +#define LDQMF_20_SCALE_FX_Q8 ( 21649 ) /* 84.567963f */ +#define LDQMF_30_SCALE_FX_Q8 ( 21632 ) /* 84.501907f */ +#define LDQMF_32_SCALE_FX_Q8 ( 21649 ) /* 84.568001f */ +#define LDQMF_40_SCALE_FX_Q8 ( 21649 ) /* 84.567986f */ +#define LDQMF_60_SCALE_FX_Q8 ( 21582 ) /* 84.303284f */ #define L_FFT 256 /* Spectral analysis - length of the FFT */ #define LOG2_L_FFT 8 /* Spectral analysis - log2 of L_FFT */ @@ -862,16 +723,14 @@ typedef enum #define VOIC_BAND_8k 17 /* Spectral analysis - number of critical bands considered as voiced in NB (related to VOIC_BINS_8k) */ #define N_SPEC (L_FFT/2) /* number of spectral bins */ -#define M_ALPHA 0.9f /* Multi-harm analysis - forgetting factor of LT correlation map */ -#define M_GAMMA 0.99f /* Multi-harm analysis - forgetting factor of active speech decision predictor */ #define THR_CORR 56 /* Multi-harm analysis - starting threshold of multi-harm. correlation */ -#define M_GAMMA_FX 32440 /* Q15 - forgetting factor of active speech decision predictor */ -#define M_ALPHA_FX 29491 /* Q15 - forgetting factor of LT correlation map */ -#define ONE_MINUS_M_ALPHA 3277 /* Q15 - one minus forgetting factor of LT correlation map */ -#define THR_CORR_INIT_FX (56<<9 ) /* Q9 - starting threshold of multi-harm. correlation */ -#define THR_NCHAR_WB_FX 2048 /* Q11 threshold for noise character (WB) */ -#define THR_NCHAR_NB_FX 2048 /* Q11 threshold for noise character (NB) */ +#define M_GAMMA_FX 32440 /* 0.99f in Q15 - forgetting factor of active speech decision predictor */ +#define M_ALPHA_FX 29491 /* 0.9f in Q15 - forgetting factor of LT correlation map */ +#define ONE_MINUS_M_ALPHA 3277 /* Q15 - one minus forgetting factor of LT correlation map */ +#define THR_CORR_INIT_FX (56<<9 ) /* Q9 - starting threshold of multi-harm. correlation */ +#define THR_NCHAR_WB_FX 2048 /* Q11 threshold for noise character (WB) */ +#define THR_NCHAR_NB_FX 2048 /* Q11 threshold for noise character (NB) */ #define L_LP 320 /* LP analysis - LP window size */ @@ -879,7 +738,7 @@ typedef enum #define L_LP_AMR_WB 384 /* LP analysis - windows size (only for AMR-WB IO mode) */ #define GRID50_POINTS 51 /* LP analysis - half-number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ #define GRID40_POINTS 41 /* LP analysis - half-number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ -#define GRID80_POINTS 80 /* LP analysis - number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ +#define GRID80_POINTS 80 /* LP analysis - number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ #define GRID100_POINTS 100 /* LP analysis - number of points to evaluate Chebyshev polynomials */ #define PIT_MIN 34 /* OL pitch analysis - Minimum pitch lag */ @@ -912,7 +771,7 @@ typedef enum #define PIT_MAX_32k 577 #define PIT_FR1_8b_32k 75 #define PIT_MAX_MAX PIT_MAX_32k -#define PIT_MAX_16k 289 +#define PIT_MAX_16k 289 #define PIT_FR1_8b 92 /* Pitch encoding - Minimum pitch lag with resolution 1 */ #define PIT_FR2_9b 128 /* Pitch encoding - Minimum pitch lag with resolution 1/2 */ @@ -944,25 +803,20 @@ typedef enum #define DTX_THR 5 /* DTX - lp_noise threshold for DTX at higher bitrates */ #define DTX_HIST_SIZE 8 /* CNG & DTX - number of last signal frames used for CNG averaging */ -#define CNG_ISF_FACT 0.9f /* CNG & DTX - CNG spectral envelope smoothing factor */ -#define STEP_AMR_WB_SID 2.625f /* CNG & DTX - CNG energy quantization step */ -#define CNG_ISF_FACT_FX 29491 /* Q15(0.9), CNG & DTX - CNG spectral envelope smoothing factor*/ -#define STEP_AMR_WB_SID_FX 10752 /* Q12 */ +#define CNG_ISF_FACT_FX 29491 /* Q15 (0.9f), CNG & DTX - CNG spectral envelope smoothing factor*/ +#define STEP_AMR_WB_SID_FX 10752 /* Q12 (2.625f), CNG & DTX - CNG energy quantization step */ #define HO_HIST_SIZE 8 /* CNG & DTX - maximal number of hangover frames used for averaging */ #define NUM_ENV_CNG 20 -#define BUF_L_NRG 0.7f /* CNG & DTX - lower threshold factor for hangover updates */ -#define BUF_H_NRG 1.03f /* CNG & DTX - higher threshold factor for hangover updates */ #define CNG_TYPE_HO 20 /* CNG & DTX - hangover for switching between CNG types */ -#define BUF_L_NRG_FX 22938 /* Q15(0.7), CNG & DTX - lower threshold offset for hangover updates */ -#define ONE_OVER_BUF_H_NRG_FX 31814 /* Q15(1/1.03), CNG & DTX - inverse of higher threshold offset for hangover updates */ -#define HO_ATT_FAC_FX 3277 /* Q15(0.1), CNG & DTX - Hangover frame attenuation rate factor */ +#define BUF_L_NRG_FX 22938 /* Q15(0.7), CNG & DTX - lower threshold offset for hangover updates */ +#define ONE_OVER_BUF_H_NRG_FX 31814 /* Q15(1/1.03), CNG & DTX - inverse of higher threshold offset for hangover updates */ +#define HO_ATT_FAC_FX 3277 /* Q15(0.1), CNG & DTX - Hangover frame attenuation rate factor */ #define BUF_DEC_RATE 25 /* CNG & DTX - buffer size decrease rate for active frames */ -#define STEP_SID 5.25f /* CNG & DTX - CNG energy quantization step */ -#define STEP_SID_FX 21504 /* Q12 */ -#define ISTEP_SID_FX 6242 /* Inverse of CNG & DTX - CNG energy quantization step in Q15(1/5.25 in Q15)*/ -#define ISTEP_AMR_WB_SID_FX 12483 /* Q15(1/2.625) Inverse of CNG & DTX - CNG energy quantization step */ +#define STEP_SID_FX 21504 /* CNG & DTX - CNG energy quantization step, 5.25f in Q12 */ +#define ISTEP_SID_FX 6242 /* Inverse of CNG & DTX - CNG energy quantization step in Q15(1/5.25 in Q15)*/ +#define ISTEP_AMR_WB_SID_FX 12483 /* Q15(1/2.625) Inverse of CNG & DTX - CNG energy quantization step */ #define MIN_ACT_CNG_UPD 20 /* DTX - Minimum number of consecutive active frames for CNG mode update */ @@ -970,11 +824,10 @@ typedef enum #define TOTALNOISE_HIST_SIZE 4 -#define SUBFFT_QIN 10 -#define DATAFFT_Q 5 -#define SUBFFT_QOUT SUBFFT_QIN-DATAFFT_Q -#define SPECAMP_Q SUBFFT_QIN - +#define SUBFFT_QIN 10 +#define DATAFFT_Q 5 +#define SUBFFT_QOUT SUBFFT_QIN-DATAFFT_Q +#define SPECAMP_Q SUBFFT_QIN #define UNKNOWN_NOISE 0 /* unknown noisy type */ #define SILENCE 1 /* speech with high SNR */ @@ -987,10 +840,8 @@ typedef enum #define PRE_SNR_NUM 32 /* number of snr to calculate average SNR of all sub-bands */ #define POWER_NUM 56 /* number of energy of several frames*/ #define PRE_SPEC_DIF_NUM 56 /* number of energy of several frames*/ -#define CLDFBVAD_VAD_ON 1 -#define COM_VAD_ON 2 - - +#define CLDFBVAD_VAD_ON 1 +#define COM_VAD_ON 2 #define MAX_SUBBAND_NUM 12 /* max number of sub-band divided non-uniformly*/ #define BG_ENG_NUM MAX_SUBBAND_NUM /* number of energy of sub-band divided non-uniformly*/ @@ -1000,19 +851,17 @@ typedef enum #define STABLE_NUM 4 /* number of time-domain stable rate*/ #define SFM_NUM 3 /* number of spectral flatness */ -#define MAX_CORR_SHIFT_FX 16384 /* corrshift limit, 0.5 in Q15 */ - +#define MAX_CORR_SHIFT_FX 16384 /* corrshift limit, 0.5 in Q15 */ #define START_NG 5 /* Stationary noise UV modification */ #define FULL_NG 10 /* Stationary noise UV modification */ -#define ISP_SMOOTHING_QUANT_A1 0.9f /* Stationary noise UV modification */ -#define ISP_SMOOTHING_QUANT_A1_FX 29491 /* 0.9f in Q15 */ /* Stationary noise UV modification */ +#define ISP_SMOOTHING_QUANT_A1_FX 29491 /* Stationary noise UV modification, 0.9f in Q15 */ -#define KP559016994_FX 18318 /* EDCT & EMDCT constants */ -#define KP951056516_FX 31164 /* EDCT & EMDCT constants */ -#define KP587785252_FX 19261 /* EDCT & EMDCT constants */ -#define KP866025403_FX 28378 /* EDCT & EMDCT constants */ -#define KP250000000_FX 8192 /* EDCT & EMDCT constants */ +#define KP559016994_FX 18318 /* EDCT & EMDCT constants */ +#define KP951056516_FX 31164 /* EDCT & EMDCT constants */ +#define KP587785252_FX 19261 /* EDCT & EMDCT constants */ +#define KP866025403_FX 28378 /* EDCT & EMDCT constants */ +#define KP250000000_FX 8192 /* EDCT & EMDCT constants */ #define FEC_BITS_CLS 2 /* FEC - number of bits for clas information */ #define FEC_BITS_ENR 5 /* FEC - number of bits for energy information */ @@ -1034,34 +883,23 @@ typedef enum #define BWS_TRAN_PERIOD 5 /* BWS - number of frames for transition period */ #define ONE_BY_BWS_TRAN_PERIOD_Q15 6554 -#define PREEMPH_FAC_FLT 0.68f /* preemphasis factor at 12.8kHz */ -#define PREEMPH_FAC_16k_FLT 0.72f -#define PREEMPH_FAC_SWB_FLT 0.9f /* preemphasis factor for super wide band */ -#define GAMMA1_FLT 0.92f /* weighting factor (numerator) default:0.92 */ -#define GAMMA16k_FLT 0.94f - -#define FORMANT_SHARPENING_G1_FLT 0.75f /* Formant sharpening numerator weighting at 12.8kHz */ -#define FORMANT_SHARPENING_G2_FLT 0.9f /* Formant sharpening denominator weighting at 12.8kHz */ -#define FORMANT_SHARPENING_G1_16k_FLT 0.8f /* Formant sharpening numerator weighting at 16kHz */ -#define FORMANT_SHARPENING_G2_16k_FLT 0.92f /* Formant sharpening denominator weighting at 16kHz */ - -#define PREEMPH_FAC 22282 /* preemphasis factor at 12.8kHz (0.68f in 0Q15) */ -#define PREEMPH_FAC_16k 23593 /* preemphasis factor at 16kHz (0.72f in 0Q15) */ -#define PREEMPH_FAC_SWB 29491 /* preemphasis factor for super wide band (0.9f in 0Q15) */ -#define GAMMA1 30147 /* weighting factor (numerator) default:0.92 (0Q15format) */ -#define GAMMA1_INV 17809 /* weighting factor (numerator) default:0.92 (1Q14format) */ -#define GAMMA16k 30802 /* weighting factor (numerator) default:0.94 (0Q15format) */ -#define GAMMA16k_INV 17430 /* weighting factor (numerator) default:0.94 (1Q14format) */ - -#define FORMANT_SHARPENING_G1 24576 /* Formant sharpening numerator weighting at 12.8kHz (0.75f) */ -#define FORMANT_SHARPENING_G2 29491 /* Formant sharpening denominator weighting at 12.8kHz (0.9f) */ -#define FORMANT_SHARPENING_G1_16k 26214 /* Formant sharpening numerator weighting at 16kHz (0.8f) */ -#define FORMANT_SHARPENING_G2_16k 30147 /* Formant sharpening denominator weighting at 16kHz (0.92f) */ - -#define LD_FSCALE_DENOM 9 +#define PREEMPH_FAC 22282 /* preemphasis factor at 12.8kHz (0.68f in 0Q15) */ +#define PREEMPH_FAC_16k 23593 /* preemphasis factor at 16kHz (0.72f in 0Q15) */ +#define PREEMPH_FAC_SWB 29491 /* preemphasis factor for super wide band (0.9f in 0Q15) */ +#define GAMMA1 30147 /* weighting factor (numerator) default:0.92 (0Q15format) */ +#define GAMMA1_INV 17809 /* weighting factor (numerator) default:0.92 (1Q14format) */ +#define GAMMA16k 30802 /* weighting factor (numerator) default:0.94 (0Q15format) */ +#define GAMMA16k_INV 17430 /* weighting factor (numerator) default:0.94 (1Q14format) */ + +#define FORMANT_SHARPENING_G1 24576 /* Formant sharpening numerator weighting at 12.8kHz (0.75f) */ +#define FORMANT_SHARPENING_G2 29491 /* Formant sharpening denominator weighting at 12.8kHz (0.9f) */ +#define FORMANT_SHARPENING_G1_16k 26214 /* Formant sharpening numerator weighting at 16kHz (0.8f) */ +#define FORMANT_SHARPENING_G2_16k 30147 /* Formant sharpening denominator weighting at 16kHz (0.92f) */ + +#define LD_FSCALE_DENOM 9 #define FSCALE_DENOM (1 << LD_FSCALE_DENOM) -#define FSCALE_DENOM_HALF FSCALE_DENOM/2 -#define FSCALE_E 2 +#define FSCALE_DENOM_HALF FSCALE_DENOM/2 +#define FSCALE_E 2 #define ACELP_FIXED_CDK_NB 41 #define ACELP_FIXED_CDK_BITS( n ) PulseConfTable[n].bits @@ -1105,74 +943,51 @@ enum #define PIT16k_FR2_EXTEND_10b 264 /* Minimum 10 bit pitch lag with resolution 1/2 of extended range @16kHz */ #define WIDTH_BAND 8 /* sub-band width in AVQ coding */ -#define G_AVQ_MIN 0.80f /* lower limit for gain Q in higher-rate ACELP contribution */ -#define G_AVQ_MAX 96.0f /* upper limit for gain Q in higher-rate ACELP contribution */ -#define FAC_PRE_AVQ 0.3f /* preemhasis factor in ACELP pre-quantizer */ -#define G_AVQ_MIN_FX 6554 /* Q13 */ -#define G_AVQ_MIN_DIV10_FX 655 /* Q13 */ -#define G_AVQ_MAX_FX 6144 /* Q6 */ -#define FAC_PRE_AVQ_FX 9830 /* preemhasis factor in ACELP pre-quantizer (0.3 in Q15) */ - - - -#define G_AVQ_MIN_INACT 0.70f /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments */ -#define G_AVQ_MAX_INACT 4.1f /* upper limit for gain Q in higher-rate ACELP contribution, inactive segments */ -#define G_AVQ_MIN_INACT_48k 0.35f /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbps */ -#define G_AVQ_MAX_INACT_48k 2.8f /* upper limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbps */ -#define G_AVQ_MIN_INACT_64k 0.25f /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbps */ -#define G_AVQ_MAX_INACT_64k 1.5f /* upper limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbps */ -#define G_AVQ_MIN_INACT_Q12 2867 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments (0.7 in Q12) */ -#define G_AVQ_MIN_INACT_48k_Q12 1434 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbit/s (0.35 in Q12) */ -#define G_AVQ_MIN_INACT_64k_Q12 1024 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbit/s (0.25 in Q12 )*/ -#define G_AVQ_DELTA_INACT_Q12 221 /* (4.1 - 0.7) / ((1 << G_AVQ_BITS) - 1) in Q12 */ -#define G_AVQ_DELTA_INACT_48k_Q12 159 /* (2.8 - 0.35) / ((1 << G_AVQ_BITS) - 1) */ -#define G_AVQ_DELTA_INACT_64k_Q12 81 /*(1.5 - 0.25) / ((1 << G_AVQ_BITS) - 1) */ -#define G_AVQ_DELTA_INACT_48k ( G_AVQ_MAX_INACT_48k - G_AVQ_MIN_INACT_48k ) / ( ( 1 << G_AVQ_BITS ) - 1 ) -#define G_AVQ_DELTA_INACT_64k ( G_AVQ_MAX_INACT_64k - G_AVQ_MIN_INACT_64k ) / ( ( 1 << G_AVQ_BITS ) - 1 ) +#define G_AVQ_MIN_FX 6554 /* lower limit for gain Q in higher-rate ACELP contribution, 0.80f in Q13 */ +#define G_AVQ_MIN_DIV10_FX 655 /* Q13 */ +#define G_AVQ_MAX_FX 6144 /* upper limit for gain Q in higher-rate ACELP contribution, 96.0f in Q6 */ +#define FAC_PRE_AVQ_FX 9830 /* preemhasis factor in ACELP pre-quantizer (0.3 in Q15) */ + +#define G_AVQ_MIN_INACT_Q12 2867 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments (0.7 in Q12) */ +#define G_AVQ_MIN_INACT_48k_Q12 1434 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbit/s (0.35 in Q12) */ +#define G_AVQ_MIN_INACT_64k_Q12 1024 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbit/s (0.25 in Q12 )*/ +#define G_AVQ_DELTA_INACT_Q12 221 /* (4.1 - 0.7) / ((1 << G_AVQ_BITS) - 1) in Q12 */ +#define G_AVQ_DELTA_INACT_48k_Q12 159 /* (2.8 - 0.35) / ((1 << G_AVQ_BITS) - 1) */ +#define G_AVQ_DELTA_INACT_64k_Q12 81 /*(1.5 - 0.25) / ((1 << G_AVQ_BITS) - 1) */ #define G_AVQ_BITS 6 /* number of bits to quantize the AVQ gain in higher-rate ACELP contribtuion */ -#define G_AVQ_DELTA ( G_AVQ_MAX - G_AVQ_MIN ) / ( ( 1 << G_AVQ_BITS ) - 1 ) -#define G_AVQ_DELTA_INACT ( G_AVQ_MAX_INACT - G_AVQ_MIN_INACT ) / ( ( 1 << G_AVQ_BITS ) - 1 ) -#define G_PITCH_MIN 0.00f /* SQ of gains: pitch gain lower limit */ -#define G_PITCH_MAX 1.22f /* SQ of gains: pitch gain upper limit */ -#define G_CODE_MIN 0.02f /* SQ of gains: code gain lower limit */ -#define G_CODE_MAX 5.00f /* SQ of gains: code gain upper limit */ +#define G_PITCH_MIN_Q14 0 /* SQ of gains: pitch gain lower limit */ +#define G_PITCH_MAX_Q13 9994 /* SQ of gains: pitch gain upper limit, 1.22 */ +#define G_PITCH_MAX_Q14 19988 /* SQ of gains: pitch gain upper limit, 1.22 in Q14 */ +#define G_CODE_MIN_FX 164 /* SQ of gains: code gain lower limit, 0.02f in Q13 */ +#define G_CODE_MAX_FX 320 /* SQ of gains: code gain upper limit, 5.0f in Q6 */ -#define G_PITCH_MIN_TC192 0.1f -#define G_PITCH_MAX_TC192 0.95f -#define G_CODE_MIN_TC192 0.6f -#define G_CODE_MAX_TC192 41.0f - -#define G_PITCH_MIN_Q14 0 -#define G_PITCH_MAX_Q13 9994/*1.22 */ -#define G_PITCH_MAX_Q14 19988 /* 1.22 in Q14 */ - -#define G_CODE_MIN_FX 164 /* Q13 */ -#define G_CODE_MAX_FX 320 /* Q6 */ - -#define G_PITCH_MIN_TC192_Q14 1638 -#define G_PITCH_MAX_TC192_Q14 15565 /* 0.95 in Q14 */ -#define G_PITCH_MAX_MINUS_MIN_TC192_Q13 6963/*(G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) */ -#define G_CODE_MIN_TC192_Q15 19661 -#define G_CODE_MIN_TC192_FX 4915 /* Q13 */ -#define G_CODE_MAX_TC192_Q0 41 +#define G_PITCH_MIN_TC192_Q14 1638 /* 0.1f in Q14 */ +#define G_PITCH_MAX_TC192_Q14 15565 /* 0.95 in Q14 */ +#define G_PITCH_MAX_MINUS_MIN_TC192_Q13 6963 /*(G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) */ +#define G_CODE_MIN_TC192_Q15 19661 /* 0.6f in Q15 */ +#define G_CODE_MIN_TC192_FX 4915 /* 41 in Q13 */ +#define G_CODE_MAX_TC192_Q0 41 #define BIT_SAVING_LOW_THR 10 #define BIT_SAVING_HIGH_THR 80 + /*--------------------------------------------------------------* * ACELP constants *---------------------------------------------------------------*/ -#define MODE_MAX 15 - -#define NB_PULSES_MAX 15 -#define ACELP_GAINS_CONST 0.8f /* ACELP - adaptive codebook gain constraint */ +#define MODE_MAX 15 +#define NB_PULSES_MAX 15 +#define ACELP_GAINS_CONST_Q31 1717986944l /* ACELP - adaptive codebook gain constraint, 0.8f in Q31 */ /*--------------------------------------------------------------* * TCX constants *---------------------------------------------------------------*/ +#define TCX_IMDCT_SCALE 15 +#define TCX_IMDCT_HEADROOM 1 + #define NBITS_TCX_GAIN 7 #define NOISE_FILL_RANGES 1 @@ -1197,7 +1012,7 @@ enum #define N_MAX_ARI 800 #define N_LTP_GAIN_MEMS 4 -#define SPEC_EXP_DEC 20 /* initial decoder spectrum exponent */ +#define SPEC_EXP_DEC 20 /* initial decoder spectrum exponent */ #define N_TCX_STARTLINE_NOISE_WB 11 @@ -1240,41 +1055,31 @@ enum #define NC16k ( M16k / 2 ) #define NO_ITER 4 /* number of iterations for tracking the root */ -#define SPC 0.0234952f -#define SPC_plus SPC * 1.001f -#define ALPHA_SQ ( ( 0.5f / PI2 ) * ( 0.5f / PI2 ) ) -#define ALPHA_SQ_Q30 (6799549) /* ( ( 0.5f / PI2 ) * ( 0.5f / PI2 ) ) in Q30 */ +#define ALPHA_SQ_Q30 (6799549) /* ( ( 0.5f / PI2 ) * ( 0.5f / PI2 ) ) in Q30 */ #define NC M / 2 -#define LSF_GAP 50.0f -#define SPC_FX 770 /* q15 */ -#define SPC_PLUS_FX 771 +#define SPC_FX 770 /* 0.0234952f in q15 */ +#define SPC_PLUS_FX 771 /* SPC * 1.001f */ -#define LSF_GAP_FX 128 /*50.0f x 2.56*/ -#define MODE1_LSF_GAP_FX 179 /* MODE1_LSF_GAP*2.56 */ /* Minimum LSF separation for end-frame ISFs */ -#define FREQ_MAX 16384 /*6400Hz in 14Q1*1.28 */ -#define FREQ_DIV 800 /*400.0f in 14Q1 */ +#define LSF_GAP_FX 128 /*50.0f x 2.56*/ +#define MODE1_LSF_GAP_FX 179 /* MODE1_LSF_GAP*2.56 */ /* Minimum LSF separation for end-frame ISFs */ +#define FREQ_MAX 16384 /*6400Hz in 14Q1*1.28 */ +#define FREQ_DIV 800 /*400.0f in 14Q1 */ #define LSF_BITS_CNG 29 #define MU_MA ( 1.0f / 3.0f ) /* original prediction factor (only for AMR-WB IO mode) */ #define ISF_GAP 50 /* Minimum ISF separation for end-frame ISFs (only in AMR-WB IO mode) */ -#define LSF_GAP_MID 80.0f /* Minimum LSF separation for mid-frame LSFs */ -#define MODE1_LSF_GAP 70.0f /* Minimum LSF separation for end-frame ISFs */ -#define PREFERSFNET 1.05 -#define ISF_GAP_FX 128 /* Minimum ISF separation for end-frame ISFs (only in AMR-WB IO mode) */ -#define LSF_GAP_MID_FX 205 /* 80.0 * 2.56 */ /* Minimum LSF separation for mid-frame LSFs */ -#define PREFERSFNET_FX 1638 /* 0.05 in Q16*/ - -#define SFNETLOWLIMIT_WB_FLT 35000 /* new sampling rate dependent thresholds used in LSF codebook decision logic, WB case */ -#define SFNETLOWLIMIT_NB_FLT 38000 /* new sampling rate dependent thresholds used in LSF codebook decision logic, NB case */ -#define SFNETLOWLIMIT_WB 3670016 /* 2.56x2.56*Q4 LSF quantizer - new sampling rate dependent thresholds used in LSF codebook decision logic, WB case */ -#define SFNETLOWLIMIT_NB 3984589 /* 2.56x2.56*Q4 LSF quantizer - new sampling rate dependent thresholds used in LSF codebook decision logic, NB case */ +#define ISF_GAP_FX 128 /* Minimum ISF separation for end-frame ISFs (only in AMR-WB IO mode) */ +#define LSF_GAP_MID_FX 205 /* 80.0 * 2.56 */ /* Minimum LSF separation for mid-frame LSFs */ +#define PREFERSFNET_FX 1638 /* 1.05 in Q16*/ + +#define SFNETLOWLIMIT_WB 3670016 /* 35000*2.56x2.56*Q4 LSF quantizer - new sampling rate dependent thresholds used in LSF codebook decision logic, WB case */ +#define SFNETLOWLIMIT_NB 3984589 /* 38000*2.56x2.56*Q4 LSF quantizer - new sampling rate dependent thresholds used in LSF codebook decision logic, NB case */ #define LSFMBEST 2 /* number of survivors from one stage to another */ #define STREAKLEN 3 /* Allow this many predictive frames, before starting limiting */ -#define STREAKMULT 0.8f /* Exponential limiting multiplier */ -#define STREAKMULT_FX 26214 /* Exponential limiting multiplier */ +#define STREAKMULT_FX 26214 /* Exponential limiting multiplier, 0.8f */ #define LSFMBEST_MAX 16 @@ -1282,14 +1087,12 @@ enum #define TCXLPC_NUMBITS 13 #define TCXLPC_IND_NUMSTAGES 1 #define TCXLPC_IND_NUMBITS 2 -#define TCXLPC_LSF_GAP_FLT 80.0f -#define TCXLPC_LSF_GAP 204 /* 80 in 14Q1*1.28 */ -#define kMaxC 8 - +#define TCXLPC_LSF_GAP 204 /* 80 in 14Q1*1.28 */ +#define kMaxC 8 #define MAX_VQ_STAGES 4 -#define MAX_VQ_STAGES_USED 9 /* this is the maximum number of stages currently used and changing this will affect the memory allocated \ - MAX_VQ_STAGES is also used as offset for addressing some arrays, so this should NOT be changed*/ +#define MAX_VQ_STAGES_USED 9 /* this is the maximum number of stages currently used and changing this will affect the memory allocated \ + MAX_VQ_STAGES is also used as offset for addressing some arrays, so this should NOT be changed*/ #define MIDLSF_NBITS 5 #define ENDLSF_NBITS 31 @@ -1301,11 +1104,11 @@ enum #define MAX_NO_VALS 4 #define WB_LIMIT_LSF 6350 #define CNG_LVQ_MODES 16 -#define MAX_NO_MODES_IVAS 169 +#define MAX_NO_MODES_IVAS 169 #define MAX_NO_MODES 128 -#define START_CNG_IVAS MAX_NO_MODES_IVAS - CNG_LVQ_MODES +#define START_CNG_IVAS MAX_NO_MODES_IVAS - CNG_LVQ_MODES #define START_CNG 112 -#define MAX_NO_MODES_p_IVAS 237 +#define MAX_NO_MODES_p_IVAS 237 #define MAX_NO_MODES_p 145 #define NO_CODING_MODES 6 #define LVQ_COD_MODES 18 @@ -1317,8 +1120,7 @@ enum #define N_STAGE_VQ 8 #define N_DIM 2 #define NUM_SUBSET 8 -#define OP_LOOP_THR_HVO_FLT 3784536.3f /* 80% : Open-loop Threshold */ -#define OP_LOOP_THR_HVO 1550146 /* 80% : Open-loop Threshold 2.56*2.56/16 */ +#define OP_LOOP_THR_HVO 1550146 /* 80% : Open-loop Threshold 3784536.3f*2.56*2.56/16 */ #define NUM_STATE 16 /* BC-TCQ - Number of state of the Trellis */ #define N_STAGE 16 /* BC-TCQ - Smaple number in a frame */ @@ -1346,10 +1148,10 @@ enum #define MAX_TD_DELAY 2 * NSUBBLOCKS /* Maximum allowed delay (in number of subblocks) of the transient detection, affects required memory */ #define NSUBBLOCKS_SHIFT 3 /* Number of subblocks which are shifter betwen TD dectector and TCX-LTP */ -#define NO_TCX 0 -#define TCX_20 1 -#define TCX_10 2 -#define TCX_5 3 +#define NO_TCX 0 +#define TCX_20 1 +#define TCX_10 2 +#define TCX_5 3 #define TRANSITION_OVERLAP ( -2 ) #define RECTANGULAR_OVERLAP ( -1 ) @@ -1358,12 +1160,12 @@ enum #define MIN_OVERLAP 2 #define HALF_OVERLAP 3 #define ALDO_WINDOW 4 -#define WINDECAY48 1230 -#define WINDECAY48_256 656 -#define WINDECAY16 410 -#define N16_CORE_SW 90 -#define N_ZERO_8 45 -#define N_ZERO_BY_FS 9216 /* == N_ZERO_MDCT_NS / FRAME_SIZE_NS in Q15 */ +#define WINDECAY48 1230 +#define WINDECAY48_256 656 +#define WINDECAY16 410 +#define N16_CORE_SW 90 +#define N_ZERO_8 45 +#define N_ZERO_BY_FS 9216 /* == N_ZERO_MDCT_NS / FRAME_SIZE_NS in Q15 */ #define SWITCH_OVERLAP_8k 15 /* == NS2SA(8000, SWITCH_GAP_LENGTH_NS) - NS2SA(8000, 10000000.0f - N_ZERO_MDCT_NS) */ #define SWITCH_GAP_LENGTH_8k 50 @@ -1390,35 +1192,25 @@ enum #define INACTIVE_CLAS 6 /* Inactive frame (used only in decoder) */ #define AUDIO_CLAS 7 /* Audio frame (used only in AMR-WB IO mode) */ -#define BETA_FEC 0.75f /* FEC - weighting factor for LSF estimation in FER */ -#define STAB_FAC_LIMIT 0.25f /* FEC - limit at which safety net is forced for next frame */ -#define BETA_FEC_FX 24576 /* FEC - weighting factor for LSF estimation in FER */ -#define STAB_FAC_LIMIT_FX 8192 /* FEC - limit at which safety net is forced for next frame */ +#define BETA_FEC_FX 24576 /* FEC - weighting factor for LSF estimation in FER, 0.75f */ +#define STAB_FAC_LIMIT_FX 8192 /* FEC - limit at which safety net is forced for next frame, 0.25f */ #define MODE1_L_FIR_FER 5 /* FEC - impulse response length for low- and high-pass filters in FEC */ #define L_FIR_FER 3 /* impulse response length for low- & high-pass filters in FER concealment */ #define L_FIR_FER2 11 /* new filter tuning: 11*/ #define MAX_UPD_CNT 5 /* FEC - maximum number of frames since last pitch update */ -#define ALPHA_S 0.6f /* FEC - damping factor for SIN_ONSET frames */ -#define ALPHA_V 1.0f /* FEC - damping factor for VOICED_CLAS frames */ -#define ALPHA_VT 0.4f /* FEC - damping factor for VOICED_TRANSITION frames */ -#define ALPHA_UT 0.8f /* FEC - damping factor for UNVOICED_TRANSITION frames */ -#define ALPHA_U 0.4f /* FEC - damping factor for UNVOICED_CLAS frames */ -#define ALPHA_UU 1.0f /* FEC - damping factor for UNVOICED_CLAS frames */ - /* attenuation strategy in case of FER */ -#define _ALPHA_S_FX 19661 -#define _ALPHA_V_FX 32767 -#define _ALPHA_VT_FX 13107 -#define _ALPHA_UT_FX 26214 -#define _ALPHA_U_FX 13107 -#define _ALPHA_U_FX_X_2 26214 -#define _ALPHA_UU_FX 32767 +#define _ALPHA_S_FX 19661 /* FEC - damping factor for SIN_ONSET frames, 0.6f */ +#define _ALPHA_V_FX 32767 /* FEC - damping factor for VOICED_CLAS frames, 1.0f */ +#define _ALPHA_VT_FX 13107 /* FEC - damping factor for VOICED_TRANSITION frames, 0.4f */ +#define _ALPHA_UT_FX 26214 /* FEC - damping factor for UNVOICED_TRANSITION frames, 0.8f */ +#define _ALPHA_U_FX 13107 /* FEC - damping factor for UNVOICED_CLAS frames, 0.4f */ +#define _ALPHA_U_FX_X_2 26214 /* FEC - damping factor for UNVOICED_CLAS frames, 1.0f */ +#define _ALPHA_UU_FX 32767 #define AGC 0.98f -#define PLC_MIN_CNG_LEV_FLT 0.01f /* minimum background level */ -#define PLC_MIN_CNG_LEV 328/*0.01f Q15*/ -#define PLC_MIN_CNG_LEV_Q21 20992/*0.01f Q21*/ +#define PLC_MIN_CNG_LEV 328 /* minimum background level, 0.01f Q15*/ +#define PLC_MIN_CNG_LEV_Q21 20992 /* minimum background level, 0.01f Q21*/ #define PLC_MIN_STAT_BUFF_SIZE 50 /* buffer size for minimum statistics */ #define G_LPC_RECOVERY_BITS 1 @@ -1431,9 +1223,9 @@ enum #define TC_SUBFR2IDX_16KHZ( x ) ( x == 0 ? 0 : x == 64 ? 1 : x == 128 ? 2 : x == 192 ? 3 : x == 256 ? 4 : 0 ) -#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_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 */ @@ -1489,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 */ @@ -1545,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 @@ -1560,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 */ @@ -1580,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 */ @@ -1730,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 @@ -1761,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 ) @@ -1787,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 { @@ -1808,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 @@ -1873,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 ) @@ -1905,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 @@ -1930,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 @@ -1958,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 */ @@ -1972,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 */ @@ -2033,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 @@ -2072,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 @@ -2120,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 @@ -2142,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 ) @@ -2162,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 */ @@ -2218,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 @@ -2257,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 */ @@ -2346,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 */ @@ -2505,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 ) @@ -2522,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 @@ -2549,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 */ @@ -2675,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 */ @@ -2692,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 @@ -2720,96 +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 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 @@ -2818,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 /*----------------------------------------------------------------------------------* @@ -3052,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))) +#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 -//tbs_vase.c -#define PRED_GAIN_E 8 +#define PRED_GAIN_E 8 -#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 -#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 515a1a43e75cd9389f7348cce804990c1d427fcf..8517668e5779027a75dcbb2329246cc0f5f8425e 100644 --- a/lib_com/codec_tcx_common_fx.c +++ b/lib_com/codec_tcx_common_fx.c @@ -1,10 +1,9 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #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 6259b5f8d25c933dcee512814d7bdbf0c5cd528f..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 @@ -62,6 +62,7 @@ #define IVAS_REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ #define IVAS_ER_LIST_HEIGHT 1.6f #define IVAS_ER_LIST_HEIGHT_FX 6710886 /* 1.6f in Q.22 */ +#define IVAS_DEFAULT_AEID 65535 /* JBM constants for adaptive-playout */ #define IVAS_TIME_SCALE_MIN 50 /* min. time-scaling [%] */ @@ -132,15 +133,6 @@ typedef struct _IVAS_ISM_METADATA Word32 gainFactor_fx; /* Q29 */ Word32 yaw_fx; /* Q22 */ Word32 pitch_fx; /* Q22 */ -#ifndef FIX_2084_FLOATING_POINT_LEFTOVERS - float azimuth; - float elevation; - float radius; - float spread; - float gainFactor; - float yaw; - float pitch; -#endif Word16 non_diegetic_flag; Word32 gain_fx; /* Q29 */ @@ -156,18 +148,17 @@ typedef struct _IVAS_EDITABLE_PARAMETERS typedef struct { - // float w, x, y, z; Word32 w_fx, x_fx, y_fx, z_fx; Word16 q_fact; } IVAS_QUATERNION; - typedef struct { float x, y, z; Word32 x_fx, y_fx, z_fx; Word16 q_fact; + } IVAS_VECTOR3; typedef enum @@ -182,12 +173,21 @@ 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_NUM_SUBFR; + +typedef enum +{ + IVAS_ROOM_SIZE_AUTO = -1, + IVAS_ROOM_SIZE_SMALL, + IVAS_ROOM_SIZE_MEDIUM, + IVAS_ROOM_SIZE_LARGE -} IVAS_RENDER_FRAMESIZE; +} IVAS_ROOM_SIZE_T; typedef struct ivas_masa_metadata_frame_struct *IVAS_MASA_METADATA_HANDLE; typedef struct ivas_masa_decoder_ext_out_meta_struct *IVAS_MASA_DECODER_EXT_OUT_META_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,18 +320,9 @@ 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 */ Word16 nBands; /* Number of frequency bands for which reverb properties are provided, integer, range [2..256] */ Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /*Q16 Center frequencies for which following values are provided: */ Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX]; /*Q26 - The room's T60 per center frequency */ @@ -342,16 +335,13 @@ typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG Word32 lowComplexity; /* Low complexity ER flag */ IVAS_VECTOR3 dimensions; /* Room dimensions [m] */ float AbsCoeff[IVAS_ROOM_ABS_COEFF]; /* Absorption coeffs */ - IVAS_VECTOR3 ListenerOrigin; /* Listener origin */ Word32 AbsCoeff_fx[IVAS_ROOM_ABS_COEFF]; /* Absorption coeffs */ + IVAS_VECTOR3 ListenerOrigin; /* Listener origin */ } IVAS_ROOM_ACOUSTICS_CONFIG_DATA; typedef struct _IVAS_RENDER_CONFIG { -#ifdef DEBUGGING - IVAS_RENDER_TYPE_OVERRIDE renderer_type_override; -#endif IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcoustics; ISAR_SPLIT_REND_CONFIG_DATA split_rend_config; float directivity[IVAS_MAX_NUM_OBJECTS * 3]; @@ -378,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 744dafa695a6c70e26ea12d3f03cef9794ed77ac..fef5b6f392e0d0f46aec523339ba65465c306818 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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -997,8 +997,7 @@ void init_tcx_cfg_ivas_fx( IF( hTcxCfg->fIsTNSAllowed ) { - InitTnsConfigs_ivas_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); - + InitTnsConfigs_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) ); } @@ -1253,7 +1252,7 @@ void init_tcx_cfg_fx( IF( hTcxCfg->fIsTNSAllowed ) { - InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); + InitTnsConfigs_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag ); 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 829b4045b554f374bffccffe5f611852ec9d212d..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -64,27 +64,27 @@ void deemph_fx_32( /*========================================================================*/ -/* FUNCTION : deemph_fx() */ +/* FUNCTION : deemph_fx() */ /*------------------------------------------------------------------------*/ -/* PURPOSE : Deemphasis: filtering through 1/(1-mu z^-1) */ +/* PURPOSE : Deemphasis: filtering through 1/(1-mu z^-1) */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) mu : deemphasis factor Q15 */ -/* _ (Word16) L : vector size */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) mu : deemphasis factor Q15 */ +/* _ (Word16) L : vector size */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) signal : signal Q_syn2-1 */ -/* _ (Word16*) mem : memory (y[-1]) Q_syn2-1 */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16*) signal : signal Q_syn2-1 */ +/* _ (Word16*) mem : memory (y[-1]) Q_syn2-1 */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void deemph_fx( - Word16 *signal, /* i/o: signal Qx */ + Word16 *signal, /* i/o: signal Qx */ const Word16 mu, /* i : deemphasis factor Q15 */ const Word16 L, /* i : vector size Q0 */ Word16 *mem /* i/o: memory (y[-1]) Qx */ @@ -150,8 +150,8 @@ void Deemph2( * * Parameters: * shift I: scale output - * x I/O: signal Qx/Qx-shift - * mu I: deemphasis factor Qx + * x I/O: signal Qx/Qx-shift + * mu I: deemphasis factor Qx * L I: vector size * mem I/O: memory (signal[-1]) Qx * diff --git a/lib_com/delay_comp_fx.c b/lib_com/delay_comp_fx.c index aff51ac2d9e68c6f017eb902a5abc929894849eb..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/disclaimer.c b/lib_com/disclaimer.c index 53210b9fe68764e1432438f2781ee4ccad778dbd..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -44,10 +44,12 @@ Word16 print_disclaimer( FILE *fPtr ) { fprintf( fPtr, "\n==================================================================================================\n" ); - fprintf( fPtr, " IVAS Codec BASOP Baseline\n" ); - fprintf( fPtr, " \n" ); - fprintf( fPtr, " Based on EVS Codec (Alternative Fixed Point) 3GPP TS26.452 Aug 12, 2021,\n" ); - fprintf( fPtr, " Version 16.3.0\n" ); + fprintf( fPtr, "\n" ); + fprintf( fPtr, " 3GPP TS26.251 IVAS Codec Version IVAS-FX-3.0 (fixed-point C-Code)\n" ); + fprintf( fPtr, "\n" ); + fprintf( fPtr, " Based on EVS Codec (Alternative Fixed Point) 3GPP TS26.452 Nov 04, 2021,\n" ); + fprintf( fPtr, " Version 16.4.0\n" ); + fprintf( fPtr, "\n" ); fprintf( fPtr, "==================================================================================================\n\n" ); return 0; diff --git a/lib_com/dlpc_bfi_fx.c b/lib_com/dlpc_bfi_fx.c index 2d6b1126862da9bd153687b0194c73b13ef165bb..dffdb982ad888d9964dcf59fe129b8e921e068c6 100644 --- a/lib_com/dlpc_bfi_fx.c +++ b/lib_com/dlpc_bfi_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index 86a8ad268b57c74982476ea5ab364fa2a7df9cc5..55bc483e0fcc2558eeea1fb5a958b54318aefda6 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 620904d08e6f6a299b6ae0adcb5e1f0ceeea078c..6203dcd67c6fccc08523e3840ab752afddc74932 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_com/enr_1_az_fx.c b/lib_com/enr_1_az_fx.c index 5e840df8bd61f89b30b90134db37f4686c8cae65..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -51,10 +51,8 @@ Word16 Enr_1_Az_fx_o( /* o : impulse response energy Q3 Word16 *y; Word16 i, j, a0, q; Word32 L_tmp, L_tmp2; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif /* Find the impulse response */ q = sub( 3, norm_s( Aq[0] ) ); diff --git a/lib_com/env_adj_fx.c b/lib_com/env_adj_fx.c index 07cddb0cd1022770cf1dafda2f74cd81513de013..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/env_stab_fx.c b/lib_com/env_stab_fx.c index 728cfddb99c5f912971f07249f99dd70ae358d81..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 @@ -31,13 +31,12 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" @@ -74,10 +73,8 @@ Word16 env_stability_fx( /* in Q15 */ Word16 exp, exp2; Word32 L_tmp, L_env_delta; Word16 inv_nb_sfm; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif IF( core_switching_flag ) { diff --git a/lib_com/env_stab_trans_fx.c b/lib_com/env_stab_trans_fx.c index 0e4d5496200524e334ed49b0f5890c880afdd1b9..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 @@ -31,16 +31,16 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" #include "wmc_auto.h" + /*--------------------------------------------------------------------------* * env_stab_transient_detect() * @@ -48,15 +48,15 @@ *--------------------------------------------------------------------------*/ void env_stab_transient_detect_fx( - const Word16 is_transient, /* i: Transient flag */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ - const Word16 norm[], /* i : quantization indices for norms */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ + const Word16 is_transient, /* i: Transient flag */ + const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ + const Word16 norm[], /* i : quantization indices for norms */ + Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ - const Word16 HQ_mode, /* i : HQ coding mode */ - const Word16 bin_th, /* i : HVQ cross-over frequency bin */ - const Word32 *L_coeff, /* i : Coded spectral coefficients */ - const Word16 Qcoeff /* i : Q of coded spectral coefficients */ + const Word16 HQ_mode, /* i : HQ coding mode */ + const Word16 bin_th, /* i : HVQ cross-over frequency bin */ + const Word32 *L_coeff, /* i : Coded spectral coefficients */ + const Word16 Qcoeff /* i : Q of coded spectral coefficients */ ) { Word16 i, blk, norm_ind, sqrt_exp, bin_th_1, temp, sh; diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 4ff9c6c1129555fe39b5ea34e4200f9afe451741..95e527da0e813e09f3196ef785d0bd7a47095a0a 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -10,91 +10,13 @@ /*======================================================================*/ -/* FUNCTION : est_tilt_fx() */ +/* FUNCTION : est_tilt_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 */ -/*=======================================================================*/ -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 : */ +/* INPUT ARGUMENTS : */ /* _ (Word16 *) exc : adaptive excitation vector Q0 */ /* _ (Word16) gain_pit : adaptive gain Q14 */ /* _ (Word16 *) code : algebraic exctitation vector Q12 */ @@ -113,15 +35,14 @@ Word16 est_tilt_fx( /* o : tilt of the code /*=======================================================================*/ /* 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 c8f0c31ac302487225d1f72345932585afb59c7e..f7b58ae6256c1f34a0a6fde9f0e94886369dd540 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "ivas_cnst.h" @@ -27,7 +27,7 @@ * Local function prototypes *-------------------------------------------------------------------*/ static void getmidbands( const Word16 *part, const Word16 npart, Word16 *midband, Word16 *psize, Word16 *psize_norm, Word16 *psize_norm_exp, Word16 *psize_inv ); - +static void mhvals( const Word16 d, Word16 *m ); /*------------------------------------------------------------------- * createFdCngCom() @@ -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 */ @@ -162,12 +164,7 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) hFdCngCom->exp_cldfb_periodog = 0; move16(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG set16_fx( hFdCngCom->coherence_fx, 16384 /* 0.5 in Q15 */, MDCT_ST_DTX_NUM_COHERENCE_BANDS ); -#else - hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ - move16(); -#endif set32_fx( hFdCngCom->olapBufferSynth_fx, 0, FFTLEN ); set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); @@ -176,110 +173,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() @@ -1811,7 +1704,6 @@ void apply_scale( ) { Word16 i; - // PMT("Verifiy if the basop ued are ok for stereo too") FOR( i = 0; i < scaleTableSize; i++ ) { cast16(); @@ -1844,7 +1736,6 @@ Word16 apply_scale_ind( ) { Word16 i; - // PMT("Verifiy if the basop ued are ok for stereo too") FOR( i = 0; i < scaleTableSize; i++ ) { cast16(); @@ -1872,7 +1763,6 @@ void apply_scale_ivas_fx( Word16 *index ) { Word16 i; - // PMT("Verifiy if the basop ued are ok for stereo too") FOR( i = 0; i < scaleTableSize; i++ ) { cast16(); @@ -2826,7 +2716,8 @@ void SynthesisSTFT_ivas_fx( /************************************************************************************** * Compute some values used in the bias correction of the minimum statistics algorithm * **************************************************************************************/ -void mhvals( + +static void mhvals( const Word16 d, Word16 *m /*, Word16 * h*/ ) @@ -3104,7 +2995,7 @@ void lpc_from_spectrum( /* LPC */ - E_LPC_lev_dur( r_h, r_l, A, NULL, lpcorder, NULL ); + E_LPC_lev_dur_fx( r_h, r_l, A, NULL, lpcorder, NULL ); } /* @@ -3137,7 +3028,6 @@ void msvq_decoder( { Word16 s, i, offset; - // PMT("msvq_decoder Not verified") offset = i_mult( Idx[0], maxN ); FOR( i = 0; i < N; i++ ) diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c index d522751fe8b2b8d6ceecfc19b384b515c636bc2d..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/fft_evs.c b/lib_com/fft_evs.c index 94c2dea8ff0a7df4fc62fb898eb379e5d2d31a79..5748be95dde18d7656aafc140702a63073b74582 100644 --- a/lib_com/fft_evs.c +++ b/lib_com/fft_evs.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/fft_fx.c b/lib_com/fft_fx.c index 018020cbed36c64ca5bc85d21147afdd3f4a6de2..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 @@ -31,13 +31,12 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index 41a70b20c9776b831574299b51601fb5921e2e6e..a7b2461cb18fe44c1b763ca4e52997a1ef2e49c3 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -113,10 +113,10 @@ void DoRTFTn_fx( * Main fuction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cdftForw_fx( - Word16 n, /* i : data length of real and imag */ + Word16 n, /* i : data length of real and imag */ Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *ip, /* i : work area for bit reversal */ - const Word16 *w /* i : cos/sin table Q14*/ + const Word16 *ip, /* i : work area for bit reversal */ + const Word16 *w /* i : cos/sin table Q14*/ ) { /* bit reversal */ @@ -131,8 +131,8 @@ static void cdftForw_fx( * Bit reversal *-----------------------------------------------------------------*/ static void bitrv2_SR_fx( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o : work area for bit reversal */ + Word16 n, /* i : data length of real and imag */ + const Word16 *ip, /* i/o : work area for bit reversal */ Word32 *a /* i/o : input/output data Q(q)*/ ) { @@ -308,7 +308,7 @@ static void bitrv2_SR_fx( * Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cftfsub_fx( - Word16 n, /* i : data length of real and imag */ + Word16 n, /* i : data length of real and imag */ Word32 *a, /* i/o : input/output data Q(q)*/ const Word16 *w /* i : cos/sin table Q14*/ ) @@ -550,10 +550,10 @@ static void cft1st_fx( * Subfunction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cftmdl_fx( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ + Word16 n, /* i : data length of real and imag */ + Word16 l, /* i : initial shift for processing */ Word32 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word16 *w /* i : cos/sin table Q30*/ + const Word16 *w /* i : cos/sin table Q30*/ ) { Word16 j, j1, j2, j3, k, k1, k2, m, m2; @@ -1468,10 +1468,10 @@ void DoRTFT128_16fx( * Main fuction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cdftForw_16fx( - Word16 n, /* i : data length of real and imag */ + Word16 n, /* i : data length of real and imag */ Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word16 *ip, /* i : work area for bit reversal */ - const Word32 *w /* i : cos/sin table Q30*/ + const Word16 *ip, /* i : work area for bit reversal */ + const Word32 *w /* i : cos/sin table Q30*/ ) { /* bit reversal */ @@ -1486,8 +1486,8 @@ static void cdftForw_16fx( * Bit reversal *-----------------------------------------------------------------*/ static void bitrv2_SR_16fx( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o : work area for bit reversal */ + Word16 n, /* i : data length of real and imag */ + const Word16 *ip, /* i/o : work area for bit reversal */ Word16 *a /* i/o : input/output data Q(Qx+Q_edct)*/ ) { @@ -1663,7 +1663,7 @@ static void bitrv2_SR_16fx( * Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cftfsub_16fx( - Word16 n, /* i : data length of real and imag */ + Word16 n, /* i : data length of real and imag */ Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ const Word32 *w /* i : cos/sin table Q30*/ ) @@ -1964,10 +1964,10 @@ static void cft1st_16fx( * Subfunction of Complex Discrete Fourier Transform *-----------------------------------------------------------------*/ static void cftmdl_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ + Word16 n, /* i : data length of real and imag */ + Word16 l, /* i : initial shift for processing */ Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ + const Word32 *w /* i : cos/sin table Q30*/ ) { Word16 j, j1, j2, j3, k, k1, k2, m, m2; @@ -2322,36 +2322,20 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) l = sub( shr( n, 3 ), 1 ); /* (3*m/8) - 1 = (n/8) - 1 */ FOR( i = 0; i < l; i++ ) { -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0++, 15 ); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. Q15 + Qx*/ acc = L_mac0_sat( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ acc = L_mac0_sat( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0++, 15 ); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. Q15 + Qx*/ - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); /* bit growth = 1 (compensated by non-fractional mode MAC). Qx - 1*/ + *RY++ = round_fx( acc ); /* bit growth = 1 (compensated by non-fractional mode MAC). Qx - 1*/ move16(); -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *IZ0--, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *IZ0--, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = add( c1_ind, c1_step ); @@ -2364,36 +2348,20 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) l = shr( m, 3 ); /* (4*m/8) - (3*m/8) = m/8 */ FOR( i = 0; i < l; i++ ) { -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0++, 15 ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ acc = L_mac0_sat( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0++, 15 ); // Q15 + Qx - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 + *RY++ = round_fx( acc ); // Qx - 1 move16(); -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *IZ0--, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *IZ0--, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = add( c1_ind, c1_step ); @@ -2403,16 +2371,10 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) } /* special case: i = m/2 i.e. 1/3 */ -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0--, 15 ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0--, 15 ); // Q15 + Qx - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 + *RY++ = round_fx( acc ); // Qx - 1 move16(); acc = 0; @@ -2434,35 +2396,20 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) l = sub( shr( m, 2 ), 1 ); /* (6*m/8) - ((m/2)+1) = m/4 - 1 */ FOR( i = 0; i < l; i++ ) { -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0--, 15 ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ acc = L_msu0_sat( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0--, 15 ); // Q15 + Qx - acc = L_mac0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 - move16(); - - acc = L_mult0( *IZ0++, -32768 ); // Q15 + Qx -#ifdef FIX_2170_ASSERT_IN_FFT3 + *RY++ = round_fx( acc ); // Qx - 1 + move16(); + + acc = L_mult0( *IZ0++, -32768 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ1++, t_sin[c1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2++, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ1++, t_sin[c1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = add( c1_ind, c1_step ); @@ -2476,35 +2423,20 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) l = shr( m, 2 ); FOR( i = 0; i < l; i++ ) { -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0--, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ acc = L_msu0_sat( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0--, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ - acc = L_msu0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 - move16(); - - acc = L_mult0( *IZ0++, -32768 ); // Q15 + Qx -#ifdef FIX_2170_ASSERT_IN_FFT3 + *RY++ = round_fx( acc ); // Qx - 1 + move16(); + + acc = L_mult0( *IZ0++, -32768 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ1++, t_sin[c1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2++, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_msu0( acc, *RZ1--, t_sin[s1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ1++, t_sin[c1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2--, t_sin[s2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2++, t_sin[c2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = sub( c1_ind, c1_step ); @@ -2514,27 +2446,16 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) } /* special case: i = m, i.e 2/3 */ -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0++, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0++, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 + *RY++ = round_fx( acc ); // Qx - 1 move16(); acc = L_deposit_l( 0 ); -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_msu0_sat( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); IZ0--; /* Just decrement the address counter */ IZ1--; @@ -2549,36 +2470,20 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) l = sub( shr( m, 3 ), 1 ); /* (9*m/8) - (m +1) = m/8 - 1 */ FOR( i = 0; i < l; i++ ) { -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0++, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ acc = L_mac0_sat( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0++, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 + *RY++ = round_fx( acc ); // Qx - 1 move16(); -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *IZ0--, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *IZ0--, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = sub( c1_ind, c1_step ); @@ -2591,36 +2496,20 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) l = shr( n, 3 ); /* (12*m/8) - (9*m/8) = 3*m/8 = n/8 */ FOR( i = 0; i < l; i++ ) { -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0++, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ acc = L_mac0_sat( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0++, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); /* Non-fractional mode gains 1 more bit headroom. Q15 + Qx*/ - acc = L_mac0( acc, *IZ1, t_sin[s1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ2, t_sin[s2_ind] ); // Q15 + Qx -#endif - *RY++ = round_fx( acc ); // Qx - 1 + *RY++ = round_fx( acc ); // Qx - 1 move16(); -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *IZ0--, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx acc = L_msu0_sat( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *IZ0--, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1++, t_sin[s1_ind] ); // Q15 + Qx - acc = L_msu0( acc, *IZ1--, t_sin[c1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2++, t_sin[s2_ind] ); // Q15 + Qx - acc = L_mac0( acc, *IZ2--, t_sin[c2_ind] ); // Q15 + Qx -#endif - *IY-- = round_fx( acc ); // Qx - 1 + *IY-- = round_fx( acc ); // Qx - 1 move16(); c1_ind = sub( c1_ind, c1_step ); @@ -2630,16 +2519,10 @@ void fft3_fx( const Word16 X[] /*Qx*/, Word16 Y[] /*Qx*/, const Word16 n ) } /* special case: i = 3*m/2 */ -#ifdef FIX_2170_ASSERT_IN_FFT3 acc = L_shl_sat( *RZ0, 15 ); // Q15 + Qx acc = L_msu0_sat( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx acc = L_mac0_sat( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx -#else - acc = L_shl( *RZ0, 15 ); // Q15 + Qx - acc = L_msu0( acc, *RZ1, t_sin[c1_ind] ); // Q15 + Qx - acc = L_mac0( acc, *RZ2, t_sin[c2_ind] ); // Q15 + Qx -#endif - *RY = round_fx( acc ); // Qx - 1 + *RY = round_fx( acc ); // Qx - 1 move16(); return; diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 9f8f0355684746df6a60744a31bcb3cbdbe1c6fa..320bf4aa28db440d966d1943a6af3a2d0e8304c2 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -643,10 +643,8 @@ void fft_rel_fx( Word16 *x0, *x1, *x2; const Word16 *s, *c; Word16 *xi2, *xi3, *xi4, *xi1; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif /*-----------------------------------------------------------------* diff --git a/lib_com/fill_spectrum_fx.c b/lib_com/fill_spectrum_fx.c index 84d3127077201edd0c41ec9daacdf25850a91254..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/findpulse_fx.c b/lib_com/findpulse_fx.c index 7e0f535b37e9262d84da0a8592f3dd87401a306f..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 @@ -31,12 +31,11 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" -#include #include "prot_fx.h" #include "cnst.h" #include "wmc_auto.h" diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index dd306f872344a86753e2db927bbd45c662389805..b6846372c6ee1434a1222e798335f46eb24439ca 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c deleted file mode 100644 index 8b69e05e8811edbc273a3cd78e735d1bc0f99375..0000000000000000000000000000000000000000 --- a/lib_com/float_to_fix_ops.c +++ /dev/null @@ -1,297 +0,0 @@ -#include -#include -#include -#include -#include "options.h" -#include "prot_fx.h" -#define WMC_TOOL_SKIP - -Word32 floatToFixed( float f, Word16 Q ) -{ - Word64 result_32; - if ( f == 1.0f && Q == Q15 ) - return MAX16B; - if ( f == 1.0f && Q == Q31 ) - return MAXVAL_WORD32; - if ( Q < 0 ) - result_32 = (Word64) ( (float) ( f ) / (double) ( (unsigned Word64) 1 << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); - else - result_32 = (Word64) ( f * (double) ( (unsigned Word64) 1 << Q ) + ( f >= 0 ? 0.5 : -0.5 ) ); - if ( result_32 > MAX_32 ) - return MAX_32; - if ( result_32 < MIN_32 ) - return MIN_32; - return (Word32) result_32; -} - - -float fixedToFloat( Word32 i, Word16 Q ) -{ - if ( Q < 0 ) - return ( i * (float) ( ( 1LL ) << ( -Q ) ) ); - else - return (float) ( i ) / (float) ( 1LL << Q ); -} -void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l ) -{ - for ( int j = 0; j < l; j++ ) - { - Word64 i64_val = floatToFixed( f[j], Q ); - IF( i64_val > MAX_32 ) - { - i64_val = MAX_32; - } - ELSE IF( i64_val < MIN_32 ) - { - i64_val = MIN_32; - } - i[j] = (Word32) i64_val; - } -} -void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l ) -{ - if ( Q <= 0 ) - { - floatToFixed_arr( f, i, Q, l ); - return; - } - for ( int j = 0; j < l; j++ ) - { - i[j] = float_to_fix16( f[j], Q ); - } -} -void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l ) -{ - if ( Q <= 0 ) - { - floatToFixed_arrL( f, i, Q, l ); - return; - } - for ( int j = 0; j < l; j++ ) - { - i[j] = float_to_fix( f[j], Q ); - } -} - -float fixedToFloat_16( Word16 i, Word16 Q ) -{ - if ( Q < 0 ) - return ( i * (float) ( ( (unsigned) 1 ) << ( -Q ) ) ); - else - return (float) ( i ) / (float) ( (unsigned int) 1 << Q ); -} -float fixedToFloat_32( Word32 number, Word16 Q ) -{ - float val = 0.0f; - assert( abs_s( Q ) <= 63 ); - if ( abs_s( Q ) > 31 ) - { - if ( Q > 0 ) - { - val = ( ( (float) number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) ); - } - else - { - val = ( (float) number * ( 1 << ( -Q - 31 ) ) * (unsigned int) MIN_32 ); - } - } - else - { - val = fixedToFloat( number, Q ); - } - return val; -} - -Word32 floatToFixed_32( float number, Word16 Q ) -{ - float val = 0.0f; - assert( abs_s( Q ) <= 63 ); - if ( abs_s( Q ) > 31 ) - { - if ( Q > 0 ) - { - val = ( number * ( (unsigned int) MAX_32 + 1 ) ) * ( 1 << ( Q - 31 ) ); - } - else - { - val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int) MIN_32; - } - if ( val >= 0.0f ) - { - assert( (Word32) val <= MAX_32 ); - } - else - { - assert( (Word32) val >= MIN_32 ); - } - } - else - { - return floatToFixed( number, Q ); - } - - return (Word32) val; -} - -void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l ) -{ - for ( int j = 0; j < l; j++ ) - { - i[j] = floatToFixed_32( f[j], Q ); - } -} - -void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l ) -{ - for ( int j = 0; j < l; j++ ) - { - f[j] = fixedToFloat_32( i[j], Q ); - } -} - -void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l ) -{ - for ( int j = 0; j < l; j++ ) - { - Word32 i32_val = floatToFixed( f[j], Q ); - IF( i32_val > MAX_16 ) - { - i32_val = MAX_16; - } - ELSE IF( i32_val < MIN_16 ) - { - i32_val = MIN_16; - } - i[j] = (Word16) i32_val; - } -} -void fixedToFloat_arrL( Word32 *i, float *f, Word16 Q, Word16 l ) -{ - for ( int j = 0; j < l; j++ ) - { - f[j] = fixedToFloat( i[j], Q ); - } -} -void fixedToFloat_arr( Word16 *i, float *f, Word16 Q, Word16 l ) -{ - for ( int j = 0; j < l; j++ ) - { - f[j] = fixedToFloat( i[j], Q ); - } -} -Word16 Q_factor( float x ) -{ - Word16 Q = 15; - if ( x >= 1 || x <= -1 ) - Q = norm_s( (Word16) L_abs( (Word32) x ) ); - return Q; -} -Word16 Q_factor_L( float x ) -{ - Word16 Q = 31; - if ( x >= 1 || x <= -1 ) - Q = norm_l( L_abs( (Word32) x ) ); - return Q; -} -Word16 Q_factor_L_32( Word32 x ) -{ - Word16 Q = 31; - if ( x >= 1 || x <= -1 ) - Q = norm_l( L_abs( (Word32) x ) ); - return Q; -} -Word16 Q_factor_arr( float *x, Word16 l ) -{ - Word16 Q = 15; - for ( int i = 0; i < l; i++ ) - { - if ( x[i] >= 1 || x[i] <= -1 ) - Q = s_min( Q, norm_s( (Word16) L_abs( (Word32) x[i] ) ) ); - } - return Q; -} -Word16 Q_factor_arrL( float *x, Word16 l ) -{ - Word16 Q = 31; - for ( int i = 0; i < l; i++ ) - { - if ( x[i] >= 1 || x[i] <= -1 ) - Q = s_min( Q, norm_l( (Word32) L_abs( (Word32) x[i] ) ) ); - } - return Q; -} - -Word16 L_get_q( float f ) -{ - if ( fabsf( f ) > (float) INT_MAX ) - { - return sub( sub( W_norm( (Word64) f ), 32 ), 0 ); - } - else - { - return sub( norm_l( (Word32) f ), 0 ); - } -} - -Word16 L_get_q_buf( float *ptr_flt, Word16 length ) -{ - Word16 k; - float ftemp = 0.0; - - for ( k = 0; k < length; k++ ) - { - if ( fabsf( ptr_flt[k] ) > ftemp ) - ftemp = fabsf( ptr_flt[k] ); - } - - if ( ftemp > (float) INT_MAX ) - { - return sub( sub( W_norm( (Word64) ftemp ), 32 ), 0 ); - } - else - { - return sub( norm_l( (Word32) ftemp ), 0 ); - } -} - -Word16 L_get_q1( float f ) -{ - if ( fabsf( f ) >= 0.f && fabsf( f ) < 1.f ) - { - return Q31; - } - else if ( fabsf( f ) > (float) INT_MAX ) - { - return sub( sub( W_norm( (Word64) f ), 32 ), 0 ); - } - else - { - return sub( norm_l( (Word32) f ), 0 ); - } -} - -Word16 L_get_q_buf1( float *ptr_flt, Word16 length ) -{ - Word16 k; - float ftemp = 0.0; - - for ( k = 0; k < length; k++ ) - { - if ( fabsf( ptr_flt[k] ) > ftemp ) - ftemp = fabsf( ptr_flt[k] ); - } - - if ( ftemp >= 0.f && ftemp < 1.f ) - { - return Q31; - } - else if ( ftemp > (float) INT_MAX ) - { - return sub( sub( W_norm( (Word64) ftemp ), 32 ), 0 ); - } - else - { - return sub( norm_l( (Word32) ftemp ), 0 ); - } -} -#undef WMC_TOOL_SKIP diff --git a/lib_com/frame_ener_fx.c b/lib_com/frame_ener_fx.c index 1ba05337caf20f13b8ad1494daf9aedb809cf03f..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 @@ -31,12 +31,11 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "wmc_auto.h" diff --git a/lib_com/gain_inov_fx.c b/lib_com/gain_inov_fx.c index cd0d34290986934dfef02fd158202ad6c2dfe685..b97f399c072437b8f2b9a629226ec2669b7c1e75 100644 --- a/lib_com/gain_inov_fx.c +++ b/lib_com/gain_inov_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/get_gain_fx.c b/lib_com/get_gain_fx.c index 69d18b600c2396544fa6e013dfc246dcbc442936..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c index a4ebbe2d576bfff7fbae1da65888ab369b3d8fb9..77f974cac810e8b78fdc549a0b60092de77ec1a0 100644 --- a/lib_com/gs_bitallocation_fx.c +++ b/lib_com/gs_bitallocation_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -10,34 +10,34 @@ #include "stl.h" /*==================================================================================*/ -/* FUNCTION : void bands_and_bit_alloc_fx(); */ +/* FUNCTION : void bands_and_bit_alloc_fx(); */ /*----------------------------------------------------------------------------------*/ /* PURPOSE : AC mode (GSC) bands and bits allocation */ /*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) cor_strong_limit : HF correlation */ -/* _ (Word16) noise_lev : dwn scaling factor Q0 */ -/* _ (Word32) core_brate : core codec used Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) cor_strong_limit : HF correlation */ +/* _ (Word16) noise_lev : dwn scaling factor Q0 */ +/* _ (Word32) core_brate : core codec used Q0 */ +/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ /* _ (Word16) bits_used : Number of bit used before frequency Q0 */ -/* _ (Word16) idx : Energy band 14 Q0 */ -/* _ (Word16*) exc_diff : Difference signal to quantize (Encoder only) */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ +/* _ (Word16) idx : Energy band 14 Q0 */ +/* _ (Word16*) exc_diff : Difference signal to quantize (Encoder only) */ +/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) bwidth : input signal bandwidth Q0 */ /*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) max_ener_band : Sorted order */ -/* _ (Word16*) nb_subbands : Number of subband allowed Q0 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) max_ener_band : Sorted order */ +/* _ (Word16*) nb_subbands : Number of subband allowed Q0 */ /* _ (Word16*) concat_in : Concatened PVQ's input vector (Encoder Only) */ -/* _ (Word16*) pvq_len : Number of bin covered with the PVQ Q0 */ +/* _ (Word16*) pvq_len : Number of bin covered with the PVQ Q0 */ /*----------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) bit :Number of bit allowed for frequency quantization */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16*) bit :Number of bit allowed for frequency quantization */ /* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q13 */ /* _ (Word32*) bits_per_bands : Number of bit allowed per allowed subband Q18 */ /*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==================================================================================*/ void bands_and_bit_alloc_fx( const Word16 cor_strong_limit, /* i : HF correlation */ diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index 2223c0f8f0a5d2fb2f8752a563100ae6f7fd94b4..5d9516d2cf459f38294d726ea437ead5558cfe85 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -41,34 +41,34 @@ static Word16 Find_norm_inv_fx( const Word32 ToDivide, Word16 *e_div ); static Word16 Find_bit_alloc_IVAS_fx( const Word32 core_brate, const Word16 GSC_IVAS_mode, const Word16 Diff_len, const Word16 nb_tot_bands, Word16 *bit, Word16 *max_ener_band, Word16 *ener_vec, Word32 *bits_per_bands ); static Word32 Find_bit_frac_fx( const Word16 nb_band, const Word16 remaining_bits ); /*==================================================================================*/ -/* FUNCTION : void bands_and_bit_alloc_ivas_fx(); */ +/* FUNCTION : void bands_and_bit_alloc_ivas_fx(); */ /*----------------------------------------------------------------------------------*/ /* PURPOSE : AC mode (GSC) bands and bits allocation */ /*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) cor_strong_limit : HF correlation */ -/* _ (Word16) noise_lev : dwn scaling factor Q0 */ -/* _ (Word32) core_brate : core codec used Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) cor_strong_limit : HF correlation */ +/* _ (Word16) noise_lev : dwn scaling factor Q0 */ +/* _ (Word32) core_brate : core codec used Q0 */ +/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ /* _ (Word16) bits_used : Number of bit used before frequency Q0 */ -/* _ (Word16) idx : Energy band 14 Q0 */ -/* _ (Word16*) exc_diff : Difference signal to quantize (Encoder only) */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ +/* _ (Word16) idx : Energy band 14 Q0 */ +/* _ (Word16*) exc_diff : Difference signal to quantize (Encoder only) */ +/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) bwidth : input signal bandwidth Q0 */ /*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) max_ener_band : Sorted order */ -/* _ (Word16*) nb_subbands : Number of subband allowed Q0 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) max_ener_band : Sorted order */ +/* _ (Word16*) nb_subbands : Number of subband allowed Q0 */ /* _ (Word16*) concat_in : Concatened PVQ's input vector (Encoder Only) */ -/* _ (Word16*) pvq_len : Number of bin covered with the PVQ Q0 */ +/* _ (Word16*) pvq_len : Number of bin covered with the PVQ Q0 */ /*----------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) bit :Number of bit allowed for frequency quantization */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16*) bit :Number of bit allowed for frequency quantization */ /* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q12 */ /* _ (Word32*) bits_per_bands : Number of bit allowed per allowed subband Q18 */ /*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==================================================================================*/ void bands_and_bit_alloc_ivas_fx( const Word16 cor_strong_limit, /* i : HF correlation */ diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 860ed90b0985c9981c63008925521e3191efea1d..c1654b43384778914ec6e1e71f04fbfcf5649491 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 @@ -31,11 +31,10 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include -#include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ @@ -44,38 +43,40 @@ #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 */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _ (Word16[]) Ener_per_bd_iQ : Target ener per band Q12 */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_diffQ : Quantized excitation Qexc */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_diffQ : Quantized excitation Qexc */ /* _ (Word16[]) Ener_per_bd_yQ : Ener per band for norm vectori->Q12/o->Q2*/ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ +/* OUTPUT ARGUMENTS : */ +/* _ None */ /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ -void Comp_and_apply_gain_fx( - 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 Comp_and_apply_gain_fx( + 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 */ + const Word16 Flag_adj_q_exc, /* i : Flag allowing Q_exc adjustment */ Word16 Qexc_diff, Word16 Q_exc ) { @@ -83,6 +84,9 @@ void Comp_and_apply_gain_fx( Word16 StartBin, NB_Qbins; Word16 y_gain; Word16 L16, frac, exp1, tmp_exp; + Word16 Q_adapt; + Word16 Q_exc_diffQ[L_FRAME16k]; + Word32 exc_diffQ32[L_FRAME16k]; Word32 L32; /* Recreate excitation for local synthesis and decoder */ @@ -92,6 +96,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 +120,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,203 +131,104 @@ 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++ ) - { - 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(); - } - } - } - - return; -} - -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 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 Qexc_diff, - Word16 *Q_exc ) -{ - Word16 i, i_band; - Word16 StartBin, NB_Qbins; - Word16 y_gain; - Word16 L16, frac, exp1, tmp_exp; - Word32 L32; - Word16 Q_exc_diffQ[L_FRAME16k]; - - /* Recreate excitation for local synthesis and decoder */ - StartBin = 0; - move16(); - NB_Qbins = 0; - 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 ); - NB_Qbins = mfreq_bindiv_loc[i_band]; - move16(); - IF( EQ_16( ReUseGain, 1 ) ) - { - y_gain = Ener_per_bd_yQ[i_band]; /*Q13*/ - move16(); - - FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) + IF( Flag_adj_q_exc != 0 ) { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Q_exc+16-tmp_exp */ - exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc-tmp_exp */ - move16(); - IF( exc_diffQ[i] ) - { - Q_exc_diffQ[i] = sub( *Q_exc, tmp_exp ); - } - ELSE + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - Q_exc_diffQ[i] = *Q_exc; + 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(); + } } - move16(); } - } - ELSE - { - /*-----------------------------------------------------------------* - * 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 */ - frac = L_Extract_lc( L32, &exp1 ); /* Extract exponent of gcode0 */ - y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); /*Q13*/ - move16(); /*Q1 */ - tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) ); - - FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) + ELSE { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ - exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc-tmp_exp */ - move16(); - IF( exc_diffQ[i] ) - { - Q_exc_diffQ[i] = sub( *Q_exc, tmp_exp ); - } - ELSE + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - Q_exc_diffQ[i] = *Q_exc; + 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(); } - move16(); } } } - - FOR( i = 0; i < StartBin + NB_Qbins; i++ ) - { - *Q_exc = s_min( *Q_exc, add( Q_exc_diffQ[i], norm_s( exc_diffQ[i] ) ) ); - move16(); - } - FOR( i = 0; i < StartBin + NB_Qbins; i++ ) + Q_adapt = Q_exc; + move16(); + test(); + IF( EQ_16( ReUseGain, 0 ) && Flag_adj_q_exc != 0 ) { - exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) ); /*Q_exc*/ + 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; + return Q_adapt; } /*========================================================================*/ -/* FUNCTION : Ener_per_band_comp_fx() */ +/* FUNCTION : Ener_per_band_comp_fx() */ /*------------------------------------------------------------------------*/ /* PURPOSE : Compute the energy per band in log domain for quantization */ -/* purposes. */ -/* Loops are decomposed to accomodate the PVQ quantization */ +/* purposes. */ +/* Loops are decomposed to accomodate the PVQ quantization */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _ (Word16*) edct_table_128_fx : edct table Q15 */ /* _ (Word16*) Q_exc_diff : input format of exc_diff */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) y_gain4 : Energy per band to quantize Q12 */ -/* _ (Word32*) etmp14 : Energy band 14 Q_exc_diff*2+1 */ -/* _ (Word32*) etmp15 : Energy band 15 Q_exc_diff*2+1 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) y_gain4 : Energy per band to quantize Q12 */ +/* _ (Word32*) etmp14 : Energy band 14 Q_exc_diff*2+1 */ +/* _ (Word32*) etmp15 : Energy band 15 Q_exc_diff*2+1 */ /*------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* 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 */ -) -{ - const Word16 *pt_fx; - Word16 j; - - pt_fx = exc_diff_fx; - FOR( j = 0; j < 2; j++ ) - { - y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/ - move16(); - pt_fx += 8; - } - - FOR( j = 1; j < Mband - 2; j++ ) - { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/ - move16(); - pt_fx += 16; - } - - IF( EQ_16( Eflag, 1 ) ) - { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ - move16(); - pt_fx += 32; - } - - return; -} -void Ener_per_band_comp_ivas_fx( +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 */ + 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 */ - const Word16 L_frame /* i : frame length */ + const Word16 L_frame /* i : frame length */ ) { const Word16 *pt_fx; @@ -355,751 +262,129 @@ void Ener_per_band_comp_ivas_fx( move16(); y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/ move16(); - pt_fx += 64; - } - - return; -} - - -/*-------------------------------------------------------------------* - * gsc_gainQ() - * - * Quantization of the energy per band - *-------------------------------------------------------------------*/ - -static void GSC_gain_adj( - const Word16 coder_type, /* i : Coder type */ - 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 */ -) -{ - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - Word16 Gain_off, i; - - IF( coder_type != INACTIVE ) - { - 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(); - } - } - ELSE - { - Gain_off = 0; - move16(); - IF( LE_32( core_brate, ACELP_7k20 ) ) - { - Gain_off = 32767; - move16(); /* 8 -> Q12 */ - } - ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) - { - Gain_off = 27034; - move16(); /* 6.6f -> Q12 */ - } - ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) - { - Gain_off = 19661; - move16(); /*4.8f-> Q12 */ - } - ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) - { - Gain_off = 14336; - move16(); /* 3.5f -> Q12 */ - } - ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) - { - Gain_off = 12288; - move16(); /* 3.0f -> Q12 dB */ - } - - /*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] = 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 */ ) ) ) ); - move16(); - } - } - - return; -} - - -/*-------------------------------------------------------------------* - * GSC_gain_adj_ivas_fx() - * - * Quantization of the energy per band - *-------------------------------------------------------------------*/ - -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 */ -) -{ - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - Word16 Gain_off, i; - - test(); - IF( ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) - { - 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(); - } - } - ELSE - { - Gain_off = 0; - move16(); - - 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 ) ) - { - Gain_off = 7168; - move16(); /* 3.5f -> Q11 */ - } - ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) - { - Gain_off = 6144; - move16(); /* 3.0f -> Q11 dB */ - } - - /*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(); - } } - 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 ) ) - { - Gain_off = 1843; // 9/20 in Q12 - move16(); - } - ELSE IF( LE_32( core_brate, ACELP_7k20 ) ) - { - Gain_off = 1638; // 8/20 in Q12; /* 0 dB */ - move16(); - } - ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) - { - Gain_off = 1351; // 6.6f/20 in Q12 /* ~-3.3 dB */ - move16(); - } - ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) - { - Gain_off = 983; // 4.8f/20 in Q12 /* ~-2.4 dB */ - move16(); - } - ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) - { - Gain_off = 717; // 3.5f/20 in Q12 /* ~-2.4 dB */ - move16(); - } - ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) - { - Gain_off = 614; // 3.0f/20 in Q12 /* ~-2.4 dB */ - move16(); - } - } - - test(); - IF( coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) ) - { - FOR( i = 0; i < Mbands_gn; i++ ) - { - Gain_out[i] = add( Gain_in[i], mean_g ); // Q12 - move16(); - } - } - ELSE - { - /*mimic ACELP decay of energy for low rates*/ - test(); - IF( element_mode == EVS_MONO && EQ_16( enc_dec, DEC ) ) - { - /* 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++ ) - { - Gain_out[i] = add( Gain_out[i], sub( mean_g, mult( Gain_off, div_s( i, Mbands_gn ) ) ) ); // Q12 - move16(); - // Gain_out[i] += mean_g - i * ( Gain_off / 20.f ) / ( (float) Mbands_gn ); - } - } - ELSE - { - FOR( i = 0; i < Mbands_gn; i++ ) - { - 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 ) ); - } - } - } - - 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]; + return; } -/*==========================================================================*/ -/* 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 */ -/*==========================================================================*/ +/*-------------------------------------------------------------------* + * GSC_gain_adj() + * + * + *-------------------------------------------------------------------*/ -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 */ +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 */ + const Word16 *y_gain_tmp, /* i : Dequantized gains */ + Word16 *y_gainQ /* i/o: Output gains Q12 */ ) { - Word16 idx_g_fx, i; - Word16 mean_4g_fx; - Word16 y_gain_tmp3_fx[MBANDS_GN]; + /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ + Word16 Gain_off, i; + Word16 Fac_div; + + Fac_div = 102; + move16(); test(); - test(); - IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) + IF( coder_type != INACTIVE && NE_16( coder_type, UNVOICED ) ) { - 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 ) ) + FOR( i = 0; i < Mbands_gn; i++ ) { - /* 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 ); + old_y_gain[i] = y_gain_tmp[i]; move16(); - y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); + y_gainQ[i] = add( y_gain_tmp[i], mean_g ); 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 ); + Gain_off = 0; /* For higher bitrate, thus for L_frame == L_FRAME16k as well */ + move16(); - IF( LE_32( core_brate_fx, ACELP_9k60 ) ) + test(); + IF( LE_32( core_brate, ACELP_5k00 ) && EQ_16( coder_type, UNVOICED ) ) /* IVAS LR mode only */ { - /*--------------------------------------------------------------------------------------* - * 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]; + Gain_off = 18432; + move16(); /* 9 -> Q11 */ + Fac_div = 205; /* Q15 -> Q16 to compensate for Gain_off being Q11 instead of Q12 */ move16(); } - ELSE + ELSE IF( LE_32( core_brate, ACELP_7k20 ) ) { - 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 ); + Gain_off = 32767; + move16(); /* 8 -> Q12 */ + } + ELSE IF( LE_32( core_brate, ACELP_8k00 ) ) + { + Gain_off = 27034; + move16(); /* 6.6f -> Q12 */ + } + ELSE IF( LE_32( core_brate, ACELP_9k60 ) ) + { + Gain_off = 19661; + move16(); /*4.8f-> Q12 */ + } + ELSE IF( LE_32( core_brate, ACELP_11k60 ) ) + { + Gain_off = 14336; + move16(); /* 3.5f -> Q12 */ + } + ELSE IF( LE_32( core_brate, ACELP_13k20 ) ) + { + Gain_off = 12288; + move16(); /* 3.0f -> Q12 dB */ + } - 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 ); + /*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] = 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, Fac_div /* 20/MBANDS_GN in Q15 */ ) ) ) ); + move16(); } } - /* 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; + return; } /*==========================================================================*/ -/* FUNCTION : Word16 gsc_gaindec_ivas_fx () */ +/* 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 */ +/* 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 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) y_gainQ_fx : quantized gain per band */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) old_y_gain_fx : AR gain quantizer for low rate */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) old_y_gain_fx : AR gain quantizer for low rate */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) : average frequency gain */ +/* 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 */ +/*! 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 */ ) { Word16 idx_g_fx, i; @@ -1107,6 +392,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc 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; @@ -1139,6 +425,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc 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 ) ) { @@ -1173,47 +460,60 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc /*--------------------------------------------------------------------------------------* * 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 ); + 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 ) ) + { + 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 - *----------------------------------------------------------------------*/ + /*----------------------------------------------------------------------* + * 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 ); + 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 ); + 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 ); + 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 ); + 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 */ + 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(); } - /*----------------------------------------------------------------------* - * 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 + { + set16_fx( y_gainQ_fx + 3, 0, MBANDS_GN16k - 3 ); + } } ELSE { @@ -1251,8 +551,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 +563,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 +680,6 @@ Word16 gsc_gainQ_fx( /*Q12*/ ELSE { /*ftmp1 = mean(y_gain4, 16);*/ - L_tmp = 0; move32(); FOR( cnt = 0; cnt < 16; cnt++ ) @@ -1382,7 +688,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 +744,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 +839,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 119811275e34a99e7b2f22226dc8385c9709fc6f..d00b8e3c0346b63084b679e242a0d2ffec76062e 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -16,26 +16,26 @@ #define BETA0_FX ( 32768 - ALPHA0_FX ) /*Q15*/ /*========================================================================*/ -/* FUNCTION : Inac_swtch_ematch_fx() */ +/* FUNCTION : Inac_swtch_ematch_fx() */ /*------------------------------------------------------------------------*/ /* PURPOSE : Apply energy matching when swithcing to INACTIVE frame coded */ -/* by the GSC technology */ +/* by the GSC technology */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) coder_type : Coding mode */ -/* _ (Word16) L_frame : Frame lenght */ -/* _ (Word32) core_brate : core bitrate */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) coder_type : Coding mode */ +/* _ (Word16) L_frame : Frame lenght */ +/* _ (Word32) core_brate : core bitrate */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc2 : CELP/GSC excitation buffer Q_exc */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc2 : CELP/GSC excitation buffer Q_exc */ /* _ (Word16[]) lt_ener_per_band : Long term energy per band Q12 */ /* _ (Word16*) Q_exc : input and output format of exc2 */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void Inac_switch_ematch_fx( @@ -77,7 +77,7 @@ 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 ) { - Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) @@ -91,7 +91,7 @@ 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 ); - Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) @@ -104,7 +104,8 @@ 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 ); - Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); + + Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame ); /* 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 2617bd5cec5817820e103de88e90af511f35e150..534f9edc224ed1c82fc4ec102ad014adbcf4a589 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" @@ -128,27 +128,27 @@ static void EstimateNoiseLevel_inner_fx( return; } /*==========================================================================*/ -/* FUNCTION : void EstimateNoiseLevel_fx() */ +/* FUNCTION : void EstimateNoiseLevel_fx() */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : */ +/* PURPOSE : */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) bitrate : Bitrate of the codec Q0 */ -/* _ (Word16) Diff_len : number of bin before cut-off frequency */ -/* _ (Word16) Mbands_gn : number of bands Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word32) bitrate : Bitrate of the codec Q0 */ +/* _ (Word16) Diff_len : number of bin before cut-off frequency */ +/* _ (Word16) Mbands_gn : number of bands Q0 */ /* _ (Word16) coder_type : coder type Q0 */ -/* _ (Word16) noise_lev : pulses dynamic Q0 */ +/* _ (Word16) noise_lev : pulses dynamic Q0 */ /* _ (Word16) pit_band_idx : bin position of the cut-off frequency */ -/* _ (Word16*) freq_nsbin_per_band : bin per bands tables Q0 */ +/* _ (Word16*) freq_nsbin_per_band : bin per bands tables Q0 */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) noisepb : Noise per band Q15 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) noisepb : Noise per band Q15 */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /* None */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==========================================================================*/ static void EstimateNoiseLevel_fx( Word16 *noisepb, /* o : Noise per band */ @@ -241,27 +241,27 @@ static void EstimateNoiseLevel_fx( } /*============================================================================*/ -/* FUNCTION : void Appy_NoiseFill_fx() */ +/* FUNCTION : void Appy_NoiseFill_fx() */ /*----------------------------------------------------------------------------*/ -/* PURPOSE : */ +/* PURPOSE : */ /*----------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _ (Word16*) seed_tcx : Seed for noise Q0 */ -/* _ (Word16*) noisepb : Noise per band Q15 */ +/* _ (Word16*) noisepb : Noise per band Q15 */ /* _ (Word16) Diff_len : number of bin before cut-off frequency Q0 */ /* _ (Word16) Mbands_gn : number of bands Q0 */ -/* _ (Word16) coder_type : pulses dynamic Q0 */ +/* _ (Word16) coder_type : pulses dynamic Q0 */ /* _ (Word16*) freq_nsbin_per_band: bin per bands tables Q0 */ -/* _ (Word16) qexc_diffQ : Q format of exc_diffQ */ +/* _ (Word16) qexc_diffQ : Q format of exc_diffQ */ /*----------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) exc_diffQ : Noise per band qexc_diffQ */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) exc_diffQ : Noise per band qexc_diffQ */ /*----------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /* None */ /*----------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*============================================================================*/ static void Apply_NoiseFill_fx( Word16 *exc_diffQ, /* i/o: Noise per band qexc_diffQ */ @@ -294,25 +294,25 @@ static void Apply_NoiseFill_fx( return; } /*==========================================================================*/ -/* FUNCTION :void freq_dnw_scaling_fx () */ +/* FUNCTION :void freq_dnw_scaling_fx () */ /*--------------------------------------------------------------------------*/ /* PURPOSE : */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) cor_strong_limit : HF correlation Q0 */ -/* _ (Word16) coder_type : coder type Q0 */ -/* _ (Word16) noise_lev : Noise level Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) cor_strong_limit : HF correlation Q0 */ +/* _ (Word16) coder_type : coder type Q0 */ +/* _ (Word16) noise_lev : Noise level Q0 */ /* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Qx : Q format of fy_norm */ +/* _ (Word16) Qx : Q format of fy_norm */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) fy_norm : Frequency quantized parameter Qx */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) fy_norm : Frequency quantized parameter Qx */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ +/* RETURN ARGUMENTS : */ +/* _None */ /*==========================================================================*/ void freq_dnw_scaling_fx( const Word16 cor_strong_limit, /* i : HF correlation */ @@ -637,381 +637,8 @@ static void envelop_modify_fx( return; } -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 */ -) -{ - Word16 i, j, k; - Word16 MAX_Bin = 0; - Word16 last_bin_tmp, ener = 0; - move16(); - Word16 noisepb[MBANDS_GN16k]; - Word16 Ener_per_bd_yQ[MBANDS_GN16k]; - Word16 *src, *dst; - Word32 L_tmp; - Word16 length_bin, bwe_flag = 0, tmp; - move16(); - Word16 frac, exp, tmp1; - Word16 tmp2; - Word16 *end, Q_hb_exc; - FOR( j = 10; j < MBANDS_GN; j++ ) - { - /* ener += (float)pow(10, Ener_per_bd_iQ[j]); - ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */ - - L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q27 to Q16 */ - - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub( exp, 14 ); - tmp1 = shl_sat( tmp, exp ); - move16(); - ener = add_sat( tmp1, ener ); /*Q0 */ - } - - test(); - IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) ) - { - if ( NE_16( last_coder_type, AUDIO ) ) - { - *last_ener = ener; - move16(); - } - test(); - test(); - IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) ) - { - MAX_Bin = 10; - move16(); - bwe_flag = 1; - move16(); - } - ELSE - { - MAX_Bin = 15; - move16(); - } - - last_bin_tmp = last_bin; - move16(); - last_bin = s_max( last_bin, MAX_Bin ); - last_bin = add( last_bin, 1 ); - } - ELSE - { - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - last_bin = MBANDS_GN16k; - move16(); - } - ELSE - { - last_bin = MBANDS_GN; - move16(); - } - last_bin_tmp = last_bin; - move16(); - } - - test(); - test(); - test(); - 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 */ - } - 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 ); - } - ELSE - { - EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame ); - } - - IF( exc_wo_nf != NULL ) - { - Copy( exc_diffQ, exc_wo_nf, L_frame ); - } - - test(); - test(); - test(); - IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) ) - { - set16_fx( noisepb, 3277, MBANDS_GN ); - } - test(); - IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) ) - { - FOR( i = 0; i < L_frame; i++ ) - { - IF( exc_diffQ[i] == 0 ) - { - /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/ - tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */ - tmp = shr( tmp, sub( 15, Qexc_diffQ ) ); /*qNoise_fac */ - exc_diffQ[i] = add( exc_diffQ[i], tmp ); - move16(); /*Q */ - } - } - } - ELSE - { - 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 ) ) - { - Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 ); - } - ELSE - { - Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); - - IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) - { - FOR( i = L_FRAME - 16; i < L_FRAME; i++ ) - { - /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */ - tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ - L_tmp = L_mult( exc_diffQ[i], tmp ); /*Q(Qexc_diffQ+10) */ - exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */ - move16(); - } - } - } - /*--------------------------------------------------------------------------------------* - * Check potential energy excitation overshoot - *--------------------------------------------------------------------------------------*/ - IF( bfi ) - { - test(); - IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */ - { - FOR( i = 0; i < last_bin; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - FOR( ; i < MBANDS_GN; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < last_bin; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - FOR( ; i < MBANDS_GN; i++ ) - { - Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) ); - move16(); - lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 ); - move16(); - } - } - } - /*--------------------------------------------------------------------------------------* - * Apply decoded gain onto the difference signal - *--------------------------------------------------------------------------------------*/ - - IF( GSC_noisy_speech ) - { - FOR( i = 0; i < L_frame; i++ ) - { - exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 ); - move16(); - } - } - - 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 ); - } - /*--------------------------------------------------------------------------------------* - * add the correction layer to the LF bins, - * and add the quantized pulses or the noise for the higher part of the spectrum - * (non valuable temporal content already zeroed) - * DC is Zeroed - *--------------------------------------------------------------------------------------*/ - - Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame ); - test(); - IF( core_brate == ACELP_8k00 && bwidth != NB ) - { - IF( EQ_16( bwe_flag, 1 ) ) - { - last_bin = sub( last_bin, 1 ); - tmp = i_mult( MAX_Bin, 16 ); - tmp1 = i_mult( last_bin, 16 ); - src = &exc_diffQ[L_FRAME - 1]; - move16(); - dst = &exc_dct_in[( tmp - 1 )]; - move16(); - end = &exc_diffQ[( tmp1 - 1 )]; - move16(); - - WHILE( src > end ) - { - *src-- = *dst--; - move16(); - } - test(); - test(); - if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) ) - { - exc_diffQ[160] = 0; - move16(); - } - - Q_hb_exc = 0; - move16(); - envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc ); - Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */ - } - - IF( LT_16( nb_subfr, 4 ) ) - { - FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ ) - { - /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ - L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ - exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */ - } - } - - tmp1 = mult_r( ener, 16384 ); - tmp1 = sub( *last_ener, tmp1 ); - tmp = mult_r( *last_ener, 16384 ); - tmp = sub( ener, tmp ); - test(); - IF( tmp > 0 && tmp1 > 0 ) - { - length_bin = 6; - move16(); - IF( last_coder_type != AUDIO ) - { - set16_fx( last_bitallocation_band, 0, 6 ); - Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 ); - } - - FOR( i = 4; i < ( 4 + length_bin ); i++ ) - { - test(); - IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) ) - { - k = shl( add( i, length_bin ), 4 ); - src = &exc_dct_in[k]; /*(i+length_bin)*16*/ - dst = &last_exc_dct_in[k]; - FOR( j = 0; j < 16; j++ ) - { - tmp = mult_r( 10923, abs_s( *src ) ); - tmp1 = mult_r( 10923, abs_s( *dst ) ); - - IF( GT_16( tmp, abs_s( *dst ) ) ) - { - tmp2 = *src; - *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */ - move16(); - tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */ - if ( tmp2 > 0 ) - { - *src = tmp; - move16(); - } - } - ELSE IF( GT_16( tmp1, abs_s( *src ) ) ) - { - tmp = mult_r( *src, 22938 ); - tmp1 = mult_r( 9830, abs_s( *dst ) ); - tmp2 = *src; - *src = sub( tmp, tmp1 ); /*Q_exc */ - move16(); - if ( tmp2 > 0 ) - { - *src = add( tmp, tmp1 ); /*Q_exc */ - move16(); - } - } - src++; - dst++; - } - } - } - } - IF( EQ_16( bwe_flag, 1 ) ) - { - Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 ); - } - ELSE - { - Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 ); - } - } - - Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 ); - Copy( &bitallocation_band[4], last_bitallocation_band, 6 ); - *last_ener = ener; - move16(); - - return; -} - -void highband_exc_dct_in_ivas_fx( +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 */ @@ -1056,6 +683,7 @@ void highband_exc_dct_in_ivas_fx( Word16 frac, exp, tmp1; Word16 tmp2; Word16 *end, Q_hb_exc; + Word16 Flag_adj_q_exc, old_Q_exc; FOR( j = 10; j < MBANDS_GN; j++ ) { @@ -1125,11 +753,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 +774,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 +796,21 @@ 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 ) ) { - Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame ); + 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, MBANDS_GN, 1, L_frame ); + Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame ); test(); IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) ) @@ -1195,9 +825,11 @@ void highband_exc_dct_in_ivas_fx( } } } + /*--------------------------------------------------------------------------------------* * Check potential energy excitation overshoot *--------------------------------------------------------------------------------------*/ + IF( bfi ) { test(); @@ -1315,45 +947,22 @@ void highband_exc_dct_in_ivas_fx( move16(); } } - - 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 ); - - 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 ); - } - } - ELSE + Flag_adj_q_exc = 0; + move16(); + IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep all EVS BE */ { - Word16 Q_tmp = *Q_exc; - move16(); - Word16 Q_old = *Q_exc; + Flag_adj_q_exc = 1; move16(); - Comp_and_apply_gain_ivas_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc ); + } + 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_ivas_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, &Q_tmp ); - IF( GT_16( Q_tmp, *Q_exc ) ) - { - Scale_sig( exc_wo_nf, L_frame, sub( *Q_exc, Q_tmp ) ); - } - ELSE IF( LT_16( Q_tmp, *Q_exc ) ) - { - Scale_sig( exc_diffQ, L_frame, sub( Q_tmp, *Q_exc ) ); - *Q_exc = Q_tmp; - move16(); - } - Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); - } - ELSE - { - Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); - } + 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 ); } /*--------------------------------------------------------------------------------------* diff --git a/lib_com/gs_preech_fx.c b/lib_com/gs_preech_fx.c index e607d66c50a2dc636e3b16714b8b953a0f781391..3f72510410c79dba6fd230d58bc99b64371a2cfb 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 @@ -31,12 +31,11 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" -#include #include "cnst.h" #include "rom_com.h" #include "prot_fx.h" @@ -54,10 +53,11 @@ 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 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*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame, /* i : Frame length Q0*/ + const Word16 element_mode /* i : Current IVAS element mode*/ ) { Word32 etmp_fx; @@ -69,6 +69,7 @@ void pre_echo_att_fx( Word16 tmp, n1, n2, exp, frac1, frac2; Word32 etmp1_fx; Word16 att_len; + Word16 etmp_e, tmp_e; 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 +109,51 @@ 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 */ + 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 + { + 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,116 +172,24 @@ 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*/ - } - - return; -} - - -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*/ - 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*/ -) -{ - Word32 etmp_fx; - Word32 finc_fx[ATT_LENGHT16k] = { 0 }; - move16(); - Word16 ratio_fx; - Word16 attack_pos_fx, i; - Word32 L_tmp; - Word16 tmp, tmp_e; - Word32 etmp1_fx; - Word16 etmp_e; - Word16 att_len; - - 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 */ - { - /*-------------------------------------------------------------------------* - * Find where the onset (attack) occurs by computing the energy per section - * The inverse weighting aims to favor the first maxima in case of - * gradual onset - *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; /* Q0 */ - move16(); - if ( EQ_16( L_frame, L_FRAME16k ) ) + IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */ { - att_len = ATT_LENGHT16k; /* Q0 */ - move16(); - } - FOR( i = 0; i < att_len; i++ ) - { - L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ - finc_fx[i] = L_tmp; - move32(); /*2*Q_new+1 */ - } - - attack_pos_fx = maximum_32_fx( finc_fx, att_len, &etmp_fx ); - - /* Scaled the maximum energy and allowed 6 dB increase*/ - etmp_fx = L_shr( etmp_fx, add( 2 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ - etmp1_fx = etmp_fx; - move32(); - *Last_frame_ener_fx = L_shl_sat( *Last_frame_ener_fx, 2 ); - move32(); /*2*Q_new+1 */ - - /* If the maximum normalized energy > last frame energy + 6dB */ - test(); - IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 ) - { - /* Find the average energy before the attack */ - 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 */ - - /* 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++ ) + 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 ) ) { - /*exc_fx[i] *= ratio_fx;*/ - exc_fx[i] = round_fx( L_shl( L_mac( -8192, exc_fx[i], ratio_fx ), 2 ) ); - move16(); + 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*/ } - *Last_frame_ener_fx = etmp1_fx; /* 2 * Q_new + 1 */ - move32(); - } - ELSE - { - /*-------------------------------------------------------* - * In normal cases, just compute the energy of the frame - *-------------------------------------------------------*/ - 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 ) ) + ELSE { - etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*31 - exp_etmp*/ + 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*/ } - *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/ - move32(); /*2*Q_new+1*/ } return; diff --git a/lib_com/guided_plc_util_fx.c b/lib_com/guided_plc_util_fx.c index 91075df44766988237168fac24bd5e9795835cff..81723b42661dfb8458e9138428fe564119d5d552 100644 --- a/lib_com/guided_plc_util_fx.c +++ b/lib_com/guided_plc_util_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -251,10 +251,10 @@ void modify_lsf( static void reorder_lsfs( - Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5) 1.28 Q1*/ - const Word16 min_dist0, /* i : minimum required distance 1.28 Q1*/ - const Word16 n, /* i : LPC order Q0*/ - const Word32 sr_core /* i : input sampling frequency Q0*/ + Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5) 1.28 Q1*/ + const Word16 min_dist0, /* i : minimum required distance 1.28 Q1*/ + const Word16 n, /* i : LPC order Q0*/ + const Word32 sr_core /* i : input sampling frequency Q0*/ ) { Word16 i; diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c index 26cc777940b510fd64b2289ad1743540febf0197..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 @@ -31,11 +31,10 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include -#include #include "options.h" #include "prot_fx.h" #include "wmc_auto.h" @@ -316,14 +315,12 @@ void hp20_fx_32_opt( prescale = s_min( prescale, diff ); prescale = sub( 1 + HP20_FX_COEFF_SCALE, prescale ); -#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC + test(); if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) || // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead LT_16( prescale_current_frame, prescale ) ) // To avoid overflow in the subsequent shr() scaling for W_y1, W_y2, x2, and x1 calculations before the for loop. -#else - if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) ) // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead -#endif { prescale_current_frame = prescale; + move16(); } diff = sub( prescale, prescaleOld ); diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 0f097b669510a450f8ecbd9de929eb230908036a..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 @@ -187,7 +187,7 @@ void Bits2indvsb_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( Rcnt_fx ); Ravg_fx = div_s( shl( be_sum_fx, exp_normn ), shl( Rcnt_fx, exp_normd ) ); - Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift exp_normn - exp_normd + 13*/ + Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift exp_normn - exp_normd + 13*/ QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); if ( be_sum_fx <= 0 ) @@ -207,7 +207,7 @@ void Bits2indvsb_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( be_sum_fx ); Bits_avg_fx = div_s( shl( Bits, exp_normn ), shl( be_sum_fx, exp_normd ) ); - Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift exp_normn - exp_normd + 13*/ + Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift exp_normn - exp_normd + 13*/ QBavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); } FOR( k = 0; k <= i; k++ ) @@ -262,7 +262,7 @@ void hq2_bit_alloc_har_fx( Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index a77513009f4ab74d365878332449c45fe86072e8..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() */ /*--------------------------------------------------------------------------*/ @@ -629,7 +464,7 @@ void reverse_transient_frame_energies_fx( p_be2--; } - k1 = sub( bands, bands_4 ); /* 3*bands/4 Q0 */ + k1 = sub( bands, bands_4 ); /* 3*bands/4 Q0 */ k2 = sub( bands, 1 ); /* Q0 */ p_be1 = &L_band_energy[k1]; /* Q14 */ p_be2 = &L_band_energy[k2]; /* Q14 */ @@ -739,13 +574,13 @@ void spt_shorten_domain_pre_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband Q0*/ - const Word16 band_start[], /* i: starting position of subband Q0*/ - const Word16 band_end[], /* i: end position of subband Q0*/ - const Word16 band_width[], /* i: band width of subband Q0*/ - Word16 org_band_start[], /* o: starting position of subband Q0*/ - Word16 org_band_end[], /* o: end position of subband Q0*/ - Word16 org_band_width[] /* o: band width of subband Q0*/ + const Word16 bands, /* i: total subband Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + const Word16 band_width[], /* i: band width of subband Q0*/ + Word16 org_band_start[], /* o: starting position of subband Q0*/ + Word16 org_band_end[], /* o: end position of subband Q0*/ + Word16 org_band_width[] /* o: band width of subband Q0*/ ) { Word16 k; @@ -774,13 +609,13 @@ void spt_shorten_domain_band_save_fx( *--------------------------------------------------------------------------*/ void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband Q0*/ - Word16 band_start[], /* i/o: starting position of subband Q0*/ - Word16 band_end[], /* i/o: end position of subband Q0*/ - Word16 band_width[], /* i/o: band width of subband Q0*/ - const Word16 org_band_start[], /* o: starting position of subband Q0*/ - const Word16 org_band_end[], /* o: end position of subband Q0*/ - const Word16 org_band_width[] /* o: band width of subband Q0*/ + const Word16 bands, /* i: total subband Q0*/ + Word16 band_start[], /* i/o: starting position of subband Q0*/ + Word16 band_end[], /* i/o: end position of subband Q0*/ + Word16 band_width[], /* i/o: band width of subband Q0*/ + const Word16 org_band_start[], /* o: starting position of subband Q0*/ + const Word16 org_band_end[], /* o: end position of subband Q0*/ + const Word16 org_band_width[] /* o: band width of subband Q0*/ ) { Word16 k; @@ -809,11 +644,11 @@ void spt_shorten_domain_band_restore_fx( *--------------------------------------------------------------------------*/ void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information Qx*/ - const Word16 bands, /* i: total number of bands Q0*/ - const Word16 band_start[], /* i: starting position of subband Q0*/ - const Word16 band_end[], /* i: end position of subband Q0*/ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ + const Word32 L_y2[], /* i: coded spectral information Qx*/ + const Word16 bands, /* i: total number of bands Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ ) { 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_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index c3fc6a3a59ca8ff21dd5fedbf9c52095ffb6463f..c1efb9def8e6cd00471c788298241b93679727aa 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index b400624487bfbb9c5b3bd897c1d88f791382cbb2..b114745b591caa955966d47245c24eaccfac0a75 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 0e00b9428f61a9c68daa8f2a4da70847b4cc48dc..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include @@ -926,12 +926,6 @@ void ivas_harm_bwe_fx( { exp1 = add( 1, exp1 ); } -#ifdef DEBUGGING - else - { - // PMT("VERIFY if this really matches IVAS float") - } -#endif tmp1 = s_max( tmp1, 16384 ); tmp1 = div_s( 16384, tmp1 ); L_tmp2 = L_deposit_h( tmp1 ); @@ -1095,12 +1089,6 @@ void harm_bwe_fx( { exp1 = add( 1, exp1 ); } -#ifdef DEBUGGING - else - { - // PMT("VERIFY if this really matches IVAS float") - } -#endif tmp1 = s_max( tmp1, 16384 ); tmp1 = div_s( 16384, tmp1 ); /*Q15*/ L_tmp2 = L_deposit_h( tmp1 ); /*Q31*/ diff --git a/lib_com/hvq_pvq_bitalloc_fx.c b/lib_com/hvq_pvq_bitalloc_fx.c index bc15fe2660fdeea5d42264efee3fcb4e5eb14c1f..905749d47d8ca12ecf270991ac0cab4a2082c75b 100644 --- a/lib_com/hvq_pvq_bitalloc_fx.c +++ b/lib_com/hvq_pvq_bitalloc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -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 f404a10c8f72d25c02b3d00260226591f0399cad..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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/igf_base_fx.c b/lib_com/igf_base_fx.c index ae2e9c51bd168a96b6229eb421d5438425568a83..79e1ee704021a8bd28d57413eb0315a6d16fcde8 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/index_pvq_opt_fx.c b/lib_com/index_pvq_opt_fx.c index e2d2690cea7f5236548ad13365125b6f6ebb7db8..e17e9c23eccb7ee8f2ff46888134c841be9f54ee 100644 --- a/lib_com/index_pvq_opt_fx.c +++ b/lib_com/index_pvq_opt_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/int_lsp_fx.c b/lib_com/int_lsp_fx.c index f40b11cfa90c0221936e10c533c073e374c6c352..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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; @@ -106,82 +106,7 @@ void int_lsp_fx( void int_lsp4_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 ) ) - { - 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_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 */ @@ -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 3dc1672ec86a746cd74d1f2d8ee3fe59fe4ab094..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/interpol_fx.c b/lib_com/interpol_fx.c index 7d4c2208de4c78c372e870f16da623948d69fa93..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include 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 c445d0299fa3acf3d7256648074877f853ad9c96..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,28 +186,31 @@ 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 -#ifdef JBM_MEMORY_OPT +#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 */ -#else -#define MAX_JBM_L_FRAME48k 1920 -#define MAX_JBM_L_FRAME_NS 40000000L -#endif #define MAX_SPAR_INTERNAL_CHANNELS IVAS_SPAR_MAX_CH #define MAX_CLDFB_DIGEST_CHANNELS 3 /* == maximum of ParamISM TCs and ParamMC TCs */ +#define EDIT_GAIN_MIN_Q29 33874260 /* Minimum allowed object gain edit with parametric modes in Q29: 0.0630957f, -24 dB */ +#define EDIT_GAIN_MAX_Q29 2137321728 /* Maximum allowed object gain edit in Q29: 3.9810719f, +12 dB */ +#define EDIT_GAIN_MIN_Q12 258 /* Minimum allowed object gain edit with parametric modes in Q12: 0.0630957f, -24 dB */ +#define EDIT_GAIN_MAX_Q12 16306 /* Maximum allowed object gain edit in Q12: 3.9810719f, +12 dB */ + typedef enum { TC_BUFFER_MODE_RENDERER, TC_BUFFER_MODE_BUFFER } TC_BUFFER_MODE; +#define ONE_BY_SUBFRAME_LEN_MS_Q31 429496730 +#define ONE_BY_SUBFR_PER_SEC_Q15 164 + /*----------------------------------------------------------------------------------* * IVAS Bitrates @@ -254,9 +257,7 @@ typedef enum /* format signaling in SID frames */ #define SID_FORMAT_NBITS 3 /* Bit 0 | Bit 1 | Bit 2 */ /*-------|-------|------ */ -#ifdef FIX_1384_MSAN_ivas_spar_dec_open #define SID_FORMAT_NONE (-0x1) /* n/a| n/a| n/a*/ -#endif #define SID_DFT_STEREO 0x0 /* 0| 0| 0 */ #define SID_MDCT_STEREO 0x1 /* 1| 0| 0 */ #define SID_ISM 0x2 /* 0| 1| 0 */ @@ -560,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 @@ -642,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)*/ @@ -815,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 @@ -889,10 +886,8 @@ enum fea_names #define MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN 20 #define MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE 3 -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG #define MDCT_ST_DTX_NUM_COHERENCE_BANDS 5 #define MDCT_ST_DTX_FIRST_BAND_OFFSET 2 -#endif typedef enum { NOISE_GEN_MODE_UNDEF = -1, @@ -1265,17 +1260,16 @@ 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 -//TODO: insert proper Q representations -#define OMASA_GAIN_EDIT_THR_FX 246 /* OMASA gain change threshold, 0.06f in Q12 */ -#define OMASA_AZI_EDIT_THR_FX ONE_IN_Q22 /* OMASA-DISC azimuth change threshold, 1.0f in Q22 */ -#define OMASA_ELE_EDIT_THR_FX ONE_IN_Q23 /* OMASA-DISC elevation change threshold, 2.0f in Q22 */ +#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 */ +#define OMASA_ELE_EDIT_THR_Q22 ONE_IN_Q23 /* OMASA-DISC elevation change threshold, 2.0f in Q22 */ #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, @@ -1295,7 +1289,7 @@ typedef enum *----------------------------------------------------------------------------------*/ #define MC_LS_SETUP_BITS 3 /* number of bits for writing the MC LS configuration */ -#define LS_SETUP_CONVERSION_NUM_MAPPINGS 35 /* number of mappings for LS setup conversion */ +#define LS_SETUP_CONVERSION_NUM_MAPPINGS 41 /* number of mappings for LS setup conversion */ typedef enum { @@ -1358,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 @@ -1535,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 @@ -1592,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 ----- */ @@ -1648,11 +1653,21 @@ typedef enum #define RV_LENGTH_NR_FC ( RV_FILTER_MAX_FFT_SIZE / 2 ) + 1 #define RV_LENGTH_NR_FC_16KHZ ( RV_FILTER_MAX_FFT_SIZE / 4 ) + 1 -#define IVAS_REVERB_DEFAULT_N_BANDS 31 +#define IVAS_REVERB_DEFAULT_L_N_BANDS 31 +#define IVAS_REVERB_DEFAULT_M_N_BANDS 31 +#define IVAS_REVERB_DEFAULT_S_N_BANDS 60 #define LR_IAC_LENGTH_NR_FC ( RV_LENGTH_NR_FC ) #define LR_IAC_LENGTH_NR_FC_16KHZ ( RV_LENGTH_NR_FC_16KHZ ) +typedef enum +{ + DEFAULT_REVERB_UNSET = -1, + DEFAULT_REVERB_SMALL, + DEFAULT_REVERB_MEDIUM, + DEFAULT_REVERB_LARGE +} IVAS_DefaultReverbSize; + /*----------------------------------------------------------------------------------* * FB mixer constants @@ -1828,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 1ba3b52aef80ecdcd1cb008a020706ac1feeead0..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /* options.h needed for debugging/development features @@ -128,9 +128,7 @@ typedef enum IVAS_ERR_BITSTREAM_READER_INVALID_FORMAT, IVAS_ERR_NO_FILE_OPEN, IVAS_ERR_SAMPLING_RATE_UNKNOWN, -#ifdef FIX_1370_EXTERNAL_ORIENTATION_CHECK IVAS_ERR_EXTERNAL_ORIENTATION_INVALID_FORMAT, -#endif /*----------------------------------------* * renderer (lib_rend only) * @@ -147,6 +145,14 @@ typedef enum IVAS_ERR_LC3PLUS_INVALID_BITRATE, IVAS_ERR_INVALID_SPLIT_REND_CONFIG, + /*----------------------------------------* + * rtp errors * + *----------------------------------------*/ + IVAS_ERR_RTP_UNDERFLOW = 0x7000, + IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, + IVAS_ERR_RTP_UNPACK_PI_DATA, + IVAS_ERR_RTP_UNSUPPORTED_FRAME, + /*----------------------------------------* * unknown error * *----------------------------------------*/ @@ -268,10 +274,8 @@ static inline const char *ivas_error_to_string( ivas_error error_code ) return "Invalid input format"; case IVAS_ERR_INVALID_INDEX: return "Invalid index"; -#ifdef FIX_1370_EXTERNAL_ORIENTATION_CHECK case IVAS_ERR_EXTERNAL_ORIENTATION_INVALID_FORMAT: return "Euler angles were detected in the input but only Quaternions are supported"; -#endif default: break; } @@ -286,6 +290,22 @@ static inline const char *ivas_error_to_string( ivas_error error_code ) { return "data error"; } + if ( ( error_code & 0x7000 ) == 0x7000 ) + { + switch ( error_code ) + { + case IVAS_ERR_RTP_UNDERFLOW: + return "RTP Undeflow in reading frame/packet"; + case IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE: + return "Output buffer size is insufficient"; + case IVAS_ERR_RTP_UNPACK_PI_DATA: + return "Unpacking PI data failure"; + case IVAS_ERR_RTP_UNSUPPORTED_FRAME: + return "Unsupported RTP frame"; + default: + return "rtp error"; + } + } return "Unknown error"; } 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 c37bef77f0bb193e02b0bd07b286551720a6ba1b..4dc294d4227ac0b685cf6655d8c4db436dffa2a9 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 @@ -60,15 +60,8 @@ void ivas_masa_dec_close_fx( MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ); -ivas_error create_evs_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ -); - void destroy_sce_enc_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - Flag is_evs /* i : Flag to indicate EVS encoder */ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ); void generate_gridEq_fx( @@ -629,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 */ @@ -800,10 +787,6 @@ void destroy_core_enc_fx( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ); -void destroy_evs_core_enc_fx( - ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ -); - ivas_error ivas_sce_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sce_id, /* i : SCE # identifier */ @@ -1050,17 +1033,12 @@ 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 */ Word32 *output_fx[], /* o : rendered time signal */ -#ifdef FIX_1330_JBM_MEMORY const Word16 subframes_rendered /* i : number of subframes rendered */ -#else - const Word16 subframes_rendered, /* i : number of subframes rendered */ - const Word16 slots_rendered /* i : number of CLDFB slots rendered */ -#endif ); void get_panning_gain_fx( @@ -1142,8 +1120,8 @@ void ivas_mono_stereo_downmix_mcmasa_fx( ); void ivas_apply_non_diegetic_panning_fx( - Word32 *input_f_fx, /* i : non-diegetic object */ - Word32 *output_fx[], /* i/o: core-coder transport mono channel/stereo output */ + Word32 *input_f_fx, /* i : non-diegetic object (mono channel) */ + Word32 *output_fx[], /* o : stereo output channels */ const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ const Word16 output_frame /* i : output frame length per channel */ ); @@ -1379,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( @@ -1506,13 +1483,6 @@ ivas_error ivas_dirac_config_fx( void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ const Word16 enc_dec /* i : encoder or decoder flag */ ); -#ifndef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG - -void dtx_read_padding_bits_fx( - DEC_CORE_HANDLE st, - const Word16 num_bits -); -#endif void FdCngEncodeMDCTStereoSID_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder state structure */ @@ -1599,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( @@ -1618,24 +1587,7 @@ 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 */ - Word16 output[], - Word16 *Q_output -); - -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 + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ ); /* o : Consumed bits Q0 */ @@ -1887,38 +1839,11 @@ void stereoFdCngCoherence_fx( Word16 fft_exp ); -void ivas_wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ - Word16 *Q_synth -); - -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 -); - +#ifndef HARM_FD_BWE /* 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 */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ 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 */ @@ -1927,7 +1852,7 @@ Word16 ivas_wb_bwe_dec_fx( const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Word16 *Qpost ); - +#endif void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ const Word16 nchan_obj /* i : number of ISM channels */ @@ -2013,15 +1938,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 */ @@ -2090,26 +2006,24 @@ UWord32 ivas_syn_output_fx( Word16 *synth_out /* o : integer 16 bits synthesis signal */ ); -#ifdef JBM_MEMORY_OPT 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) */ + 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) */ ); 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 */ + 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) */ ); -#endif 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, /* o : synthesis @internal_Fs, Q0 */ + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11 */ 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 */ @@ -2320,13 +2234,8 @@ void ivas_dirac_dec_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ const Word16 nchan_transport, /* i : number of transport channels */ -#ifdef FIX_1319_STACK_SBA_DECODER Word32 *pppQMfFrame_ts_re_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX] -#else - Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], - Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] -#endif ); void ivas_dirac_dec_render_fx( @@ -2485,7 +2394,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 */ @@ -2522,7 +2431,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 */ @@ -3007,17 +2916,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 */ @@ -3034,7 +2932,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 */ @@ -3048,17 +2946,23 @@ 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( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 cdk_index, /* i : codebook index */ const Word16 dn_orig[L_SUBFR], /* i : corr. between target and h[]. Q_dn */ +#ifdef OPT_2416_ACELP_FAST + const Word16 Q_dncn, /* i : scaling factor of dn and cn */ +#else Word16 Q_dn, +#endif const Word16 cn[L_SUBFR], /* i : residual after long term prediction q_cn*/ +#ifndef OPT_2416_ACELP_FAST const Word16 q_cn, +#endif const Word16 H[L_SUBFR], /* i : impulse response of weighted synthesis filter e(norm_s(H[0])+1) */ Word16 code[L_SUBFR], /* o : algebraic (fixed) codebook excitation */ Word16 y[], /* o : filtered fixed codebook excitation */ @@ -3731,8 +3635,8 @@ void ivas_init_binaural_hrtf_fx( ivas_error ivas_allocate_binaural_hrtf_fx( HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ - const int16_t n_channels, /* i : number of input channels */ - const int16_t allocate_init_flag /* i : Memory allocation flag */ + const Word16 n_channels, /* i : number of input channels */ + const Word16 allocate_init_flag /* i : Memory allocation flag */ ); void ivas_binRenderer_fx( @@ -3763,6 +3667,12 @@ void ivas_mc2sba_fx( const Word16 gain_lfe /* i : gain for LFE, 0 = ignore LFE */ ); +void ivas_stereo2sba_fx( + Word32 *input_fx[], /* i : core-coder transport stereo channels */ + Word32 *output_fx[], /* o : SBA output channels */ + const Word16 output_frame /* i : output frame length per channel */ +); + void ivas_param_mc_mc2sba_cldfb_fx( IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ Word32 *hoa_encoder, /* i : HOA3 encoder for the transported MC format */ @@ -3826,20 +3736,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 */ ); @@ -3865,7 +3772,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 */ @@ -3891,7 +3798,11 @@ ivas_error ivas_osba_render_sf_fx( void ivas_osba_stereo_add_channels_fx( Word32 *tc_fx[], /* i : transport channels */ Word32 *output_fx[], /* i/o: output channels */ +#ifdef FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT + const Word32 gain, /* i : gain bed value Q11 */ +#else const Word32 gain_bed_fx, /* i : gain bed value Q11 */ +#endif const Word16 nchan_out, /* i : number of output channels */ const Word16 nchan_ism, /* i : number of ISM channels */ #ifndef FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT @@ -3917,6 +3828,7 @@ void ivas_set_ism_importance_interformat_fx( const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ Word16 ism_imp[] /* o : ISM importance flags */ ); + void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( Decoder_Struct *st_ivas, Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ @@ -3926,7 +3838,6 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( const Word16 subframe ); - void ivas_omasa_decode_masa_to_total_fx( UWord16 *bit_stream, Word16 *index, @@ -4018,28 +3929,15 @@ void inverseMS_fx( const Word32 norm_fac /* i : normalization factor Q31*/ ); -#ifndef JBM_MEMORY_OPT -void ivas_syn_output_f_fx( - Word32 *synth[], /* i/o: Word32 synthesis signal */ - const Word16 output_frame, /* i : output frame length (one channel) */ - const Word16 n_channels, /* i : number of output channels */ - Word32 *synth_out /* o : integer 16 bits synthesis signal */ -); -#endif ivas_error ivas_init_encoder_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); ivas_error ivas_output_buff_dec_fx( Word32 *p_output_fx[], /* i/o: output audio buffers */ -#ifdef FIX_1330_JBM_MEMORY const Word16 nchan_out_buff, /* i : number of output channels */ const Word16 Opt_tsm, /* i : TSM option flag */ DECODER_TC_BUFFER_HANDLE hTcBuffer /* i : TSM buffer handle */ -#else - const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */ - const Word16 nchan_out_buff /* i : number of output channels */ - #endif ); ivas_error ivas_dec_get_format_fx( @@ -4047,7 +3945,7 @@ ivas_error ivas_dec_get_format_fx( ); ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); ivas_error create_mct_dec_fx( @@ -4307,8 +4205,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( @@ -4523,7 +4420,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*/ @@ -4534,8 +4431,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( @@ -5888,7 +5785,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 */ @@ -5902,17 +5799,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 */ @@ -5963,6 +5854,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 */ @@ -5981,67 +5890,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*/ @@ -6060,17 +5965,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( @@ -6168,21 +6073,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 */ @@ -6195,14 +6088,10 @@ 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*/ -#ifndef JBM_MEMORY_OPT - , - Word32 *data_fx /* i/o: transport channels/output synthesis signal */ -#endif ); void ivas_dec_prepare_renderer_fx( @@ -6213,80 +6102,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 */ ); @@ -6448,7 +6337,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*/ ); @@ -6737,7 +6626,6 @@ void ivas_binaural_hrtf_close_fx( HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i/o: decoder binaural hrtf handle */ ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*---------------------------------------------------------------------------------* * Multi-pose ring buffer Prototypes @@ -6773,7 +6661,6 @@ void ivas_CLDFB_RINGBUF_GetByIdx( const Word16 idx ); -#endif /*----------------------------------------------------------------------------------* * renderer prototypes @@ -6784,18 +6671,6 @@ void ivas_ism_renderer_close( ); -/*----------------------------------------------------------------------------------* - * Amplitude Panning VBAP prototypes - *----------------------------------------------------------------------------------*/ - -void panning_wrap_angles( - const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - float *azi_wrapped, /* o : wrapped azimuth component */ - float *ele_wrapped /* o : wrapped elevation component */ -); - - /*----------------------------------------------------------------------------------* * McMASA prototypes *----------------------------------------------------------------------------------*/ @@ -6861,18 +6736,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 */ ); @@ -6889,11 +6758,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 9773d0715db6cd47bb27636649ea460ce60daf37..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" @@ -132,12 +131,8 @@ extern const SpectrumWarping sw25600Hz[]; /* PsychLPC */ extern const SpectrumWarping sw32000Hz[]; /* PsychLPC */ extern const MDCTStereoBands_config mdctStereoBands_32000_640[]; - -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG extern const Word16 mdct_stereo_dtx_coherence_bandlengths[MDCT_ST_DTX_NUM_COHERENCE_BANDS]; extern const Word16 get_next_index_4_by_15[16]; -#endif - /*----------------------------------------------------------------------------------* * Stereo DTX ROM tables @@ -300,9 +295,7 @@ extern const Word32 diffuseness_thresholds_hr_fx[HR_MASA_ER_LEVELS + 1]; extern const Word32 no_phi_masa_inv_fx[NO_SPHERICAL_GRIDS][MAX_NO_THETA]; extern const Word32 azimuth_cb_fx[8]; extern const Word32 delta_theta_masa_fx[NO_SPHERICAL_GRIDS - 2]; -#ifdef OBJ_EDIT_BASOP extern const Word32 delta_theta_masa_inv_fx[NO_SPHERICAL_GRIDS - 2]; -#endif extern const Word16 coherence_cb0_masa_Q14[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH]; extern const Word32 coherence_cb0_masa_fx[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH]; extern const Word16 coherence_cb1_masa_Q15[MASA_NO_CV_COH1 * MASA_MAXIMUM_CODING_SUBBANDS]; /* 25 */ diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index dd99410ace5508d25b478f98e1b5a84e1af30823..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" @@ -546,15 +545,14 @@ const MDCTStereoBands_config mdctStereoBands_32000_640[] = {33, 29, 26, 18}/*number of bands for frame lengths 480, 320, 256, 160 respectively*/ }}; -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG const Word16 mdct_stereo_dtx_coherence_bandlengths[MDCT_ST_DTX_NUM_COHERENCE_BANDS] = { 6, /* 8 - MDCT_ST_DTX_FIRST_BAND_OFFSET */ 8, 16, 16, 80 }; + /* dequantization table for coherence */ const Word16 get_next_index_4_by_15[16] = { 0, 2184, 4369, 6553, 8738, 10922, 13107, 15291, 17476, 19660, 21845, 24029, 26214, 28398, 30583, 32767 }; -#endif const Word16 dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */ @@ -2100,7 +2098,7 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_64k, &ivas_param_mc_ild_mapping_CICP14_2tc, &ivas_param_mc_icc_mapping_CICP14_2tc, - &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], + &ivas_param_mc_ild_fac_CICP14_2tc_fx[0], &ivas_param_mc_dmx_fac_CICP14_2tc_fx[0] }, /* CICP14 80000 */ @@ -2122,7 +2120,7 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_96k, &ivas_param_mc_ild_mapping_CICP14_3tc, &ivas_param_mc_icc_mapping_CICP14_3tc, - &ivas_param_mc_ild_fac_CICP14_3tc_fx[0], + &ivas_param_mc_ild_fac_CICP14_3tc_fx[0], &ivas_param_mc_dmx_fac_CICP14_3tc_fx[0] }, /* CICP16 96000 */ @@ -2135,7 +2133,7 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = &ivas_param_mc_icc_mapping_CICP16_3tc, &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], &ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] - }, + }, /* CICP16 128000 */ { MC_LS_SETUP_5_1_4, @@ -2144,9 +2142,9 @@ const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS] = IVAS_128k, &ivas_param_mc_ild_mapping_CICP16_3tc, &ivas_param_mc_icc_mapping_CICP16_3tc, - &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], + &ivas_param_mc_ild_fac_CICP16_3tc_fx[0], &ivas_param_mc_dmx_fac_CICP16_3tc_fx[0] - }, + }, /* CICP19 128000 */ { MC_LS_SETUP_7_1_4, @@ -3069,30 +3067,30 @@ const Word16 nf_tw_smoothing_coeffs_fx[N_LTP_GAIN_MEMS] = const Word16 dft_trigo_12k8_fx[STEREO_DFT_N_12k8_ENC / 4 + 1] = { - 0, 402, 804, 1206, 1607, 2009, 2410, 2811, 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, 9512, 9896, 10278, 10659, - 11039, 11416, 11793, 12167, 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, 18204, 18537, 18868, - 19195, 19519, 19841, 20159, 20475, 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, 25330, 25583, - 25832, 26077, 26319, 26557, 26790, 27020, 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, 30273, - 30425, 30572, 30714, 30852, 30985, 31114, 31237, 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, - 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765, 32767 + 0, 402, 804, 1206, 1607, 2009, 2410, 2811, 3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997, 6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126, 9512, 9896, 10278, 10659, + 11039, 11416, 11793, 12167, 12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090, 15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869, 18204, 18537, 18868, + 19195, 19519, 19841, 20159, 20475, 20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884, 23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073, 25330, 25583, + 25832, 26077, 26319, 26557, 26790, 27020, 27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707, 28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117, 30273, + 30425, 30572, 30714, 30852, 30985, 31114, 31237, 31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057, 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, + 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765, 32767 }; const Word16 dft_trigo_32k_fx[STEREO_DFT_N_32k_ENC / 4 + 1] = { - 0, 160, 321, 482, 643, 804, 964, 1125, 1286, 1447, 1607, 1768, 1929, 2089, 2250, 2410, 2570, 2731, 2891, 3051, 3211, 3371, 3531, 3691, 3851, 4011, 4170, 4330, 4489, - 4648, 4808, 4967, 5126, 5284, 5443, 5602, 5760, 5918, 6076, 6234, 6392, 6550, 6707, 6865, 7022, 7179, 7336, 7493, 7649, 7805, 7961, 8117, 8273, 8429, 8584, 8739, - 8894, 9049, 9203, 9358, 9512, 9665, 9819, 9972, 10125, 10278, 10431, 10583, 10735, 10887, 11039, 11190, 11341, 11492, 11642, 11793, 11942, 12092, 12241, 12391, - 12539, 12688, 12836, 12984, 13131, 13278, 13425, 13572, 13718, 13864, 14010, 14155, 14300, 14444, 14589, 14732, 14876, 15019, 15162, 15304, 15446, 15588, 15729, - 15870, 16011, 16151, 16291, 16430, 16569, 16707, 16846, 16983, 17121, 17258, 17394, 17530, 17666, 17801, 17936, 18070, 18204, 18338, 18471, 18604, 18736, 18868, - 18999, 19130, 19260, 19390, 19519, 19648, 19777, 19905, 20032, 20159, 20286, 20412, 20538, 20663, 20787, 20911, 21035, 21158, 21281, 21403, 21524, 21645, 21766, - 21886, 22005, 22124, 22242, 22360, 22478, 22594, 22711, 22826, 22941, 23056, 23170, 23283, 23396, 23509, 23620, 23732, 23842, 23952, 24062, 24171, 24279, 24387, - 24494, 24600, 24706, 24812, 24916, 25021, 25124, 25227, 25330, 25431, 25532, 25633, 25733, 25832, 25931, 26029, 26126, 26223, 26319, 26415, 26509, 26604, 26697, - 26790, 26882, 26974, 27065, 27155, 27245, 27334, 27423, 27510, 27597, 27684, 27769, 27854, 27939, 28023, 28106, 28188, 28270, 28351, 28431, 28511, 28589, 28668, - 28745, 28822, 28898, 28974, 29049, 29123, 29196, 29269, 29341, 29412, 29482, 29552, 29621, 29690, 29758, 29825, 29891, 29956, 30021, 30085, 30149, 30211, 30273, - 30334, 30395, 30455, 30514, 30572, 30629, 30686, 30742, 30797, 30852, 30906, 30959, 31011, 31063, 31114, 31164, 31213, 31262, 31309, 31357, 31403, 31448, 31493, - 31537, 31581, 31623, 31665, 31706, 31746, 31785, 31824, 31862, 31899, 31936, 31971, 32006, 32040, 32074, 32106, 32138, 32169, 32199, 32229, 32257, 32285, 32312, - 32339, 32364, 32389, 32413, 32436, 32458, 32480, 32501, 32521, 32540, 32559, 32577, 32594, 32610, 32625, 32640, 32653, 32666, 32679, 32690, 32701, 32711, 32720, - 32728, 32736, 32742, 32748, 32753, 32758, 32761, 32764, 32766, 32767, 32767 + 0, 160, 321, 482, 643, 804, 964, 1125, 1286, 1447, 1607, 1768, 1929, 2089, 2250, 2410, 2570, 2731, 2891, 3051, 3211, 3371, 3531, 3691, 3851, 4011, 4170, 4330, 4489, + 4648, 4808, 4967, 5126, 5284, 5443, 5602, 5760, 5918, 6076, 6234, 6392, 6550, 6707, 6865, 7022, 7179, 7336, 7493, 7649, 7805, 7961, 8117, 8273, 8429, 8584, 8739, + 8894, 9049, 9203, 9358, 9512, 9665, 9819, 9972, 10125, 10278, 10431, 10583, 10735, 10887, 11039, 11190, 11341, 11492, 11642, 11793, 11942, 12092, 12241, 12391, + 12539, 12688, 12836, 12984, 13131, 13278, 13425, 13572, 13718, 13864, 14010, 14155, 14300, 14444, 14589, 14732, 14876, 15019, 15162, 15304, 15446, 15588, 15729, + 15870, 16011, 16151, 16291, 16430, 16569, 16707, 16846, 16983, 17121, 17258, 17394, 17530, 17666, 17801, 17936, 18070, 18204, 18338, 18471, 18604, 18736, 18868, + 18999, 19130, 19260, 19390, 19519, 19648, 19777, 19905, 20032, 20159, 20286, 20412, 20538, 20663, 20787, 20911, 21035, 21158, 21281, 21403, 21524, 21645, 21766, + 21886, 22005, 22124, 22242, 22360, 22478, 22594, 22711, 22826, 22941, 23056, 23170, 23283, 23396, 23509, 23620, 23732, 23842, 23952, 24062, 24171, 24279, 24387, + 24494, 24600, 24706, 24812, 24916, 25021, 25124, 25227, 25330, 25431, 25532, 25633, 25733, 25832, 25931, 26029, 26126, 26223, 26319, 26415, 26509, 26604, 26697, + 26790, 26882, 26974, 27065, 27155, 27245, 27334, 27423, 27510, 27597, 27684, 27769, 27854, 27939, 28023, 28106, 28188, 28270, 28351, 28431, 28511, 28589, 28668, + 28745, 28822, 28898, 28974, 29049, 29123, 29196, 29269, 29341, 29412, 29482, 29552, 29621, 29690, 29758, 29825, 29891, 29956, 30021, 30085, 30149, 30211, 30273, + 30334, 30395, 30455, 30514, 30572, 30629, 30686, 30742, 30797, 30852, 30906, 30959, 31011, 31063, 31114, 31164, 31213, 31262, 31309, 31357, 31403, 31448, 31493, + 31537, 31581, 31623, 31665, 31706, 31746, 31785, 31824, 31862, 31899, 31936, 31971, 32006, 32040, 32074, 32106, 32138, 32169, 32199, 32229, 32257, 32285, 32312, + 32339, 32364, 32389, 32413, 32436, 32458, 32480, 32501, 32521, 32540, 32559, 32577, 32594, 32610, 32625, 32640, 32653, 32666, 32679, 32690, 32701, 32711, 32720, + 32728, 32736, 32742, 32748, 32753, 32758, 32761, 32764, 32766, 32767, 32767 }; const Word16 dft_trigo_48k_fx[STEREO_DFT_N_MAX_ENC / 4 + 1] = @@ -4416,12 +4414,10 @@ const Word32 delta_theta_masa_fx[NO_SPHERICAL_GRIDS - 2] = { 188743680, 188743680, 150994944, 106954752, 83886080, 62914560, 45214596, 28101836, 20971520 }; -#ifdef OBJ_EDIT_BASOP // Q31 const Word32 delta_theta_masa_inv_fx[NO_SPHERICAL_GRIDS - 2] = { 47721859, 47721859, 59652324, 84215045, 107374182, 143165577, 199209986, 320519947, 429496730 }; -#endif // q = 14 const Word16 coherence_cb0_masa_Q14[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH] = { @@ -4671,7 +4667,7 @@ const Word16 ivas_lpf_4_butter_32k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { }; const Word32 ivas_lpf_4_butter_48k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - // 6, 11, 6, 1073741824, /* Q30 */ + // 6, 11, 6, 1073741824, /* Q30 */ 1477520448, 1477520448, 1477520448, 1073741824, -2113939767, 1040504054, 1073741824, 2147483480, 1073741829, 1073741824, -2133281237, 1059848324 diff --git a/lib_com/ivas_rotation_com_fx.c b/lib_com/ivas_rotation_com_fx.c index d399c6a660e352ebd6ad625d8d13753c88d432a0..27fdfb5a062fcc8b10ff8e74320957a31f1969b8 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,11 @@ void modify_Quat_q_fx( Word16 q_new /* i : quaternion describing the rotation */ ) { - 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 + 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 out_quat->q_fact = q_new; return; } @@ -141,12 +148,13 @@ void modify_Rmat_q_fx( ) { Word16 j, k; + Word16 shift = sub( q_new, q_cur ); FOR( j = 0; j < 3; j++ ) { FOR( k = 0; k < 3; k++ ) { - Rmat_out[j][k] = L_shl( Rmat_in[j][k], sub( q_new, q_cur ) ); + Rmat_out[j][k] = L_shl( Rmat_in[j][k], shift ); move32(); } } @@ -194,7 +202,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 515a10cdb1195b2259ad19591e195199e13ba508..753c3ae296d58ece183562f08f139bc9bd288bc3 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 @@ -117,8 +121,8 @@ void mvc2c( /*! r: number of clipped samples */ UWord32 ivas_syn_output_fx( - Word32 *synth[], /* i/o: float synthesis signal q_synth*/ - const Word16 q_synth, + Word32 *synth[], /* i/o: synthesis signal q_synth*/ + const Word16 q_synth, /* i : Q factor */ const Word16 output_frame, /* i : output frame length (one channel) Q0*/ const Word16 n_channels, /* i : number of output channels Q0*/ Word16 *synth_out /* o : integer 16 bits synthesis signal Q0*/ @@ -131,7 +135,7 @@ UWord32 ivas_syn_output_fx( move32(); /*-----------------------------------------------------------------* - * float to integer conversion with saturation control + * Word32 to Word16 conversion with saturation control *-----------------------------------------------------------------*/ FOR( n = 0; n < n_channels; n++ ) @@ -149,7 +153,6 @@ UWord32 ivas_syn_output_fx( return noClipping; /*Q0*/ } -#ifdef JBM_MEMORY_OPT /*-------------------------------------------------------------------* * ivas_buffer_interleaved_to_deinterleaved() @@ -158,30 +161,31 @@ UWord32 ivas_syn_output_fx( *-------------------------------------------------------------------*/ 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) */ + 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 offset, ch, m; - Word32 buffer[MAX_TRANSPORT_CHANNELS][MAX_JBM_L_FRAME48k]; + 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( m = 0; m < frame_length; m++ ) + FOR( s = 0; s < frame_length; s++ ) { - buffer[ch][m] = audio[m * n_channels + ch]; + buffer[ch][s] = audio_in[s * n_channels + ch]; move32(); } } - offset = 0; - move16(); FOR( ch = 0; ch < n_channels; ch++ ) { - Copy32( buffer[ch], audio + offset, frame_length ); - offset = add( offset, n_samp_full ); + FOR( s = 0; s < frame_length; s++ ) + { + audio_out[ch][s] = buffer[ch][s]; + move32(); + } } return; @@ -195,75 +199,36 @@ void ivas_buffer_interleaved_to_deinterleaved_fx( *-------------------------------------------------------------------*/ void ivas_buffer_deinterleaved_to_interleaved_fx( - Word32 *audio[], /* i/o: 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 */ + 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, m; -#ifdef FIX_1330_JBM_MEMORY - Word32 buffer[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; /* temp buffer needed when "*audio[]" and "*audio_out[]" are the same */ + 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++ ) { - Copy32( audio[ch], buffer[ch], frame_length ); - } -#endif - - - FOR( ch = 0; ch < n_channels; ch++ ) - { - FOR( m = 0; m < frame_length; m++ ) + FOR( s = 0; s < frame_length; s++ ) { -#ifdef FIX_1330_JBM_MEMORY - audio_out[m * n_channels + ch] = buffer[ch][m]; -#else - audio_out[m * n_channels + ch] = audio[ch][m]; -#endif + buffer[ch][s] = audio_in[ch][s]; move32(); } } - return; -} - -#else - -/*-------------------------------------------------------------------* - * ivas_syn_output_f() - * - * Output ivas synthesis signal with compensation for saturation - * returns number of clipped samples - *-------------------------------------------------------------------*/ - -/*! r: number of clipped samples */ -void ivas_syn_output_f_fx( - Word32 *synth[], /* i/o: float synthesis signal Q11*/ - const Word16 output_frame, /* i : output frame length (one channel) Q0*/ - const Word16 n_channels, /* i : number of output channels Q0*/ - Word32 *synth_out /* o : integer 16 bits synthesis signal Q11*/ -) -{ - Word16 i, n; - - /*-----------------------------------------------------------------* - * float to integer conversion with saturation control - *-----------------------------------------------------------------*/ - - FOR( n = 0; n < n_channels; n++ ) + FOR( ch = 0; ch < n_channels; ch++ ) { - FOR( i = 0; i < output_frame; i++ ) + FOR( s = 0; s < frame_length; s++ ) { - synth_out[( ( i * n_channels ) + n )] = synth[n][i]; /*Q11*/ - move16(); + audio_out[s * n_channels + ch] = buffer[ch][s]; + move32(); } } return; } -#endif /*-------------------------------------------------------------------* * mvr2r_inc() @@ -644,7 +609,7 @@ void v_mult_mat_fx( pt_y++; } - MVR2R_WORD32( tmp_y, y, Nc ); /*Qx - guardbits*/ + Copy32( tmp_y, y, Nc ); /*Qx - guardbits*/ } @@ -1992,26 +1957,6 @@ void lls_interp_n_fx( } -/* helper function for panning_wrap_angles */ -static float wrap_azi( - const float azi_deg ) -{ - float azi = azi_deg; - - /* Wrap azimuth value */ - while ( azi > 180 ) - { - azi -= 360.0f; - } - - while ( azi <= -180 ) - { - azi += 360; - } - - return azi; -} - /* helper function for panning_wrap_angles */ static Word32 wrap_azi_fx( const Word32 azi_deg /* Q22 */ ) @@ -2034,76 +1979,6 @@ static Word32 wrap_azi_fx( } -/*-------------------------------------------------------------------* - * panning_wrap_angles() - * - * Wrap angles for amplitude panning to the range: - * azimuth = (-180, 180] - * elevation = [-90, 90] - * Considers direction changes from large elevation values - *-------------------------------------------------------------------*/ - -void panning_wrap_angles( - const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - float *azi_wrapped, /* o : wrapped azimuth component */ - float *ele_wrapped /* o : wrapped elevation component */ -) -{ - float azi, ele; - - azi = azi_deg; - ele = ele_deg; - - if ( fabsf( ele ) < 90 ) - { - *ele_wrapped = ele; - *azi_wrapped = wrap_azi( azi ); - return; - } - else - { - /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ - if ( ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) - { - *azi_wrapped = 0; - while ( ele > 90 ) - { - ele -= 360; - } - while ( ele < -90 ) - { - ele += 360; - } - *ele_wrapped = ele; - } - else - { - /* Wrap elevation and adjust azimuth accordingly */ - while ( fabsf( ele ) > 90 ) - { - /* Flip to other hemisphere */ - azi += 180; - - /* Compensate elevation accordingly */ - if ( ele > 90 ) - { - ele = 180 - ele; - } - else if ( ele < -90 ) - { - ele = -180 - ele; - } - } - *azi_wrapped = wrap_azi( azi ); - *ele_wrapped = ele; - } - - return; - } -} - - /*-------------------------------------------------------------------* * panning_wrap_angles_fx() * @@ -2184,7 +2059,7 @@ void panning_wrap_angles_fx( /*-------------------------------------------------------------------------* * v_sort_ind_fixed() * - * Sort a float array + * Sort a Word32 array * (modified version of v_sort() to return an index array) *-------------------------------------------------------------------------*/ @@ -2635,8 +2510,8 @@ Word16 ceil_log_2( Word64 var_32_fx( const Word32 *x, /* i : input vector q*/ - const Word16 len, /* i : length of inputvector Q0*/ - Word16 q /* q : q-factor for the array */ + const Word16 len, /* i : length of inputvector Q0*/ + Word16 q /* q : q-factor for the array */ ) { Word16 i; 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 fd203805baabbe835078cf1125729b97e1ee6e04..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/lerp_fx.c b/lib_com/lerp_fx.c index e35814b12b18064be9cfbc9d996509398609833d..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/limit_t0_fx.c b/lib_com/limit_t0_fx.c index d3cff10d9733e7170b05ce287534cbfa63406be2..61eea907d538b486f3adf8c3222c0a395b1f17cf 100644 --- a/lib_com/limit_t0_fx.c +++ b/lib_com/limit_t0_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/log2.c b/lib_com/log2.c index 3df1a960ec4728e537d09f4aaa9a8eb0a13e1d32..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 ); @@ -127,10 +136,8 @@ Word32 pow_10( Word32 x, Word16 *Q ) /*o : Q15, i: Q26*/ Word32 L_tmp; Word16 n1, i; Word16 count = 0; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif move16(); 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 5983c11f8a7730be0ecb9eb469831d04f8fff361..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index f0fbf9bd67327f65120c8506261167690e7a75e6..8e7cef9d13cd272662af48fb8ae20b4ab37eb8b8 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index a5aee205d0d15c8c7dd833ce858cc9749881d56a..dafb07d1de8ef4ec2637d1a5aa3348705b69bfcd 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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -446,12 +446,18 @@ static Word32 Div_32_opt( Word32 L_num /*Q31*/, Word16 denom_hi /*Qx -16*/, Word * Returns: * void */ -Word16 E_LPC_lev_dur( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/ ) -{ - return ( E_LPC_lev_dur_stab( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ -} -Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/, Word16 k_max /*Q15*/ ) +static Word16 E_LPC_lev_dur_stab( +#ifdef HARM_LEV_DURBIN + const Word16 element_mode, +#endif + const Word16 Rh[] /*QR -16*/, + const Word16 Rl[] /*QR -1*/, + Word16 A[] /*Qx*/, + Word32 epsP[] /*QR*/, + const Word16 order, + Word16 *mem /*Qx*/, + Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -608,7 +614,19 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR t0 = L_Comp( Ah[i], Al[i] ); t1 = L_max( t1, L_abs( t0 ) ); } + +#ifdef HARM_LEV_DURBIN + IF( element_mode == EVS_MONO ) + { + k = s_min( norm_l( t1 ), 3 ); + } + ELSE + { + k = s_min( sub( norm_l( t1 ), 1 ), 3 ); + } +#else k = s_min( norm_l( t1 ), 3 ); +#endif A[0] = shl( 2048, k ); move16(); FOR( i = 1; i <= order; i++ ) @@ -632,16 +650,20 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR } } - return ( flag ); } -Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) +Word16 E_LPC_lev_dur_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/ ) { - return ( E_LPC_lev_dur_stab_ivas_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +#ifdef HARM_LEV_DURBIN + return ( E_LPC_lev_dur_stab( EVS_MONO, Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +#else + return ( E_LPC_lev_dur_stab( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +#endif } -Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max ) +#ifndef HARM_LEV_DURBIN +static Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max ) { Word16 i, j, k; Word16 hi, lo; @@ -822,16 +844,27 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 } } - return ( flag ); } - -Word16 E_LPC_lev_dur_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/ ) +#endif +Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) { - return ( E_LPC_lev_dur_stab_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +#ifdef HARM_LEV_DURBIN + return ( E_LPC_lev_dur_stab( IVAS_SCE /* just to differentiate from EVS_MONO */, Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +#else + return ( E_LPC_lev_dur_stab_ivas_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +#endif } -Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/, Word16 k_max /*Q15*/ ) + +static Word16 E_LPC_lev_dur_stab_fx_32( + const Word16 Rh[] /*QR -16*/, + const Word16 Rl[] /*QR -1*/, + Word32 A[] /*QA*/, + Word32 epsP[] /*QR*/, + const Word16 order, + Word32 *mem /*QA*/, + Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -965,7 +998,6 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* lo = L_Extract_lc( t0, &hi ); /* DPF format */ t0 = Mpy_32( alp_h, alp_l, hi, lo ); /* Alpha in Q31 */ - /* store denormalized alpha in epsP */ t1 = L_shr( t0, alp_exp ); if ( epsP != NULL ) @@ -1012,10 +1044,14 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* } } - return ( flag ); } +Word16 E_LPC_lev_dur_fx_32( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/ ) +{ + return ( E_LPC_lev_dur_stab_fx_32( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +} + /* * E_LPC_a_add_tilt diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index 33de5d9ac09d01ac656426a142cbec602cb610c9..491802f6be544fd1891f4105ca6e80ae2bd7e2da 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_com/lsf_msvq_ma_fx.c b/lib_com/lsf_msvq_ma_fx.c index 6f8ea44c2866d7d545400846520d544efc8415ed..d705177fc3591440db44305e2d8f179f84b9d6d4 100644 --- a/lib_com/lsf_msvq_ma_fx.c +++ b/lib_com/lsf_msvq_ma_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 0fbc7f7586c164b6b838b95dfc9d58c6ca6198de..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 @@ -354,9 +354,7 @@ void E_LPC_f_isp_a_conversion( const Word16 *isp, Word16 *a, const Word16 m ) Word32 f1[NC_MAX + 1], f2[NC_MAX + 1]; /* Q23 */ Word16 nc, q; Word32 t0, tmax, t0p, t0n; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif /*-----------------------------------------------------* @@ -777,9 +775,7 @@ void lsp2lpc_fx( Word16 tmp_pci[M + 1]; Word16 giOverflow; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif FOR( i = 0; i < order; i++ ) { @@ -956,10 +952,8 @@ Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 n, cons Word16 Q_out; Word16 m2; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); -#endif Q_out = 31 - 23; move16(); @@ -2969,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 */ @@ -3196,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/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index e9b4a559b8ebee99b86abef60ea53dd8fbae1fbc..834f7b0aab8566467ad90cc849fa69bf28bf0846 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -105,6 +105,7 @@ Word16 lsp_convert_poly_fx( powerspect_fx( grid50_fx, N50, R, S, G, DOWNCONV ); spectautocorr_fx( grid40_fx, N40, G, rh, rl ); } + /*---------------------------------------------------------------------* * Conversion from 12.8 kHz up to 16.0 kHz. * Compute the power spectrum of the LP filter, extrapolate the @@ -125,14 +126,13 @@ Word16 lsp_convert_poly_fx( spectautocorr_fx( grid50_fx, N50, G, rh, rl ); } - /*---------------------------------------------------------------------* * Compute the linear prediction coefficients from the autocorrelation * and convert to line spectrum pairs. *---------------------------------------------------------------------*/ - flag = E_LPC_lev_dur( rh, rl, A, epsP, M, oldA ); - E_LPC_a_lsp_conversion( A, w, stable_LSP_fx, M ); + flag = E_LPC_lev_dur_fx( rh, rl, A, epsP, M, oldA ); + E_LPC_a_lsp_conversion( A, w, stable_LSP_fx, M ); return ( flag ); } diff --git a/lib_com/math_op.h b/lib_com/math_op.h index 0e5fa825b534627dca3e462ab5a38d645ffcecca..d4eca9f2bad2b0664c9fec0e26f7896c22a887e2 100644 --- a/lib_com/math_op.h +++ b/lib_com/math_op.h @@ -1,5 +1,5 @@ /*--------------------------------------------------------------------------* - * MATH_OP.H * + * MATH_OP.H * *--------------------------------------------------------------------------* * Mathematical operations * *--------------------------------------------------------------------------*/ diff --git a/lib_com/mime.h b/lib_com/mime.h index 5a6eb8fee6fa6d13cc0b0d558ad994cc63542ccf..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef MIME_H #define MIME_H diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 6bd1e7a699ffd2d697a0c496939321f67864bcef..9335d26b6588ee4a64108e18a6c9f01e5ba2d2cc 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1,9 +1,8 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include -#include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "prot_fx.h" @@ -43,7 +42,12 @@ /* CALLED FROM : TX/RX */ /*==============================================================================*/ -Word16 modify_Fs_ivas_fx( /* o : length of output Q0 */ +#ifndef FIX_2410_HARM_MODIF_FS +Word16 modify_Fs_ivas_fx( /* o : length of output Q0 */ +#else +/* o : length of output Q0 */ +Word16 modify_Fs_fx( +#endif const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ Word16 lg, /* i : length of input Q0 */ const Word32 fin, /* i : frequency of input Q0 */ @@ -56,7 +60,6 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q ) { Word16 i; - Word16 lg_out, fac_num, fac_den, filt_len, frac, temp_n, mem_len; Word16 num_den; Word16 datastep, fracstep; @@ -80,17 +83,28 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q /*-------------------------------------------------------------------* * Find the resampling configuration *-------------------------------------------------------------------*/ - *Q_new_inp = 0; - move16(); + +#ifdef FIX_2410_HARM_MODIF_FS + if ( Q_new_inp != NULL ) +#endif + { + *Q_new_inp = 0; + move16(); + } /* check if fin and fout are the same */ IF( EQ_32( fin, fout ) ) { /* just copy the signal_fx and quit */ Copy( sigIn_fx, sigOut_fx, lg ); - *mem_decim_size = 0; - *Q_new_inp = 0; - move16(); - move16(); +#ifdef FIX_2410_HARM_MODIF_FS + if ( Q_new_inp != NULL ) +#endif + { + *mem_decim_size = 0; + *Q_new_inp = 0; + move16(); + move16(); + } return lg; } ELSE @@ -124,6 +138,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q /*-------------------------------------------------------------------* * Retrieve and/or calculate the resampling parameters *-------------------------------------------------------------------*/ + fac_num = cfg_ptr_fx->fac_num_fx; move16(); /*Q0*/ fac_den = cfg_ptr_fx->fac_den_fx; @@ -147,18 +162,23 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q } mem_len = shl( filt_len, 1 ); - *mem_decim_size = mem_len; - move16(); +#ifdef FIX_2410_HARM_MODIF_FS + if ( mem_decim_size != NULL ) +#endif + { + *mem_decim_size = mem_len; + move16(); + } signal_fx = signal_tab_fx + 2 * L_FILT_MAX + sub( L_FRAME48k, add( mem_len, lg ) ); signal_ana_fx = signal_fx; mem_len_ana = mem_len; move16(); } - /*-------------------------------------------------------------------* * Resample *-------------------------------------------------------------------*/ + /* append filter memory */ Copy( mem_fx, signal_fx, mem_len ); @@ -169,7 +189,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 +201,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, @@ -198,7 +215,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q /* Levinson-Durbin */ set16_fx( mem_lev_fx, 0, 18 ); - E_LPC_lev_dur( r_fx_h, r_fx_l, A_fx, LepsP, M, NULL ); + E_LPC_lev_dur_fx( r_fx_h, r_fx_l, A_fx, LepsP, M, NULL ); Copy_Scale_sig( A_fx, A_fx, M + 1, sub( norm_s( A_fx[0] ), 2 ) ); @@ -214,6 +231,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q move16(); deemph_fx( signal_fx + mem_len + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS + plus_sample_in, &mem_preemph_fx ); } + /* interpolation */ datastep = shr( div_s( shl( fac_den, 7 ), shl( fac_num, 10 ) ), 12 ); @@ -229,8 +247,12 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q { filt_len_tmp = shr( add( filt_len, 1 ), 1 ); } - - Word16 norm_cfg_ptr = norm_s( sub( cfg_ptr_fx->filter_fx[0], 1 ) ); +#ifdef FIX_2410_HARM_MODIF_FS + if ( Q_new_inp != NULL ) +#endif + { + *Q_new_inp = negate( norm_s( sub( cfg_ptr_fx->filter_fx[0], 1 ) ) ); + } FOR( i = 0; i < lg_out; i++ ) { sigOut_fx[i] = round_fx_sat( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); @@ -244,7 +266,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q } sigIn_ptr += add( lshr( j, 15 ), datastep ); } - *Q_new_inp = negate( norm_cfg_ptr ); + move16(); /* rescaling */ test(); @@ -263,8 +285,13 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q sigOut_fx[i] = round_fx( L_shl( L_mult( sigOut_fx[i], num_den ), 1 ) ); /*Q0*/ move16(); } - *Q_new_inp = add( *Q_new_inp, 1 ); - move16(); +#ifdef FIX_2410_HARM_MODIF_FS + if ( Q_new_inp != NULL ) +#endif + { + *Q_new_inp = add( *Q_new_inp, 1 ); + move16(); + } } ELSE { @@ -274,8 +301,13 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q IF( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { num_den = shl_sat( num_den, 1 ); - *Q_new_inp = add( *Q_new_inp, 1 ); - move16(); +#ifdef FIX_2410_HARM_MODIF_FS + if ( Q_new_inp != NULL ) +#endif + { + *Q_new_inp = add( *Q_new_inp, 1 ); + move16(); + } } FOR( i = 0; i < lg_out; i++ ) { @@ -304,8 +336,13 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q sigOut_fx[i] = round_fx( L_mac( L_deposit_h( sigOut_fx[i] ), sigOut_fx[i], num_den ) ); /*Q0*/ move16(); } - *Q_new_inp = add( *Q_new_inp, 1 ); - move16(); +#ifdef FIX_2410_HARM_MODIF_FS + if ( Q_new_inp != NULL ) +#endif + { + *Q_new_inp = add( *Q_new_inp, 1 ); + move16(); + } } } } @@ -323,7 +360,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q return lg_out; } - +#ifndef FIX_2410_HARM_MODIF_FS Word16 modify_Fs_fx( /* o : length of output Q0 */ const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ Word16 lg, /* i : length of input Q0 */ @@ -450,7 +487,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 +499,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, @@ -479,7 +513,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /* Levinson-Durbin */ set16_fx( mem_lev_fx, 0, 18 ); - E_LPC_lev_dur( r_fx_h, r_fx_l, A_fx, LepsP, M, NULL ); + E_LPC_lev_dur_fx( r_fx_h, r_fx_l, A_fx, LepsP, M, NULL ); Copy_Scale_sig( A_fx, A_fx, M + 1, sub( norm_s( A_fx[0] ), 2 ) ); @@ -548,11 +582,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ test(); if ( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { -#ifdef BASOP_NOGLOB_DECLARE_LOCAL num_den = shl_sat( num_den, 1 ); -#else - num_den = shl( num_den, 1 ); -#endif } FOR( i = 0; i < lg_out; i++ ) { @@ -596,6 +626,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ return lg_out; } +#endif + /*-------------------------------------------------------------------* * modify_Fs_intcub3m_sup() @@ -603,13 +635,14 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ * *-------------------------------------------------------------------*/ -Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ - const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ - const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ - const Word32 fin, /* i : frequency of input */ - Word16 sigOut[], /* o : decimated signal */ - const Word32 fout, /* i : frequency of output */ - Word16 *delayout /* o : delay of output */ +/* o : length of output */ +Word16 modify_Fs_intcub3m_sup_fx( + const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ + const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ + const Word32 fin, /* i : frequency of input */ + Word16 sigOut[], /* o : decimated signal */ + const Word32 fout, /* i : frequency of output */ + Word16 *delayout /* o : delay of output */ ) { Word16 i, k, i1, i2, k1, k2, k3, kk, cind; 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 7079c9e030df7443584fb1d169442571f052f2d7..a4ae563aa5b8ac06778cd63f1da2b11f727eec9d 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 @@ -31,130 +31,81 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef OPTIONS_H #define OPTIONS_H /* clang-format off */ + /* ################### Start compiler switches ######################## */ + +#define SUPPORT_JBM_TRACEFILE /* support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ + +/* #################### End compiler switches ######################### */ + /* ################### Start DEBUGGING switches ######################## */ -/*#define DEBUGGING*/ /* Allows debugging message to be printed out during runtime */ +#ifndef RELEASE +/*#define DEBUGGING*/ /* Activate debugging part of the code */ +#endif +/*#define WMOPS*/ /* Activate complexity and memory counters */ +/*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ +/*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ +/*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ +/*define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ + #ifdef DEBUGGING -/*#define DBG_BITSTREAM_ANALYSIS*/ /* Write bitstream with annotations to a text file */ -#define DEBUG_MODE_INFO /* Define to output most important parameters to the subdirectory "res/" */ -#define DEBUG_MODE_INFO_TWEAK /* Enable command line switch to specify subdirectory for debug info output inside "./res/" */ -#define DEBUG_FORCE_MDCT_STEREO_MODE /* Force stereo mode decision for MDCT stereo: -stereo 3 1 forces L/R coding and -stereo 3 2 forces full M/S coding */ -/*#define DEBUG_FORCE_DIR*/ /* Force modes/parameters by reading from external binary files */ -/*#define DBG_WAV_WRITER*/ /* Enable dbgwrite_wav() function for generating ".wav" files */ -#define SUPPORT_FORCE_TCX10_TCX20 /* VA: Enable -force tcx10|tcx20 command-line option */ +/*#define DBG_BITSTREAM_ANALYSIS*/ /* Write bitstream with annotations to a text file */ +#define DEBUG_MODE_INFO /* Define to output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO_TWEAK /* Enable command line switch to specify subdirectory for debug info output inside "./res/" */ +#define DEBUG_FORCE_MDCT_STEREO_MODE /* Force stereo mode decision for MDCT stereo: -stereo 3 1 forces L/R coding and -stereo 3 2 forces full M/S coding */ +/*#define DEBUG_FORCE_DIR*/ /* Force modes/parameters by reading from external binary files */ +/*#define DBG_WAV_WRITER*/ /* Enable dbgwrite_wav() function for generating ".wav" files */ +#define SUPPORT_FORCE_TCX10_TCX20 /* VA: Enable -force tcx10|tcx20 command-line option */ /*#define DEBUG_MODE_JBM */ /* define to output JBM relevant parameters */ -#endif +/*#define DEBUG_APA_SILENCE_NON_SCALED*/ /* Switch APA into mode that replaces contents of non-scaled frames with silence. Useful for identifying scaled regions in the audio output of the decoder */ -#define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ +#endif /* DEBUGGING */ -/*#define WMOPS*/ /* Activate complexity and memory counters */ -#ifdef WMOPS -#define WMOPS_PER_FRAME /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ -#define WMOPS_DETAIL /* Output detailed complexity printout for every function. Increases runtime overhead */ -#define WMOPS_WC_FRAME_ANALYSIS /* Output detailed complexity analysis for the worst-case frame */ -/*define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ -#endif +/* #################### End DEBUGGING switches ############################ */ +/* keep as part of options.h */ /*#define DISABLE_LIMITER*/ -/*#define DEBUG_APA_SILENCE_NON_SCALED*/ /* Switch APA into mode that replaces contents of non-scaled frames with silence. Useful for identifying scaled regions in the audio output of the decoder */ -/* #################### End DEBUGGING switches ############################ */ +/* ################### Start MAINTENANCE switches ########################### */ -#ifndef BASOP_NOGLOB_DEV_USE_GLOBALS -#define BASOP_NOGLOB_DECLARE_LOCAL -#endif +/* ################### Start BE switches ################################# */ +/* only BE switches wrt wrt. TS 26.251 V3.0 */ -/* ################### Start FIXES switches ########################### */ -#define REMOVE_BASOP_Util_Divide3232_Scale_cadence /* remove this division variant */ -#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 TEMP_FIX_2088_MSAN_INIT_ERROR /* Eri: Temporary fix for Issue 2088 - MSAN error. Will come with later port of JBM+Split rendering update */ -#define FIX_2092_ASSERT_IN_OMASA_RENDER /* FhG, Nokia: Fix LTV crash due to overflow in OMASA EXT output */ -#define FIX_2084_FLOATING_POINT_LEFTOVERS /* FhG: convert floating-point leftovers in IVAS_ENC_FeedObjectMetadata() */ -#define FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING /* FhG: Replace L_shl with L_shl_sat to prevent overflow when calculating scale factors for very small numbers in the logarithmic domain */ -#define FIX_APA_EXECS_SCALING /* VA: fix scaling of JBM APA buffer */ -#define FIX_2164_ASSERT_IN_OMASA_PREPROC_FOR_EDIT /* Nokia: Issue 2164: Prevent overflow when calculating equalization coefficient for editing before clamping to safe range */ -#define FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC /* FhG: fix for issue 2165 - using saturating addition in tonal MDCT PLC function */ -#define OPT_2146_BASOP_UTIL_ADD_MANT32EXP /* Dlb: optimized version of BASOP_Util_Add_Mant32Exp() */ -#define FIX_2166_ASSERT_OSBA_PLC_STEREO_OUT /* FhG: fix for issue 2166 - add missing averaging factor 0.5 in for the sum of energies in function stereo_dft_dmx_swb_nrg_fx()*/ -#define FIX_2086_ENABLE_HP20_OPT_FOR_ENC /* FhG: Enable hp20_fx_32_opt() for Encoder */ -#define FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE /* FhG: Use dynamic Q factor for synth_fx and synthFB_fx to prevent overflow */ -#define FIX_2170_ASSERT_IN_FFT3 /* Eri: Assert in fft3_fx from EVS, adding _sat */ -#define FIX_2082_FP_LEFTOVERS_OMASA_DEC /* Nokia: fix for issue 2082, cleaning remaining floating point code */ -#define FIX_2174_JBM_BASOP_ALIGNMENT /* VoiceAge, Nokia: Fixes to JBM BASOP implementation and alignment to float */ - -#define FIX_2176_ASSERT_DEC_MAP_PARAMS_DIRAC2STEREO /* FhG: Reduce hStereoDft->q_smooth_buf_fx by one to prevent overflow in the subframe_band_nrg[][] calculation */ -#define FIX_2015_PREMPH_SAT_ALT /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor, allows preemphis to get 1 more bit headroom */ -#define FIX_2178_FL_TO_FX_WITH_OBJ_EDIT_FILE_INTERFACE /* Nokia: Fixes float to fx conversion in decoder app with object edit file interface */ -#define FIX_2070_JBM_TC_CHANNEL_RESCALING_ISSUE /* Eri/Orange: scale_sig32 problem on p_tc_fx[] */ - -#define FIX_2173_UBSAN_IN_JBM_PCMDSP_APA /* FhG: Fix UBSAN problems in jbm_pcmdsp_apa_fx.c */ -#define FIX_1947_DEC_HIGH_MLD_FOR_STEREO2MONO /* FhG: Make Q-factor of synth_16_fx and output_16_fx dynamic to prevent overflow in HQ_CORE mode */ - -#define FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING /* Orange: Fix for issue 2184 - to prevent one channel from becoming inaudible in the mono downmix output */ -#define FIX_2148_OBJ_EDIT_ISSUE_WITH_OSBA /* Nokia: Add missing code to solve issue */ +/*#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 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_FLOAT_1522_LTV_MSAN_QMETADATA_ENC_EC3 /* Nokia: float issue 1522: fix uninit MSAN in EC3 of qmetadata encoding */ +#define OPT_2416_ACELP_FAST /* VA: basop issue 2426, optimisation of acelp_fast_fx ( reduc. compl. by 0.35 wmops ) */ +#define FIX_2410_HARM_MODIF_FS /* VA: basop issue 2410: Remove duplicated modif_Fs */ +#define FIX_2425_REMOVE_RC_DUPLICATES /* VA: basop issue 2425: Remove duplicated RC encoder functions */ +#define HARM_LEV_DURBIN /* VA: basop issue 2423: harmonize levinson-Durbin algorithm */ +#define HARMONIZE_TBE2 /* VA: basop issue 2399: Remove duplicated code: TBE, step 2 */ +#define HARM_FD_BWE /* VA: harmonize core-coder FD BWE function duplications */ +#define FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT /* FhG: basop issue 2411: harmonize TNSAnalysis*_fx(), DetectTnsFilt*_fx()*/ +#define HARMONIZE_READ_DECODE_TNS /* FhG basop 2389: Harm between two pairs of functions. */ #define FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT /* FhG: remove unreachable code in ivas_osba_stereo_add_channels */ +/* #################### End BE switches ################################## */ + +/* #################### Start NON-BE switches ############################ */ +/* any switch which is non-be wrt. TS 26.251 V3.0 */ + + /* ################### End FIXES switches ########################### */ -/* #################### Start BASOP porting switches ############################ */ - -#define NONBE_1244_FIX_SWB_BWE_MEMORY /* VA: issue 1244: fix to SWB BWE memory in case of switching from FB coding - pending a review by Huawei */ -#define NONBE_1302_FIX_OMASA_JBM_FLUSH /* VA: issue 1302: fix OMASA JBM bitrate switching flush in binaural output */ -#define NONBE_1328_FIX_NON_LINEARITY /* VA: Fix possible issue when computing bwe_exc_extended and previous frame were almost 0, float issue 1328 */ -#define FIX_1319_STACK_SBA_DECODER /* VA: issue 1319: Optimize the definition of buffer lengths in the SBA decoder */ -#define FIX_1320_STACK_CPE_DECODER /* VA: issue 1320: Optimize the stack memory consumption in the CPE decoder */ -#define NONBE_FIX_1376_MDCT_CONCEALMENT /* FhG: fix concealment artifact in MDCT Stereo with DTX, in case transition frame gets lost */ -#define NONBE_1377_REND_DIRATT_CONF /* Eri: Issue 1377: Error in directivity attenuation configuration for both IVAS_dec and IVAS_rend */ -#define FIX_1377_HANDLE_ERROR_CODE /* Eri: Add missing error code handling from IVAS_REND_SetObjectIDs */ -#define FIX_1053_REVERB_RECONFIGURATION -#define FIX_1119_SPLIT_RENDERING_VOIP /* FhG: Add split rendering support to decoder in VoIP mode */ -#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_938_COMPILER_WARNING /* FhG: Fix compiler warning in ivas_mdct_core_reconstruct() */ -#define FIX_1376_MISSING_ISM_METADATA /* FhG: IVAS_rend: throw error if there exists an ISM input without a corresponding metadata file path */ -#define FIX_1385_INIT_IGF_STOP_FREQ /* FhG: Initialize infoIGFStopFreq in init_igf_dec() */ -#define FIX_1387_INIT_PRM_SQQ /* FhG: initialize pointer prm_sqQ, which might be uninitialized in case of bfi == 1 */ -#define FIX_1349_TNS_CRASH /* FhG: Fix crash in TNS entropy coding, in case order of joint TNS coding is reduced to 0 */ -#define FIX_1384_MSAN_stereo_tcx_core_enc /* VA: issue 1384: fix use-of-uninitialized value in stereo_tcx_core_enc() */ -#define FIX_1384_MSAN_ivas_spar_dec_open /* VA: issue 1386: fix use-of-uninitialized value in ivas_spar_dec_open() */ -#define FIX_1388_MSAN_ivas_init_decoder /* VA: issue 1388: fix use-of-uninitialized value in ivas_init_decoder() */ -#define FIX_1288_SPLIT_REND_XSAN /* Dlb: Fix asan, msan and usan issues in split rendering mode*/ -#define FIX_NCHAN_BUFFERS /* VA: issue 1322: Correct the number of float buffers (channels) at the decoder */ -#define FIX_RENDERER_STACK /* VA: issue 1322: reduction of renderers' buffers size */ -#define JBM_MEMORY_OPT /* VA: issue 916: optimization of RAM in the JBM decoder */ -#define NONBE_1324_TC_BUFFER_MEMOERY_KEEP /* VA: issue 1324: do not reset TSM memory in JBM bitrate switching */ -#define FIX_1370_EXTERNAL_ORIENTATION_CHECK /* Nokia: add sanity check for Euler angles for external orientations */ -#define FIX_1413_IGF_INIT_PRINTOUT /* FhG: use correct variable for IGF initiliazation */ -#define CODE_IMPROVEMENTS -#define NONBE_1359_FIX_IVASREND_OMASA_BINAURAL_LOUDNESS /* Nokia: issue 1339: Apply scaling to the object-part of OMASA for binaural rendering in IVAS_rend. */ -#define NONBE_1362_FIX_OMASA_TO_MASA1_RENDERING /* Nokia: Fix OMASA to MASA1 rendering in IVAS_rend */ -#define FIX_1383_HEAD_TRACK_SANITIZER /* Nok: issue 1383: Fix head tracking struc values reading in renderer */ -#define FIX_1330_JBM_MEMORY /* VA: issue 1330: memory savings in the JBM decoder */ -#define FIX_1330_JBM_MEMORY_FIX /* VA: basop issue: 2179 fix non-BE difference in FIX_1330_JBM_MEMORY */ -#define FIX_1411_IGF_CRASH_BW_SWITCHING /* FhG: Fix for issue 1411: fixes crash that can happen for IGF with BW switching and DTX*/ -#define NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* FhG: Fix MDCT-Stereo comfort noise for certain noise types */ -#define NONBE_1344_REND_MASA_LOW_FS /* Nokia: Issue 1344: Fix sanitizer errors when using IVAS_rend to render MASA with lower sampling rates */ -#define NONBE_1412_AVOID_ROUNDING_AZ_ELEV /* FhG: Avoid rounding when passing azimuth and elevation to efap_determine_gains() */ - -// object-editing feature porting -#define TMP_FIX_SPLIT_REND // temporary fix to split-rendering (it follows the later state of the framework but it is needed now because of current test-conditions) -#define TMP_FIX_OMASA_SR_BE // temporary fix to keep OMASA split-rendering BE -#define NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES // Nokia: Fix 1399_1400 issue in float, this is essential for the BASOP porting -#define OBJ_EDIT_BASOP -#define FIX_1372_OSBA_OBJECT_EDITING /* VA: issue 1372: Fix OSBA object-editing in BINAURAL_ROOM_IR */ -#define FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES /* Nokia: Issue 2140, fixes three different sanitizer issues persisting in object editing code. */ -#define NONBE_FIX_1172_OBJ_EDIT_JBM /* VA: issue 1172: fix OMASA object editing in JBM */ -#define FIX_2193_ISM_GAINS_WITH_OE /* FhG: fix issue 2193: use edited angles in ISM gain calculation */ - -/* #################### End BASOP porting switches ############################ */ +/* ##################### End NON-BE switches ########################### */ + +/* ################## End MAINTENANCE switches ######################### */ + +/* clang-format on */ #endif diff --git a/lib_com/parameter_bitmaping_fx.c b/lib_com/parameter_bitmaping_fx.c index 92387209012c8cd2dfd7a6bacdb30ab3903715ad..5a2f8ccfe640147dd4798ff6246940ac0a119ee9 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 ) { @@ -246,12 +228,21 @@ void SetParameters_fx( IF( s_and( param->pSubParamBitMap != NULL, value > 0 ) ) { pTmp = pParameter; +#ifdef HARMONIZE_READ_DECODE_TNS if ( pSubStruct != NULL ) + { pTmp = pSubStruct; + } +#else + if ( pSubStruct != NULL ) + pTmp = pSubStruct; +#endif SetParameters( param->pSubParamBitMap, value, pTmp, pStream, pnSize ); } } } + + return; } @@ -266,13 +257,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 +310,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 +382,9 @@ void ReadFromBitstream_fx( } } } + move16(); *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) ); + + return; } diff --git a/lib_com/phase_dispersion_fx.c b/lib_com/phase_dispersion_fx.c index ce4f70e5a5c98944957ecbbc0f8f785090a471fb..5269a2ca36e4defac60158d95054df3ebe361e7b 100644 --- a/lib_com/phase_dispersion_fx.c +++ b/lib_com/phase_dispersion_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c index c0824124977b34308ef68a814d6496bfd3b1f771..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 @@ -41,7 +41,7 @@ /* PURPOSE : Interpolate pitch lag for a subframe */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (Word16) last_fx: previous frame delay, Q0 */ +/* _ (Word16) last_fx: previous frame delay, Q0 */ /* _ (Word16) current_fx: current frame delay, Q0 */ /* _ (Word16) SubNum : subframe number */ /*-------------------------------------------------------------------*/ diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index 869edfd1b89911da958ad63bdbed4235353d4690..b04456870275c50cc5f02f259d093d6f1c991319 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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; } @@ -152,7 +151,7 @@ void pred_lt4( /* _ (Word16 []) exc : output excitation buffer Q0 */ /*-----------------------------------------------------------------------*/ /* INPUT OUTPUT ARGUMENTS */ -/* NONE */ +/* NONE */ /*-----------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* NONE */ diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index e8dfb4018b74af83d82724af75a021350913c13e..46c8ccc36b531cab8b599c1b576afde3c3b97a33 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -8,17 +8,16 @@ #include "wmc_auto.h" /*-------------------------------------------------------------* - * preemph_copy_fx() + * preemph_fx() * * Preemphasis: filtering through 1 - mu z^-1 *-------------------------------------------------------------*/ -void preemph_copy_fx( - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : 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_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; @@ -28,10 +27,11 @@ void preemph_copy_fx( FOR( i = lg - 1; i > 0; i-- ) { - y[i] = msu_r_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx */ + x[i] = msu_r_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx */ move16(); } - y[0] = msu_r_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx */ + + x[0] = msu_r_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx */ move16(); *mem = temp; /* Qx */ @@ -39,10 +39,16 @@ void preemph_copy_fx( return; } -#ifndef FIX_2015_PREMPH_SAT_ALT -void preemph_copy_32fx( + +/*-------------------------------------------------------------* + * preemph_copy_fx() + * + * Preemphasis + copy: filtering through 1 - mu z^-1 + *-------------------------------------------------------------*/ + +void preemph_copy_fx( const Word16 x[], /* i : input signal Qx */ - Word32 y[], /* o : output signal Qx */ + Word16 y[], /* o : 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 */ @@ -55,10 +61,10 @@ void preemph_copy_32fx( FOR( i = lg - 1; i > 0; i-- ) { - y[i] = L_msu_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx+16 */ + y[i] = msu_r_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx */ move16(); } - y[0] = L_msu_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx+16 */ + y[0] = msu_r_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx */ move16(); *mem = temp; /* Qx */ @@ -66,7 +72,7 @@ void preemph_copy_32fx( return; } -#else + void preemph_copy_32fx2( const Word16 x[], /* i : input signal Qx */ Word32 y[], /* o : output signal Qx-1*/ @@ -93,7 +99,7 @@ void preemph_copy_32fx2( return; } -#endif + /*-------------------------------------------------------------* * preemph_ivas_fx() * @@ -131,8 +137,8 @@ void preemph_ivas_fx( * * Parameters: * shift I: scale output - * signal I/O: signal Qx/Qx+shift - * mu I: preemphasis factor Q15 + * signal I/O: signal Qx/Qx+shift + * mu I: preemphasis factor Q15 * L I: vector size * mem I/O: memory (x[-1]) * diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 2f0e059ec47a8ab08e886c3e103f9031a6261beb..49e042e2db19e255f9c8204595d6a34082816bba 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,83 +75,22 @@ u__p = x; \ x = y; \ y = u__p; \ + move32(); \ + move32(); \ + move32(); \ } #endif -/*================================================================================*/ -/* conversion functions: */ -/*================================================================================*/ - -// Float to Word32 -Word32 float_to_fix( float number, Word32 Q ); -// Word32 to Float -float fix_to_float( Word32 number, Word32 Q ); -// Float to Word16 -Word16 float_to_fix16( float number, Word16 Q ); -// Word16 to Float -float fix16_to_float( Word16 number, Word16 Q ); - -Word16 float_to_fix16_thrld( float number, Word16 Q ); - -void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l ); -void floatToFixed_arr( float *f, Word16 *i, Word16 Q, Word16 l ); -void fixedToFloat_arrL( Word32 *i, float *f, Word16 Q, Word16 l ); -void fixedToFloat_arr( Word16 *i, float *f, Word16 Q, Word16 l ); -void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l ); -void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l ); -Word16 Q_factor( float x ); -Word16 Q_factor_L( float x ); -Word16 Q_factor_arr( float *x, Word16 l ); -Word16 Q_factor_arrL( float *x, Word16 l ); -Word16 Q_factor_L_32( Word32 x ); -// Handles the cases where Q is negative -Word32 floatToFixed( float f, Word16 Q ); -float fixedToFloat( Word32 i, Word16 Q ); -Word32 floatToFixed_32( float f, Word16 Q ); -float fixedToFloat_32( Word32 i, Word16 Q ); -float fixedToFloat_16( Word16 i, Word16 Q ); - -void floatToFixed_arr16( float *f, Word16 *i, Word16 Q, Word16 l ); -void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l ); -// Float to 32-bit Mantissa and Exponent using frexp -void f2me( float n, Word32 *mantissa, Word16 *expo ); -// 32-bit Mantissa and Exponent to Float using ldexp -float me2f( Word32 m, Word16 expo ); -// Float to 32-bit Mantissa Array and Exponent -void f2me_buf( const float *x, Word32 *m, Word16 *e, const Word32 n ); -// 32-bit Mantissa Array and Exponent to Float -void me2f_buf( const Word32 *m, const Word16 e, float *out, const Word32 n ); -// Float to 16-bit Mantissa and Exponent using frexp -void f2me_16( float n, Word16 *mantissa, Word16 *expo ); -// 16-bit Mantissa and Exponent to Float using ldexp -float me2f_16( Word16 m, Word16 expo ); -// Float to 16-bit Mantissa Array and Exponent -void f2me_buf_16( const float *x, Word16 *m, Word16 *e, const Word32 n ); -// 16-bit Mantissa Array and Exponent to Float -void me2f_buf_16( const Word16 *m, const Word16 e, float *out, const Word32 n ); - -void f2fix_16( float *var_flt, Word16 *var_fix, Word32 expo ); -void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo ); -void f2fix( float *var_flt, Word32 *var_fix, Word32 expo ); -void fix2f( Word32 *var_fix, float *var_flt, Word32 expo ); - -// Get max Q factor for a float value before sat in 32-bit -Word16 L_get_q( float f ); -Word16 L_get_q1( float f ); -// Get max Q factor for a float buffer before sat in 32-bit -Word16 L_get_q_buf( float *ptr_flt, Word16 length ); -Word16 L_get_q_buf1( float *ptr_flt, Word16 length ); - -/*================================================================================*/ -/* conversion functions: */ -/*================================================================================*/ + +/*----------------------------------------------------------------------------------* + * Prototypes of tools + *----------------------------------------------------------------------------------*/ Word32 sum_l_fx( const Word32 *vec, /* i : input vector */ const Word16 lvec /* i : length of input vector */ ); - Word32 Mult_32_16( Word32 a, Word16 b ); @@ -215,13 +130,11 @@ void set32_fx( const Word16 N /* i : Lenght of the vector */ ); -// tools.c /* o : output random value */ Word16 Random( Word16 *seed /* i/o: random seed */ ); -// tools.c void Copy( const Word16 x[], /* i : i vector */ Word16 y[], /* o : output vector */ @@ -404,6 +317,13 @@ Word32 calc_tilt_bwe_fx( const Word16 N /* i : signal length */ ); +/* o : Tilt in Q24 */ +Word16 calc_tilt_bwe_fx_32( + const Word32 *sp, /* i : i signal */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ +); + void calc_norm_envelop_fx( const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ Word32 *envelope, /* o : normalized envelope Q_syn*/ @@ -412,6 +332,14 @@ void calc_norm_envelop_fx( const Word16 st_offset /* i : offset */ ); +void calc_norm_envelop_fx_32( + const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ + Word32 *envelope_fx, /* o : normalized envelope : Q16 */ + const Word16 L_swb_norm, /* i : length of envelope : Q0 */ + const Word16 SWB_flength, /* i : Length of i /output : Q0 */ + const Word16 st_offset /* i : offset : Q0 */ +); + void WB_BWE_decoding_fx( const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ Word16 *WB_fenv, /* i : WB frequency envelopes */ @@ -452,6 +380,9 @@ void SWB_BWE_decoding_fx( ); void time_envelop_shaping_fx( +#ifdef HARM_FD_BWE + const Word16 element_mode, /* i : element mode */ +#endif Word16 werr[], /* i/o: SHB synthesis Q_synth*/ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ const Word16 L, /* i : frame length */ @@ -465,14 +396,6 @@ void time_reduce_pre_echo_fx( Word16 Q_syn, Word16 Q_synth ); -void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of i /output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ -); - void hq_generic_decoding_fx( const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ @@ -993,27 +916,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 */ @@ -1260,7 +1162,7 @@ void autocorr_fx_32( const Word16 sym_flag /* i : symmetric window flag */ ); -Word16 E_LPC_lev_dur( +Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], @@ -1268,15 +1170,6 @@ Word16 E_LPC_lev_dur( const Word16 order, Word16 *parcorr ); -Word16 E_LPC_lev_dur_stab( - const Word16 Rh[], - const Word16 Rl[], - Word16 A[], - Word32 epsP[], - const Word16 order, - Word16 *parcorr, - Word16 k_max ); - Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], @@ -1285,16 +1178,7 @@ Word16 E_LPC_lev_dur_ivas_fx( const Word16 order, Word16 *parcorr ); -Word16 E_LPC_lev_dur_stab_ivas_fx( - const Word16 Rh[], - const Word16 Rl[], - Word16 A[], - Word32 epsP[], - const Word16 order, - Word16 *parcorr, - Word16 k_max ); - -Word16 E_LPC_lev_dur_fx( +Word16 E_LPC_lev_dur_fx_32( const Word16 Rh[], const Word16 Rl[], Word32 A[], @@ -1302,15 +1186,6 @@ Word16 E_LPC_lev_dur_fx( const Word16 order, Word32 *mem ); -Word16 E_LPC_lev_dur_stab_fx( - const Word16 Rh[], - const Word16 Rl[], - Word32 A[], - Word32 epsP[], - const Word16 order, - Word32 *mem, - Word16 k_max ); - Word16 lev_dur_fx( Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ @@ -1612,28 +1487,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 */ @@ -1728,17 +1583,7 @@ void int_lsp_fx( void int_lsp4_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 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_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 */ @@ -1824,51 +1669,37 @@ 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 ); + const Word16 Eflag, + const Word16 L_frame /* i : frame length */ +); 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 */ + 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 */ const Word16 L_frame /* i : frame length */ ); -void Comp_and_apply_gain_fx( - 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 Comp_and_apply_gain_fx( + 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 */ + const Word16 Flag_adj_q_exc, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ Word16 Qexc_diff, Word16 Q_exc ); -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 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 Qexc_diff, - Word16 *Q_exc ); - 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 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*/ -); - -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*/ - 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*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/, + const Word16 element_mode /* i : Current IVAS element mode*/ ); void tcx_get_windows_mode1( @@ -2262,7 +2093,7 @@ void hq2_bit_alloc_har_fx( Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ @@ -2331,19 +2162,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 */ @@ -2383,31 +2201,31 @@ void spt_shorten_domain_pre_fx( ); void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband Q0*/ - const Word16 band_start[], /* i: starting position of subband Q0*/ - const Word16 band_end[], /* i: end position of subband Q0*/ - const Word16 band_width[], /* i: band width of subband Q0*/ - Word16 org_band_start[], /* o: starting position of subband Q0*/ - Word16 org_band_end[], /* o: end position of subband Q0*/ - Word16 org_band_width[] /* o: band width of subband Q0*/ + const Word16 bands, /* i: total subband Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + const Word16 band_width[], /* i: band width of subband Q0*/ + Word16 org_band_start[], /* o: starting position of subband Q0*/ + Word16 org_band_end[], /* o: end position of subband Q0*/ + Word16 org_band_width[] /* o: band width of subband Q0*/ ); void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband Q0*/ - Word16 band_start[], /* i/o: starting position of subband Q0*/ - Word16 band_end[], /* i/o: end position of subband Q0*/ - Word16 band_width[], /* i/o: band width of subband Q0*/ - const Word16 org_band_start[], /* o: starting position of subband Q0*/ - const Word16 org_band_end[], /* o: end position of subband Q0*/ - const Word16 org_band_width[] /* o: band width of subband Q0*/ + const Word16 bands, /* i: total subband Q0*/ + Word16 band_start[], /* i/o: starting position of subband Q0*/ + Word16 band_end[], /* i/o: end position of subband Q0*/ + Word16 band_width[], /* i/o: band width of subband Q0*/ + const Word16 org_band_start[], /* o: starting position of subband Q0*/ + const Word16 org_band_end[], /* o: end position of subband Q0*/ + const Word16 org_band_width[] /* o: band width of subband Q0*/ ); void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information Qx*/ - const Word16 bands, /* i: total number of bands Q0*/ - const Word16 band_start[], /* i: starting position of subband Q0*/ - const Word16 band_end[], /* i: end position of subband Q0*/ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ + const Word32 L_y2[], /* i: coded spectral information Qx*/ + const Word16 bands, /* i: total number of bands Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ ); void bit_allocation_second_fx( @@ -2620,18 +2438,23 @@ Word32 Interpol_lc_fx( ); /* o : length of output Q0 */ -Word16 modify_Fs_ivas_fx( - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ - Word16 *Q_new_inp, /*scaling added on sigOut_fx */ - Word16 *mem_decim_size /*i: size modified for mem_fx*/ -); - +#ifndef FIX_2410_HARM_MODIF_FS +Word16 modify_Fs_ivas_fx( /* o : length of output Q0 */ +#else +Word16 modify_Fs_fx( /* o : length of output Q0 */ +#endif + const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ + Word16 lg, /* i : length of input Q0 */ + const Word32 fin, /* i : frequency of input Q0 */ + Word16 sigOut_fx[], /* o : decimated signal Q0 */ + const Word32 fout, /* i : frequency of output Q0 */ + Word16 mem_fx[], /* i/o: filter memory Q0 */ + const Word16 nblp, /* i : flag indicating if NB low-pass is applied */ + Word16 *Q_new_inp, /*scaling added on sigOut_fx */ + Word16 *mem_decim_size /*i: size modified for mem_fx*/ +); + +#ifndef FIX_2410_HARM_MODIF_FS /* o : length of output Q0 */ Word16 modify_Fs_fx( const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ @@ -2642,7 +2465,7 @@ Word16 modify_Fs_fx( Word16 mem_fx[], /* i/o: filter memory Q0 */ const Word16 nblp /* i : flag indicating if NB low-pass is applied */ ); - +#endif /* o : length of output */ Word16 modify_Fs_intcub3m_sup_fx( const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ @@ -2752,13 +2575,13 @@ 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 ) ) -#ifndef FIX_2015_PREMPH_SAT_ALT -#define PREEMPH_32FX( signal, signal_out, mu, L, mem ) preemph_copy_32fx( ( signal ), ( signal_out ), ( mu ), ( L ), ( mem ) ) -#else -#define PREEMPH_32FX( signal, signal_out, mu, L, mem ) preemph_copy_32fx2( ( signal ), ( signal_out ), ( mu ), ( L ), ( mem ) ) -#endif +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 */ Word16 y[], /* o : output signal Qx */ @@ -2767,15 +2590,6 @@ void preemph_copy_fx( Word16 *mem /* i/o: memory (x[-1]) Qx */ ); -#ifndef FIX_2015_PREMPH_SAT_ALT -void preemph_copy_32fx( - const Word16 x[], /* i : i signal Qx */ - Word32 y[], /* o : 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 */ -); -#else void preemph_copy_32fx2( const Word16 x[], /* i : i signal Qx */ Word32 y[], /* o : output signal Qx */ @@ -2783,7 +2597,6 @@ void preemph_copy_32fx2( const Word16 lg, /* i : vector size Q0 */ Word16 *mem /* i/o: memory (x[-1]) Qx */ ); -#endif void E_UTIL_f_preemph2( Word16 shift, /* Q0 */ @@ -2809,83 +2622,7 @@ Word16 E_UTIL_f_preemph3_ivas_fx( Word16 bits /* Q0 */ ); -Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */ - Word16 Q_syn, - Word16 last_extl_fx, - Word16 tilt_wb_fx ); - -void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : i signal */ - const Word16 mode, /* i : i mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - Word16 Q_syn ); - -/* o : Tilt in Q24 */ -Word16 ivas_calc_tilt_bwe_fx( - const Word32 *sp, /* i : i signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ -); - -void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of i /output */ - const Word16 st_offset /* i : offset */ -); - -void WB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of i /output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ -); - -void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of i /output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl, /* i : extension layer */ - Word16 Q_syn, - const Word16 last_extl /* i : extension layer of last frame */ -); - +#ifndef HARM_FD_BWE void time_envelop_shaping_fx( Word16 werr[], /* i/o: SHB synthesis Q_synth*/ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ @@ -2893,55 +2630,14 @@ void time_envelop_shaping_fx( Word16 *Q_synth ); void time_envelop_shaping_ivas_fx( +#ifdef HARM_FD_BWE + const Word16 element_mode, /* i : element mode */ +#endif Word16 werr[], /* i/o: SHB synthesis Q_synth*/ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ const Word16 L, /* i : frame length */ Word16 *Q_synth ); - -void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth ); - -void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : i signal : Q12 */ - const Word16 mode, /* i : i mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ -); - -void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of i /output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ -); - -void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R ); - -void save_old_syn_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 syn[], /* i : ACELP synthesis */ - Word16 old_syn[], /* o : old synthesis buffer */ - Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ - const Word16 preemph_fac, /* i : preemphasis factor */ - Word16 *mem_deemph /* i/o: deemphasis filter memory */ -); - +#endif void find_td_envelope_fx( const Word16 inp[], /* i : input signal Qx */ const Word16 len, /* i : length of the input signal */ @@ -2977,16 +2673,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 */ @@ -3014,11 +2701,6 @@ void Calc_rc0_h( Word16 *rc0 /* o : 1st parcor */ ); -void Calc_rc0_h_ivas_enc_fx( - Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ -); - void PostShortTerm_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -3053,15 +2735,16 @@ 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 */ ); void GenShapedWBExcitation_fx( +#ifndef HARMONIZE_TBE2 Word16 *excSHB, /* o : synthesized shaped shb exctiation */ const Word16 *lpc_shb, /* i : lpc coefficients */ Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation */ @@ -3071,67 +2754,94 @@ 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 ); +void GenShapedWBExcitation_ivas_fx( +#endif + 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 */ +); + 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 ); +#ifdef HARMONIZE_TBE2 +void GenShapedSHBExcitation_ivas_fx( + const Word16 enc_dec, /* i : encoder/decoder flag */ +#else 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 */ +#endif + 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] */ @@ -3160,6 +2870,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ ); +#ifndef HARMONIZE_TBE2 void GenShapedSHBExcitation_ivas_dec_fx( Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ @@ -3201,7 +2912,7 @@ void GenShapedSHBExcitation_ivas_dec_fx( Word16 *Env_error, /* o : error in SHB residual envelope modelling*/ Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */ ); - +#endif void GenSHBSynth_fx( const Word16 *shb_target_speech, /* i : i synthesized speech */ Word16 *shb_syn_speech_32k, /* o : output highband component */ @@ -3243,41 +2954,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( @@ -3314,9 +3015,9 @@ void synthesise_fb_high_band_fx( Word16 Q_fb_exc, Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ const Word32 fb_exc_energy, /* i : full band excitation energy */ - const Word16 ratio, /* i : energy ratio */ + const Word16 ratio, /* i : energy ratio */ const Word16 L_frame, /* i : ACELP frame length */ - const Word16 bfi, /* i : fec flag */ + const Word16 bfi, /* i : fec flag */ Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ Word16 bpf_memory_Q[], @@ -3374,9 +3075,9 @@ Word16 shrtCDivSignedApprox( ); void obtainEnergyQuantizerDensity_fx( - const Word16 L, /* i : left vector energy Q0*/ - const Word16 R, /* i : right vector energy Q0*/ - Word16 *Density /* o : quantizer density Q0*/ + const Word16 L, /* i : left vector energy Q0*/ + const Word16 R, /* i : right vector energy Q0*/ + Word16 *Density /* o : quantizer density Q0*/ ); void dsDirac2Dirac_fx( @@ -3385,11 +3086,11 @@ void dsDirac2Dirac_fx( ); void dsDiracPerQuanta_fx( - const Word16 td, /* i : Length of vector segment Q0*/ - const Word16 t_quanta, /* i : Assigned number of quanta Q0*/ - const Word16 dsm, /* i : Conservative rounding flag Q0*/ - const unsigned char *const *frQuanta, /* i : Quanta lookup table */ - Word16 *DsIdx /* o : Lookup table index Q0*/ + const Word16 td, /* i : Length of vector segment Q0*/ + const Word16 t_quanta, /* i : Assigned number of quanta Q0*/ + const Word16 dsm, /* i : Conservative rounding flag Q0*/ + const unsigned char *const *frQuanta, /* i : Quanta lookup table */ + Word16 *DsIdx /* o : Lookup table index Q0*/ ); void QuantaPerDsDirac_fx( @@ -3427,20 +3128,20 @@ void bandBitsAdjustment_fx( ); void densityAngle2RmsProjDec_fx( - const Word16 D, /* i : density Q0*/ - const Word16 indexphi, /* i : decoded index from AR dec Q0*/ - Word16 *oppQ15, /* o : opposite Q15*/ - Word16 *nearQ15, /* o : near Q15*/ - Word16 *oppRatioQ3 /* o : ratio Q3*/ + const Word16 D, /* i : density Q0*/ + const Word16 indexphi, /* i : decoded index from AR dec Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ); void densityAngle2RmsProjEnc_fx( - const Word16 D, /* i : density Q0*/ - const Word16 phiQ14uq, /* i : angle Q14*/ - Word16 *indexphi, /* o : index Q0*/ - Word16 *oppQ15, /* o : opposite Q15*/ - Word16 *nearQ15, /* o : near Q15*/ - Word16 *oppRatioQ3 /* o : ratio Q3*/ + const Word16 D, /* i : density Q0*/ + const Word16 phiQ14uq, /* i : angle Q14*/ + Word16 *indexphi, /* o : index Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ); void NearOppSplitAdjustment_fx( @@ -3458,7 +3159,7 @@ void NearOppSplitAdjustment_fx( Word16 oppRQ3, /* i : ratio Q0*/ Word16 *qnear, /* o : quantized near Q0*/ Word16 *qopp, /* o : quantized opposite Q0*/ - Word16 *qglobalupd /* o : quanta remaining Q0*/ + Word16 *qglobalupd /* o : quanta remaining Q0*/ ); void apply_gain_fx( @@ -3467,7 +3168,7 @@ void apply_gain_fx( const Word16 *band_end, /* i : Sub band end indices Q0 */ const Word16 num_sfm, /* i : Number of bands Q0 */ const Word16 *gains, /* i : Band gain vector Q12 */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ + Word16 *xq /* i/o: synthesis / Gain adjusted synth Q15/Q12 */ ); void fine_gain_quant_fx( @@ -3480,9 +3181,9 @@ void fine_gain_quant_fx( ); void srt_vec_ind16_fx( - const Word16 *linear, /* linear input Q3*/ - Word16 *srt, /* sorted output Q3*/ - Word16 *I, /* index for sorted output Q0*/ + const Word16 *linear, /* linear input Q3*/ + Word16 *srt, /* sorted output Q3*/ + Word16 *I, /* index for sorted output Q0*/ Word16 length /* Q0 */ ); @@ -3492,16 +3193,16 @@ Word16 atan2_fx( const Word32 x /* i : opposite side (Q15) */ ); -/* o: Number of bits needed Q0*/ +/* o: Number of bits needed Q0*/ Word16 rc_get_bits2_fx( - const Word16 N, /* i: Number of bits currently used Q0*/ - const UWord32 range /* i: Range of range coder Q0*/ + const Word16 N, /* i: Number of bits currently used Q0*/ + const UWord32 range /* i: Range of range coder Q0*/ ); void rangeCoderFinalizationFBits_fx( - Word16 Brc, /* i : Current number of decoded bits Q0*/ - UWord32 INTrc, /* i : Range coder state Q0*/ - Word16 *FBits /* i : Fractional finalization bits Q0*/ + Word16 Brc, /* i : Current number of decoded bits Q0*/ + UWord32 INTrc, /* i : Range coder state Q0*/ + Word16 *FBits /* i : Fractional finalization bits Q0*/ ); ivas_error DTFS_new_fx( @@ -3713,16 +3414,8 @@ Word32 DTFS_getEngy_band_wb_fx( Word16 lband, Word16 hband ); -void InitTnsConfiguration( - const Word16 bwidth, - const Word16 frameLength, - STnsConfig *pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ); -void InitTnsConfiguration_ivas_fx( +void InitTnsConfiguration_fx( const Word16 bwidth, const Word16 frameLength, STnsConfig *pTnsConfig, @@ -3835,7 +3528,7 @@ gp_clips_fx.c /========================================================================================================*/ void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + Word16 mem[] /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ ); Word16 gp_clip_fx( @@ -3858,10 +3551,10 @@ void gp_clip_test_isf_fx( ); void gp_clip_test_gain_pit_fx( - const Word16 element_mode, /* i : element mode Q0*/ - const Word32 core_brate, /* i : core bitrate Q0*/ - const Word16 gain_pit, /* i : gain of quantized pitch Q14*/ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14*/ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 gain_pit, /* i : gain of quantized pitch Q14*/ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14*/ ); Word16 Mode2_gp_clip_fx( @@ -3881,71 +3574,39 @@ Word16 Mode2_gp_clip_fx( ); void gp_clip_test_lsf_fx( - const Word16 element_mode, /* i : element mode Q0*/ - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28*/ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ - const Word16 m /* i : dimension of lsf Q0*/ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 m /* i : dimension of lsf Q0*/ ); void gp_clip_test_lsf_ivas_fx( const Word16 element_mode, /* i : element mode Q0*/ - const Word32 core_brate, /* i : core bitrate Q0*/ - const Word16 lsf[], /* i : LSF vector 14Q1*1.28*/ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ -); - -/*========================================================================================================/ -nelp_enc_fx.c -/========================================================================================================*/ - -void quantize_uvg_fx( - Word16 *G, - Word16 *iG1, - Word16 *iG2, - Word16 *quantG, - Word16 bandwidth ); - -void nelp_encoder_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 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 */ - 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 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 lsf[], /* i : LSF vector 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ); -void swb_bwe_enc_lr_ivas_fx( +/*========================================================================================================/ +nelp_enc_fx.c +/========================================================================================================*/ + +void quantize_uvg_fx( + Word16 *G, + Word16 *iG1, + Word16 *iG2, + Word16 *quantG, + Word16 bandwidth ); + +void nelp_encoder_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 */ Word16 QsL, @@ -4103,44 +3764,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 */ @@ -4156,8 +3790,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( @@ -4426,16 +4060,8 @@ void tcx_noise_filling_with_shift( const Word16 element_mode /* i : IVAS element mode */ ); -void InitTnsConfigs( - 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 InitTnsConfigs_ivas_fx( +void InitTnsConfigs_fx( const Word16 bwidth, const Word16 L_frame, STnsConfig tnsConfig[2][2], @@ -4800,21 +4426,19 @@ void cldfbSynthesis_fx( ); void configureCldfb( - HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ - const Word16 no_channels, /*!< Number of critically sampled bands */ - const Word16 frameSize /*!< FrameSize */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: Returns handle */ + const Word32 sampling_rate /* i : sampling rate */ ); ivas_error openCldfb( - HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: Returns handle */ + const Word16 type, /* i : analysis or synthesis */ + const Word32 sampling_rate /* i : sampling rate */ ); void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, /*!< CLDFB Handle */ - const Word16 newCldfbBands, /*!< number of cldfb bands */ + const Word32 sampling_rate, /* i : sampling rate */ const Word16 frameSize, /*!< FrameSize */ const Word8 firstFrame ); @@ -4852,9 +4476,6 @@ void GetEnergyCldfb( Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ TEC_ENC_HANDLE hTECEnc ); -Word16 CLDFB_getNumChannels( - Word32 sampleRate ); - void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ); /*!< CLDFB Handle */ @@ -4910,19 +4531,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 */ @@ -5072,7 +4682,7 @@ void fine_gain_pred_fx( ); void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *ord, /* i : Indices for energy order Q0 */ const Word16 num_sfm, /* i : Number of bands Q0 */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ @@ -5119,38 +4729,6 @@ void freq_dnw_scaling_fx( ); 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 */ -); - -void highband_exc_dct_in_ivas_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 */ @@ -5415,23 +4993,10 @@ void SynthesisSTFT_ivas_fx( const Word16 nchan_out /* i : number of output channels */ ); -void mhvals( - const Word16 d, - Word16 *m /*, float * h*/ -); - 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 ); @@ -5508,10 +5073,10 @@ void Inverse_Transform( ); void recovernorm_fx( - const Word16 *idxbuf, /* i : reordered quantization indices Q0*/ - Word16 *ynrm, /* o : recovered quantization indices Q0*/ - Word16 *normqlg2, /* o : recovered quantized norms Q0*/ - const Word16 nb_sfm /* i : number of SFMs Q0*/ + const Word16 *idxbuf, /* i : reordered quantization indices Q0*/ + Word16 *ynrm, /* o : recovered quantization indices Q0*/ + Word16 *normqlg2, /* o : recovered quantized norms Q0*/ + const Word16 nb_sfm /* i : number of SFMs Q0*/ ); Word32 ar_div( Word32 num, Word32 denum ); @@ -5948,13 +5513,13 @@ void tcx_arith_scale_envelope( ); void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ - const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 A_ind[], /* i: LPC coefficients of signal envelope Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ const Word16 L_spec, /* Q0 */ - const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ - const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ - const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ - Word32 env[] /* o: shaped signal envelope Q16*/ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ); /* returns innovation gain Q16 */ @@ -5996,31 +5561,12 @@ void swb_tbe_dec_fx( Word16 *Q_synth, Word16 *pitch_buf ); -void ivas_dequantizeSHBparams_fx_9_1( - Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ - Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ - Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ - Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors, /* o : Q15 */ - Word16 *MSFlag ); - void fb_tbe_dec_fx( Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp ); - -void fb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word32 *hb_synth, /* o : high-band synthesis */ Word16 hb_synth_exp, Word16 *fb_synth_ref, Word16 Q_fb_synth_ref, @@ -6075,7 +5621,7 @@ void lsf_dec_fx( Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ); @@ -6211,21 +5757,21 @@ Word32 dotp_me_fx( void lsf_end_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 mode2_flag, /* Q0 */ - const Word16 coder_type_org, /* i : coding type Q0*/ - const Word16 bwidth, /* i : input signal bandwidth Q0*/ - const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ - Word16 *lpc_param, /* i : LPC parameters Q0*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *nb_indices, /* o : number of indices Q0*/ - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices, /* o : number of indices Q0*/ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ); void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ - Word16 coder_type, /* i : Coder type Q0*/ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); void CNG_dec_fx( @@ -6239,14 +5785,6 @@ void CNG_dec_fx( Word32 *q_env ); void swb_CNG_dec_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 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*/ @@ -6270,7 +5808,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, @@ -6570,24 +6107,13 @@ 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 Word32 core_brate, /* i : core bitrate Q0*/ + 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*/ + 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 */ @@ -6607,17 +6133,17 @@ void hf_synth_amr_wb_fx( 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*/ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ - Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ const Word16 *hf_gain, /* i : decoded HF gain Q0*/ - const Word16 *voice_factors, /* i : voicing factors : Q15*/ - const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ - const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ const Word16 Q_exc, /* i : exc scaling */ const Word16 Q_out /* i : Q_syn2-1 */ ); @@ -6650,20 +6176,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 */ @@ -6727,17 +6239,17 @@ void bass_psfilter_init_fx( ); void bass_psfilter_fx( - BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag Q0*/ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) Q_syn2-1*/ - const Word16 L_frame, /* i : length of the last frame Q0*/ - Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] Q6*/ - const Word16 bpf_off, /* i : do not use BPF when set to 1 Q0*/ - Word16 v_stab_fx, /* i : stability factor Q15*/ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor Q15*/ - const Word16 coder_type, /* i : coder_type Q0*/ + BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ + const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag Q0*/ + Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) Q_syn2-1*/ + const Word16 L_frame, /* i : length of the last frame Q0*/ + Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] Q6*/ + const Word16 bpf_off, /* i : do not use BPF when set to 1 Q0*/ + Word16 v_stab_fx, /* i : stability factor Q15*/ + Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor Q15*/ + const Word16 coder_type, /* i : coder_type Q0*/ Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) Qx*/ + Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) Qx*/ ); void addBassPostFilter_fx( @@ -6799,7 +6311,7 @@ void PulseResynchronization_fx( ); void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ + Decoder_State *st_fx, /* i/o: decoder static memory */ Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ const Word16 *Aq, /* i : LP filter coefficient Q12*/ Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ @@ -6808,7 +6320,7 @@ void decod_audio_fx( Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ @@ -6818,21 +6330,17 @@ void decod_audio_fx( void gsc_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - const Word16 coder_type, /* i : coding type Q0*/ - Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); -void GSC_dec_init( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ -); - -void GSC_dec_init_ivas_fx( +void GSC_dec_init_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); @@ -6854,17 +6362,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 */ @@ -6894,15 +6391,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 */ @@ -6964,19 +6453,19 @@ Word16 gain_dequant_fx( Word16 *expg ); void AVQ_demuxdec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1] Q0*/ - Word16 *nb_bits, /* i/o: number of allocated bits Q0*/ - const Word16 Nsv, /* i : number of subvectors Q0*/ - Word16 nq[], /* i/o: AVQ nq index Q0*/ - Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution Q0*/ - Word16 trgtSvPos /* i : target SV for AVQ bit savings Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1] Q0*/ + Word16 *nb_bits, /* i/o: number of allocated bits Q0*/ + const Word16 Nsv, /* i : number of subvectors Q0*/ + Word16 nq[], /* i/o: AVQ nq index Q0*/ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution Q0*/ + Word16 trgtSvPos /* i : target SV for AVQ bit savings Q0*/ ); void AVQ_dec_lpc( - Word16 *indx, /* input: index[] (4 bits per words) Q0*/ - Word16 *nvecq, /* output: vector quantized Q0*/ - Word16 Nsv ); /* input: number of subvectors (lg=Nsv*8) Q0*/ + Word16 *indx, /* input: index[] (4 bits per words) Q0*/ + Word16 *nvecq, /* output: vector quantized Q0*/ + Word16 Nsv ); /* input: number of subvectors (lg=Nsv*8) Q0*/ void re8_dec_fx( Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ @@ -6991,22 +6480,22 @@ void re8_decode_base_index_fx( Word16 *x ); void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] Q0*/ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) Q0*/ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 Q0*/ + const Word16 *k, /* i : Voronoi index k[0..7] Q0*/ + const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) Q0*/ + Word16 *y /* o : 8-dimensional point y[0..7] in RE8 Q0*/ ); void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) Q0*/ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 Q0*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c Q0*/ - Word16 *ka /* o : identifier of absolute leader (to index c) Q0*/ + const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ + Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) Q0*/ + Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 Q0*/ + Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c Q0*/ + Word16 *ka /* o : identifier of absolute leader (to index c) Q0*/ ); void re8_PPV_fx( - const Word32 x[], /* i : point in R^8 Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0 */ + const Word32 x[], /* i : point in R^8 Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0 */ ); void dec_pit_exc_fx( @@ -7019,7 +6508,7 @@ void dec_pit_exc_fx( Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ const Word16 nb_subfr_fx, /* i : Number of subframe considered */ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); @@ -7161,20 +6650,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 */ @@ -7226,12 +6701,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*/ @@ -7413,7 +6882,7 @@ ivas_error createFdCngDec_fx( void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ); + const Word16 scale ); /* Delete the instance of type FD_CNG */ void deleteFdCngDec_fx( @@ -7530,12 +6999,7 @@ void generate_masking_noise_mdct_ivas_fx( HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ); ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan /* i : channel ID */ -); - -ivas_error init_decoder_ivas_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ + Decoder_State *st_fx, /* o : Decoder static variables structure */ const Word16 idchan, /* i : channel ID */ const MC_MODE mc_mode /* i : MC mode */ ); @@ -7557,7 +7021,9 @@ Word16 WB_BWE_gain_deq_fx( Word16 *WB_fenv /*Q15*/ ); +/* o : Q_syn_hb*/ Word16 wb_bwe_dec_fx( +#ifndef HARM_FD_BWE 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 output_frame, /* i : frame length */ @@ -7565,6 +7031,17 @@ Word16 wb_bwe_dec_fx( const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *Qpost ); +#else + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ + 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 */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ); +#endif /* o : BWE class */ Word16 swb_bwe_gain_deq_fx( @@ -7669,8 +7146,8 @@ void dequantize_norms_fx( void hdecnrm_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* (i) number of norms Q0*/ - Word16 *index ); /* (o) indices of quantized norms Q0*/ + const Word16 numNorms, /* (i) number of norms Q0*/ + Word16 *index ); /* (o) indices of quantized norms Q0*/ Word16 decode_huff_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7686,8 +7163,8 @@ void hdecnrm_context_fx( void hdecnrm_resize_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs Q0*/ - Word16 *index /* (o) norm quantization index vector Q0*/ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ); void huff_dec_fx( @@ -7702,9 +7179,9 @@ void huff_dec_fx( ); void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms Q0*/ - Word16 *index /* o : indices of quantized norms Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ); void tcq_core_LR_dec_fx( @@ -7767,7 +7244,7 @@ void hq_pred_hb_bws_fx( const Word16 *ynrm, /* i : norm quantization index vector Q0*/ const Word16 length, /* i : frame length Q0*/ const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ); void hq_hr_dec_fx( @@ -7779,7 +7256,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag Q1 */ + const Word16 core_switching_flag /* i : Core switching flag Q1 */ ); /* o : Consumed bits */ @@ -7828,35 +7305,29 @@ 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*/ + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ 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*/ @@ -7899,16 +7370,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 : float synthesis signal */ - 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 */ ); @@ -8073,24 +7540,24 @@ void music_postfilt_init( ); void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class Q0*/ - const Word16 coder_type, /* i : coder type Q0*/ - const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ - Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ const Word16 locattack, /* i : Flag for a detected attack Q0*/ Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ - const Word16 Q_syn, /* i : Synthesis scaling */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ - const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ - const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ - const Word16 last_coder_type /* i : Last coder_type Q0*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ ); void decod_amr_wb_fx( @@ -8124,15 +7591,15 @@ void sc_vbr_dec_init( ); ivas_error ppp_quarter_decoder_fx( - DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ + DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ + Word16 prevCW_lag_fx, /* i : Previous lag */ + Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ + Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ + Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ + Word16 bfi, /* i : FER flag */ Word16 *S_fx, /* i : sine table, Q15 */ Word16 *C_fx, /* i : cosine table, Q15 */ - DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ + DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ Decoder_State *st_fx ); void open_decoder_LPD_fx( @@ -8142,10 +7609,10 @@ void open_decoder_LPD_fx( ); void open_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate Q0*/ - const Word32 last_total_brate, /* i : last total bitrate Q0*/ - const Word16 bwidth, /* i : audio bandwidth Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 last_total_brate, /* i : last total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ const Word16 last_element_mode, /* i : last element mode Q0*/ const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization Q0*/ @@ -8215,49 +7682,49 @@ void stat_noise_uv_dec_fx( ); void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ + const Word16 coder_type, /* i : Coder type */ Word16 noisiness, /* i : noisiness parameter Q0 */ const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15 */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ - Word16 *exc2, /* i/o: excitation buffer Q_exc */ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ + Word16 *exc2, /* i/o: excitation buffer Q_exc */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q15 */ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : input bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ + const Word16 bfi, /* i : Bad frame indicator */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q15 */ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ + Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : input bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ); void stat_noise_uv_mod_ivas_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter Q=0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ - Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ + const Word16 coder_type, /* i : Coder type */ + Word16 noisiness, /* i : noisiness parameter Q=0 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ + Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q=15*/ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q=15*/ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : i bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : i bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ); Word16 FEC_SinOnset_fx( @@ -8288,37 +7755,37 @@ Word16 FEC_synchro_exc_fx( ); void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ Word16 *gain_buf ); void gaus_dec_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* o : unvoiced excitation Q12 */ - Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ - Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ - Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ - Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ - Word16 *voice_fac, /* o : estimated voicing factor Q15 */ - Word16 *gain_pit, /* o : pitch gain Q14 */ - Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ - Word16 *exc, /* o : excitation signal frame */ - Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ - Word16 *exc2, /* o : Scaled excitation signal frame */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *code, /* o : unvoiced excitation Q12 */ + Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ + Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ + Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ + Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ + Word16 *voice_fac, /* o : estimated voicing factor Q15 */ + Word16 *gain_pit, /* o : pitch gain Q14 */ + Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ + Word16 *exc, /* o : excitation signal frame */ + Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ + Word16 *exc2, /* o : Scaled excitation signal frame */ Word16 *bwe_exc_fx, - Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ - Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ + Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ + Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ ); void gaus_L2_dec( @@ -8454,13 +7921,13 @@ void mode_switch_decoder_LPD_fx( ); void mode_switch_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bwidth, /* i : audio bandwidth Q0*/ - const Word32 total_brate, /* i : total bitrate Q0*/ - const Word32 last_total_brate, /* i : last frame total bitrate Q0*/ - const Word16 frame_size_index, /* i : index determining the frame size Q0*/ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 last_element_mode, /* i : last element mode Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 last_total_brate, /* i : last frame total bitrate Q0*/ + const Word16 frame_size_index, /* i : index determining the frame size Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -8501,12 +7968,12 @@ Word16 lsf_bctcvq_decprm( ); Word16 D_lsf_tcxlpc( - const Word16 indices[], /* i : VQ indices Q0*/ - Word16 lsf_q[], /* o : quantized LSF Q1*/ - Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ - Word16 narrowband, /* i : narrowband flag Q0*/ - Word16 cdk, /* i : codebook selector Q0*/ - Word16 mem_MA[] /* i : MA memory Q1*/ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ); Word16 dec_lsf_tcxlpc( @@ -8642,7 +8109,7 @@ void ConfigureContextHm( ); Word16 CountIndexBits( - Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ + Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ Word16 PeriodicityIndex /* Q0 */ ); @@ -8660,7 +8127,21 @@ void tcx_hm_modify_envelope( Word32 env[], /* i/o: envelope Q16 */ Word16 L_frame /* i: number of spectral lines Q0 */ ); +#ifdef HARMONIZE_READ_DECODE_TNS +void ReadTnsData_fx( + STnsConfig const *pTnsConfig, + Decoder_State *st, + Word16 *pnBits, + Word16 *stream, + Word16 *pnSize ); + +Word16 DecodeTnsData_fx( + STnsConfig const *pTnsConfig, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ + STnsData *pTnsData ); +#else Word16 ReadTnsData( STnsConfig const *pTnsConfig, Decoder_State *st, @@ -8687,6 +8168,7 @@ Word16 DecodeTnsData_ivas_fx( Word16 *pnSize, STnsData *pTnsData ); +#endif void GetParameters( ParamsBitMap const *paramsBitMap, const Word16 nParams, @@ -8863,12 +8345,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 */ @@ -8888,33 +8364,33 @@ void vlpc_2st_dec( Word32 sr_core ); void lsf_weight_2st( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ - Word16 *w, /* output: weighting function (0Q15*1.28) */ + const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ + Word16 *w, /* output: weighting function (0Q15*1.28) */ const Word16 mode /* input: operational mode Q0 */ ); /* Returns: index of next coefficient */ Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes Q0*/ - Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ - Word16 *idx, /* o : index in unmapped domain Q0*/ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); /* Returns: index of next coefficient */ Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes Q0*/ - Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ - Word16 *idx, /* o : index in unmapped domain Q0*/ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + Word16 ii[2], /* i/o: coefficient indexes Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); -Word16 update_mixed_context( +Word16 update_mixed_context_fx( Word16 ctx, /* Q0 */ Word16 a /* Q0 */ ); -Word32 update_mixed_context_ivas_fx( +Word32 update_mixed_context_fx_32( Word32 ctx, /* Q0 */ Word16 a /* Q0 */ ); @@ -8953,7 +8429,7 @@ void reconfig_decoder_LPD_fx( ); void reconfig_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ const Word16 bits_frame, /* i : bit budget Q0*/ const Word16 bwidth, /* i : audio bandwidth Q0*/ const Word32 total_brate, /* i : total bitrate Q0*/ @@ -9114,9 +8590,7 @@ void decoder_tcx_ivas_fx( Word16 Aind[], Word16 synth_fx[], Word16 synthFB_fx[], -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Word16 *synth_q, -#endif const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ); @@ -9243,15 +8717,15 @@ void fft_cldfb_fx( ); void stereo_dft_dec_analyze_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 *input_fx, /* i : input signal q*/ - Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ - const Word16 chan, /* i : channel number Q0*/ - const Word16 input_frame, /* i : input frame size Q0*/ - const Word16 output_frame, /* i : output frame size Q0*/ - const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ - const Word16 k_offset, /* i : offset of DFT Q0*/ - const Word16 delay, /* i : delay in samples FOR input signal Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 *input_fx, /* i : input signal q*/ + Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 input_frame, /* i : input frame size Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ + const Word16 k_offset, /* i : offset of DFT Q0*/ + const Word16 delay, /* i : delay in samples FOR input signal Q0*/ Word16 *q, Word16 *q_DFT ); @@ -9363,12 +8837,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*/ @@ -9570,7 +9038,7 @@ Word16 deindex_lvq_ivas_fx( Word16 no_bits /* i : number of bits for lattice */ ); -void deleteCldfb_ivas_fx( +void deleteCldfb_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ); @@ -9584,14 +9052,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, @@ -9642,10 +9102,10 @@ void tcx_scalar_quantization_ivas_fx( Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( Word16 *x, /* Spectral coefficients Q0*/ - const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/ + const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/ Word16 *lastnz_out, /* Q0 */ Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/ - const Word16 target, /* Target bits Q0*/ + const Word16 target, /* Target bits Q0*/ Word16 *stop, /* Q0 */ Word16 mode, /* Q0 */ CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ @@ -9911,7 +9371,7 @@ void Vr_subt( ); /* o: index of the winning codevector */ -Word16 vquant_ivas_fx( +Word16 vquant_fx_32( Word32 x[], /* i: vector to quantize Q25 */ const Word32 x_mean[], /* i: vector mean to subtract (0 if none) Q25 */ Word32 xq[], /* o: quantized vector Q25 */ @@ -10309,7 +9769,7 @@ Word16 ceil_log_2( UWord64 val ); Word32 imax_pos_fx( - const Word32 *y /* i : Input vector for peak interpolation Qx*/ + const Word32 *y /* i : Input vector for peak interpolation Qx*/ ); void msvq_enc_ivas_fx( @@ -10394,16 +9854,16 @@ void v_sub32_fx( const Word16 N /* i : Vector length */ ); -void ivas_swb_tbe_dec_fx( +void swb_tbe_dec_ivas_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 swb_bwe_dec_fx32( @@ -10417,9 +9877,9 @@ 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 */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ Word16 synth_fx16[], /* o : synthesis */ - Word16 save_hb_synth_fx16[], /* o : HB synthesis */ + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ 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 */ @@ -10438,10 +9898,6 @@ ivas_error acelp_core_dec_fx( const Word16 read_sid_info /* i : read SID info flag */ ); -void destroy_cldfb_decoder_ivas_fx( - Decoder_State *st /* o : Decoder static variables structure */ -); - void wtda_fx32( const Word32 *new_audio, /* i : input audio Q11 */ Word32 *wtda_audio, /* o : windowed audio Q11 */ @@ -10451,17 +9907,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, @@ -10567,27 +10012,20 @@ void Copy_Scale_sig32( const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ ); +#ifndef HARMONIZE_TBE2 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 */ - 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 */ + Word16 q_reImBuffer, /* i : scale data of real and imag CLDFB buffers*/ +#ifdef HARMONIZE_TBE2 + const CLDFB_SCALE_FACTOR *cldfbScale, /* i : scale data of real and imag CLDFB buffers */ +#endif + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); - +#endif /* o : Q(2x - 31 - gb) */ Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector, Qx */ @@ -10722,26 +10160,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 */ @@ -10826,12 +10244,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 */ @@ -10931,20 +10343,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 */ @@ -10955,18 +10353,6 @@ ivas_error IGF_Reconfig_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -void configureCldfb_ivas_enc_fx( - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const Word32 sampling_rate /* i : sampling rate */ -); - -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, @@ -10984,14 +10370,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 ); - /*===========================================================================================*/ /*----------------------------------------------------------------------------------* @@ -11003,9 +10381,6 @@ Word16 own_random( Word16 *seed /* i/o: random seed */ ); -Word16 norm_ul_float( - UWord32 UL_var1 ); - /*! r: sum of all vector elements */ Word16 sum_s( const Word16 *vec, /* i : input vector */ @@ -11045,17 +10420,6 @@ void set16_zero_fx( const Word16 lvec /* i : length of the vector */ ); -void set_zero( - float *vec, /* o : input vector */ - const Word16 lvec /* i : length of the vector */ -); - -void mvr2r( - const float x[], /* i : input vector */ - float y[], /* o : output vector */ - const Word16 n /* i : vector size */ -); - void mvs2s( const Word16 x[], /* i : input vector */ Word16 y[], /* o : output vector */ @@ -11081,18 +10445,6 @@ Word16 minimum_s( Word16 *min_val /* o : minimum value in the input vector */ ); -/*! r: dequanzited gain */ -float usdequant( - const Word16 idx, /* i : quantizer index */ - const float qlow, /* i : lowest codebook entry (index 0) */ - const float delta /* i : quantization step */ -); - -void sort( - UWord16 *x, /* i/o: Vector to be sorted */ - UWord16 len /* i/o: vector length */ -); - void sort_l( Word32 *x, /* i/o: Vector to be sorted */ Word16 len /* i/o: vector length */ @@ -11203,6 +10555,12 @@ Decoder_State **reset_elements( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +void convertSerialToBytestream_fx( + const UWord16 *const serial, /* i : input serial bitstream with values 0 and 1 */ + const UWord16 num_bits, /* i : number of bits in the input bitstream */ + UWord8 *const bytestream /* o : output compact bitstream (bytestream) */ +); + void mdct_switching_dec_fx( Decoder_State *st /* i/o: decoder state structure */ ); @@ -11250,36 +10608,35 @@ void read_next_force( ); #endif -ivas_error init_encoder_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Encoder_Struct *st_ivas, /* i/o: encoder state structure */ - const Word16 idchan, /* i : channel ID */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID, /* i : interval for SID update */ - const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 element_brate /* i : element bitrate */ -); - -ivas_error acelp_core_enc_ivas_fx( - 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*/ - Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ - 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*/ - 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 ); +ivas_error init_encoder_fx( + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ +); + +ivas_error acelp_core_enc_fx( + 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*/ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ + const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ + Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ + 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*/ + 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 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*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift need to obtain 12 bits vectors */ +); void flip_and_downmix_generic_fx32( Word32 input[], /* i : input spectrum Qx*/ @@ -11320,20 +10677,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 */ @@ -11389,7 +10732,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 */ @@ -11417,15 +10761,15 @@ void tcx_hm_decode( ); void writeTCXMode_fx( - Encoder_State *st, /* i/o: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - Word16 *nbits_start /* o : nbits start Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + Word16 *nbits_start /* o : nbits start Q0*/ ); void writeTCXWindowing_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 overlap_mode /* i : overlap mode Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 overlap_mode /* i : overlap mode Q0*/ ); void writeLPCparam( @@ -11469,12 +10813,6 @@ void EncodeTnsData( Word16 *pnBits /* o : number of written bits */ ); -Word16 DecodeTnsData_ivas( - STnsConfig const *pTnsConfig, - const Word16 *stream, - Word16 *pnSize, - STnsData *pTnsData ); - void WriteTnsData( const STnsConfig *pTnsConfig, /* i : TNS Configuration struct */ const Word16 *stream, /* i : internal data stream */ @@ -11482,7 +10820,7 @@ void WriteTnsData( BSTR_ENC_HANDLE hBstr, /* o : bitstream */ Word16 *pnBits /* o : number of written bits */ ); - +#ifndef HARMONIZE_READ_DECODE_TNS void ReadTnsData_ivas( STnsConfig const *pTnsConfig, Decoder_State *st, @@ -11490,6 +10828,13 @@ void ReadTnsData_ivas( Word16 *stream, Word16 *pnSize ); +Word16 DecodeTnsData_ivas( + STnsConfig const *pTnsConfig, + const Word16 *stream, + Word16 *pnSize, + STnsData *pTnsData ); + +#endif // HARMONIZE_READ_DECODE_TNS void analysisCldfbEncoder_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ Word32 *timeIn, /*q11*/ diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 98ca8c4ab1dce71ba25c07df33b3cc7238dbd829..49a83bc7bba3971805ddde88e8584f9824c8c9a5 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -52,8 +52,8 @@ Word16 shrtCDivSignedApprox( } static void nearProjQ15_fx( - const Word16 x, /* i : input coefficient Q15*/ - Word16 *result /* o : projection Q15*/ + const Word16 x, /* i : input coefficient Q15*/ + Word16 *result /* o : projection Q15*/ ) { const Word16 a[4] = { 14967, -25518, 3415, 32351 }; /* Q15 */ @@ -81,9 +81,9 @@ static void nearProjQ15_fx( * *-------------------------------------------------------------------*/ void obtainEnergyQuantizerDensity_fx( - const Word16 L, /* i : left vector energy Q0*/ - const Word16 R, /* i : right vector energy Q0*/ - Word16 *Density /* o : quantizer density Q0*/ + const Word16 L, /* i : left vector energy Q0*/ + const Word16 R, /* i : right vector energy Q0*/ + Word16 *Density /* o : quantizer density Q0*/ ) { Word16 Rnrg, den, n; @@ -117,8 +117,8 @@ void obtainEnergyQuantizerDensity_fx( * *-------------------------------------------------------------------*/ void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, /* i : input index Q0*/ - Word16 *diracs /* o : number of diracs Q0*/ + const Word16 dsDiracIndex, /* i : input index Q0*/ + Word16 *diracs /* o : number of diracs Q0*/ ) { *diracs = dsDiracsTab[dsDiracIndex]; /* Q0 */ @@ -127,11 +127,11 @@ void dsDirac2Dirac_fx( } void dsDiracPerQuanta_fx( - const Word16 td, /* i : Length of vector segment Q0*/ - const Word16 t_quanta, /* i : Assigned number of quanta Q0*/ - const Word16 dsm, /* i : Conservative rounding flag Q0*/ - const unsigned char *const *frQuanta, /* i : Quanta lookup table */ - Word16 *DsIdx /* o : Lookup table index Q0*/ + const Word16 td, /* i : Length of vector segment Q0*/ + const Word16 t_quanta, /* i : Assigned number of quanta Q0*/ + const Word16 dsm, /* i : Conservative rounding flag Q0*/ + const unsigned char *const *frQuanta, /* i : Quanta lookup table */ + Word16 *DsIdx /* o : Lookup table index Q0*/ ) { const unsigned char *sv; @@ -241,7 +241,7 @@ void conservativeL1Norm_fx( if ( Mprime < 0 ) { - *Qspare = add( Qavail, QUANTAQ3OFFSET ); /* single op Q0*/ + *Qspare = add( Qavail, QUANTAQ3OFFSET ); /* single op Q0*/ move16(); } dsDirac2Dirac_fx( add( Mprime, 1 ), Dvec ); @@ -280,7 +280,7 @@ void bandBitsAdjustment_fx( IF( LT_16( D, Nbands ) ) { L_tmp = L_deposit_l( sub( Breserv, Bff ) ); /* Q0 */ - Btemp = extract_l( intLimCDivSigned_fx( L_tmp, s_min( D, 3 ) ) ); /* result always fits in Word16 Q0*/ + Btemp = extract_l( intLimCDivSigned_fx( L_tmp, s_min( D, 3 ) ) ); /* result always fits in Word16 Q0*/ *Breservplus = add( Bband, Breserv ); /* Q0 */ move16(); } @@ -329,9 +329,9 @@ static Word16 Ratio_base2Q11_fx( /* o : Q11 */ } static void Ratio_rQ3_fx( - Word16 opp, /* i : opposite Q15*/ - Word16 near, /* i : near Q15*/ - Word16 *result /* o : ratio Q3*/ + Word16 opp, /* i : opposite Q15*/ + Word16 near, /* i : near Q15*/ + Word16 *result /* o : ratio Q3*/ ) { Word16 tmp; @@ -344,11 +344,11 @@ static void Ratio_rQ3_fx( void densityAngle2RmsProjDec_fx( - const Word16 D, /* i : density Q0*/ - const Word16 indexphi, /* i : decoded index from AR dec Q0*/ - Word16 *oppQ15, /* o : opposite Q15*/ - Word16 *nearQ15, /* o : near Q15*/ - Word16 *oppRatioQ3 /* o : ratio Q3*/ + const Word16 D, /* i : density Q0*/ + const Word16 indexphi, /* i : decoded index from AR dec Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ) { Word16 phiQ14q; @@ -385,12 +385,12 @@ void densityAngle2RmsProjDec_fx( } void densityAngle2RmsProjEnc_fx( - const Word16 D, /* i : density Q0*/ - const Word16 phiQ14uq, /* i : angle Q14*/ - Word16 *indexphi, /* o : index Q0*/ - Word16 *oppQ15, /* o : opposite Q15*/ - Word16 *nearQ15, /* o : near Q15*/ - Word16 *oppRatioQ3 /* o : ratio Q3*/ + const Word16 D, /* i : density Q0*/ + const Word16 phiQ14uq, /* i : angle Q14*/ + Word16 *indexphi, /* o : index Q0*/ + Word16 *oppQ15, /* o : opposite Q15*/ + Word16 *nearQ15, /* o : near Q15*/ + Word16 *oppRatioQ3 /* o : ratio Q3*/ ) { *indexphi = mult_r( shl( D, 1 ), phiQ14uq ); /* Q0 */ @@ -435,14 +435,14 @@ void NearOppSplitAdjustment_fx( move16(); IF( GT_16( Nhead, 1 ) ) { - qavg = extract_h( L_shl( intLimCDivSigned_fx( L_deposit_l( qboth ), Np ), 16 ) ); /* qboth may be negative Q0*/ + qavg = extract_h( L_shl( intLimCDivSigned_fx( L_deposit_l( qboth ), Np ), 16 ) ); /* qboth may be negative Q0*/ dsDiracPerQuanta_fx( Ntail, qavg, FlagCons, hBitsN, &Midx ); QuantaPerDsDirac_fx( Nhead, Midx, hBitsN, &qmin ); qskew = sub( qavg, qmin ); /* Q0 */ qskew = s_max( 0, qskew ); /* Q0 */ } /* end of skew calc code*/ - QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out Q0*/ + QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out Q0*/ L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); /* Q0 */ L_QIb = L_deposit_l( 0 ); @@ -452,7 +452,7 @@ void NearOppSplitAdjustment_fx( } *qnear = qboth; /* Q3 */ move16(); - QIb = extract_h( L_shl_sat( L_QIb, 16 ) ); /* may saturate Q0*/ + QIb = extract_h( L_shl_sat( L_QIb, 16 ) ); /* may saturate Q0*/ if ( LE_16( QIb, qboth ) ) { *qnear = QIb; /* Q0 */ @@ -474,12 +474,12 @@ void NearOppSplitAdjustment_fx( *--------------------------------------------------------------------------*/ void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order Q0 */ - const Word16 *band_start, /* i : Sub band start indices Q0 */ - const Word16 *band_end, /* i : Sub band end indices Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word16 *gains, /* i : Band gain vector Qx */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Qx */ + const Word16 *ord, /* i : Indices for energy order Q0 */ + const Word16 *band_start, /* i : Sub band start indices Q0 */ + const Word16 *band_end, /* i : Sub band end indices Q0 */ + const Word16 num_sfm, /* i : Number of bands Q0 */ + const Word16 *gains, /* i : Band gain vector Qx */ + Word16 *xq /* i/o: synthesis / Gain adjusted synth Q15/Qx */ ) { Word16 band, i; @@ -506,7 +506,7 @@ void apply_gain_fx( * Fine gain quantization *--------------------------------------------------------------------------*/ void fine_gain_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *ord, /* i : Indices for energy order Q0 */ const Word16 num_sfm, /* i : Number of bands Q0 */ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band Q0 */ @@ -572,9 +572,9 @@ void fine_gain_quant_fx( *-------------------------------------------------------------------*/ void srt_vec_ind16_fx( - const Word16 *linear, /* linear input Q3*/ - Word16 *srt, /* sorted output Q3*/ - Word16 *I, /* index for sorted output Q0*/ + const Word16 *linear, /* linear input Q3*/ + Word16 *srt, /* sorted output Q3*/ + Word16 *I, /* index for sorted output Q0*/ Word16 length /* Q0 */ ) { diff --git a/lib_com/range_com_fx.c b/lib_com/range_com_fx.c index b84ec6c26756c7fa5aa080d2300971f81f3475e4..94eb888b72567ff1f3e746a7ec3062d4ba394b3d 100644 --- a/lib_com/range_com_fx.c +++ b/lib_com/range_com_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -13,9 +13,9 @@ * Get number of bits needed to finalize range coder *-------------------------------------------------------------------*/ -Word16 rc_get_bits2_fx( /* o: Number of bits needed Q0*/ - const Word16 N, /* i: Number of bits currently used Q0*/ - const UWord32 range /* i: Range of range coder Q0*/ +Word16 rc_get_bits2_fx( /* o: Number of bits needed Q0*/ + const Word16 N, /* i: Number of bits currently used Q0*/ + const UWord32 range /* i: Range of range coder Q0*/ ) { return add( add( N, 2 ), norm_ul( range ) ); @@ -28,9 +28,9 @@ Word16 rc_get_bits2_fx( /* o: Number of bits needed Q0*/ *-------------------------------------------------------------------*/ void rangeCoderFinalizationFBits_fx( - Word16 Brc, /* i : Current number of decoded bits Q0*/ - UWord32 INTrc, /* i : Range coder state Q0*/ - Word16 *FBits /* i : Fractional finalization bits Q0*/ + Word16 Brc, /* i : Current number of decoded bits Q0*/ + UWord32 INTrc, /* i : Range coder state Q0*/ + Word16 *FBits /* i : Fractional finalization bits Q0*/ ) { Word32 L_Bq15; diff --git a/lib_com/re8_ppv_fx.c b/lib_com/re8_ppv_fx.c index c643bf1ea21c69568e61b3a6b8e0b939d1a609ff..5398214b4cf4422896c1115aba2ef213df2d3429 100644 --- a/lib_com/re8_ppv_fx.c +++ b/lib_com/re8_ppv_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -24,8 +24,8 @@ static Word32 compute_error_2D8_fx( const Word32 x[], const Word16 y[] ); * --------------------------------------------------------------*/ void re8_PPV_fx( - const Word32 x[], /* i : point in R^8 Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0*/ + const Word32 x[], /* i : point in R^8 Q15 */ + Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0*/ ) { Word16 i, y0[8]; @@ -83,8 +83,8 @@ void re8_PPV_fx( --------------------------------------------------------------*/ static void nearest_neighbor_2D8_fx( - const Word32 x[], /* i : point in R^8 Q15*/ - Word16 y[] /* o : point in 2D8 (8-dimensional integer vector) Q0*/ + const Word32 x[], /* i : point in R^8 Q15*/ + Word16 y[] /* o : point in 2D8 (8-dimensional integer vector) Q0*/ ) { Word16 i, j; @@ -164,9 +164,9 @@ static void nearest_neighbor_2D8_fx( * (quantized) point in 2D8. --------------------------------------------------------------*/ -static Word32 compute_error_2D8_fx( /* o : mean squared error Q15*/ - const Word32 x[], /* i : input vector Q15*/ - const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) Q0*/ +static Word32 compute_error_2D8_fx( /* o : mean squared error Q15*/ + const Word32 x[], /* i : input vector Q15*/ + const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) Q0*/ ) { Word16 i, hi, lo; diff --git a/lib_com/re8_util_fx.c b/lib_com/re8_util_fx.c index de70279ebf63772e0a2bd841a2c5633ea1e94dca..cf5db258d50df53908dd11a947df4b39f5d9c30a 100644 --- a/lib_com/re8_util_fx.c +++ b/lib_com/re8_util_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -23,11 +23,11 @@ static void re8_coord_fx( const Word16 *y, Word16 *k ); * MULTI-RATE RE8 INDEXING BY VORONOI EXTENSION *----------------------------------------------------------------*/ void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) Q0*/ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 Q0*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c Q0*/ - Word16 *ka /* o : identifier of absolute leader (to index c) Q0*/ + const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) Q0*/ + Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) Q0*/ + Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 Q0*/ + Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c Q0*/ + Word16 *ka /* o : identifier of absolute leader (to index c) Q0*/ ) { Word16 i, r, iter, ka_tmp, n_tmp, mask; @@ -99,7 +99,7 @@ void re8_vor_fx( /*------------------------------------------------------------* * compute m and the mask needed for modulo m (for Voronoi coding) *------------------------------------------------------------*/ - mask = sub( shl( 1, r ), 1 ); /* 0x0..011...1 Q0*/ + mask = sub( shl( 1, r ), 1 ); /* 0x0..011...1 Q0*/ /*------------------------------------------------------------* * find the minimal value of r (or equivalently of m) in 2 iterations @@ -187,9 +187,9 @@ void re8_vor_fx( * VORONOI INDEXING (INDEX DECODING) k -> y -------------------------------------------------------------------------*/ void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] Q0*/ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) Q0*/ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 Q0*/ + const Word16 *k, /* i : Voronoi index k[0..7] Q0*/ + const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) Q0*/ + Word16 *y /* o : 8-dimensional point y[0..7] in RE8 Q0*/ ) { Word16 i, v[8], *ptr1, *ptr2, m_tmp, mm; @@ -318,8 +318,8 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i * only the id's related to the shell of number s are checked *---------------------------------------------------------------*/ - nb = Da_nb[s - 1]; /* get the number of absolute leaders used on the shell of number s Q0*/ - pos = Da_pos[s - 1]; /* get the position of the first absolute leader of shell s in Da_id Q0*/ + nb = Da_nb[s - 1]; /* get the number of absolute leaders used on the shell of number s Q0*/ + pos = Da_pos[s - 1]; /* get the position of the first absolute leader of shell s in Da_id Q0*/ move16(); move16(); @@ -350,8 +350,8 @@ static Word16 re8_identify_absolute_leader_fx( /* o : integer i -----------------------------------------------------------------------*/ static void re8_coord_fx( - const Word16 *y, /* i : 8-dimensional point y[0..7] in RE8 Q0*/ - Word16 *k /* o : coordinates k[0..7] Q0*/ + const Word16 *y, /* i : 8-dimensional point y[0..7] in RE8 Q0*/ + Word16 *k /* o : coordinates k[0..7] Q0*/ ) { Word16 i, tmp, sum; diff --git a/lib_com/recovernorm_fx.c b/lib_com/recovernorm_fx.c index 2f98597583c50159430e9798c37b86d42a4abde9..83167ea621c6341b39e3b88100d41ec3882180f6 100644 --- a/lib_com/recovernorm_fx.c +++ b/lib_com/recovernorm_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -14,10 +14,10 @@ *--------------------------------------------------------------------------*/ void recovernorm_fx( - const Word16 *idxbuf, /* i : reordered quantization indices Q0*/ - Word16 *ynrm, /* o : recovered quantization indices Q0*/ - Word16 *normqlg2, /* o : recovered quantized norms Q0*/ - const Word16 nb_sfm /* i : number of SFMs Q0*/ + const Word16 *idxbuf, /* i : reordered quantization indices Q0*/ + Word16 *ynrm, /* o : recovered quantization indices Q0*/ + Word16 *normqlg2, /* o : recovered quantized norms Q0*/ + const Word16 nb_sfm /* i : number of SFMs Q0*/ ) { Word16 i, j, k; 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 ecfb672b06e02809f463966e6f5a1228a87a72a1..d4de347d5435d76ba0adc6225b003957f9147305 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -24,18 +24,18 @@ void residu_ivas_fx( const Word16 l /* i : size of filtering */ ) { - Word32 s; - Word16 i, j; + Word64 s64; + Word16 i, j, scaling; + scaling = sub( Q15, a_exp ); FOR( i = 0; i < l; i++ ) { - s = x[i]; - move32(); + s64 = W_mult_32_16( x[i], a[0] ); FOR( j = 1; j <= m; j++ ) { - s = L_add( s, L_shl( Mpy_32_16_1( x[i - j], a[j] ), sub( Q15, a_exp ) ) ); // Qx + s64 = W_mac_32_16( s64, x[i - j], a[j] ); } - y[i] = s; + y[i] = W_shl_sat_l( s64, scaling ); move32(); } @@ -176,25 +176,25 @@ void Residu3_fx( } /*==========================================================================*/ -/* FUNCTION : void calc_residu() */ +/* FUNCTION : void calc_residu() */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : Compute the LP residual by filtering the input through */ -/* A(z) in all subframes */ +/* PURPOSE : Compute the LP residual by filtering the input through */ +/* A(z) in all subframes */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* Word16 *speech i : weighted speech signal Qx */ -/* Word16 L_frame i : order of LP filter Q0 */ +/* Word16 L_frame i : order of LP filter Q0 */ /* Word16 *p_Aq i : quantized LP filter coefficients Q12 */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* Word16 *res o : residual signal Qx+1 */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*==========================================================================*/ void calc_residu_fx( 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 e7811db89fa50d2dce8a529ae386ae1654dd03bc..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef __BASOP_UTIL_ROM_H__ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index fd1a9221d375a241c1f1973df8e9af1f3d327240..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef ROM_COM_H @@ -50,14 +50,14 @@ typedef struct { - Word32 fin_fx; /* input frequency Q0 */ - Word32 fout_fx; /* output frequency Q0 */ - Word16 fac_num_fx; /* numerator of resampling factor Q0 */ - Word16 fac_den_fx; /* denominator of resampling factor Q0 */ - Word16 lg_out; /* denominator of resampling factor Q15 */ - const Word16 *filter_fx; /* resampling filter coefficients Q14 */ - Word16 filt_len_fx; /* number of filter coeff. Q0 */ - UWord16 flags_fx; /* flags from config. table Q0 */ + Word32 fin_fx; /* input frequency Q0 */ + Word32 fout_fx; /* output frequency Q0 */ + Word16 fac_num_fx; /* numerator of resampling factor Q0 */ + Word16 fac_den_fx; /* denominator of resampling factor Q0 */ + Word16 lg_out; /* denominator of resampling factor Q15 */ + const Word16 *filter_fx; /* resampling filter coefficients Q14 */ + Word16 filt_len_fx; /* number of filter coeff. Q0 */ + UWord16 flags_fx; /* flags from config. table Q0 */ } Resampling_cfg; typedef struct @@ -109,16 +109,16 @@ extern const Word16 mid_LSF_bits_tbl[]; /* Bit allocation table for mid-frame IS extern const Word16 Es_pred_bits_tbl[]; /* Bit allocation table for scaled innovation energy prediction Q0*/ extern const Word16 gain_bits_tbl[]; /* Bit allocation table for gain quantizer Q0*/ -extern const Word16 ACB_bits_tbl[]; /* Bit allocation table for adaptive codebook (pitch) Q0*/ +extern const Word16 ACB_bits_tbl[]; /* Bit allocation table for adaptive codebook (pitch) Q0*/ extern const Word16 FCB_bits_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) Q0*/ -extern const Word16 reserved_bits_tbl[]; /* Bit allocation table for reseved bits Q0*/ +extern const Word16 reserved_bits_tbl[]; /* Bit allocation table for reseved bits Q0*/ -extern const Word16 ACB_bits_16kHz_tbl[]; /* Bit allocation table for adaptive codebook (pitch) @16kHz Q0*/ +extern const Word16 ACB_bits_16kHz_tbl[]; /* Bit allocation table for adaptive codebook (pitch) @16kHz Q0*/ extern const Word16 FCB_bits_16kHz_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) @16kHz Q0*/ -extern const Word16 gain_bits_16kHz_tbl[]; /* Bit allocation table for gain quantizer @16kHz Q0*/ -extern const Word16 AVQ_bits_16kHz_tbl[]; /* Bit allocation table for AVQ bits @16kHz ACELP, active segments Q0*/ +extern const Word16 gain_bits_16kHz_tbl[]; /* Bit allocation table for gain quantizer @16kHz Q0*/ +extern const Word16 AVQ_bits_16kHz_tbl[]; /* Bit allocation table for AVQ bits @16kHz ACELP, active segments Q0*/ -extern const UWord32 pulsestostates[17][9]; /* Number of states for any combination of pulses in any combination of vector length Q0*/ +extern const UWord32 pulsestostates[17][9]; /* Number of states for any combination of pulses in any combination of vector length Q0*/ extern const UWord8 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX + RF_MODE_MAX]; // Q0 extern const UWord8 ACELP_NRG_BITS[3]; // Q0 @@ -161,7 +161,7 @@ extern const Word16 h_high_fx[5]; // Q15 extern const Word16 sincos_t_fx[161]; // Q15 extern const Word16 sincos_t_ext_fx[]; // Q15 extern const Word32 crit_bands_fx[]; -extern const Word16 fft256_read_indexes[]; /* FFT Q0*/ +extern const Word16 fft256_read_indexes[]; /* FFT Q0*/ extern const Word16 inter4_2_fx[]; extern const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1]; /*1Q14*/ extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*Q15*/ @@ -171,7 +171,7 @@ extern const Word16 Assym_window_W16fx[]; // Q15 extern const Word16 assym_window_16k_fx[]; // Q15 extern const Word16 grid50_fx[( GRID50_POINTS - 1 ) / 2 - 1]; // Q15 extern const Word16 grid40_fx[( GRID40_POINTS - 1 ) / 2 - 1]; // Q15 -extern const Word32 crit_bands_fx[]; /* Table of critical bands Q0*/ +extern const Word32 crit_bands_fx[]; /* Table of critical bands Q0*/ extern const Word16 wind_sss_fx[LEN_WIN_SSS]; // Q15 /*window for modify_sf ana*/ extern const Word16 filter5_39s320_120_fx[]; // Q15 @@ -346,11 +346,11 @@ extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st s extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) Qlog2(2.56)*/ extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) Qlog2(2.56)*/ -extern const Word16 dico1_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 1st split Qlog2(2.56)*/ -extern const Word16 dico2_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 2nd spilt Qlog2(2.56)*/ -extern const Word16 dico3_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 3rd spilt Qlog2(2.56)*/ -extern const Word16 dico4_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 4th spilt Qlog2(2.56)*/ -extern const Word16 dico5_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 5th spilt Qlog2(2.56)*/ +extern const Word16 dico1_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 1st split Qlog2(2.56)*/ +extern const Word16 dico2_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 2nd spilt Qlog2(2.56)*/ +extern const Word16 dico3_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 3rd spilt Qlog2(2.56)*/ +extern const Word16 dico4_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 4th spilt Qlog2(2.56)*/ +extern const Word16 dico5_ns_28b_fx[]; /*Qlog2(2.56)*/ /* ISF codebook for SID frames - 28b, 5th spilt Qlog2(2.56)*/ /*----------------------------------------------------------------------------------* * LSF quantization - MSVQ tables @@ -433,7 +433,7 @@ extern const UWord32 table_no_cv[]; // Q0 extern const Word32 table_no_cv_fx[]; // Q0 extern const Word16 pl_par[]; // Q0 -// extern const Word16 pl_par_fx[]; /* 1 if even number of signs */ +// extern const Word16 pl_par_fx[]; /* 1 if even number of signs */ extern const Word16 *const Quantizers_p_fx[]; // Qlog2(2.56) extern const Word16 *const Quantizers_fx[]; // Qlog2(2.56) @@ -577,8 +577,8 @@ extern const Word16 Da_nq[]; /* Codebook number for each absolute leader */ * SWB TBE tables *------------------------------------------------------------------------------*/ -extern const Word16 skip_bands_SWB_TBE[]; /* bands for SWB TBE quantisation Q0*/ -extern const Word16 skip_bands_WB_TBE[]; /* bands for WB TBE quantisation Q0*/ +extern const Word16 skip_bands_SWB_TBE[]; /* bands for SWB TBE quantisation Q0*/ +extern const Word16 skip_bands_WB_TBE[]; /* bands for WB TBE quantisation Q0*/ extern const Word16 interpol_frac_shb[NB_SUBFR * 2]; // Q15 extern const Word16 interpol_frac_shb[NB_SUBFR * 2]; // Q15 @@ -617,11 +617,11 @@ extern const Word16 full_band_bpf_1_fx[][5]; /*Q13*/ extern const Word16 full_band_bpf_2_fx[][5]; /*Q13*/ extern const Word16 full_band_bpf_3_fx[][5]; /*Q13*/ extern const Word16 *const lsf_q_cb_fx[]; // Q15 -extern const Word16 lsf_q_cb_size[]; /* Size of each element of the above Q0*/ -extern const Word16 lsf_q_num_bits[]; /* Size of each element of the above, in bits Q0*/ +extern const Word16 lsf_q_cb_size[]; /* Size of each element of the above Q0*/ +extern const Word16 lsf_q_num_bits[]; /* Size of each element of the above, in bits Q0*/ extern const Word16 mirror_point_q_cb_fx[]; // Q15 extern const Word16 lsf_grid_fx[4][5]; // Q15 -extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table Q15*/ +extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table Q15*/ extern const Word16 overlap_coefs_fx[NSV_OVERLAP * WIDTH_BAND]; /* in Q15 */ extern const Word16 overlap_coefs_48kHz_fx[NSV_OVERLAP * WIDTH_BAND]; /* in Q15 */ @@ -1133,7 +1133,7 @@ extern const Word16 cldfb_synGain[]; // Q0 extern const Word16 *cldfb_protoFilter_2_5ms[]; // extern const Word16 *cldfb_protoFilter_5_0ms[]; extern const Word16 cldfb_scale_2_5ms[7]; // Q8 -extern const Word16 cldfb_scale_5_0ms[7]; // Q8 + extern const Word32 rot_vec_syn_re_L10_fx[5]; // Q31 extern const Word32 rot_vec_syn_im_L10_fx[5]; // Q31 @@ -1522,7 +1522,7 @@ extern const Word32 pow_tilt_32k[64]; /* Q23 */ extern const Word16 num_nelp_lp_fx[NELP_LP_ORDER + 1]; // Q13 extern const Word16 den_nelp_lp_fx[NELP_LP_ORDER + 1]; // Q13 -extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients Q15*/ +extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients Q15*/ extern const Word16 pwf78_fx[17]; // Q15 enum FUNC_GAIN_ENC @@ -1537,7 +1537,7 @@ enum FUNC_GAIN_ENC extern const Word16 hamcos_window_fx[]; // Q15 extern const Word16 CNG_burst_att_fx[6][8]; // Q15 extern const Word16 lpc_weights_fx[]; // Q15 -extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes Q12*/ +extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes Q12*/ extern const Word16 E_ROM_inter4_1_fx[PIT_UP_SAMP * L_INTERPOL1 + 1]; // Q14 extern const Word16 E_ROM_inter6_1_fx[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; // Q14 extern const Word16 kLog2TableFrac_x[256]; // Q8 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 51d65d9171b7c32b9f5515e02f2869609e76af3f..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -50,13 +50,13 @@ * Table of bitrates *----------------------------------------------------------------------------------*/ -const Word32 brate_tbl[SIZE_BRATE_TBL] = // Q0 +const Word32 brate_tbl[SIZE_BRATE_TBL] = // Q0 { ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_13k20, ACELP_16k40, ACELP_24k40, ACELP_32k, ACELP_48k, ACELP_64k, HQ_96k, HQ_128k }; -const Word32 brate_intermed_tbl[SIZE_BRATE_INTERMED_TBL] = // Q0 +const Word32 brate_intermed_tbl[SIZE_BRATE_INTERMED_TBL] = // Q0 { ACELP_5k00, ACELP_6k15, ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_11k60, ACELP_12k15, ACELP_12k85, ACELP_13k20, ACELP_14k80, ACELP_16k40, ACELP_22k60, ACELP_24k40, ACELP_29k00, ACELP_29k20, ACELP_30k20, @@ -109,7 +109,7 @@ const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB] = * - the other values represent indices created by combining different parameters into a single value through the macro SIG2IND() *----------------------------------------------------------------------------------*/ -const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = // Q0 +const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = // Q0 { /* GENERIC UNVOICED VOICED TRANSITION AUDIO INACTIVE */ ACELP_7k20, 4, @@ -160,7 +160,7 @@ const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = // Q0 *----------------------------------------------------------------------------------*/ /* bit allocation table for end-frame LSF quantizer */ -const Word16 LSF_bits_tbl[] = // Q0 +const Word16 LSF_bits_tbl[] = // Q0 { /* IC UC VC GC TC AC */ 22, 31, 24, 29, 24, 22, /* ACELP_5k00 */ @@ -186,7 +186,7 @@ const Word16 LSF_bits_tbl[] = // Q0 }; /* bit allocation table for mid-frame LSF quantizer */ -const Word16 mid_LSF_bits_tbl[] = // Q0 +const Word16 mid_LSF_bits_tbl[] = // Q0 { /* IC UC VC GC TC AC */ 2, 5, 1, 2, 2, 2, /* ACELP_5k00 */ @@ -213,7 +213,7 @@ const Word16 mid_LSF_bits_tbl[] = // Q0 /* bit allocation table for scaled innovation energy prediction */ -const Word16 Es_pred_bits_tbl[] = // Q0 +const Word16 Es_pred_bits_tbl[] = // Q0 { /* UC VC GC TC */ 0, 0, 0, 4, /* ACELP_5k00 */ @@ -240,7 +240,7 @@ const Word16 Es_pred_bits_tbl[] = // Q0 /* bit allocation table for gain quantizer (ACELP@12.8kHz) */ /* the 4 values allocated correspond to 4 subframes */ -const Word16 gain_bits_tbl[] = // Q0 +const Word16 gain_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 6,6,6,6, 7,6,6,6, 7,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_5k00 */ @@ -261,7 +261,7 @@ const Word16 gain_bits_tbl[] = // Q0 /* bit allocation table for gain gain quantizer (ACELP@16kHz) */ /* the 5 values allocated correspond to 5 subframes */ -const Word16 gain_bits_16kHz_tbl[] = // Q0 +const Word16 gain_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0,0,0,0,0, 6,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, 0, /* ACELP_8k00 */ @@ -279,7 +279,7 @@ const Word16 gain_bits_16kHz_tbl[] = // Q0 /* bit allocation table for adaptive codebook (pitch) (ACELP@12.8kHz) */ /* the 4 values correspond to 4 subframes */ -const Word16 ACB_bits_tbl[] = // Q0 +const Word16 ACB_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_5k00 */ @@ -299,7 +299,7 @@ const Word16 ACB_bits_tbl[] = // Q0 /* bit allocation table for adaptive codebook (pitch) (ACELP@16kHz) */ /* the 5 values correspond to 5 subframes */ -const Word16 ACB_bits_16kHz_tbl[] = // Q0 +const Word16 ACB_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0,0, 0,0,0, 9,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, 0, /* ACELP_8k00 */ @@ -317,7 +317,7 @@ const Word16 ACB_bits_16kHz_tbl[] = // Q0 /* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@12.8kHz) */ /* the 4 values correspond to 4 subframes */ -const Word16 FCB_bits_tbl[] = // Q0 +const Word16 FCB_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 8,8,8,8, 12,12,12,20, 7, 7, 0, 7, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_5k00 */ @@ -337,7 +337,7 @@ const Word16 FCB_bits_tbl[] = // Q0 /* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@16kHz) */ /* the 5 values correspond to 5 subframes */ -const Word16 FCB_bits_16kHz_tbl[] = // Q0 +const Word16 FCB_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 0, 0, 0, 0, 0, 12, 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, 0, /* ACELP_8k00 */ @@ -354,7 +354,7 @@ const Word16 FCB_bits_16kHz_tbl[] = // Q0 }; /* bit allocation table for AVQ bits in active segments (ACELP@16kHz) */ -const Word16 AVQ_bits_16kHz_tbl[] = // Q0 +const Word16 AVQ_bits_16kHz_tbl[] = // Q0 { /* IC GC TC0 TC64 TC128 TC192 TC256 */ 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, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ @@ -371,7 +371,7 @@ const Word16 AVQ_bits_16kHz_tbl[] = // Q0 }; /* bit allocation table for reserved bits (ACELP@12.8kHz) */ -const Word16 reserved_bits_tbl[] = // Q0 +const Word16 reserved_bits_tbl[] = // Q0 { /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_5k00 */ @@ -390,24 +390,24 @@ const Word16 reserved_bits_tbl[] = // Q0 }; /* NRG mode */ -const UWord8 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 +const UWord8 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{0,0,1,1,0,0,0,0},{2,2,1,1,0,0,0,0}}, {{1,1,1,1,0,0,0,0},{1,1,1,1,1,1,1,0}}, }; /* NRG bits : (0/2/3 bits) */ -const UWord8 ACELP_NRG_BITS[3] = { 0, 3, 4 }; // Q0 +const UWord8 ACELP_NRG_BITS[3] = { 0, 3, 4 }; // Q0 /* LTP MODE*/ -const UWord8 ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 +const UWord8 ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{0,0,1,2,0,0,0,0},{0,0,1,2,0,0,0,0}}, {{4,4,3,4,0,0,0,0},{4,4,3,4,8,0,9,0}}, }; /* LTP bits */ -const UWord8 ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = // Q0 +const UWord8 ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = // Q0 { {0,0,0,0,0}, {8,4,4,4,4}, @@ -423,25 +423,25 @@ const UWord8 ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = // Q0 /* LTF modes (0 - LOW_PASS (LP filtering), 1 - FULL_BAND (no filtering), 2 - NORMAL_OPERATION (adaptive)) */ /* Mode 2 ACELP: INACTIVE,UNVOICED,VOICED,GENERIC */ -const UWord8 ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 +const UWord8 ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{1,1,1,0,0,0,0,0},{1,1,1,0,0,0,0,0}}, {{0,0,2,0,0,0,0,0},{0,0,2,0,1,1,1,0}}, }; /* LTF bits */ -const UWord8 ACELP_LTF_BITS[4] = { 0, 0, 4, 0 }; // Q0 +const UWord8 ACELP_LTF_BITS[4] = { 0, 0, 4, 0 }; // Q0 /* GAINS ELEMENT */ /* 5 modes: (EVS: 5b/subframe), (AMRWB: 7b/subframe),(AMRWB: 6b/subframe),(UC: 5b/subframe) */ -const UWord8 ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 +const UWord8 ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{6,6,1,1,0,0,0,0},{7,7,1,1,0,0,0,0}}, {{2,2,3,3,0,0,0,0},{2,2,3,3,3,2,1,0}}, }; /* gains bits */ -const UWord8 ACELP_GAINS_BITS[10] = // Q0 +const UWord8 ACELP_GAINS_BITS[10] = // Q0 { 0, /* skip sub-frame wise gain coding*/ 5, @@ -456,14 +456,14 @@ const UWord8 ACELP_GAINS_BITS[10] = // Q0 }; /* BPF modes (0 - no filtering, 1 - filtering, 2 - adaptive) */ -const UWord8 ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 +const UWord8 ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = // Q0 { {{1,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,0}}, {{1,1,2,2,0,0,0,0},{1,1,2,2,1,1,1,1}}, }; /* BPF bits */ -const UWord8 ACELP_BPF_BITS[3] = { 0, 0, 2 }; // Q0 +const UWord8 ACELP_BPF_BITS[3] = { 0, 0, 2 }; // Q0 const Word16 ACELP_CDK_BITS[ACELP_FIXED_CDK_NB] = { 7, 10, 12, 15, 17, 20, 24, 26, 28, 30, 32, 34, 36, 40, 43, 46, @@ -489,7 +489,7 @@ const Word16 crit_bins_corr_fx[CRIT_NOIS_BAND] = 29491, 29491, 27853, 26214, 25395, 24576, 23577 , 22938, 22118, 21299, 20480, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661 }; -const Word16 crit_bins[CRIT_NOIS_BAND] = // Q0 +const Word16 crit_bins[CRIT_NOIS_BAND] = // Q0 { 4, 4, 4, 4, 4, 5, 6, 6, 6, 8, 8, 10, 11, 13, 15, 18, 22, 16, 16, 20, 20, 20, 16 }; @@ -587,7 +587,7 @@ const Word32 thren_fx[39] = /* Q8 */ 108, 76, 54 }; -const Word16 dicnlg2[40] = // Q0 +const Word16 dicnlg2[40] = // Q0 { 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, @@ -611,30 +611,30 @@ const Word16 inv_mfreq_bindiv_LD_M1_fx[] = { 3641, 3641, 3641, 3641, 3277, 2979, const Word16 post_dct_wind_fx[OFFSET2] = /*Q15 */ { - 32767, 32766, 32759, 32748, 32733, 32713, 32689, 32660, - 32627, 32590, 32548, 32502, 32452, 32397, 32338, 32274, - 32207, 32135, 32059, 31979, 31894, 31805, 31712, 31615, - 31514, 31409, 31300, 31187, 31070, 30949, 30823, 30695, - 30562, 30425, 30285, 30141, 29993, 29841, 29686, 29527, - 29365, 29200, 29030, 28858, 28682, 28503, 28320, 28134, - 27945, 27753, 27558, 27360, 27159, 26955, 26749, 26539, - 26327, 26112, 25894, 25674, 25452, 25226, 24999, 24769, - 24537, 24303, 24067, 23828, 23588, 23345, 23101, 22855, - 22607, 22358, 22107, 21854, 21600, 21345, 21088, 20830, - 20570, 20310, 20049, 19786, 19523, 19258, 18993, 18728, - 18461, 18195, 17927, 17659, 17391, 17123, 16854, 16586, - 16317, 16048, 15779, 15511, 15243, 14975, 14707, 14440, - 14173, 13907, 13642, 13377, 13114, 12851, 12589, 12328, - 12068, 11809, 11552, 11296, 11041, 10787, 10536, 10285, - 10037, 9790, 9545, 9301, 9060, 8820, 8583, 8348, - 8115, 7884, 7655, 7429, 7205, 6983, 6765, 6548, - 6335, 6124, 5916, 5710, 5508, 5308, 5112, 4918, - 4728, 4540, 4356, 4175, 3998, 3824, 3653, 3485, - 3321, 3161, 3004, 2851, 2701, 2555, 2413, 2274, - 2139, 2009, 1882, 1758, 1639, 1524, 1413, 1306, - 1203, 1104, 1009, 918, 831, 749, 671, 597, - 527, 461, 400, 343, 291, 242, 199, 159, - 124, 93, 67, 45, 27, 14, 5, 1 + 32767, 32766, 32759, 32748, 32733, 32713, 32689, 32660, + 32627, 32590, 32548, 32502, 32452, 32397, 32338, 32274, + 32207, 32135, 32059, 31979, 31894, 31805, 31712, 31615, + 31514, 31409, 31300, 31187, 31070, 30949, 30823, 30695, + 30562, 30425, 30285, 30141, 29993, 29841, 29686, 29527, + 29365, 29200, 29030, 28858, 28682, 28503, 28320, 28134, + 27945, 27753, 27558, 27360, 27159, 26955, 26749, 26539, + 26327, 26112, 25894, 25674, 25452, 25226, 24999, 24769, + 24537, 24303, 24067, 23828, 23588, 23345, 23101, 22855, + 22607, 22358, 22107, 21854, 21600, 21345, 21088, 20830, + 20570, 20310, 20049, 19786, 19523, 19258, 18993, 18728, + 18461, 18195, 17927, 17659, 17391, 17123, 16854, 16586, + 16317, 16048, 15779, 15511, 15243, 14975, 14707, 14440, + 14173, 13907, 13642, 13377, 13114, 12851, 12589, 12328, + 12068, 11809, 11552, 11296, 11041, 10787, 10536, 10285, + 10037, 9790, 9545, 9301, 9060, 8820, 8583, 8348, + 8115, 7884, 7655, 7429, 7205, 6983, 6765, 6548, + 6335, 6124, 5916, 5710, 5508, 5308, 5112, 4918, + 4728, 4540, 4356, 4175, 3998, 3824, 3653, 3485, + 3321, 3161, 3004, 2851, 2701, 2555, 2413, 2274, + 2139, 2009, 1882, 1758, 1639, 1524, 1413, 1306, + 1203, 1104, 1009, 918, 831, 749, 671, 597, + 527, 461, 400, 343, 291, 242, 199, 159, + 124, 93, 67, 45, 27, 14, 5, 1 }; const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD] = { 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 17096, 17096, 17096, 17096 };//Q14 @@ -666,22 +666,22 @@ const Word16 wind_sss_fx[LEN_WIN_SSS] = /*window for subsampling*/ const Word16 filter5_39s320_120_fx[121] = /* Q15 */ { - 19968, 19480, 18061, 15834, 12993, 9779, 6458, 3290, - 506, -1713, -3253, -4075, -4212, -3762, -2873, -1720, - -488, 654, 1568, 2160, 2389, 2263, 1838, 1201, - 460, -275, -903, -1348, -1566, -1546, -1312, -914, - -422, 90, 547, 891, 1083, 1108, 975, 716, - 376, 9, -331, -599, -762, -805, -732, -562, - -325, -61, 192, 399, 533, 582, 546, 435, - 272, 83, -103, -259, -366, -413, -398, -328, - -218, -86, 46, 161, 243, 283, 280, 238, - 166, 77, -14, -94, -153, -185, -188, -163, - -119, -62, -3, 50, 90, 113, 117, 104, - 78, 44, 9, -23, -47, -62, -65, -58, - -45, -27, -8, 9, 21, 28, 30, 27, - 20, 13, 5, -2, -7, -9, -9, -8, - -6, -3, -1, 0, 1, 1, 1, 0, - 0 + 19968, 19480, 18061, 15834, 12993, 9779, 6458, 3290, + 506, -1713, -3253, -4075, -4212, -3762, -2873, -1720, + -488, 654, 1568, 2160, 2389, 2263, 1838, 1201, + 460, -275, -903, -1348, -1566, -1546, -1312, -914, + -422, 90, 547, 891, 1083, 1108, 975, 716, + 376, 9, -331, -599, -762, -805, -732, -562, + -325, -61, 192, 399, 533, 582, 546, 435, + 272, 83, -103, -259, -366, -413, -398, -328, + -218, -86, 46, 161, 243, 283, 280, 238, + 166, 77, -14, -94, -153, -185, -188, -163, + -119, -62, -3, 50, 90, 113, 117, 104, + 78, 44, 9, -23, -47, -62, -65, -58, + -45, -27, -8, 9, 21, 28, 30, 27, + 20, 13, 5, -2, -7, -9, -9, -8, + -6, -3, -1, 0, 1, 1, 1, 0, + 0 }; @@ -691,100 +691,100 @@ const Word16 filter5_39s320_120_fx[121] = /* Q15 */ *----------------------------------------------------------------------------------*/ const Word16 Assym_window_W16fx[L_LP] = /*Q15*/ { - 2621, 2624, 2630, 2640, 2655, 2674, 2698, 2725, - 2757, 2792, 2833, 2877, 2925, 2978, 3034, 3095, - 3160, 3229, 3302, 3379, 3460, 3545, 3634, 3727, - 3824, 3925, 4029, 4138, 4250, 4366, 4486, 4609, - 4737, 4867, 5002, 5140, 5281, 5426, 5575, 5727, - 5882, 6040, 6202, 6367, 6535, 6707, 6881, 7059, - 7239, 7422, 7609, 7798, 7990, 8184, 8382, 8581, - 8784, 8989, 9196, 9406, 9618, 9832, 10049, 10268, - 10489, 10711, 10936, 11163, 11391, 11622, 11854, 12087, - 12322, 12559, 12797, 13037, 13278, 13520, 13763, 14007, - 14253, 14499, 14746, 14994, 15243, 15493, 15743, 15994, - 16245, 16496, 16748, 17000, 17253, 17505, 17758, 18010, - 18263, 18515, 18767, 19019, 19270, 19521, 19772, 20022, - 20271, 20519, 20767, 21014, 21260, 21504, 21748, 21991, - 22232, 22473, 22711, 22949, 23185, 23419, 23652, 23883, - 24113, 24340, 24566, 24790, 25012, 25231, 25449, 25664, - 25878, 26089, 26297, 26503, 26707, 26908, 27107, 27303, - 27496, 27687, 27874, 28059, 28241, 28420, 28596, 28769, - 28939, 29105, 29269, 29429, 29586, 29739, 29889, 30036, - 30179, 30319, 30455, 30588, 30717, 30842, 30964, 31082, - 31196, 31306, 31413, 31516, 31615, 31709, 31800, 31888, - 31971, 32050, 32125, 32196, 32263, 32325, 32384, 32439, - 32489, 32535, 32577, 32615, 32649, 32679, 32704, 32725, - 32742, 32755, 32763, 32767, 32767, 32758, 32741, 32715, - 32681, 32638, 32587, 32527, 32458, 32381, 32296, 32203, - 32101, 31991, 31873, 31746, 31612, 31470, 31320, 31162, - 30996, 30823, 30642, 30454, 30259, 30056, 29847, 29630, - 29407, 29177, 28940, 28697, 28448, 28193, 27931, 27664, - 27391, 27113, 26829, 26540, 26246, 25947, 25643, 25335, - 25022, 24706, 24385, 24060, 23732, 23401, 23066, 22728, - 22387, 22043, 21697, 21349, 20999, 20646, 20292, 19937, - 19580, 19223, 18864, 18505, 18145, 17785, 17425, 17065, - 16705, 16346, 15988, 15631, 15275, 14920, 14567, 14215, - 13866, 13519, 13174, 12832, 12492, 12156, 11823, 11493, - 11166, 10844, 10525, 10210, 9900, 9594, 9292, 8996, - 8704, 8418, 8137, 7861, 7591, 7327, 7068, 6816, - 6570, 6330, 6097, 5870, 5650, 5437, 5231, 5032, - 4840, 4656, 4479, 4310, 4148, 3994, 3848, 3709, - 3579, 3457, 3343, 3237, 3139, 3050, 2969, 2896, - 2832, 2776, 2729, 2690, 2660, 2639, 2626, 2621 + 2621, 2624, 2630, 2640, 2655, 2674, 2698, 2725, + 2757, 2792, 2833, 2877, 2925, 2978, 3034, 3095, + 3160, 3229, 3302, 3379, 3460, 3545, 3634, 3727, + 3824, 3925, 4029, 4138, 4250, 4366, 4486, 4609, + 4737, 4867, 5002, 5140, 5281, 5426, 5575, 5727, + 5882, 6040, 6202, 6367, 6535, 6707, 6881, 7059, + 7239, 7422, 7609, 7798, 7990, 8184, 8382, 8581, + 8784, 8989, 9196, 9406, 9618, 9832, 10049, 10268, + 10489, 10711, 10936, 11163, 11391, 11622, 11854, 12087, + 12322, 12559, 12797, 13037, 13278, 13520, 13763, 14007, + 14253, 14499, 14746, 14994, 15243, 15493, 15743, 15994, + 16245, 16496, 16748, 17000, 17253, 17505, 17758, 18010, + 18263, 18515, 18767, 19019, 19270, 19521, 19772, 20022, + 20271, 20519, 20767, 21014, 21260, 21504, 21748, 21991, + 22232, 22473, 22711, 22949, 23185, 23419, 23652, 23883, + 24113, 24340, 24566, 24790, 25012, 25231, 25449, 25664, + 25878, 26089, 26297, 26503, 26707, 26908, 27107, 27303, + 27496, 27687, 27874, 28059, 28241, 28420, 28596, 28769, + 28939, 29105, 29269, 29429, 29586, 29739, 29889, 30036, + 30179, 30319, 30455, 30588, 30717, 30842, 30964, 31082, + 31196, 31306, 31413, 31516, 31615, 31709, 31800, 31888, + 31971, 32050, 32125, 32196, 32263, 32325, 32384, 32439, + 32489, 32535, 32577, 32615, 32649, 32679, 32704, 32725, + 32742, 32755, 32763, 32767, 32767, 32758, 32741, 32715, + 32681, 32638, 32587, 32527, 32458, 32381, 32296, 32203, + 32101, 31991, 31873, 31746, 31612, 31470, 31320, 31162, + 30996, 30823, 30642, 30454, 30259, 30056, 29847, 29630, + 29407, 29177, 28940, 28697, 28448, 28193, 27931, 27664, + 27391, 27113, 26829, 26540, 26246, 25947, 25643, 25335, + 25022, 24706, 24385, 24060, 23732, 23401, 23066, 22728, + 22387, 22043, 21697, 21349, 20999, 20646, 20292, 19937, + 19580, 19223, 18864, 18505, 18145, 17785, 17425, 17065, + 16705, 16346, 15988, 15631, 15275, 14920, 14567, 14215, + 13866, 13519, 13174, 12832, 12492, 12156, 11823, 11493, + 11166, 10844, 10525, 10210, 9900, 9594, 9292, 8996, + 8704, 8418, 8137, 7861, 7591, 7327, 7068, 6816, + 6570, 6330, 6097, 5870, 5650, 5437, 5231, 5032, + 4840, 4656, 4479, 4310, 4148, 3994, 3848, 3709, + 3579, 3457, 3343, 3237, 3139, 3050, 2969, 2896, + 2832, 2776, 2729, 2690, 2660, 2639, 2626, 2621 }; const Word16 assym_window_16k_fx[L_LP_16k] = /*Q15*/ { - 2621, 2623, 2627, 2634, 2643, 2655, 2670, 2688, - 2708, 2731, 2757, 2785, 2816, 2849, 2886, 2925, - 2966, 3011, 3058, 3107, 3159, 3214, 3271, 3331, - 3394, 3459, 3527, 3597, 3670, 3745, 3823, 3903, - 3985, 4071, 4158, 4248, 4341, 4436, 4533, 4632, - 4734, 4839, 4945, 5054, 5165, 5279, 5394, 5512, - 5632, 5754, 5879, 6005, 6134, 6264, 6397, 6531, - 6668, 6807, 6947, 7090, 7234, 7381, 7529, 7679, - 7831, 7984, 8140, 8297, 8455, 8616, 8778, 8941, - 9107, 9273, 9442, 9611, 9782, 9955, 10129, 10304, - 10481, 10659, 10838, 11019, 11200, 11383, 11567, 11752, - 11938, 12125, 12313, 12502, 12693, 12883, 13075, 13268, - 13461, 13655, 13850, 14046, 14242, 14439, 14637, 14835, - 15033, 15232, 15432, 15631, 15832, 16032, 16233, 16434, - 16635, 16837, 17039, 17240, 17442, 17644, 17846, 18048, - 18250, 18452, 18653, 18855, 19056, 19257, 19458, 19658, - 19858, 20058, 20257, 20456, 20654, 20852, 21049, 21245, - 21441, 21637, 21831, 22025, 22218, 22410, 22602, 22792, - 22982, 23170, 23358, 23545, 23730, 23915, 24098, 24280, - 24461, 24641, 24820, 24997, 25173, 25348, 25521, 25693, - 25863, 26032, 26200, 26366, 26530, 26693, 26854, 27014, - 27171, 27328, 27482, 27635, 27786, 27935, 28082, 28227, - 28371, 28513, 28652, 28790, 28926, 29059, 29191, 29320, - 29448, 29573, 29697, 29818, 29937, 30053, 30168, 30280, - 30390, 30498, 30603, 30706, 30807, 30905, 31002, 31095, - 31186, 31275, 31362, 31446, 31527, 31606, 31683, 31757, - 31828, 31897, 31963, 32027, 32088, 32147, 32203, 32257, - 32307, 32356, 32401, 32444, 32484, 32522, 32557, 32589, - 32619, 32646, 32670, 32692, 32711, 32727, 32741, 32751, - 32760, 32765, 32767, 32767, 32762, 32751, 32734, 32712, - 32685, 32652, 32614, 32570, 32521, 32466, 32406, 32341, - 32270, 32194, 32112, 32026, 31934, 31837, 31735, 31627, - 31515, 31398, 31275, 31148, 31016, 30878, 30737, 30590, - 30438, 30282, 30122, 29957, 29787, 29613, 29434, 29252, - 29065, 28874, 28679, 28480, 28277, 28070, 27859, 27644, - 27426, 27205, 26980, 26751, 26520, 26285, 26047, 25805, - 25561, 25314, 25065, 24812, 24557, 24300, 24040, 23777, - 23513, 23246, 22978, 22707, 22435, 22161, 21885, 21608, - 21329, 21049, 20768, 20485, 20202, 19918, 19632, 19347, - 19060, 18773, 18486, 18198, 17911, 17623, 17335, 17047, - 16760, 16473, 16186, 15900, 15614, 15330, 15046, 14763, - 14481, 14200, 13921, 13643, 13367, 13092, 12818, 12547, - 12277, 12010, 11744, 11481, 11220, 10961, 10705, 10451, - 10200, 9951, 9706, 9463, 9223, 8987, 8754, 8523, - 8297, 8073, 7854, 7637, 7425, 7216, 7011, 6810, - 6613, 6420, 6231, 6046, 5865, 5689, 5517, 5350, - 5187, 5028, 4875, 4726, 4581, 4442, 4307, 4177, - 4052, 3932, 3818, 3708, 3603, 3503, 3409, 3320, - 3236, 3157, 3084, 3016, 2953, 2895, 2844, 2797, - 2756, 2720, 2690, 2665, 2646, 2632, 2624, 2621 + 2621, 2623, 2627, 2634, 2643, 2655, 2670, 2688, + 2708, 2731, 2757, 2785, 2816, 2849, 2886, 2925, + 2966, 3011, 3058, 3107, 3159, 3214, 3271, 3331, + 3394, 3459, 3527, 3597, 3670, 3745, 3823, 3903, + 3985, 4071, 4158, 4248, 4341, 4436, 4533, 4632, + 4734, 4839, 4945, 5054, 5165, 5279, 5394, 5512, + 5632, 5754, 5879, 6005, 6134, 6264, 6397, 6531, + 6668, 6807, 6947, 7090, 7234, 7381, 7529, 7679, + 7831, 7984, 8140, 8297, 8455, 8616, 8778, 8941, + 9107, 9273, 9442, 9611, 9782, 9955, 10129, 10304, + 10481, 10659, 10838, 11019, 11200, 11383, 11567, 11752, + 11938, 12125, 12313, 12502, 12693, 12883, 13075, 13268, + 13461, 13655, 13850, 14046, 14242, 14439, 14637, 14835, + 15033, 15232, 15432, 15631, 15832, 16032, 16233, 16434, + 16635, 16837, 17039, 17240, 17442, 17644, 17846, 18048, + 18250, 18452, 18653, 18855, 19056, 19257, 19458, 19658, + 19858, 20058, 20257, 20456, 20654, 20852, 21049, 21245, + 21441, 21637, 21831, 22025, 22218, 22410, 22602, 22792, + 22982, 23170, 23358, 23545, 23730, 23915, 24098, 24280, + 24461, 24641, 24820, 24997, 25173, 25348, 25521, 25693, + 25863, 26032, 26200, 26366, 26530, 26693, 26854, 27014, + 27171, 27328, 27482, 27635, 27786, 27935, 28082, 28227, + 28371, 28513, 28652, 28790, 28926, 29059, 29191, 29320, + 29448, 29573, 29697, 29818, 29937, 30053, 30168, 30280, + 30390, 30498, 30603, 30706, 30807, 30905, 31002, 31095, + 31186, 31275, 31362, 31446, 31527, 31606, 31683, 31757, + 31828, 31897, 31963, 32027, 32088, 32147, 32203, 32257, + 32307, 32356, 32401, 32444, 32484, 32522, 32557, 32589, + 32619, 32646, 32670, 32692, 32711, 32727, 32741, 32751, + 32760, 32765, 32767, 32767, 32762, 32751, 32734, 32712, + 32685, 32652, 32614, 32570, 32521, 32466, 32406, 32341, + 32270, 32194, 32112, 32026, 31934, 31837, 31735, 31627, + 31515, 31398, 31275, 31148, 31016, 30878, 30737, 30590, + 30438, 30282, 30122, 29957, 29787, 29613, 29434, 29252, + 29065, 28874, 28679, 28480, 28277, 28070, 27859, 27644, + 27426, 27205, 26980, 26751, 26520, 26285, 26047, 25805, + 25561, 25314, 25065, 24812, 24557, 24300, 24040, 23777, + 23513, 23246, 22978, 22707, 22435, 22161, 21885, 21608, + 21329, 21049, 20768, 20485, 20202, 19918, 19632, 19347, + 19060, 18773, 18486, 18198, 17911, 17623, 17335, 17047, + 16760, 16473, 16186, 15900, 15614, 15330, 15046, 14763, + 14481, 14200, 13921, 13643, 13367, 13092, 12818, 12547, + 12277, 12010, 11744, 11481, 11220, 10961, 10705, 10451, + 10200, 9951, 9706, 9463, 9223, 8987, 8754, 8523, + 8297, 8073, 7854, 7637, 7425, 7216, 7011, 6810, + 6613, 6420, 6231, 6046, 5865, 5689, 5517, 5350, + 5187, 5028, 4875, 4726, 4581, 4442, 4307, 4177, + 4052, 3932, 3818, 3708, 3603, 3503, 3409, 3320, + 3236, 3157, 3084, 3016, 2953, 2895, 2844, 2797, + 2756, 2720, 2690, 2665, 2646, 2632, 2624, 2621 }; const Word16 lag_window_8k[2][16] = /* LAGW_STRONG Q15*/ @@ -969,38 +969,38 @@ const Word16 sincos_t_fx[161] = { /*Q15 */ 0, - 804, 1607, 2410, 3211, 4011, - 4808, 5602, 6392, 7179, 7961, - 8739, 9512, 10278, 11039, 11793, - 12539, 13278, 14010, 14732, 15446, - 16151, 16846, 17530, 18204, 18868, - 19519, 20159, 20787, 21403, 22005, - 22594, 23170, 23732, 24279, 24812, - 25330, 25832, 26319, 26790, 27245, - 27684, 28106, 28511, 28898, 29269, - 29621, 29956, 30273, 30572, 30852, - 31114, 31357, 31581, 31785, 31971, - 32138, 32285, 32413, 32521, 32610, - 32679, 32728, 32758, 32767, 32758, - 32728, 32679, 32610, 32521, 32413, - 32285, 32138, 31971, 31785, 31581, - 31357, 31114, 30852, 30572, 30273, - 29956, 29621, 29269, 28898, 28511, - 28106, 27684, 27245, 26790, 26319, - 25832, 25330, 24812, 24279, 23732, - 23170, 22594, 22005, 21403, 20787, - 20159, 19519, 18868, 18204, 17530, - 16846, 16151, 15446, 14732, 14010, - 13278, 12539, 11793, 11039, 10278, - 9512, 8739, 7961, 7179, 6392, - 5602, 4808, 4011, 3211, 2410, - 1607, 804, 0, -804, -1607, - -2410, -3211, -4011, -4808, -5602, - -6392, -7179, -7961, -8739, -9512, - -10278, -11039, -11793, -12539, -13278, - -14010, -14732, -15446, -16151, -16846, - -17530, -18204, -18868, -19519, -20159, - -20787, -21403, -22005, -22594, -23170, + 804, 1607, 2410, 3211, 4011, + 4808, 5602, 6392, 7179, 7961, + 8739, 9512, 10278, 11039, 11793, + 12539, 13278, 14010, 14732, 15446, + 16151, 16846, 17530, 18204, 18868, + 19519, 20159, 20787, 21403, 22005, + 22594, 23170, 23732, 24279, 24812, + 25330, 25832, 26319, 26790, 27245, + 27684, 28106, 28511, 28898, 29269, + 29621, 29956, 30273, 30572, 30852, + 31114, 31357, 31581, 31785, 31971, + 32138, 32285, 32413, 32521, 32610, + 32679, 32728, 32758, 32767, 32758, + 32728, 32679, 32610, 32521, 32413, + 32285, 32138, 31971, 31785, 31581, + 31357, 31114, 30852, 30572, 30273, + 29956, 29621, 29269, 28898, 28511, + 28106, 27684, 27245, 26790, 26319, + 25832, 25330, 24812, 24279, 23732, + 23170, 22594, 22005, 21403, 20787, + 20159, 19519, 18868, 18204, 17530, + 16846, 16151, 15446, 14732, 14010, + 13278, 12539, 11793, 11039, 10278, + 9512, 8739, 7961, 7179, 6392, + 5602, 4808, 4011, 3211, 2410, + 1607, 804, 0, -804, -1607, + -2410, -3211, -4011, -4808, -5602, + -6392, -7179, -7961, -8739, -9512, + -10278, -11039, -11793, -12539, -13278, + -14010, -14732, -15446, -16151, -16846, + -17530, -18204, -18868, -19519, -20159, + -20787, -21403, -22005, -22594, -23170, }; @@ -1398,265 +1398,265 @@ const Word16 pitch_inter6_2[PIT_FIR_SIZE6_2] = const Word16 filter_LP12_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ {//Q14 - 16384, 16196, 15641, 14741, 13533, 12067, - 10402, 8604, 6742, 4887, 3105, 1459, - 0, -1230, -2202, -2900, -3322, -3478, - -3392, -3095, -2628, -2037, -1371, -676, - 0, 618, 1143, 1550, 1822, 1954, - 1946, 1811, 1565, 1233, 842, 421, - 0, -394, -736, -1008, -1196, -1294, - -1299, -1217, -1059, -839, -576, -290, - 0, 274, 514, 707, 842, 913, - 920, 865, 755, 600, 413, 208, - 0, -197, -371, -511, -609, -662, - -667, -627, -548, -436, -300, -151, - 0, 143, 270, 371, 443, 481, - 485, 456, 398, 316, 217, 109, - 0, -104, -195, -268, -319, -346, - -348, -326, -284, -225, -155, -78, - 0, 73, 137, 189, 224, 242, - 243, 227, 198, 156, 107, 54, - 0, -50, -94, -128, -151, -163, - -163, -152, -131, -103, -70, -35, - 0, 32, 60, 82, 96, 103, - 102, 95, 81, 64, 43, 21, - 0, -19, -36, -48, -56, -59, - -58, -53, -45, -35, -23, -11, - 0, 10, 18, 24, 28, 29, - 28, 25, 21, 16, 10, 5, - 0, -4, -7, -9, -10, -10, - -9, -8, -6, -5, -3, -1, - 0, 1, 1, 2, 2, 1, - 1, 1, 0, 0, 0, 0, - 0 + 16384, 16196, 15641, 14741, 13533, 12067, + 10402, 8604, 6742, 4887, 3105, 1459, + 0, -1230, -2202, -2900, -3322, -3478, + -3392, -3095, -2628, -2037, -1371, -676, + 0, 618, 1143, 1550, 1822, 1954, + 1946, 1811, 1565, 1233, 842, 421, + 0, -394, -736, -1008, -1196, -1294, + -1299, -1217, -1059, -839, -576, -290, + 0, 274, 514, 707, 842, 913, + 920, 865, 755, 600, 413, 208, + 0, -197, -371, -511, -609, -662, + -667, -627, -548, -436, -300, -151, + 0, 143, 270, 371, 443, 481, + 485, 456, 398, 316, 217, 109, + 0, -104, -195, -268, -319, -346, + -348, -326, -284, -225, -155, -78, + 0, 73, 137, 189, 224, 242, + 243, 227, 198, 156, 107, 54, + 0, -50, -94, -128, -151, -163, + -163, -152, -131, -103, -70, -35, + 0, 32, 60, 82, 96, 103, + 102, 95, 81, 64, 43, 21, + 0, -19, -36, -48, -56, -59, + -58, -53, -45, -35, -23, -11, + 0, 10, 18, 24, 28, 29, + 28, 25, 21, 16, 10, 5, + 0, -4, -7, -9, -10, -10, + -9, -8, -6, -5, -3, -1, + 0, 1, 1, 2, 2, 1, + 1, 1, 0, 0, 0, 0, + 0 }; const Word16 filter_LP12_180H_13b_fx[] = /*Q13 Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )*/ {//Q13 - 8192, 8098, 7820, 7370, 6766, 6033, - 5201, 4302, 3371, 2443, 1553, 729, - 0, -615, -1101, -1450, -1661, -1739, - -1696, -1547, -1314, -1019, -685, -338, - 0, 309, 571, 775, 911, 977, - 973, 905, 783, 616, 421, 210, - 0, -197, -368, -504, -598, -647, - -649, -608, -529, -420, -288, -145, - 0, 137, 257, 353, 421, 457, - 460, 432, 377, 300, 206, 104, - 0, -99, -185, -255, -305, -331, - -333, -314, -274, -218, -150, -76, - 0, 72, 135, 186, 221, 240, - 242, 228, 199, 158, 109, 55, - 0, -52, -97, -134, -159, -173, - -174, -163, -142, -113, -77, -39, - 0, 37, 69, 94, 112, 121, - 121, 114, 99, 78, 53, 27, - 0, -25, -47, -64, -76, -81, - -81, -76, -66, -52, -35, -18, - 0, 16, 30, 41, 48, 52, - 51, 47, 41, 32, 21, 11, - 0, -10, -18, -24, -28, -30, - -29, -27, -23, -17, -12, -6, - 0, 5, 9, 12, 14, 14, - 14, 13, 10, 8, 5, 2, - 0, -2, -4, -5, -5, -5, - -5, -4, -3, -2, -1, -1, - 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, - 0 + 8192, 8098, 7820, 7370, 6766, 6033, + 5201, 4302, 3371, 2443, 1553, 729, + 0, -615, -1101, -1450, -1661, -1739, + -1696, -1547, -1314, -1019, -685, -338, + 0, 309, 571, 775, 911, 977, + 973, 905, 783, 616, 421, 210, + 0, -197, -368, -504, -598, -647, + -649, -608, -529, -420, -288, -145, + 0, 137, 257, 353, 421, 457, + 460, 432, 377, 300, 206, 104, + 0, -99, -185, -255, -305, -331, + -333, -314, -274, -218, -150, -76, + 0, 72, 135, 186, 221, 240, + 242, 228, 199, 158, 109, 55, + 0, -52, -97, -134, -159, -173, + -174, -163, -142, -113, -77, -39, + 0, 37, 69, 94, 112, 121, + 121, 114, 99, 78, 53, 27, + 0, -25, -47, -64, -76, -81, + -81, -76, -66, -52, -35, -18, + 0, 16, 30, 41, 48, 52, + 51, 47, 41, 32, 21, 11, + 0, -10, -18, -24, -28, -30, + -29, -27, -23, -17, -12, -6, + 0, 5, 9, 12, 14, 14, + 14, 13, 10, 8, 5, 2, + 0, -2, -4, -5, -5, -5, + -5, -4, -3, -2, -1, -1, + 0, 0, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, + 0 }; const Word16 filter_LP15_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ {//Q14 - 16384, 16263, 15904, 15317, 14516, 13524, - 12366, 11073, 9678, 8216, 6723, 5236, - 3790, 2416, 1144, 0, -997, -1831, - -2492, -2976, -3285, -3425, -3408, -3248, - -2966, -2583, -2123, -1610, -1070, -526, - 0, 487, 919, 1281, 1564, 1761, - 1869, 1891, 1830, 1695, 1496, 1244, - 954, 641, 318, 0, -300, -569, - -799, -982, -1113, -1188, -1209, -1176, - -1094, -969, -809, -623, -420, -209, - 0, 198, 377, 531, 653, 741, - 793, 807, 786, 732, 649, 543, - 418, 282, 140, 0, -133, -253, - -356, -438, -497, -531, -540, -526, - -489, -433, -362, -278, -187, -93, - 0, 88, 167, 234, 288, 325, - 347, 352, 342, 317, 280, 233, - 179, 120, 59, 0, -56, -105, - -147, -180, -203, -215, -217, -210, - -194, -170, -141, -107, -72, -35, - 0, 33, 61, 85, 103, 116, - 122, 122, 117, 107, 93, 76, - 58, 38, 19, 0, -17, -31, - -43, -51, -57, -59, -58, -55, - -49, -42, -34, -25, -16, -8, - 0, 7, 12, 16, 19, 20, - 21, 20, 18, 16, 13, 10, - 7, 4, 2, 0, -1, -2, - -3, -3, -3, -3, -2, -2, - -1, -1, 0, 0, 0, 0, - 0 + 16384, 16263, 15904, 15317, 14516, 13524, + 12366, 11073, 9678, 8216, 6723, 5236, + 3790, 2416, 1144, 0, -997, -1831, + -2492, -2976, -3285, -3425, -3408, -3248, + -2966, -2583, -2123, -1610, -1070, -526, + 0, 487, 919, 1281, 1564, 1761, + 1869, 1891, 1830, 1695, 1496, 1244, + 954, 641, 318, 0, -300, -569, + -799, -982, -1113, -1188, -1209, -1176, + -1094, -969, -809, -623, -420, -209, + 0, 198, 377, 531, 653, 741, + 793, 807, 786, 732, 649, 543, + 418, 282, 140, 0, -133, -253, + -356, -438, -497, -531, -540, -526, + -489, -433, -362, -278, -187, -93, + 0, 88, 167, 234, 288, 325, + 347, 352, 342, 317, 280, 233, + 179, 120, 59, 0, -56, -105, + -147, -180, -203, -215, -217, -210, + -194, -170, -141, -107, -72, -35, + 0, 33, 61, 85, 103, 116, + 122, 122, 117, 107, 93, 76, + 58, 38, 19, 0, -17, -31, + -43, -51, -57, -59, -58, -55, + -49, -42, -34, -25, -16, -8, + 0, 7, 12, 16, 19, 20, + 21, 20, 18, 16, 13, 10, + 7, 4, 2, 0, -1, -2, + -3, -3, -3, -3, -2, -2, + -1, -1, 0, 0, 0, 0, + 0 }; const Word16 filter_LP15_180H_13b_fx[6 * 31] = /*Q13 Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )'*/ {//Q13 - 8192, 8132, 7952, 7658, 7258, 6762, - 6183, 5536, 4839, 4108, 3362, 2618, - 1895, 1208, 572, 0, -498, -915, - -1246, -1488, -1643, -1713, -1704, -1624, - -1483, -1291, -1061, -805, -535, -263, - 0, 244, 459, 640, 782, 880, - 935, 945, 915, 848, 748, 622, - 477, 320, 159, 0, -150, -285, - -400, -491, -556, -594, -604, -588, - -547, -485, -405, -312, -210, -104, - 0, 99, 189, 265, 327, 371, - 396, 404, 393, 366, 325, 271, - 209, 141, 70, 0, -66, -127, - -178, -219, -248, -266, -270, -263, - -245, -217, -181, -139, -94, -46, - 0, 44, 83, 117, 144, 163, - 173, 176, 171, 158, 140, 116, - 89, 60, 30, 0, -28, -53, - -74, -90, -101, -108, -109, -105, - -97, -85, -70, -54, -36, -18, - 0, 16, 31, 43, 52, 58, - 61, 61, 58, 53, 47, 38, - 29, 19, 9, 0, -8, -16, - -21, -26, -28, -29, -29, -27, - -25, -21, -17, -13, -8, -4, - 0, 3, 6, 8, 10, 10, - 10, 10, 9, 8, 6, 5, - 3, 2, 1, 0, -1, -1, - -1, -2, -2, -1, -1, -1, - -1, 0, 0, 0, 0, 0, - 0 + 8192, 8132, 7952, 7658, 7258, 6762, + 6183, 5536, 4839, 4108, 3362, 2618, + 1895, 1208, 572, 0, -498, -915, + -1246, -1488, -1643, -1713, -1704, -1624, + -1483, -1291, -1061, -805, -535, -263, + 0, 244, 459, 640, 782, 880, + 935, 945, 915, 848, 748, 622, + 477, 320, 159, 0, -150, -285, + -400, -491, -556, -594, -604, -588, + -547, -485, -405, -312, -210, -104, + 0, 99, 189, 265, 327, 371, + 396, 404, 393, 366, 325, 271, + 209, 141, 70, 0, -66, -127, + -178, -219, -248, -266, -270, -263, + -245, -217, -181, -139, -94, -46, + 0, 44, 83, 117, 144, 163, + 173, 176, 171, 158, 140, 116, + 89, 60, 30, 0, -28, -53, + -74, -90, -101, -108, -109, -105, + -97, -85, -70, -54, -36, -18, + 0, 16, 31, 43, 52, 58, + 61, 61, 58, 53, 47, 38, + 29, 19, 9, 0, -8, -16, + -21, -26, -28, -29, -29, -27, + -25, -21, -17, -13, -8, -4, + 0, 3, 6, 8, 10, 10, + 10, 10, 9, 8, 6, 5, + 3, 2, 1, 0, -1, -1, + -1, -2, -2, -1, -1, -1, + -1, 0, 0, 0, 0, 0, + 0 }; const Word16 filter_LP24_90H_fx[] = {//Q14 - 10240, 10208, 10111, 9951, 9731, - 9452, 9119, 8734, 8304, 7834, - 7328, 6794, 6237, 5664, 5081, - 4495, 3913, 3339, 2780, 2241, - 1727, 1242, 791, 376, 0, - -335, -629, -880, -1089, -1256, - -1383, -1471, -1523, -1540, -1527, - -1487, -1422, -1337, -1235, -1119, - -994, -862, -727, -592, -460, - -333, -212, -101, 0, 90, - 167, 232, 285, 325, 354, - 371, 378, 376, 366, 349, - 326, 299, 269, 236, 203, - 171, 139, 109, 81, 56, - 34, 15, 0, -12, -21, - -27, -30, -31, -31, -29, - -26, -22, -18, -14, -10, - -7, -4, -2, -1, 0, - 0, 0, 0, 0, 0, - 0, - 0 + 10240, 10208, 10111, 9951, 9731, + 9452, 9119, 8734, 8304, 7834, + 7328, 6794, 6237, 5664, 5081, + 4495, 3913, 3339, 2780, 2241, + 1727, 1242, 791, 376, 0, + -335, -629, -880, -1089, -1256, + -1383, -1471, -1523, -1540, -1527, + -1487, -1422, -1337, -1235, -1119, + -994, -862, -727, -592, -460, + -333, -212, -101, 0, 90, + 167, 232, 285, 325, 354, + 371, 378, 376, 366, 349, + 326, 299, 269, 236, 203, + 171, 139, 109, 81, 56, + 34, 15, 0, -12, -21, + -27, -30, -31, -31, -29, + -26, -22, -18, -14, -10, + -7, -4, -2, -1, 0, + 0, 0, 0, 0, 0, + 0, + 0 }; const Word16 filter_LP24_90H_13b_fx[] = {//Q13 - 5120, 5104, 5056, 4976, 4865, - 4726, 4559, 4367, 4152, 3917, - 3664, 3397, 3119, 2832, 2541, - 2248, 1956, 1669, 1390, 1120, - 863, 621, 396, 188, 0, - -168, -315, -440, -545, -628, - -691, -735, -761, -770, -764, - -743, -711, -668, -617, -560, - -497, -431, -364, -296, -230, - -166, -106, -51, 0, 45, - 84, 116, 143, 163, 177, - 186, 189, 188, 183, 174, - 163, 149, 134, 118, 102, - 85, 69, 54, 40, 28, - 17, 8, 0, -6, -10, - -13, -15, -16, -15, -14, - -13, -11, -9, -7, -5, - -3, -2, -1, 0, 0, - 0, 0, 0, 0, 0, - 0, - 0 + 5120, 5104, 5056, 4976, 4865, + 4726, 4559, 4367, 4152, 3917, + 3664, 3397, 3119, 2832, 2541, + 2248, 1956, 1669, 1390, 1120, + 863, 621, 396, 188, 0, + -168, -315, -440, -545, -628, + -691, -735, -761, -770, -764, + -743, -711, -668, -617, -560, + -497, -431, -364, -296, -230, + -166, -106, -51, 0, 45, + 84, 116, 143, 163, 177, + 186, 189, 188, 183, 174, + 163, 149, 134, 118, 102, + 85, 69, 54, 40, 28, + 17, 8, 0, -6, -10, + -13, -15, -16, -15, -14, + -13, -11, -9, -7, -5, + -3, -2, -1, 0, 0, + 0, 0, 0, 0, 0, + 0, + 0 }; const Word16 filter_LP3_90H_fx[] = /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ {//Q14 - 16384, 13545, 6766, 0, -3371, -2689, - 0, 1907, 1661, 0, -1314, -1187, - 0, 990, 911, 0, -783, -729, - 0, 638, 598, 0, -529, -499, - 0, 445, 421, 0, -377, -357, - 0, 321, 305, 0, -274, -260, - 0, 234, 221, 0, -199, -188, - 0, 169, 159, 0, -142, -134, - 0, 119, 112, 0, -99, -93, - 0, 81, 76, 0, -66, -61, - 0, 52, 48, 0, -41, -37, - 0, 31, 28, 0, -23, -20, - 0, 16, 14, 0, -10, -9, - 0, 6, 5, 0, -3, -2, - 0, 1, 1, 0, 0, 0, - 0 + 16384, 13545, 6766, 0, -3371, -2689, + 0, 1907, 1661, 0, -1314, -1187, + 0, 990, 911, 0, -783, -729, + 0, 638, 598, 0, -529, -499, + 0, 445, 421, 0, -377, -357, + 0, 321, 305, 0, -274, -260, + 0, 234, 221, 0, -199, -188, + 0, 169, 159, 0, -142, -134, + 0, 119, 112, 0, -99, -93, + 0, 81, 76, 0, -66, -61, + 0, 52, 48, 0, -41, -37, + 0, 31, 28, 0, -23, -20, + 0, 16, 14, 0, -10, -9, + 0, 6, 5, 0, -3, -2, + 0, 1, 1, 0, 0, 0, + 0 }; const Word16 filter_LP15_360H_13b_fx[] = /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ {//Q13 - 8192, 8132, 7954, 7662, 7265, 6772, 6196, 5552, - 4857, 4127, 3381, 2636, 1911, 1220, 579, 0, - -506, -931, -1269, -1519, -1681, -1757, -1752, -1674, - -1533, -1339, -1104, -840, -560, -276, 0, 258, - 488, 682, 836, 946, 1008, 1024, 996, 927, - 821, 687, 529, 357, 178, 0, -170, -325, - -458, -567, -646, -694, -710, -696, -652, -581, - -489, -379, -257, -129, 0, 124, 238, 338, - 420, 481, 518, 533, 523, 492, 440, 372, - 289, 197, 99, 0, -96, -184, -262, -326, - -374, -405, -417, -410, -386, -346, -293, -228, - -156, -78, 0, 76, 147, 209, 260, 299, - 324, 334, 329, 310, 279, 236, 184, 125, - 63, 0, -62, -119, -169, -211, -243, -263, - -271, -268, -252, -227, -192, -150, -102, -52, - 0, 50, 97, 138, 173, 198, 215, 222, - 219, 207, 186, 157, 123, 84, 42, 0, - -41, -80, -113, -142, -163, -176, -182, -180, - -170, -152, -129, -101, -69, -35, 0, 34, - 65, 93, 116, 133, 144, 149, 147, 139, - 125, 106, 82, 56, 28, 0, -28, -53, - -76, -95, -109, -118, -121, -120, -113, -101, - -86, -67, -46, -23, 0, 22, 43, 61, - 77, 88, 95, 98, 97, 91, 82, 69, - 54, 37, 19, 0, -18, -35, -49, -61, - -70, -76, -78, -77, -73, -65, -55, -43, - -29, -15, 0, 14, 27, 39, 48, 55, - 60, 62, 61, 57, 51, 43, 33, 23, - 11, 0, -11, -21, -30, -37, -43, -46, - -48, -47, -44, -39, -33, -26, -17, -9, - 0, 8, 16, 23, 28, 32, 35, 36, - 35, 33, 29, 25, 19, 13, 6, 0, - -6, -12, -17, -21, -24, -25, -26, -25, - -24, -21, -18, -14, -9, -5, 0, 4, - 8, 12, 14, 16, 18, 18, 17, 16, - 14, 12, 9, 6, 3, 0, -3, -6, - -8, -10, -11, -11, -12, -11, -10, -9, - -8, -6, -4, -2, 0, 2, 3, 5, - 6, 6, 7, 7, 7, 6, 5, 4, - 3, 2, 1, 0, -1, -2, -3, -3, - -3, -3, -3, -3, -3, -3, -2, -2, - -1, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0 + 8192, 8132, 7954, 7662, 7265, 6772, 6196, 5552, + 4857, 4127, 3381, 2636, 1911, 1220, 579, 0, + -506, -931, -1269, -1519, -1681, -1757, -1752, -1674, + -1533, -1339, -1104, -840, -560, -276, 0, 258, + 488, 682, 836, 946, 1008, 1024, 996, 927, + 821, 687, 529, 357, 178, 0, -170, -325, + -458, -567, -646, -694, -710, -696, -652, -581, + -489, -379, -257, -129, 0, 124, 238, 338, + 420, 481, 518, 533, 523, 492, 440, 372, + 289, 197, 99, 0, -96, -184, -262, -326, + -374, -405, -417, -410, -386, -346, -293, -228, + -156, -78, 0, 76, 147, 209, 260, 299, + 324, 334, 329, 310, 279, 236, 184, 125, + 63, 0, -62, -119, -169, -211, -243, -263, + -271, -268, -252, -227, -192, -150, -102, -52, + 0, 50, 97, 138, 173, 198, 215, 222, + 219, 207, 186, 157, 123, 84, 42, 0, + -41, -80, -113, -142, -163, -176, -182, -180, + -170, -152, -129, -101, -69, -35, 0, 34, + 65, 93, 116, 133, 144, 149, 147, 139, + 125, 106, 82, 56, 28, 0, -28, -53, + -76, -95, -109, -118, -121, -120, -113, -101, + -86, -67, -46, -23, 0, 22, 43, 61, + 77, 88, 95, 98, 97, 91, 82, 69, + 54, 37, 19, 0, -18, -35, -49, -61, + -70, -76, -78, -77, -73, -65, -55, -43, + -29, -15, 0, 14, 27, 39, 48, 55, + 60, 62, 61, 57, 51, 43, 33, 23, + 11, 0, -11, -21, -30, -37, -43, -46, + -48, -47, -44, -39, -33, -26, -17, -9, + 0, 8, 16, 23, 28, 32, 35, 36, + 35, 33, 29, 25, 19, 13, 6, 0, + -6, -12, -17, -21, -24, -25, -26, -25, + -24, -21, -18, -14, -9, -5, 0, 4, + 8, 12, 14, 16, 18, 18, 17, 16, + 14, 12, 9, 6, 3, 0, -3, -6, + -8, -10, -11, -11, -12, -11, -10, -9, + -8, -6, -4, -2, 0, 2, 3, 5, + 6, 6, 7, 7, 7, 6, 5, 4, + 3, 2, 1, 0, -1, -2, -3, -3, + -3, -3, -3, -3, -3, -3, -2, -2, + -1, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0 }; @@ -1679,33 +1679,33 @@ static const Word16 filter_LP30_300K_fx[LFE_PLC_FDEL + 1] = }; const Resampling_cfg resampling_cfg_tbl[] = -{ +{ /* fin fout up.fact. den.fac. len.out filter coefs. filter length/2 filter mem./2 flags */ { 8000, 12800, 8, 5, 256, /*filter5_39s320_120,*/ filter5_39s320_120_fx, 15, RS_INV_FAC }, - { 12800, 8000, 5, 8, 160, /*filter5_39s320_120,*/ filter5_39s320_120_fx, L_FILT_UP8k, RS_INV_FAC }, - { 16000, 8000, 6, 12, 160, /*filter_LP12_180H,*/ filter_LP12_180H_fx, 180 / 6, 0 }, - { 12800, 16000, 15, 12, 320, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT_UP16k, 0 }, - { 12800, 32000, 15, 6, 640, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT_UP32k, 0 }, - { 12800, 48000, 15, 4, 960, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT_UP48k, 0 }, - + { 12800, 8000, 5, 8, 160, /*filter5_39s320_120,*/ filter5_39s320_120_fx, L_FILT_UP8k, RS_INV_FAC }, + { 16000, 8000, 6, 12, 160, /*filter_LP12_180H,*/ filter_LP12_180H_fx, 180 / 6, 0 }, + { 12800, 16000, 15, 12, 320, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT_UP16k, 0 }, + { 12800, 32000, 15, 6, 640, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT_UP32k, 0 }, + { 12800, 48000, 15, 4, 960, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT_UP48k, 0 }, + { 16000, 12800, 12, 15, 256, /*filter_LP15_180H,*/ filter_LP15_180H_fx, L_FILT16k, 0, }, - { 16000, 32000, 12, 6, 640, /*filter_LP12_180H, */ filter_LP12_180H_fx, L_FILT16k, 0, }, - { 16000, 48000, 12, 4, 960, /*filter_LP12_180H,*/ filter_LP12_180H_fx, L_FILT16k, 0, }, - - { 32000, 12800, 6, 15, 256, /*filter_LP15_180H,*/ filter_LP15_180H_13b_fx, L_FILT32k, 0, }, - { 32000, 16000, 6, 12, 320, /*filter_LP12_180H,*/ filter_LP12_180H_13b_fx, L_FILT32k, 0, }, - { 32000, 25600, 12, 15, 512, /*filter_LP15_360H,*/ filter_LP15_360H_13b_fx, L_FILT32k, 0, }, - { 32000, 48000, 3, 2, 960, /*filter_LP3_90H,*/ filter_LP3_90H_fx, L_FILT32k, 0, }, - - { 48000, 12800, 4, 15, 256, /*filter_LP15_180H,*/ filter_LP15_180H_13b_fx, L_FILT48k, 0, }, - { 48000, 16000, 4, 12, 320, /*filter_LP12_180H,*/ filter_LP12_180H_13b_fx, L_FILT48k, 0, }, - { 48000, 25600, 8, 15, 512, /*filter_LP15_360H,*/ filter_LP15_360H_13b_fx, L_FILT48k, 0, }, - { 48000, 32000, 2, 3, 640, /*filter_LP3_90H,*/ filter_LP3_90H_fx, L_FILT48k, 0, }, - - /* configs with NB 4kHz low-pass */ - { 16000, 12800, 12, 15, 256, /*filter_LP24_90H,*/ filter_LP24_90H_fx, L_FILT16k, 0, }, - { 32000, 12800, 6, 15, 256, /*filter_LP24_90H,*/ filter_LP24_90H_13b_fx, L_FILT32k, 0, }, - { 48000, 12800, 4, 15, 256, /*filter_LP24_90H,*/ filter_LP24_90H_13b_fx, L_FILT48k, 0, }, + { 16000, 32000, 12, 6, 640, /*filter_LP12_180H, */ filter_LP12_180H_fx, L_FILT16k, 0, }, + { 16000, 48000, 12, 4, 960, /*filter_LP12_180H,*/ filter_LP12_180H_fx, L_FILT16k, 0, }, + + { 32000, 12800, 6, 15, 256, /*filter_LP15_180H,*/ filter_LP15_180H_13b_fx, L_FILT32k, 0, }, + { 32000, 16000, 6, 12, 320, /*filter_LP12_180H,*/ filter_LP12_180H_13b_fx, L_FILT32k, 0, }, + { 32000, 25600, 12, 15, 512, /*filter_LP15_360H,*/ filter_LP15_360H_13b_fx, L_FILT32k, 0, }, + { 32000, 48000, 3, 2, 960, /*filter_LP3_90H,*/ filter_LP3_90H_fx, L_FILT32k, 0, }, + + { 48000, 12800, 4, 15, 256, /*filter_LP15_180H,*/ filter_LP15_180H_13b_fx, L_FILT48k, 0, }, + { 48000, 16000, 4, 12, 320, /*filter_LP12_180H,*/ filter_LP12_180H_13b_fx, L_FILT48k, 0, }, + { 48000, 25600, 8, 15, 512, /*filter_LP15_360H,*/ filter_LP15_360H_13b_fx, L_FILT48k, 0, }, + { 48000, 32000, 2, 3, 640, /*filter_LP3_90H,*/ filter_LP3_90H_fx, L_FILT48k, 0, }, + + /* configs with NB 4kHz low-pass */ + { 16000, 12800, 12, 15, 256, /*filter_LP24_90H,*/ filter_LP24_90H_fx, L_FILT16k, 0, }, + { 32000, 12800, 6, 15, 256, /*filter_LP24_90H,*/ filter_LP24_90H_13b_fx, L_FILT32k, 0, }, + { 48000, 12800, 4, 15, 256, /*filter_LP24_90H,*/ filter_LP24_90H_13b_fx, L_FILT48k, 0, }, /* entry for LFE PLC */ { 1600, 48000, 30, 1, 960, /*filter_LP30_300K,*/ filter_LP30_300K_fx, LFE_PLC_FDEL / 30, 0, }, @@ -1743,17 +1743,17 @@ const Word16 interpol_isp_amr_wb_fx[] = { 14746, 26214, 31457, 32767 };/*Q15*/ const Word16 interpol_frac_16k_fx[NB_SUBFR16k] = { 6554, 13107, 19661, 26214, 32767 };//Q15 -const Word16 interpol_frac_mid_fx[NB_SUBFR * 3] = { 16384, 16384, 0,//Q15 - 0, 32767, 0, - 0, 16384, 16384, - 0, 0, 32767 +const Word16 interpol_frac_mid_fx[NB_SUBFR * 3] = { 16384, 16384, 0,//Q15 + 0, 32767, 0, + 0, 16384, 16384, + 0, 0, 32767 };/*Q15*/ -const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3] = { 18022, 14746, 0,//Q15 - 4915, 27853, 0, - 0, 24576, 8192, - 0, 11469, 21299, - 0, 0, 32767 +const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k * 3] = { 18022, 14746, 0,//Q15 + 4915, 27853, 0, + 0, 24576, 8192, + 0, 11469, 21299, + 0, 0, 32767 }; const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR * 3] = { 0, 22938, 9830,//Q15 @@ -1878,134 +1878,134 @@ const UWord32 pulsestostates[17][9] = const Word16 gain_qua_mless_7b_fx[128*2] = {//Q14 - 419, 28, - 1499, 607, - 1586, 322, - 1632, 144, - 1686, 229, - 1745, 495, - 2182, 409, - 2515, 716, - 2772, 824, - 3069, 1069, - 3211, 936, - 3218, 89, - 3477, 1244, - 3755, 272, - 3865, 549, - 3881, 348, - 4171, 181, - 4414, 627, - 4419, 472, - 4909, 1429, - 5238, 404, - 5241, 1651, - 5721, 85, - 5833, 250, - 5846, 693, - 5897, 325, - 6036, 544, - 6088, 779, - 6459, 1889, - 6650, 157, - 6678, 462, - 6798, 879, - 6922, 993, - 6929, 1130, - 7352, 620, - 7461, 386, - 7864, 232, - 7999, 314, - 8136, 536, - 8398, 712, - 8680, 459, - 8797, 1276, - 9046, 806, - 9198, 86, - 9434, 398, - 9730, 587, - 9735, 267, - 9742, 175, - 9917, 917, - 10042, 509, - 10053, 655, - 10132, 1030, - 10238, 339, - 10694, 1560, - 10817, 447, - 10964, 723, - 11405, 1149, - 11526, 549, - 11582, 386, - 11602, 791, - 11618, 286, - 11883, 862, - 11954, 607, - 12057, 214, - 12104, 496, - 12170, 1397, - 12437, 668, - 12616, 335, - 12668, 952, - 12684, 435, - 12983, 112, - 13235, 742, - 13399, 549, - 13525, 380, - 13527, 270, - 13625, 1044, - 13733, 482, - 13820, 617, - 14036, 817, - 14041, 1257, - 14295, 425, - 14346, 684, - 14367, 319, - 14416, 199, - 14644, 898, - 14944, 518, - 15090, 364, - 15154, 578, - 15309, 462, - 15360, 1933, - 15362, 756, - 15381, 262, - 15566, 1127, - 15699, 639, - 15804, 410, - 16081, 316, - 16161, 993, - 16359, 701, - 16451, 828, - 16500, 543, - 16540, 491, - 16617, 1729, - 16630, 196, - 16749, 369, - 16959, 1530, - 17028, 442, - 17139, 603, - 17369, 898, - 17393, 268, - 17972, 763, - 17985, 1361, - 18016, 333, - 18032, 667, - 18234, 406, - 18270, 105, - 18299, 554, - 18342, 488, - 18747, 1207, - 19027, 1073, - 19530, 216, - 19566, 963, - 19751, 835, - 19794, 615, - 19810, 298, - 19988, 710, - 19990, 449, - 20005, 374, - 20149, 531, + 419, 28, + 1499, 607, + 1586, 322, + 1632, 144, + 1686, 229, + 1745, 495, + 2182, 409, + 2515, 716, + 2772, 824, + 3069, 1069, + 3211, 936, + 3218, 89, + 3477, 1244, + 3755, 272, + 3865, 549, + 3881, 348, + 4171, 181, + 4414, 627, + 4419, 472, + 4909, 1429, + 5238, 404, + 5241, 1651, + 5721, 85, + 5833, 250, + 5846, 693, + 5897, 325, + 6036, 544, + 6088, 779, + 6459, 1889, + 6650, 157, + 6678, 462, + 6798, 879, + 6922, 993, + 6929, 1130, + 7352, 620, + 7461, 386, + 7864, 232, + 7999, 314, + 8136, 536, + 8398, 712, + 8680, 459, + 8797, 1276, + 9046, 806, + 9198, 86, + 9434, 398, + 9730, 587, + 9735, 267, + 9742, 175, + 9917, 917, + 10042, 509, + 10053, 655, + 10132, 1030, + 10238, 339, + 10694, 1560, + 10817, 447, + 10964, 723, + 11405, 1149, + 11526, 549, + 11582, 386, + 11602, 791, + 11618, 286, + 11883, 862, + 11954, 607, + 12057, 214, + 12104, 496, + 12170, 1397, + 12437, 668, + 12616, 335, + 12668, 952, + 12684, 435, + 12983, 112, + 13235, 742, + 13399, 549, + 13525, 380, + 13527, 270, + 13625, 1044, + 13733, 482, + 13820, 617, + 14036, 817, + 14041, 1257, + 14295, 425, + 14346, 684, + 14367, 319, + 14416, 199, + 14644, 898, + 14944, 518, + 15090, 364, + 15154, 578, + 15309, 462, + 15360, 1933, + 15362, 756, + 15381, 262, + 15566, 1127, + 15699, 639, + 15804, 410, + 16081, 316, + 16161, 993, + 16359, 701, + 16451, 828, + 16500, 543, + 16540, 491, + 16617, 1729, + 16630, 196, + 16749, 369, + 16959, 1530, + 17028, 442, + 17139, 603, + 17369, 898, + 17393, 268, + 17972, 763, + 17985, 1361, + 18016, 333, + 18032, 667, + 18234, 406, + 18270, 105, + 18299, 554, + 18342, 488, + 18747, 1207, + 19027, 1073, + 19530, 216, + 19566, 963, + 19751, 835, + 19794, 615, + 19810, 298, + 19988, 710, + 19990, 449, + 20005, 374, + 20149, 531, }; const Word16 gain_qua_mless_6b_stereo_fx[64 * 2] = @@ -2078,106 +2078,106 @@ const Word16 gain_qua_mless_6b_stereo_fx[64 * 2] = const Word16 gain_qua_mless_6b_fx[64 * 2] = {//Q14 - 1676, 71, - 2128, 198, - 2318, 491, - 2348, 339, - 2798, 625, - 2893, 785, - 3911, 1099, - 4779, 244, - 4781, 427, - 5115, 935, - 5294, 1509, - 5767, 114, - 6018, 543, - 6152, 335, - 6205, 675, - 6234, 1822, - 6740, 1251, - 7034, 802, - 7782, 434, - 8005, 230, - 9232, 622, - 9337, 336, - 9388, 520, - 9770, 1038, - 9865, 734, - 10224, 879, - 10617, 118, - 10776, 426, - 11518, 249, - 11708, 1399, - 12044, 587, - 12270, 501, - 12277, 348, - 12498, 684, - 13020, 786, - 13097, 1196, - 13530, 422, - 13818, 917, - 14123, 290, - 14500, 1039, - 14538, 636, - 14636, 556, - 14667, 484, - 14931, 362, - 15055, 210, - 15653, 1594, - 15830, 1874, - 15868, 717, - 15897, 828, - 16153, 434, - 16540, 294, - 16874, 608, - 16936, 513, - 17182, 373, - 17644, 1337, - 17696, 126, - 18342, 1122, - 18461, 944, - 18991, 242, - 19114, 795, - 19187, 674, - 19256, 449, - 19485, 557, - 19515, 344, + 1676, 71, + 2128, 198, + 2318, 491, + 2348, 339, + 2798, 625, + 2893, 785, + 3911, 1099, + 4779, 244, + 4781, 427, + 5115, 935, + 5294, 1509, + 5767, 114, + 6018, 543, + 6152, 335, + 6205, 675, + 6234, 1822, + 6740, 1251, + 7034, 802, + 7782, 434, + 8005, 230, + 9232, 622, + 9337, 336, + 9388, 520, + 9770, 1038, + 9865, 734, + 10224, 879, + 10617, 118, + 10776, 426, + 11518, 249, + 11708, 1399, + 12044, 587, + 12270, 501, + 12277, 348, + 12498, 684, + 13020, 786, + 13097, 1196, + 13530, 422, + 13818, 917, + 14123, 290, + 14500, 1039, + 14538, 636, + 14636, 556, + 14667, 484, + 14931, 362, + 15055, 210, + 15653, 1594, + 15830, 1874, + 15868, 717, + 15897, 828, + 16153, 434, + 16540, 294, + 16874, 608, + 16936, 513, + 17182, 373, + 17644, 1337, + 17696, 126, + 18342, 1122, + 18461, 944, + 18991, 242, + 19114, 795, + 19187, 674, + 19256, 449, + 19485, 557, + 19515, 344, }; const Word16 gain_qua_mless_5b_fx[32 * 2] = {//Q14 - 2695, 109, - 3444, 271, - 3529, 433, - 4284, 801, - 4365, 607, - 4935, 1089, - 6896, 1407, - 7722, 324, - 7913, 146, - 8090, 468, - 9049, 913, - 9499, 600, - 9894, 741, - 9942, 1840, - 11906, 382, - 12008, 1103, - 12349, 243, - 12429, 501, - 13687, 630, - 13974, 896, - 14510, 748, - 15160, 322, - 15424, 428, - 15679, 541, - 15832, 1574, - 15999, 1281, - 17223, 211, - 17719, 1029, - 18185, 649, - 18432, 818, - 18638, 353, - 18889, 493, + 2695, 109, + 3444, 271, + 3529, 433, + 4284, 801, + 4365, 607, + 4935, 1089, + 6896, 1407, + 7722, 324, + 7913, 146, + 8090, 468, + 9049, 913, + 9499, 600, + 9894, 741, + 9942, 1840, + 11906, 382, + 12008, 1103, + 12349, 243, + 12429, 501, + 13687, 630, + 13974, 896, + 14510, 748, + 15160, 322, + 15424, 428, + 15679, 541, + 15832, 1574, + 15999, 1281, + 17223, 211, + 17719, 1029, + 18185, 649, + 18432, 818, + 18638, 353, + 18889, 493, }; const Word16 E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2]= @@ -2681,7 +2681,7 @@ const Word16 Es_pred_qua_4b_fx[16] = 5742, 6821, 7834, - /*8779, */ + /*8779, */ 8778, 9701, 10610, @@ -3017,798 +3017,798 @@ const Word16 gp_gamma_4sfr_7b_fx[2 * 128] = /*Q14/Q9 */ const Word16 gp_gamma_1sfr_8b_fx[2 * 256] = /*Q14/Q9 */ { - 305, 152, - 333, 37, - 352, 556, - 573, 82, - 652, 12, - 694, 207, - 808, 389, - 915, 776, - 986, 1089, - 987, 1583, - 1055, 60, - 1202, 2779, - 1205, 20, - 1346, 127, - 1432, 332, - 1689, 6554, - 1715, 261, - 1820, 49, - 2041, 698, - 2179, 4032, - 2199, 100, - 2272, 1303, - 2317, 461, - 2340, 175, - 2562, 26, - 2574, 14814, - 2657, 2101, - 2732, 66, - 2818, 9, - 2836, 296, - 2929, 938, - 3479, 130, - 3510, 220, - 3651, 3154, - 3667, 717, - 3720, 384, - 3783, 530, - 3811, 10744, - 3883, 5385, - 3941, 1609, - 3964, 46, - 4120, 80, - 4402, 15, - 4440, 1181, - 4485, 173, - 4740, 311, - 4848, 31, - 5125, 7642, - 5147, 110, - 5167, 908, - 5237, 252, - 5323, 623, - 5376, 2514, - 5590, 7, - 5595, 4475, - 5634, 64, - 5654, 461, - 5822, 22, - 5893, 140, - 5905, 1810, - 6177, 367, - 6268, 201, - 6352, 1092, - 6567, 752, - 6626, 50, - 6734, 95, - 6758, 295, - 6882, 3085, - 6962, 1363, - 7274, 540, - 7413, 166, - 7635, 2120, - 7642, 38, - 7671, 393, - 7730, 227, - 7860, 75, - 7980, 115, - 8011, 955, - 8092, 3687, - 8120, 17, - 8146, 5902, - 8453, 672, - 8524, 1602, - 8583, 58, - 8679, 275, - 8873, 332, - 8920, 454, - 8969, 9712, - 9129, 2566, - 9159, 196, - 9193, 1127, - 9219, 142, - 9300, 9, - 9302, 828, - 9409, 91, - 9736, 26, - 9872, 574, - 10066, 246, - 10131, 1352, - 10154, 1971, - 10196, 399, - 10238, 15785, - 10255, 4254, - 10401, 67, - 10439, 43, - 10511, 116, - 10531, 7399, - 10706, 998, - 10798, 722, - 10845, 171, - 10848, 304, - 10876, 2981, - 11069, 28204, - 11139, 507, - 11280, 12, - 11427, 388, - 11459, 214, - 11647, 1174, - 11710, 5061, - 11742, 1614, - 11793, 806, - 11816, 82, - 11890, 132, - 11996, 2301, - 12000, 603, - 12060, 55, - 12232, 256, - 12299, 33, - 12438, 338, - 12452, 458, - 12627, 3563, - 12646, 9489, - 12665, 934, - 12801, 1329, - 12802, 190, - 12877, 683, - 12941, 103, - 13038, 1890, - 13209, 6209, - 13222, 12674, - 13318, 21, - 13374, 283, - 13385, 149, - 13391, 383, - 13453, 545, - 13564, 1064, - 13596, 2561, - 13771, 810, - 13834, 1481, - 13874, 69, - 14027, 226, - 14093, 4429, - 14147, 7, - 14171, 609, - 14185, 47, - 14223, 3051, - 14273, 434, - 14321, 314, - 14415, 120, - 14443, 1252, - 14500, 173, - 14557, 933, - 14616, 1696, - 14639, 8229, - 14724, 89, - 14837, 703, - 14902, 2072, - 14917, 366, - 15000, 487, - 15009, 30, - 15095, 256, - 15138, 1119, - 15228, 3580, - 15371, 1386, - 15387, 5525, - 15398, 17932, - 15462, 149, - 15471, 791, - 15551, 569, - 15554, 2467, - 15559, 201, - 15616, 14, - 15664, 319, - 15798, 401, - 15811, 974, - 15874, 41, - 15929, 1649, - 15945, 79, - 16046, 111, - 16225, 647, - 16230, 1240, - 16297, 4110, - 16328, 10499, - 16331, 278, - 16355, 3003, - 16383, 455, - 16404, 169, - 16435, 2172, - 16438, 850, - 16745, 7090, - 16776, 354, - 16801, 1063, - 16803, 62, - 16812, 223, - 16927, 530, - 16951, 721, - 17039, 1447, - 17208, 1837, - 17233, 135, - 17371, 4642, - 17570, 406, - 17608, 267, - 17696, 906, - 17702, 2529, - 17705, 23239, - 17709, 1209, - 17745, 592, - 17800, 92, - 17858, 35, - 17860, 3360, - 17866, 9, - 17978, 184, - 18035, 321, - 18255, 754, - 18274, 480, - 18320, 18, - 18406, 55, - 18582, 13017, - 18677, 1516, - 18726, 1998, - 18904, 25, - 18914, 6103, - 19020, 8567, - 19022, 1116, - 19025, 349, - 19147, 239, - 19224, 604, - 19251, 160, - 19270, 4870, - 19358, 3789, - 19394, 126, - 19394, 103, - 19433, 72, - 19444, 46, - 19448, 2842, - 19489, 430, - 19575, 815, - 19628, 1306, - 19631, 972, - 19637, 202, - 19642, 289, - 19660, 527, - 19717, 1697, - 19731, 2263, - 19754, 676, - 19854, 382, + 305, 152, + 333, 37, + 352, 556, + 573, 82, + 652, 12, + 694, 207, + 808, 389, + 915, 776, + 986, 1089, + 987, 1583, + 1055, 60, + 1202, 2779, + 1205, 20, + 1346, 127, + 1432, 332, + 1689, 6554, + 1715, 261, + 1820, 49, + 2041, 698, + 2179, 4032, + 2199, 100, + 2272, 1303, + 2317, 461, + 2340, 175, + 2562, 26, + 2574, 14814, + 2657, 2101, + 2732, 66, + 2818, 9, + 2836, 296, + 2929, 938, + 3479, 130, + 3510, 220, + 3651, 3154, + 3667, 717, + 3720, 384, + 3783, 530, + 3811, 10744, + 3883, 5385, + 3941, 1609, + 3964, 46, + 4120, 80, + 4402, 15, + 4440, 1181, + 4485, 173, + 4740, 311, + 4848, 31, + 5125, 7642, + 5147, 110, + 5167, 908, + 5237, 252, + 5323, 623, + 5376, 2514, + 5590, 7, + 5595, 4475, + 5634, 64, + 5654, 461, + 5822, 22, + 5893, 140, + 5905, 1810, + 6177, 367, + 6268, 201, + 6352, 1092, + 6567, 752, + 6626, 50, + 6734, 95, + 6758, 295, + 6882, 3085, + 6962, 1363, + 7274, 540, + 7413, 166, + 7635, 2120, + 7642, 38, + 7671, 393, + 7730, 227, + 7860, 75, + 7980, 115, + 8011, 955, + 8092, 3687, + 8120, 17, + 8146, 5902, + 8453, 672, + 8524, 1602, + 8583, 58, + 8679, 275, + 8873, 332, + 8920, 454, + 8969, 9712, + 9129, 2566, + 9159, 196, + 9193, 1127, + 9219, 142, + 9300, 9, + 9302, 828, + 9409, 91, + 9736, 26, + 9872, 574, + 10066, 246, + 10131, 1352, + 10154, 1971, + 10196, 399, + 10238, 15785, + 10255, 4254, + 10401, 67, + 10439, 43, + 10511, 116, + 10531, 7399, + 10706, 998, + 10798, 722, + 10845, 171, + 10848, 304, + 10876, 2981, + 11069, 28204, + 11139, 507, + 11280, 12, + 11427, 388, + 11459, 214, + 11647, 1174, + 11710, 5061, + 11742, 1614, + 11793, 806, + 11816, 82, + 11890, 132, + 11996, 2301, + 12000, 603, + 12060, 55, + 12232, 256, + 12299, 33, + 12438, 338, + 12452, 458, + 12627, 3563, + 12646, 9489, + 12665, 934, + 12801, 1329, + 12802, 190, + 12877, 683, + 12941, 103, + 13038, 1890, + 13209, 6209, + 13222, 12674, + 13318, 21, + 13374, 283, + 13385, 149, + 13391, 383, + 13453, 545, + 13564, 1064, + 13596, 2561, + 13771, 810, + 13834, 1481, + 13874, 69, + 14027, 226, + 14093, 4429, + 14147, 7, + 14171, 609, + 14185, 47, + 14223, 3051, + 14273, 434, + 14321, 314, + 14415, 120, + 14443, 1252, + 14500, 173, + 14557, 933, + 14616, 1696, + 14639, 8229, + 14724, 89, + 14837, 703, + 14902, 2072, + 14917, 366, + 15000, 487, + 15009, 30, + 15095, 256, + 15138, 1119, + 15228, 3580, + 15371, 1386, + 15387, 5525, + 15398, 17932, + 15462, 149, + 15471, 791, + 15551, 569, + 15554, 2467, + 15559, 201, + 15616, 14, + 15664, 319, + 15798, 401, + 15811, 974, + 15874, 41, + 15929, 1649, + 15945, 79, + 16046, 111, + 16225, 647, + 16230, 1240, + 16297, 4110, + 16328, 10499, + 16331, 278, + 16355, 3003, + 16383, 455, + 16404, 169, + 16435, 2172, + 16438, 850, + 16745, 7090, + 16776, 354, + 16801, 1063, + 16803, 62, + 16812, 223, + 16927, 530, + 16951, 721, + 17039, 1447, + 17208, 1837, + 17233, 135, + 17371, 4642, + 17570, 406, + 17608, 267, + 17696, 906, + 17702, 2529, + 17705, 23239, + 17709, 1209, + 17745, 592, + 17800, 92, + 17858, 35, + 17860, 3360, + 17866, 9, + 17978, 184, + 18035, 321, + 18255, 754, + 18274, 480, + 18320, 18, + 18406, 55, + 18582, 13017, + 18677, 1516, + 18726, 1998, + 18904, 25, + 18914, 6103, + 19020, 8567, + 19022, 1116, + 19025, 349, + 19147, 239, + 19224, 604, + 19251, 160, + 19270, 4870, + 19358, 3789, + 19394, 126, + 19394, 103, + 19433, 72, + 19444, 46, + 19448, 2842, + 19489, 430, + 19575, 815, + 19628, 1306, + 19631, 972, + 19637, 202, + 19642, 289, + 19660, 527, + 19717, 1697, + 19731, 2263, + 19754, 676, + 19854, 382, }; const Word16 gp_gamma_1sfr_7b_fx[2 * 128] = /*Q14/Q9 */ { - 350, 85, - 428, 24, - 438, 681, - 642, 195, - 1071, 2012, - 1080, 402, - 1148, 1236, - 1159, 62, - 1424, 12, - 1662, 134, - 1985, 299, - 2100, 34, - 2163, 3168, - 2219, 538, - 2393, 6580, - 2499, 967, - 2882, 221, - 2974, 12743, - 3251, 98, - 3294, 51, - 3586, 1560, - 3711, 411, - 3721, 700, - 3862, 21, - 3947, 169, - 4001, 2249, - 4198, 4632, - 4372, 8, - 4993, 70, - 5022, 265, - 5568, 1194, - 5664, 495, - 5698, 115, - 5885, 854, - 6115, 2990, - 6266, 153, - 6376, 39, - 6432, 16, - 6601, 345, - 7108, 1957, - 7231, 660, - 7491, 202, - 7687, 93, - 8054, 3882, - 8108, 9624, - 8186, 1424, - 8243, 59, - 8354, 935, - 8358, 6401, - 8383, 439, - 8794, 285, - 8940, 124, - 9643, 25, - 9643, 581, - 9670, 2709, - 10065, 160, - 10218, 9, - 10240, 1728, - 10249, 80, - 10418, 1113, - 10497, 373, - 10650, 236, - 11095, 44, - 11095, 756, - 11284, 4978, - 11290, 16722, - 11815, 2299, - 11882, 482, - 12059, 114, - 12332, 8550, - 12363, 1394, - 12392, 186, - 12517, 336, - 12549, 3413, - 12694, 953, - 13096, 614, - 13185, 71, - 13247, 262, - 13479, 1914, - 13791, 14, - 13805, 30, - 14064, 138, - 14182, 420, - 14212, 1175, - 14477, 765, - 14605, 2745, - 14612, 6324, - 14730, 4199, - 14833, 301, - 14842, 203, - 14910, 12790, - 15171, 100, - 15191, 1625, - 15289, 532, - 15405, 52, - 15550, 985, - 16096, 357, - 16175, 2113, - 16284, 232, - 16333, 669, - 16363, 22999, - 16396, 156, - 16443, 1270, - 16455, 3482, - 16543, 8, - 16650, 5425, - 16878, 452, - 16989, 84, - 17024, 9676, - 17194, 876, - 17730, 20, - 17780, 1442, - 17864, 38, - 17874, 254, - 17929, 526, - 18011, 2403, - 18751, 7153, - 18786, 117, - 18820, 4420, - 19002, 63, - 19099, 401, - 19111, 183, - 19197, 776, - 19202, 2953, - 19236, 1052, - 19255, 301, - 19354, 1760, - 19432, 593, + 350, 85, + 428, 24, + 438, 681, + 642, 195, + 1071, 2012, + 1080, 402, + 1148, 1236, + 1159, 62, + 1424, 12, + 1662, 134, + 1985, 299, + 2100, 34, + 2163, 3168, + 2219, 538, + 2393, 6580, + 2499, 967, + 2882, 221, + 2974, 12743, + 3251, 98, + 3294, 51, + 3586, 1560, + 3711, 411, + 3721, 700, + 3862, 21, + 3947, 169, + 4001, 2249, + 4198, 4632, + 4372, 8, + 4993, 70, + 5022, 265, + 5568, 1194, + 5664, 495, + 5698, 115, + 5885, 854, + 6115, 2990, + 6266, 153, + 6376, 39, + 6432, 16, + 6601, 345, + 7108, 1957, + 7231, 660, + 7491, 202, + 7687, 93, + 8054, 3882, + 8108, 9624, + 8186, 1424, + 8243, 59, + 8354, 935, + 8358, 6401, + 8383, 439, + 8794, 285, + 8940, 124, + 9643, 25, + 9643, 581, + 9670, 2709, + 10065, 160, + 10218, 9, + 10240, 1728, + 10249, 80, + 10418, 1113, + 10497, 373, + 10650, 236, + 11095, 44, + 11095, 756, + 11284, 4978, + 11290, 16722, + 11815, 2299, + 11882, 482, + 12059, 114, + 12332, 8550, + 12363, 1394, + 12392, 186, + 12517, 336, + 12549, 3413, + 12694, 953, + 13096, 614, + 13185, 71, + 13247, 262, + 13479, 1914, + 13791, 14, + 13805, 30, + 14064, 138, + 14182, 420, + 14212, 1175, + 14477, 765, + 14605, 2745, + 14612, 6324, + 14730, 4199, + 14833, 301, + 14842, 203, + 14910, 12790, + 15171, 100, + 15191, 1625, + 15289, 532, + 15405, 52, + 15550, 985, + 16096, 357, + 16175, 2113, + 16284, 232, + 16333, 669, + 16363, 22999, + 16396, 156, + 16443, 1270, + 16455, 3482, + 16543, 8, + 16650, 5425, + 16878, 452, + 16989, 84, + 17024, 9676, + 17194, 876, + 17730, 20, + 17780, 1442, + 17864, 38, + 17874, 254, + 17929, 526, + 18011, 2403, + 18751, 7153, + 18786, 117, + 18820, 4420, + 19002, 63, + 19099, 401, + 19111, 183, + 19197, 776, + 19202, 2953, + 19236, 1052, + 19255, 301, + 19354, 1760, + 19432, 593, }; const Word16 gp_gamma_1sfr_6b_fx[2 * 64] = /*Q14/Q9 */ { - 436, 182, - 473, 63, - 962, 16, - 992, 647, - 1258, 1582, - 1447, 351, - 1711, 125, - 1809, 46, - 2569, 4173, - 2607, 957, - 2826, 251, - 2904, 12481, - 3248, 26, - 3594, 2254, - 3664, 78, - 3715, 483, - 4232, 8, - 4681, 188, - 5066, 6623, - 5232, 1273, - 6232, 695, - 6234, 49, - 6238, 113, - 6312, 318, - 7012, 17, - 7327, 3183, - 8008, 1739, - 8692, 446, - 8769, 163, - 8923, 1019, - 9094, 81, - 10358, 286, - 10491, 28, - 10612, 9788, - 10715, 760, - 11045, 4822, - 11319, 2403, - 11684, 56, - 12314, 108, - 12460, 556, - 12580, 9, - 12716, 213, - 12821, 1336, - 14202, 374, - 14325, 16971, - 14612, 838, - 14625, 3285, - 14668, 6231, - 14919, 39, - 15131, 137, - 15476, 1847, - 16056, 255, - 16277, 494, - 16290, 66, - 16582, 1048, - 16859, 17, - 17220, 8723, - 17443, 4295, - 18069, 2499, - 18212, 176, - 18499, 91, - 18517, 1445, - 18522, 332, - 18596, 663, + 436, 182, + 473, 63, + 962, 16, + 992, 647, + 1258, 1582, + 1447, 351, + 1711, 125, + 1809, 46, + 2569, 4173, + 2607, 957, + 2826, 251, + 2904, 12481, + 3248, 26, + 3594, 2254, + 3664, 78, + 3715, 483, + 4232, 8, + 4681, 188, + 5066, 6623, + 5232, 1273, + 6232, 695, + 6234, 49, + 6238, 113, + 6312, 318, + 7012, 17, + 7327, 3183, + 8008, 1739, + 8692, 446, + 8769, 163, + 8923, 1019, + 9094, 81, + 10358, 286, + 10491, 28, + 10612, 9788, + 10715, 760, + 11045, 4822, + 11319, 2403, + 11684, 56, + 12314, 108, + 12460, 556, + 12580, 9, + 12716, 213, + 12821, 1336, + 14202, 374, + 14325, 16971, + 14612, 838, + 14625, 3285, + 14668, 6231, + 14919, 39, + 15131, 137, + 15476, 1847, + 16056, 255, + 16277, 494, + 16290, 66, + 16582, 1048, + 16859, 17, + 17220, 8723, + 17443, 4295, + 18069, 2499, + 18212, 176, + 18499, 91, + 18517, 1445, + 18522, 332, + 18596, 663, }; const Word16 gp_gamma_2sfr_7b_fx[2 * 128] = /*Q14/Q9 */ { - 99, 1224, - 156, 243, - 168, 579, - 290, 355, - 437, 441, - 475, 187, - 734, 738, - 930, 93, - 1133, 153, - 1136, 298, - 1490, 508, - 1946, 401, - 1978, 16790, - 2098, 224, - 2117, 962, - 2407, 119, - 2686, 339, - 2929, 555, - 3404, 271, - 3465, 171, - 3469, 422, - 3714, 663, - 4436, 494, - 4494, 332, - 4571, 220, - 4583, 2182, - 4997, 848, - 5346, 380, - 5419, 108, - 5570, 579, - 5758, 266, - 5875, 442, - 5927, 170, - 6204, 3338, - 6394, 6435, - 6515, 328, - 6638, 730, - 6687, 1472, - 7045, 1056, - 7101, 498, - 7123, 210, - 7163, 9668, - 7345, 386, - 7598, 280, - 7853, 627, - 8462, 442, - 8648, 331, - 8822, 236, - 8887, 551, - 8953, 906, - 9317, 136, - 9587, 386, - 9651, 691, - 9796, 286, - 9852, 489, - 10005, 1215, - 10041, 192, - 10623, 576, - 10758, 329, - 10840, 425, - 10944, 792, - 11038, 257, - 11190, 1870, - 11541, 501, - 11729, 642, - 11873, 367, - 12064, 163, - 12332, 216, - 12339, 1100, - 12339, 295, - 12478, 444, - 12561, 568, - 12665, 845, - 13257, 396, - 13317, 677, - 13411, 511, - 13709, 324, - 13710, 1547, - 13711, 246, - 14054, 991, - 14112, 447, - 14246, 580, - 14355, 748, - 14394, 175, - 14453, 99, - 14604, 363, - 14887, 491, - 15074, 282, - 15110, 637, - 15242, 1292, - 15351, 413, - 15430, 843, - 15700, 541, - 15776, 204, - 15964, 335, - 15992, 688, - 16077, 453, - 16315, 4617, - 16406, 1032, - 16549, 595, - 16666, 384, - 16850, 776, - 16851, 482, - 16916, 253, - 17234, 309, - 17307, 2128, - 17469, 546, - 17666, 643, - 17699, 421, - 17852, 882, - 17870, 146, - 18146, 1244, - 18457, 489, - 18478, 346, - 18588, 723, - 18826, 208, - 19011, 1731, - 19042, 586, - 19286, 281, - 19428, 944, - 19446, 382, - 19555, 444, - 19689, 792, - 19755, 1111, - 19762, 527, - 19769, 1405, - 19774, 657, - 19780, 2675, + 99, 1224, + 156, 243, + 168, 579, + 290, 355, + 437, 441, + 475, 187, + 734, 738, + 930, 93, + 1133, 153, + 1136, 298, + 1490, 508, + 1946, 401, + 1978, 16790, + 2098, 224, + 2117, 962, + 2407, 119, + 2686, 339, + 2929, 555, + 3404, 271, + 3465, 171, + 3469, 422, + 3714, 663, + 4436, 494, + 4494, 332, + 4571, 220, + 4583, 2182, + 4997, 848, + 5346, 380, + 5419, 108, + 5570, 579, + 5758, 266, + 5875, 442, + 5927, 170, + 6204, 3338, + 6394, 6435, + 6515, 328, + 6638, 730, + 6687, 1472, + 7045, 1056, + 7101, 498, + 7123, 210, + 7163, 9668, + 7345, 386, + 7598, 280, + 7853, 627, + 8462, 442, + 8648, 331, + 8822, 236, + 8887, 551, + 8953, 906, + 9317, 136, + 9587, 386, + 9651, 691, + 9796, 286, + 9852, 489, + 10005, 1215, + 10041, 192, + 10623, 576, + 10758, 329, + 10840, 425, + 10944, 792, + 11038, 257, + 11190, 1870, + 11541, 501, + 11729, 642, + 11873, 367, + 12064, 163, + 12332, 216, + 12339, 1100, + 12339, 295, + 12478, 444, + 12561, 568, + 12665, 845, + 13257, 396, + 13317, 677, + 13411, 511, + 13709, 324, + 13710, 1547, + 13711, 246, + 14054, 991, + 14112, 447, + 14246, 580, + 14355, 748, + 14394, 175, + 14453, 99, + 14604, 363, + 14887, 491, + 15074, 282, + 15110, 637, + 15242, 1292, + 15351, 413, + 15430, 843, + 15700, 541, + 15776, 204, + 15964, 335, + 15992, 688, + 16077, 453, + 16315, 4617, + 16406, 1032, + 16549, 595, + 16666, 384, + 16850, 776, + 16851, 482, + 16916, 253, + 17234, 309, + 17307, 2128, + 17469, 546, + 17666, 643, + 17699, 421, + 17852, 882, + 17870, 146, + 18146, 1244, + 18457, 489, + 18478, 346, + 18588, 723, + 18826, 208, + 19011, 1731, + 19042, 586, + 19286, 281, + 19428, 944, + 19446, 382, + 19555, 444, + 19689, 792, + 19755, 1111, + 19762, 527, + 19769, 1405, + 19774, 657, + 19780, 2675, }; const Word16 gp_gamma_2sfr_6b_fx[2 * 64] = /*Q14/Q9 */ { - 185, 306, - 435, 519, - 458, 145, - 1000, 211, - 1217, 394, - 1241, 751, - 1788, 93, - 2026, 1234, - 2162, 265, - 2397, 158, - 2617, 472, - 3324, 340, - 3391, 623, - 3835, 207, - 4503, 17210, - 4628, 407, - 4939, 897, - 5102, 275, - 5300, 120, - 5560, 511, - 6309, 1909, - 6571, 335, - 6770, 205, - 6990, 642, - 7085, 5087, - 7500, 428, - 8357, 827, - 8452, 261, - 9079, 537, - 9289, 354, - 9854, 1176, - 9864, 165, - 10436, 8580, - 10549, 437, - 10615, 677, - 11010, 282, - 11940, 530, - 12183, 367, - 12475, 920, - 12865, 225, - 13359, 618, - 13431, 441, - 13521, 1623, - 14177, 341, - 14299, 130, - 14452, 775, - 14799, 508, - 15250, 276, - 15715, 1130, - 15757, 660, - 15879, 422, - 16355, 3256, - 16439, 187, - 16751, 562, - 16906, 331, - 17178, 827, - 17889, 471, - 18219, 2175, - 18786, 248, - 18985, 1354, - 19067, 703, - 19220, 384, - 19349, 954, - 19422, 553, + 185, 306, + 435, 519, + 458, 145, + 1000, 211, + 1217, 394, + 1241, 751, + 1788, 93, + 2026, 1234, + 2162, 265, + 2397, 158, + 2617, 472, + 3324, 340, + 3391, 623, + 3835, 207, + 4503, 17210, + 4628, 407, + 4939, 897, + 5102, 275, + 5300, 120, + 5560, 511, + 6309, 1909, + 6571, 335, + 6770, 205, + 6990, 642, + 7085, 5087, + 7500, 428, + 8357, 827, + 8452, 261, + 9079, 537, + 9289, 354, + 9854, 1176, + 9864, 165, + 10436, 8580, + 10549, 437, + 10615, 677, + 11010, 282, + 11940, 530, + 12183, 367, + 12475, 920, + 12865, 225, + 13359, 618, + 13431, 441, + 13521, 1623, + 14177, 341, + 14299, 130, + 14452, 775, + 14799, 508, + 15250, 276, + 15715, 1130, + 15757, 660, + 15879, 422, + 16355, 3256, + 16439, 187, + 16751, 562, + 16906, 331, + 17178, 827, + 17889, 471, + 18219, 2175, + 18786, 248, + 18985, 1354, + 19067, 703, + 19220, 384, + 19349, 954, + 19422, 553, }; const Word16 gp_gamma_3sfr_6b_fx[2 * 64] = /*Q14/Q9 */ { - 195, 150, - 817, 288, - 1152, 616, - 1366, 188, - 1377, 410, - 1526, 902, - 1570, 98, - 2258, 238, - 2489, 518, - 2935, 338, - 3142, 161, - 3456, 1705, - 3990, 432, - 4159, 709, - 4187, 270, - 4374, 1236, - 5283, 526, - 5431, 131, - 5507, 356, - 5762, 211, - 6792, 620, - 6842, 446, - 6969, 304, - 7671, 807, - 8362, 245, - 8448, 530, - 8610, 380, - 9314, 1088, - 9828, 170, - 9921, 7010, - 10026, 459, - 10193, 312, - 10261, 658, - 11554, 394, - 11739, 882, - 11791, 542, - 11985, 4329, - 11996, 246, - 12762, 13441, - 12844, 1512, - 13131, 465, - 13135, 339, - 13215, 740, - 14138, 608, - 14524, 417, - 14780, 1030, - 14823, 283, - 15016, 171, - 15264, 527, - 15823, 2706, - 15943, 699, - 15959, 360, - 16350, 473, - 17211, 573, - 17366, 901, - 17517, 238, - 17799, 414, - 18069, 1415, - 18630, 1920, - 18887, 634, - 19018, 318, - 19304, 495, - 19400, 1114, - 19413, 767, + 195, 150, + 817, 288, + 1152, 616, + 1366, 188, + 1377, 410, + 1526, 902, + 1570, 98, + 2258, 238, + 2489, 518, + 2935, 338, + 3142, 161, + 3456, 1705, + 3990, 432, + 4159, 709, + 4187, 270, + 4374, 1236, + 5283, 526, + 5431, 131, + 5507, 356, + 5762, 211, + 6792, 620, + 6842, 446, + 6969, 304, + 7671, 807, + 8362, 245, + 8448, 530, + 8610, 380, + 9314, 1088, + 9828, 170, + 9921, 7010, + 10026, 459, + 10193, 312, + 10261, 658, + 11554, 394, + 11739, 882, + 11791, 542, + 11985, 4329, + 11996, 246, + 12762, 13441, + 12844, 1512, + 13131, 465, + 13135, 339, + 13215, 740, + 14138, 608, + 14524, 417, + 14780, 1030, + 14823, 283, + 15016, 171, + 15264, 527, + 15823, 2706, + 15943, 699, + 15959, 360, + 16350, 473, + 17211, 573, + 17366, 901, + 17517, 238, + 17799, 414, + 18069, 1415, + 18630, 1920, + 18887, 634, + 19018, 318, + 19304, 495, + 19400, 1114, + 19413, 767, }; const Word16 gp_gamma_4sfr_6b_fx[2 * 64] = /*Q14/Q9 */ { - 153, 141, - 282, 501, - 399, 239, - 783, 369, - 1110, 744, - 1430, 183, - 1440, 1748, - 1524, 1091, - 1602, 296, - 1828, 99, - 2000, 439, - 2678, 228, - 2815, 600, - 3084, 347, - 3861, 477, - 4154, 163, - 4214, 285, - 4428, 733, - 4976, 384, - 5482, 566, - 5552, 234, - 6158, 929, - 6536, 470, - 6560, 326, - 7288, 173, - 7429, 663, - 7447, 10616, - 7871, 407, - 8457, 266, - 8559, 550, - 8679, 1421, - 9457, 356, - 9533, 785, - 9854, 471, - 10584, 5781, - 10792, 3815, - 10813, 206, - 10829, 302, - 10986, 606, - 11380, 433, - 11468, 1073, - 12485, 356, - 12726, 520, - 12783, 721, - 13554, 259, - 13763, 139, - 13884, 430, - 14060, 2592, - 14266, 599, - 14332, 925, - 14997, 337, - 15355, 485, - 15526, 712, - 16440, 587, - 16504, 395, - 16626, 204, - 17228, 1287, - 17563, 805, - 17629, 517, - 18159, 1814, - 18320, 303, - 19228, 437, - 19263, 636, - 19417, 989, + 153, 141, + 282, 501, + 399, 239, + 783, 369, + 1110, 744, + 1430, 183, + 1440, 1748, + 1524, 1091, + 1602, 296, + 1828, 99, + 2000, 439, + 2678, 228, + 2815, 600, + 3084, 347, + 3861, 477, + 4154, 163, + 4214, 285, + 4428, 733, + 4976, 384, + 5482, 566, + 5552, 234, + 6158, 929, + 6536, 470, + 6560, 326, + 7288, 173, + 7429, 663, + 7447, 10616, + 7871, 407, + 8457, 266, + 8559, 550, + 8679, 1421, + 9457, 356, + 9533, 785, + 9854, 471, + 10584, 5781, + 10792, 3815, + 10813, 206, + 10829, 302, + 10986, 606, + 11380, 433, + 11468, 1073, + 12485, 356, + 12726, 520, + 12783, 721, + 13554, 259, + 13763, 139, + 13884, 430, + 14060, 2592, + 14266, 599, + 14332, 925, + 14997, 337, + 15355, 485, + 15526, 712, + 16440, 587, + 16504, 395, + 16626, 204, + 17228, 1287, + 17563, 805, + 17629, 517, + 18159, 1814, + 18320, 303, + 19228, 437, + 19263, 636, + 19417, 989, }; @@ -3961,305 +3961,305 @@ const Word16 fir_6k_7k_fx[31] = }; const Word16 no_lead_fx[][MAX_NO_SCALES * 2] = {//Q0 - { 1, 0, 0, 1, 0, 0, }, /* 14 */ - { 2, 0, 0, 1, 0, 0, }, /* 15 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 4, 2, 0, 2, 0, 0, }, /* 19 */ - { 7, 5, 2, 5, 4, 2, }, /* 25 */ - { 8, 8, 3, 8, 6, 2, }, /* 28 */ /* mode UV WB*/ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 4, 0, 0, 2, 1, 0, }, /* 19 */ - { 9, 8, 8, 2, 2, 1, }, /* 24 */ - { 8, 5, 2, 5, 2, 1, }, /* 25 */ - { 18, 16, 8, 5, 5, 1, }, /* 29 */ - { 24, 21, 10, 8, 8, 2, }, /* 32 */ /* mode UV NB*/ - - { 2, 0, 0, 2, 0, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 7, 5, 2, 2, 0, 0, }, /* 21 */ - { 5, 2, 1, 4, 1, 0, }, /* 22 */ - { 8, 5, 2, 5, 2, 0, }, /* 25 */ - { 8, 7, 4, 5, 3, 2, }, - { 8, 8, 4, 6, 5, 2, }, - { 13, 8, 5, 6, 5, 2, }, - { 13, 8, 5, 8, 6, 2, }, - { 13, 8, 5, 11, 8, 2, }, /* 30 */ - { 24, 21, 8, 9, 8, 2, }, /* 32 */ - { 23, 18, 8, 13, 11, 3, }, - { 23, 21, 8, 17, 13, 4, }, /* 34 */ - { 31, 31, 17, 26, 25, 9, }, /* 37 */ /* mode V WB*/ - { 2, 0, 0, 2, 2, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 7, 5, 2, 2, 2, 0, }, /* 22 */ - { 8, 7, 2, 2, 2, 0, }, /* 23 */ - { 11, 8, 2, 2, 2, 0, }, /* 24 */ - { 13, 13, 9, 2, 2, 0, }, /* 25 */ - { 13, 11, 7, 5, 2, 0, }, /* 27 */ - { 18, 14, 9, 5, 5, 2, }, /* 29 */ - { 31, 31, 14, 11, 11, 5, }, /* 34 */ - { 31, 31, 27, 24, 21, 14, }, /* 37 */ /* mode V NB */ - { 5, 4, 0, 0, 0, 0, }, /* 12 (11.883) */ - { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 8, 8, 7, 5, 2, 0, }, /* 26 (25.904) */ - { 13, 9, 8, 5, 2, 0, }, /* 27 (26.829) */ - { 13, 11, 8, 5, 5, 1, }, /* 28 (27.989) */ - { 13, 9, 8, 8, 5, 2, }, /* 29 (28.984) */ - { 22, 16, 10, 6, 5, 2, }, /* 30 (29.980) */ - { 21, 14, 10, 8, 7, 2, }, /* 31 (30.966) */ - { 24, 21, 10, 8, 8, 2, }, /* 32 (31.995) */ /* G WB*/ - - { 5, 4, 1, 0, 0, 0, }, /* 12 (11.925) */ - { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ - { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ - { 5, 4, 1, 2, 0, 0, }, /* 20 (19.838) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 9, 8, 5, 2, 1, 0, }, /* 23 (22.815) */ - { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ - { 13, 8, 7, 4, 2, 0, }, /* 26 (25.993) */ - { 13, 9, 8, 5, 2, 2, }, /* 27 (26.954) */ - { 18, 13, 8, 5, 2, 2, }, /* 28 (27.992) */ - { 21, 13, 11, 5, 3, 2, }, /* 29 (28.996) */ - { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ - { 23, 21, 17, 7, 5, 2, }, /* 31 (30.962) */ - { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ /* G NB*/ - { 2, 0, 0, 2, 0, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 4, 1, 0, 4, 0, 0, }, /* 21 */ - { 5, 2, 0, 4, 1, 0, }, /* 22 */ - { 8, 5, 2, 4, 0, 0, }, /* 24 */ - { 8, 5, 2, 5, 2, 0, }, /* 25 */ - { 14, 10, 5, 5, 5, 1, }, /* 28 */ - { 14, 10, 5, 8, 8, 4, }, /* 30 */ - { 13, 10, 5, 13, 8, 8, }, - { 23, 21, 8, 8, 8, 4, }, - { 23, 18, 5, 13, 8, 8, }, /* 33 */ - /* mode T WB */ - { 2, 0, 0, 2, 2, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 7, 5, 2, 2, 2, 0, }, /* 22 */ - { 8, 7, 4, 2, 2, 0, }, /* 23 */ - { 11, 8, 5, 2, 2, 0, }, /* 24 */ - { 18, 8, 5, 2, 2, 0, }, /* 25 */ - { 16, 8, 5, 5, 5, 2, }, /* 28 */ - { 28, 23, 8, 5, 5, 5, }, /* 31 */ - { 31, 31, 8, 5, 5, 7, }, /* 32 */ /* mode T NB */ - - { 18, 18, 11, 9, 6, 5, }, /* 31 */ - { 24, 23, 13, 9, 6, 5, }, /* 32 */ /* mode G 16k */ - - { 24, 23, 13, 9, 6, 5, }, /* 32 (31.998) */ - { 36, 31, 18, 9, 6, 5, }, /* 33 (32.983) */ /* T 16k */ - - { 2, 0, 0, 2, 2, 0, }, /* 17 */ - { 7, 5, 2, 2, 0, 0, }, /* 21 */ - { 7, 5, 2, 2, 2, 0, }, /* 22 */ - { 9, 8, 3, 4, 2, 0, }, /* 25 */ - { 11, 9, 8, 4, 2, 0, }, /* 26 */ - { 48, 48, 34, 13, 11, 9 }, /* 36 */ /* mode AUDIO_WB 36 + 4 + 1 */ - - { 22, 10, 3, 0, 0, 0 }, /* 17 */ - { 6, 6, 2, 2, 0, 0 }, /* 21 */ - { 6, 6, 2, 2, 2, 0 }, /* 22 */ - { 23, 10, 3, 2, 2, 0 }, /* 26 */ - { 32, 16, 3, 2, 2, 0 }, /* 27 */ /* AUDIO_NB */ - { 39, 30, 12, 2, 2, 0 }, /* 28 */ /* AUDIO_NB */ - { 11, 9, 8, 4, 2, 0, }, /* 26 */ - { 48, 48, 48, 13, 9, 8 }, /* 36 */ /* mode AUDIO_WB 16k 15-36 + 4 + 1*/ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 13, 13, 5, 5, 5, 0, }, /* 28 (27.994) */ - { 18, 17, 5, 5, 5, 1, }, /* 29 (28.996) */ - { 17, 13, 5, 8, 6, 2, }, /* 30 (29.991) */ - { 23, 21, 8, 9, 8, 3, }, /* 32 (31.992) */ - { 31, 29, 16, 8, 8, 3, }, /* 33 (32.993) */ - { 31, 25, 16, 12, 8, 8, }, /* 34 (33.968) */ - { 46, 48, 18, 18, 18, 12, }, /* 37 (36.995) */ /* VOICED 16k */ - { 14, 12, 9, 2, 2, 0, }, /* 25 (24.980) */ - { 15, 13, 3, 2, 2, 0, }, /* 25 (24.974) */ - { 17, 3, 0, 2, 2, 1, }, /* 25 (24.852) */ - { 13, 10, 3, 2, 2, 2, }, /* 25 (24.994) */ - { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ - { 7, 3, 0, 5, 3, 1, }, /* 25 (24.671) */ - { 4, 3, 2, 6, 6, 5, }, /* 25 (24.936) */ - { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ - { 4, 2, 0, 9, 8, 2, }, /* 25 (24.853) */ - { 4, 2, 0, 9, 7, 6, }, /* 25 (24.881) */ - { 6, 3, 0, 6, 3, 2, }, /* 25 (24.939) */ - { 3, 2, 0, 9, 8, 5, }, /* 25 (24.996) */ - { 2, 2, 0, 15, 3, 3, }, /* 25 (24.310) */ - { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ - { 4, 4, 2, 7, 6, 3, }, /* 25 (24.984) */ - { 3, 2, 0, 9, 7, 6, }, /* 25 (24.866) */ - -}; - -const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2] = // Q0 -{ - - { 2, 1, 0, 0, 0, 0, }, /* 9 (8.464) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ - { 8, 5, 2, 4, 0, 0, }, /* 24 (23.949) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 13, 11, 5, 5, 2, 0, }, /* 27 (26.902) */ - { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ - { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ - { 16, 13, 5, 8, 7, 2, }, /* 30 (29.954) */ - { 21, 21, 5, 8, 5, 2, }, /* 31 (30.978) */ - { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ - { 32, 23, 5, 13, 11, 5, }, /* 34 (33.975) */ - { 36, 31, 8, 16, 13, 5, }, /* 35 (34.975) */ - { 45, 35, 16, 18, 13, 5, }, /* 36 (35.889) */ - { 45, 35, 16, 38, 31, 8, }, /* 39 (38.488) */ /* V WB*/ /* 14 */ - - { 2, 0, 0, 0, 0, 0, }, /* 8 (7.913) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ - { 13, 11, 5, 2, 1, 0, }, /* 24 (23.999) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 13, 11, 5, 5, 2, 1, }, /* 27 (26.962) */ - { 13, 11, 5, 5, 5, 2, }, /* 28 (27.835) */ - { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ - { 23, 21, 5, 5, 5, 2, }, /* 30 (29.969) */ - { 23, 18, 5, 8, 5, 2, }, /* 31 (30.952) */ - { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ - { 43, 41, 13, 9, 8, 5, }, /* 34 (33.992) */ - { 43, 36, 13, 13, 10, 5, }, /* 35 (35.000) */ - { 43, 40, 13, 17, 13, 9, }, /* 36 (35.980) */ - { 43, 42, 13, 31, 30, 18, }, /* 39 (38.512) */ /* V NB*/ /* 29 */ - - { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ - { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ - { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ - { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ - { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ - { 14, 13, 8, 5, 4, 0, }, /* 28 (27.969) */ - { 18, 17, 13, 5, 4, 2, }, /* 29 (28.996) */ - { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ - { 31, 23, 21, 5, 5, 2, }, /* 31 (30.931) */ - { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ - { 31, 23, 21, 9, 8, 5, }, /* 33 (32.982) */ - { 32, 31, 24, 11, 8, 5, }, /* 34 (33.967) */ - { 32, 32, 28, 13, 11, 8, }, /* 35 (34.994) */ /* G WB*/ /* 44 */ - - { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ - { 5, 4, 2, 1, 0, 0, }, /* 19 (18.792) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ - { 13, 11, 2, 2, 1, 0, }, /* 24 (23.932) */ - { 16, 13, 2, 2, 2, 0, }, /* 25 (24.955) */ - { 21, 17, 2, 2, 2, 0, }, /* 26 (25.991) */ - { 13, 12, 2, 5, 5, 2, }, /* 28 (27.979) */ - { 18, 16, 2, 5, 5, 2, }, /* 29 (28.878) */ - { 23, 21, 2, 5, 5, 2, }, /* 30 (29.954) */ - { 32, 28, 2, 5, 5, 2, }, /* 31 (30.893) */ - { 38, 31, 2, 7, 5, 2, }, /* 32 (31.963) */ - { 33, 31, 2, 8, 8, 4, }, /* 33 (32.997) */ - { 42, 31, 2, 9, 9, 8, }, /* 34 (33.986) */ - { 42, 31, 2, 13, 11, 9, }, /* 35 (34.952) */ /* G NB*/ /* 59 */ - - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 13, 8, 5, 4, 2, 0, }, /* 26 */ - { 13, 8, 5, 8, 6, 2, }, /* 29 */ - { 13, 8, 5, 9, 8, 5, }, /* 30 */ - { 48, 48, 48, 36, 36, 28 }, /* 40 */ /* mode 7 AUDIO_WB */ /* 65*/ - - { 7, 5, 2, 2, 0, 0 }, /* 21 */ - { 13, 13, 9, 2, 2, 0 }, /* 25 */ - { 18, 18, 9, 2, 2, 0 }, /* 26 */ - { 24, 23, 10, 5, 4, 2 }, /* 30 */ - { 31, 31, 12, 5, 5, 2 }, /* 31 */ /*AUDIO_NB */ /* 70 */ - { 43, 34, 12, 5, 5, 4 }, /* 32 */ /*AUDIO_NB */ /* 71 */ - { 13, 8, 5, 9, 8, 5, }, /* 30 */ - { 48, 48, 45, 45, 31, 25 }, /* 40 */ /* mode AUDIO_WB 16k */ /* 73*/ - - { 2, 0, 0, 2, 2, 0, }, /* 17 (16.823) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 7, 5, 2, 2, 2, 0, }, /* 22 (21.907) */ - { 13, 11, 10, 2, 2, 0, }, /* 25 (24.863) */ - { 18, 18, 10, 2, 2, 0, }, /* 26 (25.921) */ - { 13, 9, 9, 5, 2, 0, }, /* 27 (26.837) */ - { 40, 28, 25, 18, 17, 2, }, /* 36 (35.998) */ /* INACTIVE NB*/ /* 80*/ - - { 18, 17, 11, 0, 0, 0, }, /* 17 (16.932) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ - { 18, 18, 12, 2, 2, 0, }, /* 26 (25.999) */ - { 23, 23, 16, 2, 2, 0, }, /* 27 (26.981) */ - { 36, 32, 24, 17, 13, 13, }, /* 36 (35.929) */ /* INACTIVE WB */ /* 87 */ - - { 2, 2, 0, 2, 0, 0, }, /* 17 (16.823) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ - { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ - { 23, 22, 17, 2, 2, 0, }, /* 27 (26.914) */ - { 34, 32, 24, 16, 16, 13, }, /* 36 (35.915) */ /* INACTIVE WB 16k*/ /* 94 */ - - { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ - { 5, 4, 0, 1, 0, 0, }, /* 19 (18.703) */ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ - { 15, 13, 5, 2, 0, 0, }, /* 24 (23.999) */ - { 18, 16, 8, 5, 5, 1, }, /* 29 (28.966) */ - { 42, 32, 31, 5, 5, 2, }, /* 32 (31.990) */ /* UNVOICED NB*/ /* 100 */ - - { 1, 0, 0, 1, 0, 0, }, /* 14 (13.640) */ - { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ - { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ /* UNVOICED WB */ /* 106 */ - { 9, 3, 0, 4, 0, 0, }, /* 24 (23.818) */ - { 18, 13, 10, 8, 3, 0, }, /* 30 (29.992) */ - { 24, 18, 10, 9, 3, 0, }, /* 31 (30.998) */ - { 32, 25, 10, 9, 3, 0, }, /* 32 (31.987) */ - { 42, 31, 10, 12, 3, 2, }, /* 34 (33.994) */ - { 44, 32, 27, 15, 3, 2, }, /* 35 (35.000) */ - { 44, 32, 25, 19, 3, 2, }, /* 36 (35.994) */ - { 48, 39, 32, 35, 15, 3, }, /* 39 (38.301) */ /* VOICED 16k */ - { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 107 */ - { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ - { 32, 31, 18, 9, 7, 5, }, /* 33 (32.990) */ - { 31, 31, 18, 11, 9, 8, }, /* 34 (33.974) */ - { 32, 32, 20, 13, 12, 8, }, /* 35 (34.989) */ - { 32, 32, 23, 18, 17, 8, }, /* 36 (35.988) */ - { 32, 32, 23, 23, 22, 10, }, /* 37 (36.989) */ /* GENERIC 16k*/ /* 113 */ - - { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ /* 114 */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ - { 16, 13, 8, 4, 2, 0, }, /* 27 (26.883) */ - { 13, 13, 8, 5, 4, 2, }, /* 28 (27.901) */ - { 23, 18, 13, 5, 5, 2, }, /* 30 (29.916) */ - { 23, 23, 13, 7, 5, 2, }, /* 31 (30.993) */ - { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ - { 32, 31, 24, 8, 7, 2, }, /* 33 (32.958) */ - { 42, 32, 31, 9, 9, 4, }, /* 34 (33.987) */ - { 40, 32, 29, 12, 9, 9, }, /* 35 (34.994) */ - { 40, 32, 31, 17, 11, 11, }, /* 36 (35.968) */ - { 41, 32, 31, 20, 18, 13, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ /* 128 */ - - { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 129 */ - { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ - { 31, 31, 18, 9, 8, 2, }, /* 33 (32.995) */ - { 48, 32, 24, 9, 8, 3, }, /* 34 (33.993) */ - { 48, 32, 28, 11, 10, 3, }, /* 35 (34.992) */ - { 48, 37, 32, 16, 12, 4, }, /* 36 (35.997) */ - { 48, 37, 32, 18, 17, 12, }, /* 37 (36.961) */ /* AUDIO 16k */ + { 1, 0, 0, 1, 0, 0, }, /* 14 */ + { 2, 0, 0, 1, 0, 0, }, /* 15 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 4, 2, 0, 2, 0, 0, }, /* 19 */ + { 7, 5, 2, 5, 4, 2, }, /* 25 */ + { 8, 8, 3, 8, 6, 2, }, /* 28 */ /* mode UV WB*/ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 4, 0, 0, 2, 1, 0, }, /* 19 */ + { 9, 8, 8, 2, 2, 1, }, /* 24 */ + { 8, 5, 2, 5, 2, 1, }, /* 25 */ + { 18, 16, 8, 5, 5, 1, }, /* 29 */ + { 24, 21, 10, 8, 8, 2, }, /* 32 */ /* mode UV NB*/ + + { 2, 0, 0, 2, 0, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 7, 5, 2, 2, 0, 0, }, /* 21 */ + { 5, 2, 1, 4, 1, 0, }, /* 22 */ + { 8, 5, 2, 5, 2, 0, }, /* 25 */ + { 8, 7, 4, 5, 3, 2, }, + { 8, 8, 4, 6, 5, 2, }, + { 13, 8, 5, 6, 5, 2, }, + { 13, 8, 5, 8, 6, 2, }, + { 13, 8, 5, 11, 8, 2, }, /* 30 */ + { 24, 21, 8, 9, 8, 2, }, /* 32 */ + { 23, 18, 8, 13, 11, 3, }, + { 23, 21, 8, 17, 13, 4, }, /* 34 */ + { 31, 31, 17, 26, 25, 9, }, /* 37 */ /* mode V WB*/ + { 2, 0, 0, 2, 2, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 7, 5, 2, 2, 2, 0, }, /* 22 */ + { 8, 7, 2, 2, 2, 0, }, /* 23 */ + { 11, 8, 2, 2, 2, 0, }, /* 24 */ + { 13, 13, 9, 2, 2, 0, }, /* 25 */ + { 13, 11, 7, 5, 2, 0, }, /* 27 */ + { 18, 14, 9, 5, 5, 2, }, /* 29 */ + { 31, 31, 14, 11, 11, 5, }, /* 34 */ + { 31, 31, 27, 24, 21, 14, }, /* 37 */ /* mode V NB */ + { 5, 4, 0, 0, 0, 0, }, /* 12 (11.883) */ + { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 8, 8, 7, 5, 2, 0, }, /* 26 (25.904) */ + { 13, 9, 8, 5, 2, 0, }, /* 27 (26.829) */ + { 13, 11, 8, 5, 5, 1, }, /* 28 (27.989) */ + { 13, 9, 8, 8, 5, 2, }, /* 29 (28.984) */ + { 22, 16, 10, 6, 5, 2, }, /* 30 (29.980) */ + { 21, 14, 10, 8, 7, 2, }, /* 31 (30.966) */ + { 24, 21, 10, 8, 8, 2, }, /* 32 (31.995) */ /* G WB*/ + + { 5, 4, 1, 0, 0, 0, }, /* 12 (11.925) */ + { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ + { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ + { 5, 4, 1, 2, 0, 0, }, /* 20 (19.838) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 9, 8, 5, 2, 1, 0, }, /* 23 (22.815) */ + { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ + { 13, 8, 7, 4, 2, 0, }, /* 26 (25.993) */ + { 13, 9, 8, 5, 2, 2, }, /* 27 (26.954) */ + { 18, 13, 8, 5, 2, 2, }, /* 28 (27.992) */ + { 21, 13, 11, 5, 3, 2, }, /* 29 (28.996) */ + { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ + { 23, 21, 17, 7, 5, 2, }, /* 31 (30.962) */ + { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ /* G NB*/ + { 2, 0, 0, 2, 0, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 4, 1, 0, 4, 0, 0, }, /* 21 */ + { 5, 2, 0, 4, 1, 0, }, /* 22 */ + { 8, 5, 2, 4, 0, 0, }, /* 24 */ + { 8, 5, 2, 5, 2, 0, }, /* 25 */ + { 14, 10, 5, 5, 5, 1, }, /* 28 */ + { 14, 10, 5, 8, 8, 4, }, /* 30 */ + { 13, 10, 5, 13, 8, 8, }, + { 23, 21, 8, 8, 8, 4, }, + { 23, 18, 5, 13, 8, 8, }, /* 33 */ + /* mode T WB */ + { 2, 0, 0, 2, 2, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 7, 5, 2, 2, 2, 0, }, /* 22 */ + { 8, 7, 4, 2, 2, 0, }, /* 23 */ + { 11, 8, 5, 2, 2, 0, }, /* 24 */ + { 18, 8, 5, 2, 2, 0, }, /* 25 */ + { 16, 8, 5, 5, 5, 2, }, /* 28 */ + { 28, 23, 8, 5, 5, 5, }, /* 31 */ + { 31, 31, 8, 5, 5, 7, }, /* 32 */ /* mode T NB */ + + { 18, 18, 11, 9, 6, 5, }, /* 31 */ + { 24, 23, 13, 9, 6, 5, }, /* 32 */ /* mode G 16k */ + + { 24, 23, 13, 9, 6, 5, }, /* 32 (31.998) */ + { 36, 31, 18, 9, 6, 5, }, /* 33 (32.983) */ /* T 16k */ + + { 2, 0, 0, 2, 2, 0, }, /* 17 */ + { 7, 5, 2, 2, 0, 0, }, /* 21 */ + { 7, 5, 2, 2, 2, 0, }, /* 22 */ + { 9, 8, 3, 4, 2, 0, }, /* 25 */ + { 11, 9, 8, 4, 2, 0, }, /* 26 */ + { 48, 48, 34, 13, 11, 9 }, /* 36 */ /* mode AUDIO_WB 36 + 4 + 1 */ + + { 22, 10, 3, 0, 0, 0 }, /* 17 */ + { 6, 6, 2, 2, 0, 0 }, /* 21 */ + { 6, 6, 2, 2, 2, 0 }, /* 22 */ + { 23, 10, 3, 2, 2, 0 }, /* 26 */ + { 32, 16, 3, 2, 2, 0 }, /* 27 */ /* AUDIO_NB */ + { 39, 30, 12, 2, 2, 0 }, /* 28 */ /* AUDIO_NB */ + { 11, 9, 8, 4, 2, 0, }, /* 26 */ + { 48, 48, 48, 13, 9, 8 }, /* 36 */ /* mode AUDIO_WB 16k 15-36 + 4 + 1*/ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 13, 13, 5, 5, 5, 0, }, /* 28 (27.994) */ + { 18, 17, 5, 5, 5, 1, }, /* 29 (28.996) */ + { 17, 13, 5, 8, 6, 2, }, /* 30 (29.991) */ + { 23, 21, 8, 9, 8, 3, }, /* 32 (31.992) */ + { 31, 29, 16, 8, 8, 3, }, /* 33 (32.993) */ + { 31, 25, 16, 12, 8, 8, }, /* 34 (33.968) */ + { 46, 48, 18, 18, 18, 12, }, /* 37 (36.995) */ /* VOICED 16k */ + { 14, 12, 9, 2, 2, 0, }, /* 25 (24.980) */ + { 15, 13, 3, 2, 2, 0, }, /* 25 (24.974) */ + { 17, 3, 0, 2, 2, 1, }, /* 25 (24.852) */ + { 13, 10, 3, 2, 2, 2, }, /* 25 (24.994) */ + { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ + { 7, 3, 0, 5, 3, 1, }, /* 25 (24.671) */ + { 4, 3, 2, 6, 6, 5, }, /* 25 (24.936) */ + { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ + { 4, 2, 0, 9, 8, 2, }, /* 25 (24.853) */ + { 4, 2, 0, 9, 7, 6, }, /* 25 (24.881) */ + { 6, 3, 0, 6, 3, 2, }, /* 25 (24.939) */ + { 3, 2, 0, 9, 8, 5, }, /* 25 (24.996) */ + { 2, 2, 0, 15, 3, 3, }, /* 25 (24.310) */ + { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ + { 4, 4, 2, 7, 6, 3, }, /* 25 (24.984) */ + { 3, 2, 0, 9, 7, 6, }, /* 25 (24.866) */ + +}; + +const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2] = // Q0 +{ + + { 2, 1, 0, 0, 0, 0, }, /* 9 (8.464) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ + { 8, 5, 2, 4, 0, 0, }, /* 24 (23.949) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 13, 11, 5, 5, 2, 0, }, /* 27 (26.902) */ + { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ + { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ + { 16, 13, 5, 8, 7, 2, }, /* 30 (29.954) */ + { 21, 21, 5, 8, 5, 2, }, /* 31 (30.978) */ + { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ + { 32, 23, 5, 13, 11, 5, }, /* 34 (33.975) */ + { 36, 31, 8, 16, 13, 5, }, /* 35 (34.975) */ + { 45, 35, 16, 18, 13, 5, }, /* 36 (35.889) */ + { 45, 35, 16, 38, 31, 8, }, /* 39 (38.488) */ /* V WB*/ /* 14 */ + + { 2, 0, 0, 0, 0, 0, }, /* 8 (7.913) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ + { 13, 11, 5, 2, 1, 0, }, /* 24 (23.999) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 13, 11, 5, 5, 2, 1, }, /* 27 (26.962) */ + { 13, 11, 5, 5, 5, 2, }, /* 28 (27.835) */ + { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ + { 23, 21, 5, 5, 5, 2, }, /* 30 (29.969) */ + { 23, 18, 5, 8, 5, 2, }, /* 31 (30.952) */ + { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ + { 43, 41, 13, 9, 8, 5, }, /* 34 (33.992) */ + { 43, 36, 13, 13, 10, 5, }, /* 35 (35.000) */ + { 43, 40, 13, 17, 13, 9, }, /* 36 (35.980) */ + { 43, 42, 13, 31, 30, 18, }, /* 39 (38.512) */ /* V NB*/ /* 29 */ + + { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ + { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ + { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ + { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ + { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ + { 14, 13, 8, 5, 4, 0, }, /* 28 (27.969) */ + { 18, 17, 13, 5, 4, 2, }, /* 29 (28.996) */ + { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ + { 31, 23, 21, 5, 5, 2, }, /* 31 (30.931) */ + { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ + { 31, 23, 21, 9, 8, 5, }, /* 33 (32.982) */ + { 32, 31, 24, 11, 8, 5, }, /* 34 (33.967) */ + { 32, 32, 28, 13, 11, 8, }, /* 35 (34.994) */ /* G WB*/ /* 44 */ + + { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ + { 5, 4, 2, 1, 0, 0, }, /* 19 (18.792) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ + { 13, 11, 2, 2, 1, 0, }, /* 24 (23.932) */ + { 16, 13, 2, 2, 2, 0, }, /* 25 (24.955) */ + { 21, 17, 2, 2, 2, 0, }, /* 26 (25.991) */ + { 13, 12, 2, 5, 5, 2, }, /* 28 (27.979) */ + { 18, 16, 2, 5, 5, 2, }, /* 29 (28.878) */ + { 23, 21, 2, 5, 5, 2, }, /* 30 (29.954) */ + { 32, 28, 2, 5, 5, 2, }, /* 31 (30.893) */ + { 38, 31, 2, 7, 5, 2, }, /* 32 (31.963) */ + { 33, 31, 2, 8, 8, 4, }, /* 33 (32.997) */ + { 42, 31, 2, 9, 9, 8, }, /* 34 (33.986) */ + { 42, 31, 2, 13, 11, 9, }, /* 35 (34.952) */ /* G NB*/ /* 59 */ + + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 13, 8, 5, 4, 2, 0, }, /* 26 */ + { 13, 8, 5, 8, 6, 2, }, /* 29 */ + { 13, 8, 5, 9, 8, 5, }, /* 30 */ + { 48, 48, 48, 36, 36, 28 }, /* 40 */ /* mode 7 AUDIO_WB */ /* 65*/ + + { 7, 5, 2, 2, 0, 0 }, /* 21 */ + { 13, 13, 9, 2, 2, 0 }, /* 25 */ + { 18, 18, 9, 2, 2, 0 }, /* 26 */ + { 24, 23, 10, 5, 4, 2 }, /* 30 */ + { 31, 31, 12, 5, 5, 2 }, /* 31 */ /*AUDIO_NB */ /* 70 */ + { 43, 34, 12, 5, 5, 4 }, /* 32 */ /*AUDIO_NB */ /* 71 */ + { 13, 8, 5, 9, 8, 5, }, /* 30 */ + { 48, 48, 45, 45, 31, 25 }, /* 40 */ /* mode AUDIO_WB 16k */ /* 73*/ + + { 2, 0, 0, 2, 2, 0, }, /* 17 (16.823) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 7, 5, 2, 2, 2, 0, }, /* 22 (21.907) */ + { 13, 11, 10, 2, 2, 0, }, /* 25 (24.863) */ + { 18, 18, 10, 2, 2, 0, }, /* 26 (25.921) */ + { 13, 9, 9, 5, 2, 0, }, /* 27 (26.837) */ + { 40, 28, 25, 18, 17, 2, }, /* 36 (35.998) */ /* INACTIVE NB*/ /* 80*/ + + { 18, 17, 11, 0, 0, 0, }, /* 17 (16.932) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ + { 18, 18, 12, 2, 2, 0, }, /* 26 (25.999) */ + { 23, 23, 16, 2, 2, 0, }, /* 27 (26.981) */ + { 36, 32, 24, 17, 13, 13, }, /* 36 (35.929) */ /* INACTIVE WB */ /* 87 */ + + { 2, 2, 0, 2, 0, 0, }, /* 17 (16.823) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ + { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ + { 23, 22, 17, 2, 2, 0, }, /* 27 (26.914) */ + { 34, 32, 24, 16, 16, 13, }, /* 36 (35.915) */ /* INACTIVE WB 16k*/ /* 94 */ + + { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ + { 5, 4, 0, 1, 0, 0, }, /* 19 (18.703) */ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ + { 15, 13, 5, 2, 0, 0, }, /* 24 (23.999) */ + { 18, 16, 8, 5, 5, 1, }, /* 29 (28.966) */ + { 42, 32, 31, 5, 5, 2, }, /* 32 (31.990) */ /* UNVOICED NB*/ /* 100 */ + + { 1, 0, 0, 1, 0, 0, }, /* 14 (13.640) */ + { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ + { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ /* UNVOICED WB */ /* 106 */ + { 9, 3, 0, 4, 0, 0, }, /* 24 (23.818) */ + { 18, 13, 10, 8, 3, 0, }, /* 30 (29.992) */ + { 24, 18, 10, 9, 3, 0, }, /* 31 (30.998) */ + { 32, 25, 10, 9, 3, 0, }, /* 32 (31.987) */ + { 42, 31, 10, 12, 3, 2, }, /* 34 (33.994) */ + { 44, 32, 27, 15, 3, 2, }, /* 35 (35.000) */ + { 44, 32, 25, 19, 3, 2, }, /* 36 (35.994) */ + { 48, 39, 32, 35, 15, 3, }, /* 39 (38.301) */ /* VOICED 16k */ + { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 107 */ + { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ + { 32, 31, 18, 9, 7, 5, }, /* 33 (32.990) */ + { 31, 31, 18, 11, 9, 8, }, /* 34 (33.974) */ + { 32, 32, 20, 13, 12, 8, }, /* 35 (34.989) */ + { 32, 32, 23, 18, 17, 8, }, /* 36 (35.988) */ + { 32, 32, 23, 23, 22, 10, }, /* 37 (36.989) */ /* GENERIC 16k*/ /* 113 */ + + { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ /* 114 */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ + { 16, 13, 8, 4, 2, 0, }, /* 27 (26.883) */ + { 13, 13, 8, 5, 4, 2, }, /* 28 (27.901) */ + { 23, 18, 13, 5, 5, 2, }, /* 30 (29.916) */ + { 23, 23, 13, 7, 5, 2, }, /* 31 (30.993) */ + { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ + { 32, 31, 24, 8, 7, 2, }, /* 33 (32.958) */ + { 42, 32, 31, 9, 9, 4, }, /* 34 (33.987) */ + { 40, 32, 29, 12, 9, 9, }, /* 35 (34.994) */ + { 40, 32, 31, 17, 11, 11, }, /* 36 (35.968) */ + { 41, 32, 31, 20, 18, 13, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ /* 128 */ + + { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 129 */ + { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ + { 31, 31, 18, 9, 8, 2, }, /* 33 (32.995) */ + { 48, 32, 24, 9, 8, 3, }, /* 34 (33.993) */ + { 48, 32, 28, 11, 10, 3, }, /* 35 (34.992) */ + { 48, 37, 32, 16, 12, 4, }, /* 36 (35.997) */ + { 48, 37, 32, 18, 17, 12, }, /* 37 (36.961) */ /* AUDIO 16k */ }; /*----------------------------------------------------------------------------------* @@ -4345,7 +4345,7 @@ const Word16 filt_lp_16kHz_fx[1 + L_FILT16k] = * Pulse indexing tables for ACELP innovation coding *-------------------------------------------------------------------*/ -const Word32 PI_select_table[23][8] = // Q0 +const Word32 PI_select_table[23][8] = // Q0 { {1, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0}, @@ -4372,7 +4372,7 @@ const Word32 PI_select_table[23][8] = // Q0 {1, 22, 231, 1540, 7315, 26334, 74613, 1705444} }; -const Word32 PI_offset[8][8] = // Q0 +const Word32 PI_offset[8][8] = // Q0 { /* for 0p(0). */ {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, @@ -4392,15 +4392,15 @@ const Word32 PI_offset[8][8] = // Q0 {0x00000,0x00000,0x165800,0x454400,0x654200,0x6E2500,0x6F2B80,0x6F36C0} }; -const Word16 PI_factor[7] = {0,0,120,560,1820,4368,8008}; // Q0 +const Word16 PI_factor[7] = {0,0,120,560,1820,4368,8008}; // Q0 /* ACELP pulse coding */ -const Word16 hi_to_low_tmpl[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8 }; // Q0 -const UWord16 low_len[10] = { 0, 0, 8, 5, 7,11,13,15,16,16 }; // Q0 -const UWord16 low_mask[10] = { 0, 0, 255,31,127,2047,8191,32767,65535,65535 }; // Q0 -const UWord16 indx_fact[10] = { 0, 0,2,172,345,140,190,223,463,1732 }; // Q0 -const Word16 index_len[3] = { 0, 5, 9 }; // Q0 -const Word16 index_mask_ACELP[3] = { 0, 31, 511 }; // Q0 +const Word16 hi_to_low_tmpl[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8 }; // Q0 +const UWord16 low_len[10] = { 0, 0, 8, 5, 7,11,13,15,16,16 }; // Q0 +const UWord16 low_mask[10] = { 0, 0, 255,31,127,2047,8191,32767,65535,65535 }; // Q0 +const UWord16 indx_fact[10] = { 0, 0,2,172,345,140,190,223,463,1732 }; // Q0 +const Word16 index_len[3] = { 0, 5, 9 }; // Q0 +const Word16 index_mask_ACELP[3] = { 0, 31, 511 }; // Q0 /*------------------------------------------------------------------------------* @@ -4874,88 +4874,88 @@ const Word16 edct_table_400_fx[] =/*Q16 */ const Word16 edct_table_320_16fx[320] =/*Q16 */ { - 7747, 7747, 7747, 7746, 7746, 7745, 7744, 7742, - 7741, 7739, 7737, 7735, 7733, 7730, 7728, 7725, - 7722, 7719, 7716, 7712, 7708, 7704, 7700, 7696, - 7692, 7687, 7682, 7677, 7672, 7666, 7661, 7655, - 7649, 7643, 7637, 7630, 7623, 7617, 7610, 7602, - 7595, 7587, 7580, 7572, 7563, 7555, 7547, 7538, - 7529, 7520, 7511, 7501, 7492, 7482, 7472, 7462, - 7451, 7441, 7430, 7419, 7408, 7397, 7386, 7374, - 7362, 7350, 7338, 7326, 7314, 7301, 7288, 7275, - 7262, 7249, 7235, 7221, 7208, 7194, 7179, 7165, - 7150, 7136, 7121, 7106, 7091, 7075, 7060, 7044, - 7028, 7012, 6995, 6979, 6962, 6946, 6929, 6912, - 6894, 6877, 6859, 6842, 6824, 6806, 6787, 6769, - 6750, 6732, 6713, 6694, 6674, 6655, 6635, 6616, - 6596, 6576, 6556, 6535, 6515, 6494, 6473, 6452, - 6431, 6410, 6388, 6367, 6345, 6323, 6301, 6279, - 6257, 6234, 6211, 6189, 6166, 6143, 6119, 6096, - 6072, 6049, 6025, 6001, 5977, 5953, 5928, 5904, - 5879, 5854, 5829, 5804, 5779, 5753, 5728, 5702, - 5676, 5650, 5624, 5598, 5572, 5545, 5518, 5492, - 5465, 5438, 5411, 5383, 5356, 5328, 5301, 5273, - 5245, 5217, 5189, 5160, 5132, 5104, 5075, 5046, - 5017, 4988, 4959, 4930, 4900, 4871, 4841, 4811, - 4781, 4751, 4721, 4691, 4661, 4630, 4600, 4569, - 4538, 4508, 4477, 4446, 4414, 4383, 4352, 4320, - 4288, 4257, 4225, 4193, 4161, 4129, 4097, 4064, - 4032, 3999, 3967, 3934, 3901, 3868, 3835, 3802, - 3769, 3736, 3702, 3669, 3635, 3602, 3568, 3534, - 3500, 3466, 3432, 3398, 3364, 3330, 3295, 3261, - 3226, 3192, 3157, 3122, 3087, 3052, 3017, 2982, - 2947, 2912, 2877, 2841, 2806, 2771, 2735, 2699, - 2664, 2628, 2592, 2556, 2520, 2484, 2448, 2412, - 2376, 2340, 2304, 2267, 2231, 2194, 2158, 2121, - 2085, 2048, 2011, 1975, 1938, 1901, 1864, 1827, - 1790, 1753, 1716, 1679, 1642, 1605, 1567, 1530, - 1493, 1455, 1418, 1381, 1343, 1306, 1268, 1231, - 1193, 1156, 1118, 1080, 1043, 1005, 967, 930, - 892, 854, 816, 778, 740, 703, 665, 627, - 589, 551, 513, 475, 437, 399, 361, 323, - 285, 247, 209, 171, 133, 95, 57, 19 + 7747, 7747, 7747, 7746, 7746, 7745, 7744, 7742, + 7741, 7739, 7737, 7735, 7733, 7730, 7728, 7725, + 7722, 7719, 7716, 7712, 7708, 7704, 7700, 7696, + 7692, 7687, 7682, 7677, 7672, 7666, 7661, 7655, + 7649, 7643, 7637, 7630, 7623, 7617, 7610, 7602, + 7595, 7587, 7580, 7572, 7563, 7555, 7547, 7538, + 7529, 7520, 7511, 7501, 7492, 7482, 7472, 7462, + 7451, 7441, 7430, 7419, 7408, 7397, 7386, 7374, + 7362, 7350, 7338, 7326, 7314, 7301, 7288, 7275, + 7262, 7249, 7235, 7221, 7208, 7194, 7179, 7165, + 7150, 7136, 7121, 7106, 7091, 7075, 7060, 7044, + 7028, 7012, 6995, 6979, 6962, 6946, 6929, 6912, + 6894, 6877, 6859, 6842, 6824, 6806, 6787, 6769, + 6750, 6732, 6713, 6694, 6674, 6655, 6635, 6616, + 6596, 6576, 6556, 6535, 6515, 6494, 6473, 6452, + 6431, 6410, 6388, 6367, 6345, 6323, 6301, 6279, + 6257, 6234, 6211, 6189, 6166, 6143, 6119, 6096, + 6072, 6049, 6025, 6001, 5977, 5953, 5928, 5904, + 5879, 5854, 5829, 5804, 5779, 5753, 5728, 5702, + 5676, 5650, 5624, 5598, 5572, 5545, 5518, 5492, + 5465, 5438, 5411, 5383, 5356, 5328, 5301, 5273, + 5245, 5217, 5189, 5160, 5132, 5104, 5075, 5046, + 5017, 4988, 4959, 4930, 4900, 4871, 4841, 4811, + 4781, 4751, 4721, 4691, 4661, 4630, 4600, 4569, + 4538, 4508, 4477, 4446, 4414, 4383, 4352, 4320, + 4288, 4257, 4225, 4193, 4161, 4129, 4097, 4064, + 4032, 3999, 3967, 3934, 3901, 3868, 3835, 3802, + 3769, 3736, 3702, 3669, 3635, 3602, 3568, 3534, + 3500, 3466, 3432, 3398, 3364, 3330, 3295, 3261, + 3226, 3192, 3157, 3122, 3087, 3052, 3017, 2982, + 2947, 2912, 2877, 2841, 2806, 2771, 2735, 2699, + 2664, 2628, 2592, 2556, 2520, 2484, 2448, 2412, + 2376, 2340, 2304, 2267, 2231, 2194, 2158, 2121, + 2085, 2048, 2011, 1975, 1938, 1901, 1864, 1827, + 1790, 1753, 1716, 1679, 1642, 1605, 1567, 1530, + 1493, 1455, 1418, 1381, 1343, 1306, 1268, 1231, + 1193, 1156, 1118, 1080, 1043, 1005, 967, 930, + 892, 854, 816, 778, 740, 703, 665, 627, + 589, 551, 513, 475, 437, 399, 361, 323, + 285, 247, 209, 171, 133, 95, 57, 19 }; const Word16 edct_table_128_16fx[128] = /*Q15 */ { - 9742, 9740, 9737, 9733, 9727, 9720, 9711, 9701, - 9689, 9676, 9661, 9645, 9627, 9608, 9588, 9566, - 9543, 9518, 9492, 9464, 9435, 9405, 9373, 9339, - 9305, 9269, 9231, 9192, 9152, 9110, 9067, 9023, - 8977, 8930, 8882, 8832, 8781, 8728, 8675, 8619, - 8563, 8505, 8447, 8386, 8325, 8262, 8198, 8133, - 8067, 7999, 7930, 7860, 7789, 7717, 7643, 7568, - 7492, 7415, 7337, 7258, 7178, 7097, 7014, 6931, - 6846, 6761, 6674, 6586, 6498, 6408, 6318, 6226, - 6134, 6040, 5946, 5851, 5755, 5658, 5560, 5462, - 5362, 5262, 5161, 5059, 4957, 4854, 4750, 4645, - 4539, 4433, 4327, 4219, 4111, 4002, 3893, 3783, - 3673, 3562, 3450, 3338, 3226, 3113, 2999, 2885, - 2771, 2656, 2541, 2425, 2309, 2193, 2076, 1959, - 1842, 1724, 1607, 1489, 1370, 1252, 1133, 1014, - 895, 776, 657, 538, 418, 299, 179, 60 + 9742, 9740, 9737, 9733, 9727, 9720, 9711, 9701, + 9689, 9676, 9661, 9645, 9627, 9608, 9588, 9566, + 9543, 9518, 9492, 9464, 9435, 9405, 9373, 9339, + 9305, 9269, 9231, 9192, 9152, 9110, 9067, 9023, + 8977, 8930, 8882, 8832, 8781, 8728, 8675, 8619, + 8563, 8505, 8447, 8386, 8325, 8262, 8198, 8133, + 8067, 7999, 7930, 7860, 7789, 7717, 7643, 7568, + 7492, 7415, 7337, 7258, 7178, 7097, 7014, 6931, + 6846, 6761, 6674, 6586, 6498, 6408, 6318, 6226, + 6134, 6040, 5946, 5851, 5755, 5658, 5560, 5462, + 5362, 5262, 5161, 5059, 4957, 4854, 4750, 4645, + 4539, 4433, 4327, 4219, 4111, 4002, 3893, 3783, + 3673, 3562, 3450, 3338, 3226, 3113, 2999, 2885, + 2771, 2656, 2541, 2425, 2309, 2193, 2076, 1959, + 1842, 1724, 1607, 1489, 1370, 1252, 1133, 1014, + 895, 776, 657, 538, 418, 299, 179, 60 }; const Word16 edct_table_160_16fx[160] =//Q15 { - 9213, 9212, 9211, 9208, 9204, 9200, 9195, 9188, - 9181, 9173, 9164, 9155, 9144, 9132, 9120, 9107, - 9093, 9078, 9062, 9045, 9027, 9009, 8989, 8969, - 8948, 8926, 8903, 8880, 8855, 8830, 8803, 8776, - 8748, 8719, 8690, 8659, 8628, 8596, 8563, 8529, - 8495, 8459, 8423, 8386, 8348, 8309, 8270, 8230, - 8188, 8147, 8104, 8061, 8016, 7971, 7926, 7879, - 7832, 7784, 7735, 7686, 7635, 7584, 7533, 7480, - 7427, 7373, 7319, 7263, 7207, 7151, 7093, 7035, - 6976, 6917, 6857, 6796, 6735, 6673, 6610, 6547, - 6483, 6418, 6353, 6287, 6221, 6154, 6086, 6018, - 5949, 5880, 5810, 5739, 5668, 5597, 5525, 5452, - 5379, 5305, 5231, 5156, 5081, 5005, 4929, 4852, - 4775, 4698, 4620, 4541, 4462, 4383, 4303, 4223, - 4142, 4061, 3980, 3898, 3816, 3734, 3651, 3568, - 3484, 3400, 3316, 3231, 3146, 3061, 2976, 2890, - 2804, 2718, 2631, 2544, 2457, 2370, 2282, 2195, - 2107, 2019, 1930, 1842, 1753, 1664, 1575, 1486, - 1397, 1307, 1218, 1128, 1038, 948, 858, 768, - 678, 588, 497, 407, 317, 226, 136, 45 + 9213, 9212, 9211, 9208, 9204, 9200, 9195, 9188, + 9181, 9173, 9164, 9155, 9144, 9132, 9120, 9107, + 9093, 9078, 9062, 9045, 9027, 9009, 8989, 8969, + 8948, 8926, 8903, 8880, 8855, 8830, 8803, 8776, + 8748, 8719, 8690, 8659, 8628, 8596, 8563, 8529, + 8495, 8459, 8423, 8386, 8348, 8309, 8270, 8230, + 8188, 8147, 8104, 8061, 8016, 7971, 7926, 7879, + 7832, 7784, 7735, 7686, 7635, 7584, 7533, 7480, + 7427, 7373, 7319, 7263, 7207, 7151, 7093, 7035, + 6976, 6917, 6857, 6796, 6735, 6673, 6610, 6547, + 6483, 6418, 6353, 6287, 6221, 6154, 6086, 6018, + 5949, 5880, 5810, 5739, 5668, 5597, 5525, 5452, + 5379, 5305, 5231, 5156, 5081, 5005, 4929, 4852, + 4775, 4698, 4620, 4541, 4462, 4383, 4303, 4223, + 4142, 4061, 3980, 3898, 3816, 3734, 3651, 3568, + 3484, 3400, 3316, 3231, 3146, 3061, 2976, 2890, + 2804, 2718, 2631, 2544, 2457, 2370, 2282, 2195, + 2107, 2019, 1930, 1842, 1753, 1664, 1575, 1486, + 1397, 1307, 1218, 1128, 1038, 948, 858, 768, + 678, 588, 497, 407, 317, 226, 136, 45 }; @@ -4965,8 +4965,8 @@ const Word16 edct_table_160_16fx[160] =//Q15 const Word16 mean_isf_amr_wb_fx[M] =/*Qlog2(2.56)*/ { - 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, - 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 + 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, + 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 };/*1.28f Q1*/ /*----------------------------------------------------------------------------------* @@ -4975,8 +4975,8 @@ const Word16 mean_isf_amr_wb_fx[M] =/*Qlog2(2.56)*/ const Word16 mean_isf_noise_amr_wb_fx[M] =/*Qlog2(2.56)*/ { - 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240, - 8229, 9153,10098, 11108, 12144, 13184,14165, 3803 + 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240, + 8229, 9153,10098, 11108, 12144, 13184,14165, 3803 };/*14Q1*1.28*/ /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ @@ -4984,47 +4984,47 @@ const Word16 mean_isf_noise_amr_wb_fx[M] =/*Qlog2(2.56)*/ * Indirection for 1st stage 1st split of 46 bit cb. : The transmitted_index = indirect_dico1[found_index]; *------------------------------------------------------*/ -const Word16 Indirect_dico1[SIZE_BK1] = // Q0 -{ - 2, 6, 18, 22, 34, 35, 38, 50, - 66, 67, 70, 82, 98, 99, 102, 130, - 131, 134, 146, 150, 162, 178, 194, 198, - 210, 226, 230, 242, 0, 1, 3, 4, - 5, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 19, 20, 21, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 36, 37, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 51, - 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 68, 69, - 71, 72, 73, 74, 75, 76, 77, 78, - 79, 80, 81, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 100, 101, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 120, 121, 122, - 123, 124, 125, 126, 127, 128, 129, 132, - 133, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 147, 148, 149, 151, - 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 163, 164, 165, 166, 167, 168, - 169, 170, 171, 172, 173, 174, 175, 176, - 177, 179, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, - 195, 196, 197, 199, 200, 201, 202, 203, - 204, 205, 206, 207, 208, 209, 211, 212, - 213, 214, 215, 216, 217, 218, 219, 220, - 221, 222, 223, 224, 225, 227, 228, 229, - 231, 232, 233, 234, 235, 236, 237, 238, - 239, 240, 241, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255 +const Word16 Indirect_dico1[SIZE_BK1] = // Q0 +{ + 2, 6, 18, 22, 34, 35, 38, 50, + 66, 67, 70, 82, 98, 99, 102, 130, + 131, 134, 146, 150, 162, 178, 194, 198, + 210, 226, 230, 242, 0, 1, 3, 4, + 5, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 19, 20, 21, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 36, 37, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 51, + 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 68, 69, + 71, 72, 73, 74, 75, 76, 77, 78, + 79, 80, 81, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 100, 101, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 127, 128, 129, 132, + 133, 135, 136, 137, 138, 139, 140, 141, + 142, 143, 144, 145, 147, 148, 149, 151, + 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 163, 164, 165, 166, 167, 168, + 169, 170, 171, 172, 173, 174, 175, 176, + 177, 179, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, + 195, 196, 197, 199, 200, 201, 202, 203, + 204, 205, 206, 207, 208, 209, 211, 212, + 213, 214, 215, 216, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 227, 228, 229, + 231, 232, 233, 234, 235, 236, 237, 238, + 239, 240, 241, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255 }; /*----------------------------------------------------------------------------------* * Initial LSF memory *----------------------------------------------------------------------------------*/ -const Word16 lsf_init_fx[16] = /*14Q1*1.28*/ +const Word16 lsf_init_fx[16] = /*14Q1*1.28*/ { 960, 1920, 2880, 3840, 4800, 5760, 6720, 7680, 8640, 9600, 10560, 11520, 12480, 13440, 14400, 15360 }; @@ -5065,38 +5065,38 @@ const Word16 gaus_dico_fx[190] = const Word16 gaus_dico_swb_fx[256] = { /*Q15 */ - 709, 11759, -5333, -2701, 2397, -18, -4286, 2368, - -4576, -1584, -900, -940, 3676, 5441, -44, 2234, - -5698, 3082, -2671, 1666, -640, -3343, -1005, -1689, - 2048, 281, -3935, -3723, 5628, 385, -746, -3243, - -3332, -7228, -1748, -206, -5474, 2554, 2861, 3168, - 5039, 588, -508, -8167, 6549, -3433, 2187, -3666, - -5874, 2767, 8370, 1038, 6434, 6279, 625, 4030, - -1031, 1823, 9896, -1395, 2712, -1110, -742, 6142, - -4456, -10487, -144, -5104, 1968, -312, 6176, 2173, - 2334, -240, 2712, 7460, 2219, -3116, -56, 2770, - 5577, -1225, 770, 3557, 2246, 2322, 3077, 41, - 992, -4971, 441, -5039, 4913, 3811, 1142, -1283, - -6578, 4171, -1473, -3793, -5008, 1984, -1138, -1185, - 5646, 1014, -5118, 7141, 2656, -7241, -3538, 2337, - 7239, -504, -943, -10129, 702, -3811, -302, 2435, - 5090, 3744, 2335, -3904, -1401, -1662, -7256, 6484, - -6864, -5428, 1954, -7316, -1420, -1542, 5442, 311, - 3698, -1343, -2974, 8756, 324, -1903, 2580, 2635, - 4236, -1851, 3147, -772, -708, -3830, 2601, -1889, - -3444, -762, 3939, 3206, -7406, -837, -1167, -438, - 3707, -1015, -7472, 1849, 4277, 1459, -3047, -3760, - 740, -7134, -3753, -3092, 209, -12121, 1398, 2266, - 2505, -7974, -1121, -3481, -5644, 1329, 4532, 958, - 5311, -4258, -3195, -1769, -3055, 4399, -15, 10182, - 4503, 1912, -1574, 5054, -3163, 4881, -5364, 1925, - -1205, -6432, 2305, -8917, -1422, 514, -3001, 3928, - 2321, 360, -355, 1477, -3492, -4570, 1913, 2772, - -1380, -5161, 3812, 2614, 2204, -3135, 1244, -3066, - -4446, -6389, 4899, -5250, 1372, 1999, 1122, 5312, - 1310, -1189, -3310, 6403, 3818, 7734, 1620, -8533, - 706, 7498, -4472, 1272, -949, 3203, -4427, -2855, - 4419, 2283, 6410, 2584, -3397, -3382, -2976, -48, + 709, 11759, -5333, -2701, 2397, -18, -4286, 2368, + -4576, -1584, -900, -940, 3676, 5441, -44, 2234, + -5698, 3082, -2671, 1666, -640, -3343, -1005, -1689, + 2048, 281, -3935, -3723, 5628, 385, -746, -3243, + -3332, -7228, -1748, -206, -5474, 2554, 2861, 3168, + 5039, 588, -508, -8167, 6549, -3433, 2187, -3666, + -5874, 2767, 8370, 1038, 6434, 6279, 625, 4030, + -1031, 1823, 9896, -1395, 2712, -1110, -742, 6142, + -4456, -10487, -144, -5104, 1968, -312, 6176, 2173, + 2334, -240, 2712, 7460, 2219, -3116, -56, 2770, + 5577, -1225, 770, 3557, 2246, 2322, 3077, 41, + 992, -4971, 441, -5039, 4913, 3811, 1142, -1283, + -6578, 4171, -1473, -3793, -5008, 1984, -1138, -1185, + 5646, 1014, -5118, 7141, 2656, -7241, -3538, 2337, + 7239, -504, -943, -10129, 702, -3811, -302, 2435, + 5090, 3744, 2335, -3904, -1401, -1662, -7256, 6484, + -6864, -5428, 1954, -7316, -1420, -1542, 5442, 311, + 3698, -1343, -2974, 8756, 324, -1903, 2580, 2635, + 4236, -1851, 3147, -772, -708, -3830, 2601, -1889, + -3444, -762, 3939, 3206, -7406, -837, -1167, -438, + 3707, -1015, -7472, 1849, 4277, 1459, -3047, -3760, + 740, -7134, -3753, -3092, 209, -12121, 1398, 2266, + 2505, -7974, -1121, -3481, -5644, 1329, 4532, 958, + 5311, -4258, -3195, -1769, -3055, 4399, -15, 10182, + 4503, 1912, -1574, 5054, -3163, 4881, -5364, 1925, + -1205, -6432, 2305, -8917, -1422, 514, -3001, 3928, + 2321, 360, -355, 1477, -3492, -4570, 1913, 2772, + -1380, -5161, 3812, 2614, 2204, -3135, 1244, -3066, + -4446, -6389, 4899, -5250, 1372, 1999, 1122, 5312, + 1310, -1189, -3310, 6403, 3818, 7734, 1620, -8533, + 706, 7498, -4472, 1272, -949, 3203, -4427, -2855, + 4419, 2283, 6410, 2584, -3397, -3382, -2976, -48, }; @@ -5104,7 +5104,7 @@ const Word16 gaus_dico_swb_fx[256] = * CLDFB tables *----------------------------------------------------------------------------------*/ -const Word16 freqTable[2] = {20, 40}; // Q0 +const Word16 freqTable[2] = {20, 40}; // Q0 /* SNR: 109.44, PHASE: 3.500000000000000 */ @@ -6657,11 +6657,11 @@ const Word16 iRotVectr_60[] =//Q(sqrt(1.0/2.00)) W16(0x9ae0), W16(0x99a2), W16(0x98ac), W16(0x97fe), W16(0x9799) }; -const Word16 cldfb_anaScale[] = // Q0 +const Word16 cldfb_anaScale[] = // Q0 { SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60, SCALE_CLDFB_ANA_30 }; -const Word16 cldfb_synScale[] = // Q0 +const Word16 cldfb_synScale[] = // Q0 { SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60, SCALE_CLDFB_SYN_30 }; @@ -6749,7 +6749,7 @@ const Word32 rot_vec_syn_im_L20_fx[10] = const Word32 rot_vec_syn_re_L30_fx[15] = { 240075408 ,238431728 ,234175760 ,227354112 ,218041520 ,206340016 ,192377808 ,176307872 , - 158306272 ,138570240 ,117315992 ,94776408 ,71198440 ,46840400 ,21969170 , + 158306272 ,138570240 ,117315992 ,94776408 ,71198440 ,46840400 ,21969170 , }; @@ -6757,7 +6757,7 @@ const Word32 rot_vec_syn_re_L30_fx[15] = const Word32 rot_vec_syn_im_L30_fx[15] = { -3142759 ,-28220256 ,-52988564 ,-77176320 ,-100518520 ,-122759408 ,-143655328 ,-162977328 , - -180513712 ,-196072352 ,-209482768 ,-220598064 ,-229296448 ,-235482592 ,-239088752 , + -180513712 ,-196072352 ,-209482768 ,-220598064 ,-229296448 ,-235482592 ,-239088752 , }; @@ -6765,7 +6765,7 @@ const Word32 rot_vec_syn_im_L30_fx[15] = const Word32 rot_vec_syn_re_L32_fx[16] = { 240077888 ,238633056 ,234890064 ,228884944 ,220675536 ,210340896 ,197980576 ,183713584 , - 167677328 ,150026240 ,130930336 ,110573488 ,89151760 ,66871456 ,43947140 ,20599588 , + 167677328 ,150026240 ,130930336 ,110573488 ,89151760 ,66871456 ,43947140 ,20599588 , }; @@ -6773,7 +6773,7 @@ const Word32 rot_vec_syn_re_L32_fx[16] = const Word32 rot_vec_syn_im_L32_fx[16] = { -2946347 ,-26463908 ,-49726608 ,-72510408 ,-94595904 ,-115770384 ,-135829936 ,-154581360 , - -171844080 ,-187451856 ,-201254368 ,-213118704 ,-222930576 ,-230595504 ,-236039664 ,-239210640 , + -171844080 ,-187451856 ,-201254368 ,-213118704 ,-222930576 ,-230595504 ,-236039664 ,-239210640 , }; @@ -6781,8 +6781,8 @@ const Word32 rot_vec_syn_im_L32_fx[16] = const Word32 rot_vec_syn_re_L40_fx[20] = { 240084400 ,239159360 ,236759824 ,232900592 ,227605456 ,220907040 ,212846672 ,203474016 , - 192846896 ,181030800 ,168098592 ,154130000 ,139211136 ,123434000 ,106895848 ,89698648 , - 71948424 ,53754620 ,35229396 ,16486972 , + 192846896 ,181030800 ,168098592 ,154130000 ,139211136 ,123434000 ,106895848 ,89698648 , + 71948424 ,53754620 ,35229396 ,16486972 , }; @@ -6790,8 +6790,8 @@ const Word32 rot_vec_syn_re_L40_fx[20] = const Word32 rot_vec_syn_im_L40_fx[20] = { -2357099 ,-21186638 ,-39885552 ,-58338564 ,-76431896 ,-94054000 ,-111096224 ,-127453512 , - -143025008 ,-157714704 ,-171432032 ,-184092416 ,-195617824 ,-205937184 ,-214986864 ,-222711088 , - -229062224 ,-234001104 ,-237497296 ,-239529232 , + -143025008 ,-157714704 ,-171432032 ,-184092416 ,-195617824 ,-205937184 ,-214986864 ,-222711088 , + -229062224 ,-234001104 ,-237497296 ,-239529232 , }; @@ -6799,9 +6799,9 @@ const Word32 rot_vec_syn_im_L40_fx[20] = const Word32 rot_vec_syn_re_L60_fx[30] = { 240090832 ,239679552 ,238611328 ,236889088 ,234517552 ,231503216 ,227854352 ,223580960 ,218694736 , - 213209088 ,207139056 ,200501264 ,193313904 ,185596688 ,177370784 ,168658704 ,159484336 ,149872832 , - 139850544 ,129444936 ,118684528 ,107598816 ,96218184 ,84573816 ,72697640 ,60622212 ,48380616 , - 36006412 ,23533520 ,10996123 , + 213209088 ,207139056 ,200501264 ,193313904 ,185596688 ,177370784 ,168658704 ,159484336 ,149872832 , + 139850544 ,129444936 ,118684528 ,107598816 ,96218184 ,84573816 ,72697640 ,60622212 ,48380616 , + 36006412 ,23533520 ,10996123 , }; @@ -6809,9 +6809,9 @@ const Word32 rot_vec_syn_re_L60_fx[30] = const Word32 rot_vec_syn_im_L60_fx[30] = { -1571413 ,-14134643 ,-26659130 ,-39110548 ,-51454764 ,-63657948 ,-75686648 ,-87507896 ,-99089296 , - -110399096 ,-121406296 ,-132080736 ,-142393152 ,-152315264 ,-161819904 ,-170881008 ,-179473744 , - -187574544 ,-195161216 ,-202212960 ,-208710464 ,-214635904 ,-219973040 ,-224707248 ,-228825536 , - -232316640 ,-235170976 ,-237380736 ,-238939840 ,-239844032 , + -110399096 ,-121406296 ,-132080736 ,-142393152 ,-152315264 ,-161819904 ,-170881008 ,-179473744 , + -187574544 ,-195161216 ,-202212960 ,-208710464 ,-214635904 ,-219973040 ,-224707248 ,-228825536 , + -232316640 ,-235170976 ,-237380736 ,-238939840 ,-239844032 , }; @@ -7022,21 +7022,21 @@ const Word32 scaleTable_cn_only_amrwbio_fx_by_10f[SIZE_SCALE_TABLE_CN_AMRWB][2] { ACELP_12k65, 429496729 } }; -const Word16 sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 279 }; // Q0 +const Word16 sidparts_encoder_noise_est[SIZE_SIDPARTS_ENC_NOISE_EST] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 279 }; // Q0 -const Word16 sidPartitions_nb[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 159 }; // Q0 -const Word16 sidPartitions_wb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255 }; // Q0 -const Word16 sidPartitions_wb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259 }; // Q0 -const Word16 sidPartitions_wb3[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319 }; // Q0 -const Word16 sidPartitions_swb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 274 }; // Q0 -const Word16 sidPartitions_swb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319, 324, 329, 339 }; // Q0 +const Word16 sidPartitions_nb[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 159 }; // Q0 +const Word16 sidPartitions_wb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255 }; // Q0 +const Word16 sidPartitions_wb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259 }; // Q0 +const Word16 sidPartitions_wb3[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319 }; // Q0 +const Word16 sidPartitions_swb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 274 }; // Q0 +const Word16 sidPartitions_swb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319, 324, 329, 339 }; // Q0 -const Word16 shapingPartitions_nb[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 159 }; // Q0 -const Word16 shapingPartitions_wb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 -const Word16 shapingPartitions_wb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 -const Word16 shapingPartitions_wb3[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; // Q0 -const Word16 shapingPartitions_swb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 -const Word16 shapingPartitions_swb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; // Q0 +const Word16 shapingPartitions_nb[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 159 }; // Q0 +const Word16 shapingPartitions_wb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 +const Word16 shapingPartitions_wb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 +const Word16 shapingPartitions_wb3[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; // Q0 +const Word16 shapingPartitions_swb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; // Q0 +const Word16 shapingPartitions_swb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; // Q0 const FD_CNG_SETUP FdCngSetup_nb = { 512, 160, sizeof(sidPartitions_nb)/sizeof(Word16), sidPartitions_nb, sizeof(shapingPartitions_nb)/sizeof(Word16), shapingPartitions_nb }; const FD_CNG_SETUP FdCngSetup_wb1 = { 512, 256, sizeof(sidPartitions_wb1)/sizeof(Word16), sidPartitions_wb1, sizeof(shapingPartitions_wb1)/sizeof(Word16), shapingPartitions_wb1 }; @@ -7046,8 +7046,8 @@ const FD_CNG_SETUP FdCngSetup_swb1 = { 512, 256, sizeof(sidPartitions_swb1)/size const FD_CNG_SETUP FdCngSetup_swb2 = { 640, 320, sizeof(sidPartitions_swb2)/sizeof(Word16), sidPartitions_swb2, sizeof(shapingPartitions_swb2)/sizeof(Word16), shapingPartitions_swb2 }; -const Word16 levels_37bits[FD_CNG_stages_37bits] = { 128, 64, 64, 64, 64, 64 }; // Q0 -const Word16 bits_37bits[FD_CNG_stages_37bits] = { 7, 6, 6, 6, 6, 6 }; // Q0 +const Word16 levels_37bits[FD_CNG_stages_37bits] = { 128, 64, 64, 64, 64, 64 }; // Q0 +const Word16 bits_37bits[FD_CNG_stages_37bits] = { 7, 6, 6, 6, 6, 6 }; // Q0 /* IDCT_MATRIX_ROM: 18*24 Word16 = 432 Word16 */ /* or compressed IDCT_MATRIX_ROM: 18*24 Word8 + 25 = 230 Word16 + WMOPS (INDIRECT(432) and STORE(432) ) */ @@ -7060,8 +7060,8 @@ const Word16 bits_37bits[FD_CNG_stages_37bits] = { 7, 6, 6, 6, 6, 6 }; // Q0 /* additional minor Table ROM ( dct_mid points 18 Word16, dct_col_upshifts 52, scaleFactors 2*2 = ~= 74 Word16s */ -const Word16 cdk1_ivas_entries_per_segment[FDCNG_VQ_DCT_NSEGM] = { 16, 17, 17, 78 }; // Q0 -const Word16 cdk1_ivas_cum_entries_per_segment[FDCNG_VQ_DCT_NSEGM + 1] = { 0, 16 ,33, 50, 128 }; // Q0 +const Word16 cdk1_ivas_entries_per_segment[FDCNG_VQ_DCT_NSEGM] = { 16, 17, 17, 78 }; // Q0 +const Word16 cdk1_ivas_cum_entries_per_segment[FDCNG_VQ_DCT_NSEGM + 1] = { 0, 16 ,33, 50, 128 }; // Q0 const Word16 /* DCT trunc_len */ cdk1_ivas_cols_per_segment[FDCNG_VQ_DCT_NSEGM] = { FDCNG_VQ_DCT_MINTRUNC, 10, 16, FDCNG_VQ_DCT_MAXTRUNC }; /* 8, 10, 16, 18 */ const Word16 /* segment inner DCT trunc_len */ cdk1_ivas_trunc_dct_cols_per_segment[FDCNG_VQ_DCT_NSEGM] = { FDCNG_VQ_DCT_MAXTRUNC - FDCNG_VQ_DCT_MINTRUNC, FDCNG_VQ_DCT_MAXTRUNC - 10 , FDCNG_VQ_DCT_MAXTRUNC - 16 , 0 }; @@ -7079,25 +7079,25 @@ const Word8* const cdk_37bits_ivas_stage1_W8Qx_dct_sections[] = { cdk1_ivas_dct_ /* scaling constants */ const Word32 fdcng_dct_scaleF_fx[3] = { 902561792, 56410112,1481781 };//Q31 -const Word16 stage1_col_syn_shift_segm0[8] = { // Q0 +const Word16 stage1_col_syn_shift_segm0[8] = { // Q0 4, 4, 4, 3, 2, 2, 2, 1 }; -const Word16 stage1_col_syn_shift_segm1[10] = { // Q0 +const Word16 stage1_col_syn_shift_segm1[10] = { // Q0 4, 4, 4, 3, 2, 2, 2, 1, 1, 1 }; -const Word16 stage1_col_syn_shift_segm2[16] = { // Q0 +const Word16 stage1_col_syn_shift_segm2[16] = { // Q0 4, 4, 4, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1 }; -const Word16 stage1_col_syn_shift_segm3[18] = { // Q0 +const Word16 stage1_col_syn_shift_segm3[18] = { // Q0 4, 4, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 }; /* segment individual shiftfactor to Q4 for each stored DCT Word8 coeff column */ -const Word16 * stage1_dct_col_syn_shift[FDCNG_VQ_DCT_NSEGM] = { stage1_col_syn_shift_segm0, stage1_col_syn_shift_segm1,stage1_col_syn_shift_segm2,stage1_col_syn_shift_segm3 }; // Q0 +const Word16 * stage1_dct_col_syn_shift[FDCNG_VQ_DCT_NSEGM] = { stage1_col_syn_shift_segm0, stage1_col_syn_shift_segm1,stage1_col_syn_shift_segm2,stage1_col_syn_shift_segm3 }; // Q0 /* 25 unique abs values of idct24_18matrix Q16 */ @@ -7124,7 +7124,7 @@ const Word8 idctT2_24_compressed_idx[(FDCNG_VQ_DCT_MAXTRUNC * FDCNG_VQ_MAX_LEN) 12, 5, -14, -15, 4, 23, 6, -13, -16, 3, 22, 7, -12, -17, 2, 21, 8, -11, 12, 3, -18, -9, 12, 15, -6, -21, 0, 21, 6, -15, -12, 9, 18, -3, -24, -3, 12, 1, -22, -3, 20, 5, -18, -7, 16, 9, -14, -11, 12, 13, -10, -15, 8, 17 -}; // Q0 +}; // Q0 const Word16 unique_idctT2_21coeffsQ16[23] = {//Q16 @@ -7156,7 +7156,7 @@ const Word8 idctT2_21_compressed_idx[(FDCNG_VQ_DCT_MAXTRUNC *( (21/2) + 1)) /* /*tables in truncated DCTII_24 domain */ -const Word8 /*seg 0, 16 x 8 */ cdk1_ivas_dct_s0_W8[128] = { // Q0 +const Word8 /*seg 0, 16 x 8 */ cdk1_ivas_dct_s0_W8[128] = { // Q0 29, -126, 8, -34, -45, -42, -13, 2, 22, -120, 0, -27, -41, -50, -25, 42, 20, -116, -2, -39, -61, -33, -22, -25, @@ -7175,7 +7175,7 @@ const Word8 /*seg 0, 16 x 8 */ cdk1_ivas_dct_s0_W8[128] = { // Q0 -17, 125, 6, 74, 21, 85, 5, 98 }; -const Word8 /*seg 1, 17 x 10 */ cdk1_ivas_dct_s1_W8[170] = { // Q0 +const Word8 /*seg 1, 17 x 10 */ cdk1_ivas_dct_s1_W8[170] = { // Q0 20, -127, -12, -9, 1, -30, -2, -1, -43, -54, 24, -113, 3, -39, -49, -25, -15, -27, 6, 2, 55, 17, 74, 22, 78, 77, 87, 97, 89, 61, @@ -7195,7 +7195,7 @@ const Word8 /*seg 1, 17 x 10 */ cdk1_ivas_dct_s1_W8[170] = { // Q0 -8, 127, 23, 24, 58, 89, 46, 20, 14, 54 }; -const Word8 /*seg 2, 17 x 16 */ cdk1_ivas_dct_s2_W8[272] = { // Q0 +const Word8 /*seg 2, 17 x 16 */ cdk1_ivas_dct_s2_W8[272] = { // Q0 32, -69, 21, 3, -9, 17, 3, 14, 15, 35, -17, -10, -20, 28, -52, -19, 24, -49, 17, 9, -6, 14, 22, 33, 51, 38, 21, 14, 5, 38, 13, -5, 27, -8, 30, 9, 93, 65, 65, 66, 67, 30, 39, 21, 9, 22, 5, -17, @@ -7215,7 +7215,7 @@ const Word8 /*seg 2, 17 x 16 */ cdk1_ivas_dct_s2_W8[272] = { // Q0 4, 117, 37, 43, 44, 32, 13, 75, 32, 33, 15, -70, 51, 39, 68, 15 }; -const Word8 /*seg 3, 78 x 18 */ cdk1_ivas_dct_s3_W8[1404] = { // Q0 +const Word8 /*seg 3, 78 x 18 */ cdk1_ivas_dct_s3_W8[1404] = { // Q0 21, -127, -23, -10, 7, -26, 1, 6, -39, -53, -19, -84, -34, 16, -10, -24, -75, 9, 76, -117, 124, -63, 75, 72, -9, 115, 42, 100, -36, 120, -37, 66, 46, 72, -34, 18, 24, -115, 3, -65, -47, -24, -7, -13, 1, -18, -10, -58, -30, 2, -37, -27, -78, 9, @@ -7299,7 +7299,7 @@ const Word8 /*seg 3, 78 x 18 */ cdk1_ivas_dct_s3_W8[1404] = { // Q0 /* stage1 low complex search tables */ /* segm_neighbour_fwd/segm_neighbour_rev nex/previous indeces in an circularly ordered list of close MSE neighbours */ -const Word8 cdk1_ivas_segm_neighbour_fwd[128] = { // Q0 +const Word8 cdk1_ivas_segm_neighbour_fwd[128] = { // Q0 3, 0, 4, 62, 5, 58, 64, 59, 33, 19, 9, 127, 26, 12, 28, 31, 1, 2, 51, 38, 18, 25, 43, 21, @@ -7317,7 +7317,7 @@ const Word8 cdk1_ivas_segm_neighbour_fwd[128] = { // Q0 82, 103, 121, 110, 109, 115, 40, 123, 116, 122, 120, 46, 93, 20, 125, 45 }; -const Word8 cdk1_ivas_segm_neighbour_rev[128] = { // Q0 +const Word8 cdk1_ivas_segm_neighbour_rev[128] = { // Q0 1, 16, 17, 0, 2, 4, 63, 51, 65, 10, 44, 27, 13, 29, 30, 49, 50, 57, 20, 9, 125, 23, 36, 26, @@ -8706,11 +8706,11 @@ const Word16 cdk_37bits_6_fx[1536] =//Q7 const Word16 * const cdk_37bits[] = { cdk_37bits_1_fx, cdk_37bits_2_fx, cdk_37bits_3_fx, cdk_37bits_4_fx, cdk_37bits_5_fx, cdk_37bits_6_fx -}; // Q7 +}; // Q7 const Word16 * const ivas_cdk_37bits_fx[] = { NULL, cdk_37bits_2_fx, cdk_37bits_3_fx, cdk_37bits_4_fx, cdk_37bits_5_fx, cdk_37bits_6_fx -}; // Q7 +}; // Q7 /* Sine tables for FFT */ /* for (j=0; jfftlen/2+1; j++) hs->fftSineTab[j] = (float)sin(2.0*EVS_PI*j/hs->fftlen); */ @@ -8942,290 +8942,290 @@ const Word16 olapWinSyn320_fx[320] = const Word16 dico1_isf_fx[] = {/*Qlog2(2.56)*/ - 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923, - 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241, - 633, 898, 996, 756, 662, 683, 783, 909, 996, - 830, 736, 278, 820, 1254, 686, 712, 1039, 473, - 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061, - 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044, - 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314, - -31, 469, 803, 659, 619, 658, 843, 987, 1113, - 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742, - 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71, - 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391, - 1513, 1714, 1238, 534, 276, 315, 461, 459, 508, - 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006, - -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712, - -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217, - 670, 1208, 1168, 860, 742, 601, 528, 403, 309, - 397, 621, 966, 752, 579, 398, 400, 329, 252, - 510, 864, 1108, 807, 939, 902, 925, 717, 481, - 539, 835, 913, 719, 617, 544, 591, 565, 642, - 162, 889, 654, 108, -34, 244, 488, 561, 532, - -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823, - -14, 945, 990, 801, 755, 815, 847, 913, 892, - 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380, - 529, 1851, 2003, 1228, 622, -41, -416, 344, 819, - 635, 1058, 883, 492, 372, 312, 317, 274, 241, - 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339, - 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539, - 148, 751, 1515, 1105, 867, 606, 474, 448, 399, - 579, 1081, 1035, 390, 3, -263, -198, -82, 38, - 18, -68, -12, 313, 761, 405, 249, 111, -76, - -91, 827, 948, 648, 613, 535, 522, 490, 421, - 41, -44, -281, -472, 652, 534, 193, 135, -90, - 41, -121, -356, -60, 663, 307, 61, -48, -344, - -118, -204, 328, 512, 870, 793, 610, 402, 186, - 156, 293, 74, -338, -475, -897, -594, -161, -497, - 226, 131, -138, 307, 169, -271, -164, -387, -624, - 62, -32, -61, -252, -541, -828, -1027, -523, -662, - 102, -61, 141, 112, -270, -251, -541, 25, -150, - 6, -132, -356, -686, -96, -322, -522, -31, -326, - -36, -209, -521, -229, 307, -132, -5, -99, -384, - 60, -51, -237, -668, -973, -407, -708, -75, -172, - 26, -138, -266, 111, -302, 43, -278, -356, -359, - 570, 822, 496, -154, -312, -92, 137, 279, 371, - -146, 368, 409, 68, 6, 77, 167, 202, 162, - -103, 294, 607, 415, 483, 462, 480, 431, 408, - -120, -338, -612, -524, 584, 331, 92, 433, 276, - -178, -293, -154, -41, 269, 100, -9, 213, 160, - -218, -304, 463, 454, 397, 273, 202, 286, 273, - -232, 7, 6, -388, -472, -427, -378, -167, -100, - -294, -183, 134, -47, 101, -88, -84, -117, -3, - 57, 17, -202, -634, -989, -1119, -533, 176, -36, - 120, -28, 23, 111, -319, 318, -22, -77, 266, - -271, -464, -434, -658, -640, -385, -385, -99, -69, - -198, -259, -266, -44, -39, -139, -137, 171, 66, - 9, -145, -377, -846, -1000, -111, -325, 342, 135, - -81, -286, -380, 192, -57, 307, 76, -24, -140, - 677, 702, 247, 56, 249, 141, -105, -236, -99, - 36, -39, -69, 348, 198, -93, 322, 91, -72, - -127, -376, -657, 139, 623, 223, 501, 306, 220, - -113, -384, -796, 504, 438, 85, 213, -83, -194, - -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806, - 8, -126, -317, -103, -351, -695, -98, -268, -537, - 33, -103, -290, 167, -39, -407, 44, -208, -375, - 104, -23, -64, -291, -637, -851, -1084, -61, -112, - -75, -306, -434, 218, -148, -354, -680, -133, -216, - -121, -377, -718, -97, -130, -361, -156, -379, -599, - -56, -254, -586, 235, 157, -214, 11, -260, -149, - -124, -267, -397, -580, -593, -527, -805, -385, 346, - -193, -440, -708, -351, -141, -255, -499, -147, -185, - 448, 660, 494, 208, 509, 461, 338, 291, 149, - -223, 88, 335, 159, 212, 191, 286, 308, 205, - -171, -242, 514, 362, 295, 524, 552, 694, 585, - -64, -308, -448, -21, 284, 786, 446, 289, 92, - -218, -390, -7, 169, 206, 330, 352, 408, 358, - -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305, - -133, -341, -65, 678, 417, 440, 486, 518, 780, - 33, -44, -191, -344, -461, -755, -201, 217, -31, - -353, -547, -44, 123, -61, -68, -79, 29, 60, - 73, -57, -406, -766, -1243, -1203, 240, 400, 165, - -73, -282, -601, -213, -171, -375, 332, 35, -103, - -29, -207, -553, -476, -638, -908, 172, -22, -135, - -192, -239, -164, -103, -111, -47, 153, 125, 110, - -1, -203, -570, -1030, -1424, -535, 155, 1, 147, - -333, -653, -865, -197, -158, -21, -44, 95, 108, - 389, 588, 490, 33, -237, -524, -628, -136, -260, - 40, -177, -462, 453, 862, 380, 131, -130, -405, - -76, -281, -741, -742, 898, 619, 277, 71, -222, - -32, -265, -556, -25, 994, 682, 305, 126, -165, - -69, -349, -585, 234, 1158, 903, 626, 510, 251, - -1, -99, -272, -210, -603, -351, -540, -811, -383, - -16, -230, -504, 410, 149, -205, -343, -651, -639, - 103, -9, -227, -205, -562, -781, -1079, -1208, -156, - 143, 63, -135, -67, -317, -602, -784, -1154, -640, - -144, -391, -674, -622, -200, -254, -660, -947, -395, - -40, -250, -625, 27, 543, 94, -131, -386, -673, - -123, -371, -757, -451, -564, -614, -415, -711, -35, - -116, -309, -593, -268, 239, -33, -338, -650, -135, - 94, 251, 554, 57, -312, -423, -154, -57, 235, - -268, -71, 381, 114, -44, -87, 125, 173, 133, - -131, -19, 1149, 670, 486, 356, 309, 369, 296, - -223, -501, -899, -722, -70, 6, 131, 310, 394, - -99, -303, -517, 249, 64, -53, 135, -11, 453, - -147, -399, -730, -401, 817, 738, 802, 749, 575, - -154, -435, -739, 800, 593, 366, 529, 318, 326, - -224, 45, -39, -387, -515, -518, -608, -384, -321, - -315, -377, 143, -101, -113, -377, -177, -144, -12, - 117, 40, -239, -651, -1051, -581, -737, -990, -328, - 26, -50, -157, -23, -453, -283, -531, -546, 192, - -252, -501, -743, -589, -627, -499, -328, -118, -72, - -324, -494, -244, -306, -144, -177, -262, -135, -78, - -36, -234, -519, -961, -1290, -314, -479, -371, -45, - -95, -292, -535, -8, -300, 112, -164, -277, 198, - -99, -128, 880, 836, 579, 351, 23, -95, -217, - -27, -258, 124, 1011, 597, 425, 144, 7, -73, - -69, -300, -683, -435, 1132, 899, 504, 332, 109, - -74, -323, -637, 563, 1074, 608, 371, 105, -49, - -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933, - -82, -306, -613, -222, -378, -675, -545, -671, -845, - 53, -124, -347, 422, 52, -125, -270, -529, 9, - 79, -89, -320, -662, -999, -1199, -1243, -676, -297, - -68, -273, -611, 137, -146, -397, -627, -845, -220, - -112, -346, -797, -826, 234, -132, -188, -278, -522, - -159, -405, -734, -419, 293, 74, -167, -167, 184, - -153, -437, -833, -1080, -336, -472, -561, -340, -253, - -169, -423, -820, -904, -131, -19, -346, -604, 31, - 33, -31, 312, 62, -148, 49, -59, 564, 486, - -306, -333, 194, -44, 67, 72, 147, 205, 243, - -207, -49, 1360, 983, 969, 991, 1014, 1110, 973, - -211, -172, 883, 627, 711, 674, 705, 798, 746, - -88, -325, -763, -974, 687, 908, 514, 382, 172, - -292, -612, -805, 63, 131, 270, 259, 352, 348, - -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285, - -180, -461, -614, 657, 691, 745, 854, 783, 713, - -97, -309, -477, -614, -777, -734, -768, -526, -472, - -344, -476, -35, -169, 49, -77, -150, -240, -141, - -52, -268, -639, -919, -1278, -1113, -342, -333, -151, - -68, -242, -585, -73, -209, -478, -159, -429, 133, - -197, -499, -1005, -1268, -272, -224, -105, -67, 17, - -363, -618, -414, -116, -62, 20, 10, 116, 108, - -195, -475, -906, -1260, -891, -441, -277, -142, -28, - -226, -519, -950, -700, -275, -266, -116, -105, 82, - 404, 511, 520, 327, 17, -194, -333, -536, -586, - -114, -130, 276, 237, 204, 342, 135, -16, -111, - 191, 180, -137, -467, 272, 106, -95, 17, -192, - -80, -290, -626, 194, 598, 196, 21, -281, 77, - 137, 367, 534, 764, 670, 382, 296, 153, 84, - 303, 497, 144, -85, -125, -539, -482, -464, -764, - 233, 347, 68, -147, 169, -210, -242, -226, -482, - 307, 422, 154, -175, -386, -722, -724, -904, -1015, - 309, 308, 160, -60, -470, -420, -598, -791, -219, - 68, 121, -137, -560, -146, -446, -515, -494, -729, - 130, 53, -227, 46, 474, 32, -161, -192, -490, - 213, 164, -71, -465, -876, -161, -456, -587, -48, - 218, 117, 39, 177, -194, -88, -226, -418, 50, - 210, 547, 569, 279, 121, -44, -50, 10, -84, - 58, 140, 182, -5, 267, 117, 106, 211, 198, - 153, 559, 872, 460, 222, 108, 188, 180, 183, - 158, 119, 284, -153, -271, 229, 87, 110, -57, - -183, 82, 118, 21, 13, 40, 118, 191, 185, - 163, 56, 609, 341, 50, 329, 68, 266, 218, - 100, 206, 18, -304, -107, -436, -487, -65, -306, - -86, 154, 134, -30, -45, -73, -104, -80, -96, - 245, 330, 10, -440, -849, -1082, 79, 40, -265, - 196, 372, 272, -181, -493, -389, 275, 80, -59, - 2, -12, -246, -505, -100, -436, 21, -187, -431, - -221, -48, 36, -271, -186, -147, -109, 26, 71, - 213, 140, 72, -351, -620, -84, -363, 69, 46, - 91, 167, -3, -95, -99, -105, -48, 114, 147, - 259, 249, 172, 607, 406, 52, 59, -189, -320, - 115, -85, -54, 574, 128, 226, -59, -253, 130, - 39, 364, 757, 940, 728, 660, 659, 583, 770, - -115, -338, -760, -471, 394, 37, 441, 178, 6, - -57, -305, -525, 796, 453, 188, -4, -114, 248, - 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811, - 135, 359, 551, 425, 749, 815, 874, 704, 502, - 132, 247, 0, -206, -449, -750, -258, -514, -633, - 248, 249, 91, 121, -195, -499, -90, -282, -435, - 78, 20, -277, -623, -983, -1224, -415, -458, -639, - 347, 509, 208, -179, -464, -728, -76, -237, -486, - -103, -343, -756, -713, -265, -609, -191, -398, -636, - -121, -383, -749, 567, 252, -36, -354, -417, -50, - 204, 100, -149, -650, -1081, -47, -7, -263, 111, - -46, -180, -267, -324, -562, -394, -692, 398, 292, - 482, 670, 683, 624, 442, 165, 116, 36, -149, - 108, 247, 291, 247, 355, 122, 109, 224, 296, - 292, 349, 725, 482, 388, 329, 429, 620, 667, - -34, 197, 213, -127, 84, 494, 620, 575, 375, - 126, 207, 172, 167, 362, 202, 296, 395, 455, - -6, 250, 539, 467, 636, 801, 1149, 1287, 1118, - 27, 240, 369, 280, 440, 411, 634, 892, 953, - 159, 170, -58, -395, -797, -690, 77, -211, -334, - -5, -28, -13, -74, -335, -603, 300, 88, -205, - 82, -33, -364, -698, -1203, -1153, 110, -146, -289, - 113, 1, -243, -588, -994, -496, 414, 160, 42, - -56, -247, -440, -693, -996, -479, 11, -178, -357, - -151, -353, -327, -211, -340, 141, 65, 425, 453, - 34, -169, -455, -932, -1215, 138, 499, 256, 324, - 68, 139, -15, -547, -478, 17, 306, 502, 481, - -32, -134, 445, 129, -143, -244, -503, -507, -599, - 61, -140, -345, 496, 458, -2, 20, -227, -514, - 215, 519, 920, 1053, 1090, 791, 528, 290, 155, - -54, -233, -647, -602, 639, 294, -2, -167, -442, - -78, -315, -791, -113, 820, 403, 158, -116, -356, - -105, -379, -236, 1224, 893, 749, 568, 356, 214, - -17, -199, -144, 50, -283, -247, -578, -846, -1087, - 69, -11, -381, -206, 209, -284, -387, -416, -716, - 39, -5, -145, -374, -682, -909, -1074, -1169, -1066, - 287, 226, 67, -221, -662, -171, -421, -642, -707, - -132, -348, -538, -448, -20, -4, -354, -748, -933, - 4, -75, -289, -598, 317, 52, -208, -297, -559, - -88, -264, -358, -589, -631, -248, -523, -822, -1071, - 70, -8, 54, -314, -515, 92, -146, -274, -493, - 199, 62, 391, 158, -141, 71, -219, -203, -207, - 152, 40, 329, 162, -29, 48, -149, 108, 127, - 267, 722, 1256, 882, 625, 248, 8, -81, -60, - -58, -138, -291, -600, -12, -2, -39, 147, 117, - -107, -345, -513, 459, 76, 92, -272, 388, 262, - 362, 516, 203, -409, -716, -831, -331, 185, 209, - -117, -391, -298, 671, 292, 538, 257, 166, -38, - -102, -319, -194, -283, -573, -262, -579, -219, -444, - -235, 78, 11, -168, -101, -229, -263, -321, -123, - 70, 50, -170, -599, -996, -588, -263, -516, -455, - 394, 363, 229, -136, -538, 21, -183, -348, -201, - -124, -368, -640, -879, -847, -209, -409, -494, -515, - -127, -341, -541, -425, -510, -10, -252, -473, -291, - 84, -69, -201, -676, -868, 103, -311, -132, -320, - 5, -173, -188, -297, -628, 197, -57, 7, -11, - 49, -160, 56, 558, 111, 33, -311, -440, -463, - -1, -246, -307, 862, 453, 139, -170, -355, -232, - -197, -38, 1702, 1331, 1252, 950, 692, 504, 426, - -108, -344, -861, -1172, 444, 354, 88, -46, -220, - -53, -321, -494, 1113, 744, 364, 198, -34, -75, - -69, 199, 897, 1140, 1343, 1183, 977, 742, 522, - 122, 44, -269, 27, -155, -562, -307, -590, -773, - 154, 42, -160, 252, -129, -305, -471, -733, -371, - 135, 185, -82, -416, -722, -913, -504, -743, -880, - 149, 214, -84, -329, -680, -835, -426, -661, -81, - -128, -380, -735, -998, -337, 17, -182, -467, -697, - -84, -290, -510, -592, 13, 440, 154, -38, -279, - 70, -61, -246, -727, -1047, -80, -381, -535, -704, - 178, -2, -146, -670, -938, 482, 138, 63, 65, - -11, 15, 772, 443, 142, -20, -209, -126, -161, - -32, -249, 95, 552, 124, 30, -343, 82, -86, - -163, -257, 899, 1097, 906, 751, 502, 390, 294, - -51, -258, -447, -806, -368, 763, 464, 364, 183, - -166, -374, -367, 87, 35, 399, 418, 856, 833, - -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157, - -173, -312, 107, 345, 400, 790, 870, 1113, 1001, - -7, -120, -387, -410, -614, -943, -226, -384, -491, - -203, -288, -51, -331, -90, -178, -408, -573, -338, - 56, -29, -273, -627, -1041, -798, -247, -467, 148, - 66, -2, -205, -205, -575, -349, -57, -352, -58, - -45, -225, -471, -924, -497, 77, -32, 44, -135, - -277, -491, -497, -502, -424, -202, -137, 77, 96, - 26, -179, -469, -1008, -1260, 262, -35, -132, -259, - -66, -232, -447, -533, -789, -191, -100, -267, 364, - 111, 43, -287, -423, -608, -987, -922, -799, -827, - 77, 76, -101, -260, -549, -850, -88, -231, -329, - 75, 24, -66, -269, -427, -528, -773, 201, -5, - 67, 7, -61, -320, -487, 12, -200, -242, -94, - 27, -54, -149, -354, -661, -594, -450, -481, 560, - 31, -69, -246, -549, -1141, -178, -232, -275, -288, - 16, -84, -176, 7, -83, -210, -246, -424, -589, - 63, -60, -201, -90, -269, -400, -685, -1218, -258, - 169, 217, 142, -71, -243, -433, -504, -511, -537, - 6, -105, -234, -321, -188, -131, -307, -521, -1319, - -34, -151, -369, 11, 44, -95, -280, -500, 160, - 31, -37, -163, -334, 288, 89, -150, -86, -299, - -35, -161, -362, -74, -74, -263, 240, 9, -153, - -45, -208, -529, -896, 89, 24, -130, -313, -373, - 234, 276, 197, -10, -236, -162, -134, -85, -112, - 42, -73, 133, 392, 98, 72, -153, -162, -99, - -3, -145, -338, 408, 401, 133, -52, -296, -501, - 3, -109, -152, -85, -56, 42, -145, 703, 205, - -49, -149, -281, -134, -121, -41, -21, 16, 958, - 30, -107, -196, -463, -523, 490, 236, 70, -128, - -33, -161, -364, -148, 757, 516, 250, 43, -65, - -34, -193, -244, 750, 527, 349, 234, 172, 134, - -64, -223, -379, 55, 28, 248, 793, 442, 320, - 29, -85, -298, -622, -888, 127, 206, 387, 460, - -48, -170, -477, -876, 573, 635, 440, 375, 311, - 42, 3, -212, -441, -718, -821, 388, 373, 211, - -106, -155, 1092, 459, 570, 561, 506, 604, 514, - -144, -264, 0, 460, 619, 877, 916, 1273, 921 + 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923, + 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241, + 633, 898, 996, 756, 662, 683, 783, 909, 996, + 830, 736, 278, 820, 1254, 686, 712, 1039, 473, + 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061, + 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044, + 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314, + -31, 469, 803, 659, 619, 658, 843, 987, 1113, + 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742, + 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71, + 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391, + 1513, 1714, 1238, 534, 276, 315, 461, 459, 508, + 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006, + -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712, + -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217, + 670, 1208, 1168, 860, 742, 601, 528, 403, 309, + 397, 621, 966, 752, 579, 398, 400, 329, 252, + 510, 864, 1108, 807, 939, 902, 925, 717, 481, + 539, 835, 913, 719, 617, 544, 591, 565, 642, + 162, 889, 654, 108, -34, 244, 488, 561, 532, + -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823, + -14, 945, 990, 801, 755, 815, 847, 913, 892, + 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380, + 529, 1851, 2003, 1228, 622, -41, -416, 344, 819, + 635, 1058, 883, 492, 372, 312, 317, 274, 241, + 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339, + 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539, + 148, 751, 1515, 1105, 867, 606, 474, 448, 399, + 579, 1081, 1035, 390, 3, -263, -198, -82, 38, + 18, -68, -12, 313, 761, 405, 249, 111, -76, + -91, 827, 948, 648, 613, 535, 522, 490, 421, + 41, -44, -281, -472, 652, 534, 193, 135, -90, + 41, -121, -356, -60, 663, 307, 61, -48, -344, + -118, -204, 328, 512, 870, 793, 610, 402, 186, + 156, 293, 74, -338, -475, -897, -594, -161, -497, + 226, 131, -138, 307, 169, -271, -164, -387, -624, + 62, -32, -61, -252, -541, -828, -1027, -523, -662, + 102, -61, 141, 112, -270, -251, -541, 25, -150, + 6, -132, -356, -686, -96, -322, -522, -31, -326, + -36, -209, -521, -229, 307, -132, -5, -99, -384, + 60, -51, -237, -668, -973, -407, -708, -75, -172, + 26, -138, -266, 111, -302, 43, -278, -356, -359, + 570, 822, 496, -154, -312, -92, 137, 279, 371, + -146, 368, 409, 68, 6, 77, 167, 202, 162, + -103, 294, 607, 415, 483, 462, 480, 431, 408, + -120, -338, -612, -524, 584, 331, 92, 433, 276, + -178, -293, -154, -41, 269, 100, -9, 213, 160, + -218, -304, 463, 454, 397, 273, 202, 286, 273, + -232, 7, 6, -388, -472, -427, -378, -167, -100, + -294, -183, 134, -47, 101, -88, -84, -117, -3, + 57, 17, -202, -634, -989, -1119, -533, 176, -36, + 120, -28, 23, 111, -319, 318, -22, -77, 266, + -271, -464, -434, -658, -640, -385, -385, -99, -69, + -198, -259, -266, -44, -39, -139, -137, 171, 66, + 9, -145, -377, -846, -1000, -111, -325, 342, 135, + -81, -286, -380, 192, -57, 307, 76, -24, -140, + 677, 702, 247, 56, 249, 141, -105, -236, -99, + 36, -39, -69, 348, 198, -93, 322, 91, -72, + -127, -376, -657, 139, 623, 223, 501, 306, 220, + -113, -384, -796, 504, 438, 85, 213, -83, -194, + -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806, + 8, -126, -317, -103, -351, -695, -98, -268, -537, + 33, -103, -290, 167, -39, -407, 44, -208, -375, + 104, -23, -64, -291, -637, -851, -1084, -61, -112, + -75, -306, -434, 218, -148, -354, -680, -133, -216, + -121, -377, -718, -97, -130, -361, -156, -379, -599, + -56, -254, -586, 235, 157, -214, 11, -260, -149, + -124, -267, -397, -580, -593, -527, -805, -385, 346, + -193, -440, -708, -351, -141, -255, -499, -147, -185, + 448, 660, 494, 208, 509, 461, 338, 291, 149, + -223, 88, 335, 159, 212, 191, 286, 308, 205, + -171, -242, 514, 362, 295, 524, 552, 694, 585, + -64, -308, -448, -21, 284, 786, 446, 289, 92, + -218, -390, -7, 169, 206, 330, 352, 408, 358, + -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305, + -133, -341, -65, 678, 417, 440, 486, 518, 780, + 33, -44, -191, -344, -461, -755, -201, 217, -31, + -353, -547, -44, 123, -61, -68, -79, 29, 60, + 73, -57, -406, -766, -1243, -1203, 240, 400, 165, + -73, -282, -601, -213, -171, -375, 332, 35, -103, + -29, -207, -553, -476, -638, -908, 172, -22, -135, + -192, -239, -164, -103, -111, -47, 153, 125, 110, + -1, -203, -570, -1030, -1424, -535, 155, 1, 147, + -333, -653, -865, -197, -158, -21, -44, 95, 108, + 389, 588, 490, 33, -237, -524, -628, -136, -260, + 40, -177, -462, 453, 862, 380, 131, -130, -405, + -76, -281, -741, -742, 898, 619, 277, 71, -222, + -32, -265, -556, -25, 994, 682, 305, 126, -165, + -69, -349, -585, 234, 1158, 903, 626, 510, 251, + -1, -99, -272, -210, -603, -351, -540, -811, -383, + -16, -230, -504, 410, 149, -205, -343, -651, -639, + 103, -9, -227, -205, -562, -781, -1079, -1208, -156, + 143, 63, -135, -67, -317, -602, -784, -1154, -640, + -144, -391, -674, -622, -200, -254, -660, -947, -395, + -40, -250, -625, 27, 543, 94, -131, -386, -673, + -123, -371, -757, -451, -564, -614, -415, -711, -35, + -116, -309, -593, -268, 239, -33, -338, -650, -135, + 94, 251, 554, 57, -312, -423, -154, -57, 235, + -268, -71, 381, 114, -44, -87, 125, 173, 133, + -131, -19, 1149, 670, 486, 356, 309, 369, 296, + -223, -501, -899, -722, -70, 6, 131, 310, 394, + -99, -303, -517, 249, 64, -53, 135, -11, 453, + -147, -399, -730, -401, 817, 738, 802, 749, 575, + -154, -435, -739, 800, 593, 366, 529, 318, 326, + -224, 45, -39, -387, -515, -518, -608, -384, -321, + -315, -377, 143, -101, -113, -377, -177, -144, -12, + 117, 40, -239, -651, -1051, -581, -737, -990, -328, + 26, -50, -157, -23, -453, -283, -531, -546, 192, + -252, -501, -743, -589, -627, -499, -328, -118, -72, + -324, -494, -244, -306, -144, -177, -262, -135, -78, + -36, -234, -519, -961, -1290, -314, -479, -371, -45, + -95, -292, -535, -8, -300, 112, -164, -277, 198, + -99, -128, 880, 836, 579, 351, 23, -95, -217, + -27, -258, 124, 1011, 597, 425, 144, 7, -73, + -69, -300, -683, -435, 1132, 899, 504, 332, 109, + -74, -323, -637, 563, 1074, 608, 371, 105, -49, + -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933, + -82, -306, -613, -222, -378, -675, -545, -671, -845, + 53, -124, -347, 422, 52, -125, -270, -529, 9, + 79, -89, -320, -662, -999, -1199, -1243, -676, -297, + -68, -273, -611, 137, -146, -397, -627, -845, -220, + -112, -346, -797, -826, 234, -132, -188, -278, -522, + -159, -405, -734, -419, 293, 74, -167, -167, 184, + -153, -437, -833, -1080, -336, -472, -561, -340, -253, + -169, -423, -820, -904, -131, -19, -346, -604, 31, + 33, -31, 312, 62, -148, 49, -59, 564, 486, + -306, -333, 194, -44, 67, 72, 147, 205, 243, + -207, -49, 1360, 983, 969, 991, 1014, 1110, 973, + -211, -172, 883, 627, 711, 674, 705, 798, 746, + -88, -325, -763, -974, 687, 908, 514, 382, 172, + -292, -612, -805, 63, 131, 270, 259, 352, 348, + -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285, + -180, -461, -614, 657, 691, 745, 854, 783, 713, + -97, -309, -477, -614, -777, -734, -768, -526, -472, + -344, -476, -35, -169, 49, -77, -150, -240, -141, + -52, -268, -639, -919, -1278, -1113, -342, -333, -151, + -68, -242, -585, -73, -209, -478, -159, -429, 133, + -197, -499, -1005, -1268, -272, -224, -105, -67, 17, + -363, -618, -414, -116, -62, 20, 10, 116, 108, + -195, -475, -906, -1260, -891, -441, -277, -142, -28, + -226, -519, -950, -700, -275, -266, -116, -105, 82, + 404, 511, 520, 327, 17, -194, -333, -536, -586, + -114, -130, 276, 237, 204, 342, 135, -16, -111, + 191, 180, -137, -467, 272, 106, -95, 17, -192, + -80, -290, -626, 194, 598, 196, 21, -281, 77, + 137, 367, 534, 764, 670, 382, 296, 153, 84, + 303, 497, 144, -85, -125, -539, -482, -464, -764, + 233, 347, 68, -147, 169, -210, -242, -226, -482, + 307, 422, 154, -175, -386, -722, -724, -904, -1015, + 309, 308, 160, -60, -470, -420, -598, -791, -219, + 68, 121, -137, -560, -146, -446, -515, -494, -729, + 130, 53, -227, 46, 474, 32, -161, -192, -490, + 213, 164, -71, -465, -876, -161, -456, -587, -48, + 218, 117, 39, 177, -194, -88, -226, -418, 50, + 210, 547, 569, 279, 121, -44, -50, 10, -84, + 58, 140, 182, -5, 267, 117, 106, 211, 198, + 153, 559, 872, 460, 222, 108, 188, 180, 183, + 158, 119, 284, -153, -271, 229, 87, 110, -57, + -183, 82, 118, 21, 13, 40, 118, 191, 185, + 163, 56, 609, 341, 50, 329, 68, 266, 218, + 100, 206, 18, -304, -107, -436, -487, -65, -306, + -86, 154, 134, -30, -45, -73, -104, -80, -96, + 245, 330, 10, -440, -849, -1082, 79, 40, -265, + 196, 372, 272, -181, -493, -389, 275, 80, -59, + 2, -12, -246, -505, -100, -436, 21, -187, -431, + -221, -48, 36, -271, -186, -147, -109, 26, 71, + 213, 140, 72, -351, -620, -84, -363, 69, 46, + 91, 167, -3, -95, -99, -105, -48, 114, 147, + 259, 249, 172, 607, 406, 52, 59, -189, -320, + 115, -85, -54, 574, 128, 226, -59, -253, 130, + 39, 364, 757, 940, 728, 660, 659, 583, 770, + -115, -338, -760, -471, 394, 37, 441, 178, 6, + -57, -305, -525, 796, 453, 188, -4, -114, 248, + 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811, + 135, 359, 551, 425, 749, 815, 874, 704, 502, + 132, 247, 0, -206, -449, -750, -258, -514, -633, + 248, 249, 91, 121, -195, -499, -90, -282, -435, + 78, 20, -277, -623, -983, -1224, -415, -458, -639, + 347, 509, 208, -179, -464, -728, -76, -237, -486, + -103, -343, -756, -713, -265, -609, -191, -398, -636, + -121, -383, -749, 567, 252, -36, -354, -417, -50, + 204, 100, -149, -650, -1081, -47, -7, -263, 111, + -46, -180, -267, -324, -562, -394, -692, 398, 292, + 482, 670, 683, 624, 442, 165, 116, 36, -149, + 108, 247, 291, 247, 355, 122, 109, 224, 296, + 292, 349, 725, 482, 388, 329, 429, 620, 667, + -34, 197, 213, -127, 84, 494, 620, 575, 375, + 126, 207, 172, 167, 362, 202, 296, 395, 455, + -6, 250, 539, 467, 636, 801, 1149, 1287, 1118, + 27, 240, 369, 280, 440, 411, 634, 892, 953, + 159, 170, -58, -395, -797, -690, 77, -211, -334, + -5, -28, -13, -74, -335, -603, 300, 88, -205, + 82, -33, -364, -698, -1203, -1153, 110, -146, -289, + 113, 1, -243, -588, -994, -496, 414, 160, 42, + -56, -247, -440, -693, -996, -479, 11, -178, -357, + -151, -353, -327, -211, -340, 141, 65, 425, 453, + 34, -169, -455, -932, -1215, 138, 499, 256, 324, + 68, 139, -15, -547, -478, 17, 306, 502, 481, + -32, -134, 445, 129, -143, -244, -503, -507, -599, + 61, -140, -345, 496, 458, -2, 20, -227, -514, + 215, 519, 920, 1053, 1090, 791, 528, 290, 155, + -54, -233, -647, -602, 639, 294, -2, -167, -442, + -78, -315, -791, -113, 820, 403, 158, -116, -356, + -105, -379, -236, 1224, 893, 749, 568, 356, 214, + -17, -199, -144, 50, -283, -247, -578, -846, -1087, + 69, -11, -381, -206, 209, -284, -387, -416, -716, + 39, -5, -145, -374, -682, -909, -1074, -1169, -1066, + 287, 226, 67, -221, -662, -171, -421, -642, -707, + -132, -348, -538, -448, -20, -4, -354, -748, -933, + 4, -75, -289, -598, 317, 52, -208, -297, -559, + -88, -264, -358, -589, -631, -248, -523, -822, -1071, + 70, -8, 54, -314, -515, 92, -146, -274, -493, + 199, 62, 391, 158, -141, 71, -219, -203, -207, + 152, 40, 329, 162, -29, 48, -149, 108, 127, + 267, 722, 1256, 882, 625, 248, 8, -81, -60, + -58, -138, -291, -600, -12, -2, -39, 147, 117, + -107, -345, -513, 459, 76, 92, -272, 388, 262, + 362, 516, 203, -409, -716, -831, -331, 185, 209, + -117, -391, -298, 671, 292, 538, 257, 166, -38, + -102, -319, -194, -283, -573, -262, -579, -219, -444, + -235, 78, 11, -168, -101, -229, -263, -321, -123, + 70, 50, -170, -599, -996, -588, -263, -516, -455, + 394, 363, 229, -136, -538, 21, -183, -348, -201, + -124, -368, -640, -879, -847, -209, -409, -494, -515, + -127, -341, -541, -425, -510, -10, -252, -473, -291, + 84, -69, -201, -676, -868, 103, -311, -132, -320, + 5, -173, -188, -297, -628, 197, -57, 7, -11, + 49, -160, 56, 558, 111, 33, -311, -440, -463, + -1, -246, -307, 862, 453, 139, -170, -355, -232, + -197, -38, 1702, 1331, 1252, 950, 692, 504, 426, + -108, -344, -861, -1172, 444, 354, 88, -46, -220, + -53, -321, -494, 1113, 744, 364, 198, -34, -75, + -69, 199, 897, 1140, 1343, 1183, 977, 742, 522, + 122, 44, -269, 27, -155, -562, -307, -590, -773, + 154, 42, -160, 252, -129, -305, -471, -733, -371, + 135, 185, -82, -416, -722, -913, -504, -743, -880, + 149, 214, -84, -329, -680, -835, -426, -661, -81, + -128, -380, -735, -998, -337, 17, -182, -467, -697, + -84, -290, -510, -592, 13, 440, 154, -38, -279, + 70, -61, -246, -727, -1047, -80, -381, -535, -704, + 178, -2, -146, -670, -938, 482, 138, 63, 65, + -11, 15, 772, 443, 142, -20, -209, -126, -161, + -32, -249, 95, 552, 124, 30, -343, 82, -86, + -163, -257, 899, 1097, 906, 751, 502, 390, 294, + -51, -258, -447, -806, -368, 763, 464, 364, 183, + -166, -374, -367, 87, 35, 399, 418, 856, 833, + -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157, + -173, -312, 107, 345, 400, 790, 870, 1113, 1001, + -7, -120, -387, -410, -614, -943, -226, -384, -491, + -203, -288, -51, -331, -90, -178, -408, -573, -338, + 56, -29, -273, -627, -1041, -798, -247, -467, 148, + 66, -2, -205, -205, -575, -349, -57, -352, -58, + -45, -225, -471, -924, -497, 77, -32, 44, -135, + -277, -491, -497, -502, -424, -202, -137, 77, 96, + 26, -179, -469, -1008, -1260, 262, -35, -132, -259, + -66, -232, -447, -533, -789, -191, -100, -267, 364, + 111, 43, -287, -423, -608, -987, -922, -799, -827, + 77, 76, -101, -260, -549, -850, -88, -231, -329, + 75, 24, -66, -269, -427, -528, -773, 201, -5, + 67, 7, -61, -320, -487, 12, -200, -242, -94, + 27, -54, -149, -354, -661, -594, -450, -481, 560, + 31, -69, -246, -549, -1141, -178, -232, -275, -288, + 16, -84, -176, 7, -83, -210, -246, -424, -589, + 63, -60, -201, -90, -269, -400, -685, -1218, -258, + 169, 217, 142, -71, -243, -433, -504, -511, -537, + 6, -105, -234, -321, -188, -131, -307, -521, -1319, + -34, -151, -369, 11, 44, -95, -280, -500, 160, + 31, -37, -163, -334, 288, 89, -150, -86, -299, + -35, -161, -362, -74, -74, -263, 240, 9, -153, + -45, -208, -529, -896, 89, 24, -130, -313, -373, + 234, 276, 197, -10, -236, -162, -134, -85, -112, + 42, -73, 133, 392, 98, 72, -153, -162, -99, + -3, -145, -338, 408, 401, 133, -52, -296, -501, + 3, -109, -152, -85, -56, 42, -145, 703, 205, + -49, -149, -281, -134, -121, -41, -21, 16, 958, + 30, -107, -196, -463, -523, 490, 236, 70, -128, + -33, -161, -364, -148, 757, 516, 250, 43, -65, + -34, -193, -244, 750, 527, 349, 234, 172, 134, + -64, -223, -379, 55, 28, 248, 793, 442, 320, + 29, -85, -298, -622, -888, 127, 206, 387, 460, + -48, -170, -477, -876, 573, 635, 440, 375, 311, + 42, 3, -212, -441, -718, -821, 388, 373, 211, + -106, -155, 1092, 459, 570, 561, 506, 604, 514, + -144, -264, 0, 460, 619, 877, 916, 1273, 921 }; /*-------------------------------------------------------------------* @@ -9235,262 +9235,262 @@ const Word16 dico1_isf_fx[] = /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ const Word16 dico2_isf_fx[] = {/*Qlog2(2.56)*/ - 1357, 1313, 1136, 784, 438, 181, 145, - 636, 648, 667, 568, 442, 217, 362, - 427, 440, 674, 524, 332, 117, -417, - 121, 295, 468, 465, 230, 44, -221, - -147, -240, 149, 80, 390, 278, 106, - -418, -556, 552, 511, 235, 144, -95, - 43, 193, 274, 150, 67, 34, -273, - -43, -126, 171, 416, 282, 63, -354, - -372, -86, -344, -108, -94, -182, -89, - -600, -840, -200, 465, 258, -11, -253, - -48, 329, 97, -290, -543, -795, -354, - -570, -117, 187, 10, -133, -416, -76, - -618, -129, -247, -371, 45, -76, 277, - -1022, -1079, 126, 474, 254, 127, 52, - -281, 76, -167, -361, -283, -551, -283, - -119, -52, -1, 134, -32, -204, -415, - 1064, 827, 637, 684, 464, 209, 12, - 482, 416, 449, 371, 335, 294, 194, - 719, 576, 365, 135, 113, 91, -199, - 298, 176, 493, 366, 194, 163, 36, - -35, -236, -259, -36, -4, 99, 152, - -98, -306, -27, 228, 90, 111, -86, - 91, 13, -211, -258, -106, 86, -64, - 73, -35, -57, -31, 162, 35, -192, - -109, -335, -629, -66, -61, -128, 322, - -495, -669, -728, 193, 31, -220, 122, - 324, 95, -89, -91, -409, -710, -154, - 0, -234, 92, 33, -343, -609, -220, - -343, -408, -476, -655, -153, 82, 222, - -490, -745, -255, 49, -48, 135, -127, - 119, -67, -328, -390, -272, -545, -56, - -57, -130, -10, -7, -164, -47, -22, - 984, 1064, 961, 568, 210, -27, 16, - 811, 691, 754, 514, 224, -35, 166, - 662, 704, 618, 386, 57, -211, -257, - 510, 359, 418, 393, 91, -144, -18, - -193, -31, -27, 223, 89, -143, 24, - -112, -98, 471, 319, 185, 3, 175, - 252, 146, -47, 272, 48, -211, -234, - 146, 69, 203, 364, 68, -52, 51, - -259, -478, -697, -349, -758, -501, 63, - -501, -769, -289, 79, -311, -497, -106, - 251, 53, -235, -469, -895, -884, 145, - -416, -551, 140, -133, -523, -775, 44, - -326, -423, -713, -497, -86, -431, 99, - -757, -772, -160, -76, -46, -32, 379, - 85, -35, -200, -401, -663, -1040, -247, - -180, -330, -92, -376, 27, -183, -110, - 1279, 1086, 781, 502, 324, 164, 157, - 682, 466, 449, 277, 146, 28, 409, - 635, 472, 390, 107, -232, -538, -139, - 196, 396, 332, 213, 209, -29, -81, - 150, -95, -312, 76, -77, -320, -50, - 46, 9, 47, 175, 139, 30, 384, - 218, 206, -24, -250, -96, -276, -183, - 26, 119, 38, 14, -4, -133, -52, - -477, -614, -987, -715, -631, -813, 200, - -744, -1009, -1065, -745, -631, -171, 18, - -137, -251, -483, -613, -980, -1203, 12, - -605, -767, -562, -686, -1088, -515, 58, - -202, -428, -782, -1072, -96, -234, -179, - -480, -709, -1070, -897, -131, -92, 321, - -145, -193, -512, -729, -572, -765, -210, - -331, -585, -525, -631, -281, -208, -303, - 1165, 1104, 939, 828, 716, 426, 155, - 6, -109, 820, 778, 415, 113, -27, - 381, 339, 314, 265, 121, -9, -474, - -373, 47, 584, 442, 99, -231, -113, - -496, -38, -285, 262, 305, 170, 4, - -587, -556, 69, 66, 471, 354, 13, - -138, 70, -18, 106, 67, 167, -302, - -445, -141, 185, 191, 151, 83, -133, - -257, -521, -720, -198, 134, -46, -182, - -819, -1168, -777, 512, 359, 95, -113, - 137, -2, -74, -138, -401, -114, -371, - -242, -466, 204, 223, -31, -212, -192, - -532, -637, -466, -686, 256, 277, -139, - -1141, -1244, -381, -75, -54, 14, 88, - -311, 115, -143, -499, -343, 124, -416, - -616, -147, -135, 43, -4, 121, -369, - 835, 783, 641, 390, 355, 350, 64, - 72, 194, 443, 467, 436, 219, 372, - 464, 369, 192, 4, -156, -72, -226, - 57, 206, 303, 205, 188, 101, 265, - -40, -205, -488, -184, 276, 64, -26, - -217, -433, -297, 137, 328, 308, -289, - 378, 81, -308, -465, 57, -37, 227, - -100, 24, -36, -151, 199, 8, 143, - -426, -697, -1059, -133, 388, 161, 321, - -644, -1023, -1271, 39, 66, -123, 70, - 372, 177, -173, -556, -553, -304, -189, - -117, -369, -425, -122, -462, -152, -73, - -649, -850, -1189, -767, 497, 360, 222, - -798, -1139, -1455, -190, 430, 234, 179, - 42, -94, -405, -692, 38, -202, -246, - -169, -366, -290, -88, -64, 32, -292, - 1010, 923, 938, 710, 465, 230, 342, - 217, 300, 1054, 675, 68, -458, -179, - 78, 453, 316, 18, -237, -496, -243, - 167, 21, 424, 215, -91, -303, -170, - -290, -81, -70, -67, 40, 54, -59, - -353, -427, -90, 53, 94, 9, 54, - -28, 318, 283, 15, -240, -58, 79, - -75, -121, 229, 35, 58, 6, -133, - -351, -514, -744, -834, -705, -137, 164, - -1124, -1388, -1055, -230, -73, 40, 36, - -163, -233, -532, -785, -1170, -697, 96, - -788, -959, -246, -430, -624, -165, -8, - -856, -540, -630, -907, -337, -70, 76, - -937, -1042, -659, -733, -208, 199, -26, - -523, 78, -98, -501, -869, -890, -81, - -624, -703, -45, -348, -25, 87, -186, - 1005, 823, 546, 249, 90, -22, 207, - 298, 397, 381, 319, 200, 62, 303, - 473, 379, 133, -247, -632, -441, 75, - 284, 208, 391, 115, -25, 44, 95, - -72, 79, -95, -63, -129, -293, 203, - -164, -349, 115, 122, 69, -1, 378, - 348, 170, 99, 58, -179, -302, 188, - -190, -2, 150, 23, -51, -11, 216, - -615, -863, -1090, -1427, -802, -48, -6, - -961, -1276, -1548, -727, -58, 56, 223, - -124, -255, -561, -988, -1277, -148, -82, - -480, -660, -891, -1191, -1339, -325, 20, - -621, -917, -1296, -1350, 264, 289, 50, - -844, -1022, -1345, -1329, -293, 46, 278, - -260, -468, -829, -1176, -533, -560, -78, - -215, -484, -822, -1233, -791, 15, -138, - 1301, 1317, 1262, 1048, 716, 357, -64, - 578, 824, 925, 802, 630, 362, 102, - 470, 925, 767, 514, 327, 190, -112, - 225, 492, 495, 437, 598, 384, -45, - 43, 82, -42, 175, 519, 342, -64, - -304, -154, 159, 576, 403, 221, 327, - 214, 244, 122, -62, 312, 92, -160, - 218, 208, 310, 268, 306, 323, -199, - -285, -269, -79, -124, -143, -153, 236, - -205, -384, -426, 344, 59, -185, -184, - -272, 247, 126, -210, -518, -468, 78, - -99, -120, 502, 160, -280, -557, 304, - -423, -17, -283, -443, 215, 212, -140, - -564, -684, -228, 510, 361, 130, 323, - -428, 335, 98, -65, 36, -215, -246, - -362, 51, 364, -16, -234, 150, -165, - 914, 883, 751, 653, 676, 464, -153, - 631, 545, 535, 720, 596, 360, -81, - 783, 712, 512, 439, 341, 251, -391, - 497, 417, 249, 372, 295, 173, -193, - 128, -110, -385, 93, 39, 173, -231, - 216, -59, -253, 462, 389, 154, 69, - 455, 270, -4, -337, -49, 233, -322, - 307, 143, 53, 218, 128, 236, -156, - -37, -186, -240, -411, -110, 9, 399, - -140, -365, -628, 258, 380, 214, 277, - 131, 454, 177, -285, -520, 108, -214, - 77, -141, 201, -123, -490, -131, 60, - -14, -194, -521, -741, 273, 362, -33, - -362, -566, -287, -228, 161, 237, 317, - -269, 195, -75, -375, -204, 11, 77, - -128, -264, -156, -223, -475, 265, 27, - 1238, 1147, 916, 689, 432, 210, -280, - 800, 664, 879, 726, 411, 160, -164, - 454, 686, 536, 275, 147, 46, 111, - 303, 486, 512, 355, 241, 181, -69, - 79, 92, 29, 147, 233, 52, 17, - -171, 289, 131, 439, 271, 3, -10, - 413, 241, 144, 174, 155, -2, 14, - 58, 217, 247, 219, 149, 175, -18, - 228, -8, -240, -206, -513, -191, 202, - -96, -272, -454, 33, -300, -575, 46, - -10, -108, -246, -347, -770, -535, 9, - -326, -430, -61, -321, -704, -299, 201, - -1, -280, -603, -419, -185, 18, -36, - -516, -522, -379, -291, -181, -97, 27, - -159, -313, -525, -224, -510, -831, -197, - -292, -459, -59, -310, -562, -143, -351, - 1066, 912, 631, 389, 207, 86, -224, - 596, 512, 596, 505, 314, 122, -48, - 787, 861, 441, -93, -303, 33, -190, - 257, 469, 337, 51, 15, 298, -93, - 295, 73, -119, 25, 36, 23, 108, - -28, -3, -32, 114, 21, 185, 107, - 482, 305, 15, -279, -319, 52, 96, - 226, 46, 115, 72, -136, 133, -125, - 18, -207, -559, -590, -503, -482, 321, - -571, -789, -951, -172, -441, -538, 113, - 181, 14, -310, -641, -1001, -202, 159, - -136, -393, -433, -513, -911, -144, -22, - 72, -265, -706, -954, -159, 53, 332, - -338, -591, -852, -383, -395, 56, 44, - 43, -158, -464, -897, -631, -157, -294, - -161, -128, -328, -573, -483, -125, 11, - 1017, 906, 1051, 1005, 679, 341, -102, - 359, 334, 1567, 1314, 723, 105, 10, - -65, 726, 529, 301, 220, 43, -273, - -510, 436, 719, 566, 358, 179, 114, - -560, 298, 133, -120, 342, 225, 14, - -899, -101, 217, 617, 400, 146, -58, - -41, 352, 82, -196, 39, 121, -167, - -212, 59, 447, 284, 423, 250, -169, - -371, -484, -596, 30, -41, 249, 22, - -372, -650, -794, 477, 445, 216, -79, - -352, 275, 17, -443, -929, 92, 19, - -699, -696, 431, 264, -49, -310, 182, - -978, -217, -430, -400, 101, 261, 72, - -929, -889, -357, -13, 463, 378, 236, - -826, 56, 30, -299, -360, -128, -51, - -878, -299, -111, 75, 65, 36, 3, - 817, 368, -25, 354, 697, 591, -173, - 309, 212, 222, 751, 484, 140, -56, - 593, 379, 70, -8, 258, 180, 110, - 165, -46, 255, 297, 219, 273, 105, - 160, -70, -358, -181, 379, 330, 319, - -238, -369, -198, 740, 580, 319, -143, - 201, 109, -202, -456, 328, 276, -141, - 203, 170, 111, 42, 207, 360, 188, - -345, -399, -513, -233, 650, 422, 81, - -635, -961, -1220, 463, 539, 204, 209, - 202, -25, -194, -498, -787, 193, -143, - -449, -538, 195, -106, -331, 68, 62, - -228, -477, -840, -576, 317, 128, 283, - -671, -937, -807, -114, 391, 335, -62, - 246, 2, -314, -679, -303, 180, -88, - -107, -272, 90, -198, -28, 290, -112, - 885, 1149, 1021, 712, 496, 281, -83, - 269, 492, 787, 643, 347, 70, 124, - 336, 636, 499, 92, -229, -179, 191, - 26, 402, 564, 340, 149, -11, 135, - -440, 561, 470, 204, -72, -186, 140, - -720, 14, 355, 229, 68, -133, 465, - 110, 310, 103, 12, 106, 29, 158, - -178, 113, 161, 142, 121, 115, 27, - -651, -414, -645, -152, -164, -13, -429, - -639, -944, -681, -104, -81, 52, -189, - -663, -164, -316, -683, -954, -205, -83, - -609, -669, -172, -517, -694, 283, -80, - -646, -152, -383, -678, -246, -40, -143, - -747, -796, -745, -390, -98, 43, 275, - -599, -199, -398, -433, -436, -538, 31, - -1107, -568, -376, -265, -126, -21, 1, - 847, 573, 308, 392, 305, 101, 55, - 273, 293, 201, 267, 346, 201, 123, - 727, 480, 226, 2, -65, -138, 164, - 273, 208, 173, 292, 12, 253, 174, - 340, 207, 180, 88, 116, 46, 475, - -460, -166, -30, 13, 110, 173, 396, - 137, 88, 43, -137, -94, 34, 284, - 96, -14, 226, 40, 63, 70, 130, - -467, -735, -1012, -1174, -307, 305, -67, - -612, -920, -1146, -567, -8, 92, -25, - -182, -271, -492, -754, -857, 287, -75, - -494, -787, -689, -683, -709, 137, -326, - -288, -550, -903, -1105, 334, 321, -62, - -354, -653, -834, -445, 1, 377, -152, - -162, -306, -608, -937, -297, 247, -192, - -234, -477, -244, -488, -266, 342, -332 + 1357, 1313, 1136, 784, 438, 181, 145, + 636, 648, 667, 568, 442, 217, 362, + 427, 440, 674, 524, 332, 117, -417, + 121, 295, 468, 465, 230, 44, -221, + -147, -240, 149, 80, 390, 278, 106, + -418, -556, 552, 511, 235, 144, -95, + 43, 193, 274, 150, 67, 34, -273, + -43, -126, 171, 416, 282, 63, -354, + -372, -86, -344, -108, -94, -182, -89, + -600, -840, -200, 465, 258, -11, -253, + -48, 329, 97, -290, -543, -795, -354, + -570, -117, 187, 10, -133, -416, -76, + -618, -129, -247, -371, 45, -76, 277, + -1022, -1079, 126, 474, 254, 127, 52, + -281, 76, -167, -361, -283, -551, -283, + -119, -52, -1, 134, -32, -204, -415, + 1064, 827, 637, 684, 464, 209, 12, + 482, 416, 449, 371, 335, 294, 194, + 719, 576, 365, 135, 113, 91, -199, + 298, 176, 493, 366, 194, 163, 36, + -35, -236, -259, -36, -4, 99, 152, + -98, -306, -27, 228, 90, 111, -86, + 91, 13, -211, -258, -106, 86, -64, + 73, -35, -57, -31, 162, 35, -192, + -109, -335, -629, -66, -61, -128, 322, + -495, -669, -728, 193, 31, -220, 122, + 324, 95, -89, -91, -409, -710, -154, + 0, -234, 92, 33, -343, -609, -220, + -343, -408, -476, -655, -153, 82, 222, + -490, -745, -255, 49, -48, 135, -127, + 119, -67, -328, -390, -272, -545, -56, + -57, -130, -10, -7, -164, -47, -22, + 984, 1064, 961, 568, 210, -27, 16, + 811, 691, 754, 514, 224, -35, 166, + 662, 704, 618, 386, 57, -211, -257, + 510, 359, 418, 393, 91, -144, -18, + -193, -31, -27, 223, 89, -143, 24, + -112, -98, 471, 319, 185, 3, 175, + 252, 146, -47, 272, 48, -211, -234, + 146, 69, 203, 364, 68, -52, 51, + -259, -478, -697, -349, -758, -501, 63, + -501, -769, -289, 79, -311, -497, -106, + 251, 53, -235, -469, -895, -884, 145, + -416, -551, 140, -133, -523, -775, 44, + -326, -423, -713, -497, -86, -431, 99, + -757, -772, -160, -76, -46, -32, 379, + 85, -35, -200, -401, -663, -1040, -247, + -180, -330, -92, -376, 27, -183, -110, + 1279, 1086, 781, 502, 324, 164, 157, + 682, 466, 449, 277, 146, 28, 409, + 635, 472, 390, 107, -232, -538, -139, + 196, 396, 332, 213, 209, -29, -81, + 150, -95, -312, 76, -77, -320, -50, + 46, 9, 47, 175, 139, 30, 384, + 218, 206, -24, -250, -96, -276, -183, + 26, 119, 38, 14, -4, -133, -52, + -477, -614, -987, -715, -631, -813, 200, + -744, -1009, -1065, -745, -631, -171, 18, + -137, -251, -483, -613, -980, -1203, 12, + -605, -767, -562, -686, -1088, -515, 58, + -202, -428, -782, -1072, -96, -234, -179, + -480, -709, -1070, -897, -131, -92, 321, + -145, -193, -512, -729, -572, -765, -210, + -331, -585, -525, -631, -281, -208, -303, + 1165, 1104, 939, 828, 716, 426, 155, + 6, -109, 820, 778, 415, 113, -27, + 381, 339, 314, 265, 121, -9, -474, + -373, 47, 584, 442, 99, -231, -113, + -496, -38, -285, 262, 305, 170, 4, + -587, -556, 69, 66, 471, 354, 13, + -138, 70, -18, 106, 67, 167, -302, + -445, -141, 185, 191, 151, 83, -133, + -257, -521, -720, -198, 134, -46, -182, + -819, -1168, -777, 512, 359, 95, -113, + 137, -2, -74, -138, -401, -114, -371, + -242, -466, 204, 223, -31, -212, -192, + -532, -637, -466, -686, 256, 277, -139, + -1141, -1244, -381, -75, -54, 14, 88, + -311, 115, -143, -499, -343, 124, -416, + -616, -147, -135, 43, -4, 121, -369, + 835, 783, 641, 390, 355, 350, 64, + 72, 194, 443, 467, 436, 219, 372, + 464, 369, 192, 4, -156, -72, -226, + 57, 206, 303, 205, 188, 101, 265, + -40, -205, -488, -184, 276, 64, -26, + -217, -433, -297, 137, 328, 308, -289, + 378, 81, -308, -465, 57, -37, 227, + -100, 24, -36, -151, 199, 8, 143, + -426, -697, -1059, -133, 388, 161, 321, + -644, -1023, -1271, 39, 66, -123, 70, + 372, 177, -173, -556, -553, -304, -189, + -117, -369, -425, -122, -462, -152, -73, + -649, -850, -1189, -767, 497, 360, 222, + -798, -1139, -1455, -190, 430, 234, 179, + 42, -94, -405, -692, 38, -202, -246, + -169, -366, -290, -88, -64, 32, -292, + 1010, 923, 938, 710, 465, 230, 342, + 217, 300, 1054, 675, 68, -458, -179, + 78, 453, 316, 18, -237, -496, -243, + 167, 21, 424, 215, -91, -303, -170, + -290, -81, -70, -67, 40, 54, -59, + -353, -427, -90, 53, 94, 9, 54, + -28, 318, 283, 15, -240, -58, 79, + -75, -121, 229, 35, 58, 6, -133, + -351, -514, -744, -834, -705, -137, 164, + -1124, -1388, -1055, -230, -73, 40, 36, + -163, -233, -532, -785, -1170, -697, 96, + -788, -959, -246, -430, -624, -165, -8, + -856, -540, -630, -907, -337, -70, 76, + -937, -1042, -659, -733, -208, 199, -26, + -523, 78, -98, -501, -869, -890, -81, + -624, -703, -45, -348, -25, 87, -186, + 1005, 823, 546, 249, 90, -22, 207, + 298, 397, 381, 319, 200, 62, 303, + 473, 379, 133, -247, -632, -441, 75, + 284, 208, 391, 115, -25, 44, 95, + -72, 79, -95, -63, -129, -293, 203, + -164, -349, 115, 122, 69, -1, 378, + 348, 170, 99, 58, -179, -302, 188, + -190, -2, 150, 23, -51, -11, 216, + -615, -863, -1090, -1427, -802, -48, -6, + -961, -1276, -1548, -727, -58, 56, 223, + -124, -255, -561, -988, -1277, -148, -82, + -480, -660, -891, -1191, -1339, -325, 20, + -621, -917, -1296, -1350, 264, 289, 50, + -844, -1022, -1345, -1329, -293, 46, 278, + -260, -468, -829, -1176, -533, -560, -78, + -215, -484, -822, -1233, -791, 15, -138, + 1301, 1317, 1262, 1048, 716, 357, -64, + 578, 824, 925, 802, 630, 362, 102, + 470, 925, 767, 514, 327, 190, -112, + 225, 492, 495, 437, 598, 384, -45, + 43, 82, -42, 175, 519, 342, -64, + -304, -154, 159, 576, 403, 221, 327, + 214, 244, 122, -62, 312, 92, -160, + 218, 208, 310, 268, 306, 323, -199, + -285, -269, -79, -124, -143, -153, 236, + -205, -384, -426, 344, 59, -185, -184, + -272, 247, 126, -210, -518, -468, 78, + -99, -120, 502, 160, -280, -557, 304, + -423, -17, -283, -443, 215, 212, -140, + -564, -684, -228, 510, 361, 130, 323, + -428, 335, 98, -65, 36, -215, -246, + -362, 51, 364, -16, -234, 150, -165, + 914, 883, 751, 653, 676, 464, -153, + 631, 545, 535, 720, 596, 360, -81, + 783, 712, 512, 439, 341, 251, -391, + 497, 417, 249, 372, 295, 173, -193, + 128, -110, -385, 93, 39, 173, -231, + 216, -59, -253, 462, 389, 154, 69, + 455, 270, -4, -337, -49, 233, -322, + 307, 143, 53, 218, 128, 236, -156, + -37, -186, -240, -411, -110, 9, 399, + -140, -365, -628, 258, 380, 214, 277, + 131, 454, 177, -285, -520, 108, -214, + 77, -141, 201, -123, -490, -131, 60, + -14, -194, -521, -741, 273, 362, -33, + -362, -566, -287, -228, 161, 237, 317, + -269, 195, -75, -375, -204, 11, 77, + -128, -264, -156, -223, -475, 265, 27, + 1238, 1147, 916, 689, 432, 210, -280, + 800, 664, 879, 726, 411, 160, -164, + 454, 686, 536, 275, 147, 46, 111, + 303, 486, 512, 355, 241, 181, -69, + 79, 92, 29, 147, 233, 52, 17, + -171, 289, 131, 439, 271, 3, -10, + 413, 241, 144, 174, 155, -2, 14, + 58, 217, 247, 219, 149, 175, -18, + 228, -8, -240, -206, -513, -191, 202, + -96, -272, -454, 33, -300, -575, 46, + -10, -108, -246, -347, -770, -535, 9, + -326, -430, -61, -321, -704, -299, 201, + -1, -280, -603, -419, -185, 18, -36, + -516, -522, -379, -291, -181, -97, 27, + -159, -313, -525, -224, -510, -831, -197, + -292, -459, -59, -310, -562, -143, -351, + 1066, 912, 631, 389, 207, 86, -224, + 596, 512, 596, 505, 314, 122, -48, + 787, 861, 441, -93, -303, 33, -190, + 257, 469, 337, 51, 15, 298, -93, + 295, 73, -119, 25, 36, 23, 108, + -28, -3, -32, 114, 21, 185, 107, + 482, 305, 15, -279, -319, 52, 96, + 226, 46, 115, 72, -136, 133, -125, + 18, -207, -559, -590, -503, -482, 321, + -571, -789, -951, -172, -441, -538, 113, + 181, 14, -310, -641, -1001, -202, 159, + -136, -393, -433, -513, -911, -144, -22, + 72, -265, -706, -954, -159, 53, 332, + -338, -591, -852, -383, -395, 56, 44, + 43, -158, -464, -897, -631, -157, -294, + -161, -128, -328, -573, -483, -125, 11, + 1017, 906, 1051, 1005, 679, 341, -102, + 359, 334, 1567, 1314, 723, 105, 10, + -65, 726, 529, 301, 220, 43, -273, + -510, 436, 719, 566, 358, 179, 114, + -560, 298, 133, -120, 342, 225, 14, + -899, -101, 217, 617, 400, 146, -58, + -41, 352, 82, -196, 39, 121, -167, + -212, 59, 447, 284, 423, 250, -169, + -371, -484, -596, 30, -41, 249, 22, + -372, -650, -794, 477, 445, 216, -79, + -352, 275, 17, -443, -929, 92, 19, + -699, -696, 431, 264, -49, -310, 182, + -978, -217, -430, -400, 101, 261, 72, + -929, -889, -357, -13, 463, 378, 236, + -826, 56, 30, -299, -360, -128, -51, + -878, -299, -111, 75, 65, 36, 3, + 817, 368, -25, 354, 697, 591, -173, + 309, 212, 222, 751, 484, 140, -56, + 593, 379, 70, -8, 258, 180, 110, + 165, -46, 255, 297, 219, 273, 105, + 160, -70, -358, -181, 379, 330, 319, + -238, -369, -198, 740, 580, 319, -143, + 201, 109, -202, -456, 328, 276, -141, + 203, 170, 111, 42, 207, 360, 188, + -345, -399, -513, -233, 650, 422, 81, + -635, -961, -1220, 463, 539, 204, 209, + 202, -25, -194, -498, -787, 193, -143, + -449, -538, 195, -106, -331, 68, 62, + -228, -477, -840, -576, 317, 128, 283, + -671, -937, -807, -114, 391, 335, -62, + 246, 2, -314, -679, -303, 180, -88, + -107, -272, 90, -198, -28, 290, -112, + 885, 1149, 1021, 712, 496, 281, -83, + 269, 492, 787, 643, 347, 70, 124, + 336, 636, 499, 92, -229, -179, 191, + 26, 402, 564, 340, 149, -11, 135, + -440, 561, 470, 204, -72, -186, 140, + -720, 14, 355, 229, 68, -133, 465, + 110, 310, 103, 12, 106, 29, 158, + -178, 113, 161, 142, 121, 115, 27, + -651, -414, -645, -152, -164, -13, -429, + -639, -944, -681, -104, -81, 52, -189, + -663, -164, -316, -683, -954, -205, -83, + -609, -669, -172, -517, -694, 283, -80, + -646, -152, -383, -678, -246, -40, -143, + -747, -796, -745, -390, -98, 43, 275, + -599, -199, -398, -433, -436, -538, 31, + -1107, -568, -376, -265, -126, -21, 1, + 847, 573, 308, 392, 305, 101, 55, + 273, 293, 201, 267, 346, 201, 123, + 727, 480, 226, 2, -65, -138, 164, + 273, 208, 173, 292, 12, 253, 174, + 340, 207, 180, 88, 116, 46, 475, + -460, -166, -30, 13, 110, 173, 396, + 137, 88, 43, -137, -94, 34, 284, + 96, -14, 226, 40, 63, 70, 130, + -467, -735, -1012, -1174, -307, 305, -67, + -612, -920, -1146, -567, -8, 92, -25, + -182, -271, -492, -754, -857, 287, -75, + -494, -787, -689, -683, -709, 137, -326, + -288, -550, -903, -1105, 334, 321, -62, + -354, -653, -834, -445, 1, 377, -152, + -162, -306, -608, -937, -297, 247, -192, + -234, -477, -244, -488, -266, 342, -332 }; /*-------------------------------------------------------------------* @@ -9513,70 +9513,70 @@ const Word16 dico2_isf_fx[] = /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ const Word16 dico21_isf_46b_fx[] = {/*Qlog2(2.56)*/ - 329, 409, 249, - -33, 505, 160, - -29, -14, 582, - -262, 127, 354, - 145, 237, 175, - -152, 245, 122, - 27, 42, 340, - -84, -93, 311, - 285, 222, -156, - 47, -43, -504, - 234, 121, 385, - 104, -317, 45, - 176, 195, 8, - 104, -59, -94, - 177, 53, 192, - -34, -127, 152, - 570, 277, -34, - -67, -329, -639, - -157, -272, 462, - -177, -462, 198, - 322, 179, 115, - -386, 171, 19, - 19, -12, 195, - -120, -252, 201, - 304, 36, -336, - -128, -221, -380, - 171, -185, 296, - -242, -312, 23, - 198, 39, 16, - -3, -177, -111, - 111, -93, 76, - -92, -223, 4, - 177, 406, -44, - -168, 380, -149, - -4, 273, 331, - -420, 513, 277, - 21, 247, 47, - -58, 131, -2, - -3, 134, 180, - -145, 40, 175, - 189, 74, -145, - -27, -45, -325, - 370, -114, -21, - -83, -415, -173, - 77, 95, -51, - -40, -30, -67, - 71, 88, 86, - -35, -98, 14, - 69, 197, -334, - -196, 79, -231, - -348, -137, 218, - -352, -89, -85, - 47, 201, -130, - -165, 37, -15, - -43, 3, 86, - -161, -108, 79, - 83, 21, -237, - -81, -149, -238, - 150, -186, -251, - -186, -249, -162, - -19, 66, -139, - -26, -50, -181, - 24, 11, 0, - -130, -105, -98 + 329, 409, 249, + -33, 505, 160, + -29, -14, 582, + -262, 127, 354, + 145, 237, 175, + -152, 245, 122, + 27, 42, 340, + -84, -93, 311, + 285, 222, -156, + 47, -43, -504, + 234, 121, 385, + 104, -317, 45, + 176, 195, 8, + 104, -59, -94, + 177, 53, 192, + -34, -127, 152, + 570, 277, -34, + -67, -329, -639, + -157, -272, 462, + -177, -462, 198, + 322, 179, 115, + -386, 171, 19, + 19, -12, 195, + -120, -252, 201, + 304, 36, -336, + -128, -221, -380, + 171, -185, 296, + -242, -312, 23, + 198, 39, 16, + -3, -177, -111, + 111, -93, 76, + -92, -223, 4, + 177, 406, -44, + -168, 380, -149, + -4, 273, 331, + -420, 513, 277, + 21, 247, 47, + -58, 131, -2, + -3, 134, 180, + -145, 40, 175, + 189, 74, -145, + -27, -45, -325, + 370, -114, -21, + -83, -415, -173, + 77, 95, -51, + -40, -30, -67, + 71, 88, 86, + -35, -98, 14, + 69, 197, -334, + -196, 79, -231, + -348, -137, 218, + -352, -89, -85, + 47, 201, -130, + -165, 37, -15, + -43, 3, 86, + -161, -108, 79, + 83, 21, -237, + -81, -149, -238, + 150, -186, -251, + -186, -249, -162, + -19, 66, -139, + -26, -50, -181, + 24, 11, 0, + -130, -105, -98 }; /*-------------------------------------------------------------------* @@ -9586,134 +9586,134 @@ const Word16 dico21_isf_46b_fx[] = /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ const Word16 dico22_isf_46b_fx[] = {/*Qlog2(2.56)*/ - -127, 310, 42, - -242, 197, 5, - -151, 84, -17, - -214, 127, -149, - -247, -131, 159, - -268, -267, -95, - -217, 1, -79, - -271, -80, -185, - -45, 436, 159, - 165, 199, 391, - -33, 81, 187, - -66, -42, 355, - -298, -57, 343, - -108, -537, 226, - -144, -23, 193, - 176, -402, 87, - 53, 296, 25, - -84, 253, -104, - -58, 105, -126, - -169, 174, -314, - -48, 44, -294, - -164, -417, -242, - -139, 3, -194, - -155, -207, -211, - 119, 322, 213, - 333, 50, 380, - 237, 247, -2, - 466, -16, 201, - 238, -255, -107, - 67, -440, -149, - 122, -88, -139, - 88, -247, -73, - -41, 231, 167, - -62, 155, 16, - -65, 16, 77, - -68, -2, -63, - -151, -300, 160, - -18, -333, 54, - -56, -94, 5, - 2, -190, 14, - 92, 148, 209, - 108, 9, 272, - 108, 35, 110, - 142, -85, 145, - 47, -157, 279, - 3, -320, 246, - 43, -72, 68, - 86, -217, 135, - 36, 140, 79, - 56, 175, -49, - 26, 45, 3, - 73, 55, -101, - 109, -183, -242, - -4, -283, -242, - 48, -68, -48, - -6, -153, -122, - 161, 196, 96, - 232, 80, 190, - 165, 97, 11, - 258, -31, 71, - 267, -77, -91, - 311, -209, 87, - 152, -14, -22, - 150, -149, 9, - -324, 557, 187, - -384, 307, 46, - -251, 27, 77, - -365, 77, -52, - -482, -84, 160, - -424, -515, -64, - -294, -120, -4, - -476, -116, -109, - -97, 318, 365, - 106, 627, 445, - -190, 120, 287, - -146, 65, 619, - -427, 242, 363, - -361, -371, 432, - -347, 102, 168, - -629, 195, -14, - -65, 476, -47, - -297, 320, -168, - -55, 356, -264, - -391, 82, -286, - -51, -31, -556, - -178, -399, -586, - -205, -49, -360, - -343, -238, -337, - 220, 457, 58, - 561, 467, 259, - 340, 270, -168, - 450, 77, -280, - 60, 167, -413, - 133, -252, -492, - 216, 157, -290, - 282, 0, -495, - -226, 293, 183, - -157, 135, 122, - -158, -59, 39, - -133, -118, -97, - -332, -309, 113, - -160, -425, -6, - -149, -211, 24, - -80, -277, -90, - -11, 125, 338, - 130, -71, 465, - 5, -45, 184, - 237, -95, 253, - -139, -197, 297, - -19, -300, 511, - -63, -152, 139, - 250, -289, 336, - 124, 339, -150, - 34, 176, -208, - 171, 166, -116, - 94, 38, -229, - 75, -65, -339, - -78, -205, -385, - 0, -30, -163, - -56, -110, -242, - 321, 244, 194, - 505, 238, -1, - 317, 116, 65, - 309, 88, -74, - 452, -51, -50, - 334, -217, -290, - 211, 41, -152, - 238, -55, -260 + -127, 310, 42, + -242, 197, 5, + -151, 84, -17, + -214, 127, -149, + -247, -131, 159, + -268, -267, -95, + -217, 1, -79, + -271, -80, -185, + -45, 436, 159, + 165, 199, 391, + -33, 81, 187, + -66, -42, 355, + -298, -57, 343, + -108, -537, 226, + -144, -23, 193, + 176, -402, 87, + 53, 296, 25, + -84, 253, -104, + -58, 105, -126, + -169, 174, -314, + -48, 44, -294, + -164, -417, -242, + -139, 3, -194, + -155, -207, -211, + 119, 322, 213, + 333, 50, 380, + 237, 247, -2, + 466, -16, 201, + 238, -255, -107, + 67, -440, -149, + 122, -88, -139, + 88, -247, -73, + -41, 231, 167, + -62, 155, 16, + -65, 16, 77, + -68, -2, -63, + -151, -300, 160, + -18, -333, 54, + -56, -94, 5, + 2, -190, 14, + 92, 148, 209, + 108, 9, 272, + 108, 35, 110, + 142, -85, 145, + 47, -157, 279, + 3, -320, 246, + 43, -72, 68, + 86, -217, 135, + 36, 140, 79, + 56, 175, -49, + 26, 45, 3, + 73, 55, -101, + 109, -183, -242, + -4, -283, -242, + 48, -68, -48, + -6, -153, -122, + 161, 196, 96, + 232, 80, 190, + 165, 97, 11, + 258, -31, 71, + 267, -77, -91, + 311, -209, 87, + 152, -14, -22, + 150, -149, 9, + -324, 557, 187, + -384, 307, 46, + -251, 27, 77, + -365, 77, -52, + -482, -84, 160, + -424, -515, -64, + -294, -120, -4, + -476, -116, -109, + -97, 318, 365, + 106, 627, 445, + -190, 120, 287, + -146, 65, 619, + -427, 242, 363, + -361, -371, 432, + -347, 102, 168, + -629, 195, -14, + -65, 476, -47, + -297, 320, -168, + -55, 356, -264, + -391, 82, -286, + -51, -31, -556, + -178, -399, -586, + -205, -49, -360, + -343, -238, -337, + 220, 457, 58, + 561, 467, 259, + 340, 270, -168, + 450, 77, -280, + 60, 167, -413, + 133, -252, -492, + 216, 157, -290, + 282, 0, -495, + -226, 293, 183, + -157, 135, 122, + -158, -59, 39, + -133, -118, -97, + -332, -309, 113, + -160, -425, -6, + -149, -211, 24, + -80, -277, -90, + -11, 125, 338, + 130, -71, 465, + 5, -45, 184, + 237, -95, 253, + -139, -197, 297, + -19, -300, 511, + -63, -152, 139, + 250, -289, 336, + 124, 339, -150, + 34, 176, -208, + 171, 166, -116, + 94, 38, -229, + 75, -65, -339, + -78, -205, -385, + 0, -30, -163, + -56, -110, -242, + 321, 244, 194, + 505, 238, -1, + 317, 116, 65, + 309, 88, -74, + 452, -51, -50, + 334, -217, -290, + 211, 41, -152, + 238, -55, -260 }; /*-------------------------------------------------------------------* @@ -9723,134 +9723,134 @@ const Word16 dico22_isf_46b_fx[] = /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ const Word16 dico23_isf_46b_fx[] = {/*Qlog2(2.56)*/ - -10, 151, 359, - 136, 298, 223, - 255, -104, 290, - 423, 6, 183, - -270, -269, -98, - -52, -82, 13, - -82, -274, -97, - 90, -246, -72, - -299, -70, 421, - -88, 365, 430, - 187, -318, 381, - 380, 37, 488, - -373, -316, 79, - -308, -101, 5, - -135, -451, 8, - 72, -421, -154, - 180, 170, -121, - 62, 177, -40, - 326, 80, -105, - 248, 263, -5, - -168, -181, -221, - -2, -23, -158, - -14, -149, -121, - 119, -91, -147, - 119, 332, -153, - 49, 303, 34, - 442, -55, -69, - 217, 454, 58, - -359, -187, -375, - -42, 50, -274, - -8, -267, -249, - 85, -86, -346, - -77, -40, 345, - 89, 134, 219, - 156, -80, 160, - 108, 40, 116, - -158, -206, 29, - 5, -32, 175, - -65, -158, 146, - 55, -78, 73, - -114, -222, 353, - -47, 81, 211, - 49, -151, 268, - 105, 4, 302, - -263, -132, 183, - -151, -28, 201, - -177, -307, 166, - 101, -221, 130, - 74, 58, -98, - 32, 44, 13, - 194, 30, -142, - 170, 96, 8, - -136, -119, -91, - -65, 8, -55, - 3, -188, 12, - 45, -63, -49, - 149, -21, -19, - 24, 144, 95, - 254, -22, 60, - 161, 196, 96, - -158, -61, 48, - -70, 33, 82, - -23, -321, 58, - 155, -147, 5, - -364, 328, 77, - -21, 453, 173, - -108, 82, 630, - 367, 263, 208, - -300, -62, -176, - -205, 143, -158, - -169, -410, -264, - 257, -269, -100, - -636, 289, -2, - -292, 627, 173, - -382, -363, 387, - 248, 524, 447, - -521, -111, -107, - -395, 118, -274, - -343, -680, -125, - -172, -447, -663, - 75, 148, -367, - -79, 263, -94, - 249, 148, -286, - 380, 271, -162, - -142, -4, -186, - -57, 111, -125, - -35, -108, -254, - 100, 29, -242, - -80, 303, -264, - -78, 464, -57, - 248, -22, -494, - 661, 662, 44, - -193, -40, -330, - -178, 145, -337, - -90, -199, -400, - -40, -23, -498, - -192, 114, 315, - -41, 244, 190, - 88, -97, 485, - 241, 80, 212, - -246, 40, 87, - -156, 147, 134, - -2, -334, 239, - 308, -203, 110, - -459, 251, 422, - -218, 310, 228, - -86, -346, 654, - 184, 175, 425, - -481, -63, 169, - -349, 117, 188, - -125, -560, 310, - 158, -416, 94, - 46, 171, -192, - -63, 157, 14, - 256, -35, -271, - 322, 123, 53, - -214, 4, -76, - -156, 86, -18, - 128, -197, -232, - 265, -90, -98, - -308, 332, -145, - -131, 308, 58, - 509, 59, -339, - 562, 196, -14, - -378, 100, -47, - -234, 202, 1, - 104, -270, -493, - 319, -210, -325 + -10, 151, 359, + 136, 298, 223, + 255, -104, 290, + 423, 6, 183, + -270, -269, -98, + -52, -82, 13, + -82, -274, -97, + 90, -246, -72, + -299, -70, 421, + -88, 365, 430, + 187, -318, 381, + 380, 37, 488, + -373, -316, 79, + -308, -101, 5, + -135, -451, 8, + 72, -421, -154, + 180, 170, -121, + 62, 177, -40, + 326, 80, -105, + 248, 263, -5, + -168, -181, -221, + -2, -23, -158, + -14, -149, -121, + 119, -91, -147, + 119, 332, -153, + 49, 303, 34, + 442, -55, -69, + 217, 454, 58, + -359, -187, -375, + -42, 50, -274, + -8, -267, -249, + 85, -86, -346, + -77, -40, 345, + 89, 134, 219, + 156, -80, 160, + 108, 40, 116, + -158, -206, 29, + 5, -32, 175, + -65, -158, 146, + 55, -78, 73, + -114, -222, 353, + -47, 81, 211, + 49, -151, 268, + 105, 4, 302, + -263, -132, 183, + -151, -28, 201, + -177, -307, 166, + 101, -221, 130, + 74, 58, -98, + 32, 44, 13, + 194, 30, -142, + 170, 96, 8, + -136, -119, -91, + -65, 8, -55, + 3, -188, 12, + 45, -63, -49, + 149, -21, -19, + 24, 144, 95, + 254, -22, 60, + 161, 196, 96, + -158, -61, 48, + -70, 33, 82, + -23, -321, 58, + 155, -147, 5, + -364, 328, 77, + -21, 453, 173, + -108, 82, 630, + 367, 263, 208, + -300, -62, -176, + -205, 143, -158, + -169, -410, -264, + 257, -269, -100, + -636, 289, -2, + -292, 627, 173, + -382, -363, 387, + 248, 524, 447, + -521, -111, -107, + -395, 118, -274, + -343, -680, -125, + -172, -447, -663, + 75, 148, -367, + -79, 263, -94, + 249, 148, -286, + 380, 271, -162, + -142, -4, -186, + -57, 111, -125, + -35, -108, -254, + 100, 29, -242, + -80, 303, -264, + -78, 464, -57, + 248, -22, -494, + 661, 662, 44, + -193, -40, -330, + -178, 145, -337, + -90, -199, -400, + -40, -23, -498, + -192, 114, 315, + -41, 244, 190, + 88, -97, 485, + 241, 80, 212, + -246, 40, 87, + -156, 147, 134, + -2, -334, 239, + 308, -203, 110, + -459, 251, 422, + -218, 310, 228, + -86, -346, 654, + 184, 175, 425, + -481, -63, 169, + -349, 117, 188, + -125, -560, 310, + 158, -416, 94, + 46, 171, -192, + -63, 157, 14, + 256, -35, -271, + 322, 123, 53, + -214, 4, -76, + -156, 86, -18, + 128, -197, -232, + 265, -90, -98, + -308, 332, -145, + -131, 308, 58, + 509, 59, -339, + 562, 196, -14, + -378, 100, -47, + -234, 202, 1, + 104, -270, -493, + 319, -210, -325 }; /*-------------------------------------------------------------------* @@ -9860,38 +9860,38 @@ const Word16 dico23_isf_46b_fx[] = /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ const Word16 dico24_isf_46b_fx[] = {/*Qlog2(2.56)*/ - -79, -89, -4, - -171, 77, -211, - 160, -193, 98, - 120, -103, 323, - 32, -22, -129, - 72, 78, -268, - 182, -76, -66, - 309, 99, -145, - -229, -157, -84, - -383, 98, -71, - -90, -352, 12, - -284, -178, 178, - -65, -125, -166, - -87, -175, -351, - 42, -198, -48, - 154, -140, -243, - -77, 18, 108, - -39, 355, 91, - 87, 8, 155, - -4, 158, 239, - 128, 95, -54, - 7, 246, -124, - 258, 15, 89, - 206, 216, 98, - -201, 9, 18, - -312, 233, 204, - -39, -174, 155, - -144, -9, 284, - -57, 70, -69, - -157, 187, 18, - 54, -30, 23, - 24, 135, 55 + -79, -89, -4, + -171, 77, -211, + 160, -193, 98, + 120, -103, 323, + 32, -22, -129, + 72, 78, -268, + 182, -76, -66, + 309, 99, -145, + -229, -157, -84, + -383, 98, -71, + -90, -352, 12, + -284, -178, 178, + -65, -125, -166, + -87, -175, -351, + 42, -198, -48, + 154, -140, -243, + -77, 18, 108, + -39, 355, 91, + 87, 8, 155, + -4, 158, 239, + 128, 95, -54, + 7, 246, -124, + 258, 15, 89, + 206, 216, 98, + -201, 9, 18, + -312, 233, 204, + -39, -174, 155, + -144, -9, 284, + -57, 70, -69, + -157, 187, 18, + 54, -30, 23, + 24, 135, 55 }; /*-------------------------------------------------------------------* @@ -9901,38 +9901,38 @@ const Word16 dico24_isf_46b_fx[] = /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ const Word16 dico25_isf_46b_fx[] = {/*Qlog2(2.56)*/ - 169, 142, -119, 115, - 206, -20, 94, 226, - -106, 313, -21, 16, - -62, 161, 71, 255, - -89, 101, -185, 125, - 72, -30, -201, 344, - -258, 33, -8, 81, - -104, -154, 72, 296, - 144, -68, -268, -25, - 81, -78, -87, 106, - 22, 155, -186, -119, - -46, -28, 27, 91, - -114, -37, -175, -33, - -94, -222, -189, 122, - -132, -119, -191, -270, - -172, -173, 18, -43, - 279, 135, -42, -128, - 187, -86, 229, -138, - 159, 240, 140, 46, - 69, 25, 227, 77, - 21, 115, 13, 8, - 68, -248, 126, 81, - -150, 137, 207, -9, - -154, -133, 289, 67, - 143, -37, -86, -326, - 180, -32, 19, -23, - 26, 168, 116, -233, - -32, -26, 118, -78, - 3, -8, -45, -115, - 57, -215, -54, -83, - -209, 112, -22, -167, - -91, -151, 168, -262 + 169, 142, -119, 115, + 206, -20, 94, 226, + -106, 313, -21, 16, + -62, 161, 71, 255, + -89, 101, -185, 125, + 72, -30, -201, 344, + -258, 33, -8, 81, + -104, -154, 72, 296, + 144, -68, -268, -25, + 81, -78, -87, 106, + 22, 155, -186, -119, + -46, -28, 27, 91, + -114, -37, -175, -33, + -94, -222, -189, 122, + -132, -119, -191, -270, + -172, -173, 18, -43, + 279, 135, -42, -128, + 187, -86, 229, -138, + 159, 240, 140, 46, + 69, 25, 227, 77, + 21, 115, 13, 8, + 68, -248, 126, 81, + -150, 137, 207, -9, + -154, -133, 289, 67, + 143, -37, -86, -326, + 180, -32, 19, -23, + 26, 168, 116, -233, + -32, -26, 118, -78, + 3, -8, -45, -115, + 57, -215, -54, -83, + -209, 112, -22, -167, + -91, -151, 168, -262 }; @@ -9954,134 +9954,134 @@ const Word16 dico25_isf_46b_fx[] = /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ const Word16 dico21_isf_36b_fx[] = {/*Qlog2(2.56)*/ - -52, -96, 212, 315, -73, - 82, -204, 363, 136, -197, - -126, -331, 183, 218, 143, - -49, -41, 557, 230, 72, - 2, -73, 163, 377, 221, - 133, 111, 278, 215, -110, - -102, -20, 284, 113, 273, - 84, 319, 290, 18, 85, - -25, -5, 125, 132, -204, - -38, -5, 286, -9, -356, - -140, -256, 92, 117, -189, - -144, 191, 313, 51, -98, - 167, -10, 44, 247, 36, - 381, 197, 238, 74, 6, - 38, -408, 29, -3, -85, - 92, 266, 157, -25, -200, - 161, -121, 70, 84, -140, - -16, -86, 112, -94, -189, - -269, -270, 351, 107, -24, - -68, -67, 492, -103, -155, - -53, -131, 62, 122, 10, - 135, 84, 283, -55, -120, - -12, -219, 331, -81, 167, - 220, -136, 147, -172, -42, - 140, -95, -109, -88, -194, - 0, -2, -4, -33, -381, - -66, -217, 152, -186, -402, - 244, 108, 156, -140, -395, - 113, -136, -196, 110, -24, - 214, 118, 11, -64, -131, - -110, -286, -6, -332, 16, - 94, 97, 79, -291, -205, - -5, -39, -20, 252, -96, - 76, 174, 101, 163, 61, - -69, -239, -55, 399, 6, - -115, 319, 164, 275, 196, - -15, 36, -47, 331, 121, - 226, 209, 271, 325, 184, - 13, -80, -218, 471, 353, - 288, 378, 16, -51, 251, - 174, 116, 52, 149, -279, - 235, 276, 39, 120, -48, - 0, -108, -108, 241, -339, - -93, 534, 45, 33, -87, - 194, 149, -71, 405, -44, - 409, 370, 81, -186, -154, - 25, -102, -448, 124, -173, - 22, 408, -110, -310, -214, - -26, 23, -83, 114, 14, - -110, 164, 52, 223, -82, - 37, -25, -263, 306, -15, - -466, 415, 292, 165, -18, - 29, -19, -171, 155, 182, - 179, 144, -27, 231, 258, - -103, -247, -396, 238, 113, - 375, -154, -109, -4, 156, - 98, 85, -292, -5, -124, - 116, 139, -116, -98, -294, - -14, -83, -278, -117, -378, - 106, 33, -106, -344, -484, - 119, 17, -412, 138, 166, - 384, 101, -204, 88, -156, - -121, -284, -300, -1, -166, - 280, 33, -152, -313, -81, - -37, 22, 229, 153, 37, - -60, -83, 236, -8, -41, - -169, -228, 126, -20, 363, - -235, 17, 364, -156, 156, - -25, -30, 72, 144, 156, - 153, -26, 256, 97, 144, - -21, -37, 48, -65, 250, - 63, 77, 273, -128, 124, - -129, -26, 40, 9, -115, - -6, 82, 38, -90, -182, - -336, -13, 28, 158, 91, - -30, 241, 137, -170, -17, - 146, 14, -11, 33, 61, - 192, 197, 54, -84, 85, - 23, -200, -78, -29, 140, - 122, 237, 106, -341, 136, - -57, -142, -85, -16, -74, - -59, -90, -8, -187, -20, - -211, -267, 216, -179, -110, - -50, -7, 220, -267, -70, - -57, -42, -17, -15, 71, - 32, 21, 63, -137, 33, - -137, -175, 104, -68, 97, - -67, -43, 133, -301, 221, - -116, -200, -81, -92, -272, - -64, -41, -54, -244, -220, - -287, -242, -50, -87, -89, - -245, 236, 102, -166, -295, - 66, 24, -162, -71, 95, - 66, 136, -90, -220, -36, - -98, -161, -222, -188, 29, - -18, 18, -19, -415, 9, - 49, 61, 100, 39, -56, - -111, 82, 135, -31, 52, - -90, -153, -93, 189, 182, - -214, 295, 119, -74, 284, - 2, 137, 37, 47, 182, - 92, 117, 184, -53, 373, - -21, -14, -35, 136, 391, - 146, 129, -164, -28, 333, - 92, 80, -84, 100, -134, - -8, 217, -32, 3, -47, - -151, 251, -215, 142, 92, - -224, 310, -172, -275, 98, - 159, 155, -177, 112, 53, - 205, 27, 8, -240, 192, - 169, 120, -319, -201, 106, - 11, 36, -86, -237, 455, - -109, -154, -163, 174, -55, - -38, 32, -101, -78, -59, - -205, -321, -97, 69, 79, - -310, 44, 18, -185, 34, - -115, -20, -148, -39, 203, - -29, 154, -30, -158, 166, - -45, -131, -317, -24, 363, - -165, -205, -112, -222, 265, - -32, -44, -150, 54, -193, - -6, -38, -255, -169, -115, - -266, 87, -189, -36, -169, - -60, -87, -266, -436, -170, - -68, -81, -278, 24, 38, - -23, -19, -155, -256, 141, - -61, -226, -565, -175, 71, - 9, -29, -237, -515, 263 + -52, -96, 212, 315, -73, + 82, -204, 363, 136, -197, + -126, -331, 183, 218, 143, + -49, -41, 557, 230, 72, + 2, -73, 163, 377, 221, + 133, 111, 278, 215, -110, + -102, -20, 284, 113, 273, + 84, 319, 290, 18, 85, + -25, -5, 125, 132, -204, + -38, -5, 286, -9, -356, + -140, -256, 92, 117, -189, + -144, 191, 313, 51, -98, + 167, -10, 44, 247, 36, + 381, 197, 238, 74, 6, + 38, -408, 29, -3, -85, + 92, 266, 157, -25, -200, + 161, -121, 70, 84, -140, + -16, -86, 112, -94, -189, + -269, -270, 351, 107, -24, + -68, -67, 492, -103, -155, + -53, -131, 62, 122, 10, + 135, 84, 283, -55, -120, + -12, -219, 331, -81, 167, + 220, -136, 147, -172, -42, + 140, -95, -109, -88, -194, + 0, -2, -4, -33, -381, + -66, -217, 152, -186, -402, + 244, 108, 156, -140, -395, + 113, -136, -196, 110, -24, + 214, 118, 11, -64, -131, + -110, -286, -6, -332, 16, + 94, 97, 79, -291, -205, + -5, -39, -20, 252, -96, + 76, 174, 101, 163, 61, + -69, -239, -55, 399, 6, + -115, 319, 164, 275, 196, + -15, 36, -47, 331, 121, + 226, 209, 271, 325, 184, + 13, -80, -218, 471, 353, + 288, 378, 16, -51, 251, + 174, 116, 52, 149, -279, + 235, 276, 39, 120, -48, + 0, -108, -108, 241, -339, + -93, 534, 45, 33, -87, + 194, 149, -71, 405, -44, + 409, 370, 81, -186, -154, + 25, -102, -448, 124, -173, + 22, 408, -110, -310, -214, + -26, 23, -83, 114, 14, + -110, 164, 52, 223, -82, + 37, -25, -263, 306, -15, + -466, 415, 292, 165, -18, + 29, -19, -171, 155, 182, + 179, 144, -27, 231, 258, + -103, -247, -396, 238, 113, + 375, -154, -109, -4, 156, + 98, 85, -292, -5, -124, + 116, 139, -116, -98, -294, + -14, -83, -278, -117, -378, + 106, 33, -106, -344, -484, + 119, 17, -412, 138, 166, + 384, 101, -204, 88, -156, + -121, -284, -300, -1, -166, + 280, 33, -152, -313, -81, + -37, 22, 229, 153, 37, + -60, -83, 236, -8, -41, + -169, -228, 126, -20, 363, + -235, 17, 364, -156, 156, + -25, -30, 72, 144, 156, + 153, -26, 256, 97, 144, + -21, -37, 48, -65, 250, + 63, 77, 273, -128, 124, + -129, -26, 40, 9, -115, + -6, 82, 38, -90, -182, + -336, -13, 28, 158, 91, + -30, 241, 137, -170, -17, + 146, 14, -11, 33, 61, + 192, 197, 54, -84, 85, + 23, -200, -78, -29, 140, + 122, 237, 106, -341, 136, + -57, -142, -85, -16, -74, + -59, -90, -8, -187, -20, + -211, -267, 216, -179, -110, + -50, -7, 220, -267, -70, + -57, -42, -17, -15, 71, + 32, 21, 63, -137, 33, + -137, -175, 104, -68, 97, + -67, -43, 133, -301, 221, + -116, -200, -81, -92, -272, + -64, -41, -54, -244, -220, + -287, -242, -50, -87, -89, + -245, 236, 102, -166, -295, + 66, 24, -162, -71, 95, + 66, 136, -90, -220, -36, + -98, -161, -222, -188, 29, + -18, 18, -19, -415, 9, + 49, 61, 100, 39, -56, + -111, 82, 135, -31, 52, + -90, -153, -93, 189, 182, + -214, 295, 119, -74, 284, + 2, 137, 37, 47, 182, + 92, 117, 184, -53, 373, + -21, -14, -35, 136, 391, + 146, 129, -164, -28, 333, + 92, 80, -84, 100, -134, + -8, 217, -32, 3, -47, + -151, 251, -215, 142, 92, + -224, 310, -172, -275, 98, + 159, 155, -177, 112, 53, + 205, 27, 8, -240, 192, + 169, 120, -319, -201, 106, + 11, 36, -86, -237, 455, + -109, -154, -163, 174, -55, + -38, 32, -101, -78, -59, + -205, -321, -97, 69, 79, + -310, 44, 18, -185, 34, + -115, -20, -148, -39, 203, + -29, 154, -30, -158, 166, + -45, -131, -317, -24, 363, + -165, -205, -112, -222, 265, + -32, -44, -150, 54, -193, + -6, -38, -255, -169, -115, + -266, 87, -189, -36, -169, + -60, -87, -266, -436, -170, + -68, -81, -278, 24, 38, + -23, -19, -155, -256, 141, + -61, -226, -565, -175, 71, + 9, -29, -237, -515, 263 }; /*-------------------------------------------------------------------* @@ -10092,134 +10092,134 @@ const Word16 dico21_isf_36b_fx[] = const Word16 dico22_isf_36b_fx[] = {/*Qlog2(2.56)*/ - -298, -6, 95, 31, - -213, -87, -122, 261, - 4, -49, 208, 14, - -129, -110, 30, 118, - -214, 258, 110, -235, - -41, -18, -126, 120, - 103, 65, 127, -37, - 126, -36, -24, 25, - -138, -67, -278, -186, - -164, -194, -201, 78, - -211, -87, -51, -221, - -174, -79, -94, -39, - 23, -6, -157, -240, - 22, -110, -153, -68, - 148, -5, -2, -149, - -1, -135, -39, -179, - 68, 360, -117, -15, - 137, 47, -278, 146, - 136, 260, 135, 65, - 61, 116, -45, 97, - 231, 379, 87, -120, - 338, 177, -272, 3, - 266, 156, 28, -69, - 260, 84, -85, 86, - -266, 154, -256, -182, - -17, -65, -304, -6, - -40, 175, -151, -180, - -27, 27, -87, -63, - 121, 114, -166, -469, - 159, -66, -323, -231, - 214, 152, -141, -212, - 137, 36, -184, -51, - -282, -237, 40, 10, - -48, -235, -37, 251, - -54, -323, 136, 29, - -88, -174, 213, 198, - -390, 99, -63, -375, - 107, -169, -164, 424, - 69, -111, 141, -167, - 74, -129, 65, 144, - -353, -207, -205, -109, - -160, -386, -355, 98, - -176, -493, -20, -143, - -252, -432, -2, 216, - -90, -174, -168, -411, - 13, -284, -229, -160, - -87, -279, 34, -251, - -75, -263, -58, -42, - 420, 53, -211, -358, - 384, -35, -374, 396, - 68, -228, 323, -2, - 167, -307, 192, 194, - 459, 329, -5, -332, - 375, 79, -7, 313, - 282, -124, 200, -92, - 271, -162, -70, 180, - -157, -298, -514, -309, - 58, -163, -546, 18, - 124, -364, 167, -238, - 83, -411, -117, 96, - 140, -112, -388, -624, - 259, -133, -317, 41, - 163, -130, -64, -334, - 226, -165, -124, -110, - -466, -61, 6, 229, - -153, 205, -145, 242, - -159, 48, 195, 148, - -58, 28, 31, 279, - -303, 185, 279, -4, - -61, 197, 59, 86, - -114, 123, 168, -52, - 35, 36, 100, 126, - -407, 102, -77, -40, - -338, -1, -342, 156, - -179, 105, -34, -97, - -185, 84, -35, 108, - -133, 107, -91, -357, - -180, 54, -229, 24, - -44, 47, 47, -182, - -66, 13, 45, 4, - -339, 251, 64, 226, - -42, 101, -350, 275, - -99, 398, 142, 121, - 111, 12, -102, 260, - 0, 505, 260, -94, - 161, 285, -96, 224, - -4, 206, 314, 33, - 167, 139, 88, 204, - -235, 316, -60, -25, - -8, -150, -312, 201, - -36, 292, 61, -104, - -40, 174, -162, 42, - -21, 402, -29, -351, - 21, 152, -360, -93, - 57, 191, 212, -196, - 76, 158, -21, -69, - -328, -185, 331, 119, - -53, 285, 56, 337, - -107, -24, 405, 29, - -18, 137, 272, 277, - -255, 22, 173, -191, - 295, 322, 325, 302, - 21, -27, 332, -178, - 119, 13, 271, 129, - -455, -180, 116, -191, - -227, 62, -148, 524, - -176, -287, 282, -157, - -243, 13, 199, 430, - -59, -49, 115, -365, - 72, -172, -137, 93, - -138, -126, 141, -84, - 5, -124, 38, -20, - -258, 311, 601, 213, - 94, 130, -61, 502, - -1, -157, 485, 313, - 146, -74, 158, 345, - 276, 135, 280, -57, - 490, 252, 99, 43, - 267, -74, 429, 105, - 278, -23, 119, 94, - -542, 488, 257, -115, - -84, -244, -438, 478, - -113, -545, 387, 101, - -95, -306, 111, 498, - 95, 166, 22, -301, - 420, -15, -58, -78, - 270, 29, 122, -282, - 160, -240, 50, -38 + -298, -6, 95, 31, + -213, -87, -122, 261, + 4, -49, 208, 14, + -129, -110, 30, 118, + -214, 258, 110, -235, + -41, -18, -126, 120, + 103, 65, 127, -37, + 126, -36, -24, 25, + -138, -67, -278, -186, + -164, -194, -201, 78, + -211, -87, -51, -221, + -174, -79, -94, -39, + 23, -6, -157, -240, + 22, -110, -153, -68, + 148, -5, -2, -149, + -1, -135, -39, -179, + 68, 360, -117, -15, + 137, 47, -278, 146, + 136, 260, 135, 65, + 61, 116, -45, 97, + 231, 379, 87, -120, + 338, 177, -272, 3, + 266, 156, 28, -69, + 260, 84, -85, 86, + -266, 154, -256, -182, + -17, -65, -304, -6, + -40, 175, -151, -180, + -27, 27, -87, -63, + 121, 114, -166, -469, + 159, -66, -323, -231, + 214, 152, -141, -212, + 137, 36, -184, -51, + -282, -237, 40, 10, + -48, -235, -37, 251, + -54, -323, 136, 29, + -88, -174, 213, 198, + -390, 99, -63, -375, + 107, -169, -164, 424, + 69, -111, 141, -167, + 74, -129, 65, 144, + -353, -207, -205, -109, + -160, -386, -355, 98, + -176, -493, -20, -143, + -252, -432, -2, 216, + -90, -174, -168, -411, + 13, -284, -229, -160, + -87, -279, 34, -251, + -75, -263, -58, -42, + 420, 53, -211, -358, + 384, -35, -374, 396, + 68, -228, 323, -2, + 167, -307, 192, 194, + 459, 329, -5, -332, + 375, 79, -7, 313, + 282, -124, 200, -92, + 271, -162, -70, 180, + -157, -298, -514, -309, + 58, -163, -546, 18, + 124, -364, 167, -238, + 83, -411, -117, 96, + 140, -112, -388, -624, + 259, -133, -317, 41, + 163, -130, -64, -334, + 226, -165, -124, -110, + -466, -61, 6, 229, + -153, 205, -145, 242, + -159, 48, 195, 148, + -58, 28, 31, 279, + -303, 185, 279, -4, + -61, 197, 59, 86, + -114, 123, 168, -52, + 35, 36, 100, 126, + -407, 102, -77, -40, + -338, -1, -342, 156, + -179, 105, -34, -97, + -185, 84, -35, 108, + -133, 107, -91, -357, + -180, 54, -229, 24, + -44, 47, 47, -182, + -66, 13, 45, 4, + -339, 251, 64, 226, + -42, 101, -350, 275, + -99, 398, 142, 121, + 111, 12, -102, 260, + 0, 505, 260, -94, + 161, 285, -96, 224, + -4, 206, 314, 33, + 167, 139, 88, 204, + -235, 316, -60, -25, + -8, -150, -312, 201, + -36, 292, 61, -104, + -40, 174, -162, 42, + -21, 402, -29, -351, + 21, 152, -360, -93, + 57, 191, 212, -196, + 76, 158, -21, -69, + -328, -185, 331, 119, + -53, 285, 56, 337, + -107, -24, 405, 29, + -18, 137, 272, 277, + -255, 22, 173, -191, + 295, 322, 325, 302, + 21, -27, 332, -178, + 119, 13, 271, 129, + -455, -180, 116, -191, + -227, 62, -148, 524, + -176, -287, 282, -157, + -243, 13, 199, 430, + -59, -49, 115, -365, + 72, -172, -137, 93, + -138, -126, 141, -84, + 5, -124, 38, -20, + -258, 311, 601, 213, + 94, 130, -61, 502, + -1, -157, 485, 313, + 146, -74, 158, 345, + 276, 135, 280, -57, + 490, 252, 99, 43, + 267, -74, 429, 105, + 278, -23, 119, 94, + -542, 488, 257, -115, + -84, -244, -438, 478, + -113, -545, 387, 101, + -95, -306, 111, 498, + 95, 166, 22, -301, + 420, -15, -58, -78, + 270, 29, 122, -282, + 160, -240, 50, -38 }; /*-------------------------------------------------------------------* @@ -10229,70 +10229,70 @@ const Word16 dico22_isf_36b_fx[] = /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ const Word16 dico23_isf_36b_fx[] = {/*Qlog2(2.56)*/ - 81, -18, 68, -27, -122, -280, -4, - 45, -177, 209, -30, -136, -74, 131, - -44, 101, -75, -88, -48, -137, -54, - -245, -28, 63, -18, -112, -103, 58, - -79, -6, 220, -65, 114, -35, -50, - 109, -65, 143, -114, 129, 76, 125, - 166, 90, -61, -242, 186, -74, -43, - -46, -92, 49, -227, 24, -155, 39, - 67, 85, 99, -42, 53, -184, -281, - 142, -122, 0, 21, -142, -15, -17, - 223, 92, -21, -48, -82, -14, -167, - 51, -37, -243, -30, -90, 18, -56, - 54, 105, 74, 86, 69, 13, -101, - 196, 72, -89, 43, 65, 19, 39, - 121, 34, 131, -82, 25, 213, -156, - 101, -102, -136, -21, 57, 214, 22, - 36, -124, 205, 204, 58, -156, -83, - 83, -117, 137, 137, 85, 116, 44, - -92, -148, -68, 11, -102, -197, -220, - -76, -185, -58, 132, -26, -183, 85, - -7, -31, -2, 23, 205, -151, 10, - -27, -37, -5, -18, 292, 131, 1, - 117, -168, 9, -93, 80, -59, -125, - -182, -244, 98, -24, 135, -22, 94, - 221, 97, 106, 42, 43, -160, 83, - 25, -64, -21, 6, 14, -15, 154, - 126, 15, -140, 150, -10, -207, -114, - 79, -63, -211, -70, -28, -217, 165, - 46, 38, -22, 281, 132, -62, 109, - 112, 54, -112, -93, 208, 27, 296, - 115, 10, -147, 41, 216, 42, -276, - 50, -115, -254, 167, 117, -2, 61, - 17, 144, 34, -72, -186, -150, 272, - -29, -66, -89, -95, -149, 129, 251, - 122, 0, -50, -234, -91, 36, 26, - -105, -102, -88, -121, -236, -7, -11, - -204, 109, 5, -191, 105, -15, 163, - -80, 32, -24, -209, 41, 294, 70, - -106, -94, -204, -118, 120, -50, -37, - -82, -241, 46, -131, -29, 150, -55, - 33, 155, 120, -89, -8, 7, 62, - 213, 82, 61, 18, -161, 144, 152, - 30, 131, 65, -87, -255, -17, -107, - -8, 85, -64, 51, -162, 223, -53, - -134, 261, 69, -56, 218, 72, -111, - 2, 155, -113, -87, 49, 85, -28, - -163, 42, -1, -196, 7, 39, -245, - 14, -137, -79, 11, -160, 202, -293, - -94, 33, 208, 100, 56, -44, 326, - -78, -41, 232, 13, -142, 227, 80, - -16, -87, 201, 33, -133, 15, -183, - -58, -192, -47, 184, -128, 133, 99, - -205, 11, -155, 78, 52, 72, 141, - -246, 26, 99, 151, 59, 115, -64, - -79, -47, -16, -14, 6, 47, -43, - -72, -178, -27, 162, 112, 43, -174, - -175, 238, 186, 71, -54, -188, -76, - -225, 233, 39, -39, -158, 122, 44, - -26, 43, 84, 130, -93, -51, 22, - 3, 92, -150, 136, -182, -57, 97, - -131, 179, -78, 80, 91, -165, 90, - -2, 148, 15, 130, 65, 175, 117, - -138, 114, -137, 132, 3, -10, -186, - 140, -4, -37, 254, -62, 92, -109 + 81, -18, 68, -27, -122, -280, -4, + 45, -177, 209, -30, -136, -74, 131, + -44, 101, -75, -88, -48, -137, -54, + -245, -28, 63, -18, -112, -103, 58, + -79, -6, 220, -65, 114, -35, -50, + 109, -65, 143, -114, 129, 76, 125, + 166, 90, -61, -242, 186, -74, -43, + -46, -92, 49, -227, 24, -155, 39, + 67, 85, 99, -42, 53, -184, -281, + 142, -122, 0, 21, -142, -15, -17, + 223, 92, -21, -48, -82, -14, -167, + 51, -37, -243, -30, -90, 18, -56, + 54, 105, 74, 86, 69, 13, -101, + 196, 72, -89, 43, 65, 19, 39, + 121, 34, 131, -82, 25, 213, -156, + 101, -102, -136, -21, 57, 214, 22, + 36, -124, 205, 204, 58, -156, -83, + 83, -117, 137, 137, 85, 116, 44, + -92, -148, -68, 11, -102, -197, -220, + -76, -185, -58, 132, -26, -183, 85, + -7, -31, -2, 23, 205, -151, 10, + -27, -37, -5, -18, 292, 131, 1, + 117, -168, 9, -93, 80, -59, -125, + -182, -244, 98, -24, 135, -22, 94, + 221, 97, 106, 42, 43, -160, 83, + 25, -64, -21, 6, 14, -15, 154, + 126, 15, -140, 150, -10, -207, -114, + 79, -63, -211, -70, -28, -217, 165, + 46, 38, -22, 281, 132, -62, 109, + 112, 54, -112, -93, 208, 27, 296, + 115, 10, -147, 41, 216, 42, -276, + 50, -115, -254, 167, 117, -2, 61, + 17, 144, 34, -72, -186, -150, 272, + -29, -66, -89, -95, -149, 129, 251, + 122, 0, -50, -234, -91, 36, 26, + -105, -102, -88, -121, -236, -7, -11, + -204, 109, 5, -191, 105, -15, 163, + -80, 32, -24, -209, 41, 294, 70, + -106, -94, -204, -118, 120, -50, -37, + -82, -241, 46, -131, -29, 150, -55, + 33, 155, 120, -89, -8, 7, 62, + 213, 82, 61, 18, -161, 144, 152, + 30, 131, 65, -87, -255, -17, -107, + -8, 85, -64, 51, -162, 223, -53, + -134, 261, 69, -56, 218, 72, -111, + 2, 155, -113, -87, 49, 85, -28, + -163, 42, -1, -196, 7, 39, -245, + 14, -137, -79, 11, -160, 202, -293, + -94, 33, 208, 100, 56, -44, 326, + -78, -41, 232, 13, -142, 227, 80, + -16, -87, 201, 33, -133, 15, -183, + -58, -192, -47, 184, -128, 133, 99, + -205, 11, -155, 78, 52, 72, 141, + -246, 26, 99, 151, 59, 115, -64, + -79, -47, -16, -14, 6, 47, -43, + -72, -178, -27, 162, 112, 43, -174, + -175, 238, 186, 71, -54, -188, -76, + -225, 233, 39, -39, -158, 122, 44, + -26, 43, 84, 130, -93, -51, 22, + 3, 92, -150, 136, -182, -57, 97, + -131, 179, -78, 80, 91, -165, 90, + -2, 148, 15, 130, 65, 175, 117, + -138, 114, -137, 132, 3, -10, -186, + 140, -4, -37, 254, -62, 92, -109 }; /*-------------------------------------------------------------------* @@ -10314,70 +10314,70 @@ const Word16 dico23_isf_36b_fx[] = /* ISF codebook for SID frames - 28b, 1st split */ const Word16 dico1_ns_28b_fx[] = {/*Qlog2(2.56)*/ - -269, -673, - -222, -537, - -233, -430, - -138, -451, - -212, -331, - -192, -241, - -87, -231, - -191, -128, - -70, -106, - -164, -6, - 74, -179, - 27, -33, - -102, 74, - -162, 115, - -94, 172, - -6, 130, - -143, 234, - 14, 218, - -65, 270, - 88, 182, - -124, 341, - -44, 381, - 38, 335, - 117, 274, - -112, 454, - 74, 431, - -5, 488, - 175, 384, - -83, 561, - 122, 529, - 21, 601, - 229, 481, - 231, 303, - 226, 608, - 300, 372, - 210, 187, - 306, 265, - 328, 473, - 382, 331, - 371, 132, - 139, 58, - 365, 21, - 250, -82, - 443, 218, - 483, 110, - 426, 415, - 579, 222, - 518, 333, - 573, 448, - 455, 529, - 685, 329, - 332, 580, - 595, 593, - 468, 645, - 762, 517, - 326, 709, - 485, 793, - 130, 684, - 671, 737, - 354, 876, - 88, 806, - -65, 706, - -35, 1016, - 266, 1123 + -269, -673, + -222, -537, + -233, -430, + -138, -451, + -212, -331, + -192, -241, + -87, -231, + -191, -128, + -70, -106, + -164, -6, + 74, -179, + 27, -33, + -102, 74, + -162, 115, + -94, 172, + -6, 130, + -143, 234, + 14, 218, + -65, 270, + 88, 182, + -124, 341, + -44, 381, + 38, 335, + 117, 274, + -112, 454, + 74, 431, + -5, 488, + 175, 384, + -83, 561, + 122, 529, + 21, 601, + 229, 481, + 231, 303, + 226, 608, + 300, 372, + 210, 187, + 306, 265, + 328, 473, + 382, 331, + 371, 132, + 139, 58, + 365, 21, + 250, -82, + 443, 218, + 483, 110, + 426, 415, + 579, 222, + 518, 333, + 573, 448, + 455, 529, + 685, 329, + 332, 580, + 595, 593, + 468, 645, + 762, 517, + 326, 709, + 485, 793, + 130, 684, + 671, 737, + 354, 876, + 88, 806, + -65, 706, + -35, 1016, + 266, 1123 }; /*-------------------------------------------------------------------* @@ -10387,70 +10387,70 @@ const Word16 dico1_ns_28b_fx[] = /* ISF codebook for SID frames - 28b, 2nd spilt */ const Word16 dico2_ns_28b_fx[] = {/*Qlog2(2.56)*/ - -824, -884, -949, - -805, -456, -418, - -442, -438, -541, - -217, -578, -793, - -168, -444, -582, - -287, -492, -274, - -552, -297, -300, - -163, -333, -358, - -370, -232, -232, - -175, -358, -159, - -381, -21, -357, - -184, -159, -162, - -53, -191, -280, - 18, -267, -215, - -138, 61, -283, - 71, -95, -294, - 13, -156, -546, - 0, -83, -79, - 44, 97, -316, - 178, -52, -213, - 222, -261, -422, - 237, -118, -44, - 141, 145, -132, - 363, 81, -287, - 213, 65, 34, - -107, 94, -5, - 91, -29, 126, - -355, 51, -41, - -219, -76, 145, - -63, 100, 244, - -719, 44, 27, - -572, -124, 155, - -423, 133, 315, - -917, 71, 224, - -268, 318, 131, - -93, -190, 420, - -97, 122, 491, - -79, 317, 355, - 130, 100, 325, - 86, -293, 210, - 133, 258, 161, - 176, -73, 465, - 195, 300, 384, - 348, 22, 221, - 376, 183, 409, - 377, 286, 202, - 242, 213, 659, - 257, 565, 248, - 344, 408, -76, - 405, 440, 509, - 612, 385, 379, - 536, 607, 216, - -56, 582, 192, - 100, 517, 567, - -365, 448, 445, - 728, 347, 10, - 505, 357, 759, - 636, 582, 658, - 335, 517, 852, - 378, 809, 572, - -195, 878, 829, - 529, 707, 987, - 918, 726, 392, - 1250, 997, 1063 + -824, -884, -949, + -805, -456, -418, + -442, -438, -541, + -217, -578, -793, + -168, -444, -582, + -287, -492, -274, + -552, -297, -300, + -163, -333, -358, + -370, -232, -232, + -175, -358, -159, + -381, -21, -357, + -184, -159, -162, + -53, -191, -280, + 18, -267, -215, + -138, 61, -283, + 71, -95, -294, + 13, -156, -546, + 0, -83, -79, + 44, 97, -316, + 178, -52, -213, + 222, -261, -422, + 237, -118, -44, + 141, 145, -132, + 363, 81, -287, + 213, 65, 34, + -107, 94, -5, + 91, -29, 126, + -355, 51, -41, + -219, -76, 145, + -63, 100, 244, + -719, 44, 27, + -572, -124, 155, + -423, 133, 315, + -917, 71, 224, + -268, 318, 131, + -93, -190, 420, + -97, 122, 491, + -79, 317, 355, + 130, 100, 325, + 86, -293, 210, + 133, 258, 161, + 176, -73, 465, + 195, 300, 384, + 348, 22, 221, + 376, 183, 409, + 377, 286, 202, + 242, 213, 659, + 257, 565, 248, + 344, 408, -76, + 405, 440, 509, + 612, 385, 379, + 536, 607, 216, + -56, 582, 192, + 100, 517, 567, + -365, 448, 445, + 728, 347, 10, + 505, 357, 759, + 636, 582, 658, + 335, 517, 852, + 378, 809, 572, + -195, 878, 829, + 529, 707, 987, + 918, 726, 392, + 1250, 997, 1063 }; /*-------------------------------------------------------------------* @@ -10460,70 +10460,70 @@ const Word16 dico2_ns_28b_fx[] = /* ISF codebook for SID frames - 28b, 3rd spilt */ const Word16 dico3_ns_28b_fx[] = {/*Qlog2(2.56)*/ - -805, -838, -774, - -522, -627, -828, - -477, -486, -603, - -295, -481, -634, - -366, -384, -393, - -186, -414, -396, - -237, -394, -106, - -252, -202, -275, - -61, -177, -442, - -84, -198, -199, - -179, -125, -31, - -72, -47, -163, - -298, -220, 215, - -64, -168, 251, - -133, 156, -59, - -30, -2, 127, - 54, 66, -61, - -233, 21, 251, - 209, -50, 32, - 33, 194, 136, - -117, -18, 475, - 202, 46, 309, - 256, 185, 53, - 35, 200, 390, - 200, 263, 242, - -216, 302, 294, - 128, 358, 0, - 19, 431, 287, - 224, 447, 280, - 367, 165, 213, - 397, 314, 319, - 383, 379, 75, - 277, 325, 462, - 394, 505, 334, - 251, 98, -213, - 450, 153, 448, - 565, 226, 76, - 470, 383, 502, - 635, 390, 278, - 237, 135, 620, - 342, 401, 649, - 331, 551, 518, - 130, 418, 592, - 531, 306, 737, - 729, 389, 580, - 497, 557, 699, - 296, 383, 874, - 283, 624, 759, - 126, 622, 476, - 559, 595, 472, - 382, 770, 616, - 719, 613, 745, - 540, 639, 928, - 517, 826, 801, - 684, 811, 604, - 752, 786, 857, - 933, 661, 350, - 694, 450, 1061, - 562, 911, 1051, - 824, 813, 1104, - 758, 1047, 882, - 1140, 917, 889, - 1039, 1246, 1426, - 1483, 1666, 1876 + -805, -838, -774, + -522, -627, -828, + -477, -486, -603, + -295, -481, -634, + -366, -384, -393, + -186, -414, -396, + -237, -394, -106, + -252, -202, -275, + -61, -177, -442, + -84, -198, -199, + -179, -125, -31, + -72, -47, -163, + -298, -220, 215, + -64, -168, 251, + -133, 156, -59, + -30, -2, 127, + 54, 66, -61, + -233, 21, 251, + 209, -50, 32, + 33, 194, 136, + -117, -18, 475, + 202, 46, 309, + 256, 185, 53, + 35, 200, 390, + 200, 263, 242, + -216, 302, 294, + 128, 358, 0, + 19, 431, 287, + 224, 447, 280, + 367, 165, 213, + 397, 314, 319, + 383, 379, 75, + 277, 325, 462, + 394, 505, 334, + 251, 98, -213, + 450, 153, 448, + 565, 226, 76, + 470, 383, 502, + 635, 390, 278, + 237, 135, 620, + 342, 401, 649, + 331, 551, 518, + 130, 418, 592, + 531, 306, 737, + 729, 389, 580, + 497, 557, 699, + 296, 383, 874, + 283, 624, 759, + 126, 622, 476, + 559, 595, 472, + 382, 770, 616, + 719, 613, 745, + 540, 639, 928, + 517, 826, 801, + 684, 811, 604, + 752, 786, 857, + 933, 661, 350, + 694, 450, 1061, + 562, 911, 1051, + 824, 813, 1104, + 758, 1047, 882, + 1140, 917, 889, + 1039, 1246, 1426, + 1483, 1666, 1876 }; /*-------------------------------------------------------------------* @@ -10533,38 +10533,38 @@ const Word16 dico3_ns_28b_fx[] = /* ISF codebook for SID frames - 28b, 4th spilt */ const Word16 dico4_ns_28b_fx[] = {/*Qlog2(2.56)*/ - -776, -854, -891, -920, - -552, -610, -663, -741, - -321, -370, -476, -565, - 274, -160, -456, 201, - 265, 67, -160, -306, - -8, -210, 79, 272, - 163, 236, 307, 308, - 578, 317, 64, 298, - -9, 197, 342, 620, - 343, 232, 314, 622, - 173, 149, 548, 527, - 356, 370, 481, 376, - 135, 444, 488, 556, - 391, 471, 487, 653, - 228, 424, 576, 835, - 422, 372, 722, 682, - 295, 673, 693, 635, - 539, 596, 590, 449, - 475, 618, 659, 818, - 735, 517, 491, 673, - 602, 346, 257, 877, - 625, 635, 849, 720, - 727, 818, 698, 595, - 653, 481, 690, 1139, - 814, 762, 704, 908, - 507, 747, 898, 936, - 848, 855, 924, 785, - 646, 1037, 882, 795, - 772, 845, 1024, 1151, - 1133, 983, 818, 921, - 940, 1068, 1252, 1302, - 1588, 1767, 1718, 1513 + -776, -854, -891, -920, + -552, -610, -663, -741, + -321, -370, -476, -565, + 274, -160, -456, 201, + 265, 67, -160, -306, + -8, -210, 79, 272, + 163, 236, 307, 308, + 578, 317, 64, 298, + -9, 197, 342, 620, + 343, 232, 314, 622, + 173, 149, 548, 527, + 356, 370, 481, 376, + 135, 444, 488, 556, + 391, 471, 487, 653, + 228, 424, 576, 835, + 422, 372, 722, 682, + 295, 673, 693, 635, + 539, 596, 590, 449, + 475, 618, 659, 818, + 735, 517, 491, 673, + 602, 346, 257, 877, + 625, 635, 849, 720, + 727, 818, 698, 595, + 653, 481, 690, 1139, + 814, 762, 704, 908, + 507, 747, 898, 936, + 848, 855, 924, 785, + 646, 1037, 882, 795, + 772, 845, 1024, 1151, + 1133, 983, 818, 921, + 940, 1068, 1252, 1302, + 1588, 1767, 1718, 1513 }; /*-------------------------------------------------------------------* @@ -10574,38 +10574,38 @@ const Word16 dico4_ns_28b_fx[] = /* ISF codebook for SID frames - 28b, 5th spilt */ const Word16 dico5_ns_28b_fx[] = {/*Qlog2(2.56)*/ - -810, -879, -945, -254, - 248, 184, 671, 128, - 288, 703, 918, 99, - 658, 558, 662, 219, - 552, 585, 910, 208, - 559, 804, 759, 119, - 606, 774, 921, -139, - 782, 761, 748, 208, - 756, 708, 983, 56, - 544, 864, 1010, 152, - 737, 698, 987, 299, - 771, 924, 879, 103, - 536, 785, 961, 405, - 667, 916, 801, 328, - 738, 705, 773, 439, - 823, 871, 992, 355, - 640, 1004, 1052, 369, - 724, 822, 949, 597, - 415, 655, 729, 482, - 1009, 896, 793, 363, - 908, 803, 687, -25, - 1016, 838, 1011, 189, - 947, 1112, 942, 222, - 914, 1049, 981, 527, - 956, 987, 1011, -120, - 781, 1049, 1121, 92, - 1178, 1053, 884, 47, - 1123, 1059, 1182, 118, - 933, 972, 1277, 357, - 1109, 918, 1101, 503, - 1039, 1286, 1220, 317, - 1351, 1207, 1010, 326 + -810, -879, -945, -254, + 248, 184, 671, 128, + 288, 703, 918, 99, + 658, 558, 662, 219, + 552, 585, 910, 208, + 559, 804, 759, 119, + 606, 774, 921, -139, + 782, 761, 748, 208, + 756, 708, 983, 56, + 544, 864, 1010, 152, + 737, 698, 987, 299, + 771, 924, 879, 103, + 536, 785, 961, 405, + 667, 916, 801, 328, + 738, 705, 773, 439, + 823, 871, 992, 355, + 640, 1004, 1052, 369, + 724, 822, 949, 597, + 415, 655, 729, 482, + 1009, 896, 793, 363, + 908, 803, 687, -25, + 1016, 838, 1011, 189, + 947, 1112, 942, 222, + 914, 1049, 981, 527, + 956, 987, 1011, -120, + 781, 1049, 1121, 92, + 1178, 1053, 884, 47, + 1123, 1059, 1182, 118, + 933, 972, 1277, 357, + 1109, 918, 1101, 503, + 1039, 1286, 1220, 317, + 1351, 1207, 1010, 326 }; /*1.28f Q1*/ const Word16 means_nb_31bits_ma_lsf[16] = { 861 /*336.3281f*1.28f Q1*/, 1360 /*531.2500f*1.28f Q1*/, 2270 /*886.7188f*1.28f Q1*/, 3243 /*1266.7969f*1.28f Q1*/, 4171 /*1629.2969f*1.28f Q1*/, 5052 /*1973.4375f*1.28f Q1*/, 6012 /*2348.4375f*1.28f Q1*/, 6776 /*2646.8750f*1.28f Q1*/, 7676 /*2998.4375f*1.28f Q1*/, 8428 /*3292.1875f*1.28f Q1*/, 9194 /*3591.4062f*1.28f Q1*/, 9744 /*3806.2500f*1.28f Q1*/, 10580 /*4132.8125f*1.28f Q1*/, 11911 /*4652.7344f*1.28f Q1*/, 13440 /*5250.0000f*1.28f Q1*/, 15061 /*5883.2031f*1.28f Q1*/ }; @@ -10655,7 +10655,7 @@ const lsp_unw_triplet p16_gamma0_94to1[16] = /* Q14 */ }; -const Word16 dico_lsf_abs_8b[256 * M] = /*14Q1*1.28*/ +const Word16 dico_lsf_abs_8b[256 * M] = /*14Q1*1.28*/ { 966, 1761, 2937, 3740, 4574, 5488, 6457, 7398, 8355, 9289, 10254, 11211, 12247, 13202, 14221, 15172, 1540, 2731, 3544, 4232, 5065, 5917, 6846, 7707, 8602, 9538, 10479, 11445, 12439, 13339, 14332, 15243, @@ -11209,7 +11209,7 @@ const Word16 lsf_cdk_wb_vc_stg3[] = /* 14Q1*1.28 */ 13, 12, 1888, 3621, 3935, 4000, 3607, 2932, 2128 }; -const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = /* 14Q1*1.28 */ +const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = /* 14Q1*1.28 */ { { { lsf_cdk_wb_gc_stg1, lsf_cdk_wb_gc_stg2, lsf_cdk_wb_gc_stg3 }, @@ -11221,12 +11221,12 @@ const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = /* 14Q1*1.28 */ } }; -const Word16 lsf_numbits[TCXLPC_NUMSTAGES] = { 5, 4, 4 }; // Q0 +const Word16 lsf_numbits[TCXLPC_NUMSTAGES] = { 5, 4, 4 }; // Q0 -const Word16 lsf_dims_ivas[TCXLPC_NUMSTAGES] = { 16, 6, 10 }; // Q0 -const Word16 lsf_offs_ivas[TCXLPC_NUMSTAGES] = { 0, 0, 6 }; // Q0 -const Word16 lsf_dims[TCXLPC_NUMSTAGES] = { 16, 8, 12 }; // Q0 -const Word16 lsf_offs[TCXLPC_NUMSTAGES] = { 0, 0, 4 }; // Q0 +const Word16 lsf_dims_ivas[TCXLPC_NUMSTAGES] = { 16, 6, 10 }; // Q0 +const Word16 lsf_offs_ivas[TCXLPC_NUMSTAGES] = { 0, 0, 6 }; // Q0 +const Word16 lsf_dims[TCXLPC_NUMSTAGES] = { 16, 8, 12 }; // Q0 +const Word16 lsf_offs[TCXLPC_NUMSTAGES] = { 0, 0, 4 }; // Q0 const Word16 lsf_ind_cdk_nb_gc_stg4[] = /* 14Q1*1.28 */ @@ -11258,17 +11258,17 @@ const Word16 lsf_ind_cdk_wb_vc_stg4[] = /* 14Q1*1.28 */ 2256, 2704, 0 }; -const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES] = /* 14Q1*1.28 */ +const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES] = /* 14Q1*1.28 */ { { { lsf_ind_cdk_wb_gc_stg4 }, { lsf_ind_cdk_wb_vc_stg4 } }, { { lsf_ind_cdk_nb_gc_stg4 }, { lsf_ind_cdk_nb_vc_stg4 } } }; -const Word16 lsf_ind_numbits[TCXLPC_IND_NUMSTAGES] = { 2 }; // Q0 +const Word16 lsf_ind_numbits[TCXLPC_IND_NUMSTAGES] = { 2 }; // Q0 -const Word16 lsf_ind_dims_ivas[TCXLPC_IND_NUMSTAGES] = { 2 }; // Q0 -const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES] = { 4 }; // Q0 -const Word16 lsf_ind_offs[TCXLPC_IND_NUMSTAGES] = { 0 }; // Q0 +const Word16 lsf_ind_dims_ivas[TCXLPC_IND_NUMSTAGES] = { 2 }; // Q0 +const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES] = { 4 }; // Q0 +const Word16 lsf_ind_offs[TCXLPC_IND_NUMSTAGES] = { 0 }; // Q0 const Word16 min_distance_thr[2][2] = /* 14Q1*1.28 */ { @@ -11563,22 +11563,22 @@ const Word16 means_swb_cleanspeech_lsf32k0[16] = { 757, 1855, 2862, 3798, 4705, /* An 16-by-1 matrix */ -const Word16 SVWB2_Ave_fx[16] = { 998, 1488, 2682, 3823, 5084, 6305, 7485, 8686, 9861, 11004, 12339, 13664, 15088, 16330, 17663, 18754 }; // Q2.56 +const Word16 SVWB2_Ave_fx[16] = { 998, 1488, 2682, 3823, 5084, 6305, 7485, 8686, 9861, 11004, 12339, 13664, 15088, 16330, 17663, 18754 }; // Q2.56 /* An 16-by-1 matrix */ const Word16 IANB_Ave_fx[16] = { 726, 1433, 2493, 3408, 4340, 5215, 6103, 6947, 7772, 8536, 9252, 10012, 10909, 12427, 13997, 15193 -}; // Q2.56 +}; // Q2.56 /* An 16-by-1 matrix */ const Word16 IAWB_Ave_fx[16] = { 577, 1350, 2526, 3535, 4539, 5504, 6497, 7460, 8445, 9396, 10371, 11319, 12307, 13268, 14249, 15207 -}; // Q2.56 +}; // Q2.56 /* An 16-by-1 matrix */ const Word16 IAWB2_Ave_fx[16] = { 731, 1777, 3194, 4386, 5629, 6806, 8012, 9164, 10329, 11469, 12731, 14037, 15326, 16538, 17801, 18927 -}; // Q2.56 +}; // Q2.56 /* Length 16 vector in Scale = 2.56f */ const Word16 UVNB_Ave_fx[16] = { 1018, 1764, 2856, 3751, 4611, 5410, 6233, 6961, 7685, 8304, 8859, 9325, 9977, 11741, 13699, 15074 }; /* Length 16 vector in Scale = 2.56f */ @@ -11737,7 +11737,7 @@ const Word16 CB_lsf[] = 10, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ 13 /* Mode 18 : CNG, Safety net */ -}; // Q0 +}; // Q0 const Word16 CB_p_lsf[] = { @@ -11760,20 +11760,20 @@ const Word16 CB_p_lsf[] = -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 10, /* Mode 17 : AUDIO WB16k, Predictive */ 9, /* Mode 18 : GENERIC WB, MA Predictive */ -}; // Q0 +}; // Q0 const Word16 *const ModeMeans_fx[] = { IANB_Ave_fx, UVNB_Ave_fx, SVNB_Ave_fx, GENB_Ave_fx, TRNB_Ave_fx, AUNB_Ave_fx, IAWB_Ave_fx, UVWB_Ave_fx, SVWB_Ave_fx, GEWB_Ave_fx, TRWB_Ave_fx, AUWB_Ave_fx, IAWB2_Ave_fx, NULL, SVWB2_Ave_fx, GEWB2_Ave_fx, TRWB2_Ave_fx, AUWB2_Ave_fx -}; //Qlog2(2.56) +}; //Qlog2(2.56) const Word16 * const Predictors_fx[] = { Predictor6_fx, NULL, Predictor1_fx, Predictor3_fx, NULL, Predictor6_fx,Predictor5_fx, NULL, Predictor0_fx, Predictor2_fx, NULL, Predictor5_fx, Predictor7_fx, NULL, Predictor8_fx, Predictor4_fx, NULL, Predictor7_fx -}; // Q15 +}; // Q15 const Word16 CBsizes[] = { 1,2,4,8,16,32,64 -}; // Q0 +}; // Q0 const Word16 CBbits[] = @@ -11797,7 +11797,7 @@ const Word16 CBbits[] = 4, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ 4, /* Mode 18: CNG, Safety net */ -}; // Q0 +}; // Q0 const Word16 CBbits_p[] = @@ -11821,7 +11821,7 @@ const Word16 CBbits_p[] = -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 5, /* Mode 17 : AUDIO WB16k, Predictive */ 5, /* Mode 9 : GENERIC WB, Predictive */ -}; // Q0 +}; // Q0 @@ -11846,7 +11846,7 @@ const Word16 BitsVQ[]= 8, /* Mode 16 : TRANSITION WB16k, Safety net */ -1, /* Mode 17 : AUDIO WB16k, Safety net */ 4, /* Mode 18: CNG, Safety net */ -}; // Q0 +}; // Q0 const Word16 BitsVQ_p[]= @@ -11870,7 +11870,7 @@ const Word16 BitsVQ_p[]= -1, /* Mode 16 : TRANSITION WB16k, Predictive */ 5, /* Mode 17 : AUDIO WB16k, Predictive */ 5, /* Mode 18 : GENERIC WB, MA Predictive */ -}; // Q0 +}; // Q0 const Word16 predmode_tab_float[][6] = @@ -11887,7 +11887,7 @@ const Word16 predmode_tab[][6] = {1,1,2,2,0,2}, {1,-1,2,1,0,1}, {1,1,2,1,0,2} /* should check how is the cb for audio mode at 13.2*/ -}; // Q0 +}; // Q0 const Word16 SVNB_SN1_fx[256] = @@ -12513,7 +12513,7 @@ const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS] = /*Q1 */ {7, 3, 1, 0}, }; -const Word16 no_vals[NO_LEADERS]= {2,1,2,2,2,2,3,2,1,3,2,2,2,3,3,3,2,3,3,2,3,2,3,2,3,3,4,2,3,2,2,3,2,2,4,2,2,3,3,3,3,4,4,2,3,1,3,3,3}; // Q0 +const Word16 no_vals[NO_LEADERS]= {2,1,2,2,2,2,3,2,1,3,2,2,2,3,3,3,2,3,3,2,3,2,3,2,3,3,4,2,3,2,2,3,2,2,4,2,2,3,3,3,3,4,4,2,3,1,3,3,3}; // Q0 const Word16 no_vals_ind[NO_LEADERS][MAX_NO_VALS]= { @@ -12566,7 +12566,7 @@ const Word16 no_vals_ind[NO_LEADERS][MAX_NO_VALS]= {1,5,2,0}, {2,2,4,0}, {1,2,5,0} -}; // Q0 +}; // Q0 const Word16 C_VQ[LATTICE_DIM+1][LATTICE_DIM+1] = @@ -12584,16 +12584,16 @@ const Word16 C_VQ[LATTICE_DIM+1][LATTICE_DIM+1] = const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1] = { - {1,0,0,0,0,0,0,0,0}, - {1,1,0,0,0,0,0,0,0}, - {1,2,1,0,0,0,0,0,0}, - {1,3,3,1,0,0,0,0,0}, - {1,4,6,4,1,0,0,0,0}, - {1,5,10,10,5,1,0,0,0}, - {1,6,15,20,15,6,1,0,0}, - {1,7,21,35,35,21,7,1,0}, - {1,8,28,56,70,56,28,8,1} -}; // Q0 + {1,0,0,0,0,0,0,0,0}, + {1,1,0,0,0,0,0,0,0}, + {1,2,1,0,0,0,0,0,0}, + {1,3,3,1,0,0,0,0,0}, + {1,4,6,4,1,0,0,0,0}, + {1,5,10,10,5,1,0,0,0}, + {1,6,15,20,15,6,1,0,0}, + {1,7,21,35,35,21,7,1,0}, + {1,8,28,56,70,56,28,8,1} +}; // Q0 const UWord32 table_no_cv[] = //Q0 { @@ -12603,17 +12603,17 @@ const UWord32 table_no_cv[] = //Q0 }; //Q0 const Word32 table_no_cv_fx[] = { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, - 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, - 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000 - ,0 -}; // Q0 + 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, + 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000 + ,0 +}; // Q0 const Word16 pi0[] = { 28,1,70,8,8,28,168,28,1,280,28,56,8,56,420,56, 70, 56,420, 56, 280, 56, 168, 28, 560, 168,336,28,280,28,8, 280,70, 8, 1120, 8, 8, 280, 168, 56, 420, 336, 840, 28, 168, 1, 168, 420, 168 -}; // Q0 +}; // Q0 const Word16 pl_HQ_fx[] = /* Q1 vectors in first layers */ { @@ -12671,7 +12671,7 @@ const Word16 pl_HQ_fx[] = /* Q1 vectors in first layers */ * LSF quantization for CNG *----------------------------------------------------------------------------------*/ -const Word16 cng_sort[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1}; // Q0 +const Word16 cng_sort[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1}; // Q0 const Word16 perm_MSLVQ[][4] = @@ -12694,7 +12694,7 @@ const Word16 perm_MSLVQ[][4] = {6,11,7,12}, {6,11,7,12}, {6,11,7,12} -}; // Q0 +}; // Q0 const Word16 pl_par[] = /* 1 if even number of signs */ { @@ -12702,7 +12702,7 @@ const Word16 pl_par[] = /* 1 if even number of signs */ 0, -1, 1, 0, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 0, 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, 1, -1 -}; // Q0 +}; // Q0 const Word16 scales_fx[][6] =//Q11 { @@ -13183,7 +13183,7 @@ const Word16 inv_sigma_p_ivas_fx[][16] = {471, 409, 323, 325, 308, 295, 304, 290, 281, 280, 271, 262, 251, 255, 266, 312} }; -const Word8 leaders_short[][MAX_NO_SCALES] = // Q0 +const Word8 leaders_short[][MAX_NO_SCALES] = // Q0 {{ 0, 0, 0}, { 1, 0, 0}, { 15, 3, 3}, @@ -13461,7 +13461,7 @@ const Word8 leaders_short[][MAX_NO_SCALES] = // Q0 { 48, 48, 47}, { 48, 48, 48}}; -const UWord8 no_lead_idx[][2] = { // Q0 +const UWord8 no_lead_idx[][2] = { // Q0 { 1, 1}, { 4, 1}, { 41, 1}, @@ -13632,7 +13632,7 @@ const UWord8 no_lead_idx[][2] = { // Q0 { 55, 31}, { 81, 7}, }; -const UWord8 no_lead_p_idx[][2] = { // Q0 +const UWord8 no_lead_p_idx[][2] = { // Q0 { 5, 0}, { 3, 0}, { 41, 0}, @@ -13914,24 +13914,24 @@ const Word16 offset_in_lvq_mode_SN[][21] = const Word16 offset_in_lvq_mode_SN_fx[][21] = {//Q0 - {0}, /* I NB */ - {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ - {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ - {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */ - {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ - {0}, /* I WB */ - {0,1,1,1,2,3,3,3,3,3,3,4,4,4,5}, /* UV WB*/ - {0,1,1,1,2,3,3,3,4,5,6,7,8,9,9,10,11,12,12,12,13}, /* V WB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ - {0,1,1,1,2,3,3,4,5,5,5,6,6,7,8,9,10}, /* T WB */ - {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ - {0}, - {0}, - {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ - {0}, /* G 16k */ - {0,1}, /* T 16k */ - {0}, /*{0,0,0,0,0,0,0,0,0,0,1} */ /* A 16k */ + {0}, /* I NB */ + {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ + {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {0}, /* I WB */ + {0,1,1,1,2,3,3,3,3,3,3,4,4,4,5}, /* UV WB*/ + {0,1,1,1,2,3,3,3,4,5,6,7,8,9,9,10,11,12,12,12,13}, /* V WB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ + {0,1,1,1,2,3,3,4,5,5,5,6,6,7,8,9,10}, /* T WB */ + {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ + {0}, + {0}, + {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ + {0}, /* G 16k */ + {0,1}, /* T 16k */ + {0}, /*{0,0,0,0,0,0,0,0,0,0,1} */ /* A 16k */ }; const Word16 offset_in_lvq_mode_pred[][32] = @@ -13959,25 +13959,25 @@ const Word16 offset_in_lvq_mode_pred[][32] = const Word16 offset_in_lvq_mode_pred_fx[][32] = {//Q0 - {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ - {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ - {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ - {0}, /* T NB */ - {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ - {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I WB */ - {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV WB */ - {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V WB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ - {0}, /* T WB */ - {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ - {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */ - {0}, /* UV 16k */ - {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ - {0,0,0,0,0,0,1,2,3,4,5,6}, /* G 16k */ - {0}, /* T 16k */ - {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */ - {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ + {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ + {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I WB */ + {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV WB */ + {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V WB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ + {0}, /* T WB */ + {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */ + {0}, /* UV 16k */ + {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ + {0,0,0,0,0,0,1,2,3,4,5,6}, /* G 16k */ + {0}, /* T 16k */ + {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */ + {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/ }; /*-----------------------------------------------------------------* @@ -13987,16 +13987,16 @@ const Word16 NTRANS[4][NUM_STATE] = {{0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14}, {1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15}, /* indices of previous state of second branches */ {4,2,1,3,0,2,1,3,2,0,3,1,7,0,3,1}, /* indices of previous subset of first branch */ {2,0,3,6,2,0,3,1,0,2,1,3,0,2,1,5} /* indices of previous subset of second branch */ -}; // Q0 +}; // Q0 const Word16 NTRANS2[4][NUM_STATE] = {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7}, {8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}, {4,2,2,0,1,3,3,6,0,2,2,0,1,3,3,1}, {2,0,0,2,3,1,1,3,7,0,0,2,3,1,1,5} -}; // Q0 +}; // Q0 /* BC-TCQ Bit Allocations */ -const Word16 BC_TCVQ_BIT_ALLOC_40B[M/2+4] = {1, 4, 5,5,4,4, 2,2,2,2, 5,4 }; /*1+39bit Q0*/ +const Word16 BC_TCVQ_BIT_ALLOC_40B[M/2+4] = {1, 4, 5,5,4,4, 2,2,2,2, 5,4 }; /*1+39bit Q0*/ const Word16 FixBranch_tbl[4][4][N_STAGE_VQ - 4] = { @@ -14004,25 +14004,25 @@ const Word16 FixBranch_tbl[4][4][N_STAGE_VQ - 4] = {{0, 0, 1, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {1, 1, 1, 0}}, /* incase of initial state 4 */ {{0, 0, 0, 1}, {1, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 0, 1}}, /* incase of initial state 8 */ {{0, 0, 1, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}, {1, 1, 1, 1}} /* incase of initial state 12 */ -}; // Q0 +}; // Q0 /* Intra-Prediction */ const Word16 SN_IntraCoeff_fx[N_STAGE_VQ - 1][2][2] = /* Q15 */ { - {{-14822, 26501}, {-17180, 10012}}, + {{-14822, 26501}, {-17180, 10012}}, {{ 317, 19858}, { -432, 13799}}, {{ 4747, 22069}, { 2653, 19016}}, {{ 6823, 20747}, { 7077, 19154}}, {{ 1665, 25161}, { 2519, 13654}}, - {{ 166, 18043}, { -221, 9732}}, + {{ 166, 18043}, { -221, 9732}}, {{ -781, 20026}, { -5332, 18882}} }; const Word16 AR_IntraCoeff_fx[N_STAGE_VQ - 1][2][2] = /* Q15 */ { - {{-9584, 22162}, {-13849, 7127}}, - {{ 1604, 16400}, { 2861, 9414}}, + {{-9584, 22162}, {-13849, 7127}}, + {{ 1604, 16400}, { 2861, 9414}}, {{ 6537, 16475}, { 3498, 13792}}, {{ 7879, 14434}, { 7021, 12992}}, {{ 6329, 16215}, { 5200, 10052}}, @@ -14032,14 +14032,14 @@ const Word16 AR_IntraCoeff_fx[N_STAGE_VQ - 1][2][2] = /* Q15 */ const Word16 scale_ARSN_fx[M] = /* Q14 */ { - 29994, 30153, 29506, 28534, 28246, 28618, 26388, 27029, - 25726, 25474, 25797, 26540, 25613, 24968, 25880, 25584 + 29994, 30153, 29506, 28534, 28246, 28618, 26388, 27029, + 25726, 25474, 25797, 26540, 25613, 24968, 25880, 25584 }; const Word16 scale_inv_ARSN_fx[M] = /* Q15 */ { - 17898, 17806, 18196, 18815, 19005, 18760, 20342, 19864, - 20870, 21076, 20811, 20228, 20962, 21502, 20745, 20985 + 17898, 17806, 18196, 18815, 19005, 18760, 20342, 19864, + 20870, 21076, 20811, 20228, 20962, 21502, 20745, 20985 }; /* TCVQ Codebook */ @@ -14047,90 +14047,90 @@ const Word16 scale_inv_ARSN_fx[M] = /* Q15 */ const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2] = /* x2.65 */ {//Qlog2(2.56) { - {-435 , -434}, {-233 , 124}, {-381 , 44}, {-274 , -88}, {-332 , -224}, {-563 , -600}, {-332 , 134}, { 53 , -739}, - {-567 , 0}, { 149 , 316}, {-191 , 541}, {-123 , 317}, {-493 , -634}, {-528 , 268}, {-321 , -386}, {-432 , -220}, - {-244 , -230}, { -33 , 454}, {-188 , -642}, {-131 , -215}, {-676 , 263}, {-472 , -403}, {-312 , -159}, {-340 , 297}, - {-121 , -217}, { -6 , 241}, {-203 , -211}, {-126 , -15}, {-734 , -374}, {-458 , -6}, {-297 , -27}, {-307 , -553}, - {-177 , 3}, {-175 , -273}, { 63 , 363}, { 133 , 527}, {-133 , -185}, {-449 , -1206}, {-287 , -281}, {-131 , 869}, - {-100 , -105}, { -75 , -179}, {-141 , 131}, { -32 , 108}, { -81 , 161}, {-446 , -230}, {-283 , -884}, {-128 , -165}, - {-153 , -451}, {-177 , -114}, {-113 , -127}, {-223 , -355}, {-246 , -447}, {-396 , -705}, {-280 , 329}, { -37 , -64}, - {-118 , 208}, { -82 , 64}, {-339 , -367}, { -58 , -132}, {-458 , 644}, {-381 , -543}, {-272 , 557}, { 62 , 75}, - {-307 , -829}, { 310 , 445}, { 73 , -26}, { 95 , 219}, { 223 , 611}, { 279 , 195}, { 430 , 575}, { 424 , 221}, - { -25 , 2}, { 323 , 236}, {-100 , -310}, { 11 , -35}, { 83 , -3}, { 281 , 738}, { 495 , 393}, { 89 , 1284}, - { 32 , 136}, { 29 , 34}, { 491 , 575}, { 105 , -188}, { 15 , -440}, { 285 , 10}, { 516 , -105}, { 313 , 704}, - { -6 , -274}, { -62 , -64}, { -12 , -127}, { 170 , 2387}, { 162 , 196}, { 336 , 413}, { 543 , 210}, { 231 , -70}, - { -2 , 691}, { 98 , 134}, { 25 , 141}, { 261 , 305}, { 312 , -322}, { 336 , 228}, { 561 , 781}, { 766 , 514}, - { -14 , -117}, { 166 , 905}, { -50 , 1}, { 471 , 369}, { 345 , 247}, { 347 , -383}, { 561 , 1128}, { 513 , 1030}, - { 100 , -15}, { 185 , 70}, { 167 , 131}, { 122 , 36}, { 561 , 743}, { 401 , 111}, { 595 , -579}, { 674 , 215}, - { 191 , 189}, { 38 , -78}, { 428 , 0}, { 261 , 136}, { -29 , -99}, { 405 , 308}, { 614 , 574}, {1682 , 1704} + {-435 , -434}, {-233 , 124}, {-381 , 44}, {-274 , -88}, {-332 , -224}, {-563 , -600}, {-332 , 134}, { 53 , -739}, + {-567 , 0}, { 149 , 316}, {-191 , 541}, {-123 , 317}, {-493 , -634}, {-528 , 268}, {-321 , -386}, {-432 , -220}, + {-244 , -230}, { -33 , 454}, {-188 , -642}, {-131 , -215}, {-676 , 263}, {-472 , -403}, {-312 , -159}, {-340 , 297}, + {-121 , -217}, { -6 , 241}, {-203 , -211}, {-126 , -15}, {-734 , -374}, {-458 , -6}, {-297 , -27}, {-307 , -553}, + {-177 , 3}, {-175 , -273}, { 63 , 363}, { 133 , 527}, {-133 , -185}, {-449 , -1206}, {-287 , -281}, {-131 , 869}, + {-100 , -105}, { -75 , -179}, {-141 , 131}, { -32 , 108}, { -81 , 161}, {-446 , -230}, {-283 , -884}, {-128 , -165}, + {-153 , -451}, {-177 , -114}, {-113 , -127}, {-223 , -355}, {-246 , -447}, {-396 , -705}, {-280 , 329}, { -37 , -64}, + {-118 , 208}, { -82 , 64}, {-339 , -367}, { -58 , -132}, {-458 , 644}, {-381 , -543}, {-272 , 557}, { 62 , 75}, + {-307 , -829}, { 310 , 445}, { 73 , -26}, { 95 , 219}, { 223 , 611}, { 279 , 195}, { 430 , 575}, { 424 , 221}, + { -25 , 2}, { 323 , 236}, {-100 , -310}, { 11 , -35}, { 83 , -3}, { 281 , 738}, { 495 , 393}, { 89 , 1284}, + { 32 , 136}, { 29 , 34}, { 491 , 575}, { 105 , -188}, { 15 , -440}, { 285 , 10}, { 516 , -105}, { 313 , 704}, + { -6 , -274}, { -62 , -64}, { -12 , -127}, { 170 , 2387}, { 162 , 196}, { 336 , 413}, { 543 , 210}, { 231 , -70}, + { -2 , 691}, { 98 , 134}, { 25 , 141}, { 261 , 305}, { 312 , -322}, { 336 , 228}, { 561 , 781}, { 766 , 514}, + { -14 , -117}, { 166 , 905}, { -50 , 1}, { 471 , 369}, { 345 , 247}, { 347 , -383}, { 561 , 1128}, { 513 , 1030}, + { 100 , -15}, { 185 , 70}, { 167 , 131}, { 122 , 36}, { 561 , 743}, { 401 , 111}, { 595 , -579}, { 674 , 215}, + { 191 , 189}, { 38 , -78}, { 428 , 0}, { 261 , 136}, { -29 , -99}, { 405 , 308}, { 614 , 574}, {1682 , 1704} }, { - {-942 , -168}, {-262 , -361}, { -53 , -171}, {-245 , 472}, {-2145 , -2315}, {-1307 , 1261}, {-870 , -1940}, { -652 , -564}, - {-500 , 447}, {-578 , -198}, {-554 , 111}, { -98 , -84}, {-1315 , 0}, {-1229 , -1618}, {-868 , 230}, { -385 , 1061}, - {-768 , -998}, {-202 , -60}, {-283 , -197}, {-142 , -325}, { -558 , 755}, {-1217 , 456}, {-803 , 766}, { -982 , 743}, - {-415 , -357}, { -28 , 1054}, { 114 , -246}, { 81 , 732}, { -804 , -506}, {-1126 , -112}, {-797 , -132}, { -289 , -204}, - {-347 , -29}, { -37 , -259}, {-142 , -438}, {-249 , 87}, { -874 , 341}, {-1074 , -2635}, {-668 , -1552}, {-1140 , -764}, - {-245 , -513}, { -48 , 526}, { 14 , 395}, {-452 , -646}, { -441 , -969}, { -953 , -1284}, {-645 , -387}, { -736 , 111}, - {-163 , 305}, {-349 , 224}, {-225 , 736}, { 94 , -85}, { -302 , -549}, { -937 , -892}, {-605 , -1089}, { -64 , -101}, - {-161 , -211}, {-392 , -1299}, {-148 , 125}, { 14 , 131}, { -432 , -127}, { -920 , -510}, {-598 , -730}, { 85 , 154}, - { 25 , -155}, { -57 , 238}, { 471 , 276}, { 421 , 680}, { -173 , 316}, { 597 , 1805}, { 906 , -673}, { 538 , 450}, - {-267 , -805}, { 2 , -19}, { 222 , 219}, { 185 , 352}, { -33 , -178}, { 606 , 118}, { 959 , -70}, { 350 , -91}, - { -87 , 42}, { 727 , 905}, { 54 , 33}, { 316 , 44}, { 251 , 15}, { 610 , -122}, { 990 , 1436}, { 82 , 1480}, - { 181 , 535}, { 177 , 130}, { 700 , 565}, { 626 , 331}, { 279 , 551}, { 680 , 707}, {1012 , 727}, { 1057 , 766}, - { -13 , -396}, { 364 , 412}, { 442 , -181}, { 202 , -386}, { 565 , 1397}, { 740 , 2621}, {1080 , 361}, { 1118 , 191}, - { 81 , 266}, { 217 , -130}, { 349 , 1009}, { 678 , -476}, { 1361 , 878}, { 795 , 472}, {1267 , 1034}, { 1040 , 1255}, - { 351 , 201}, { -69 , -633}, { -36 , -1046}, { 808 , 30}, { 1300 , -198}, { 803 , 1026}, {1390 , -326}, { 2291 , 2479}, - { 166 , 13}, { 521 , 84}, { 255 , -717}, { 987 , 448}, { 777 , 220}, { 811 , 208}, {1395 , 2021}, { 1499 , 417} + {-942 , -168}, {-262 , -361}, { -53 , -171}, {-245 , 472}, {-2145 , -2315}, {-1307 , 1261}, {-870 , -1940}, { -652 , -564}, + {-500 , 447}, {-578 , -198}, {-554 , 111}, { -98 , -84}, {-1315 , 0}, {-1229 , -1618}, {-868 , 230}, { -385 , 1061}, + {-768 , -998}, {-202 , -60}, {-283 , -197}, {-142 , -325}, { -558 , 755}, {-1217 , 456}, {-803 , 766}, { -982 , 743}, + {-415 , -357}, { -28 , 1054}, { 114 , -246}, { 81 , 732}, { -804 , -506}, {-1126 , -112}, {-797 , -132}, { -289 , -204}, + {-347 , -29}, { -37 , -259}, {-142 , -438}, {-249 , 87}, { -874 , 341}, {-1074 , -2635}, {-668 , -1552}, {-1140 , -764}, + {-245 , -513}, { -48 , 526}, { 14 , 395}, {-452 , -646}, { -441 , -969}, { -953 , -1284}, {-645 , -387}, { -736 , 111}, + {-163 , 305}, {-349 , 224}, {-225 , 736}, { 94 , -85}, { -302 , -549}, { -937 , -892}, {-605 , -1089}, { -64 , -101}, + {-161 , -211}, {-392 , -1299}, {-148 , 125}, { 14 , 131}, { -432 , -127}, { -920 , -510}, {-598 , -730}, { 85 , 154}, + { 25 , -155}, { -57 , 238}, { 471 , 276}, { 421 , 680}, { -173 , 316}, { 597 , 1805}, { 906 , -673}, { 538 , 450}, + {-267 , -805}, { 2 , -19}, { 222 , 219}, { 185 , 352}, { -33 , -178}, { 606 , 118}, { 959 , -70}, { 350 , -91}, + { -87 , 42}, { 727 , 905}, { 54 , 33}, { 316 , 44}, { 251 , 15}, { 610 , -122}, { 990 , 1436}, { 82 , 1480}, + { 181 , 535}, { 177 , 130}, { 700 , 565}, { 626 , 331}, { 279 , 551}, { 680 , 707}, {1012 , 727}, { 1057 , 766}, + { -13 , -396}, { 364 , 412}, { 442 , -181}, { 202 , -386}, { 565 , 1397}, { 740 , 2621}, {1080 , 361}, { 1118 , 191}, + { 81 , 266}, { 217 , -130}, { 349 , 1009}, { 678 , -476}, { 1361 , 878}, { 795 , 472}, {1267 , 1034}, { 1040 , 1255}, + { 351 , 201}, { -69 , -633}, { -36 , -1046}, { 808 , 30}, { 1300 , -198}, { 803 , 1026}, {1390 , -326}, { 2291 , 2479}, + { 166 , 13}, { 521 , 84}, { 255 , -717}, { 987 , 448}, { 777 , 220}, { 811 , 208}, {1395 , 2021}, { 1499 , 417} } }; const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2] = {//Qlog2(2.56) { - {-357 , -53}, {-525 , 167}, {-232 , 255}, {-132 , -359}, {-940 , -221}, { -260 , -1296}, {-1197 , -455}, { -833 , 49}, - {-132 , -1}, {-401 , -280}, {-212 , -217}, {-194 , 92}, {-580 , -710}, { -862 , -750}, { -669 , 430}, { -521 , 719}, - {-620 , -454}, {-239 , 509}, { -15 , -575}, { 389 , 704}, {-890 , 518}, {-1154 , 84}, { -632 , -1023}, { -620 , -1263}, - {-268 , -470}, {-326 , -738}, { 44 , 635}, { 73 , 362}, {-226 , -22}, { -625 , -106}, { -720 , -114}, {-1114 , -1070}, - { 19 , -250}, { 83 , 99}, { 35 , -16}, { 263 , -316}, { 472 , 1096}, { -52 , -328}, { -249 , 971}, { 1387 , 876}, - { 10 , 203}, { 869 , 649}, { 225 , 170}, { 301 , 83}, {1256 , 482}, { 391 , -777}, { 1064 , -320}, { 52 , 1207}, - { 309 , 375}, { 469 , 226}, { 619 , 400}, { 60 , -93}, { 335 , 244}, { 316 , -65}, { -45 , -987}, { 648 , -294}, - { 218 , -66}, {-108 , -133}, { 500 , -19}, { 824 , 163}, { 483 , -443}, { 1297 , 240}, { 1000 , 1205}, { 623 , 1347} + {-357 , -53}, {-525 , 167}, {-232 , 255}, {-132 , -359}, {-940 , -221}, { -260 , -1296}, {-1197 , -455}, { -833 , 49}, + {-132 , -1}, {-401 , -280}, {-212 , -217}, {-194 , 92}, {-580 , -710}, { -862 , -750}, { -669 , 430}, { -521 , 719}, + {-620 , -454}, {-239 , 509}, { -15 , -575}, { 389 , 704}, {-890 , 518}, {-1154 , 84}, { -632 , -1023}, { -620 , -1263}, + {-268 , -470}, {-326 , -738}, { 44 , 635}, { 73 , 362}, {-226 , -22}, { -625 , -106}, { -720 , -114}, {-1114 , -1070}, + { 19 , -250}, { 83 , 99}, { 35 , -16}, { 263 , -316}, { 472 , 1096}, { -52 , -328}, { -249 , 971}, { 1387 , 876}, + { 10 , 203}, { 869 , 649}, { 225 , 170}, { 301 , 83}, {1256 , 482}, { 391 , -777}, { 1064 , -320}, { 52 , 1207}, + { 309 , 375}, { 469 , 226}, { 619 , 400}, { 60 , -93}, { 335 , 244}, { 316 , -65}, { -45 , -987}, { 648 , -294}, + { 218 , -66}, {-108 , -133}, { 500 , -19}, { 824 , 163}, { 483 , -443}, { 1297 , 240}, { 1000 , 1205}, { 623 , 1347} }, { - {-424 , -965}, { -46 , -194}, { 20 , 298}, {-333 , -278}, {-797 , -522}, {-868 , -60}, { -20 , -140}, {-1085 , -904}, - {-615 , -243}, {-367 , 22}, {-261 , -519}, {-111 , -27}, {-745 , 142}, {-484 , -1519}, { -329 , 13}, {-1077 , 92}, - {-529 , 218}, {-519 , -597}, {-276 , -72}, { -87 , -398}, { -51 , -1257}, {-291 , 409}, { -883 , 611}, { 176 , -401}, - {-134 , -245}, { 37 , 506}, { 23 , -10}, {-225 , 293}, {-913 , -1324}, {-174 , -290}, {-1086 , -386}, { -139 , -78}, - {-123 , 125}, { -26 , -738}, { 113 , -344}, { 175 , 182}, { 754 , -446}, {1207 , 529}, { 932 , 990}, { 136 , 122}, - { 267 , 327}, { 382 , -182}, { 718 , 471}, { 738 , 108}, { 158 , 130}, { 437 , 401}, { 358 , -667}, { 1380 , 836}, - { 184 , -17}, { 435 , 231}, { 403 , 63}, { 151 , -125}, {-109 , -237}, { 692 , -241}, { 1247 , 193}, { 885 , 324}, - {-283 , 661}, { 44 , 105}, { 156 , 911}, { 387 , 588}, { 690 , 1459}, { 664 , 1057}, { -38 , 1455}, { 645 , 909} + {-424 , -965}, { -46 , -194}, { 20 , 298}, {-333 , -278}, {-797 , -522}, {-868 , -60}, { -20 , -140}, {-1085 , -904}, + {-615 , -243}, {-367 , 22}, {-261 , -519}, {-111 , -27}, {-745 , 142}, {-484 , -1519}, { -329 , 13}, {-1077 , 92}, + {-529 , 218}, {-519 , -597}, {-276 , -72}, { -87 , -398}, { -51 , -1257}, {-291 , 409}, { -883 , 611}, { 176 , -401}, + {-134 , -245}, { 37 , 506}, { 23 , -10}, {-225 , 293}, {-913 , -1324}, {-174 , -290}, {-1086 , -386}, { -139 , -78}, + {-123 , 125}, { -26 , -738}, { 113 , -344}, { 175 , 182}, { 754 , -446}, {1207 , 529}, { 932 , 990}, { 136 , 122}, + { 267 , 327}, { 382 , -182}, { 718 , 471}, { 738 , 108}, { 158 , 130}, { 437 , 401}, { 358 , -667}, { 1380 , 836}, + { 184 , -17}, { 435 , 231}, { 403 , 63}, { 151 , -125}, {-109 , -237}, { 692 , -241}, { 1247 , 193}, { 885 , 324}, + {-283 , 661}, { 44 , 105}, { 156 , 911}, { 387 , 588}, { 690 , 1459}, { 664 , 1057}, { -38 , 1455}, { 645 , 909} } }; const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2] = {//Qlog2(2.56) { - {-487 , 9}, {-456 , -400}, { 96 , 451}, {-239 , 422}, {-685 , -1309}, { 68 , -709}, {-302 , -1185}, { 481 , -287}, - {-287 , -697}, {-194 , 73}, {-159 , -132}, {-161 , -312}, {-809 , 417}, {-860 , -926}, { -26 , -71}, {-1052 , -432}, - { 53 , 134}, { 106 , -140}, { 336 , -18}, { 404 , 735}, {-109 , -516}, { 719 , -65}, { -34 , 1336}, { -171 , 905}, - { 52 , -347}, { 359 , 266}, { 715 , 351}, { 100 , 133}, { 87 , 130}, { 975 , 999}, {1257 , 547}, { 738 , 1372} + {-487 , 9}, {-456 , -400}, { 96 , 451}, {-239 , 422}, {-685 , -1309}, { 68 , -709}, {-302 , -1185}, { 481 , -287}, + {-287 , -697}, {-194 , 73}, {-159 , -132}, {-161 , -312}, {-809 , 417}, {-860 , -926}, { -26 , -71}, {-1052 , -432}, + { 53 , 134}, { 106 , -140}, { 336 , -18}, { 404 , 735}, {-109 , -516}, { 719 , -65}, { -34 , 1336}, { -171 , 905}, + { 52 , -347}, { 359 , 266}, { 715 , 351}, { 100 , 133}, { 87 , 130}, { 975 , 999}, {1257 , 547}, { 738 , 1372} }, { - {-340 , -464}, {-216 , -779}, { 104 , -403}, { -92 , -221}, {-760 , -602}, {-914 , -811}, {-661 , -895}, {-1292 , -290}, - {-317 , 131}, {-575 , -154}, {-228 , -129}, {-257 , 487}, {-286 , -1354}, { -93 , -259}, {-798 , 179}, { -815 , -1368}, - { 215 , 570}, { -2 , 73}, { 545 , 167}, { 250 , 188}, { 76 , 48}, {-943 , 587}, { 379 , 1232}, { 1070 , 112}, - { 117 , -27}, { 389 , -142}, { 18 , 214}, { 735 , 581}, {1098 , 1244}, { 451 , 408}, {1482 , 650}, { -174 , 1160} + {-340 , -464}, {-216 , -779}, { 104 , -403}, { -92 , -221}, {-760 , -602}, {-914 , -811}, {-661 , -895}, {-1292 , -290}, + {-317 , 131}, {-575 , -154}, {-228 , -129}, {-257 , 487}, {-286 , -1354}, { -93 , -259}, {-798 , 179}, { -815 , -1368}, + { 215 , 570}, { -2 , 73}, { 545 , 167}, { 250 , 188}, { 76 , 48}, {-943 , 587}, { 379 , 1232}, { 1070 , 112}, + { 117 , -27}, { 389 , -142}, { 18 , 214}, { 735 , 581}, {1098 , 1244}, { 451 , 408}, {1482 , 650}, { -174 , 1160} }, { - {-256 , -485}, { -67 , 571}, { -5 , 161}, {-171 , 153}, {-1188 , -440}, {-1081 , 110}, {-641 , -921}, {-232 , -96}, - {-511 , 146}, {-288 , -93}, { 484 , 665}, {-610 , -366}, { -357 , -899}, { -861 , -1088}, { -78 , -105}, {-265 , -845}, - { 15 , 18}, { 79 , -383}, {-205 , -258}, { 306 , 264}, { 28 , 69}, { 34 , 65}, {1170 , 669}, { 133 , 74}, - { 521 , 183}, { 132 , 84}, { 362 , -90}, { 57 , -181}, { 894 , 456}, { 1147 , 742}, { 212 , 274}, { 891 , 262} + {-256 , -485}, { -67 , 571}, { -5 , 161}, {-171 , 153}, {-1188 , -440}, {-1081 , 110}, {-641 , -921}, {-232 , -96}, + {-511 , 146}, {-288 , -93}, { 484 , 665}, {-610 , -366}, { -357 , -899}, { -861 , -1088}, { -78 , -105}, {-265 , -845}, + { 15 , 18}, { 79 , -383}, {-205 , -258}, { 306 , 264}, { 28 , 69}, { 34 , 65}, {1170 , 669}, { 133 , 74}, + { 521 , 183}, { 132 , 84}, { 362 , -90}, { 57 , -181}, { 894 , 456}, { 1147 , 742}, { 212 , 274}, { 891 , 262} }, { - { 94 , 464}, { 8 , 138}, {-365 , -640}, {-399 , 172}, {-249 , -109}, { -94 , -316}, {-163 , -250}, {-598 , -704}, - {-185 , 36}, {-470 , -199}, { 65 , 241}, {-104 , -362}, {-220 , -801}, {-866 , -66}, {-931 , -400}, {-172 , -132}, - {-148 , -494}, { 465 , 251}, {-179 , -72}, { 439 , 287}, { 824 , 559}, { 33 , 134}, { 59 , 134}, { 88 , 146}, - { 186 , 43}, { 69 , -261}, { 267 , -96}, { 40 , 79}, { 84 , 130}, { 678 , 378}, { 811 , 448}, { 920 , 541} + { 94 , 464}, { 8 , 138}, {-365 , -640}, {-399 , 172}, {-249 , -109}, { -94 , -316}, {-163 , -250}, {-598 , -704}, + {-185 , 36}, {-470 , -199}, { 65 , 241}, {-104 , -362}, {-220 , -801}, {-866 , -66}, {-931 , -400}, {-172 , -132}, + {-148 , -494}, { 465 , 251}, {-179 , -72}, { 439 , 287}, { 824 , 559}, { 33 , 134}, { 59 , 134}, { 88 , 146}, + { 186 , 43}, { 69 , -261}, { 267 , -96}, { 40 , 79}, { 84 , 130}, { 678 , 378}, { 811 , 448}, { 920 , 541} } }; @@ -14138,155 +14138,155 @@ const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2] = const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2] = {//Qlog2(2.56) { - {-639 , 105}, {-488 , -449}, {-530 , -811}, {-419 , -634}, {-781 , -1061}, {-585 , 386}, {-501 , -737}, {-489 , -728}, - {-702 , -685}, {-510 , -762}, {-390 , -287}, {-379 , -379}, {-573 , -848}, {-583 , -778}, {-500 , -810}, {-671 , -420}, - {-516 , 802}, {-265 , -492}, {-523 , -568}, {-195 , 2882}, {-600 , -172}, {-568 , -869}, {-497 , 663}, {-643 , -929}, - {-346 , -378}, {-253 , -313}, {-418 , 595}, {-240 , -465}, {-424 , -546}, {-556 , -305}, {-497 , 2453}, {-451 , -235}, - {-452 , -670}, {-368 , -624}, {-379 , -662}, {-305 , -85}, {-549 , 399}, {-546 , -644}, {-484 , -426}, {-387 , -546}, - {-325 , -550}, {-229 , 118}, { -83 , 1004}, {-120 , 465}, {-289 , -222}, {-516 , 155}, {-480 , 1494}, {-415 , 138}, - {-419 , -100}, {-347 , 1091}, {-434 , 76}, {-138 , -291}, {-434 , -719}, {-514 , 945}, {-473 , -26}, {-144 , -320}, - {-376 , 1505}, {-329 , 374}, {-316 , -504}, { -58 , -6}, {-270 , -466}, {-507 , -540}, {-466 , -181}, {-256 , -518}, - {-196 , 726}, { -88 , -356}, {-186 , -394}, { 31 , -201}, { -77 , -319}, { 408 , 136}, { 630 , 680}, { 875 , 1365}, - {-200 , -190}, { 166 , 1289}, { 600 , 1085}, { 276 , 464}, { 567 , 1575}, { 425 , 278}, { 666 , 377}, {1209 , 2344}, - {-182 , -409}, { -95 , -141}, { 65 , 507}, { 127 , 212}, { 340 , 235}, { 481 , 408}, { 721 , 1203}, {1112 , 756}, - { 162 , 362}, { 138 , 753}, {-169 , -128}, { 187 , -32}, { 68 , -93}, { 528 , 2866}, { 786 , 789}, {1247 , 1468}, - {-476 , 2428}, { 20 , 133}, { 2 , -236}, { 426 , 799}, { 393 , 590}, { 532 , 1562}, { 807 , 534}, {1410 , 1051}, - { -14 , -263}, { 83 , -158}, { 158 , -38}, { 616 , 550}, { 845 , 543}, { 536 , 238}, { 912 , 1521}, {1635 , 1344}, - { 115 , -55}, { 263 , 87}, {-126 , 234}, { 376 , 191}, { 459 , 2644}, { 542 , 927}, { 941 , 948}, {1896 , 1528}, - { -19 , 1853}, { 455 , 366}, { 545 , 283}, { 831 , 835}, {1217 , 846}, { 560 , 542}, {1013 , 650}, {1905 , 2343} + {-639 , 105}, {-488 , -449}, {-530 , -811}, {-419 , -634}, {-781 , -1061}, {-585 , 386}, {-501 , -737}, {-489 , -728}, + {-702 , -685}, {-510 , -762}, {-390 , -287}, {-379 , -379}, {-573 , -848}, {-583 , -778}, {-500 , -810}, {-671 , -420}, + {-516 , 802}, {-265 , -492}, {-523 , -568}, {-195 , 2882}, {-600 , -172}, {-568 , -869}, {-497 , 663}, {-643 , -929}, + {-346 , -378}, {-253 , -313}, {-418 , 595}, {-240 , -465}, {-424 , -546}, {-556 , -305}, {-497 , 2453}, {-451 , -235}, + {-452 , -670}, {-368 , -624}, {-379 , -662}, {-305 , -85}, {-549 , 399}, {-546 , -644}, {-484 , -426}, {-387 , -546}, + {-325 , -550}, {-229 , 118}, { -83 , 1004}, {-120 , 465}, {-289 , -222}, {-516 , 155}, {-480 , 1494}, {-415 , 138}, + {-419 , -100}, {-347 , 1091}, {-434 , 76}, {-138 , -291}, {-434 , -719}, {-514 , 945}, {-473 , -26}, {-144 , -320}, + {-376 , 1505}, {-329 , 374}, {-316 , -504}, { -58 , -6}, {-270 , -466}, {-507 , -540}, {-466 , -181}, {-256 , -518}, + {-196 , 726}, { -88 , -356}, {-186 , -394}, { 31 , -201}, { -77 , -319}, { 408 , 136}, { 630 , 680}, { 875 , 1365}, + {-200 , -190}, { 166 , 1289}, { 600 , 1085}, { 276 , 464}, { 567 , 1575}, { 425 , 278}, { 666 , 377}, {1209 , 2344}, + {-182 , -409}, { -95 , -141}, { 65 , 507}, { 127 , 212}, { 340 , 235}, { 481 , 408}, { 721 , 1203}, {1112 , 756}, + { 162 , 362}, { 138 , 753}, {-169 , -128}, { 187 , -32}, { 68 , -93}, { 528 , 2866}, { 786 , 789}, {1247 , 1468}, + {-476 , 2428}, { 20 , 133}, { 2 , -236}, { 426 , 799}, { 393 , 590}, { 532 , 1562}, { 807 , 534}, {1410 , 1051}, + { -14 , -263}, { 83 , -158}, { 158 , -38}, { 616 , 550}, { 845 , 543}, { 536 , 238}, { 912 , 1521}, {1635 , 1344}, + { 115 , -55}, { 263 , 87}, {-126 , 234}, { 376 , 191}, { 459 , 2644}, { 542 , 927}, { 941 , 948}, {1896 , 1528}, + { -19 , 1853}, { 455 , 366}, { 545 , 283}, { 831 , 835}, {1217 , 846}, { 560 , 542}, {1013 , 650}, {1905 , 2343} }, { - {-528 , -246}, {-631 , 56}, {-717 , -277}, { -40 , 1327}, {-1011 , -688}, {-827 , -341}, {-656 , -1599}, { -992 , -1559}, - {-450 , 933}, {-540 , 2109}, {-598 , -1267}, {-387 , -512}, {-1100 , -1979}, {-812 , -617}, {-649 , -147}, { -874 , 586}, - {-720 , -601}, {-281 , -279}, {-578 , 635}, { 169 , 80}, {-1020 , -134}, {-794 , 259}, {-638 , 821}, { -907 , 42}, - {-709 , -1525}, {-482 , 1340}, {-232 , -979}, { 104 , 2314}, { -918 , -1179}, {-790 , 1284}, {-609 , 2259}, { -854 , -978}, - {-624 , 326}, {-194 , 1705}, { -88 , 1060}, { 383 , 1190}, { -415 , 15}, {-789 , -1145}, {-604 , 407}, { -869 , 1136}, - {-503 , -1047}, {-545 , -794}, {-128 , 471}, { 84 , 638}, { -591 , -1509}, {-699 , 1746}, {-600 , -369}, { -784 , 1642}, - {-221 , -668}, {-223 , 261}, { -82 , -446}, {-378 , -1215}, { -741 , 969}, {-689 , -863}, {-569 , -595}, {-1012 , -403}, - {-331 , 518}, {-175 , 787}, {-220 , -3}, { -46 , -841}, { -960 , 297}, {-666 , 68}, {-565 , -1364}, { -265 , -21}, - { 649 , 767}, { 255 , 360}, { 338 , -342}, {1664 , 1627}, { 205 , -226}, { 967 , 31}, {1217 , 928}, { 1697 , 1233}, - { 322 , 1445}, { 320 , 1790}, { 413 , 212}, { 994 , 209}, { 766 , 264}, { 974 , 883}, {1228 , 241}, { 1679 , 801}, - { 75 , 312}, { 754 , 1425}, { 348 , 621}, { 644 , 474}, { 1008 , 763}, {1036 , 2024}, {1354 , 530}, { 1611 , 2129}, - { 162 , 931}, { 883 , 822}, { 990 , 488}, { 615 , -203}, { 1929 , 1234}, {1059 , 1375}, {1382 , 1426}, { 2048 , 1599}, - { 602 , 162}, { 380 , 820}, { 709 , 1064}, {1168 , 1374}, { 549 , 583}, {1062 , 470}, {1415 , 1092}, { 2095 , 2234}, - { 187 , -630}, { 118 , -493}, { 714 , 1787}, {1298 , 673}, { 957 , 1258}, {1082 , 1124}, {1460 , 786}, { 2124 , 1205}, - { 34 , -189}, { 54 , -35}, { 798 , 0}, { 747 , 2378}, { 1420 , 1152}, {1118 , 1673}, {1492 , 2287}, { 2416 , 1618}, - {1159 , 1795}, { 389 , -126}, {1194 , 1003}, {1578 , 1002}, { 1294 , 366}, {1148 , 694}, {1513 , 1791}, { 2746 , 2096} + {-528 , -246}, {-631 , 56}, {-717 , -277}, { -40 , 1327}, {-1011 , -688}, {-827 , -341}, {-656 , -1599}, { -992 , -1559}, + {-450 , 933}, {-540 , 2109}, {-598 , -1267}, {-387 , -512}, {-1100 , -1979}, {-812 , -617}, {-649 , -147}, { -874 , 586}, + {-720 , -601}, {-281 , -279}, {-578 , 635}, { 169 , 80}, {-1020 , -134}, {-794 , 259}, {-638 , 821}, { -907 , 42}, + {-709 , -1525}, {-482 , 1340}, {-232 , -979}, { 104 , 2314}, { -918 , -1179}, {-790 , 1284}, {-609 , 2259}, { -854 , -978}, + {-624 , 326}, {-194 , 1705}, { -88 , 1060}, { 383 , 1190}, { -415 , 15}, {-789 , -1145}, {-604 , 407}, { -869 , 1136}, + {-503 , -1047}, {-545 , -794}, {-128 , 471}, { 84 , 638}, { -591 , -1509}, {-699 , 1746}, {-600 , -369}, { -784 , 1642}, + {-221 , -668}, {-223 , 261}, { -82 , -446}, {-378 , -1215}, { -741 , 969}, {-689 , -863}, {-569 , -595}, {-1012 , -403}, + {-331 , 518}, {-175 , 787}, {-220 , -3}, { -46 , -841}, { -960 , 297}, {-666 , 68}, {-565 , -1364}, { -265 , -21}, + { 649 , 767}, { 255 , 360}, { 338 , -342}, {1664 , 1627}, { 205 , -226}, { 967 , 31}, {1217 , 928}, { 1697 , 1233}, + { 322 , 1445}, { 320 , 1790}, { 413 , 212}, { 994 , 209}, { 766 , 264}, { 974 , 883}, {1228 , 241}, { 1679 , 801}, + { 75 , 312}, { 754 , 1425}, { 348 , 621}, { 644 , 474}, { 1008 , 763}, {1036 , 2024}, {1354 , 530}, { 1611 , 2129}, + { 162 , 931}, { 883 , 822}, { 990 , 488}, { 615 , -203}, { 1929 , 1234}, {1059 , 1375}, {1382 , 1426}, { 2048 , 1599}, + { 602 , 162}, { 380 , 820}, { 709 , 1064}, {1168 , 1374}, { 549 , 583}, {1062 , 470}, {1415 , 1092}, { 2095 , 2234}, + { 187 , -630}, { 118 , -493}, { 714 , 1787}, {1298 , 673}, { 957 , 1258}, {1082 , 1124}, {1460 , 786}, { 2124 , 1205}, + { 34 , -189}, { 54 , -35}, { 798 , 0}, { 747 , 2378}, { 1420 , 1152}, {1118 , 1673}, {1492 , 2287}, { 2416 , 1618}, + {1159 , 1795}, { 389 , -126}, {1194 , 1003}, {1578 , 1002}, { 1294 , 366}, {1148 , 694}, {1513 , 1791}, { 2746 , 2096} } }; const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2] = {//Qlog2(2.56) { - {-709 , -609}, {-615 , -1025}, {-430 , -321}, { -44 , 1032}, {-1050 , -32}, {-1028 , -1856}, {-970 , -109}, { -572 , -1426}, - {-568 , 154}, {-142 , -189}, { -80 , 533}, { -38 , -632}, { -391 , 1275}, { -986 , -732}, {-479 , -510}, { -966 , 96}, - {-847 , -1387}, {-895 , 607}, {-368 , -930}, {-386 , 352}, { -290 , 10}, { -833 , 94}, {-528 , 1718}, { -210 , 115}, - {-529 , 857}, {-727 , -230}, {-128 , 31}, { 133 , 76}, { -275 , -777}, { -615 , -1367}, {-339 , -13}, {-1035 , 1231}, - { 448 , 851}, { 599 , 106}, {1103 , 1112}, { 635 , 1249}, { 761 , 774}, { 531 , -71}, { 722 , 473}, { 767 , 413}, - { 258 , 276}, { 346 , -380}, { 487 , 504}, {1114 , 122}, { 882 , 1553}, { 1983 , 1239}, {2126 , 1217}, { 1742 , 1262}, - { 135 , -252}, { 216 , 545}, { 500 , -125}, {1379 , 1910}, { 304 , 76}, { 1509 , 609}, {1543 , 1385}, { 542 , 1831}, - {-240 , -467}, { 771 , 652}, { 913 , 280}, {1307 , 716}, { 1834 , 1029}, { 1049 , 491}, {1624 , 733}, { 2495 , 1944} + {-709 , -609}, {-615 , -1025}, {-430 , -321}, { -44 , 1032}, {-1050 , -32}, {-1028 , -1856}, {-970 , -109}, { -572 , -1426}, + {-568 , 154}, {-142 , -189}, { -80 , 533}, { -38 , -632}, { -391 , 1275}, { -986 , -732}, {-479 , -510}, { -966 , 96}, + {-847 , -1387}, {-895 , 607}, {-368 , -930}, {-386 , 352}, { -290 , 10}, { -833 , 94}, {-528 , 1718}, { -210 , 115}, + {-529 , 857}, {-727 , -230}, {-128 , 31}, { 133 , 76}, { -275 , -777}, { -615 , -1367}, {-339 , -13}, {-1035 , 1231}, + { 448 , 851}, { 599 , 106}, {1103 , 1112}, { 635 , 1249}, { 761 , 774}, { 531 , -71}, { 722 , 473}, { 767 , 413}, + { 258 , 276}, { 346 , -380}, { 487 , 504}, {1114 , 122}, { 882 , 1553}, { 1983 , 1239}, {2126 , 1217}, { 1742 , 1262}, + { 135 , -252}, { 216 , 545}, { 500 , -125}, {1379 , 1910}, { 304 , 76}, { 1509 , 609}, {1543 , 1385}, { 542 , 1831}, + {-240 , -467}, { 771 , 652}, { 913 , 280}, {1307 , 716}, { 1834 , 1029}, { 1049 , 491}, {1624 , 733}, { 2495 , 1944} }, { - {-729 , -852}, {-590 , 306}, {-398 , 295}, { -31 , 13}, {-659 , -75}, {-604 , -1229}, {-519 , -675}, {-823 , 47}, - {-755 , -207}, {-818 , -424}, {-705 , -1285}, {-258 , -828}, {-807 , -707}, {-182 , -712}, {-928 , 3}, {-455 , -1149}, - {-844 , 422}, {-596 , -1008}, {-504 , -470}, {-459 , 737}, {-338 , -728}, {-836 , 1028}, {-613 , 1242}, {-609 , 1292}, - {-285 , 36}, {-280 , -424}, { 100 , 126}, {-459 , -135}, {-159 , -151}, {-287 , 190}, { 56 , -262}, {-264 , -317}, - { -8 , 603}, { 63 , 301}, { 537 , -155}, { 289 , 569}, { 193 , -412}, { 864 , 79}, { 686 , 399}, { 842 , 1657}, - { 115 , -211}, { 608 , 340}, { 12 , -650}, { 711 , 1103}, { 101 , 510}, { 358 , -416}, {1266 , 453}, { 532 , 612}, - {-256 , -680}, { 41 , 1163}, { 597 , 793}, { 484 , -61}, { 476 , 256}, {1729 , 1246}, {1209 , 1483}, {1472 , 1113}, - { 389 , 330}, { 176 , -388}, {1025 , 317}, {1049 , 732}, {1480 , 1108}, {1285 , 616}, {1730 , 999}, {2001 , 1669} + {-729 , -852}, {-590 , 306}, {-398 , 295}, { -31 , 13}, {-659 , -75}, {-604 , -1229}, {-519 , -675}, {-823 , 47}, + {-755 , -207}, {-818 , -424}, {-705 , -1285}, {-258 , -828}, {-807 , -707}, {-182 , -712}, {-928 , 3}, {-455 , -1149}, + {-844 , 422}, {-596 , -1008}, {-504 , -470}, {-459 , 737}, {-338 , -728}, {-836 , 1028}, {-613 , 1242}, {-609 , 1292}, + {-285 , 36}, {-280 , -424}, { 100 , 126}, {-459 , -135}, {-159 , -151}, {-287 , 190}, { 56 , -262}, {-264 , -317}, + { -8 , 603}, { 63 , 301}, { 537 , -155}, { 289 , 569}, { 193 , -412}, { 864 , 79}, { 686 , 399}, { 842 , 1657}, + { 115 , -211}, { 608 , 340}, { 12 , -650}, { 711 , 1103}, { 101 , 510}, { 358 , -416}, {1266 , 453}, { 532 , 612}, + {-256 , -680}, { 41 , 1163}, { 597 , 793}, { 484 , -61}, { 476 , 256}, {1729 , 1246}, {1209 , 1483}, {1472 , 1113}, + { 389 , 330}, { 176 , -388}, {1025 , 317}, {1049 , 732}, {1480 , 1108}, {1285 , 616}, {1730 , 999}, {2001 , 1669} } }; const Word16 SN_TCVQ_CB_SUB3_fx[4][32][2] = {//Qlog2(2.56) { - {-377 , -872}, {-407 , 801}, {-611 , -449}, {-397 , -87}, {-476 , -1063}, {-797 , -249}, {-263 , -662}, {-473 , 1508}, - {-716 , 310}, {-616 , -982}, {-742 , -1326}, { 197 , 327}, {-894 , -1556}, {-871 , -1259}, {-708 , -1380}, {-789 , -848}, - { 64 , -313}, { -59 , -547}, { -2 , 67}, { 363 , -167}, { 633 , 1840}, { 232 , -357}, {1243 , 1492}, {1640 , 973}, - { 203 , 518}, { 511 , 946}, { 612 , 241}, {1085 , 724}, { 811 , 326}, { 863 , 241}, { 556 , 534}, {1956 , 2087} + {-377 , -872}, {-407 , 801}, {-611 , -449}, {-397 , -87}, {-476 , -1063}, {-797 , -249}, {-263 , -662}, {-473 , 1508}, + {-716 , 310}, {-616 , -982}, {-742 , -1326}, { 197 , 327}, {-894 , -1556}, {-871 , -1259}, {-708 , -1380}, {-789 , -848}, + { 64 , -313}, { -59 , -547}, { -2 , 67}, { 363 , -167}, { 633 , 1840}, { 232 , -357}, {1243 , 1492}, {1640 , 973}, + { 203 , 518}, { 511 , 946}, { 612 , 241}, {1085 , 724}, { 811 , 326}, { 863 , 241}, { 556 , 534}, {1956 , 2087} }, { - {-948 , 28}, {-827 , -1180}, {-348 , -331}, { -36 , 216}, {-1453 , -1162}, {-682 , -639}, {-747 , -1517}, {-704 , 1228}, - {-535 , -988}, {-550 , -109}, {-478 , 580}, {-310 , -699}, {-1308 , -225}, {-775 , -1581}, {-831 , -613}, {-120 , -222}, - { 32 , 200}, { 120 , -221}, { 470 , 466}, { 808 , 313}, { 950 , 711}, { 430 , -576}, {1984 , 1405}, {1645 , 887}, - { 131 , 1148}, { 286 , 508}, { 342 , -236}, {1003 , 1202}, { 317 , -726}, {1493 , 732}, {1336 , 694}, {2382 , 1772} + {-948 , 28}, {-827 , -1180}, {-348 , -331}, { -36 , 216}, {-1453 , -1162}, {-682 , -639}, {-747 , -1517}, {-704 , 1228}, + {-535 , -988}, {-550 , -109}, {-478 , 580}, {-310 , -699}, {-1308 , -225}, {-775 , -1581}, {-831 , -613}, {-120 , -222}, + { 32 , 200}, { 120 , -221}, { 470 , 466}, { 808 , 313}, { 950 , 711}, { 430 , -576}, {1984 , 1405}, {1645 , 887}, + { 131 , 1148}, { 286 , 508}, { 342 , -236}, {1003 , 1202}, { 317 , -726}, {1493 , 732}, {1336 , 694}, {2382 , 1772} }, { - {-874 , -374}, {-237 , 26}, { 15 , 870}, {-710 , 433}, { 40 , -769}, {-1059 , -1350}, { 65 , 208}, {-1012 , -1369}, - { -79 , -459}, {-671 , -942}, { -12 , 56}, {-162 , -431}, {-820 , -1073}, { -886 , -136}, {-327 , -501}, { -55 , -14}, - { 652 , 647}, { 365 , 411}, { 614 , 252}, { 154 , 215}, { 12 , 62}, { 226 , 177}, {1689 , 1213}, { 751 , 179}, - { 31 , 182}, { 281 , -291}, {-354 , -642}, { 939 , 924}, { 619 , 90}, { 1675 , 1130}, { 827 , 272}, { 1550 , 1446} + {-874 , -374}, {-237 , 26}, { 15 , 870}, {-710 , 433}, { 40 , -769}, {-1059 , -1350}, { 65 , 208}, {-1012 , -1369}, + { -79 , -459}, {-671 , -942}, { -12 , 56}, {-162 , -431}, {-820 , -1073}, { -886 , -136}, {-327 , -501}, { -55 , -14}, + { 652 , 647}, { 365 , 411}, { 614 , 252}, { 154 , 215}, { 12 , 62}, { 226 , 177}, {1689 , 1213}, { 751 , 179}, + { 31 , 182}, { 281 , -291}, {-354 , -642}, { 939 , 924}, { 619 , 90}, { 1675 , 1130}, { 827 , 272}, { 1550 , 1446} }, { - {-366 , -916}, {-346 , -234}, {-518 , -140}, { 26 , 305}, {-254 , -92}, {-634 , -976}, {-493 , -1076}, {-334 , -913}, - {-566 , 68}, { 102 , 216}, {-296 , -927}, {-501 , -1030}, {-437 , -1006}, {-146 , -145}, {-211 , -202}, { 62 , 359}, - { 163 , -122}, { 759 , 553}, { 82 , 207}, {-177 , -243}, { 163 , 343}, {1152 , 929}, { 197 , 248}, { 43 , -147}, - { 169 , 371}, {-468 , -1043}, { 686 , 418}, { 563, 245}, {1052 , 843}, { 259 , 341}, {1063 , 637}, { 865 , 654} + {-366 , -916}, {-346 , -234}, {-518 , -140}, { 26 , 305}, {-254 , -92}, {-634 , -976}, {-493 , -1076}, {-334 , -913}, + {-566 , 68}, { 102 , 216}, {-296 , -927}, {-501 , -1030}, {-437 , -1006}, {-146 , -145}, {-211 , -202}, { 62 , 359}, + { 163 , -122}, { 759 , 553}, { 82 , 207}, {-177 , -243}, { 163 , 343}, {1152 , 929}, { 197 , 248}, { 43 , -147}, + { 169 , 371}, {-468 , -1043}, { 686 , 418}, { 563, 245}, {1052 , 843}, { 259 , 341}, {1063 , 637}, { 865 , 654} } }; const Word16 AR_SVQ_CB1_fx[32][8] = /* x2.56 */ {//Qlog2(2.56) - { -1, 4, 16, 4, 45, -110, 10, 167, }, - { -3, 2, 8, -12, -7, 23, 279, -46, }, - { 0, 2, 1, 8, -73, -40, 71, -97, }, - { 0, 2, 42, 74, -39, 72, 27, 8, }, - { 0, 1, 9, -6, 40, -65, -55, -128, }, - { 0, 0, 8, -10, -43, 105, -5, -126, }, - { 0, 0, 12, -3, -98, -18, -88, -73, }, - { 0, 1, -6, -12, -49, -179, -30, -15, }, - { -1, 0, 24, 78, 25, -69, -26, -14, }, - { 0, 1, -1, -29, 23, -65, -126, 34, }, - { 2, -4, -23, -7, -13, -2, -22, -4, }, - { -1, 1, -2, 44, -54, -58, 107, 60, }, - { 0, 1, -3, -15, -54, 97, -100, 41, }, - { 0, -2, -81, 93, -13, 18, -31, -75, }, - { -1, 2, 0, -5, 166, -64, -48, 8, }, - { -2, 0, -27, -108, 36, 3, 12, -80, }, - { 0, 0, 0, 4, 82, -1, 79, 54, }, - { 1, -4, 5, -9, -38, 289, 16, 16, }, - { -1, 2, 6, -68, 61, 67, -31, 100, }, - { 3, -6, 2, -2, -1, -6, -217, 273, }, - { 0, 1, -43, -62, -7, -60, 28, 78, }, - { -1, 2, 10, 0, 76, 84, -55, -45, }, - { -1, -2, 4, 5, -32, 75, 70, 176, }, - { 2, -1, 0, 6, 27, 29, -220, -97, }, - { -1, 1, 90, -56, -10, -16, 29, 8, }, - { -1, 3, -10, 0, 2, -24, 49, -336, }, - { -1, 1, -8, -9, 55, -134, 105, -44, }, - { 0, 1, -16, 69, 51, 40, -51, 98, }, - { 0, 2, -12, -32, -140, 49, 50, 26, }, - { 0, 3, 8, 29, 77, 24, 76, -103, }, - { -1, 2, -24, -18, 7, 100, 94, 5, }, - { 0, -1, 10, 26, -87, -34, -56, 103, } + { -1, 4, 16, 4, 45, -110, 10, 167, }, + { -3, 2, 8, -12, -7, 23, 279, -46, }, + { 0, 2, 1, 8, -73, -40, 71, -97, }, + { 0, 2, 42, 74, -39, 72, 27, 8, }, + { 0, 1, 9, -6, 40, -65, -55, -128, }, + { 0, 0, 8, -10, -43, 105, -5, -126, }, + { 0, 0, 12, -3, -98, -18, -88, -73, }, + { 0, 1, -6, -12, -49, -179, -30, -15, }, + { -1, 0, 24, 78, 25, -69, -26, -14, }, + { 0, 1, -1, -29, 23, -65, -126, 34, }, + { 2, -4, -23, -7, -13, -2, -22, -4, }, + { -1, 1, -2, 44, -54, -58, 107, 60, }, + { 0, 1, -3, -15, -54, 97, -100, 41, }, + { 0, -2, -81, 93, -13, 18, -31, -75, }, + { -1, 2, 0, -5, 166, -64, -48, 8, }, + { -2, 0, -27, -108, 36, 3, 12, -80, }, + { 0, 0, 0, 4, 82, -1, 79, 54, }, + { 1, -4, 5, -9, -38, 289, 16, 16, }, + { -1, 2, 6, -68, 61, 67, -31, 100, }, + { 3, -6, 2, -2, -1, -6, -217, 273, }, + { 0, 1, -43, -62, -7, -60, 28, 78, }, + { -1, 2, 10, 0, 76, 84, -55, -45, }, + { -1, -2, 4, 5, -32, 75, 70, 176, }, + { 2, -1, 0, 6, 27, 29, -220, -97, }, + { -1, 1, 90, -56, -10, -16, 29, 8, }, + { -1, 3, -10, 0, 2, -24, 49, -336, }, + { -1, 1, -8, -9, 55, -134, 105, -44, }, + { 0, 1, -16, 69, 51, 40, -51, 98, }, + { 0, 2, -12, -32, -140, 49, 50, 26, }, + { 0, 3, 8, 29, 77, 24, 76, -103, }, + { -1, 2, -24, -18, 7, 100, 94, 5, }, + { 0, -1, 10, 26, -87, -34, -56, 103, } }; const Word16 AR_SVQ_CB2_fx[16][8] = /* x2.56 */ {//Qlog2(2.56) - { -37, -59, 208, -88, 54, 58, -16, -24, }, - { 0, -98, 9, -65, -182, -21, 19, 9, }, - { -1, 110, -8, 59, 201, 9, -38, -22, }, - { -1, 40, -22, -183, 46, -162, -38, -6, }, - { 12, 2, -193, 64, -43, -48, 11, 9, }, - { -83, 175, -8, -55, -65, 66, 26, 6, }, - { 29, 3, 2, -10, -100, 293, 75, -12, }, - { 7, -54, -76, -91, 63, 119, -84, -84, }, - { 3, 7, 6, 6, -30, 15, -176, 168, }, - { -10, 45, 26, 57, -92, -68, -117, -134, }, - { 0, -37, -34, -69, 106, 54, 121, 131, }, - { -25, -64, 7, 205, 1, 93, 27, 6, }, - { 64, 28, 51, 8, -7, 18, 27, 0, }, - { -20, 44, 57, 78, -55, -170, 88, 93, }, - { 12, -125, 12, 56, 100, -160, -87, -3, }, - { -7, -18, -7, -6, 36, -54, 175, -176, } + { -37, -59, 208, -88, 54, 58, -16, -24, }, + { 0, -98, 9, -65, -182, -21, 19, 9, }, + { -1, 110, -8, 59, 201, 9, -38, -22, }, + { -1, 40, -22, -183, 46, -162, -38, -6, }, + { 12, 2, -193, 64, -43, -48, 11, 9, }, + { -83, 175, -8, -55, -65, 66, 26, 6, }, + { 29, 3, 2, -10, -100, 293, 75, -12, }, + { 7, -54, -76, -91, 63, 119, -84, -84, }, + { 3, 7, 6, 6, -30, 15, -176, 168, }, + { -10, 45, 26, 57, -92, -68, -117, -134, }, + { 0, -37, -34, -69, 106, 54, 121, 131, }, + { -25, -64, 7, 205, 1, 93, 27, 6, }, + { 64, 28, 51, 8, -7, 18, 27, 0, }, + { -20, 44, 57, 78, -55, -170, 88, 93, }, + { 12, -125, 12, 56, 100, -160, -87, -3, }, + { -7, -18, -7, -6, 36, -54, 175, -176, } }; const Word16 W_DTX_HO_FX[HO_HIST_SIZE] = /* Q15 */ { - 6554, 5243, 4194, 3355, 2684, 2147, 1718, 344 + 6554, 5243, 4194, 3355, 2684, 2147, 1718, 344 }; @@ -14301,7 +14301,7 @@ const Word16 HO_ATT_FX[5] = /* Q15 */ 17597, 20205, 22410, 23198, 23198 }; -const Word16 uniform_model[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; // Q0 +const Word16 uniform_model[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; // Q0 /*-----------------------------------------------------------------* @@ -14311,10 +14311,10 @@ const Word16 uniform_model[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; // Q0 const Word16 tbl_mid_gen_wb_2b_fx[] =//Q13 { - 3814, 5145, 5856, 5290, 5277, 4880, 4877, 4273, 3868, 3776, 3392, 3163, 3120, 3019, 3395, 5814, - 1482, 861, 1968, 3198, 3105, 3737, 3749, 4525, 4982, 4828, 5023, 5335, 5327, 5296, 5092, 3444, - 3955, 3851, 1520, 1666, 1554, 1385, 1537, 1276, 1443, 1526, 1597, 1636, 1867, 2041, 2483, 2059, - 7038, 8112, 7324, 6969, 6877, 7028, 6987, 7098, 7003, 6955, 6927, 6808, 6685, 6459, 5871, 6047, + 3814, 5145, 5856, 5290, 5277, 4880, 4877, 4273, 3868, 3776, 3392, 3163, 3120, 3019, 3395, 5814, + 1482, 861, 1968, 3198, 3105, 3737, 3749, 4525, 4982, 4828, 5023, 5335, 5327, 5296, 5092, 3444, + 3955, 3851, 1520, 1666, 1554, 1385, 1537, 1276, 1443, 1526, 1597, 1636, 1867, 2041, 2483, 2059, + 7038, 8112, 7324, 6969, 6877, 7028, 6987, 7098, 7003, 6955, 6927, 6808, 6685, 6459, 5871, 6047, }; const Word16 tbl_mid_gen_wb_4b_fx[] = @@ -14340,156 +14340,156 @@ const Word16 tbl_mid_gen_wb_4b_fx[] = const Word16 tbl_mid_gen_wb_5b_fx[] = {//Q13 - 6510, 8058, 7103, 6095, 6483, 5866, 6026, 6443, 6882, 6907, 7015, 6581, 5649, 4044, 2816, 2519, - 3778, 2123, 3580, 4221, 2598, 4631, 2844, 4905, 5446, 4529, 5186, 6228, 6210, 5693, 6213, -4670, - 9050, 9934, 8441, 7921, 7546, 7840, 7977, 8335, 8679, 8706, 8703, 8607, 8560, 8375, 7759, 6405, - 4243, 5775, 2939, 5887, 4078, 3117, 5267, 5680, 4589, 2401, 731, 1011, 1657, 4733, 7051, 3992, - 2508, 3156, 3347, 1605, 4450, 4633, 3476, 6019, 4083, 3824, 5133, 6020, 3253, 1368, 1736, 13507, - 5934, 6372, 4494, 2957, 4424, 6667, 8167, 8413, 7957, 7139, 5518, 3059, 2829, 2821, 2773, 3274, - 4984, 5566, 5831, 4556, 5732, 6738, 6689, 4683, 2265, 4214, 7242, 9989, 9776, 9068, 4748, 2292, - 2601, 4933, 2764, 4923, 3763, 3678, 5596, 2079, 6108, 6824, 5507, 5612, 6793, 5553, 1140, 9993, - 7084, 6685, 5313, 5196, 3111, 5337, 3535, 2476, 2477, 1737, 2090, 4033, 5680, 6548, 7310, 11811, - 8140, 8602, 7166, 6738, 6018, 5299, 5686, 4722, 4108, 4456, 3713, 3131, 2658, 2336, 2250, 8051, - 727, 1865, 6073, 3932, 2258, 2413, 4823, 5733, 5101, 6126, 4690, 1130, 1172, 1479, 3956, 7204, - 6042, 1024, 5371, 5997, 4964, 5575, 5078, 5843, 6909, 8465, 8601, 6137, 5699, 8049, 9922, 8318, - 2728, 1625, 4750, 5004, 5799, 4938, 6353, 3274, 1781, 3095, 1479, 3136, 5470, 1391, -626, 2422, - 4407, 3228, 1266, 1488, 1222, 963, 1148, 1182, 1330, 1770, 860, 381, 813, 1268, 2352, 3956, - 1683, -120, 83, 1239, 946, 1609, 1982, 3215, 3950, 4200, 4497, 4898, 4551, 3595, 2345, 2444, - 1055, 3207, 7460, 6808, 7103, 6980, 7902, 8196, 6821, 6190, 6405, 7414, 7967, 7506, 6921, 9871, - 3164, 7995, 8446, 8770, 8443, 8302, 7372, 7049, 6090, 5698, 5090, 4792, 4996, 4874, 4285, 6685, - 3681, 319, 536, 3174, 4495, 5486, 5807, 5751, 5461, 4423, 3556, 3449, 5148, 7560, 6277, 3783, - 1987, 4209, 6954, 5880, 7459, 7762, 4326, 4958, 5154, 2150, 2988, 2469, 1175, 1099, 3999, 3950, - 1306, 2303, 7748, 8238, 6116, 2824, 1772, 1130, 2538, 3345, 5317, 4773, 3668, 5458, 5519, 5594, - 4140, 4329, 3339, 3001, 2669, -79, -582, -1729, -680, 1294, 2752, 3700, 3627, 4428, 4950, 2744, - 5309, 3611, 993, 3526, 2043, 3938, 2069, 1434, 4173, 2609, 2704, 3690, 3686, 1894, 1401, -1682, - 6091, 4810, 970, 1063, 1707, 3056, 4597, 6742, 7397, 6913, 7359, 7884, 7571, 6830, 6039, 3823, - 6599, 6006, 1248, 4330, 6935, 3784, 3535, 3902, 3221, 5384, 5691, 5997, 5975, 6731, 9125, 5385, - 204, 242, 2009, 3375, 3412, 3407, 2691, 2547, 598, -150, 67, 250, 618, 1185, 1987, 1157, - 4986, 7977, 6971, 1528, 86, 281, 1497, 3002, 4193, 4430, 4721, 5317, 6001, 6181, 6962, 5480, - 6914, 7963, 5254, 3050, 5365, 3224, 3781, 3044, 2571, 3155, 2243, 1612, 2157, 2526, 2784, -1629, - 7350, 6702, 2435, 1937, 2549, 1978, 2819, 2817, 2059, 2493, 3408, 2344, 1239, 1177, 914, 3763, - 4362, 3105, -1457, -1760, 314, 1452, 2603, 1642, 1670, 1652, 2258, 2492, 3844, 4399, 5213, 660, - 350, 357, 109, 83, -555, -886, -714, -587, -120, 25, 189, 531, 591, 146, 156, 1435, - 498, 211, 3062, 6766, 7150, 8142, 7531, 7527, 7855, 6898, 6613, 6480, 5290, 4310, 5341, 4129, - 2753, 6959, 7088, 4622, 2646, 2395, 1756, 325, 488, 259, -125, -577, -553, 615, 557, 4617, + 6510, 8058, 7103, 6095, 6483, 5866, 6026, 6443, 6882, 6907, 7015, 6581, 5649, 4044, 2816, 2519, + 3778, 2123, 3580, 4221, 2598, 4631, 2844, 4905, 5446, 4529, 5186, 6228, 6210, 5693, 6213, -4670, + 9050, 9934, 8441, 7921, 7546, 7840, 7977, 8335, 8679, 8706, 8703, 8607, 8560, 8375, 7759, 6405, + 4243, 5775, 2939, 5887, 4078, 3117, 5267, 5680, 4589, 2401, 731, 1011, 1657, 4733, 7051, 3992, + 2508, 3156, 3347, 1605, 4450, 4633, 3476, 6019, 4083, 3824, 5133, 6020, 3253, 1368, 1736, 13507, + 5934, 6372, 4494, 2957, 4424, 6667, 8167, 8413, 7957, 7139, 5518, 3059, 2829, 2821, 2773, 3274, + 4984, 5566, 5831, 4556, 5732, 6738, 6689, 4683, 2265, 4214, 7242, 9989, 9776, 9068, 4748, 2292, + 2601, 4933, 2764, 4923, 3763, 3678, 5596, 2079, 6108, 6824, 5507, 5612, 6793, 5553, 1140, 9993, + 7084, 6685, 5313, 5196, 3111, 5337, 3535, 2476, 2477, 1737, 2090, 4033, 5680, 6548, 7310, 11811, + 8140, 8602, 7166, 6738, 6018, 5299, 5686, 4722, 4108, 4456, 3713, 3131, 2658, 2336, 2250, 8051, + 727, 1865, 6073, 3932, 2258, 2413, 4823, 5733, 5101, 6126, 4690, 1130, 1172, 1479, 3956, 7204, + 6042, 1024, 5371, 5997, 4964, 5575, 5078, 5843, 6909, 8465, 8601, 6137, 5699, 8049, 9922, 8318, + 2728, 1625, 4750, 5004, 5799, 4938, 6353, 3274, 1781, 3095, 1479, 3136, 5470, 1391, -626, 2422, + 4407, 3228, 1266, 1488, 1222, 963, 1148, 1182, 1330, 1770, 860, 381, 813, 1268, 2352, 3956, + 1683, -120, 83, 1239, 946, 1609, 1982, 3215, 3950, 4200, 4497, 4898, 4551, 3595, 2345, 2444, + 1055, 3207, 7460, 6808, 7103, 6980, 7902, 8196, 6821, 6190, 6405, 7414, 7967, 7506, 6921, 9871, + 3164, 7995, 8446, 8770, 8443, 8302, 7372, 7049, 6090, 5698, 5090, 4792, 4996, 4874, 4285, 6685, + 3681, 319, 536, 3174, 4495, 5486, 5807, 5751, 5461, 4423, 3556, 3449, 5148, 7560, 6277, 3783, + 1987, 4209, 6954, 5880, 7459, 7762, 4326, 4958, 5154, 2150, 2988, 2469, 1175, 1099, 3999, 3950, + 1306, 2303, 7748, 8238, 6116, 2824, 1772, 1130, 2538, 3345, 5317, 4773, 3668, 5458, 5519, 5594, + 4140, 4329, 3339, 3001, 2669, -79, -582, -1729, -680, 1294, 2752, 3700, 3627, 4428, 4950, 2744, + 5309, 3611, 993, 3526, 2043, 3938, 2069, 1434, 4173, 2609, 2704, 3690, 3686, 1894, 1401, -1682, + 6091, 4810, 970, 1063, 1707, 3056, 4597, 6742, 7397, 6913, 7359, 7884, 7571, 6830, 6039, 3823, + 6599, 6006, 1248, 4330, 6935, 3784, 3535, 3902, 3221, 5384, 5691, 5997, 5975, 6731, 9125, 5385, + 204, 242, 2009, 3375, 3412, 3407, 2691, 2547, 598, -150, 67, 250, 618, 1185, 1987, 1157, + 4986, 7977, 6971, 1528, 86, 281, 1497, 3002, 4193, 4430, 4721, 5317, 6001, 6181, 6962, 5480, + 6914, 7963, 5254, 3050, 5365, 3224, 3781, 3044, 2571, 3155, 2243, 1612, 2157, 2526, 2784, -1629, + 7350, 6702, 2435, 1937, 2549, 1978, 2819, 2817, 2059, 2493, 3408, 2344, 1239, 1177, 914, 3763, + 4362, 3105, -1457, -1760, 314, 1452, 2603, 1642, 1670, 1652, 2258, 2492, 3844, 4399, 5213, 660, + 350, 357, 109, 83, -555, -886, -714, -587, -120, 25, 189, 531, 591, 146, 156, 1435, + 498, 211, 3062, 6766, 7150, 8142, 7531, 7527, 7855, 6898, 6613, 6480, 5290, 4310, 5341, 4129, + 2753, 6959, 7088, 4622, 2646, 2395, 1756, 325, 488, 259, -125, -577, -553, 615, 557, 4617, }; const Word16 tbl_mid_voi_wb_1b_fx[] = /* Q13*/ { - 4551, 4599, 4754, 5035, 4982, 5228, 5318, 5603, 5699, 5652, 5642, 5766, 5825, 5874, 5819, 6056, - 3816, 3355, 2321, 2712, 2900, 2715, 2790, 2508, 2506, 2610, 2617, 2419, 2538, 2622, 3004, 2725, + 4551, 4599, 4754, 5035, 4982, 5228, 5318, 5603, 5699, 5652, 5642, 5766, 5825, 5874, 5819, 6056, + 3816, 3355, 2321, 2712, 2900, 2715, 2790, 2508, 2506, 2610, 2617, 2419, 2538, 2622, 3004, 2725, }; const Word16 tbl_mid_voi_wb_4b_fx[] =//Q13 { - 4337, 4235, 3526, 4083, 3514, 5457, 3168, 2509, 4418, 5021, 1313, 2952, 5347, 3893, 8325, 11758, - 4180, 4037, 3965, 3481, 4028, 3284, 2644, 4585, 4749, 3076, 3211, 1101, 4175, 7440, 5745, -4105, - 4239, 3957, 4450, 4974, 5400, 5734, 6246, 6586, 7774, 2699, 2783, 3474, 1345, -316, 5069, 4904, - 3964, 3810, 2673, 3031, 2249, 3168, 3155, 4204, 7316, 7176, 8680, 7147, 4918, 4136, 3142, 3011, - 4071, 3853, 3898, 3973, 3464, 2878, 5783, 5341, 1725, 801, 1194, 4239, 6866, 4950, 794, 6270, - 3933, 3750, 4931, 3667, 3585, 2550, 4308, 5757, 4503, 7081, 4893, 1076, 109, 1650, 1887, 8861, - 4803, 4827, 4969, 5511, 5768, 4327, 5277, 4934, 6909, 7672, 5355, 3940, 9990, 9622, 7457, 4202, - 4515, 4259, 2444, 4847, 3728, 4599, 4975, 6144, 4087, 4367, 7025, 5028, 2405, 7014, 13366, 6264, - 4746, 4556, 5408, 5866, 4733, 4088, 3965, 3329, 4669, 3105, 5918, 7824, 6026, 9177, 1856, 13229, - 4130, 4214, 2516, 3542, 4847, 3751, 3704, 2380, 4190, 4787, 4651, 4981, 5702, -27, -2961, 129, - 4461, 4724, 5233, 4680, 6010, 7222, 6351, 3069, 605, 5934, 5627, 3836, 3490, 6060, 3556, 2585, - 4628, 4723, 5465, 4180, 4460, 6173, 5915, 7260, 4703, 4114, 3938, 9585, 8085, 3781, 7520, 625, - 5002, 5621, 6352, 6914, 7170, 7719, 7585, 8408, 8360, 7883, 7370, 7222, 6616, 6002, 5565, 9394, - 4059, 4121, 4178, 4417, 3437, 1460, 1031, 111, 585, 1708, 4219, 5419, 2585, 3195, 6149, 3221, - 3394, 2776, 1970, 2707, 2983, 3931, 3247, 1729, 449, -109, -46, -469, 397, 1980, 2305, 1573, - 3259, 1870, 242, 392, 748, 615, 1185, 1285, 2259, 2687, 2212, 1762, 2174, 1887, 1847, 2073, + 4337, 4235, 3526, 4083, 3514, 5457, 3168, 2509, 4418, 5021, 1313, 2952, 5347, 3893, 8325, 11758, + 4180, 4037, 3965, 3481, 4028, 3284, 2644, 4585, 4749, 3076, 3211, 1101, 4175, 7440, 5745, -4105, + 4239, 3957, 4450, 4974, 5400, 5734, 6246, 6586, 7774, 2699, 2783, 3474, 1345, -316, 5069, 4904, + 3964, 3810, 2673, 3031, 2249, 3168, 3155, 4204, 7316, 7176, 8680, 7147, 4918, 4136, 3142, 3011, + 4071, 3853, 3898, 3973, 3464, 2878, 5783, 5341, 1725, 801, 1194, 4239, 6866, 4950, 794, 6270, + 3933, 3750, 4931, 3667, 3585, 2550, 4308, 5757, 4503, 7081, 4893, 1076, 109, 1650, 1887, 8861, + 4803, 4827, 4969, 5511, 5768, 4327, 5277, 4934, 6909, 7672, 5355, 3940, 9990, 9622, 7457, 4202, + 4515, 4259, 2444, 4847, 3728, 4599, 4975, 6144, 4087, 4367, 7025, 5028, 2405, 7014, 13366, 6264, + 4746, 4556, 5408, 5866, 4733, 4088, 3965, 3329, 4669, 3105, 5918, 7824, 6026, 9177, 1856, 13229, + 4130, 4214, 2516, 3542, 4847, 3751, 3704, 2380, 4190, 4787, 4651, 4981, 5702, -27, -2961, 129, + 4461, 4724, 5233, 4680, 6010, 7222, 6351, 3069, 605, 5934, 5627, 3836, 3490, 6060, 3556, 2585, + 4628, 4723, 5465, 4180, 4460, 6173, 5915, 7260, 4703, 4114, 3938, 9585, 8085, 3781, 7520, 625, + 5002, 5621, 6352, 6914, 7170, 7719, 7585, 8408, 8360, 7883, 7370, 7222, 6616, 6002, 5565, 9394, + 4059, 4121, 4178, 4417, 3437, 1460, 1031, 111, 585, 1708, 4219, 5419, 2585, 3195, 6149, 3221, + 3394, 2776, 1970, 2707, 2983, 3931, 3247, 1729, 449, -109, -46, -469, 397, 1980, 2305, 1573, + 3259, 1870, 242, 392, 748, 615, 1185, 1285, 2259, 2687, 2212, 1762, 2174, 1887, 1847, 2073, }; const Word16 tbl_mid_voi_wb_5b_fx[] =//Q13 { - 4182, 3820, 4103, 5620, 4100, 4478, 3949, 5053, 2918, 3083, 4229, 3732, 1823, 6350, 17230, 4601, - 4361, 4077, 2236, 4128, 3216, 4673, 6022, 6522, 5746, 4282, 3121, 4448, 6457, 12573, 4401, 7796, - 4228, 4086, 4375, 4320, 4474, 4735, 4427, 5616, 5975, 138, 5887, 3722, 2304, -3430, 4995, 6246, - 4320, 4344, 4008, 4327, 3323, 6835, 3627, 3330, 3123, 3971, 2382, 1801, 6422, 3162, 9038, 14129, - 4193, 4202, 4413, 2703, 4175, 4330, 2615, 7600, 1717, 3506, 5671, 7170, 3545, 2350, -2738, 7287, - 4170, 3912, 4323, 3821, 4450, 6765, 7496, 8107, 7447, 5525, 3088, 1963, 2014, 3330, 976, 1002, - 4583, 4419, 3584, 4125, 4783, 5133, 3188, 5000, 4812, 4639, 10038, 7018, 5114, 5567, 3292, -6364, - 3926, 4092, 2710, 2721, 1799, 3509, 4542, 3351, 4583, 5877, 6539, 5135, 981, 4029, 7221, 592, - 4624, 4567, 4468, 4630, 5710, 5222, 5883, 2562, 8453, 2825, 109, 6491, 1210, 2921, 7292, 7118, - 4245, 4160, 5119, 4356, 5544, 3034, 1507, 4179, 5971, 1949, 3388, 613, 4995, 9019, 6755, -628, - 4905, 4962, 4529, 7025, 4905, 4470, 5063, 3440, 6348, 6102, 4319, 4395, 7515, 6549, -3697, 6513, - 4683, 4592, 5303, 4593, 4171, 5264, 6116, 7434, 4105, 5454, 2544, 8493, 6491, 894, 8983, -2406, - 3632, 3435, 3988, 4195, 3684, 2173, 6735, 4552, -339, 763, 308, 3463, 6123, 2895, 2831, 5715, - 4316, 4111, 2236, 2682, 1058, 544, 2541, 1677, 3549, 2767, 3376, 5901, 6689, 5811, 6617, 3311, - 4487, 4285, 4992, 3656, 5970, 4547, 3975, 5998, 4985, 6614, 4807, 1971, 14937, 4388, 6153, 3352, - 4601, 4710, 4957, 4454, 4873, 7207, 5881, 3461, 2282, 1829, 5617, 9926, 10043, 7722, 3232, 4629, - 3965, 3837, 2088, 4265, 5042, 3478, 4453, 2804, 4162, 4858, 4315, 4343, 5193, -1823, -5028, -1137, - 3439, 2837, 2549, 4062, 2857, 2657, 2662, 5088, 10548, 8913, 6631, 6395, 5568, 3210, 2431, 3400, - 4073, 3839, 5806, 5296, 3766, 2342, 2585, 891, 3144, 2988, 6807, 4626, 3700, 5854, 1543, 16158, - 4189, 4045, 4293, 4527, 4008, 1413, 4871, 6081, 3297, 6546, 5006, -365, -2369, 1375, 5522, 8787, - 4778, 4782, 4941, 4538, 4497, 3129, 4934, 4371, 7175, 6923, 8620, 10236, 8664, 10088, 10923, 7314, - 4945, 5016, 6439, 6353, 6624, 6463, 6938, 7547, 7004, 7283, 7655, 7149, 7650, 2747, 3416, 14892, - 4776, 5431, 5515, 6194, 5700, 5485, 2795, 5476, 4024, 8891, 2930, 7916, 3428, 8070, 5920, 13440, - 4718, 4986, 4800, 5286, 6567, 6554, 6601, 1235, -1216, 6556, 6098, 3962, 4361, 5536, 5517, 3935, - 4741, 4679, 5593, 4891, 3849, 5675, 6487, 6239, 7062, 12044, 10918, 2438, 3977, 7296, 8445, 6625, - 4859, 5781, 6592, 7399, 8027, 8858, 8139, 8951, 8760, 5506, 6294, 6540, 6516, 7527, 7688, 4084, - 4077, 3771, 3650, 3381, 3367, 4048, 3899, 4382, 3017, -2156, -1464, -2207, 828, 4838, 2071, 2363, - 3796, 3437, 3558, 3842, 2170, 4311, 2602, 696, 1939, 2576, 1239, 328, -129, -647, 1702, 2893, - 4015, 3506, 367, 1350, 3328, 3700, 3827, 2439, 1434, 3887, 2279, 1593, 3673, 5508, 3905, -2973, - 4088, 3990, 3732, 3256, 4718, 1375, 152, -99, -254, 1140, 3578, 3316, 2195, 2408, 5027, 999, - 3749, 3175, 1475, 686, 2006, 1959, 1558, 3059, 5374, 5014, 2439, 2396, 2467, 2218, 1031, 7866, - 2037, 701, 124, 278, 328, 253, 660, 528, 826, 473, 801, 800, 1053, 1330, 804, 967, + 4182, 3820, 4103, 5620, 4100, 4478, 3949, 5053, 2918, 3083, 4229, 3732, 1823, 6350, 17230, 4601, + 4361, 4077, 2236, 4128, 3216, 4673, 6022, 6522, 5746, 4282, 3121, 4448, 6457, 12573, 4401, 7796, + 4228, 4086, 4375, 4320, 4474, 4735, 4427, 5616, 5975, 138, 5887, 3722, 2304, -3430, 4995, 6246, + 4320, 4344, 4008, 4327, 3323, 6835, 3627, 3330, 3123, 3971, 2382, 1801, 6422, 3162, 9038, 14129, + 4193, 4202, 4413, 2703, 4175, 4330, 2615, 7600, 1717, 3506, 5671, 7170, 3545, 2350, -2738, 7287, + 4170, 3912, 4323, 3821, 4450, 6765, 7496, 8107, 7447, 5525, 3088, 1963, 2014, 3330, 976, 1002, + 4583, 4419, 3584, 4125, 4783, 5133, 3188, 5000, 4812, 4639, 10038, 7018, 5114, 5567, 3292, -6364, + 3926, 4092, 2710, 2721, 1799, 3509, 4542, 3351, 4583, 5877, 6539, 5135, 981, 4029, 7221, 592, + 4624, 4567, 4468, 4630, 5710, 5222, 5883, 2562, 8453, 2825, 109, 6491, 1210, 2921, 7292, 7118, + 4245, 4160, 5119, 4356, 5544, 3034, 1507, 4179, 5971, 1949, 3388, 613, 4995, 9019, 6755, -628, + 4905, 4962, 4529, 7025, 4905, 4470, 5063, 3440, 6348, 6102, 4319, 4395, 7515, 6549, -3697, 6513, + 4683, 4592, 5303, 4593, 4171, 5264, 6116, 7434, 4105, 5454, 2544, 8493, 6491, 894, 8983, -2406, + 3632, 3435, 3988, 4195, 3684, 2173, 6735, 4552, -339, 763, 308, 3463, 6123, 2895, 2831, 5715, + 4316, 4111, 2236, 2682, 1058, 544, 2541, 1677, 3549, 2767, 3376, 5901, 6689, 5811, 6617, 3311, + 4487, 4285, 4992, 3656, 5970, 4547, 3975, 5998, 4985, 6614, 4807, 1971, 14937, 4388, 6153, 3352, + 4601, 4710, 4957, 4454, 4873, 7207, 5881, 3461, 2282, 1829, 5617, 9926, 10043, 7722, 3232, 4629, + 3965, 3837, 2088, 4265, 5042, 3478, 4453, 2804, 4162, 4858, 4315, 4343, 5193, -1823, -5028, -1137, + 3439, 2837, 2549, 4062, 2857, 2657, 2662, 5088, 10548, 8913, 6631, 6395, 5568, 3210, 2431, 3400, + 4073, 3839, 5806, 5296, 3766, 2342, 2585, 891, 3144, 2988, 6807, 4626, 3700, 5854, 1543, 16158, + 4189, 4045, 4293, 4527, 4008, 1413, 4871, 6081, 3297, 6546, 5006, -365, -2369, 1375, 5522, 8787, + 4778, 4782, 4941, 4538, 4497, 3129, 4934, 4371, 7175, 6923, 8620, 10236, 8664, 10088, 10923, 7314, + 4945, 5016, 6439, 6353, 6624, 6463, 6938, 7547, 7004, 7283, 7655, 7149, 7650, 2747, 3416, 14892, + 4776, 5431, 5515, 6194, 5700, 5485, 2795, 5476, 4024, 8891, 2930, 7916, 3428, 8070, 5920, 13440, + 4718, 4986, 4800, 5286, 6567, 6554, 6601, 1235, -1216, 6556, 6098, 3962, 4361, 5536, 5517, 3935, + 4741, 4679, 5593, 4891, 3849, 5675, 6487, 6239, 7062, 12044, 10918, 2438, 3977, 7296, 8445, 6625, + 4859, 5781, 6592, 7399, 8027, 8858, 8139, 8951, 8760, 5506, 6294, 6540, 6516, 7527, 7688, 4084, + 4077, 3771, 3650, 3381, 3367, 4048, 3899, 4382, 3017, -2156, -1464, -2207, 828, 4838, 2071, 2363, + 3796, 3437, 3558, 3842, 2170, 4311, 2602, 696, 1939, 2576, 1239, 328, -129, -647, 1702, 2893, + 4015, 3506, 367, 1350, 3328, 3700, 3827, 2439, 1434, 3887, 2279, 1593, 3673, 5508, 3905, -2973, + 4088, 3990, 3732, 3256, 4718, 1375, 152, -99, -254, 1140, 3578, 3316, 2195, 2408, 5027, 999, + 3749, 3175, 1475, 686, 2006, 1959, 1558, 3059, 5374, 5014, 2439, 2396, 2467, 2218, 1031, 7866, + 2037, 701, 124, 278, 328, 253, 660, 528, 826, 473, 801, 800, 1053, 1330, 804, 967, }; const Word16 tbl_mid_unv_wb_4b_fx[] =//Q13 { - 5190, 3143, 50, 2521, 5180, 6320, 3890, 3365, 3582, 3517, 3406, 3049, 2864, 1621, 1932, -950, - 6813, 6650, 2135, 972, 452, 1453, 3221, 1697, 3165, 4443, 5924, 6297, 3907, 2862, 3586, 4625, - 3204, 2673, 6499, 4319, 1054, 559, 4404, 5815, 5072, 6625, 4493, 2479, 1773, 1606, 2099, 8330, - 1924, 2666, 4171, 5517, 5898, 7238, 7318, 7696, 7250, 6269, 6164, 6038, 5249, 4284, 4147, 2828, - 2834, 788, 77, 2016, 1824, 3224, 3441, 4472, 6286, 6717, 6783, 6743, 6715, 7051, 6562, 2531, - 6386, 5634, 5761, 5184, 3523, 4284, 1867, 1045, 579, 1176, 1743, 2599, 5276, 5564, 5368, 7914, - 1795, 1380, 5184, 9326, 8023, 3138, 1258, 1729, 3328, 3934, 5169, 5645, 5271, 5894, 5591, 5145, - 5734, 5844, 8799, 8753, 5628, 5710, 5255, 4872, 5349, 3431, 3006, 2486, 1418, 974, 1115, 2035, - 4194, 8421, 1812, 6078, 3003, 3455, 6719, 7501, 2120, 1892, 2658, 2317, 2296, 5735, 6553, 4485, - 8072, 11456, 6455, 5069, 4918, 4936, 4819, 4932, 6029, 6246, 6289, 6704, 6749, 5337, 4526, 3974, - 3709, 5584, 4884, -1502, 4864, 2333, 606, 5976, 6438, 2413, 1937, 3663, 5593, 6989, 6450, 3555, - 3843, -6887, 3697, 3880, 4448, 4264, 5961, 4198, 3583, 3942, 3606, 3768, 4457, 4374, 4096, 4524, - 2551, 6781, 7017, 2902, 9227, 8728, 7130, 1873, 2308, 4393, 3981, 3976, 4002, 4080, 4820, 5611, - 220, -174, -43, -542, 449, 1470, 1759, 1893, 1294, 995, 723, 723, 769, 994, 1369, 4413, - 1651, 2259, 3079, 2913, 1176, -491, -1262, -827, -217, 908, 1126, 1751, 1901, 1765, 2656, 247, - 5380, 7307, 7727, 8135, 8270, 8471, 8792, 8573, 8335, 8420, 8057, 7562, 7119, 7458, 6806, 7385, + 5190, 3143, 50, 2521, 5180, 6320, 3890, 3365, 3582, 3517, 3406, 3049, 2864, 1621, 1932, -950, + 6813, 6650, 2135, 972, 452, 1453, 3221, 1697, 3165, 4443, 5924, 6297, 3907, 2862, 3586, 4625, + 3204, 2673, 6499, 4319, 1054, 559, 4404, 5815, 5072, 6625, 4493, 2479, 1773, 1606, 2099, 8330, + 1924, 2666, 4171, 5517, 5898, 7238, 7318, 7696, 7250, 6269, 6164, 6038, 5249, 4284, 4147, 2828, + 2834, 788, 77, 2016, 1824, 3224, 3441, 4472, 6286, 6717, 6783, 6743, 6715, 7051, 6562, 2531, + 6386, 5634, 5761, 5184, 3523, 4284, 1867, 1045, 579, 1176, 1743, 2599, 5276, 5564, 5368, 7914, + 1795, 1380, 5184, 9326, 8023, 3138, 1258, 1729, 3328, 3934, 5169, 5645, 5271, 5894, 5591, 5145, + 5734, 5844, 8799, 8753, 5628, 5710, 5255, 4872, 5349, 3431, 3006, 2486, 1418, 974, 1115, 2035, + 4194, 8421, 1812, 6078, 3003, 3455, 6719, 7501, 2120, 1892, 2658, 2317, 2296, 5735, 6553, 4485, + 8072, 11456, 6455, 5069, 4918, 4936, 4819, 4932, 6029, 6246, 6289, 6704, 6749, 5337, 4526, 3974, + 3709, 5584, 4884, -1502, 4864, 2333, 606, 5976, 6438, 2413, 1937, 3663, 5593, 6989, 6450, 3555, + 3843, -6887, 3697, 3880, 4448, 4264, 5961, 4198, 3583, 3942, 3606, 3768, 4457, 4374, 4096, 4524, + 2551, 6781, 7017, 2902, 9227, 8728, 7130, 1873, 2308, 4393, 3981, 3976, 4002, 4080, 4820, 5611, + 220, -174, -43, -542, 449, 1470, 1759, 1893, 1294, 995, 723, 723, 769, 994, 1369, 4413, + 1651, 2259, 3079, 2913, 1176, -491, -1262, -827, -217, 908, 1126, 1751, 1901, 1765, 2656, 247, + 5380, 7307, 7727, 8135, 8270, 8471, 8792, 8573, 8335, 8420, 8057, 7562, 7119, 7458, 6806, 7385, }; const Word16 tbl_mid_unv_wb_5b_fx[] = {//Q13 - 6237, 6323, 1151, 763, 4218, 6546, 8437, 8701, 7456, 6604, 4631, 2901, 3050, 1793, 1955, 2260, - 5542, 4318, 5343, 5521, 5999, 5477, 5265, 5234, 4616, 3329, 3444, 1816, -442, 45, -2, 8922, - 6370, 8208, 6583, 5630, 5401, 5458, 5188, 5595, 6637, 6891, 6962, 6967, 7014, 6330, 5445, 3101, - 2750, 2858, 5206, 4594, 3310, 3494, 2463, 3410, 3405, 6151, 7682, 8593, 4440, 3715, 2946, -4371, - 1157, 661, 3743, 6418, 7515, 8319, 7485, 7298, 7928, 7515, 6812, 5671, 5095, 5122, 4997, 3940, - 5133, 3446, 2693, 1620, 1860, 2663, 4603, 6289, 7451, 7255, 7511, 7486, 8869, 8704, 8431, 6632, - 2497, 6706, 7036, 3437, 10854, 8893, 6033, 3021, 2936, 4766, 4145, 4097, 5177, 4883, 5920, 7612, - -152, -54, 3955, 1170, 5562, 4695, 1370, 8293, 3106, 1942, 5508, 4878, 3495, 1094, 1079, 5401, - 482, 373, 220, -355, -236, -328, -426, -147, 244, 563, 567, 915, 1012, 676, 804, 2721, - 437, 816, 3208, 3395, 2501, 3795, 4380, 2553, 399, 31, -519, -475, -162, 1755, 2852, 1040, - 2067, 2125, 1247, 2393, 2872, 2218, 3502, 3977, 4712, 4275, 2600, 2380, 2314, 2893, 3555, 13929, - 3967, -635, -1752, 2490, 303, 969, 1045, 2839, 5670, 4651, 5202, 5248, 4182, 4381, 5492, 53, - 3041, 2494, 9264, 4970, 360, -3795, 6296, 6475, 4482, 6667, 5265, 2908, 2381, 2889, 3718, 5160, - 3364, 4119, 5929, 3164, -745, 9368, 1652, -719, 6323, 5113, 1919, 1260, 2630, 3585, 2224, 3178, - 1643, 837, 8074, 8337, 4237, 2332, 2190, -1176, 1968, 1238, 2354, 4756, 5269, 5759, 4962, 5411, - 7590, 6471, 2635, 1869, 1209, 1505, 2118, 892, 1652, 3717, 5010, 3969, 2265, 2428, 3278, 5027, - 7289, 8658, 11183, 8913, 6084, 6673, 5961, 4041, 3839, 2643, 2094, 3215, 2956, 2895, 3327, 5063, - 5814, -4982, 1120, 2112, 4384, 5288, 6052, 4305, 4724, 5062, 3380, 4200, 5838, 7181, 6383, 4771, - 3891, 7361, 4160, 1422, 4971, 939, 281, 3585, 4817, 1176, -306, 260, 3815, 8273, 7095, 1529, - 8179, 19416, 3518, 3547, 4619, 4231, 3359, 3606, 5131, 4469, 5204, 5115, 4941, 4772, 4175, 5160, - 4539, 5393, 2706, 5371, 1468, 8488, 10356, 2778, 1426, 371, 8093, 7808, 5208, 5996, 6081, 5057, - 3266, 3481, -4953, -5638, 4022, 5502, 3586, 3117, 2737, 3826, 3658, 3933, 3602, 4920, 4959, 3483, - 3846, 9592, 3360, 6480, 1215, 3170, 5218, 8641, 664, 2695, 3353, 1479, 1687, 6049, 7074, 4696, - 2231, 4497, 6761, 6799, 5941, 5445, 8083, 7944, 5879, 3744, 2518, 6482, 6581, 6096, 6379, -133, - 3360, 6078, 1064, 13807, 8185, 3605, 4327, 3777, 6211, 4977, 5015, 4871, 5825, 2506, 2130, 4946, - 5412, 4507, 952, 4098, 5027, 3949, 3501, 1778, 1955, 2126, 1626, 3669, 4446, -1101, 736, -2708, - 4824, 7481, 8884, -2619, -2754, 281, 4158, 3251, 4602, 2946, 3915, 6169, 6075, 3495, 3266, 4375, - 6135, 2668, 6784, 10326, 6892, 5479, 1511, 3070, 6410, 9193, 6954, 1084, 2873, 7030, 8139, 5670, - 7255, 5764, 5122, 5787, 3129, 5475, -2720, 3770, -827, 872, 1591, 4645, 7218, 5513, 5778, 6323, - 1185, -13100, 5560, 5867, 4153, 2591, 4923, 3450, 2062, 4251, 4289, 3397, 3835, 2082, 2343, 3172, - 4460, 4411, 3940, 4420, 9410, -2789, -2525, -2877, -1868, 2850, 4490, 4093, 3162, 3889, 3800, 3492, - 6408, 8292, 8434, 8544, 8707, 9146, 9377, 9301, 9063, 8945, 8346, 8173, 7175, 7254, 6120, 7420, + 6237, 6323, 1151, 763, 4218, 6546, 8437, 8701, 7456, 6604, 4631, 2901, 3050, 1793, 1955, 2260, + 5542, 4318, 5343, 5521, 5999, 5477, 5265, 5234, 4616, 3329, 3444, 1816, -442, 45, -2, 8922, + 6370, 8208, 6583, 5630, 5401, 5458, 5188, 5595, 6637, 6891, 6962, 6967, 7014, 6330, 5445, 3101, + 2750, 2858, 5206, 4594, 3310, 3494, 2463, 3410, 3405, 6151, 7682, 8593, 4440, 3715, 2946, -4371, + 1157, 661, 3743, 6418, 7515, 8319, 7485, 7298, 7928, 7515, 6812, 5671, 5095, 5122, 4997, 3940, + 5133, 3446, 2693, 1620, 1860, 2663, 4603, 6289, 7451, 7255, 7511, 7486, 8869, 8704, 8431, 6632, + 2497, 6706, 7036, 3437, 10854, 8893, 6033, 3021, 2936, 4766, 4145, 4097, 5177, 4883, 5920, 7612, + -152, -54, 3955, 1170, 5562, 4695, 1370, 8293, 3106, 1942, 5508, 4878, 3495, 1094, 1079, 5401, + 482, 373, 220, -355, -236, -328, -426, -147, 244, 563, 567, 915, 1012, 676, 804, 2721, + 437, 816, 3208, 3395, 2501, 3795, 4380, 2553, 399, 31, -519, -475, -162, 1755, 2852, 1040, + 2067, 2125, 1247, 2393, 2872, 2218, 3502, 3977, 4712, 4275, 2600, 2380, 2314, 2893, 3555, 13929, + 3967, -635, -1752, 2490, 303, 969, 1045, 2839, 5670, 4651, 5202, 5248, 4182, 4381, 5492, 53, + 3041, 2494, 9264, 4970, 360, -3795, 6296, 6475, 4482, 6667, 5265, 2908, 2381, 2889, 3718, 5160, + 3364, 4119, 5929, 3164, -745, 9368, 1652, -719, 6323, 5113, 1919, 1260, 2630, 3585, 2224, 3178, + 1643, 837, 8074, 8337, 4237, 2332, 2190, -1176, 1968, 1238, 2354, 4756, 5269, 5759, 4962, 5411, + 7590, 6471, 2635, 1869, 1209, 1505, 2118, 892, 1652, 3717, 5010, 3969, 2265, 2428, 3278, 5027, + 7289, 8658, 11183, 8913, 6084, 6673, 5961, 4041, 3839, 2643, 2094, 3215, 2956, 2895, 3327, 5063, + 5814, -4982, 1120, 2112, 4384, 5288, 6052, 4305, 4724, 5062, 3380, 4200, 5838, 7181, 6383, 4771, + 3891, 7361, 4160, 1422, 4971, 939, 281, 3585, 4817, 1176, -306, 260, 3815, 8273, 7095, 1529, + 8179, 19416, 3518, 3547, 4619, 4231, 3359, 3606, 5131, 4469, 5204, 5115, 4941, 4772, 4175, 5160, + 4539, 5393, 2706, 5371, 1468, 8488, 10356, 2778, 1426, 371, 8093, 7808, 5208, 5996, 6081, 5057, + 3266, 3481, -4953, -5638, 4022, 5502, 3586, 3117, 2737, 3826, 3658, 3933, 3602, 4920, 4959, 3483, + 3846, 9592, 3360, 6480, 1215, 3170, 5218, 8641, 664, 2695, 3353, 1479, 1687, 6049, 7074, 4696, + 2231, 4497, 6761, 6799, 5941, 5445, 8083, 7944, 5879, 3744, 2518, 6482, 6581, 6096, 6379, -133, + 3360, 6078, 1064, 13807, 8185, 3605, 4327, 3777, 6211, 4977, 5015, 4871, 5825, 2506, 2130, 4946, + 5412, 4507, 952, 4098, 5027, 3949, 3501, 1778, 1955, 2126, 1626, 3669, 4446, -1101, 736, -2708, + 4824, 7481, 8884, -2619, -2754, 281, 4158, 3251, 4602, 2946, 3915, 6169, 6075, 3495, 3266, 4375, + 6135, 2668, 6784, 10326, 6892, 5479, 1511, 3070, 6410, 9193, 6954, 1084, 2873, 7030, 8139, 5670, + 7255, 5764, 5122, 5787, 3129, 5475, -2720, 3770, -827, 872, 1591, 4645, 7218, 5513, 5778, 6323, + 1185, -13100, 5560, 5867, 4153, 2591, 4923, 3450, 2062, 4251, 4289, 3397, 3835, 2082, 2343, 3172, + 4460, 4411, 3940, 4420, 9410, -2789, -2525, -2877, -1868, 2850, 4490, 4093, 3162, 3889, 3800, 3492, + 6408, 8292, 8434, 8544, 8707, 9146, 9377, 9301, 9063, 8945, 8346, 8173, 7175, 7254, 6120, 7420, }; @@ -14504,7 +14504,7 @@ const Word16 select_table22[5][9] = {0, 0, 1, 3, 6, 10, 15, 21, 28}, {0, 0, 0, 1, 4, 10, 20, 35, 56}, {0, 0, 0, 0, 1, 5, 15, 35, 70} -}; // Q0 +}; // Q0 /* value of leader element */ const Word16 vals_a[36][4] = @@ -14514,7 +14514,7 @@ const Word16 vals_a[36][4] = {1,3,5}, {0,2,6}, {0,4}, {0,2,6}, {0,2,4,6}, {1,7}, {0,8}, {0,6}, {0,2,8}, {0,4,8}, {1,9}, {0,2,10}, {0,8}, {0,6,10}, {0,12}, {0,4,12}, {0,10}, {0,2,14}, {0,8,12}, {0,16} -}; // Q0 +}; // Q0 /* code parameter for every leader */ const Word16 vals_q[36][4] = @@ -14524,7 +14524,7 @@ const Word16 vals_q[36][4] = {7,3,2,1}, {2,3,2,1}, {3,2,3}, {4,3,4,1}, {3,4,3,2}, {7,2,1}, {1,2,1}, {2,2,2}, {3,3,3,1}, {2,3,2,1}, {7,2,1}, {2,3,2,1}, {2,2,2}, {2,3,2,1}, {1,2,1}, {2,3,2,1}, {2,2,2}, {2,3,2,1}, {2,3,2,1}, {1,2,1} -}; // Q0 +}; // Q0 /* codebook start address for every leader */ const UWord16 Is[36] = @@ -14532,13 +14532,13 @@ const UWord16 Is[36] = 0, 128, 256, 1376, 240, 0, 1792, 2400, 5376, 5632, 12800, 3744, 21760, 22784, 31744, 38912, 45632, 3856, 52800, 53248, 57728, 60416, 4080, 61440, 61552, 62896, 63120, 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 -}; // Q0 +}; // Q0 /* A3 - Number of the absolute leaders in codebook Q3 */ const Word16 AA3[NB_LDQ3] = { 0, 1, 4, 2, 3, 7, 11, 17, 22 -}; // Q0 +}; // Q0 /* A4 - Number of the absolute leaders in codebook Q4 */ const Word16 AA4[NB_LDQ4] = @@ -14546,13 +14546,13 @@ const Word16 AA4[NB_LDQ4] = 5, 6, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 -}; // Q0 +}; // Q0 /* I3 - Cardinality offsets for absolute leaders in Q3 */ const UWord16 II3[NB_LDQ3] = { 0, 128, 240, 256, 1376, 2400, 3744, 3856, 4080 -}; // Q0 +}; // Q0 /* I4 - Cardinality offset for absolute leaders in Q4 */ const UWord16 II4[NB_LDQ4] = @@ -14560,21 +14560,21 @@ const UWord16 II4[NB_LDQ4] = 0, 1792, 5376, 5632, 12800, 21760, 22784, 31744, 38912, 45632, 52800, 53248, 57728, 60416, 61440, 61552, 62896, 63120, 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 -}; // Q0 +}; // Q0 /* Position of the first absolute leader on a spherical shell (or sphere) */ const Word16 Da_pos[NB_SPHERE] = { 0, 2, 5, 8, 13, 18, 20, 22, 23, 25, 26, 27, 27, 28, 28, 28, 29, 30, 31, 31, 32, 32, 32, 32, 32, 34, 35, 35, 35, 35, 35, 35 -}; // Q0 +}; // Q0 /* Number of absolute leaders on a spherical shell */ const Word16 Da_nb[NB_SPHERE] = { 2, 3, 3, 5, 5, 2, 2, 1, 2, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1 -}; // Q0 +}; // Q0 /* Identification code of an absolute leader */ const Word16 Da_id[NB_LEADER] = @@ -14584,7 +14584,7 @@ const Word16 Da_id[NB_LEADER] = 0x0059, 0x00A4, 0x0060, 0x00A8, 0x00C4, 0x012D, 0x0200, 0x0144, 0x0204, 0x0220, 0x0335, 0x04E4, 0x0400, 0x0584, 0x0A20, 0x0A40, 0x09C4, 0x12C4, 0x0C20, 0x2000 -}; // Q0 +}; // Q0 /* Codebook number for each absolute leader */ const Word16 Da_nq[NB_LEADER+2] = @@ -14592,15 +14592,15 @@ const Word16 Da_nq[NB_LEADER+2] = 2, 2, 3, 3, 2, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 100 -}; // Q0 +}; // Q0 /*------------------------------------------------------------------------------* * SWB TBE tables *------------------------------------------------------------------------------*/ -const Word16 skip_bands_SWB_TBE[NUM_SHB_SUBFR+1] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320}; /* bands for SWB TBE quantisation Q0*/ -const Word16 skip_bands_WB_TBE[NUM_SHB_SUBFR/2+1] = {0, 10, 20, 30, 40, 50, 60, 70, 80}; /* bands for WB TBE quantisation Q0*/ +const Word16 skip_bands_SWB_TBE[NUM_SHB_SUBFR+1] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320}; /* bands for SWB TBE quantisation Q0*/ +const Word16 skip_bands_WB_TBE[NUM_SHB_SUBFR/2+1] = {0, 10, 20, 30, 40, 50, 60, 70, 80}; /* bands for WB TBE quantisation Q0*/ const Word16 interpol_frac_shb[NB_SUBFR * 2] = { @@ -14637,8 +14637,8 @@ const Word16 Hilbert_coeffs_fx[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1] = /* Q14 */ const Word16 window_shb_fx[L_SHB_LAHEAD] = /*sin, 1, sin */ { /*Q15(round) */ - 1513, 4527, 7502, 10413, 13236, 15945, 18518, 20934, 23170, 25210, - 27034, 28627, 29976, 31069, 31898, 32454, 32733, 32767, 32767, 32767, + 1513, 4527, 7502, 10413, 13236, 15945, 18518, 20934, 23170, 25210, + 27034, 28627, 29976, 31069, 31898, 32454, 32733, 32767, 32767, 32767, }; /* Upsampled overlap add window for SHB excitation used transition generation */ @@ -14646,10 +14646,10 @@ const Word16 window_shb_fx[L_SHB_LAHEAD] = /*sin, 1, sin */ const Word16 window_shb_32k_fx[2 * L_SHB_LAHEAD] = { /*Q15(round) */ - 1513, 3020, 4527, 6015, 7502, 8958, 10413, 11825, 13236, 14590, - 15945, 17232, 18518, 19726, 20934, 22052, 23170, 24190, 25210, 26122, - 27034, 27830, 28627, 29301, 29976, 30523, 31069, 31483, 31898, 32176, - 32454, 32593, 32733, 32751, 32767, 32767, 32767, 32767, 32767, 32767, + 1513, 3020, 4527, 6015, 7502, 8958, 10413, 11825, 13236, 14590, + 15945, 17232, 18518, 19726, 20934, 22052, 23170, 24190, 25210, 26122, + 27034, 27830, 28627, 29301, 29976, 30523, 31069, 31483, 31898, 32176, + 32454, 32593, 32733, 32751, 32767, 32767, 32767, 32767, 32767, 32767, }; /* Short overlap add window for SHB excitation used in anal and synth */ @@ -14657,10 +14657,10 @@ const Word16 window_shb_32k_fx[2 * L_SHB_LAHEAD] = const Word16 subwin_shb_fx[SHB_OVERLAP_LEN + 1] = { /*Q15(round) */ - 0, 202, 802, 1786, 3129, - 4799, 6754, 8946, 11321, 13821, - 16384,18947, 21447, 23822, 26014, - 27969, 29639, 30982, 31966, 32566, + 0, 202, 802, 1786, 3129, + 4799, 6754, 8946, 11321, 13821, + 16384,18947, 21447, 23822, 26014, + 27969, 29639, 30982, 31966, 32566, 32767 }; @@ -14670,7 +14670,7 @@ const Word16 window_wb_fx[L_SHB_LAHEAD / 4] =/*sin, 1 */ /* Short overlap add window for SHB excitation used in anal and synth */ const Word16 subwin_wb_fx[SHB_OVERLAP_LEN / 2 + 1] = -{ 0, 5126, 10126, 14876, 19261, 23170, 26510, 29197, 31164, 32365, 32767 }; // Q15 +{ 0, 5126, 10126, 14876, 19261, 23170, 26510, 29197, 31164, 32365, 32767 }; // Q15 /* Window for calculating SHB LPC coeffs */ @@ -14719,21 +14719,21 @@ const Word16 win_lpc_hb_wb_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5 / 32] = const Word16 win_lpc_hb_wb_ivas_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5 / 32] = {//Q15 - 6, 51, 140, 274, - 453, 675, 940, 1247, - 1596, 1985, 2414, 2882, - 3386, 3926, 4499, 5106, - 5743, 6410, 7104, 7823, - 8566, 9331, 10114, 10915, - 11731, 12559, 13398, 14245, - 15099, 15955, 16813, 17669, - 18523, 19370, 20209, 21037, - 21853, 22654, 23437, 24202, - 24945, 25664, 26358, 27025, - 27662, 28269, 28842, 29382, - 29886, 30354, 30783, 31172, - 31521, 31828, 32093, 32315, - 32494, 32628, 32717, 32762 + 6, 51, 140, 274, + 453, 675, 940, 1247, + 1596, 1985, 2414, 2882, + 3386, 3926, 4499, 5106, + 5743, 6410, 7104, 7823, + 8566, 9331, 10114, 10915, + 11731, 12559, 13398, 14245, + 15099, 15955, 16813, 17669, + 18523, 19370, 20209, 21037, + 21853, 22654, 23437, 24202, + 24945, 25664, 26358, 27025, + 27662, 28269, 28842, 29382, + 29886, 30354, 30783, 31172, + 31521, 31828, 32093, 32315, + 32494, 32628, 32717, 32762 }; @@ -14755,291 +14755,291 @@ const Word16 ola_win_shb_switch_fold_fx[L_SUBFR16k] = const Word16 win_flatten_fx[L_FRAME16k / 2] = /*Q15 */ { - 3, 13, 28, 50, 78, 113, 154, 200, 254, 313, - 378, 450, 528, 611, 701, 797, 899, 1006, 1120, 1239, - 1365, 1496, 1632, 1775, 1923, 2076, 2235, 2400, 2569, 2745, - 2925, 3110, 3301, 3496, 3697, 3902, 4112, 4327, 4546, 4770, - 4999, 5232, 5469, 5710, 5955, 6205, 6458, 6715, 6976, 7240, - 7508, 7779, 8054, 8331, 8612, 8896, 9183, 9472, 9764, 10059, - 10356, 10655, 10956, 11260, 11566, 11873, 12182, 12493, 12805, 13119, - 13434, 13750, 14067, 14385, 14703, 15023, 15342, 15663, 15983, 16304, - 16625, 16945, 17265, 17586, 17905, 18224, 18542, 18860, 19176, 19492, - 19806, 20119, 20431, 20741, 21049, 21355, 21660, 21963, 22263, 22561, - 22857, 23150, 23441, 23729, 24014, 24297, 24576, 24852, 25125, 25395, - 25661, 25923, 26182, 26437, 26689, 26936, 27179, 27418, 27653, 27884, - 28110, 28332, 28549, 28761, 28969, 29172, 29370, 29563, 29751, 29934, - 30112, 30284, 30451, 30613, 30769, 30920, 31065, 31205, 31338, 31467, - 31589, 31705, 31816, 31921, 32020, 32113, 32199, 32280, 32355, 32423, - 32486, 32542, 32592, 32636, 32673, 32704, 32730, 32748, 32761, 32767 + 3, 13, 28, 50, 78, 113, 154, 200, 254, 313, + 378, 450, 528, 611, 701, 797, 899, 1006, 1120, 1239, + 1365, 1496, 1632, 1775, 1923, 2076, 2235, 2400, 2569, 2745, + 2925, 3110, 3301, 3496, 3697, 3902, 4112, 4327, 4546, 4770, + 4999, 5232, 5469, 5710, 5955, 6205, 6458, 6715, 6976, 7240, + 7508, 7779, 8054, 8331, 8612, 8896, 9183, 9472, 9764, 10059, + 10356, 10655, 10956, 11260, 11566, 11873, 12182, 12493, 12805, 13119, + 13434, 13750, 14067, 14385, 14703, 15023, 15342, 15663, 15983, 16304, + 16625, 16945, 17265, 17586, 17905, 18224, 18542, 18860, 19176, 19492, + 19806, 20119, 20431, 20741, 21049, 21355, 21660, 21963, 22263, 22561, + 22857, 23150, 23441, 23729, 24014, 24297, 24576, 24852, 25125, 25395, + 25661, 25923, 26182, 26437, 26689, 26936, 27179, 27418, 27653, 27884, + 28110, 28332, 28549, 28761, 28969, 29172, 29370, 29563, 29751, 29934, + 30112, 30284, 30451, 30613, 30769, 30920, 31065, 31205, 31338, 31467, + 31589, 31705, 31816, 31921, 32020, 32113, 32199, 32280, 32355, 32423, + 32486, 32542, 32592, 32636, 32673, 32704, 32730, 32748, 32761, 32767 }; const Word16 win_flatten_4k_fx[L_FRAME16k / 8] = /*Q15 */ { - 13, 114, 315, 615, 1013, 1505, 2089, 2761, - 3517, 4353, 5263, 6241, 7282, 8378, 9525, 10713, - 11937, 13188, 14458, 15741, 17027, 18310, 19580, 20831, - 22055, 23243, 24390, 25486, 26527, 27505, 28415, 29251, - 30007, 30679, 31263, 31755, 32153, 32453, 32654, 32755 + 13, 114, 315, 615, 1013, 1505, 2089, 2761, + 3517, 4353, 5263, 6241, 7282, 8378, 9525, 10713, + 11937, 13188, 14458, 15741, 17027, 18310, 19580, 20831, + 22055, 23243, 24390, 25486, 26527, 27505, 28415, 29251, + 30007, 30679, 31263, 31755, 32153, 32453, 32654, 32755 }; const Word16 wb_bwe_lsfvq_cbook_8bit_fx[256 * 6] = {//Q15 - 2107, 3430, 5123, 6677, 9403, 13197, - 4031, 5069, 7343, 8910, 10647, 12245, - 2037, 3542, 6708, 8763, 10505, 12655, - 5732, 6373, 7912, 9546, 12584, 14230, - 2028, 3337, 5473, 7880, 10269, 12450, - 5809, 6497, 8317, 9624, 11497, 14007, - 2428, 3962, 5675, 7724, 11361, 13385, - 6348, 8307, 8898, 9948, 11058, 13350, - 3552, 4421, 5896, 7143, 9975, 13233, - 5719, 6344, 7482, 8403, 10765, 13455, - 3509, 4379, 5896, 7437, 11765, 14307, - 4521, 8122, 8791, 9856, 11232, 14020, - 2175, 3970, 7788, 9803, 11334, 12910, - 4511, 8156, 8886, 10450, 12686, 14959, - 4223, 5285, 7053, 8423, 11317, 14566, - 7159, 8379, 9040, 10122, 11799, 14270, - 1866, 3064, 4848, 7227, 11225, 13963, - 5915, 6631, 8740, 10002, 11385, 12726, - 3342, 4547, 6475, 9404, 11994, 13418, - 6156, 6880, 8932, 10353, 12380, 13746, - 2648, 4972, 7575, 9476, 12117, 13875, - 5822, 6526, 8747, 10941, 12671, 13971, - 4032, 5110, 7592, 9267, 11374, 14390, - 6864, 8384, 9086, 10649, 12944, 15026, - 3661, 4636, 6668, 8329, 10374, 12185, - 5802, 6444, 8344, 9811, 12234, 14843, - 3593, 4436, 6663, 8693, 11539, 14272, - 5110, 8270, 9006, 10703, 12269, 13901, - 1992, 3229, 5616, 9085, 11419, 13254, - 4319, 5859, 9602, 11396, 12836, 14199, - 3836, 4822, 8285, 10190, 11728, 13302, - 8016, 8698, 10179, 11434, 12944, 14783, - 1891, 3329, 6168, 8307, 10818, 14213, - 5803, 6442, 7973, 9131, 11090, 12657, - 2803, 5499, 8093, 9694, 11223, 12849, - 6222, 6981, 8615, 9848, 12016, 13380, - 2543, 4747, 7638, 9373, 11129, 13652, - 5912, 6615, 9006, 10553, 11959, 13312, - 3604, 4520, 7650, 9833, 12161, 14748, - 7970, 8729, 9780, 10789, 12483, 13985, - 3793, 4716, 7041, 8547, 10610, 13601, - 5640, 6235, 7313, 8370, 12057, 14300, - 3765, 4699, 6784, 9512, 12663, 14216, - 4634, 8363, 9195, 10385, 11477, 13310, - 2462, 4816, 8556, 10394, 11920, 13468, - 3698, 7974, 9207, 10962, 13507, 15208, - 3738, 4667, 7545, 10775, 13024, 14559, - 7267, 8610, 9509, 11264, 12821, 14495, - 2624, 4295, 6173, 8897, 12343, 14174, - 6324, 7135, 8742, 10013, 12598, 14108, - 4448, 5839, 8842, 10335, 11737, 13071, - 6147, 6988, 9510, 10893, 12240, 13535, - 3025, 5140, 7152, 9223, 11404, 13255, - 5985, 6782, 9611, 11341, 12723, 14007, - 4679, 5958, 8100, 9842, 11835, 13492, - 7740, 8565, 9432, 10478, 12611, 14609, - 3830, 4784, 7681, 9528, 11134, 12675, - 5742, 6527, 8359, 10728, 13195, 14626, - 4491, 5635, 7284, 8749, 11594, 13785, - 6772, 8490, 9253, 10943, 12476, 13973, - 2024, 3588, 7524, 10453, 12198, 13858, - 5783, 8882, 9978, 11763, 13237, 14829, - 3979, 5009, 8342, 10323, 12231, 14313, - 8148, 8903, 10193, 11350, 13246, 14490, - 2297, 3810, 5638, 7265, 9162, 11514, - 5809, 6518, 7832, 8766, 10327, 11957, - 2535, 4591, 7415, 9080, 10623, 12257, - 5948, 6598, 8515, 10082, 12721, 14188, - 2443, 4278, 6581, 8172, 9883, 11807, - 5913, 6535, 8878, 10296, 12141, 14245, - 2428, 3925, 6409, 9835, 11962, 13628, - 7430, 8531, 9302, 10259, 11444, 12933, - 3701, 4694, 6372, 7671, 9445, 11571, - 5822, 6470, 7807, 8885, 11506, 14529, - 3742, 4580, 6232, 7860, 11252, 13127, - 5710, 8330, 8943, 10243, 11696, 14511, - 2607, 4197, 6714, 10408, 12714, 14320, - 4116, 8438, 9717, 11018, 12156, 13663, - 4224, 5318, 7486, 10110, 12779, 14331, - 5565, 8413, 9115, 10930, 12588, 14759, - 1898, 3150, 5779, 9497, 12432, 14439, - 6274, 7186, 9258, 10404, 11733, 12952, - 3700, 4591, 7575, 9533, 11461, 13777, - 6234, 7104, 9032, 10986, 13088, 14417, - 2354, 4579, 7744, 9960, 12629, 14802, - 6050, 6729, 9345, 10745, 12436, 14253, - 4345, 5529, 8117, 9718, 12433, 14109, - 8009, 8701, 9863, 10954, 13046, 14474, - 4184, 5186, 6876, 8428, 11236, 12973, - 6113, 6842, 8386, 9659, 12892, 14707, - 3989, 4936, 7152, 8879, 11743, 13632, - 5169, 8411, 9209, 11361, 13452, 15076, - 2397, 4387, 7033, 9035, 11821, 13736, - 3607, 8128, 10170, 11565, 12819, 14147, - 4449, 5805, 8963, 10676, 12596, 14558, - 7911, 8741, 10040, 11622, 13579, 15092, - 2372, 4290, 6990, 8705, 10637, 13685, - 6137, 6917, 8382, 9380, 10859, 12348, - 3235, 5973, 8187, 10174, 12420, 14382, - 6077, 6764, 8551, 9803, 12150, 14079, - 2952, 5097, 6853, 8952, 12066, 14080, - 6606, 7683, 9508, 10695, 12182, 13601, - 3707, 4638, 7468, 10484, 12295, 13754, - 7960, 8715, 10051, 11348, 12757, 14072, - 4139, 5241, 7576, 9037, 10912, 13485, - 5838, 6444, 7768, 8965, 12867, 14998, - 4245, 5338, 7248, 9190, 12328, 14047, - 6159, 8874, 9899, 11134, 12150, 13512, - 2250, 4288, 8698, 10944, 12624, 14316, - 3146, 6848, 9904, 11775, 13534, 14953, - 4044, 5161, 8365, 10294, 12945, 14907, - 7398, 8724, 9813, 11821, 13246, 14552, - 2121, 3890, 6855, 9274, 12059, 14663, - 6329, 7182, 8789, 10081, 13001, 14917, - 4484, 5761, 8634, 10295, 12111, 14022, - 6326, 7208, 9672, 11078, 12830, 14529, - 3230, 5564, 7646, 9955, 12011, 13683, - 4683, 6896, 10002, 11805, 13329, 14747, - 4771, 6044, 8081, 10305, 12526, 14037, - 8231, 9203, 10351, 11427, 12926, 14635, - 4385, 5774, 7989, 9305, 10751, 12299, - 5810, 6658, 9062, 11629, 13359, 14655, - 4288, 5388, 7804, 9378, 11781, 13652, - 4398, 8560, 9646, 11161, 12701, 14872, - 1947, 3440, 7202, 10953, 13222, 14806, - 4686, 8972, 10615, 12054, 13260, 14615, - 3801, 4849, 8922, 11200, 12882, 14423, - 8061, 8813, 10453, 11912, 13335, 14710, - 2365, 3888, 5664, 7346, 10407, 14331, - 4563, 5839, 7472, 8684, 10572, 12800, - 2593, 4197, 6719, 9323, 11229, 12919, - 6081, 6774, 8132, 9244, 12202, 13918, - 2405, 3981, 6144, 8740, 11347, 13796, - 5793, 6444, 8286, 10049, 12152, 13520, - 2795, 4727, 6528, 8506, 11323, 13474, - 6181, 8598, 9346, 10614, 11725, 13545, - 4002, 5001, 6596, 7792, 9987, 13065, - 5748, 6365, 7759, 9028, 11818, 13487, - 3906, 4863, 6462, 7763, 10705, 14359, - 4315, 8428, 9322, 10582, 11942, 14500, - 2812, 4622, 7346, 10036, 11745, 13429, - 4221, 8338, 9277, 11280, 12869, 14317, - 4345, 5427, 7121, 8736, 12787, 14837, - 7678, 8614, 9456, 10461, 12024, 13852, - 2193, 3662, 5609, 7867, 12276, 14739, - 6083, 6864, 8879, 10080, 11623, 13720, - 4114, 5125, 7224, 9729, 11808, 13297, - 6383, 7232, 9252, 10720, 12622, 14030, - 2788, 5189, 8074, 9953, 11795, 14361, - 6079, 6987, 8662, 10589, 12444, 14390, - 4480, 5690, 7708, 9115, 11800, 14576, - 7848, 8763, 9802, 10924, 12515, 14832, - 3582, 4575, 6729, 9084, 11139, 12800, - 5885, 6534, 8853, 10432, 12664, 14960, - 3891, 4850, 7195, 8932, 12097, 14665, - 5797, 8545, 9385, 11556, 12997, 14392, - 1962, 3544, 7039, 9349, 11272, 13857, - 4106, 5493, 9652, 12038, 13603, 14932, - 4328, 5413, 7949, 10282, 12164, 13618, - 8135, 8918, 10057, 11085, 13190, 15015, - 2702, 4627, 6447, 8009, 10197, 13676, - 5998, 6656, 8315, 9496, 11597, 13122, - 3146, 6293, 8530, 10158, 11798, 13558, - 6374, 7289, 8698, 9776, 11885, 14236, - 3171, 5794, 7737, 9377, 11312, 13878, - 6279, 7150, 9192, 10414, 12052, 14174, - 4117, 5195, 7805, 9512, 12450, 14849, - 7963, 8955, 10071, 11129, 12324, 13605, - 4365, 5505, 7013, 8171, 10488, 13658, - 6124, 6894, 8286, 9349, 11859, 14737, - 3753, 4673, 6421, 8146, 12726, 14980, - 5457, 8706, 9598, 11035, 12294, 14268, - 2783, 4916, 7947, 10568, 12395, 14123, - 3909, 8145, 9524, 11951, 14052, 15282, - 3952, 5139, 8180, 11380, 13699, 15085, - 7200, 9031, 10025, 11484, 12924, 14848, - 2533, 4412, 6472, 8299, 11405, 14627, - 6563, 7530, 9064, 10267, 12560, 14422, - 4849, 6618, 8678, 10166, 11983, 13841, - 6393, 7569, 9960, 11300, 12644, 13906, - 3170, 5117, 7158, 9665, 11687, 14114, - 6122, 7071, 10013, 11733, 13170, 14466, - 4308, 5441, 7607, 9900, 11904, 14292, - 8129, 9024, 10087, 11081, 12670, 14356, - 4253, 5392, 8175, 9780, 11353, 12988, - 5453, 6638, 8596, 11453, 13885, 15263, - 4664, 5903, 7618, 9420, 12198, 13853, - 7149, 8859, 9746, 11029, 12219, 14188, - 2318, 4251, 7702, 9889, 11778, 14182, - 6679, 9280, 10573, 11950, 13100, 14491, - 4010, 5176, 8989, 10821, 12250, 13654, - 8076, 8886, 10411, 11722, 12992, 14267, - 2308, 4017, 6024, 7618, 9736, 13081, - 6001, 6751, 7987, 8966, 10964, 13589, - 2908, 5350, 7266, 8739, 10442, 12981, - 6143, 6839, 9027, 10366, 12881, 14416, - 2667, 4224, 6172, 8378, 10717, 12602, - 6275, 7120, 9249, 10613, 12580, 14823, - 2692, 4586, 6968, 9858, 12120, 14209, - 7771, 8769, 9743, 10745, 11943, 13225, - 4201, 5355, 7129, 8337, 9975, 11767, - 6216, 7100, 8444, 9442, 11298, 13690, - 4111, 5040, 6562, 8071, 12034, 13923, - 6657, 8599, 9337, 10665, 12040, 14704, - 3060, 5215, 7260, 10118, 12577, 14386, - 5103, 8913, 10157, 11519, 12669, 14220, - 4633, 5920, 7804, 9514, 12741, 14690, - 6720, 8585, 9448, 11556, 13510, 15095, - 2361, 3970, 6213, 9335, 13270, 15075, - 6506, 7440, 9041, 10179, 12024, 13587, - 4221, 5405, 8311, 9818, 11579, 14044, - 6216, 7224, 9515, 11389, 13545, 15068, - 2872, 5507, 8153, 10650, 13065, 14825, - 6002, 6676, 9393, 11023, 12965, 14755, - 4438, 5642, 8268, 10097, 12295, 14724, - 7797, 8622, 9642, 10932, 13287, 15118, - 4471, 5638, 7551, 9217, 11440, 12928, - 6051, 6890, 8906, 10655, 13437, 15116, - 3953, 4934, 7779, 9619, 12204, 14012, - 5439, 8649, 9791, 12232, 13899, 15193, - 2728, 4495, 6728, 9363, 11344, 14053, - 4069, 8460, 9835, 11742, 13366, 14825, - 4874, 6937, 9226, 10944, 12845, 14547, - 8195, 9093, 10392, 11594, 13355, 15010, - 2956, 5192, 7080, 8765, 11014, 14174, - 6384, 7287, 8812, 9816, 11336, 12808, - 2912, 6122, 9132, 10874, 12583, 14265, - 6148, 6925, 8821, 10030, 12212, 14758, - 2572, 4778, 7325, 9216, 11620, 14651, - 6654, 7718, 9546, 10806, 12633, 14354, - 4328, 5514, 8231, 10852, 12821, 14261, - 8051, 9205, 10385, 11490, 12674, 13988, - 4624, 6013, 7907, 9239, 11160, 13787, - 5786, 6531, 8210, 9968, 13410, 15249, - 3859, 4898, 7132, 9692, 13395, 15118, - 6712, 8944, 10028, 11521, 12690, 14118, - 2417, 4875, 9132, 11671, 13382, 14841, - 4113, 8355, 10734, 12517, 13905, 15115, - 4455, 5753, 7923, 10298, 13343, 15030, - 6998, 8878, 10113, 12233, 13768, 15107, - 2720, 4801, 6883, 9267, 12694, 14837, - 6507, 7496, 9312, 10696, 13185, 14850, - 4631, 6341, 9164, 10796, 12325, 13734, - 6602, 7817, 9932, 11349, 13132, 14672, - 3089, 5561, 7579, 9433, 12256, 14633, - 6246, 7715, 10371, 12065, 13563, 14878, - 4757, 6352, 8543, 10216, 12748, 14620, - 8183, 9366, 10628, 11857, 13185, 14599, - 4734, 6314, 8348, 9716, 11274, 12942, - 5824, 6871, 9829, 12268, 13874, 15138, - 4719, 6142, 8224, 9683, 11915, 14350, - 6288, 8774, 9655, 11204, 12696, 14867, - 2661, 4586, 7326, 10934, 13501, 15026, - 5932, 9323, 10877, 12454, 13715, 15004, - 4467, 6039, 8842, 11164, 13356, 14901, - 7880, 9158, 10593, 12209, 13609, 14989, + 2107, 3430, 5123, 6677, 9403, 13197, + 4031, 5069, 7343, 8910, 10647, 12245, + 2037, 3542, 6708, 8763, 10505, 12655, + 5732, 6373, 7912, 9546, 12584, 14230, + 2028, 3337, 5473, 7880, 10269, 12450, + 5809, 6497, 8317, 9624, 11497, 14007, + 2428, 3962, 5675, 7724, 11361, 13385, + 6348, 8307, 8898, 9948, 11058, 13350, + 3552, 4421, 5896, 7143, 9975, 13233, + 5719, 6344, 7482, 8403, 10765, 13455, + 3509, 4379, 5896, 7437, 11765, 14307, + 4521, 8122, 8791, 9856, 11232, 14020, + 2175, 3970, 7788, 9803, 11334, 12910, + 4511, 8156, 8886, 10450, 12686, 14959, + 4223, 5285, 7053, 8423, 11317, 14566, + 7159, 8379, 9040, 10122, 11799, 14270, + 1866, 3064, 4848, 7227, 11225, 13963, + 5915, 6631, 8740, 10002, 11385, 12726, + 3342, 4547, 6475, 9404, 11994, 13418, + 6156, 6880, 8932, 10353, 12380, 13746, + 2648, 4972, 7575, 9476, 12117, 13875, + 5822, 6526, 8747, 10941, 12671, 13971, + 4032, 5110, 7592, 9267, 11374, 14390, + 6864, 8384, 9086, 10649, 12944, 15026, + 3661, 4636, 6668, 8329, 10374, 12185, + 5802, 6444, 8344, 9811, 12234, 14843, + 3593, 4436, 6663, 8693, 11539, 14272, + 5110, 8270, 9006, 10703, 12269, 13901, + 1992, 3229, 5616, 9085, 11419, 13254, + 4319, 5859, 9602, 11396, 12836, 14199, + 3836, 4822, 8285, 10190, 11728, 13302, + 8016, 8698, 10179, 11434, 12944, 14783, + 1891, 3329, 6168, 8307, 10818, 14213, + 5803, 6442, 7973, 9131, 11090, 12657, + 2803, 5499, 8093, 9694, 11223, 12849, + 6222, 6981, 8615, 9848, 12016, 13380, + 2543, 4747, 7638, 9373, 11129, 13652, + 5912, 6615, 9006, 10553, 11959, 13312, + 3604, 4520, 7650, 9833, 12161, 14748, + 7970, 8729, 9780, 10789, 12483, 13985, + 3793, 4716, 7041, 8547, 10610, 13601, + 5640, 6235, 7313, 8370, 12057, 14300, + 3765, 4699, 6784, 9512, 12663, 14216, + 4634, 8363, 9195, 10385, 11477, 13310, + 2462, 4816, 8556, 10394, 11920, 13468, + 3698, 7974, 9207, 10962, 13507, 15208, + 3738, 4667, 7545, 10775, 13024, 14559, + 7267, 8610, 9509, 11264, 12821, 14495, + 2624, 4295, 6173, 8897, 12343, 14174, + 6324, 7135, 8742, 10013, 12598, 14108, + 4448, 5839, 8842, 10335, 11737, 13071, + 6147, 6988, 9510, 10893, 12240, 13535, + 3025, 5140, 7152, 9223, 11404, 13255, + 5985, 6782, 9611, 11341, 12723, 14007, + 4679, 5958, 8100, 9842, 11835, 13492, + 7740, 8565, 9432, 10478, 12611, 14609, + 3830, 4784, 7681, 9528, 11134, 12675, + 5742, 6527, 8359, 10728, 13195, 14626, + 4491, 5635, 7284, 8749, 11594, 13785, + 6772, 8490, 9253, 10943, 12476, 13973, + 2024, 3588, 7524, 10453, 12198, 13858, + 5783, 8882, 9978, 11763, 13237, 14829, + 3979, 5009, 8342, 10323, 12231, 14313, + 8148, 8903, 10193, 11350, 13246, 14490, + 2297, 3810, 5638, 7265, 9162, 11514, + 5809, 6518, 7832, 8766, 10327, 11957, + 2535, 4591, 7415, 9080, 10623, 12257, + 5948, 6598, 8515, 10082, 12721, 14188, + 2443, 4278, 6581, 8172, 9883, 11807, + 5913, 6535, 8878, 10296, 12141, 14245, + 2428, 3925, 6409, 9835, 11962, 13628, + 7430, 8531, 9302, 10259, 11444, 12933, + 3701, 4694, 6372, 7671, 9445, 11571, + 5822, 6470, 7807, 8885, 11506, 14529, + 3742, 4580, 6232, 7860, 11252, 13127, + 5710, 8330, 8943, 10243, 11696, 14511, + 2607, 4197, 6714, 10408, 12714, 14320, + 4116, 8438, 9717, 11018, 12156, 13663, + 4224, 5318, 7486, 10110, 12779, 14331, + 5565, 8413, 9115, 10930, 12588, 14759, + 1898, 3150, 5779, 9497, 12432, 14439, + 6274, 7186, 9258, 10404, 11733, 12952, + 3700, 4591, 7575, 9533, 11461, 13777, + 6234, 7104, 9032, 10986, 13088, 14417, + 2354, 4579, 7744, 9960, 12629, 14802, + 6050, 6729, 9345, 10745, 12436, 14253, + 4345, 5529, 8117, 9718, 12433, 14109, + 8009, 8701, 9863, 10954, 13046, 14474, + 4184, 5186, 6876, 8428, 11236, 12973, + 6113, 6842, 8386, 9659, 12892, 14707, + 3989, 4936, 7152, 8879, 11743, 13632, + 5169, 8411, 9209, 11361, 13452, 15076, + 2397, 4387, 7033, 9035, 11821, 13736, + 3607, 8128, 10170, 11565, 12819, 14147, + 4449, 5805, 8963, 10676, 12596, 14558, + 7911, 8741, 10040, 11622, 13579, 15092, + 2372, 4290, 6990, 8705, 10637, 13685, + 6137, 6917, 8382, 9380, 10859, 12348, + 3235, 5973, 8187, 10174, 12420, 14382, + 6077, 6764, 8551, 9803, 12150, 14079, + 2952, 5097, 6853, 8952, 12066, 14080, + 6606, 7683, 9508, 10695, 12182, 13601, + 3707, 4638, 7468, 10484, 12295, 13754, + 7960, 8715, 10051, 11348, 12757, 14072, + 4139, 5241, 7576, 9037, 10912, 13485, + 5838, 6444, 7768, 8965, 12867, 14998, + 4245, 5338, 7248, 9190, 12328, 14047, + 6159, 8874, 9899, 11134, 12150, 13512, + 2250, 4288, 8698, 10944, 12624, 14316, + 3146, 6848, 9904, 11775, 13534, 14953, + 4044, 5161, 8365, 10294, 12945, 14907, + 7398, 8724, 9813, 11821, 13246, 14552, + 2121, 3890, 6855, 9274, 12059, 14663, + 6329, 7182, 8789, 10081, 13001, 14917, + 4484, 5761, 8634, 10295, 12111, 14022, + 6326, 7208, 9672, 11078, 12830, 14529, + 3230, 5564, 7646, 9955, 12011, 13683, + 4683, 6896, 10002, 11805, 13329, 14747, + 4771, 6044, 8081, 10305, 12526, 14037, + 8231, 9203, 10351, 11427, 12926, 14635, + 4385, 5774, 7989, 9305, 10751, 12299, + 5810, 6658, 9062, 11629, 13359, 14655, + 4288, 5388, 7804, 9378, 11781, 13652, + 4398, 8560, 9646, 11161, 12701, 14872, + 1947, 3440, 7202, 10953, 13222, 14806, + 4686, 8972, 10615, 12054, 13260, 14615, + 3801, 4849, 8922, 11200, 12882, 14423, + 8061, 8813, 10453, 11912, 13335, 14710, + 2365, 3888, 5664, 7346, 10407, 14331, + 4563, 5839, 7472, 8684, 10572, 12800, + 2593, 4197, 6719, 9323, 11229, 12919, + 6081, 6774, 8132, 9244, 12202, 13918, + 2405, 3981, 6144, 8740, 11347, 13796, + 5793, 6444, 8286, 10049, 12152, 13520, + 2795, 4727, 6528, 8506, 11323, 13474, + 6181, 8598, 9346, 10614, 11725, 13545, + 4002, 5001, 6596, 7792, 9987, 13065, + 5748, 6365, 7759, 9028, 11818, 13487, + 3906, 4863, 6462, 7763, 10705, 14359, + 4315, 8428, 9322, 10582, 11942, 14500, + 2812, 4622, 7346, 10036, 11745, 13429, + 4221, 8338, 9277, 11280, 12869, 14317, + 4345, 5427, 7121, 8736, 12787, 14837, + 7678, 8614, 9456, 10461, 12024, 13852, + 2193, 3662, 5609, 7867, 12276, 14739, + 6083, 6864, 8879, 10080, 11623, 13720, + 4114, 5125, 7224, 9729, 11808, 13297, + 6383, 7232, 9252, 10720, 12622, 14030, + 2788, 5189, 8074, 9953, 11795, 14361, + 6079, 6987, 8662, 10589, 12444, 14390, + 4480, 5690, 7708, 9115, 11800, 14576, + 7848, 8763, 9802, 10924, 12515, 14832, + 3582, 4575, 6729, 9084, 11139, 12800, + 5885, 6534, 8853, 10432, 12664, 14960, + 3891, 4850, 7195, 8932, 12097, 14665, + 5797, 8545, 9385, 11556, 12997, 14392, + 1962, 3544, 7039, 9349, 11272, 13857, + 4106, 5493, 9652, 12038, 13603, 14932, + 4328, 5413, 7949, 10282, 12164, 13618, + 8135, 8918, 10057, 11085, 13190, 15015, + 2702, 4627, 6447, 8009, 10197, 13676, + 5998, 6656, 8315, 9496, 11597, 13122, + 3146, 6293, 8530, 10158, 11798, 13558, + 6374, 7289, 8698, 9776, 11885, 14236, + 3171, 5794, 7737, 9377, 11312, 13878, + 6279, 7150, 9192, 10414, 12052, 14174, + 4117, 5195, 7805, 9512, 12450, 14849, + 7963, 8955, 10071, 11129, 12324, 13605, + 4365, 5505, 7013, 8171, 10488, 13658, + 6124, 6894, 8286, 9349, 11859, 14737, + 3753, 4673, 6421, 8146, 12726, 14980, + 5457, 8706, 9598, 11035, 12294, 14268, + 2783, 4916, 7947, 10568, 12395, 14123, + 3909, 8145, 9524, 11951, 14052, 15282, + 3952, 5139, 8180, 11380, 13699, 15085, + 7200, 9031, 10025, 11484, 12924, 14848, + 2533, 4412, 6472, 8299, 11405, 14627, + 6563, 7530, 9064, 10267, 12560, 14422, + 4849, 6618, 8678, 10166, 11983, 13841, + 6393, 7569, 9960, 11300, 12644, 13906, + 3170, 5117, 7158, 9665, 11687, 14114, + 6122, 7071, 10013, 11733, 13170, 14466, + 4308, 5441, 7607, 9900, 11904, 14292, + 8129, 9024, 10087, 11081, 12670, 14356, + 4253, 5392, 8175, 9780, 11353, 12988, + 5453, 6638, 8596, 11453, 13885, 15263, + 4664, 5903, 7618, 9420, 12198, 13853, + 7149, 8859, 9746, 11029, 12219, 14188, + 2318, 4251, 7702, 9889, 11778, 14182, + 6679, 9280, 10573, 11950, 13100, 14491, + 4010, 5176, 8989, 10821, 12250, 13654, + 8076, 8886, 10411, 11722, 12992, 14267, + 2308, 4017, 6024, 7618, 9736, 13081, + 6001, 6751, 7987, 8966, 10964, 13589, + 2908, 5350, 7266, 8739, 10442, 12981, + 6143, 6839, 9027, 10366, 12881, 14416, + 2667, 4224, 6172, 8378, 10717, 12602, + 6275, 7120, 9249, 10613, 12580, 14823, + 2692, 4586, 6968, 9858, 12120, 14209, + 7771, 8769, 9743, 10745, 11943, 13225, + 4201, 5355, 7129, 8337, 9975, 11767, + 6216, 7100, 8444, 9442, 11298, 13690, + 4111, 5040, 6562, 8071, 12034, 13923, + 6657, 8599, 9337, 10665, 12040, 14704, + 3060, 5215, 7260, 10118, 12577, 14386, + 5103, 8913, 10157, 11519, 12669, 14220, + 4633, 5920, 7804, 9514, 12741, 14690, + 6720, 8585, 9448, 11556, 13510, 15095, + 2361, 3970, 6213, 9335, 13270, 15075, + 6506, 7440, 9041, 10179, 12024, 13587, + 4221, 5405, 8311, 9818, 11579, 14044, + 6216, 7224, 9515, 11389, 13545, 15068, + 2872, 5507, 8153, 10650, 13065, 14825, + 6002, 6676, 9393, 11023, 12965, 14755, + 4438, 5642, 8268, 10097, 12295, 14724, + 7797, 8622, 9642, 10932, 13287, 15118, + 4471, 5638, 7551, 9217, 11440, 12928, + 6051, 6890, 8906, 10655, 13437, 15116, + 3953, 4934, 7779, 9619, 12204, 14012, + 5439, 8649, 9791, 12232, 13899, 15193, + 2728, 4495, 6728, 9363, 11344, 14053, + 4069, 8460, 9835, 11742, 13366, 14825, + 4874, 6937, 9226, 10944, 12845, 14547, + 8195, 9093, 10392, 11594, 13355, 15010, + 2956, 5192, 7080, 8765, 11014, 14174, + 6384, 7287, 8812, 9816, 11336, 12808, + 2912, 6122, 9132, 10874, 12583, 14265, + 6148, 6925, 8821, 10030, 12212, 14758, + 2572, 4778, 7325, 9216, 11620, 14651, + 6654, 7718, 9546, 10806, 12633, 14354, + 4328, 5514, 8231, 10852, 12821, 14261, + 8051, 9205, 10385, 11490, 12674, 13988, + 4624, 6013, 7907, 9239, 11160, 13787, + 5786, 6531, 8210, 9968, 13410, 15249, + 3859, 4898, 7132, 9692, 13395, 15118, + 6712, 8944, 10028, 11521, 12690, 14118, + 2417, 4875, 9132, 11671, 13382, 14841, + 4113, 8355, 10734, 12517, 13905, 15115, + 4455, 5753, 7923, 10298, 13343, 15030, + 6998, 8878, 10113, 12233, 13768, 15107, + 2720, 4801, 6883, 9267, 12694, 14837, + 6507, 7496, 9312, 10696, 13185, 14850, + 4631, 6341, 9164, 10796, 12325, 13734, + 6602, 7817, 9932, 11349, 13132, 14672, + 3089, 5561, 7579, 9433, 12256, 14633, + 6246, 7715, 10371, 12065, 13563, 14878, + 4757, 6352, 8543, 10216, 12748, 14620, + 8183, 9366, 10628, 11857, 13185, 14599, + 4734, 6314, 8348, 9716, 11274, 12942, + 5824, 6871, 9829, 12268, 13874, 15138, + 4719, 6142, 8224, 9683, 11915, 14350, + 6288, 8774, 9655, 11204, 12696, 14867, + 2661, 4586, 7326, 10934, 13501, 15026, + 5932, 9323, 10877, 12454, 13715, 15004, + 4467, 6039, 8842, 11164, 13356, 14901, + 7880, 9158, 10593, 12209, 13609, 14989, }; const Word16 swb_tbe_lsfvq_cbook_8b[256 * LPC_SHB_ORDER] = /* Q15 */ @@ -15362,68 +15362,68 @@ const Word16 wac_swb_ivas_l[LPC_SHB_ORDER] = const Word16 lbr_wb_bwe_lsfvq_cbook_2bit_fx[4 * 4] = { /*Q15 */ - 3876, 5920, 8951, 11884, - 6556, 7979, 10835, 13133, - 4401, 6781, 10676, 13493, - 8453, 9693, 12024, 13921, + 3876, 5920, 8951, 11884, + 6556, 7979, 10835, 13133, + 4401, 6781, 10676, 13493, + 8453, 9693, 12024, 13921, }; const Word16 SHBCB_SubGain5bit_fx[128] = { /*Q14 */ - -2388, -7806, -6576, -6024, - -7066, -5430, -4998, -3495, - -16722, -15343, -960, -7940, - -26291, -5921, -4917, -4378, - -1526, -6621, -8475, -9624, - -8047, -4086, -8940, -3043, - -3630, -5129, -4964, -7381, - -270, -18662, -24233, -25418, - -9246, -7551, -5584, -2053, - -2091, -4622, -9199, -14628, - -4645, -2197, -10255, -9697, - -2438, -9386, -11737, -4570, - -14366, -11436, -8252, -819, - -16192, -16332, -17043, -225, - -5407, -8588, -7577, -2296, - -26309, -21930, -7522, -2514, - -3260, -4246, -7947, -6614, - -1820, -5520, -15272, -19764, - -3706, -3737, -5850, -10520, - -10081, -4050, -4065, -5001, - -3908, -9909, -2881, -9604, - -520, -11156, -12620, -12768, - -4539, -5149, -6208, -4462, - -4866, -7672, -4235, -4407, - -9163, -13411, -2975, -3915, - -12267, -7568, -3842, -2827, - -7181, -4914, -2608, -9392, - -6275, -2868, -5962, -6511, - -12962, -1034, -8517, -10992, - -8247, -7608, -2502, -5026, - -5812, -4998, -3860, -5778, - -16907, -5974, -4434, -3276, + -2388, -7806, -6576, -6024, + -7066, -5430, -4998, -3495, + -16722, -15343, -960, -7940, + -26291, -5921, -4917, -4378, + -1526, -6621, -8475, -9624, + -8047, -4086, -8940, -3043, + -3630, -5129, -4964, -7381, + -270, -18662, -24233, -25418, + -9246, -7551, -5584, -2053, + -2091, -4622, -9199, -14628, + -4645, -2197, -10255, -9697, + -2438, -9386, -11737, -4570, + -14366, -11436, -8252, -819, + -16192, -16332, -17043, -225, + -5407, -8588, -7577, -2296, + -26309, -21930, -7522, -2514, + -3260, -4246, -7947, -6614, + -1820, -5520, -15272, -19764, + -3706, -3737, -5850, -10520, + -10081, -4050, -4065, -5001, + -3908, -9909, -2881, -9604, + -520, -11156, -12620, -12768, + -4539, -5149, -6208, -4462, + -4866, -7672, -4235, -4407, + -9163, -13411, -2975, -3915, + -12267, -7568, -3842, -2827, + -7181, -4914, -2608, -9392, + -6275, -2868, -5962, -6511, + -12962, -1034, -8517, -10992, + -8247, -7608, -2502, -5026, + -5812, -4998, -3860, -5778, + -16907, -5974, -4434, -3276, }; const Word16 HBCB_SubGain5bit_fx[128] = {//Q8 - -15224, -17789, -9897, -5048, -456, -1232, -2238, -2782, - -3391, -3864, -4026, -4045, -2017, -1311, -878, -1973, - -12837, -15376, -8273, -4141, -2791, -3037, -2403, -342, - -3388, -3646, -3471, -2829, -157, -2025, -2318, -2243, - -14652, -16433, -7699, -1188, -2567, -1755, -346, -1682, - -2068, -2321, -2344, -2348, -1759, -1038, -1865, -2041, - -11396, -13719, -7749, -2734, -809, -1935, -1886, -781, - -2136, -1940, -942, -1571, -1926, -2378, -2572, -2145, - -17531, -19267, -7721, -2672, -714, -675, -1516, -2071, - -1925, -2325, -2523, -2657, -1644, -1674, -2036, -2017, - -12781, -14601, -6714, -1380, -2093, -1704, -1124, -756, - -2776, -2687, -2066, -1202, -1102, -680, -1956, -2376, - -14436, -15846, -4918, -2071, -1613, -744, -1807, -1381, - -620, -1294, -2026, -2162, -794, -1755, -1167, -1762, - -11627, -13377, -5876, -1959, -1009, -1879, -1027, -1915, - -1734, -1265, -2001, -1018, -698, -1733, -2172, -1195, + -15224, -17789, -9897, -5048, -456, -1232, -2238, -2782, + -3391, -3864, -4026, -4045, -2017, -1311, -878, -1973, + -12837, -15376, -8273, -4141, -2791, -3037, -2403, -342, + -3388, -3646, -3471, -2829, -157, -2025, -2318, -2243, + -14652, -16433, -7699, -1188, -2567, -1755, -346, -1682, + -2068, -2321, -2344, -2348, -1759, -1038, -1865, -2041, + -11396, -13719, -7749, -2734, -809, -1935, -1886, -781, + -2136, -1940, -942, -1571, -1926, -2378, -2572, -2145, + -17531, -19267, -7721, -2672, -714, -675, -1516, -2071, + -1925, -2325, -2523, -2657, -1644, -1674, -2036, -2017, + -12781, -14601, -6714, -1380, -2093, -1704, -1124, -756, + -2776, -2687, -2066, -1202, -1102, -680, -1956, -2376, + -14436, -15846, -4918, -2071, -1613, -744, -1807, -1381, + -620, -1294, -2026, -2162, -794, -1755, -1167, -1762, + -11627, -13377, -5876, -1959, -1009, -1879, -1027, -1915, + -1734, -1265, -2001, -1018, -698, -1733, -2172, -1195, }; @@ -15488,12 +15488,12 @@ const Word16 full_band_bpf_3_fx[6][5] = /*in Q13*/ /* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ -const Word16 lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; // Q0 -const Word16 lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; // Q0 +const Word16 lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; // Q0 +const Word16 lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; // Q0 /* Tables for approximation of upper half of SWB LSFs */ -const Word16 mirror_point_q_cb_fx[MIRROR_POINT_Q_CB_SIZE] = { 471, 692, 896, 1216 }; // Q15 +const Word16 mirror_point_q_cb_fx[MIRROR_POINT_Q_CB_SIZE] = { 471, 692, 896, 1216 }; // Q15 const Word16 allpass_poles_3_ov_2[9] = /* Q15 */ { @@ -15541,8 +15541,8 @@ const Word16 F_2_5_fx[64] = /*Q10 */ * SWB BWE tables *------------------------------------------------------------------------------*/ -const Word16 swb_bwe_trans_subband[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560}; // Q0 -const Word16 swb_bwe_trans_subband_width[SWB_FENV_TRANS] = {76, 76, 84, 84}; // Q0 +const Word16 swb_bwe_trans_subband[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560}; // Q0 +const Word16 swb_bwe_trans_subband_width[SWB_FENV_TRANS] = {76, 76, 84, 84}; // Q0 const Word16 sqrt_swb_bwe_trans_subband_width_fx[SWB_FENV_TRANS] = { 17854, 17854, 18770, 18770 };/*Q11 */ @@ -15550,607 +15550,607 @@ const Word16 sqrt_swb_bwe_subband_fx_L1[SWB_FENV] = { 16384, 20066, 16384, 20066 const Word16 sqrt_swb_bwe_subband_fx_L2[SWB_FENV / 2] = { 25905, 25905, 25905, 25905, 28378, 28378, 32767 }; /*Q12 */ -const Word16 swb_bwe_subband[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560}; // Q0 -const Word16 fb_bwe_subband[DIM_FB + 1] = { 640, 680, 720, 800 }; // Q0 -const Word16 fb_bwe_sm_subband[DIM_FB] = { 656, 696, 760 }; // Q0 +const Word16 swb_bwe_subband[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560}; // Q0 +const Word16 fb_bwe_subband[DIM_FB + 1] = { 640, 680, 720, 800 }; // Q0 +const Word16 fb_bwe_sm_subband[DIM_FB] = { 656, 696, 760 }; // Q0 const Word16 swb_inv_bwe_subband_width_fx[SWB_FENV] = { 2048,1365,2048,1365,2048,1365,2048,1365,1365,1365,1365,1365,1024,1024 };//Q15 -const Word16 swb_bwe_sm_subband[SWB_FENV] = {248, 268, 288, 308, 328, 348, 368, 388, 412, 436, 460, 484, 512, 544}; // Q0 -const Word16 smooth_factor_fx[SWB_FENV - 1] = { 1638, 1638, 1638, 1638, 1638, 1638, 1638, 1366, 1366, 1366, 1366, 1024, 1024 };//Q15 +const Word16 swb_bwe_sm_subband[SWB_FENV] = {248, 268, 288, 308, 328, 348, 368, 388, 412, 436, 460, 484, 512, 544}; // Q0 +const Word16 smooth_factor_fx[SWB_FENV - 1] = { 1638, 1638, 1638, 1638, 1638, 1638, 1638, 1366, 1366, 1366, 1366, 1024, 1024 };//Q15 -const Word16 fb_bwe_subband_float[DIM_FB+1] = {640, 680, 720, 800}; // Q0 +const Word16 fb_bwe_subband_float[DIM_FB+1] = {640, 680, 720, 800}; // Q0 const Word16 fb_inv_bwe_subband_width_fx[DIM_FB] = { 819, 819, 409 };//Q15 -const Word16 fb_bwe_sm_subband_float[DIM_FB] = {656, 696, 760}; // Q0 +const Word16 fb_bwe_sm_subband_float[DIM_FB] = {656, 696, 760}; // Q0 const Word16 fb_smooth_factor_fx[DIM_FB] = { 1024, 819, 512 };//Q15 const Word16 EnvCdbk11_fx[N_CB11 * DIM11] = /*Q8 */ { - -2220, 29, 1168, 2124, 2180, 1208, 741, - 1521, -312, -843, -1523, -1970, -2205, -2541, - 746, 1835, 3461, 4398, 4292, 4184, 3462, - 1627, 2475, 2937, 2839, 2198, 1729, 1325, - -514, -731, -557, -200, 100, 475, 540, - 655, 956, 1272, 1083, 774, 687, 459, - 5987, 5460, 4689, 4192, 3845, 3615, 3393, - 3571, 4840, 5784, 6266, 5933, 5158, 4433, - 2959, 2087, 1180, 979, 1180, 1371, 1636, - 6029, 6157, 6431, 6762, 6998, 7153, 7050, - -822, 210, 450, 178, -639, -1346, -1577, - 4451, 4184, 4111, 4329, 4833, 5232, 5512, - 3420, 3994, 4321, 4205, 3684, 3154, 2651, - -3734, -2305, -1388, -324, 22, -847, -1141, - 850, 510, 896, 1780, 2130, 2688, 2826, - 3294, 2823, 2510, 2516, 3029, 3413, 3843, - -3563, -3409, -3199, -2917, -2584, -2282, -1981, - -2738, -3185, -3752, -4320, -4484, -4524, -4329, - -7534, -7481, -7283, -7175, -6757, -6281, -5865, - -4868, -4836, -4603, -4422, -4086, -3738, -3323, - -13896, -13775, -13484, -13339, -12926, -12399, -11970, - 8409, 8420, 8305, 8103, 7954, 7778, 7496, - 7180, 6845, 6369, 5971, 5557, 5309, 5027, - 4633, 4008, 3267, 2422, 2072, 1778, 1510, - 10128, 10432, 10540, 10473, 10176, 9837, 9586, - 2933, 2695, 2060, 1286, 424, -254, -825, - -10032, -9847, -9544, -9420, -9000, -8508, -8084, - 1830, 927, -158, -388, -360, -368, -287, - -21962, -21904, -21548, -21471, -21004, -20511, -20064, - -6090, -6142, -5937, -5852, -5493, -5104, -4671, - -1382, -1640, -2205, -2557, -2785, -3019, -2994, - -1300, -1567, -1744, -1642, -1409, -1080, -902, + -2220, 29, 1168, 2124, 2180, 1208, 741, + 1521, -312, -843, -1523, -1970, -2205, -2541, + 746, 1835, 3461, 4398, 4292, 4184, 3462, + 1627, 2475, 2937, 2839, 2198, 1729, 1325, + -514, -731, -557, -200, 100, 475, 540, + 655, 956, 1272, 1083, 774, 687, 459, + 5987, 5460, 4689, 4192, 3845, 3615, 3393, + 3571, 4840, 5784, 6266, 5933, 5158, 4433, + 2959, 2087, 1180, 979, 1180, 1371, 1636, + 6029, 6157, 6431, 6762, 6998, 7153, 7050, + -822, 210, 450, 178, -639, -1346, -1577, + 4451, 4184, 4111, 4329, 4833, 5232, 5512, + 3420, 3994, 4321, 4205, 3684, 3154, 2651, + -3734, -2305, -1388, -324, 22, -847, -1141, + 850, 510, 896, 1780, 2130, 2688, 2826, + 3294, 2823, 2510, 2516, 3029, 3413, 3843, + -3563, -3409, -3199, -2917, -2584, -2282, -1981, + -2738, -3185, -3752, -4320, -4484, -4524, -4329, + -7534, -7481, -7283, -7175, -6757, -6281, -5865, + -4868, -4836, -4603, -4422, -4086, -3738, -3323, + -13896, -13775, -13484, -13339, -12926, -12399, -11970, + 8409, 8420, 8305, 8103, 7954, 7778, 7496, + 7180, 6845, 6369, 5971, 5557, 5309, 5027, + 4633, 4008, 3267, 2422, 2072, 1778, 1510, + 10128, 10432, 10540, 10473, 10176, 9837, 9586, + 2933, 2695, 2060, 1286, 424, -254, -825, + -10032, -9847, -9544, -9420, -9000, -8508, -8084, + 1830, 927, -158, -388, -360, -368, -287, + -21962, -21904, -21548, -21471, -21004, -20511, -20064, + -6090, -6142, -5937, -5852, -5493, -5104, -4671, + -1382, -1640, -2205, -2557, -2785, -3019, -2994, + -1300, -1567, -1744, -1642, -1409, -1080, -902, }; const Word16 EnvCdbk1st_fx[N_CB1ST * DIM1ST] = /*Q8 */ { - -1819, -1138, 751, - -494, 162, -826, - -3199, -123, 2479, - -2071, 238, -429, - -1819, 1780, 1233, - 284, 1187, -1123, - -1689, -722, -484, - -1256, 52, -1336, - -604, 3738, -1297, - 555, 412, 743, - -626, -1685, 1527, - 145, 1557, -224, - -638, 1370, 1589, - -1188, 37, -410, - -428, -3320, 1860, - 2597, -95, -2876, - -742, -583, -684, - 1607, -1671, -1874, - -1111, -936, -1374, - 275, -2314, 518, - 2682, 2368, -302, - 1809, -555, -579, - 3193, -1270, -1208, - 750, 84, 154, - -1160, 429, 1098, - 816, -613, -2897, - 2159, -1885, 1245, - -671, 426, 3177, - 867, -144, -639, - 843, -1888, 2271, - 1542, 259, -148, - -1680, 1027, 285, - 162, -763, 1666, - -1916, 1175, -1227, - -345, -907, -151, - 1979, 1062, 402, - -1231, 2437, 3130, - -2422, 361, 1040, - -4314, -4106, -4221, - 146, -1200, -1828, - 485, 889, -3847, - 384, -2461, -2845, - 1526, -600, 1599, - -838, -571, 1097, - 1776, -3393, 4058, - -3330, 2429, 1732, - 468, -2140, -934, - 833, 2292, -1129, - -20, -1029, 652, - -346, 168, 1834, - -1730, 838, 2234, - 1622, -1695, -194, - -3198, -773, 228, - 1070, 1741, 285, - 1655, -212, -1628, - 2178, 604, 1784, - 1801, -3224, -848, - -819, 348, 187, - 16, 300, 244, - 769, 201, 1554, - 719, -394, 780, - 311, 2853, 185, - 1163, 489, -1022, - -330, 459, 877, - 109, -541, -691, - -509, -267, 478, - -340, -417, -1403, - -860, -675, -2703, - 1025, 826, 250, - -1043, 1008, -434, - -1042, -631, 60, - -173, 332, -2084, - 984, 919, -2042, - -1257, -2287, 339, - 366, -1309, -158, - 1041, 1039, 1083, - 3566, 918, 227, - 62, -139, 936, - 2424, 730, -1022, - -745, 1954, 427, - -1091, -1358, -478, - -173, 2121, -2367, - -2175, 2535, -1946, - -880, -1964, -1549, - -249, -1203, -927, - -2377, -443, -1775, - -1439, -582, 2037, - -529, -3679, -550, - 608, -284, -1566, - 201, 63, -344, - 1376, 218, 816, - 2471, -348, 479, - -1388, 988, -2674, - 1429, -3538, 1125, - 864, -1351, 845, - 301, 977, 408, - -1122, 3364, 1107, - -213, 730, -329, - 839, -683, -92, - 631, 1172, 2364, - 598, 685, -329, - -780, -1317, 448, - -424, -153, -199, - 768, -331, 2825, - 882, -1047, -975, - -375, -1835, -299, - 2861, -3375, -3158, - 2099, 2168, -2630, - 1602, 1930, 1451, - 1294, 1265, -586, - -2500, -2570, -2667, - -806, -1529, 3272, - -522, 1072, 478, - 4035, -2491, 480, - -1908, 2414, -178, - -1563, -143, 438, - 205, 861, 1287, - -691, 963, -1374, - -2359, -2032, -886, - 162, -442, 160, - 194, 2494, 1960, - -2533, -2578, 1924, - 267, 1701, 937, - 2919, 2950, 2382, - -670, 2102, -859, - -3147, 1385, -215, - 1482, -595, 415, - 228, 290, -1060, + -1819, -1138, 751, + -494, 162, -826, + -3199, -123, 2479, + -2071, 238, -429, + -1819, 1780, 1233, + 284, 1187, -1123, + -1689, -722, -484, + -1256, 52, -1336, + -604, 3738, -1297, + 555, 412, 743, + -626, -1685, 1527, + 145, 1557, -224, + -638, 1370, 1589, + -1188, 37, -410, + -428, -3320, 1860, + 2597, -95, -2876, + -742, -583, -684, + 1607, -1671, -1874, + -1111, -936, -1374, + 275, -2314, 518, + 2682, 2368, -302, + 1809, -555, -579, + 3193, -1270, -1208, + 750, 84, 154, + -1160, 429, 1098, + 816, -613, -2897, + 2159, -1885, 1245, + -671, 426, 3177, + 867, -144, -639, + 843, -1888, 2271, + 1542, 259, -148, + -1680, 1027, 285, + 162, -763, 1666, + -1916, 1175, -1227, + -345, -907, -151, + 1979, 1062, 402, + -1231, 2437, 3130, + -2422, 361, 1040, + -4314, -4106, -4221, + 146, -1200, -1828, + 485, 889, -3847, + 384, -2461, -2845, + 1526, -600, 1599, + -838, -571, 1097, + 1776, -3393, 4058, + -3330, 2429, 1732, + 468, -2140, -934, + 833, 2292, -1129, + -20, -1029, 652, + -346, 168, 1834, + -1730, 838, 2234, + 1622, -1695, -194, + -3198, -773, 228, + 1070, 1741, 285, + 1655, -212, -1628, + 2178, 604, 1784, + 1801, -3224, -848, + -819, 348, 187, + 16, 300, 244, + 769, 201, 1554, + 719, -394, 780, + 311, 2853, 185, + 1163, 489, -1022, + -330, 459, 877, + 109, -541, -691, + -509, -267, 478, + -340, -417, -1403, + -860, -675, -2703, + 1025, 826, 250, + -1043, 1008, -434, + -1042, -631, 60, + -173, 332, -2084, + 984, 919, -2042, + -1257, -2287, 339, + 366, -1309, -158, + 1041, 1039, 1083, + 3566, 918, 227, + 62, -139, 936, + 2424, 730, -1022, + -745, 1954, 427, + -1091, -1358, -478, + -173, 2121, -2367, + -2175, 2535, -1946, + -880, -1964, -1549, + -249, -1203, -927, + -2377, -443, -1775, + -1439, -582, 2037, + -529, -3679, -550, + 608, -284, -1566, + 201, 63, -344, + 1376, 218, 816, + 2471, -348, 479, + -1388, 988, -2674, + 1429, -3538, 1125, + 864, -1351, 845, + 301, 977, 408, + -1122, 3364, 1107, + -213, 730, -329, + 839, -683, -92, + 631, 1172, 2364, + 598, 685, -329, + -780, -1317, 448, + -424, -153, -199, + 768, -331, 2825, + 882, -1047, -975, + -375, -1835, -299, + 2861, -3375, -3158, + 2099, 2168, -2630, + 1602, 1930, 1451, + 1294, 1265, -586, + -2500, -2570, -2667, + -806, -1529, 3272, + -522, 1072, 478, + 4035, -2491, 480, + -1908, 2414, -178, + -1563, -143, 438, + 205, 861, 1287, + -691, 963, -1374, + -2359, -2032, -886, + 162, -442, 160, + 194, 2494, 1960, + -2533, -2578, 1924, + 267, 1701, 937, + 2919, 2950, 2382, + -670, 2102, -859, + -3147, 1385, -215, + 1482, -595, 415, + 228, 290, -1060, }; const Word16 EnvCdbk2nd_fx[N_CB2ND * DIM2ND] = /*Q8 */ { - 1104, -1833, -1110, -954, - 757, 853, -176, 286, - -873, -587, -7, 1458, - -462, -553, -350, 104, - 1938, 1957, -1340, -703, - 1202, -779, 21, 1996, - -2851, -169, 1049, 940, - -1355, -726, -1788, 1076, - -767, -641, -646, -880, - 135, -832, -197, -889, - -826, 3, 279, -502, - -714, 544, -526, 375, - 291, -1076, -816, -3929, - -1175, -475, 2219, -642, - 197, -219, -1052, -1601, - 1175, -162, -695, -336, - 1124, 126, -2326, -1573, - 1164, -1323, -1958, 1074, - -2080, -2152, 113, 649, - -637, -860, 721, 267, - -609, 1658, -1006, -1352, - 1631, 2225, 2128, 1827, - -1112, -1351, 1856, 1656, - -2132, 1006, 770, -1294, - -472, 776, 1661, 2248, - -121, -574, -1481, -316, - 2565, -1081, 188, 293, - 398, 2598, 704, -1129, - 1023, 104, 550, 499, - -416, 127, 253, -1894, - 456, -2578, 190, 1018, - -1488, 286, -1202, -915, - -1164, 1874, 1651, 302, - -1312, -1547, -1625, -1516, - 170, -233, 817, 1209, - -1090, 341, 709, 725, - 854, 819, -278, -1083, - -15, 113, 286, 283, - 1166, -906, 1880, 301, - 342, -7, -587, 776, - -785, -1259, -1166, 3194, - -1630, -1071, 300, -1080, - -12, 190, -538, -493, - 351, 907, 1929, -1534, - 480, 36, 593, -526, - 813, 1216, 986, 89, - 98, 1010, -2272, 268, - 2766, -102, -1307, -873, - -1660, -467, -365, 47, - 1496, 1277, -228, -2791, - 1565, -669, 520, -1598, - -361, 1078, 457, -364, - 543, -950, 28, 248, - 1904, 815, -1034, 1125, - -13, -1951, 1085, -1005, - -2223, 1519, -624, 857, - 1121, 831, 872, 1295, - 193, 2284, -422, 609, - -156, 827, -733, 2065, - -3390, -3384, -3197, -3220, - 31, 896, 539, 978, - -21, 408, 1502, 405, - -583, -1662, -665, -164, - 2193, 976, 613, -436, + 1104, -1833, -1110, -954, + 757, 853, -176, 286, + -873, -587, -7, 1458, + -462, -553, -350, 104, + 1938, 1957, -1340, -703, + 1202, -779, 21, 1996, + -2851, -169, 1049, 940, + -1355, -726, -1788, 1076, + -767, -641, -646, -880, + 135, -832, -197, -889, + -826, 3, 279, -502, + -714, 544, -526, 375, + 291, -1076, -816, -3929, + -1175, -475, 2219, -642, + 197, -219, -1052, -1601, + 1175, -162, -695, -336, + 1124, 126, -2326, -1573, + 1164, -1323, -1958, 1074, + -2080, -2152, 113, 649, + -637, -860, 721, 267, + -609, 1658, -1006, -1352, + 1631, 2225, 2128, 1827, + -1112, -1351, 1856, 1656, + -2132, 1006, 770, -1294, + -472, 776, 1661, 2248, + -121, -574, -1481, -316, + 2565, -1081, 188, 293, + 398, 2598, 704, -1129, + 1023, 104, 550, 499, + -416, 127, 253, -1894, + 456, -2578, 190, 1018, + -1488, 286, -1202, -915, + -1164, 1874, 1651, 302, + -1312, -1547, -1625, -1516, + 170, -233, 817, 1209, + -1090, 341, 709, 725, + 854, 819, -278, -1083, + -15, 113, 286, 283, + 1166, -906, 1880, 301, + 342, -7, -587, 776, + -785, -1259, -1166, 3194, + -1630, -1071, 300, -1080, + -12, 190, -538, -493, + 351, 907, 1929, -1534, + 480, 36, 593, -526, + 813, 1216, 986, 89, + 98, 1010, -2272, 268, + 2766, -102, -1307, -873, + -1660, -467, -365, 47, + 1496, 1277, -228, -2791, + 1565, -669, 520, -1598, + -361, 1078, 457, -364, + 543, -950, 28, 248, + 1904, 815, -1034, 1125, + -13, -1951, 1085, -1005, + -2223, 1519, -624, 857, + 1121, 831, 872, 1295, + 193, 2284, -422, 609, + -156, 827, -733, 2065, + -3390, -3384, -3197, -3220, + 31, 896, 539, 978, + -21, 408, 1502, 405, + -583, -1662, -665, -164, + 2193, 976, 613, -436, }; const Word16 EnvCdbk3rd_fx[N_CB3RD * DIM3RD] = /*Q8 */ { - 1031, -2454, 748, - 2770, 2442, 1761, - -2348, 4079, -959, - 1874, -735, -2242, - -59, 35, 201, - -1518, 162, 1809, - -1977, -1063, -103, - 2485, 1212, -863, - 882, 192, 39, - 1356, 851, 979, - -1377, -2961, -1477, - 497, -808, 593, - -394, -748, -1564, - -950, -198, -436, - -503, -1420, -234, - 318, 985, -1905, - -118, 1783, 1563, - 220, 929, 400, - 857, 37, -995, - -807, 1943, -409, - -743, -524, 552, - 940, 1643, -299, - 805, -1421, -768, - -2330, 705, 156, - 61, 203, 1213, - -138, 517, -642, - 64, -501, -435, - 2194, -625, 157, - -1600, 341, -1611, - 1137, -351, 2353, - -811, -1715, 1522, - -870, 613, 446, + 1031, -2454, 748, + 2770, 2442, 1761, + -2348, 4079, -959, + 1874, -735, -2242, + -59, 35, 201, + -1518, 162, 1809, + -1977, -1063, -103, + 2485, 1212, -863, + 882, 192, 39, + 1356, 851, 979, + -1377, -2961, -1477, + 497, -808, 593, + -394, -748, -1564, + -950, -198, -436, + -503, -1420, -234, + 318, 985, -1905, + -118, 1783, 1563, + 220, 929, 400, + 857, 37, -995, + -807, 1943, -409, + -743, -524, 552, + 940, 1643, -299, + 805, -1421, -768, + -2330, 705, 156, + 61, 203, 1213, + -138, 517, -642, + 64, -501, -435, + 2194, -625, 157, + -1600, 341, -1611, + 1137, -351, 2353, + -811, -1715, 1522, + -870, 613, 446, }; const Word16 EnvCdbk4th_fx[N_CB4TH * DIM4TH] = /*Q8 */ { - 1024, -210, -207, 591, - -280, -2486, -951, 958, - 1539, 1136, 411, 1314, - 1761, -202, 1339, 203, - -2438, -2109, -2028, -2125, - 1849, -1408, -670, 144, - -469, 2674, -1589, -3604, - 1642, -702, 139, 2476, - -483, 372, -861, 540, - -119, 827, 863, 952, - 23, 99, -24, -303, - 488, -2233, -1432, -1399, - 54, -43, 96, -1527, - 1170, 133, -119, -717, - 258, -1215, -439, 160, - -1049, 793, 970, -770, - -1914, -1245, 1281, 422, - -1194, 1005, 176, -2368, - -1631, 1316, -1125, -361, - 1124, 1132, 61, -2186, - 790, -2055, 1174, 938, - 2974, 3874, 2315, 2040, - -300, 2484, 59, -860, - 543, 1307, -1868, -725, - 389, -115, -945, -146, - -1837, -578, -620, 975, - 389, 1779, 1732, 296, - 377, 897, 1555, 2269, - -854, 26, 590, 1413, - -780, -985, 1389, 2639, - 312, -277, -935, -3289, - 1740, 1852, 641, -519, - 738, 898, -466, 115, - 1187, -286, -1514, -1309, - 74, -801, -583, -987, - 510, -667, 430, -191, - 418, -303, 806, 1258, - -1083, -1065, 362, -2114, - -1075, 82, 260, 286, - -2579, 14, 75, -854, - -661, -634, 482, -581, - -338, -306, 3255, 388, - -230, -24, 1161, 205, - 256, 546, -141, 1379, - -63, -775, -484, 1478, - -517, -546, -451, 86, - 1473, -1201, 430, -1892, - 394, 831, 620, -664, - 334, 64, 1773, -1576, - -1783, 1270, 1020, 944, - 1023, 98, -1908, 1330, - -560, -1044, 380, 707, - -427, -708, -1815, -90, - -54, 2298, -537, 1151, - -499, 703, -1018, 3322, - 92, 717, -607, -1032, - -1313, -1393, -580, -485, - 34, -2192, 788, -860, - 2641, 628, -776, -259, - -702, -159, -1483, -1638, - -33, -63, 97, 553, - 692, 523, 548, 349, - -913, 54, -456, -702, - -341, 944, 157, 100, + 1024, -210, -207, 591, + -280, -2486, -951, 958, + 1539, 1136, 411, 1314, + 1761, -202, 1339, 203, + -2438, -2109, -2028, -2125, + 1849, -1408, -670, 144, + -469, 2674, -1589, -3604, + 1642, -702, 139, 2476, + -483, 372, -861, 540, + -119, 827, 863, 952, + 23, 99, -24, -303, + 488, -2233, -1432, -1399, + 54, -43, 96, -1527, + 1170, 133, -119, -717, + 258, -1215, -439, 160, + -1049, 793, 970, -770, + -1914, -1245, 1281, 422, + -1194, 1005, 176, -2368, + -1631, 1316, -1125, -361, + 1124, 1132, 61, -2186, + 790, -2055, 1174, 938, + 2974, 3874, 2315, 2040, + -300, 2484, 59, -860, + 543, 1307, -1868, -725, + 389, -115, -945, -146, + -1837, -578, -620, 975, + 389, 1779, 1732, 296, + 377, 897, 1555, 2269, + -854, 26, 590, 1413, + -780, -985, 1389, 2639, + 312, -277, -935, -3289, + 1740, 1852, 641, -519, + 738, 898, -466, 115, + 1187, -286, -1514, -1309, + 74, -801, -583, -987, + 510, -667, 430, -191, + 418, -303, 806, 1258, + -1083, -1065, 362, -2114, + -1075, 82, 260, 286, + -2579, 14, 75, -854, + -661, -634, 482, -581, + -338, -306, 3255, 388, + -230, -24, 1161, 205, + 256, 546, -141, 1379, + -63, -775, -484, 1478, + -517, -546, -451, 86, + 1473, -1201, 430, -1892, + 394, 831, 620, -664, + 334, 64, 1773, -1576, + -1783, 1270, 1020, 944, + 1023, 98, -1908, 1330, + -560, -1044, 380, 707, + -427, -708, -1815, -90, + -54, 2298, -537, 1151, + -499, 703, -1018, 3322, + 92, 717, -607, -1032, + -1313, -1393, -580, -485, + 34, -2192, 788, -860, + 2641, 628, -776, -259, + -702, -159, -1483, -1638, + -33, -63, 97, 553, + 692, 523, 548, 349, + -913, 54, -456, -702, + -341, 944, 157, 100, }; const Word16 EnvCdbkFB_fx[N_CB_FB * DIM_FB] = /*Q7 */ { - -2126, -1242, -945, - 1628, -686, -539, - 1230, 2245, 2532, - 2822, 3094, 2669, - -12376, -11507, -11342, - 2678, 3533, 3510, - 489, 903, 689, - 1930, 2929, 3025, - 3424, 4179, 4050, - -2500, -1707, -1415, - -3511, -2563, -2224, - -865, -987, -1212, - -424, 891, 1919, - 1976, 2520, 2277, - 673, 1667, 1945, - 5169, 6024, 5983, - -1367, -501, -236, - -254, 679, 989, - -18974, -18088, -17834, - -23007, -22053, -22109, - 2262, 2301, -625, - -124, 431, 372, - 1454, 1962, 1791, - 200, 1094, 1347, - -997, -110, 213, - -697, 267, 602, - -3066, -2172, -1876, - -4358, -3493, -3164, - -360, 59, -472, - -1813, -919, -601, - 4204, 4967, 4913, - 953, 1457, 1245 + -2126, -1242, -945, + 1628, -686, -539, + 1230, 2245, 2532, + 2822, 3094, 2669, + -12376, -11507, -11342, + 2678, 3533, 3510, + 489, 903, 689, + 1930, 2929, 3025, + 3424, 4179, 4050, + -2500, -1707, -1415, + -3511, -2563, -2224, + -865, -987, -1212, + -424, 891, 1919, + 1976, 2520, 2277, + 673, 1667, 1945, + 5169, 6024, 5983, + -1367, -501, -236, + -254, 679, 989, + -18974, -18088, -17834, + -23007, -22053, -22109, + 2262, 2301, -625, + -124, 431, 372, + 1454, 1962, 1791, + 200, 1094, 1347, + -997, -110, 213, + -697, 267, 602, + -3066, -2172, -1876, + -4358, -3493, -3164, + -360, 59, -472, + -1813, -919, -601, + 4204, 4967, 4913, + 953, 1457, 1245 }; const Word16 Mean_env_fb_fx[DIM_FB] = { 1760, 805, 473 }; /*Q8 */ const Word16 w_NOR_fx[SWB_FENV] = /*Q15 */ { - 32767, 32056, 31374, 30720, 30093, 29491, 28913, - 28357, 27822, 27307, 26810, 26331, 25869, 25423, + 32767, 32056, 31374, 30720, 30093, 29491, 28913, + 28357, 27822, 27307, 26810, 26331, 25869, 25423, }; const Word16 Mean_env_fx[SWB_FENV] = /*Q8 */ { - 7327, 7414, 7181, 7160, 6889, 6866, 6746, - 6651, 6385, 6152, 5873, 5668, 5435, 5222, + 7327, 7414, 7181, 7160, 6889, 6866, 6746, + 6651, 6385, 6152, 5873, 5668, 5435, 5222, }; const Word16 Env_TR_Cdbk1_fx[N_CB_TR1 * DIM_TR1] = /*Q8 */ { - 229, -2347, - 8199, 7726, - -312, 1700, - 9881, 5949, - 8942, 8358, - 3865, 3287, - 2405, 796, - 3664, 1433, - 3059, 2215, - 618, 874, - -5479, -4636, - 2237, 2512, - 4265, 2428, - 6583, 2065, - 4548, 6579, - 11325, 7340, - 10578, 9264, - 8491, 6457, - -1380, -2484, - 3377, 5069, - 7393, 5120, - 4798, 4440, - 5506, 7614, - -3371, -3982, - 2806, 2959, - 2242, 3550, - 1334, 3065, - 2055, -1350, - 815, 5507, - 4940, 1457, - -1950, -1046, - 653, -1133, - 872, -3622, - -1756, 245, - 5792, 5542, - 4084, 7696, - 4569, 5204, - -810, -1555, - 10127, 10384, - 11341, 11713, - 6365, 4996, - 8641, 10527, - 5914, 3366, - 4522, 3266, - 5217, 2830, - 8107, 8980, - 3952, 5858, - 5848, 8990, - 6424, 5931, - 5185, 3823, - 6367, 6917, - 3548, 2683, - 1634, 2098, - 2729, -89, - 6964, 7664, - 3179, 3561, - 6388, 4193, - 4024, 4828, - -378, 434, - 9338, 9507, - 7593, 3483, - -6835, -6317, - 5207, 5029, - 11326, 10488, - 7411, 6086, - 10072, 8255, - -6099, -5652, - 7074, 8702, - -12228, -11384, - -11471, -10567, - -13025, -12253, - -12879, -11289, - -13952, -13062, - -16214, -15389, - -11659, -10789, - -12351, -11477, - -12789, -11947, - -15139, -14249, - -11326, -11219, - -11950, -11093, - -11800, -10928, - -23738, -22881, - 12795, 11890, - -3793, -2879, - -27373, -26492, - -11928, -11531, - -12110, -11258, - -20492, -19634, - -14371, -13608, - -12591, -11728, - -14055, -11739, - 9471, 7272, - -11184, -10335, - -13313, -11673, - -12209, -10610, - -13465, -12761, - 7690, 7115, - 2564, 4496, - 5587, 4551, - -813, -562, - -4483, -5521, - 1556, 98, - 2, 3468, - 1410, 1339, - 4049, 161, - -4538, -4026, - -9866, -9115, - -1616, -4727, - 2457, 1653, - 631, 2155, - -17982, -17082, - 2628, 6088, - -10791, -9933, - -12426, -11566, - 4322, 4000, - -1574, 2162, - -7968, -7599, - 1523, 4192, - 5621, 6537, - -2511, -1987, - 12471, 9218, - 8746, 4971, - 3642, 4148, - 5089, 5948, - 350, -92, - 7028, 6683, - -2430, -3216, - -3974, -886, + 229, -2347, + 8199, 7726, + -312, 1700, + 9881, 5949, + 8942, 8358, + 3865, 3287, + 2405, 796, + 3664, 1433, + 3059, 2215, + 618, 874, + -5479, -4636, + 2237, 2512, + 4265, 2428, + 6583, 2065, + 4548, 6579, + 11325, 7340, + 10578, 9264, + 8491, 6457, + -1380, -2484, + 3377, 5069, + 7393, 5120, + 4798, 4440, + 5506, 7614, + -3371, -3982, + 2806, 2959, + 2242, 3550, + 1334, 3065, + 2055, -1350, + 815, 5507, + 4940, 1457, + -1950, -1046, + 653, -1133, + 872, -3622, + -1756, 245, + 5792, 5542, + 4084, 7696, + 4569, 5204, + -810, -1555, + 10127, 10384, + 11341, 11713, + 6365, 4996, + 8641, 10527, + 5914, 3366, + 4522, 3266, + 5217, 2830, + 8107, 8980, + 3952, 5858, + 5848, 8990, + 6424, 5931, + 5185, 3823, + 6367, 6917, + 3548, 2683, + 1634, 2098, + 2729, -89, + 6964, 7664, + 3179, 3561, + 6388, 4193, + 4024, 4828, + -378, 434, + 9338, 9507, + 7593, 3483, + -6835, -6317, + 5207, 5029, + 11326, 10488, + 7411, 6086, + 10072, 8255, + -6099, -5652, + 7074, 8702, + -12228, -11384, + -11471, -10567, + -13025, -12253, + -12879, -11289, + -13952, -13062, + -16214, -15389, + -11659, -10789, + -12351, -11477, + -12789, -11947, + -15139, -14249, + -11326, -11219, + -11950, -11093, + -11800, -10928, + -23738, -22881, + 12795, 11890, + -3793, -2879, + -27373, -26492, + -11928, -11531, + -12110, -11258, + -20492, -19634, + -14371, -13608, + -12591, -11728, + -14055, -11739, + 9471, 7272, + -11184, -10335, + -13313, -11673, + -12209, -10610, + -13465, -12761, + 7690, 7115, + 2564, 4496, + 5587, 4551, + -813, -562, + -4483, -5521, + 1556, 98, + 2, 3468, + 1410, 1339, + 4049, 161, + -4538, -4026, + -9866, -9115, + -1616, -4727, + 2457, 1653, + 631, 2155, + -17982, -17082, + 2628, 6088, + -10791, -9933, + -12426, -11566, + 4322, 4000, + -1574, 2162, + -7968, -7599, + 1523, 4192, + 5621, 6537, + -2511, -1987, + 12471, 9218, + 8746, 4971, + 3642, 4148, + 5089, 5948, + 350, -92, + 7028, 6683, + -2430, -3216, + -3974, -886, }; const Word16 Env_TR_Cdbk2_fx[N_CB_TR2 * DIM_TR2] = /*Q8 */ { - 2639, 375, - -481, 1694, - -2400, -3306, - 86, -4018, - -1301, 47, - 734, 299, - 957, -1039, - 2204, 1486, - 361, -1136, - 2628, -838, - -2010, 1296, - 373, 127, - -573, 2604, - 689, -1554, - 1676, -371, - 1298, 279, - -901, 1086, - 1747, -2723, - 214, -657, - -731, -909, - 1545, -1658, - -369, -2208, - -1276, 1748, - 1141, -522, - 186, -1893, - -1260, -2016, - -478, -504, - 1287, 1882, - -97, -1400, - -1372, -1165, - 800, -152, - 413, -240, - -208, -858, - -90, -399, - 492, 2519, - 913, 1368, - -344, 282, - 305, 526, - -251, 860, - -1066, 567, - -2800, -687, - 1, 674, - 176, 878, - -716, -153, - 706, 831, - -1083, -424, - 419, 1192, - -132, 565, - 708, -2406, - 600, -661, - 1712, 2969, - -1974, 379, - -672, 208, - 26, 296, - -1821, -501, - -513, 635, - 266, 1737, - -221, 1232, - -3498, 1632, - -337, -66, - -552, -1427, - 1329, 850, - -718, -2948, - -3, 0, + 2639, 375, + -481, 1694, + -2400, -3306, + 86, -4018, + -1301, 47, + 734, 299, + 957, -1039, + 2204, 1486, + 361, -1136, + 2628, -838, + -2010, 1296, + 373, 127, + -573, 2604, + 689, -1554, + 1676, -371, + 1298, 279, + -901, 1086, + 1747, -2723, + 214, -657, + -731, -909, + 1545, -1658, + -369, -2208, + -1276, 1748, + 1141, -522, + 186, -1893, + -1260, -2016, + -478, -504, + 1287, 1882, + -97, -1400, + -1372, -1165, + 800, -152, + 413, -240, + -208, -858, + -90, -399, + 492, 2519, + 913, 1368, + -344, 282, + 305, 526, + -251, 860, + -1066, 567, + -2800, -687, + 1, 674, + 176, 878, + -716, -153, + 706, 831, + -1083, -424, + 419, 1192, + -132, 565, + 708, -2406, + 600, -661, + 1712, 2969, + -1974, 379, + -672, 208, + 26, 296, + -1821, -501, + -513, 635, + 266, 1737, + -221, 1232, + -3498, 1632, + -337, -66, + -552, -1427, + 1329, 850, + -718, -2948, + -3, 0, }; const Word16 Mean_env_tr_fx[5] = { 6971, 6095, 6111, 4995 }; /*Q8 */ @@ -16162,15 +16162,15 @@ const Word16 Mean_env_tr_fx[5] = { 6971, 6095, 6111, 4995 }; /*Q8 */ const Word16 gain_table_SWB_BWE_fx[NB_SWB_SUBBANDS] = { -6554/*-0.4f*/, 1638/*0.1f*/, 9830/*0.6f*/, 18022/*1.1f*/ }; /* Q14 */ -const Word16 bits_lagIndices_modeNormal[NB_SWB_SUBBANDS] = {2, 2, 1, 1}; // Q0 -const Word16 subband_offsets_12KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_12KBPS, SWB_SB_OFF1_12KBPS, SWB_SB_OFF2_12KBPS, SWB_SB_OFF3_12KBPS}; // Q0 -const Word16 subband_offsets_16KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_16KBPS, SWB_SB_OFF1_16KBPS, SWB_SB_OFF2_16KBPS, SWB_SB_OFF3_16KBPS}; // Q0 +const Word16 bits_lagIndices_modeNormal[NB_SWB_SUBBANDS] = {2, 2, 1, 1}; // Q0 +const Word16 subband_offsets_12KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_12KBPS, SWB_SB_OFF1_12KBPS, SWB_SB_OFF2_12KBPS, SWB_SB_OFF3_12KBPS}; // Q0 +const Word16 subband_offsets_16KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_16KBPS, SWB_SB_OFF1_16KBPS, SWB_SB_OFF2_16KBPS, SWB_SB_OFF3_16KBPS}; // Q0 /* Search offset for the subbands that use a partial search */ const Word16 subband_search_offsets[NB_SWB_SUBBANDS] = { 0, 0, 64, 64 -}; // Q0 +}; // Q0 @@ -16190,25 +16190,25 @@ const Word16 bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = {1,1}; / const Word16 subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR] = { SWB_SB_OFF0_SUB5_12KBPS_HAR, SWB_SB_OFF1_SUB5_12KBPS_HAR, SWB_SB_OFF2_SUB5_12KBPS_HAR, SWB_SB_OFF3_SUB5_12KBPS_HAR -}; // Q0 +}; // Q0 /* Search offset for the subbands that use a partial search */ const Word16 subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = { 120, 210 -}; // Q0 +}; // Q0 /* 16.4 kbps */ const Word16 subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR] = { SWB_SB_OFF0_SUB5_16KBPS_HAR, SWB_SB_OFF1_SUB5_16KBPS_HAR, SWB_SB_OFF2_SUB5_16KBPS_HAR, SWB_SB_OFF3_SUB5_16KBPS_HAR -}; // Q0 +}; // Q0 /* Search offset for the subbands that use a partial search */ const Word16 subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = { 120, 210 -}; // Q0 +}; // Q0 /*------------------------------------------------------------------------------* @@ -16323,7 +16323,7 @@ const Word16 expPkEnrg_tbl[45] = 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38 -}; // Q0 +}; // Q0 const Word32 manPkEnrg_tbl[45] = { @@ -16336,7 +16336,7 @@ const Word32 manPkEnrg_tbl[45] = 1073744140, 536870912, 1073744140, 536870912, 1073697800, 536870912, 1073697800, 536870912, 1073883168, 536870912, 1073512448, 536870912, 1073512448, 536870912, 1073512448 -}; // Q0 +}; // Q0 const Word32 E_max5_tbl[40] = { 2047999999, 1448154663, 1024000000, 1448154663, 1024000000, @@ -16347,38 +16347,38 @@ const Word32 E_max5_tbl[40] = 1448156250, 1024000000, 1448156250, 1024000000, 1448156250, 1024000000, 1448156250, 1024000000, 1448125000, 1024000000, 1448125000, 1024000000, 1448250000, 1024000000, 1448000000 -}; // Q0 +}; // Q0 const Word16 resize_huffsizn[32] = { 0, 0, 0, 0, 0, 11, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0 -}; // Q0 +}; // Q0 const Word16 huffsizn[32] = { 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 4, 4, 3, 3, 3, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7 -}; // Q0 +}; // Q0 const Word16 huffnorm_tran[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,122, 10, 6, 1, 0, 3, 2, 26, 58, 186, 442, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; // Q0 +}; // Q0 const Word16 huffsizn_tran[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5, 3, 2, 2, 2, 4, 6, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; // Q0 +}; // Q0 const Word16 pgain_huffsizn[32] = { 10, 11, 10, 10, 9, 8, 6, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 10, 10, 12, 12 -}; // Q0 +}; // Q0 const Word16 dicnlg2_float[40] = { @@ -16386,34 +16386,34 @@ const Word16 dicnlg2_float[40] = 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 -}; // Q0 +}; // Q0 /*** Table for quantization of MLT coefficients ***/ const Word16 norm_order_48[NB_SFM] = { 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 40, 41, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 42, 43, 39, 35, 31, 27, 23, 19, 15, 14, 7, 6 -}; // Q0 +}; // Q0 const Word16 norm_order_32[SFM_N_SWB] = { 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 35, 31, 27, 23, 19, 15, 14, 7, 6 -}; // Q0 +}; // Q0 const Word16 norm_order_16[SFM_N_WB] = { 0, 1, 8, 9, 16, 20, 24, 21, 17, 11, 10, 3, 2, 4, 5, 12, 13, 18, 22, 25, 23, 19, 15, 14, 7, 6 -}; // Q0 +}; // Q0 -const Word16 intl_bw_16[N_INTL_GRP_16] = {16, 16}; // Q0 -const Word16 intl_bw_32[N_INTL_GRP_32] = {16, 24}; // Q0 -const Word16 intl_bw_48[N_INTL_GRP_48] = {16, 24, 32}; // Q0 +const Word16 intl_bw_16[N_INTL_GRP_16] = {16, 16}; // Q0 +const Word16 intl_bw_32[N_INTL_GRP_32] = {16, 24}; // Q0 +const Word16 intl_bw_48[N_INTL_GRP_48] = {16, 24, 32}; // Q0 -const Word16 intl_cnt_16[N_INTL_GRP_16] = {4, 1}; // Q0 -const Word16 intl_cnt_32[N_INTL_GRP_32] = {4, 4}; // Q0 -const Word16 intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; // Q0 +const Word16 intl_cnt_16[N_INTL_GRP_16] = {4, 1}; // Q0 +const Word16 intl_cnt_32[N_INTL_GRP_32] = {4, 4}; // Q0 +const Word16 intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; // Q0 const Word16 band_start_HQ[44] = { @@ -16421,7 +16421,7 @@ const Word16 band_start_HQ[44] = 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, 544, 576, 608, 640, 672, 704, 736, 768 -}; // Q0 +}; // Q0 const Word16 band_end_HQ[44] = { @@ -16429,7 +16429,7 @@ const Word16 band_end_HQ[44] = 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, 544, 576, 608, 640, 672, 704, 736, 768, 800 -}; // Q0 +}; // Q0 const Word16 band_len_HQ[44] = { @@ -16437,29 +16437,29 @@ const Word16 band_len_HQ[44] = 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32 -}; // Q0 +}; // Q0 const Word16 band_start_wb[26] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288 -}; // Q0 +}; // Q0 const Word16 band_end_wb[26] = { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288, 320 -}; // Q0 +}; // Q0 const Word16 band_len_wb[26] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32 -}; // Q0 -const Word16 band_len_harm_float[SFM_N_HARM_FB] = // Q0 +}; // Q0 +const Word16 band_len_harm_float[SFM_N_HARM_FB] = // Q0 { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 96 @@ -16481,8 +16481,8 @@ const Word16 rat_fx[SFM_N_WB] = { 24576, 24576, 24576, 24576, 24576, 24576, 2457 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 13107, 13107 };//Q14 -const Word16 sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; // Q0 -const Word16 a_map[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; // Q0 +const Word16 sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; // Q0 +const Word16 a_map[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; // Q0 const Word32 SQRT_DIM_fx[65] = /* sqrt(x) for x = 0, 1, ..., 64. in Q15 */ @@ -16567,7 +16567,7 @@ const Word16 subf_norm_groups[4][11] = {2,3,10,11,17,21,25,29,33,37,41}, {4,5,12,13,18,22,26,30,34,38,42}, {6,7,14,15,19,23,27,31,35,39,43} -}; // Q0 +}; // Q0 const Word16 gain_att_fx[40] = /* Q=15 */ { @@ -16676,17 +16676,17 @@ const Word32 pow_getbitsfrompulses_fx[16] = /*Q21 */ }; const Word16 DDP_fx[4] = { 3, 0, 1, 2 };//Q0 -const Word16 step_tcq[8][STATES] = { {0,4}, {0,4}, {1,5}, {1,5}, {2,6}, {2,6}, {3,7}, {3,7} }; // Q0 -const Word16 denc[8][STATES] = { {0,2}, {2,0}, {1,3}, {3,1}, {2,0}, {0,2}, {3,1}, {1,3} }; /* enc trellis Q0*/ -const Word16 ddec[8][STATES] = { {0,2}, {1,3}, {2,0}, {3,1}, {2,0}, {3,1}, {0,2}, {1,3} }; /* dec trellis Q0*/ +const Word16 step_tcq[8][STATES] = { {0,4}, {0,4}, {1,5}, {1,5}, {2,6}, {2,6}, {3,7}, {3,7} }; // Q0 +const Word16 denc[8][STATES] = { {0,2}, {2,0}, {1,3}, {3,1}, {2,0}, {0,2}, {3,1}, {1,3} }; /* enc trellis Q0*/ +const Word16 ddec[8][STATES] = { {0,2}, {1,3}, {2,0}, {3,1}, {2,0}, {3,1}, {0,2}, {1,3} }; /* dec trellis Q0*/ -const Word16 step_LSB[STATES_LSB][2] = { {0,1}, {2,3}, {0,1}, {2,3} }; // Q0 -const Word16 denc_LSB[STATES_LSB][2] = { {0,3}, {2,1}, {3,0}, {1,2} }; // Q0 -const Word16 dqnt_LSB[STATES_LSB][4] = { {0,8,1,8}, {0,8,1,8}, {8,0,8,1}, {8,0,8,1} }; // Q0 +const Word16 step_LSB[STATES_LSB][2] = { {0,1}, {2,3}, {0,1}, {2,3} }; // Q0 +const Word16 denc_LSB[STATES_LSB][2] = { {0,3}, {2,1}, {3,0}, {1,2} }; // Q0 +const Word16 dqnt_LSB[STATES_LSB][4] = { {0,8,1,8}, {0,8,1,8}, {8,0,8,1}, {8,0,8,1} }; // Q0 -const Word16 dstep_LSB[4][2] = { {0,2}, {0,2}, {1,3}, {1,3} }; // Q0 -const Word16 ddec_LSB[4][2] = { {0,3}, {3,0}, {2,1}, {1,2} }; // Q0 +const Word16 dstep_LSB[4][2] = { {0,2}, {0,2}, {1,3}, {1,3} }; // Q0 +const Word16 ddec_LSB[4][2] = { {0,3}, {3,0}, {2,1}, {1,2} }; // Q0 const Word16 nextstate[STATES][2] = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {0, 1}, {2, 3}, {4, 5}, {6, 7}};/*current state points to next two states Q0*/ @@ -16695,7 +16695,7 @@ const Word16 nextstate[STATES][2] = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {0, 1}, {2, * PVQ tables *------------------------------------------------------------------------------*/ -const Word16 fine_gain_bits[8] = {0, 0, 0, 1, 2, 2, 4, 5}; // Q0 +const Word16 fine_gain_bits[8] = {0, 0, 0, 1, 2, 2, 4, 5}; // Q0 const Word16 finegain_1_fx[2] = { -12204, 12647 }; /* Q14 */ const Word16 finegain_2_fx[4] = { -17773, -5925, 6010, 18769 }; /* Q14 */ const Word16 finegain_3_fx[8] = { -16384, -11703, -7022, -2341, 2341, 7022, 11703, 16384 }; /* Q14 */ @@ -16714,7 +16714,7 @@ const Word16 finegain_5_fx[32] = /* Q14 */ const Word16* finegain_fx[5] = { finegain_1_fx, finegain_2_fx, finegain_3_fx, finegain_4_fx, finegain_5_fx };/* Q14 */ -const UWord8 hBitsMinus1_N01[2] = {1, 7}; // Q0 +const UWord8 hBitsMinus1_N01[2] = {1, 7}; // Q0 const UWord8 hBitsMinus1_N02[65]= { @@ -16723,7 +16723,7 @@ const UWord8 hBitsMinus1_N02[65]= 60, 61, 62, 63, 63, 64, 65, 65, 67, 68, 69, 69, 70, 71, 72, 72, 73, 74, 75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 84, 85, 86, 87, 87 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N03[65]= { @@ -16732,7 +16732,7 @@ const UWord8 hBitsMinus1_N03[65]= 104, 106, 108, 110, 111, 113, 114, 115, 118, 120, 122, 123, 125, 127, 128, 129, 131, 133, 135, 137, 139, 141, 142, 144, 145, 146, 149, 151, 153, 155, 157, 158, 160 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N04[65]= { @@ -16741,7 +16741,7 @@ const UWord8 hBitsMinus1_N04[65]= 144, 147, 150, 152, 154, 156, 158, 160, 164, 167, 170, 173, 175, 177, 180, 182, 184, 187, 190, 193, 196, 199, 201, 203, 205, 207, 211, 214, 217, 220, 222, 225, 227 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N05[54]= { @@ -16749,101 +16749,101 @@ const UWord8 hBitsMinus1_N05[54]= 131, 134, 136, 139, 141, 144, 148, 152, 155, 158, 161, 164, 167, 170, 172, 176, 181, 184, 188, 191, 194, 197, 200, 202, 207, 211, 215, 219, 222, 225, 228, 231, 233, 238, 242, 246, 250, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N06[42]= { 41, 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, 153, 156, 159, 162, 165, 168, 173, 178, 183, 187, 191, 194, 198, 201, 204, 209, 214, 219, 224, 228, 231, 235, 238, 241, 247, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N07[34]= { 33, 30, 52, 70, 85, 98, 109, 118, 126, 134, 141, 147, 153, 158, 163, 168, 172, 176, 180, 184, 188, 191, 197, 203, 208, 213, 218, 222, 226, 230, 233, 240, 246, 252 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N08[29]= { 28, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, 190, 195, 200, 204, 208, 212, 219, 226, 232, 238, 243, 248, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N09[25]= { 24, 33, 58, 79, 97, 112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, 207, 212, 217, 222, 227, 231, 240, 247, 254 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N10[22]= { 21, 34, 61, 83, 101, 118, 132, 145, 157, 167, 177, 186, 194, 202, 209, 216, 222, 228, 234, 239, 245, 250 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N11[19]= { 18, 35, 63, 86, 106, 123, 139, 152, 165, 176, 187, 197, 206, 214, 222, 230, 237, 243, 250 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N12[17]= { 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N13[16]= { 15, 37, 67, 92, 113, 133, 150, 165, 180, 193, 205, 216, 227, 237, 246, 254, -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N14[14]= { 13, 38, 68, 94, 117, 137, 155, 171, 186, 200, 213, 225, 236, 247 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N15[13]= { 12, 39, 70, 97, 120, 141, 160, 177, 193, 207, 221, 233, 245 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N16[13]= { 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N17[12]= { 11, 40, 73, 101, 126, 148, 168, 187, 204, 220, 234, 248 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N18[12]= { 11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N19[11]= { 10, 41, 75, 105, 131, 154, 176, 196, 214, 231, 247 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N20[11]= { 10, 42, 77, 107, 133, 157, 179, 200, 219, 236, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N21[10]= { 9, 43, 78, 108, 135, 160, 183, 204, 223, 241 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N22[10]= { 9, 43, 79, 110, 138, 163, 186, 207, 227, 246 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N23[10]= { @@ -16853,139 +16853,139 @@ const UWord8 hBitsMinus1_N23[10]= const UWord8 hBitsMinus1_N24[10]= { 9, 44, 81, 113, 142, 168, 192, 214, 235, 255 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N25[9]= { 8, 45, 82, 114, 143, 170, 195, 217, 239 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N26[9]= { 8, 45, 83, 116, 145, 172, 197, 221, 242 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N27[9]= { 8, 46, 84, 117, 147, 175, 200, 224, 246 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N28[9]= { 8, 46, 84, 118, 149, 177, 202, 227, 249 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N29[9]= { 8, 46, 85, 119, 150, 179, 205, 229, 252 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N30[8]= { 7, 47, 86, 121, 152, 181, 207, 232 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N31[8]= { 7, 47, 87, 122, 153, 182, 209, 235 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N32[8]= { 7, 47, 87, 123, 155, 184, 212, 237 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N33[8]= { 7, 48, 88, 124, 156, 186, 214, 240 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N34[8]= { 7, 48, 89, 125, 158, 188, 216, 242 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N35[8]= { 7, 49, 90, 126, 159, 189, 218, 245 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N36[8]= { 7, 49, 90, 127, 160, 191, 220, 247 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N37[8]= { 7, 49, 91, 128, 162, 193, 222, 249 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N38[8]= { 7, 49, 91, 129, 163, 194, 224, 251 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N39[8]= { 7, 50, 92, 130, 164, 196, 225, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N40[8]= { 7, 50, 93, 131, 165, 197, 227, 255 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N41[7]= { 6, 50, 93, 131, 166, 199, 229 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N42[7]= { 6, 51, 94, 132, 167, 200, 230 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N43[7]= { 6, 51, 94, 133, 168, 201, 232 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N44[7]= { 6, 51, 95, 134, 170, 203, 234 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N45[7]= { 6, 51, 95, 135, 171, 204, 235 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N46[7]= { 6, 52, 96, 135, 172, 205, 237 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N47[7]= { 6, 52, 96, 136, 173, 206, 238 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N48[7]= { 6, 52, 97, 137, 174, 208, 240 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N49[7]= { 6, 52, 97, 138, 175, 209, 241 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N50[7]= { 6, 53, 98, 138, 175, 210, 243 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N51[7]= { 6, 53, 98, 139, 176, 211, 244 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N52[7]= { 6, 53, 99, 140, 177, 212, 245 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N53[7]= { 6, 53, 99, 140, 178, 213, 247 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N54[7]= { 6, 54, 100, 141, 179, 214, 248 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N55[7]= { 6, 54, 100, 142, 180, 216, 249 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N56[7]= { 6, 54, 100, 142, 181, 217, 250 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N57[7]= { 6, 54, 101, 143, 181, 218, 252 @@ -16993,31 +16993,31 @@ const UWord8 hBitsMinus1_N57[7]= const UWord8 hBitsMinus1_N58[7]= { 6, 54, 101, 143, 182, 219, 253 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N59[7]= { 6, 55, 102, 144, 183, 220, 254 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N60[7]= { 6, 55, 102, 145, 184, 221, 255 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N61[6]= { 5, 55, 102, 145, 185, 221 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N62[6]= { 5, 55, 103, 146, 185, 222 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N63[6]= { 5, 55, 103, 146, 186, 223 -}; // Q0 +}; // Q0 const UWord8 hBitsMinus1_N64[6]= { 5, 55, 103, 147, 187, 224 -}; // Q0 +}; // Q0 const Word16 dsHighDiracsTab[PVQ_MAX_BAND_SIZE - DS_INDEX_LINEAR_END ] = { 23, 25, 27, 29, 31, 33, 35, 37, 39, @@ -17025,7 +17025,7 @@ const Word16 dsHighDiracsTab[PVQ_MAX_BAND_SIZE - DS_INDEX_LINEAR_END ] = 83, 91, 99, 107, 115, 123, 131, 139, 147, 163, 179, 195, 211, 227, 243, 259, 275, 291, 323, 355, 387, 419, 451, 483, 512 -}; // Q0 +}; // Q0 const UWord32 intLimCDivInvDQ31[67+1] = { @@ -17038,7 +17038,7 @@ const UWord32 intLimCDivInvDQ31[67+1] = 0x02aaaaab, 0x029cbc15, 0x028f5c29, 0x02828283, 0x02762763, 0x026a43a0, 0x025ed098, 0x0253c826, 0x02492493, 0x023ee090, 0x0234f72d, 0x022b63cc, 0x02222223, 0x02192e2a, 0x02108422, 0x02082083, 0x02000000, 0x01f81f82, 0x01f07c20, 0x01e9131b -}; // Q0 +}; // Q0 const UWord8 obtainEnergyQuantizerDensity_f[57] = { @@ -17049,7 +17049,7 @@ const UWord8 obtainEnergyQuantizerDensity_f[57] = 16,18,20,20,22,24,26,30, 32,34,38,42,46,50,54,58, 64,70,76,82,90,98,108,118, 128 -}; // Q0 +}; // Q0 /* (char)ceil(log2(hBitsN[N][0])) - 2) */ @@ -17063,7 +17063,7 @@ const UWord8 f_log2_n[ PVQ_MAX_BAND_SIZE + 1] = 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01}; // Q0 + 0x01}; // Q0 const UWord8 * const hBitsN[ PVQ_MAX_BAND_SIZE + 1 ]= { @@ -17080,7 +17080,7 @@ hBitsMinus1_N45, hBitsMinus1_N46, hBitsMinus1_N47, hBitsMinus1_N48, hBit hBitsMinus1_N50, hBitsMinus1_N51, hBitsMinus1_N52, hBitsMinus1_N53, hBitsMinus1_N54, hBitsMinus1_N55, hBitsMinus1_N56, hBitsMinus1_N57, hBitsMinus1_N58, hBitsMinus1_N59, hBitsMinus1_N60, hBitsMinus1_N61, hBitsMinus1_N62, hBitsMinus1_N63, hBitsMinus1_N64, -}; // Q0 +}; // Q0 const Word16 lim_neg_inv_tbl_fx[MAX_SPLITS + 1 ] = { /* 1 = optimized inv_tbl_fx constant for div by 1, Q15 */ @@ -17109,16 +17109,16 @@ const UWord32 exactdivodd[ODD_DIV_SIZE] = 438261969U, 4210752251U, 2350076445U, 1483715975U, 3089362441U, 2693454067U, 3238827797U, 3204181951U, 3237744577U, 128207979U, 2738819725U, 3811027319U, 3353604601U, 2519714147U, 1059797125U, 1631000239U, 2014922929U, 724452315U, 4244438269U, 1875962727U, 4198451177U, 3539808211U, 1062196213U, 3571604383U -}; // Q0 +}; // Q0 -const Word16 gain_cb_size[MAX_GAIN_BITS] = {2, 4, 8, 16, 32}; // Q0 +const Word16 gain_cb_size[MAX_GAIN_BITS] = {2, 4, 8, 16, 32}; // Q0 -const Word16 inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB Q0*/ +const Word16 inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB Q0*/ const Word16 hq_nominal_scaling_inv[7] = { 0, 8192, 11585, 0, 16384, 0, 20066 }; /*Q13 */ const Word16 hq_nominal_scaling[7] = { 0, 32767, 23170, 0, 16384, 0, 13377 }; /*Q15 */ -const Word16 l_spec_tbl[4] = {L_SPEC8k, L_SPEC16k, L_SPEC32k, L_SPEC48k}; /* corresponds to NB, WB, SWB, FB Q0*/ -const Word16 l_spec_ext_tbl[4] = {0, L_SPEC16k_EXT, L_SPEC32k_EXT, L_SPEC48k_EXT}; /* corresponds to NB, WB, SWB, FB Q0*/ +const Word16 l_spec_tbl[4] = {L_SPEC8k, L_SPEC16k, L_SPEC32k, L_SPEC48k}; /* corresponds to NB, WB, SWB, FB Q0*/ +const Word16 l_spec_ext_tbl[4] = {0, L_SPEC16k_EXT, L_SPEC32k_EXT, L_SPEC48k_EXT}; /* corresponds to NB, WB, SWB, FB Q0*/ const Word16 sinq_16k[3 * L_FRAME16k / 20] =/*Q15 */ { 536, 1608, 2678, 3745, 4808, 5866, 6918, 7962, @@ -17161,29 +17161,29 @@ const Word16 sinq_48k[3 * L_FRAME48k / 20] =/*Q15 */ /* subband width tables */ /* NB short win: 7200/8000/9600, 13200/16400/24400 */ -const Word16 band_width_40_4_6_0_0_0[4] = { 6, 8, 11, 15 }; // Q0 -const Word16 band_width_40_5_6_0_0_0[5] = { 6, 7, 7, 9, 11 }; // Q0 +const Word16 band_width_40_4_6_0_0_0[4] = { 6, 8, 11, 15 }; // Q0 +const Word16 band_width_40_5_6_0_0_0[5] = { 6, 7, 7, 9, 11 }; // Q0 /* NB long win: 7200, 8000, 9600, 13200, 16400 */ -const Word16 band_width_160_13_6_2_0_0[13] = { 6, 6, 6, 6, 7, 8, 9, 10, 13, 15, 19, 24, 31 }; // Q0 -const Word16 band_width_160_14_6_3_0_0[14] = { 6, 6, 6, 6, 6, 7, 8, 9, 10, 12, 15, 18, 22, 29 }; // Q0 -const Word16 band_width_160_17_6_3_0_0[17] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 13, 15, 17, 19 }; // Q0 -const Word16 band_width_160_18_6_4_0_0[18] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 15, 17 }; // Q0 +const Word16 band_width_160_13_6_2_0_0[13] = { 6, 6, 6, 6, 7, 8, 9, 10, 13, 15, 19, 24, 31 }; // Q0 +const Word16 band_width_160_14_6_3_0_0[14] = { 6, 6, 6, 6, 6, 7, 8, 9, 10, 12, 15, 18, 22, 29 }; // Q0 +const Word16 band_width_160_17_6_3_0_0[17] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 13, 15, 17, 19 }; // Q0 +const Word16 band_width_160_18_6_4_0_0[18] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 15, 17 }; // Q0 /* WB short win: 13200/16400/24400 */ -const Word16 band_width_80_7_6_0_0_0[7] = { 6, 7, 8, 10, 12, 16, 21 }; // Q0 +const Word16 band_width_80_7_6_0_0_0[7] = { 6, 7, 8, 10, 12, 16, 21 }; // Q0 /* WB long win: 13200, 16400 */ -const Word16 band_width_320_18_6_3_0_0[18] = { 6, 6, 6, 6, 6, 7, 7, 8, 10, 11, 13, 16, 19, 24, 30, 37, 47, 61 }; // Q0 -const Word16 band_width_320_20_6_3_0_0[20] = { 6, 6, 6, 6, 6, 6, 7, 8, 8, 9, 11, 12, 14, 17, 20, 23, 28, 34, 42, 51 }; // Q0 +const Word16 band_width_320_18_6_3_0_0[18] = { 6, 6, 6, 6, 6, 7, 7, 8, 10, 11, 13, 16, 19, 24, 30, 37, 47, 61 }; // Q0 +const Word16 band_width_320_20_6_3_0_0[20] = { 6, 6, 6, 6, 6, 6, 7, 8, 8, 9, 11, 12, 14, 17, 20, 23, 28, 34, 42, 51 }; // Q0 /* SWB short win: 13200, 16400 */ -const Word16 band_width_142_8_8_0_0_0[8] = {7,8,10,11,15,21,29,41}; // Q0 -const Word16 band_width_160_8_8_0_0_0[8] = { 8, 9, 11,13,17,23,32,47}; // Q0 +const Word16 band_width_142_8_8_0_0_0[8] = {7,8,10,11,15,21,29,41}; // Q0 +const Word16 band_width_160_8_8_0_0_0[8] = { 8, 9, 11,13,17,23,32,47}; // Q0 /* SWB long win: 13200, 16400 */ -const Word16 band_width_568_22_6_2_0_0[22] = { 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 13, 16, 19, 23, 28, 34, 42, 55, 68, 84, 105}; // Q0 -const Word16 band_width_640_24_6_4_0_0[24] = { 6, 6, 6, 6, 6, 6, 7,7,8,9,10,11,13,15,18,21,26,32,39,48,59, 74,92,115}; // Q0 +const Word16 band_width_568_22_6_2_0_0[22] = { 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 13, 16, 19, 23, 28, 34, 42, 55, 68, 84, 105}; // Q0 +const Word16 band_width_640_24_6_4_0_0[24] = { 6, 6, 6, 6, 6, 6, 7,7,8,9,10,11,13,15,18,21,26,32,39,48,59, 74,92,115}; // Q0 /* LR-MDCT: NB configuration tables */ const Xcore_Config xcore_config_8kHz_007200bps_long = { 13, L_FRAME8k, band_width_160_13_6_2_0_0, 536870912L, 24576, 24576/*eref*/, 13107, 13107/*bit_alloc_weight*/, 2, 2, 0, 0 /*p2a_th*/, 13107/*pd_thresh*/, 4260/*ld_slope*/, 19661/*ni_coef*/ }; @@ -17215,7 +17215,7 @@ const Word16 Nb[ NB_SFM] = 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32 -}; // Q0 +}; // Q0 /* log2(Nb) to calculate minimum bits for one pulse in PVQ */ const Word16 LNb[ NB_SFM] = @@ -17223,30 +17223,30 @@ const Word16 LNb[ NB_SFM] = 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 -}; // Q0 +}; // Q0 /*------------------------------------------------------------------------------* * GSC tables *------------------------------------------------------------------------------*/ -const Word16 gsc_sfm_start[MBANDS_GN] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240}; // Q0 +const Word16 gsc_sfm_start[MBANDS_GN] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240}; // Q0 -const Word16 gsc_sfm_end[MBANDS_GN] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256}; // Q0 +const Word16 gsc_sfm_end[MBANDS_GN] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256}; // Q0 -const Word16 gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; // Q0 +const Word16 gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; // Q0 const Word16 sm_table_fx[] = { - 32767, 32126, 31480, 30838, 30196, 29557, 28918, 28279, 27643, 27007, - 26375, 25746, 25120, 24494, 23875, 23255, 22643, 22033, 21427, 20824, - 20228, 19638, 19048, 18468, 17891, 17321, 16758, 16197, 15647, 15103, - 14562, 14031, 13507, 12989, 12481, 11980, 11488, 11000, 10525, 10056, - 9598, 9146, 8706, 8274, 7851, 7438, 7035, 6642, 6259, 5885, - 5521, 5171, 4830, 4499, 4178, 3870, 3572, 3287, 3011, 2746, - 2494, 2254, 2025, 1809, 1602, 1412, 1229, 1062, 904, 760, - 629, 511, 403, 308, 226, 157, 102, 56, 26, 7, -}; // Q15 + 32767, 32126, 31480, 30838, 30196, 29557, 28918, 28279, 27643, 27007, + 26375, 25746, 25120, 24494, 23875, 23255, 22643, 22033, 21427, 20824, + 20228, 19638, 19048, 18468, 17891, 17321, 16758, 16197, 15647, 15103, + 14562, 14031, 13507, 12989, 12481, 11980, 11488, 11000, 10525, 10056, + 9598, 9146, 8706, 8274, 7851, 7438, 7035, 6642, 6259, 5885, + 5521, 5171, 4830, 4499, 4178, 3870, 3572, 3287, 3011, 2746, + 2494, 2254, 2025, 1809, 1602, 1412, 1229, 1062, 904, 760, + 629, 511, 403, 308, 226, 157, 102, 56, 26, 7, +}; // Q15 const Word16 GSC_freq_bits[] = { @@ -17263,21 +17263,21 @@ const Word16 GSC_freq_bits[] = 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_22k60*/ 26, 96, 0, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4 /* ACELP_24k40*/ -}; // Q0 +}; // Q0 const Word32 GSC_freq_bits_fx[] =/*Q18*/ { - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_5k00*/ - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_6k15*/ - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_7k20*/ - 5505024, 19660800, -1048576, 6815744, 4194304, 3145728, 2883584, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ - 6815744, 20971520, -786432, 7340032, 4718592, 3407872, 3145728, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_11k60*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k15*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k85*/ - 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_14k80*/ - 8126464, 25165824, -262144, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ - 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ - 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ + 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_5k00*/ + 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_6k15*/ + 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_7k20*/ + 5505024, 19660800, -1048576, 6815744, 4194304, 3145728, 2883584, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ + 6815744, 20971520, -786432, 7340032, 4718592, 3407872, 3145728, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ + 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_11k60*/ + 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k15*/ + 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k85*/ + 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_14k80*/ + 8126464, 25165824, -262144, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ + 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ + 8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/ }; const Word32 GSC_freq_bits_fx_Q18[] =/*Q18*/ @@ -17299,9 +17299,9 @@ const Word32 GSC_freq_bits_fx_Q18[] =/*Q18*/ const Word16 Compl_GSC_freq_bits[] = { 5, 10, 10, 10 /* bitrate > ACELP_16k40 && FS = 16kHz */ -}; // Q0 +}; // Q0 -const Word16 mfreq_bindiv_loc[] = { 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; // Q0 +const Word16 mfreq_bindiv_loc[] = { 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; // Q0 const Word16 mean_gp_fx[] = { 9590 }; /*Q14*/ @@ -17319,507 +17319,507 @@ const Word16 Gain_meanNB_fx[] = const Word16 Gain_mean_dicNB_fx[1 * 64] = /*Q12 */ { - -1309, -931, -568, -396, -54, 807, 1174, 1533, - 1901, 2092, 2286, 2493, 2698, 3130, 2909, 286, - -748, 990, 631, -1119, -1697, -2114, -2788, -5399, - -9841, -1902, -3270, -7975, -7438, -6926, -7192, -2325, - -1504, -2549, -3022, -3532, -3818, -4136, -4751, -5071, - -5756, -6093, -8998, -6389, -8765, -9438, 3369, 3917, - 3619, 4684, -8264, 4255, -4433, -6662, -9230, -7678, - 5859, 118, 457, -227, 1717, 1353, -8499, -9649 + -1309, -931, -568, -396, -54, 807, 1174, 1533, + 1901, 2092, 2286, 2493, 2698, 3130, 2909, 286, + -748, 990, 631, -1119, -1697, -2114, -2788, -5399, + -9841, -1902, -3270, -7975, -7438, -6926, -7192, -2325, + -1504, -2549, -3022, -3532, -3818, -4136, -4751, -5071, + -5756, -6093, -8998, -6389, -8765, -9438, 3369, 3917, + 3619, 4684, -8264, 4255, -4433, -6662, -9230, -7678, + 5859, 118, 457, -227, 1717, 1353, -8499, -9649 }; const Word16 Mean_dic_NB_fx[1 * 10] = /*Q12 */ { - -444, -100, -120, -37, 25, - 70, 148, 63, 170, 229 + -444, -100, -120, -37, 25, + 70, 148, 63, 170, 229 }; const Word16 Gain_dic1_NB_fx[3 * 64] = /*Q12 */ { - -606, -92, 5, - -1965, 294, 666, - -440, 119, 661, - -106, 267, 108, - -1213, 345, -136, - -1251, 618, 566, - -1905, -750, 648, - -1043, -360, -498, - -18, -322, 96, - 334, 116, -247, - -1929, 660, 23, - -1845, 1178, 485, - -180, 836, 167, - -1892, -922, -321, - 416, -437, -344, - 595, -548, 158, - -265, -807, -338, - -1065, -1015, -20, - -626, 595, -333, - -569, 1090, 651, - 27, 587, -331, - -184, -85, -503, - -1902, -1807, 326, - -1861, -159, -989, - -666, 143, -1163, - -1718, 1031, -744, - 847, 301, -59, - 720, -1001, -216, - 1380, -866, -969, - 803, -4, -608, - 233, 408, -998, - 1459, 87, 263, - 345, -615, -1026, - 877, -148, -7, - 68, -1075, 270, - 802, 329, 475, - -1923, -126, -38, - 1275, -419, -349, - 401, 926, 575, - 846, -233, 547, - 693, -1880, 356, - -362, -1683, -219, - 231, -339, 598, - 1227, -616, 267, - 1116, 91, -1316, - -551, -650, 530, - 444, 32, 181, - -384, 1207, -775, - -993, 1163, 41, - 784, -1018, 538, - 635, 636, -424, - 1373, -1367, 149, - 1442, 401, -444, - 1094, 888, 123, - 874, 1113, -1082, - -646, -1112, -1103, - 539, -1632, -683, - 402, 571, 99, - -1778, -1809, -849, - -732, -1691, 700, - -678, 526, 274, - 320, 1227, -118, - -1222, -180, 454, - 173, 349, 530 + -606, -92, 5, + -1965, 294, 666, + -440, 119, 661, + -106, 267, 108, + -1213, 345, -136, + -1251, 618, 566, + -1905, -750, 648, + -1043, -360, -498, + -18, -322, 96, + 334, 116, -247, + -1929, 660, 23, + -1845, 1178, 485, + -180, 836, 167, + -1892, -922, -321, + 416, -437, -344, + 595, -548, 158, + -265, -807, -338, + -1065, -1015, -20, + -626, 595, -333, + -569, 1090, 651, + 27, 587, -331, + -184, -85, -503, + -1902, -1807, 326, + -1861, -159, -989, + -666, 143, -1163, + -1718, 1031, -744, + 847, 301, -59, + 720, -1001, -216, + 1380, -866, -969, + 803, -4, -608, + 233, 408, -998, + 1459, 87, 263, + 345, -615, -1026, + 877, -148, -7, + 68, -1075, 270, + 802, 329, 475, + -1923, -126, -38, + 1275, -419, -349, + 401, 926, 575, + 846, -233, 547, + 693, -1880, 356, + -362, -1683, -219, + 231, -339, 598, + 1227, -616, 267, + 1116, 91, -1316, + -551, -650, 530, + 444, 32, 181, + -384, 1207, -775, + -993, 1163, 41, + 784, -1018, 538, + 635, 636, -424, + 1373, -1367, 149, + 1442, 401, -444, + 1094, 888, 123, + 874, 1113, -1082, + -646, -1112, -1103, + 539, -1632, -683, + 402, 571, 99, + -1778, -1809, -849, + -732, -1691, 700, + -678, 526, 274, + 320, 1227, -118, + -1222, -180, 454, + 173, 349, 530 }; const Word16 Gain_dic2_NB_fx[3 * 32] = /*Q12 */ { - 28, 0, -66, - -557, 4, 206, - 281, -642, 36, - -417, 81, -494, - -380, 684, 450, - 521, -1544, 258, - -1119, 613, -1151, - 514, 24, 797, - 292, -84, -526, - 296, 418, -231, - -419, -68, 976, - 2, -308, 398, - -456, -1007, 263, - -1221, -371, 446, - -221, -390, -181, - -1210, 588, 751, - -1093, 528, -174, - 590, 372, -1271, - -79, -251, -1241, - -1016, -487, -512, - 542, 581, 338, - -265, 456, -105, - 490, -71, 89, - 42, 235, 379, - 31, 1194, -202, - 173, -839, 850, - -46, 500, -802, - 152, 933, 1073, - 980, 345, -263, - 807, -580, -521, - -23, -992, -585, - 876, -576, 411 + 28, 0, -66, + -557, 4, 206, + 281, -642, 36, + -417, 81, -494, + -380, 684, 450, + 521, -1544, 258, + -1119, 613, -1151, + 514, 24, 797, + 292, -84, -526, + 296, 418, -231, + -419, -68, 976, + 2, -308, 398, + -456, -1007, 263, + -1221, -371, 446, + -221, -390, -181, + -1210, 588, 751, + -1093, 528, -174, + 590, 372, -1271, + -79, -251, -1241, + -1016, -487, -512, + 542, 581, 338, + -265, 456, -105, + 490, -71, 89, + 42, 235, 379, + 31, 1194, -202, + 173, -839, 850, + -46, 500, -802, + 152, 933, 1073, + 980, 345, -263, + 807, -580, -521, + -23, -992, -585, + 876, -576, 411 }; const Word16 Gain_dic3_NB_fx[4 * 16] = /*Q12 */ { - -16, 65, -227, 11, - -214, 553, 366, 185, - 137, -338, -300, -625, - -122, 82, 538, -797, - 160, 285, -1103, 35, - -594, 312, -379, -423, - 169, -642, -395, 363, - 351, -1166, 630, -261, - -1190, 217, 416, 187, - -577, 244, -636, 858, - 580, 482, -220, 635, - 475, -188, 372, 27, - -65, -369, 504, 910, - -423, -442, 124, -40, - 480, 575, -41, -651, - 682, 680, 910, 489 + -16, 65, -227, 11, + -214, 553, 366, 185, + 137, -338, -300, -625, + -122, 82, 538, -797, + 160, 285, -1103, 35, + -594, 312, -379, -423, + 169, -642, -395, 363, + 351, -1166, 630, -261, + -1190, 217, 416, 187, + -577, 244, -636, 858, + 580, 482, -220, 635, + 475, -188, 372, 27, + -65, -369, 504, 910, + -423, -442, 124, -40, + 480, 575, -41, -651, + 682, 680, 910, 489 }; const Word16 Gain_dic2_NBHR_fx[3 * 64] = /*Q12 */ { - 29, 0, -94, - -605, -202, -174, - 324, -380, -163, - -126, -301, -306, - -288, 124, 112, - -86, 524, -115, - 234, 18, -464, - -55, -281, 179, - 161, 446, 632, - 366, -82, 97, - 228, -1149, 270, - 293, 286, -143, - -123, -35, -896, - -540, -675, 175, - 331, -483, -687, - -779, 204, -668, - -492, 768, -510, - -1215, -620, -483, - 681, -76, -296, - -671, 396, -45, - -759, 298, 564, - -284, 589, 321, - -1366, -592, 496, - -448, -585, -712, - 12, -756, -90, - 513, 167, -927, - -1172, 1060, -1198, - -477, 748, 1006, - 42, 103, 1277, - -940, 1049, 138, - -924, -14, -1469, - 684, 679, -1580, - 417, -374, -1572, - 607, 270, 256, - 567, 778, 843, - 1414, -223, -542, - 97, 200, 251, - 222, 1074, -547, - -714, -285, 1046, - 386, -684, 984, - 338, 674, 116, - -274, 171, -368, - 581, -1871, 342, - 94, 442, -597, - -293, -1205, 851, - -127, 501, -1247, - 175, 1700, 1357, - -24, 1224, 285, - 707, -952, -293, - 668, 492, -407, - 1164, 751, 201, - 381, -595, 288, - -1570, 481, -531, - -597, -160, 326, - -578, -1311, -40, - -118, -523, 576, - -1513, 527, 757, - -184, 40, 609, - -1215, 98, 68, - -65, -1324, -836, - 821, -299, 204, - 796, 21, 840, - 310, -133, 542, - 1042, -974, 537 + 29, 0, -94, + -605, -202, -174, + 324, -380, -163, + -126, -301, -306, + -288, 124, 112, + -86, 524, -115, + 234, 18, -464, + -55, -281, 179, + 161, 446, 632, + 366, -82, 97, + 228, -1149, 270, + 293, 286, -143, + -123, -35, -896, + -540, -675, 175, + 331, -483, -687, + -779, 204, -668, + -492, 768, -510, + -1215, -620, -483, + 681, -76, -296, + -671, 396, -45, + -759, 298, 564, + -284, 589, 321, + -1366, -592, 496, + -448, -585, -712, + 12, -756, -90, + 513, 167, -927, + -1172, 1060, -1198, + -477, 748, 1006, + 42, 103, 1277, + -940, 1049, 138, + -924, -14, -1469, + 684, 679, -1580, + 417, -374, -1572, + 607, 270, 256, + 567, 778, 843, + 1414, -223, -542, + 97, 200, 251, + 222, 1074, -547, + -714, -285, 1046, + 386, -684, 984, + 338, 674, 116, + -274, 171, -368, + 581, -1871, 342, + 94, 442, -597, + -293, -1205, 851, + -127, 501, -1247, + 175, 1700, 1357, + -24, 1224, 285, + 707, -952, -293, + 668, 492, -407, + 1164, 751, 201, + 381, -595, 288, + -1570, 481, -531, + -597, -160, 326, + -578, -1311, -40, + -118, -523, 576, + -1513, 527, 757, + -184, 40, 609, + -1215, 98, 68, + -65, -1324, -836, + 821, -299, 204, + 796, 21, 840, + 310, -133, 542, + 1042, -974, 537 }; const Word16 Gain_dic3_NBHR_fx[4 * 128] = /*Q12 */ { - 293, 7, -202, -95, - 535, 110, 542, -512, - -578, 65, -560, -345, - 206, 332, 10, -533, - -76, 356, -14, 83, - 149, -372, -195, -490, - -478, -241, -55, 113, - -293, -470, -606, 62, - 797, -1448, 625, -1128, - 173, 464, -1686, -49, - -392, -295, -159, -464, - -715, 420, -146, -984, - -36, 28, -484, 119, - 472, 272, -729, -116, - 68, -87, -628, -429, - 429, -918, -158, -191, - -545, 230, -435, 261, - -128, 15, -791, 612, - 268, -387, -1258, 102, - 378, 238, 301, 3, - -494, 149, 131, -124, - 634, -308, 99, 24, - 572, 711, 754, -1137, - -1109, 400, 1093, 369, - -831, -423, 1583, 1089, - -83, 156, -105, 1078, - -930, 476, 152, 380, - 776, 1162, 788, -43, - 279, 50, 408, 597, - 476, 483, 73, 749, - 903, 686, 80, -411, - 195, -768, 280, 344, - -263, -999, -46, -284, - -66, 263, 315, -1239, - 435, 578, -234, -1169, - 199, -1669, 188, 114, - -57, 419, -509, -633, - 98, -119, 129, -816, - -157, -365, -249, 537, - 67, -624, 121, 1153, - 1444, 142, -584, 38, - 1086, -84, 162, 994, - 392, -384, -124, 533, - 252, 183, -1161, -885, - -431, -829, 102, 432, - -708, 987, -1021, -644, - -64, 120, -1684, 985, - 210, -494, -906, 1302, - 50, -186, 177, 185, - -256, 872, -1004, 387, - 564, -80, -679, 515, - -763, -40, -1174, 228, - -1029, 199, -59, -297, - 30, -47, 198, -264, - -396, -1435, 913, -1018, - -141, 962, 36, 458, - 36, -388, 776, -1000, - -74, 489, 1137, 140, - -970, -766, 666, -117, - 90, 599, 1665, 1405, - -313, -685, -764, -615, - 563, -462, -627, -768, - 792, 560, -1445, 556, - -581, 721, -559, 1137, - -699, -273, 274, -846, - 940, -690, 747, -253, - -177, -541, 1355, -217, - -586, 427, 1196, -868, - 147, 532, -550, 405, - 258, 677, -245, -166, - 772, 1062, -331, 482, - 388, 1870, -576, 1585, - 462, 865, 454, 1212, - 570, 528, -681, 1229, - -386, 607, 599, 865, - -154, -20, -211, -231, - 96, 736, 408, -259, - 763, -1533, 1094, 249, - 705, -1132, 1757, -1082, - 310, -481, 329, -395, - 194, -781, 59, -954, - -933, -957, -25, 1866, - -852, -224, -482, 822, - -1438, 490, 221, 1281, - 392, 677, 539, 347, - 884, -614, 1844, 678, - -773, 484, -928, 2477, - -274, -461, 378, -263, - -283, -312, 583, 342, - 453, -1541, 378, 1266, - 778, 1095, 1290, 824, - -958, -443, -208, -71, - 985, -1001, -123, 473, - 56, -1003, -513, 474, - -259, 1435, 975, 315, - -59, -169, 724, 961, - -210, 1030, 341, -977, - 1054, 2917, -7, -877, - -852, -228, 330, 625, - 9, -524, -97, -14, - 16, -50, 476, 2406, - 264, -238, 768, 56, - 187, 108, -169, 446, - 673, 238, 992, 671, - -218, 285, 485, 181, - 669, -526, 639, 571, - 650, 20, -188, -516, - 1031, 165, 526, 136, - -333, 307, 102, -569, - -157, 309, -934, -121, - -336, 141, 39, 536, - 662, 364, -133, 222, - -1284, 637, -636, 77, - 1241, 846, 467, 638, - 842, 328, 1330, -320, - 152, -1009, 550, -215, - -772, 13, 594, -122, - 336, -410, -547, -2, - 869, -106, 321, -1180, - 516, 1247, -828, -577, - -670, 873, 367, -132, - -415, 630, -287, -164, - -105, 138, 657, -441, - -160, -1085, 940, 704, - -128, -68, -369, -1052, - -1434, 594, 546, -665, - -1849, 75, 175, 174, - -1283, 729, -1590, 1032 + 293, 7, -202, -95, + 535, 110, 542, -512, + -578, 65, -560, -345, + 206, 332, 10, -533, + -76, 356, -14, 83, + 149, -372, -195, -490, + -478, -241, -55, 113, + -293, -470, -606, 62, + 797, -1448, 625, -1128, + 173, 464, -1686, -49, + -392, -295, -159, -464, + -715, 420, -146, -984, + -36, 28, -484, 119, + 472, 272, -729, -116, + 68, -87, -628, -429, + 429, -918, -158, -191, + -545, 230, -435, 261, + -128, 15, -791, 612, + 268, -387, -1258, 102, + 378, 238, 301, 3, + -494, 149, 131, -124, + 634, -308, 99, 24, + 572, 711, 754, -1137, + -1109, 400, 1093, 369, + -831, -423, 1583, 1089, + -83, 156, -105, 1078, + -930, 476, 152, 380, + 776, 1162, 788, -43, + 279, 50, 408, 597, + 476, 483, 73, 749, + 903, 686, 80, -411, + 195, -768, 280, 344, + -263, -999, -46, -284, + -66, 263, 315, -1239, + 435, 578, -234, -1169, + 199, -1669, 188, 114, + -57, 419, -509, -633, + 98, -119, 129, -816, + -157, -365, -249, 537, + 67, -624, 121, 1153, + 1444, 142, -584, 38, + 1086, -84, 162, 994, + 392, -384, -124, 533, + 252, 183, -1161, -885, + -431, -829, 102, 432, + -708, 987, -1021, -644, + -64, 120, -1684, 985, + 210, -494, -906, 1302, + 50, -186, 177, 185, + -256, 872, -1004, 387, + 564, -80, -679, 515, + -763, -40, -1174, 228, + -1029, 199, -59, -297, + 30, -47, 198, -264, + -396, -1435, 913, -1018, + -141, 962, 36, 458, + 36, -388, 776, -1000, + -74, 489, 1137, 140, + -970, -766, 666, -117, + 90, 599, 1665, 1405, + -313, -685, -764, -615, + 563, -462, -627, -768, + 792, 560, -1445, 556, + -581, 721, -559, 1137, + -699, -273, 274, -846, + 940, -690, 747, -253, + -177, -541, 1355, -217, + -586, 427, 1196, -868, + 147, 532, -550, 405, + 258, 677, -245, -166, + 772, 1062, -331, 482, + 388, 1870, -576, 1585, + 462, 865, 454, 1212, + 570, 528, -681, 1229, + -386, 607, 599, 865, + -154, -20, -211, -231, + 96, 736, 408, -259, + 763, -1533, 1094, 249, + 705, -1132, 1757, -1082, + 310, -481, 329, -395, + 194, -781, 59, -954, + -933, -957, -25, 1866, + -852, -224, -482, 822, + -1438, 490, 221, 1281, + 392, 677, 539, 347, + 884, -614, 1844, 678, + -773, 484, -928, 2477, + -274, -461, 378, -263, + -283, -312, 583, 342, + 453, -1541, 378, 1266, + 778, 1095, 1290, 824, + -958, -443, -208, -71, + 985, -1001, -123, 473, + 56, -1003, -513, 474, + -259, 1435, 975, 315, + -59, -169, 724, 961, + -210, 1030, 341, -977, + 1054, 2917, -7, -877, + -852, -228, 330, 625, + 9, -524, -97, -14, + 16, -50, 476, 2406, + 264, -238, 768, 56, + 187, 108, -169, 446, + 673, 238, 992, 671, + -218, 285, 485, 181, + 669, -526, 639, 571, + 650, 20, -188, -516, + 1031, 165, 526, 136, + -333, 307, 102, -569, + -157, 309, -934, -121, + -336, 141, 39, 536, + 662, 364, -133, 222, + -1284, 637, -636, 77, + 1241, 846, 467, 638, + 842, 328, 1330, -320, + 152, -1009, 550, -215, + -772, 13, 594, -122, + 336, -410, -547, -2, + 869, -106, 321, -1180, + 516, 1247, -828, -577, + -670, 873, 367, -132, + -415, 630, -287, -164, + -105, 138, 657, -441, + -160, -1085, 940, 704, + -128, -68, -369, -1052, + -1434, 594, 546, -665, + -1849, 75, 175, 174, + -1283, 729, -1590, 1032 }; const Word16 YG_mean16_fx[1 * 16] = /*Q12 */ { - -396, -192, -168, -136, -60, -17, 45, 39, - 120, 81, 90, 67, 147, 34, 163, 184 + -396, -192, -168, -136, -60, -17, 45, 39, + 120, 81, 90, 67, 147, 34, 163, 184 }; const Word16 YG_dicMR_1_fx[4 * 64] = /*Q12 */ { - -1879, 826, 539, -210, - -120, 267, -137, -142, - -798, -473, 434, 243, - 297, -896, 369, 307, - -1883, -1333, 416, 510, - -1955, -660, -471, 224, - -905, -804, -517, 433, - -961, 20, -258, -224, - 209, 977, -213, -17, - 536, -244, 159, 97, - -265, 775, 412, -327, - 337, -391, -237, -472, - -1962, -1836, -692, 471, - 625, 173, -463, -15, - -965, 263, 62, 600, - -782, 889, -433, 211, - -1791, 852, -453, -776, - -182, -177, -1078, 80, - -364, 350, 280, 293, - -902, 1119, 295, -1194, - 16, 440, -342, 459, - -1825, -1584, -1382, -798, - 723, 57, -1235, -661, - 888, -1638, 277, 234, - 340, 345, 141, -610, - 1280, -23, 17, 144, - -639, -852, -520, -553, - 1032, 843, 149, 435, - 581, 783, 519, -196, - 457, 945, 498, -1289, - -1897, -41, 425, 514, - 787, 161, 506, 385, - -559, 1079, 319, 515, - 500, 340, 60, 106, - 251, -997, -1163, -960, - 261, -1288, -631, 335, - 1241, -620, -387, -662, - 167, 194, 476, 67, - 830, -261, 430, -1201, - -479, -123, 71, -1162, - 225, -1482, 132, -802, - 680, 763, -1010, 429, - 200, -125, 261, 590, - 771, -740, -183, 229, - -1860, -348, 278, -549, - -1768, 967, 281, 594, - -1727, -1697, 87, -764, - 1169, 631, -114, -471, - -1636, -101, -1324, -91, - 821, -745, 458, -264, - 1014, -576, 390, 470, - 1041, -517, -1018, 367, - 826, 17, 426, -326, - -467, -1641, 201, 325, - -1906, 428, -338, 222, - -1021, 630, 419, -75, - -86, -379, -203, 234, - 659, 527, -491, -1507, - -564, -1745, -979, -173, - -1764, -433, -743, -1090, - 242, 709, 269, 497, - 716, 74, -208, 618, - -297, 645, -864, -805, - -46, -326, 412, -296 + -1879, 826, 539, -210, + -120, 267, -137, -142, + -798, -473, 434, 243, + 297, -896, 369, 307, + -1883, -1333, 416, 510, + -1955, -660, -471, 224, + -905, -804, -517, 433, + -961, 20, -258, -224, + 209, 977, -213, -17, + 536, -244, 159, 97, + -265, 775, 412, -327, + 337, -391, -237, -472, + -1962, -1836, -692, 471, + 625, 173, -463, -15, + -965, 263, 62, 600, + -782, 889, -433, 211, + -1791, 852, -453, -776, + -182, -177, -1078, 80, + -364, 350, 280, 293, + -902, 1119, 295, -1194, + 16, 440, -342, 459, + -1825, -1584, -1382, -798, + 723, 57, -1235, -661, + 888, -1638, 277, 234, + 340, 345, 141, -610, + 1280, -23, 17, 144, + -639, -852, -520, -553, + 1032, 843, 149, 435, + 581, 783, 519, -196, + 457, 945, 498, -1289, + -1897, -41, 425, 514, + 787, 161, 506, 385, + -559, 1079, 319, 515, + 500, 340, 60, 106, + 251, -997, -1163, -960, + 261, -1288, -631, 335, + 1241, -620, -387, -662, + 167, 194, 476, 67, + 830, -261, 430, -1201, + -479, -123, 71, -1162, + 225, -1482, 132, -802, + 680, 763, -1010, 429, + 200, -125, 261, 590, + 771, -740, -183, 229, + -1860, -348, 278, -549, + -1768, 967, 281, 594, + -1727, -1697, 87, -764, + 1169, 631, -114, -471, + -1636, -101, -1324, -91, + 821, -745, 458, -264, + 1014, -576, 390, 470, + 1041, -517, -1018, 367, + 826, 17, 426, -326, + -467, -1641, 201, 325, + -1906, 428, -338, 222, + -1021, 630, 419, -75, + -86, -379, -203, 234, + 659, 527, -491, -1507, + -564, -1745, -979, -173, + -1764, -433, -743, -1090, + 242, 709, 269, 497, + 716, 74, -208, 618, + -297, 645, -864, -805, + -46, -326, 412, -296 }; const Word16 YG_dicMR_2_fx[4 * 32] = /*Q12 */ { - 93, 217, -122, 37, - -13, -83, 105, -491, - -398, -592, 399, -160, - 543, -81, -470, 408, - 394, -630, -94, -258, - -665, 133, -136, -125, - 397, -351, 630, -148, - -1166, 406, -865, 554, - -136, -302, -263, 81, - -674, -657, -571, -691, - -206, 381, -699, 122, - 272, -1506, 356, 15, - 451, -961, 638, -1133, - 316, -787, 165, 585, - 312, -144, 185, 274, - 39, -706, -997, 250, - -915, -871, -114, 458, - -834, 348, 364, -1188, - 450, 723, -256, 412, - 369, 468, -1371, 416, - 344, 164, 290, -1094, - 664, 122, 34, -218, - 555, 254, 559, 825, - 312, 492, 496, -27, - -399, 315, 690, -330, - -458, 710, 206, 415, - 290, 89, -662, -467, - -72, 593, -108, -460, - -217, 46, 319, 189, - -1366, 199, 365, 62, - -552, -166, 772, 861, - -159, 120, -215, 775 + 93, 217, -122, 37, + -13, -83, 105, -491, + -398, -592, 399, -160, + 543, -81, -470, 408, + 394, -630, -94, -258, + -665, 133, -136, -125, + 397, -351, 630, -148, + -1166, 406, -865, 554, + -136, -302, -263, 81, + -674, -657, -571, -691, + -206, 381, -699, 122, + 272, -1506, 356, 15, + 451, -961, 638, -1133, + 316, -787, 165, 585, + 312, -144, 185, 274, + 39, -706, -997, 250, + -915, -871, -114, 458, + -834, 348, 364, -1188, + 450, 723, -256, 412, + 369, 468, -1371, 416, + 344, 164, 290, -1094, + 664, 122, 34, -218, + 555, 254, 559, 825, + 312, 492, 496, -27, + -399, 315, 690, -330, + -458, 710, 206, 415, + 290, 89, -662, -467, + -72, 593, -108, -460, + -217, 46, 319, 189, + -1366, 199, 365, 62, + -552, -166, 772, 861, + -159, 120, -215, 775 }; const Word16 YG_dicMR_3_fx[4 * 32] = /*Q12 */ { - -103, -143, -85, -19, - -404, 182, -795, 84, - 398, -594, -55, -256, - 283, 128, -472, 279, - -246, -628, 281, 297, - -853, 468, 358, -915, - 272, 149, 209, -443, - -168, -504, 452, -525, - 624, -427, 779, 117, - 1079, 404, -98, 80, - 136, 165, 142, -1394, - 513, -566, -150, 822, - 124, 646, 199, 272, - -165, -702, -615, 165, - 333, 810, -457, 1038, - -360, 105, -110, 537, - -224, 125, 562, -26, - 699, -1105, 809, -1323, - -1229, 841, -767, 571, - -310, 437, -114, -230, - -1045, 630, 564, 322, - 282, 1170, -723, -306, - -328, -247, -251, -598, - 354, 332, -1593, 499, - 332, -23, 219, 304, - 325, -1511, 378, 299, - -94, -54, 679, 956, - 507, 830, 861, -739, - -895, -135, 16, -34, - 677, 650, 961, 714, - 816, -665, -1741, -671, - 274, 93, -617, -433 + -103, -143, -85, -19, + -404, 182, -795, 84, + 398, -594, -55, -256, + 283, 128, -472, 279, + -246, -628, 281, 297, + -853, 468, 358, -915, + 272, 149, 209, -443, + -168, -504, 452, -525, + 624, -427, 779, 117, + 1079, 404, -98, 80, + 136, 165, 142, -1394, + 513, -566, -150, 822, + 124, 646, 199, 272, + -165, -702, -615, 165, + 333, 810, -457, 1038, + -360, 105, -110, 537, + -224, 125, 562, -26, + 699, -1105, 809, -1323, + -1229, 841, -767, 571, + -310, 437, -114, -230, + -1045, 630, 564, 322, + 282, 1170, -723, -306, + -328, -247, -251, -598, + 354, 332, -1593, 499, + 332, -23, 219, 304, + 325, -1511, 378, 299, + -94, -54, 679, 956, + 507, 830, 861, -739, + -895, -135, 16, -34, + 677, 650, 961, 714, + 816, -665, -1741, -671, + 274, 93, -617, -433 }; const Word16 YG_dicMR_4_fx[4 * 16] = /*Q12 */ { - -163, -44, -108, 32, - 556, 153, 115, 120, - 617, 818, 802, 719, - -639, -665, 122, 664, - 353, -555, -352, -86, - -1162, 833, -1034, 326, - -511, -406, -478, -523, - 491, -1473, 404, -21, - 148, 288, -45, -544, - -61, 172, -791, -44, - 715, -449, 861, 504, - -108, 263, 610, 118, - 962, 826, -1013, -37, - -32, -495, 362, -214, - -37, 661, -75, 289, - -835, 243, 85, -105 + -163, -44, -108, 32, + 556, 153, 115, 120, + 617, 818, 802, 719, + -639, -665, 122, 664, + 353, -555, -352, -86, + -1162, 833, -1034, 326, + -511, -406, -478, -523, + 491, -1473, 404, -21, + 148, 288, -45, -544, + -61, 172, -791, -44, + 715, -449, 861, 504, + -108, 263, 610, 118, + 962, 826, -1013, -37, + -32, -495, 362, -214, + -37, 661, -75, 289, + -835, 243, 85, -105 }; @@ -17830,128 +17830,128 @@ const Word16 mean_m_fx[1 * 1] = /*Q12 */ const Word16 mean_gain_dic_fx[1 * 64] = { - -739, -519, -76, 147, 574, 779, 983, 1185, - 1384, 1580, 1784, 1989, 2204, 2643, 2864, 2422, - 362, -295, -1197, -1936, -2757, -11755, -8216, 3083, - 3311, -1434, -1682, -3341, -9284, -9057, -8616, -7783, - -7359, -6964, -6592, -6233, -5470, -5050, -4651, -3954, - -2470, -963, -2199, -3042, -3643, -4292, -5854, -10199, - 4103, 3548, 4390, 4717, 3817, -10525, -11521, -9570, - -9899, -9171, -10841, -11165, 5500, 5079, 6139, 6993 + -739, -519, -76, 147, 574, 779, 983, 1185, + 1384, 1580, 1784, 1989, 2204, 2643, 2864, 2422, + 362, -295, -1197, -1936, -2757, -11755, -8216, 3083, + 3311, -1434, -1682, -3341, -9284, -9057, -8616, -7783, + -7359, -6964, -6592, -6233, -5470, -5050, -4651, -3954, + -2470, -963, -2199, -3042, -3643, -4292, -5854, -10199, + 4103, 3548, 4390, 4717, 3817, -10525, -11521, -9570, + -9899, -9171, -10841, -11165, 5500, 5079, 6139, 6993 }; /* Q12 */ const Word16 YGain_mean_LR_fx[1 * 12] =/* Q12 */ { - -385, -178, -143, -116, -46, -12, - 64, 50, 118, 68, 133, 151 + -385, -178, -143, -116, -46, -12, + 64, 50, 118, 68, 133, 151 }; const Word16 YGain_dic1_LR_fx[3 * 32] = /*Q12 */ { - -1909, 159, -90, - -155, 416, -15, - -99, -84, 396, - -1832, -848, -320, - -779, 1024, 45, - -1860, -1761, 273, - 81, -341, -309, - -819, -3, -315, - 483, 215, -194, - 242, 937, -76, - -1830, -1753, -1102, - -1589, 868, -657, - -911, 389, 421, - -1834, 915, 390, - -144, 564, -869, - 878, -1544, 301, - 446, 332, 376, - -540, -822, -1001, - 548, -192, 232, - 920, -589, -175, - 869, 717, -564, - 797, -103, -1047, - -335, -1732, -186, - -1840, -345, 566, - 1205, 109, 43, - 985, -456, 570, - 650, -1223, -874, - 928, 752, 390, - -124, 833, 575, - -1811, -249, -1142, - -711, -767, 185, - 344, -876, 267, + -1909, 159, -90, + -155, 416, -15, + -99, -84, 396, + -1832, -848, -320, + -779, 1024, 45, + -1860, -1761, 273, + 81, -341, -309, + -819, -3, -315, + 483, 215, -194, + 242, 937, -76, + -1830, -1753, -1102, + -1589, 868, -657, + -911, 389, 421, + -1834, 915, 390, + -144, 564, -869, + 878, -1544, 301, + 446, 332, 376, + -540, -822, -1001, + 548, -192, 232, + 920, -589, -175, + 869, 717, -564, + 797, -103, -1047, + -335, -1732, -186, + -1840, -345, 566, + 1205, 109, 43, + 985, -456, 570, + 650, -1223, -874, + 928, 752, 390, + -124, 833, 575, + -1811, -249, -1142, + -711, -767, 185, + 344, -876, 267, }; const Word16 YGain_dic2_LR_fx[4 * 32] = /*Q12 */ { - -294, -73, -41, 11, - 276, 330, -1316, 173, - 26, -712, 86, 1, - -841, -539, 246, -479, - 43, -207, 709, 116, - 104, -197, 227, -548, - 261, -228, 165, 606, - 613, 403, -122, -420, - 14, 182, -544, -669, - -734, 392, -492, -131, - -1316, 274, 116, 331, - -1339, 535, -1261, 608, - -346, 277, -426, 729, - -1067, -836, -571, 388, - 643, 503, 484, 532, - -148, 447, 120, -392, - -600, 263, 519, -75, - 686, -346, 379, 23, - 130, 239, 376, -1366, - 68, 656, -361, 92, - 608, 286, -405, 487, - -1031, 507, 523, -971, - 51, -44, -521, 172, - -573, -500, 398, 632, - 240, 147, 104, 51, - -319, -680, -890, -398, - -195, 503, 306, 459, - 335, 368, 662, -389, - 378, -788, -537, 680, - 433, -1129, 472, -883, - 472, -312, -301, -207, - 378, -1346, 433, 408, + -294, -73, -41, 11, + 276, 330, -1316, 173, + 26, -712, 86, 1, + -841, -539, 246, -479, + 43, -207, 709, 116, + 104, -197, 227, -548, + 261, -228, 165, 606, + 613, 403, -122, -420, + 14, 182, -544, -669, + -734, 392, -492, -131, + -1316, 274, 116, 331, + -1339, 535, -1261, 608, + -346, 277, -426, 729, + -1067, -836, -571, 388, + 643, 503, 484, 532, + -148, 447, 120, -392, + -600, 263, 519, -75, + 686, -346, 379, 23, + 130, 239, 376, -1366, + 68, 656, -361, 92, + 608, 286, -405, 487, + -1031, 507, 523, -971, + 51, -44, -521, 172, + -573, -500, 398, 632, + 240, 147, 104, 51, + -319, -680, -890, -398, + -195, 503, 306, 459, + 335, 368, 662, -389, + 378, -788, -537, 680, + 433, -1129, 472, -883, + 472, -312, -301, -207, + 378, -1346, 433, 408, }; const Word16 YGain_dic3_LR_fx[5 * 32] = /*Q12 */ { - -332, -191, -122, -455, -210, - 364, -48, -664, 408, 225, - -576, -342, 367, 52, 270, - -392, -157, -77, 625, -224, - -183, -652, -406, 99, 266, - 24, 65, 74, 525, 613, - -805, 306, -383, -21, 247, - 16, 133, -416, -4, -567, - 294, -750, 443, -367, 228, - 536, 816, 767, 562, 594, - -54, 200, -1108, -582, 227, - 123, -43, 414, -376, -649, - 592, -652, -674, -386, -356, - 100, -58, -45, -108, 103, - -727, -194, -1170, 931, 1096, - 512, 758, -440, -769, -1051, - 362, 787, -276, -139, 149, - -218, 387, 457, -414, 265, - -202, 663, -1104, 882, -338, - -57, 405, 269, 257, -221, - 335, 864, 1164, -611, -618, - 1275, 494, -1783, 119, 1222, - 752, 76, 270, 73, -57, - 376, -1255, 145, 724, 603, - -989, 618, 659, 675, 560, - 128, -147, -138, -368, 963, - 140, -170, 866, 538, 127, - 122, -616, 166, 236, -396, - 374, 279, 407, 650, -1269, - -861, 613, -755, -1334, -972, - -922, 314, 416, -114, -648, - 265, 85, 61, -1110, 45 + -332, -191, -122, -455, -210, + 364, -48, -664, 408, 225, + -576, -342, 367, 52, 270, + -392, -157, -77, 625, -224, + -183, -652, -406, 99, 266, + 24, 65, 74, 525, 613, + -805, 306, -383, -21, 247, + 16, 133, -416, -4, -567, + 294, -750, 443, -367, 228, + 536, 816, 767, 562, 594, + -54, 200, -1108, -582, 227, + 123, -43, 414, -376, -649, + 592, -652, -674, -386, -356, + 100, -58, -45, -108, 103, + -727, -194, -1170, 931, 1096, + 512, 758, -440, -769, -1051, + 362, 787, -276, -139, 149, + -218, 387, 457, -414, 265, + -202, 663, -1104, 882, -338, + -57, 405, 269, 257, -221, + 335, 864, 1164, -611, -618, + 1275, 494, -1783, 119, 1222, + 752, 76, 270, 73, -57, + 376, -1255, 145, 724, 603, + -989, 618, 659, 675, 560, + 128, -147, -138, -368, 963, + 140, -170, 866, 538, 127, + 122, -616, 166, 236, -396, + 374, 279, 407, 650, -1269, + -861, 613, -755, -1334, -972, + -922, 314, 416, -114, -648, + 265, 85, 61, -1110, 45 }; const Word16 YG_mean16HR_fx[] = @@ -18331,33 +18331,33 @@ const Word16 Odx_fft64[64] = { 0,59,54,49,44,39,34,29,24,19,14,9,4,63,58,53,48,43,38,33,28,23,18,13,8,3,62,57,52,47,42,37, 32,27,22,17,12,7,2,61,56,51,46,41,36,31,26,21,16,11,6,1,60,55,50,45,40,35,30,25,20,15,10,5 -}; // Q0 +}; // Q0 -const Word16 Ip_fft64[6] = { 32,1,0,64,32,96 }; // Q0 +const Word16 Ip_fft64[6] = { 32,1,0,64,32,96 }; // Q0 -const Word16 Odx_fft32_15[32] = { 0,17,2,19,4,21,6,23,8,25,10,27,12,29,14,31,16,1,18,3,20,5,22,7,24,9,26,11,28,13,30,15 }; // Q0 +const Word16 Odx_fft32_15[32] = { 0,17,2,19,4,21,6,23,8,25,10,27,12,29,14,31,16,1,18,3,20,5,22,7,24,9,26,11,28,13,30,15 }; // Q0 const Word32 w_fft32_16fx[16] =//Q30 { - 1073741824, 0, 759250113, 759250113, 992008059, 410903236, 410903236, 992008059, - 1053110143, 209476636, 596539003, 892783685, 892783685, 596539003, 209476636, 1053110143 + 1073741824, 0, 759250113, 759250113, 992008059, 410903236, 410903236, 992008059, + 1053110143, 209476636, 596539003, 892783685, 892783685, 596539003, 209476636, 1053110143 }; -const Word16 Ip_fft32[6] = { 16,1,0,32,16,48 }; // Q0 +const Word16 Ip_fft32[6] = { 16,1,0,32,16,48 }; // Q0 -const Word16 Odx_fft32_5[32] = { 0,27,22,17,12,7,2,29,24,19,14,9,4,31,26,21,16,11,6,1,28,23,18,13,8,3,30,25,20,15,10,5 }; // Q0 +const Word16 Odx_fft32_5[32] = { 0,27,22,17,12,7,2,29,24,19,14,9,4,31,26,21,16,11,6,1,28,23,18,13,8,3,30,25,20,15,10,5 }; // Q0 -const Word16 Odx_fft16[16] = {0,11,6,1,12,7,2,13,8,3,14,9,4,15,10,5}; // Q0 +const Word16 Odx_fft16[16] = {0,11,6,1,12,7,2,13,8,3,14,9,4,15,10,5}; // Q0 -const Word16 Ip_fft16[6] = {8,1,0,16,8,24}; // Q0 +const Word16 Ip_fft16[6] = {8,1,0,16,8,24}; // Q0 -const Word16 Ip_fft8[6] = {4,1,0,8,4,12}; // Q0 +const Word16 Ip_fft8[6] = {4,1,0,8,4,12}; // Q0 const Word16 Idx_dortft80[80] = { 0,65,50,35,20,5,70,55,40,25,10,75,60,45,30,15,16,1,66,51,36,21,6,71,56,41,26,11,76,61, 46,31,32,17,2,67,52,37,22,7,72,57,42,27,12,77,62,47,48,33,18,3,68,53,38,23,8,73,58,43, 28,13,78,63,64,49,34,19,4,69,54,39,24,9,74,59,44,29,14,79 -}; // Q0 +}; // Q0 const Word16 Idx_dortft120[120] = { @@ -18366,7 +18366,7 @@ const Word16 Idx_dortft120[120] = 96,81,66,51,36,21,6,111,112,97,82,67,52,37,22,7,8,113,98,83,68,53,38,23, 24,9,114,99,84,69,54,39,40,25,10,115,100,85,70,55,56,41,26,11,116,101,86, 71,72,57,42,27,12,117,102,87,88,73,58,43,28,13,118,103,104,89,74,59,44,29,14,119 -}; // Q0 +}; // Q0 const Word16 Idx_dortft160[160] = { @@ -18379,7 +18379,7 @@ const Word16 Idx_dortft160[160] = 108,13,78,143,48,113,18,83,148,53,118,23,88,153,58,123,28,93, 158,63,64,129,34,99,4,69,134,39,104,9,74,139,44,109,14,79, 144,49,114,19,84,149,54,119,24,89,154,59,124,29,94,159 -}; // Q0 +}; // Q0 const Word16 Idx_dortft320[320] = { @@ -18394,7 +18394,7 @@ const Word16 Idx_dortft320[320] = 58,123,188,253,318,63,64,129,194,259,4,69,134,199,264,9,74,139,204,269,14,79,144,209,274,19,84,149,214,279,24,89,154, 219,284,29,94,159,224,289,34,99,164,229,294,39,104,169,234,299,44,109,174,239,304,49,114,179,244,309,54,119,184,249, 314,59,124,189,254,319 -}; // Q0 +}; // Q0 const Word16 Idx_dortft480[480] = { @@ -18416,25 +18416,25 @@ const Word16 Idx_dortft480[480] = 117,342,87,312,57,282,27,252,477,222,447,448,193,418,163,388,133,358,103,328,73,298,43,268,13,238,463, 208,433,178,403,148,373,118,343,88,313,58,283,28,253,478,223,224,449,194,419,164,389,134,359,104,329,74, 299,44,269,14,239,464,209,434,179,404,149,374,119,344,89,314,59,284,29,254,479 -}; // Q0 +}; // Q0 -const Word16 Ip_fft128[10] = { 64, 1, 0, 128, 64, 192, 32, 160, 96, 224 }; // Q0 +const Word16 Ip_fft128[10] = { 64, 1, 0, 128, 64, 192, 32, 160, 96, 224 }; // Q0 const Word32 w_fft128_16fx[64] = { - 1073741824, 0, 759250112, 759250112, 992008064, 410903232, 410903232, 992008064, - 1053110144, 209476640, 596539008, 892783680, 892783680, 596539008, 209476640, 1053110144, - 1068571456, 105245104, 681174592, 830013632, 946955712, 506158400, 311690816, 1027506880, - 1027506880, 311690816, 506158400, 946955712, 830013632, 681174592, 105245104, 1068571456, - 1072448448, 52686008, 721080960, 795590208, 970651136, 459083776, 361732736, 1010975232, - 1041563136, 260897968, 552013632, 920979072, 862437504, 639627264, 157550640, 1062120192, - 1062120192, 157550640, 639627264, 862437504, 920979072, 552013632, 260897968, 1041563136, - 1010975232, 361732736, 459083776, 970651136, 795590208, 721080960, 52686008, 1072448448, -}; // Q30 + 1073741824, 0, 759250112, 759250112, 992008064, 410903232, 410903232, 992008064, + 1053110144, 209476640, 596539008, 892783680, 892783680, 596539008, 209476640, 1053110144, + 1068571456, 105245104, 681174592, 830013632, 946955712, 506158400, 311690816, 1027506880, + 1027506880, 311690816, 506158400, 946955712, 830013632, 681174592, 105245104, 1068571456, + 1072448448, 52686008, 721080960, 795590208, 970651136, 459083776, 361732736, 1010975232, + 1041563136, 260897968, 552013632, 920979072, 862437504, 639627264, 157550640, 1062120192, + 1062120192, 157550640, 639627264, 862437504, 920979072, 552013632, 260897968, 1041563136, + 1010975232, 361732736, 459083776, 970651136, 795590208, 721080960, 52686008, 1072448448, +}; // Q30 -const Word16 Ip_fft256[10] = {128, 1, 0, 256, 128, 384, 64, 320,192, 448}; // Q0 +const Word16 Ip_fft256[10] = {128, 1, 0, 256, 128, 384, 64, 320,192, 448}; // Q0 -const Word16 Ip_fft512[18] = {256, 1, 0, 512, 256, 768, 128, 640,384, 896, 64, 576, 320, 832, 192, 704,448, 960}; // Q0 +const Word16 Ip_fft512[18] = {256, 1, 0, 512, 256, 768, 128, 640,384, 896, 64, 576, 320, 832, 192, 704,448, 960}; // Q0 const Word16 w_fft512_fx_evs[256] =//Q14 { @@ -18475,13 +18475,13 @@ const Word16 Idx_dortft40[40] = { 0, 25, 10, 35, 20, 5, 30, 15, 16, 1, 26, 11, 36, 21, 6, 31, 32, 17, 2, 27, 12, 37, 22, 7, 8, 33, 18, 3, 28, 13, 38, 23, 24, 9, 34, 19, 4, 29, 14, 39 -}; // Q0 +}; // Q0 -const Word16 Odx_fft8_5[8] = {0, 3, 6, 1, 4, 7, 2, 5}; // Q0 -const Word16 Idx_dortft20[20] = {0, 5, 10, 15, 16, 1, 6, 11, 12, 17, 2, 7, 8, 13, 18, 3, 4, 9, 14, 19}; // Q0 -const Word16 Odx_fft4_5[4] = {0, 3, 2, 1}; // Q0 -const Word16 Ip_fft4[6] = {2,1,0,4,2,6}; // Q0 -const Word16 ip_edct2_64[6] = {16, 64, 0, 32, 16, 48}; // Q0 +const Word16 Odx_fft8_5[8] = {0, 3, 6, 1, 4, 7, 2, 5}; // Q0 +const Word16 Idx_dortft20[20] = {0, 5, 10, 15, 16, 1, 6, 11, 12, 17, 2, 7, 8, 13, 18, 3, 4, 9, 14, 19}; // Q0 +const Word16 Odx_fft4_5[4] = {0, 3, 2, 1}; // Q0 +const Word16 Ip_fft4[6] = {2,1,0,4,2,6}; // Q0 +const Word16 ip_edct2_64[6] = {16, 64, 0, 32, 16, 48}; // Q0 const Word16 w_edct2_64_fx[80] = /*Q14 */ { @@ -18517,7 +18517,7 @@ const Word16 hvq_cb_search_overlap24k[17] = 113, 128, 128, 128, 128, 128, 128, 128, 128 -}; // Q0 +}; // Q0 const Word16 hvq_cb_search_overlap32k[21] = { @@ -18527,7 +18527,7 @@ const Word16 hvq_cb_search_overlap32k[21] = 128, 128, 128, 128, 128, 128, 128, 128, 128 -}; // Q0 +}; // Q0 const Word16 hvq_peak_cb_fx[1024] = /* Q15 */ { @@ -18636,43 +18636,43 @@ const Word16 hvq_peak_cb_fx[1024] = /* Q15 */ 6066, 4720, 25084,-28951 }; -const Word16 hvq_pg_huff_offset[NUM_PG_HUFFLEN] = {0,2,3,8,9,11,13,15,19}; // Q0 -const Word16 hvq_pg_huff_thres[NUM_PG_HUFFLEN] = {0,0x2,0x4,0x18,0x20,0x40,0x80,0x100,0x300}; // Q0 +const Word16 hvq_pg_huff_offset[NUM_PG_HUFFLEN] = {0,2,3,8,9,11,13,15,19}; // Q0 +const Word16 hvq_pg_huff_thres[NUM_PG_HUFFLEN] = {0,0x2,0x4,0x18,0x20,0x40,0x80,0x100,0x300}; // Q0 const Word16 hvq_pg_huff_tab[32] = { 30, 31, 1, 0, 2, 3, 28, 29, 4, 5, 27, 25, 26, 6, 24, 7, 8, 22, 23, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 -}; // Q0 +}; // Q0 const Word16 hvq_cp_huff_len[52] = { 3, 4, 5, 6, 6, 6, 6, 6, 4, 4, 5, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 9, 10, 10, 11, 11, 11, 10, 10, 10, 10, 11, 12, 12, 13, 13, 12, 12, 11, 12 -}; // Q0 +}; // Q0 const Word16 hvq_cp_huff_val[52] = { 7, 8, 6, 3, 4, 5, 6, 7, 9, 10, 7, 8, 9, 10, 11, 12, 13, 11, 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 3, 4, 5, 6, 7, 5, 4, 5, 3, 4, 5, 6, 7, 8, 9, 6, 1, 2, 0, 1, 3, 4, 7, 5 -}; // Q0 +}; // Q0 -const Word16 hvq_cp_layer1_map5[HVQ_CP_MAP_LEN] = { 16, 8, 4, 2, 1, 18, 17, 9 }; // Q0 +const Word16 hvq_cp_layer1_map5[HVQ_CP_MAP_LEN] = { 16, 8, 4, 2, 1, 18, 17, 9 }; // Q0 -const Word16 hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN] = { 0x0, 0x2, 0xC, 0x20, 0x50, 0x60, 0x100, 0x180, 0x600, 0x1000, 0x1C00 }; // Q0 -const Word16 hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN] = { 0, 2, 7, 12, 18, 19, 24, 26, 35, 45, 51 }; // Q0 +const Word16 hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN] = { 0x0, 0x2, 0xC, 0x20, 0x50, 0x60, 0x100, 0x180, 0x600, 0x1000, 0x1C00 }; // Q0 +const Word16 hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN] = { 0, 2, 7, 12, 18, 19, 24, 26, 35, 45, 51 }; // Q0 const Word16 hvq_cp_huff_tab[52] = { 46, 47, 44, 45, 48, 49, 51, 36, 37, 38, 43, 50, 34, 35, 39, 40, 41, 42, 33, 28, 29, 30, 31, 32, 26, 27, 3, 4, 5, 6, 7, 22, 23, 24, 25, 2, 10, 11, 12, 13, 17, 18, 19, 20, 21, 1, 8, 9, 14, 15, 16, 0 -}; // Q0 +}; // Q0 /*----------------------------------------------------------------------------------* * FEC for HQ core *----------------------------------------------------------------------------------*/ -const Word16 Num_bands_NB[MAX_SB_NB] = {8,8,2}; // Q0 +const Word16 Num_bands_NB[MAX_SB_NB] = {8,8,2}; // Q0 const Word16 SmoothingWin_NB875_fx[70] = /*Q15*/ { @@ -18698,430 +18698,430 @@ const Word16 bp1_den_coef_wb_fx[5] = { 16384, 0, -30498, 0, 14262, }; /* Q14 */ const Word16 shape1_num_coef_fx[11] = /* Q15 */ { - 31437, -2443, -13636, 4316, - -10188, 48, 2639, -3575, - -776, 1046, 399 + 31437, -2443, -13636, 4316, + -10188, 48, 2639, -3575, + -776, 1046, 399 }; const Word16 shape1_den_coef_fx[11] = { 32767, /* Q15 */ - 2940, -12237, 4032, -9609, - -1998, 2335, -3900, -1595, - 857, 253 + 2940, -12237, 4032, -9609, + -1998, 2335, -3900, -1595, + 857, 253 }; const Word16 shape2_num_coef_fx[11] = /* Q15 */ { - 30760, 31, -9699, 9516, - -5878, -7249, -10468, 442, - 3278, -63, 1115 + 30760, 31, -9699, 9516, + -5878, -7249, -10468, 442, + 3278, -63, 1115 }; const Word16 shape2_den_coef_fx[11] = { 32767, /* Q15 */ - 16019, -890, 12799, 2346, - -6985, -13192, -5795, -949, - -1492, -304 + 16019, -890, 12799, 2346, + -6985, -13192, -5795, -949, + -1492, -304 }; const Word16 shape3_num_coef_fx[11] = /* Q15 */ { - 30685, -383, -9937, -9605, - -5997, 7611, -10393, -355, - 3239, 12, 1196 + 30685, -383, -9937, -9605, + -5997, 7611, -10393, -355, + 3239, 12, 1196 }; const Word16 shape3_den_coef_fx[11] = { 32767, /* Q15 */ - -16498, -911, -12947, 2286, - 7430, -13385, 6066, -1182, - 1580, -273 + -16498, -911, -12947, 2286, + 7430, -13385, 6066, -1182, + 1580, -273 }; const Word16 txlpf1_num_coef_fx[11] = /* Q13 */ { - 138, 198, 514, 681, 921, - 964, 921, 681, 514, 198, - 138, + 138, 198, 514, 681, 921, + 964, 921, 681, 514, 198, + 138, }; const Word16 txlpf1_den_coef_fx[11] = /* Q13 */ { - 8192,-18945, 31613,-31149, 24494, - -12753, 5528, -1436, 347, -25, - 4, + 8192,-18945, 31613,-31149, 24494, + -12753, 5528, -1436, 347, -25, + 4, }; const Word16 txhpf1_num_coef_fx[11] = /* Q13 */ { - 138, -198, 514, -681, 921, - -964, 921, -681, 514, -198, - 138, + 138, -198, 514, -681, 921, + -964, 921, -681, 514, -198, + 138, }; const Word16 txhpf1_den_coef_fx[11] = /* Q13 */ { - 8192, 18945, 31613, 31149, 24494, - 12753, 5528, 1436, 347, 25, - 4, + 8192, 18945, 31613, 31149, 24494, + 12753, 5528, 1436, 347, 25, + 4, }; /* NELP filter coefficients */ const Word16 bp1_num_coef_nb_fx_order7[8] = { - /* Q = BP1_COEF_NB_QF_ORDER7 = 13 */ - 1481, 6730, 15579, 22923, 22923, 15579, 6730, 1481, + /* Q = BP1_COEF_NB_QF_ORDER7 = 13 */ + 1481, 6730, 15579, 22923, 22923, 15579, 6730, 1481, }; const Word16 bp1_den_coef_nb_fx_order7[8] = { - /* Q = BP1_COEF_NB_QF_ORDER7 = 13 */ - 8192, 16156, 23814, 21855, 14620, 6614, 1907, 268, + /* Q = BP1_COEF_NB_QF_ORDER7 = 13 */ + 8192, 16156, 23814, 21855, 14620, 6614, 1907, 268, }; /* NELP gain tables */ const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2] = /* Q13 */ { - { -2224, -2114, }, - { 12666, 12314, }, - { 3723, 9690, }, - { 17880, 17978, }, - { 4136, 3946, }, - { 11605, 21280, }, - { 9777, 9340, }, - { 21701, 21627, }, - { 1088, 1679, }, - { 13993, 13697, }, - { 10443, 5214, }, - { 19702, 19692, }, - { 5458, 5317, }, - { 17051, 16918, }, - { 14206, 8503, }, - { 24330, 24271, }, - { -118, -279, }, - { 11615, 14863, }, - { 6898, 6544, }, - { 18913, 18637, }, - { 1142, 6811, }, - { 15995, 16070, }, - { 6921, 13182, }, - { 22857, 22741, }, - { 3017, 2260, }, - { 14952, 14992, }, - { 8176, 8093, }, - { 20721, 20549, }, - { 7441, 2370, }, - { 17897, 13988, }, - { 10986, 10966, }, - { 26098, 25992, }, + { -2224, -2114, }, + { 12666, 12314, }, + { 3723, 9690, }, + { 17880, 17978, }, + { 4136, 3946, }, + { 11605, 21280, }, + { 9777, 9340, }, + { 21701, 21627, }, + { 1088, 1679, }, + { 13993, 13697, }, + { 10443, 5214, }, + { 19702, 19692, }, + { 5458, 5317, }, + { 17051, 16918, }, + { 14206, 8503, }, + { 24330, 24271, }, + { -118, -279, }, + { 11615, 14863, }, + { 6898, 6544, }, + { 18913, 18637, }, + { 1142, 6811, }, + { 15995, 16070, }, + { 6921, 13182, }, + { 22857, 22741, }, + { 3017, 2260, }, + { 14952, 14992, }, + { 8176, 8093, }, + { 20721, 20549, }, + { 7441, 2370, }, + { 17897, 13988, }, + { 10986, 10966, }, + { 26098, 25992, }, }; const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2] = /* Q13 */ { - { -4791, -5157, }, - { 4824, 4937, }, - { -3443, 3610, }, - { 5539, 15293, }, - { -469, -3986, }, - { 7977, 8157, }, - { 2748, 2492, }, - { 14070, 14014, }, - { -2486, -2863, }, - { 6033, 5892, }, - { 2678, -441, }, - { 11741, 11804, }, - { -256, -847, }, - { 9153, 8922, }, - { -106, 5979, }, - { 16876, 16741, }, - { -3584, -3873, }, - { 3511, 9538, }, - { 401, 416, }, - { 11082, 10550, }, - { -1418, -1725, }, - { 8988, 5255, }, - { 6275, 1137, }, - { 15372, 15247, }, - { -3899, 301, }, - { 6976, 7095, }, - { 1581, 1453, }, - { 12988, 12824, }, - { 2692, -3093, }, - { 9778, 10153, }, - { 3938, 3628, }, - { 18823, 18695, }, + { -4791, -5157, }, + { 4824, 4937, }, + { -3443, 3610, }, + { 5539, 15293, }, + { -469, -3986, }, + { 7977, 8157, }, + { 2748, 2492, }, + { 14070, 14014, }, + { -2486, -2863, }, + { 6033, 5892, }, + { 2678, -441, }, + { 11741, 11804, }, + { -256, -847, }, + { 9153, 8922, }, + { -106, 5979, }, + { 16876, 16741, }, + { -3584, -3873, }, + { 3511, 9538, }, + { 401, 416, }, + { 11082, 10550, }, + { -1418, -1725, }, + { 8988, 5255, }, + { 6275, 1137, }, + { 15372, 15247, }, + { -3899, 301, }, + { 6976, 7095, }, + { 1581, 1453, }, + { 12988, 12824, }, + { 2692, -3093, }, + { 9778, 10153, }, + { 3938, 3628, }, + { 18823, 18695, }, }; const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5] = /* Q12 */ { - { 914, 990, 1490, 5954, 2618, }, - { 5599, 4621, 4078, 3493, 3057, }, - { 4930, 4031, 2999, 2150, 1706, }, - { 7722, 3021, 1804, 1478, 1452, }, - { 1171, 1390, 6895, 2592, 1486, }, - { 4155, 4287, 4409, 4515, 4577, }, - { 3633, 3661, 3694, 3711, 3736, }, - { 13212, 5009, 2611, 2175, 2048, }, - { 3716, 2887, 2253, 1965, 1723, }, - { 7141, 4567, 3434, 2970, 2396, }, - { 2856, 3038, 3259, 3481, 3709, }, - { 5929, 5459, 4923, 4448, 4084, }, - { 980, 1024, 1550, 5686, 8038, }, - { 3516, 7354, 10392, 3619, 2856, }, - { 2598, 3093, 3582, 4780, 5965, }, - { 1962, 10993, 5020, 2861, 2587, }, - { 796, 916, 1010, 1175, 7720, }, - { 4445, 4406, 4344, 4249, 4175, }, - { 1454, 6493, 2611, 1758, 1765, }, - { 6296, 7686, 4763, 2945, 2203, }, - { 1502, 1573, 1895, 2981, 5464, }, - { 4750, 4829, 4909, 4929, 4895, }, - { 3644, 3774, 3922, 4037, 4116, }, - { 9051, 7403, 6003, 4746, 4081, }, - { 1558, 1869, 2331, 3000, 3595, }, - { 4671, 4646, 4614, 4553, 4482, }, - { 2262, 2608, 3158, 3890, 4468, }, - { 5556, 5441, 6824, 7146, 5724, }, - { 1470, 1550, 2016, 11169, 3828, }, - { 5488, 6270, 6771, 8202, 9281, }, - { 3477, 3693, 4113, 4460, 4705, }, - { 10877, 17984, 10194, 7291, 2824, }, - { 1327, 1498, 1476, 1667, 2138, }, - { 4463, 4299, 4094, 3880, 3731, }, - { 3188, 3164, 3156, 3104, 3140, }, - { 9757, 5690, 3366, 2296, 1792, }, - { 1731, 1753, 12406, 4082, 2247, }, - { 3866, 4060, 5007, 5274, 5225, }, - { 3998, 3957, 3900, 3839, 3789, }, - { 18040, 9417, 5567, 3465, 2504, }, - { 2160, 2532, 2895, 2577, 2321, }, - { 5052, 4789, 4490, 4203, 3953, }, - { 3381, 3415, 3458, 3496, 3536, }, - { 6166, 5811, 5440, 5035, 4650, }, - { 2839, 3389, 5057, 7558, 10414, }, - { 3875, 4431, 5183, 6310, 7166, }, - { 4311, 4130, 3571, 3070, 8555, }, - { 8791, 8260, 7299, 6243, 5421, }, - { 1191, 1237, 1368, 1814, 11819, }, - { 2486, 5729, 6150, 4222, 3667, }, - { 4018, 3825, 3600, 3388, 3256, }, - { 7504, 5817, 4989, 4065, 3322, }, - { 1430, 1962, 5546, 4096, 4681, }, - { 5393, 5378, 5324, 5230, 5052, }, - { 4041, 4090, 4132, 4159, 4181, }, - { 12469, 9221, 5735, 3617, 2501, }, - { 2482, 2565, 2768, 3088, 3461, }, - { 5209, 5080, 4905, 4706, 4522, }, - { 3139, 3362, 3647, 3910, 4156, }, - { 7139, 6588, 5941, 5251, 4674, }, - { 1719, 1866, 7993, 7634, 3987, }, - { 3587, 5289, 7882, 13519, 16095, }, - { 2409, 2515, 2749, 7316, 4636, }, - { 30391, 18493, 13798, 4799, 2283, }, + { 914, 990, 1490, 5954, 2618, }, + { 5599, 4621, 4078, 3493, 3057, }, + { 4930, 4031, 2999, 2150, 1706, }, + { 7722, 3021, 1804, 1478, 1452, }, + { 1171, 1390, 6895, 2592, 1486, }, + { 4155, 4287, 4409, 4515, 4577, }, + { 3633, 3661, 3694, 3711, 3736, }, + { 13212, 5009, 2611, 2175, 2048, }, + { 3716, 2887, 2253, 1965, 1723, }, + { 7141, 4567, 3434, 2970, 2396, }, + { 2856, 3038, 3259, 3481, 3709, }, + { 5929, 5459, 4923, 4448, 4084, }, + { 980, 1024, 1550, 5686, 8038, }, + { 3516, 7354, 10392, 3619, 2856, }, + { 2598, 3093, 3582, 4780, 5965, }, + { 1962, 10993, 5020, 2861, 2587, }, + { 796, 916, 1010, 1175, 7720, }, + { 4445, 4406, 4344, 4249, 4175, }, + { 1454, 6493, 2611, 1758, 1765, }, + { 6296, 7686, 4763, 2945, 2203, }, + { 1502, 1573, 1895, 2981, 5464, }, + { 4750, 4829, 4909, 4929, 4895, }, + { 3644, 3774, 3922, 4037, 4116, }, + { 9051, 7403, 6003, 4746, 4081, }, + { 1558, 1869, 2331, 3000, 3595, }, + { 4671, 4646, 4614, 4553, 4482, }, + { 2262, 2608, 3158, 3890, 4468, }, + { 5556, 5441, 6824, 7146, 5724, }, + { 1470, 1550, 2016, 11169, 3828, }, + { 5488, 6270, 6771, 8202, 9281, }, + { 3477, 3693, 4113, 4460, 4705, }, + { 10877, 17984, 10194, 7291, 2824, }, + { 1327, 1498, 1476, 1667, 2138, }, + { 4463, 4299, 4094, 3880, 3731, }, + { 3188, 3164, 3156, 3104, 3140, }, + { 9757, 5690, 3366, 2296, 1792, }, + { 1731, 1753, 12406, 4082, 2247, }, + { 3866, 4060, 5007, 5274, 5225, }, + { 3998, 3957, 3900, 3839, 3789, }, + { 18040, 9417, 5567, 3465, 2504, }, + { 2160, 2532, 2895, 2577, 2321, }, + { 5052, 4789, 4490, 4203, 3953, }, + { 3381, 3415, 3458, 3496, 3536, }, + { 6166, 5811, 5440, 5035, 4650, }, + { 2839, 3389, 5057, 7558, 10414, }, + { 3875, 4431, 5183, 6310, 7166, }, + { 4311, 4130, 3571, 3070, 8555, }, + { 8791, 8260, 7299, 6243, 5421, }, + { 1191, 1237, 1368, 1814, 11819, }, + { 2486, 5729, 6150, 4222, 3667, }, + { 4018, 3825, 3600, 3388, 3256, }, + { 7504, 5817, 4989, 4065, 3322, }, + { 1430, 1962, 5546, 4096, 4681, }, + { 5393, 5378, 5324, 5230, 5052, }, + { 4041, 4090, 4132, 4159, 4181, }, + { 12469, 9221, 5735, 3617, 2501, }, + { 2482, 2565, 2768, 3088, 3461, }, + { 5209, 5080, 4905, 4706, 4522, }, + { 3139, 3362, 3647, 3910, 4156, }, + { 7139, 6588, 5941, 5251, 4674, }, + { 1719, 1866, 7993, 7634, 3987, }, + { 3587, 5289, 7882, 13519, 16095, }, + { 2409, 2515, 2749, 7316, 4636, }, + { 30391, 18493, 13798, 4799, 2283, }, }; const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5] = /* Q12 */ { - { 1565, 1391, 1635, 5228, 2681, }, - { 2156, 2558, 6205, 5561, 3944, }, - { 2039, 2406, 3094, 3409, 3968, }, - { 5090, 5065, 4989, 4858, 4764, }, - { 1436, 1736, 2816, 2362, 2400, }, - { 4375, 4425, 4465, 4478, 4493, }, - { 4648, 4081, 3550, 2981, 2667, }, - { 1705, 1950, 3679, 7828, 9895, }, - { 2839, 1826, 1443, 1210, 1245, }, - { 1387, 1410, 1768, 8873, 4383, }, - { 4022, 3784, 3565, 3316, 3096, }, - { 9983, 7147, 5225, 3742, 3027, }, - { 6769, 2357, 1531, 1448, 1556, }, - { 4591, 4671, 4735, 4765, 4789, }, - { 4308, 4198, 4052, 3896, 3769, }, - { 2288, 2550, 4922, 8294, 14878, }, - { 1361, 1480, 1511, 1991, 10450, }, - { 2933, 3131, 3694, 4687, 5201, }, - { 3984, 3048, 2479, 2644, 5514, }, - { 5353, 5480, 5488, 5434, 5437, }, - { 3319, 2881, 2528, 2152, 1927, }, - { 4873, 4748, 4578, 4407, 4257, }, - { 6185, 4396, 3751, 3400, 2899, }, - { 2159, 8067, 7534, 5121, 3640, }, - { 2265, 10177, 3803, 2588, 2441, }, - { 2188, 2206, 4293, 12691, 5893, }, - { 3587, 3651, 3760, 3864, 3960, }, - { 13158, 9752, 7171, 5431, 5364, }, - { 5710, 4173, 2928, 2090, 1774, }, - { 3531, 3831, 4641, 5787, 6622, }, - { 4395, 4356, 4281, 4194, 4111, }, - { 2243, 2476, 5814, 3965, 27176, }, - { 1575, 1667, 7544, 3005, 1984, }, - { 2583, 2511, 11684, 5765, 4807, }, - { 3632, 3458, 3277, 3114, 2971, }, - { 8569, 6778, 5866, 5515, 5141, }, - { 3267, 3035, 2940, 2782, 2691, }, - { 3929, 4249, 4577, 4877, 5162, }, - { 4443, 4173, 3864, 3590, 3337, }, - { 3998, 4725, 5728, 6873, 7885, }, - { 4369, 2824, 2237, 1648, 1404, }, - { 1000, 1022, 1477, 2682, 15276, }, - { 3916, 3851, 3766, 3664, 3591, }, - { 13206, 4485, 3230, 3897, 3648, }, - { 10002, 3515, 2393, 2233, 2211, }, - { 4603, 4836, 5071, 5259, 5411, }, - { 3919, 4035, 4177, 4304, 4419, }, - { 3046, 8332, 16475, 11172, 10858, }, - { 1027, 1007, 1196, 1578, 5937, }, - { 1892, 2422, 3227, 3920, 7400, }, - { 3584, 3532, 3508, 3470, 3437, }, - { 5363, 6155, 6805, 6854, 6811, }, - { 4038, 3512, 3030, 2636, 2332, }, - { 6760, 6124, 5235, 4299, 3687, }, - { 4125, 6528, 4068, 3238, 3483, }, - { 5020, 5905, 7082, 8554, 9623, }, - { 1399, 5868, 3069, 1726, 1655, }, - { 4691, 4234, 3974, 3757, 9616, }, - { 3978, 4003, 4003, 3983, 3960, }, - { 2103, 16858, 9252, 4860, 4727, }, - { 8043, 5294, 3970, 3098, 2583, }, - { 4680, 5109, 5576, 5965, 6275, }, - { 4867, 4584, 4276, 3958, 3682, }, - { 1213, 3115, 6552, 22778, 20977, }, + { 1565, 1391, 1635, 5228, 2681, }, + { 2156, 2558, 6205, 5561, 3944, }, + { 2039, 2406, 3094, 3409, 3968, }, + { 5090, 5065, 4989, 4858, 4764, }, + { 1436, 1736, 2816, 2362, 2400, }, + { 4375, 4425, 4465, 4478, 4493, }, + { 4648, 4081, 3550, 2981, 2667, }, + { 1705, 1950, 3679, 7828, 9895, }, + { 2839, 1826, 1443, 1210, 1245, }, + { 1387, 1410, 1768, 8873, 4383, }, + { 4022, 3784, 3565, 3316, 3096, }, + { 9983, 7147, 5225, 3742, 3027, }, + { 6769, 2357, 1531, 1448, 1556, }, + { 4591, 4671, 4735, 4765, 4789, }, + { 4308, 4198, 4052, 3896, 3769, }, + { 2288, 2550, 4922, 8294, 14878, }, + { 1361, 1480, 1511, 1991, 10450, }, + { 2933, 3131, 3694, 4687, 5201, }, + { 3984, 3048, 2479, 2644, 5514, }, + { 5353, 5480, 5488, 5434, 5437, }, + { 3319, 2881, 2528, 2152, 1927, }, + { 4873, 4748, 4578, 4407, 4257, }, + { 6185, 4396, 3751, 3400, 2899, }, + { 2159, 8067, 7534, 5121, 3640, }, + { 2265, 10177, 3803, 2588, 2441, }, + { 2188, 2206, 4293, 12691, 5893, }, + { 3587, 3651, 3760, 3864, 3960, }, + { 13158, 9752, 7171, 5431, 5364, }, + { 5710, 4173, 2928, 2090, 1774, }, + { 3531, 3831, 4641, 5787, 6622, }, + { 4395, 4356, 4281, 4194, 4111, }, + { 2243, 2476, 5814, 3965, 27176, }, + { 1575, 1667, 7544, 3005, 1984, }, + { 2583, 2511, 11684, 5765, 4807, }, + { 3632, 3458, 3277, 3114, 2971, }, + { 8569, 6778, 5866, 5515, 5141, }, + { 3267, 3035, 2940, 2782, 2691, }, + { 3929, 4249, 4577, 4877, 5162, }, + { 4443, 4173, 3864, 3590, 3337, }, + { 3998, 4725, 5728, 6873, 7885, }, + { 4369, 2824, 2237, 1648, 1404, }, + { 1000, 1022, 1477, 2682, 15276, }, + { 3916, 3851, 3766, 3664, 3591, }, + { 13206, 4485, 3230, 3897, 3648, }, + { 10002, 3515, 2393, 2233, 2211, }, + { 4603, 4836, 5071, 5259, 5411, }, + { 3919, 4035, 4177, 4304, 4419, }, + { 3046, 8332, 16475, 11172, 10858, }, + { 1027, 1007, 1196, 1578, 5937, }, + { 1892, 2422, 3227, 3920, 7400, }, + { 3584, 3532, 3508, 3470, 3437, }, + { 5363, 6155, 6805, 6854, 6811, }, + { 4038, 3512, 3030, 2636, 2332, }, + { 6760, 6124, 5235, 4299, 3687, }, + { 4125, 6528, 4068, 3238, 3483, }, + { 5020, 5905, 7082, 8554, 9623, }, + { 1399, 5868, 3069, 1726, 1655, }, + { 4691, 4234, 3974, 3757, 9616, }, + { 3978, 4003, 4003, 3983, 3960, }, + { 2103, 16858, 9252, 4860, 4727, }, + { 8043, 5294, 3970, 3098, 2583, }, + { 4680, 5109, 5576, 5965, 6275, }, + { 4867, 4584, 4276, 3958, 3682, }, + { 1213, 3115, 6552, 22778, 20977, }, }; const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5] = /* Q12 */ { - { 773, 785, 785, 785, 860, }, - { 3560, 3521, 3410, 3265, 3167, }, - { 1766, 2982, 10273, 3790, 2248, }, - { 4986, 4753, 4496, 4172, 3922, }, - { 2036, 2030, 2009, 1973, 1897, }, - { 3291, 3554, 3868, 4126, 4345, }, - { 3207, 3122, 3026, 2913, 2797, }, - { 13220, 6844, 3967, 2746, 2466, }, - { 1553, 1627, 1392, 1766, 3679, }, - { 5379, 4640, 3844, 3254, 2635, }, - { 1600, 1622, 2430, 9446, 4214, }, - { 5115, 5200, 5311, 5365, 5343, }, - { 6229, 3008, 1989, 1622, 1597, }, - { 1726, 2114, 7046, 6162, 4301, }, - { 1004, 1056, 1841, 6006, 7101, }, - { 6388, 9659, 4510, 2774, 2113, }, - { 1060, 1153, 1400, 1733, 2121, }, - { 3448, 3523, 3612, 3683, 3770, }, - { 1496, 2045, 2910, 3563, 4058, }, - { 4419, 4592, 4795, 4921, 4978, }, - { 1407, 5314, 2788, 1675, 1350, }, - { 4210, 4225, 4227, 4186, 4169, }, - { 2247, 8245, 4392, 2522, 1709, }, - { 7211, 6741, 6110, 5397, 4680, }, - { 3602, 2286, 1577, 1229, 1148, }, - { 6674, 5227, 3576, 2448, 1901, }, - { 954, 1035, 1079, 1683, 9558, }, - { 4011, 5853, 8979, 7138, 4484, }, - { 2784, 2702, 2637, 2546, 2471, }, - { 4414, 4065, 4627, 4208, 9275, }, - { 2771, 3012, 3357, 3735, 4066, }, - { 19742, 8603, 3943, 2546, 2085, }, - { 1132, 1123, 1107, 1093, 1114, }, - { 3913, 3838, 3733, 3630, 3548, }, - { 948, 1565, 6063, 2654, 1667, }, - { 6159, 5567, 4884, 4241, 3770, }, - { 925, 1164, 1585, 6062, 3090, }, - { 3818, 4037, 4322, 4536, 4726, }, - { 4291, 3894, 3441, 3006, 2733, }, - { 8544, 6487, 4962, 3812, 2970, }, - { 1744, 1758, 1704, 1633, 1576, }, - { 4416, 4259, 4044, 3810, 3628, }, - { 1919, 2159, 3323, 13977, 7898, }, - { 5952, 5731, 5419, 5061, 4732, }, - { 2775, 2812, 2507, 2540, 6585, }, - { 3436, 3960, 4661, 5975, 6274, }, - { 3082, 3150, 3246, 3337, 3404, }, - { 4089, 16018, 8285, 4116, 2704, }, - { 1419, 1425, 1400, 1371, 1363, }, - { 3825, 3890, 3953, 3993, 4015, }, - { 2498, 2689, 2846, 3011, 3213, }, - { 5122, 5024, 4881, 4691, 4524, }, - { 2285, 2325, 2317, 2313, 2271, }, - { 4493, 4529, 4517, 4478, 4443, }, - { 9138, 3969, 2522, 2222, 2415, }, - { 10009, 8719, 7292, 5837, 4532, }, - { 831, 908, 1039, 1656, 6813, }, - { 2070, 5478, 5174, 3911, 3694, }, - { 1577, 1565, 1635, 2583, 13154, }, - { 5590, 5788, 5922, 6752, 7063, }, - { 4061, 3497, 2710, 2099, 1716, }, - { 2750, 3118, 16574, 7891, 3651, }, - { 2598, 3072, 3809, 4906, 5172, }, - { 15348, 10948, 7740, 4979, 3446, }, + { 773, 785, 785, 785, 860, }, + { 3560, 3521, 3410, 3265, 3167, }, + { 1766, 2982, 10273, 3790, 2248, }, + { 4986, 4753, 4496, 4172, 3922, }, + { 2036, 2030, 2009, 1973, 1897, }, + { 3291, 3554, 3868, 4126, 4345, }, + { 3207, 3122, 3026, 2913, 2797, }, + { 13220, 6844, 3967, 2746, 2466, }, + { 1553, 1627, 1392, 1766, 3679, }, + { 5379, 4640, 3844, 3254, 2635, }, + { 1600, 1622, 2430, 9446, 4214, }, + { 5115, 5200, 5311, 5365, 5343, }, + { 6229, 3008, 1989, 1622, 1597, }, + { 1726, 2114, 7046, 6162, 4301, }, + { 1004, 1056, 1841, 6006, 7101, }, + { 6388, 9659, 4510, 2774, 2113, }, + { 1060, 1153, 1400, 1733, 2121, }, + { 3448, 3523, 3612, 3683, 3770, }, + { 1496, 2045, 2910, 3563, 4058, }, + { 4419, 4592, 4795, 4921, 4978, }, + { 1407, 5314, 2788, 1675, 1350, }, + { 4210, 4225, 4227, 4186, 4169, }, + { 2247, 8245, 4392, 2522, 1709, }, + { 7211, 6741, 6110, 5397, 4680, }, + { 3602, 2286, 1577, 1229, 1148, }, + { 6674, 5227, 3576, 2448, 1901, }, + { 954, 1035, 1079, 1683, 9558, }, + { 4011, 5853, 8979, 7138, 4484, }, + { 2784, 2702, 2637, 2546, 2471, }, + { 4414, 4065, 4627, 4208, 9275, }, + { 2771, 3012, 3357, 3735, 4066, }, + { 19742, 8603, 3943, 2546, 2085, }, + { 1132, 1123, 1107, 1093, 1114, }, + { 3913, 3838, 3733, 3630, 3548, }, + { 948, 1565, 6063, 2654, 1667, }, + { 6159, 5567, 4884, 4241, 3770, }, + { 925, 1164, 1585, 6062, 3090, }, + { 3818, 4037, 4322, 4536, 4726, }, + { 4291, 3894, 3441, 3006, 2733, }, + { 8544, 6487, 4962, 3812, 2970, }, + { 1744, 1758, 1704, 1633, 1576, }, + { 4416, 4259, 4044, 3810, 3628, }, + { 1919, 2159, 3323, 13977, 7898, }, + { 5952, 5731, 5419, 5061, 4732, }, + { 2775, 2812, 2507, 2540, 6585, }, + { 3436, 3960, 4661, 5975, 6274, }, + { 3082, 3150, 3246, 3337, 3404, }, + { 4089, 16018, 8285, 4116, 2704, }, + { 1419, 1425, 1400, 1371, 1363, }, + { 3825, 3890, 3953, 3993, 4015, }, + { 2498, 2689, 2846, 3011, 3213, }, + { 5122, 5024, 4881, 4691, 4524, }, + { 2285, 2325, 2317, 2313, 2271, }, + { 4493, 4529, 4517, 4478, 4443, }, + { 9138, 3969, 2522, 2222, 2415, }, + { 10009, 8719, 7292, 5837, 4532, }, + { 831, 908, 1039, 1656, 6813, }, + { 2070, 5478, 5174, 3911, 3694, }, + { 1577, 1565, 1635, 2583, 13154, }, + { 5590, 5788, 5922, 6752, 7063, }, + { 4061, 3497, 2710, 2099, 1716, }, + { 2750, 3118, 16574, 7891, 3651, }, + { 2598, 3072, 3809, 4906, 5172, }, + { 15348, 10948, 7740, 4979, 3446, }, }; const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5] = /* Q12 */ { - { 961, 867, 812, 771, 775, }, - { 2544, 2686, 3010, 3605, 5048, }, - { 1524, 1818, 2889, 3029, 3046, }, - { 4195, 4301, 4421, 4497, 4580, }, - { 2026, 1990, 1965, 1943, 1939, }, - { 4338, 4156, 3963, 3750, 3590, }, - { 7732, 2904, 1804, 1407, 1513, }, - { 1613, 2353, 11315, 5764, 4291, }, - { 1519, 1462, 1434, 1341, 1294, }, - { 1627, 1710, 2163, 9654, 5615, }, - { 2322, 7293, 3251, 2020, 2066, }, - { 4967, 5112, 5174, 5203, 5230, }, - { 1590, 1449, 1943, 5947, 3563, }, - { 7747, 5170, 3268, 2392, 2082, }, - { 3970, 3559, 3164, 2774, 2493, }, - { 1993, 2210, 3204, 3717, 23534, }, - { 1185, 1236, 1423, 2115, 4772, }, - { 3935, 3840, 3714, 3583, 3477, }, - { 1640, 1550, 1800, 2609, 10880, }, - { 4067, 4437, 4811, 5108, 5536, }, - { 1472, 1367, 1533, 2132, 7352, }, - { 4310, 4284, 4216, 4117, 4057, }, - { 10817, 4587, 2611, 2066, 2037, }, - { 2089, 2427, 4698, 14635, 7517, }, - { 2529, 1561, 1209, 976, 945, }, - { 2908, 3070, 4055, 5862, 6448, }, - { 2676, 2861, 3115, 3295, 3408, }, - { 2932, 14330, 6533, 3739, 3462, }, - { 3681, 3079, 2559, 2151, 1903, }, - { 5636, 5316, 4978, 4690, 4425, }, - { 2298, 7228, 6976, 4251, 3347, }, - { 2504, 3421, 6784, 8483, 15064, }, - { 1253, 1180, 1136, 1094, 1076, }, - { 3451, 3524, 3600, 3646, 3707, }, - { 1701, 2030, 6574, 4746, 4451, }, - { 4688, 4751, 4762, 4727, 4722, }, - { 2977, 2363, 1883, 1563, 1399, }, - { 5080, 4685, 4275, 3835, 3513, }, - { 5445, 3828, 2851, 2242, 1948, }, - { 1929, 5037, 17760, 8346, 6300, }, - { 1839, 1782, 1680, 1586, 1534, }, - { 3086, 3472, 4031, 4950, 9695, }, - { 3199, 3052, 2896, 2751, 2622, }, - { 5822, 5782, 5727, 5566, 5478, }, - { 1548, 2234, 6748, 2562, 1722, }, - { 6699, 5216, 4475, 3531, 3028, }, - { 3773, 3628, 3460, 3279, 3155, }, - { 1581, 1672, 2929, 20221, 16432, }, - { 1210, 1215, 1389, 1678, 2177, }, - { 3863, 3886, 3937, 3961, 3989, }, - { 1541, 1745, 1829, 3479, 15563, }, - { 4444, 4952, 5573, 6056, 6545, }, - { 2460, 2397, 2284, 2133, 2041, }, - { 4808, 4676, 4493, 4322, 4213, }, - { 15031, 6644, 3315, 2900, 2885, }, - { 4003, 4760, 6946, 8274, 8401, }, - { 5001, 2495, 1594, 1337, 1365, }, - { 3428, 3706, 4073, 4457, 4670, }, - { 3326, 3277, 3222, 3142, 3088, }, - { 6162, 6317, 6494, 6459, 6530, }, - { 2659, 2599, 2537, 2482, 2546, }, - { 8554, 6902, 5233, 4116, 3650, }, - { 4643, 4099, 3616, 3201, 2895, }, - { 9589, 26630, 15412, 12532, 8715, }, + { 961, 867, 812, 771, 775, }, + { 2544, 2686, 3010, 3605, 5048, }, + { 1524, 1818, 2889, 3029, 3046, }, + { 4195, 4301, 4421, 4497, 4580, }, + { 2026, 1990, 1965, 1943, 1939, }, + { 4338, 4156, 3963, 3750, 3590, }, + { 7732, 2904, 1804, 1407, 1513, }, + { 1613, 2353, 11315, 5764, 4291, }, + { 1519, 1462, 1434, 1341, 1294, }, + { 1627, 1710, 2163, 9654, 5615, }, + { 2322, 7293, 3251, 2020, 2066, }, + { 4967, 5112, 5174, 5203, 5230, }, + { 1590, 1449, 1943, 5947, 3563, }, + { 7747, 5170, 3268, 2392, 2082, }, + { 3970, 3559, 3164, 2774, 2493, }, + { 1993, 2210, 3204, 3717, 23534, }, + { 1185, 1236, 1423, 2115, 4772, }, + { 3935, 3840, 3714, 3583, 3477, }, + { 1640, 1550, 1800, 2609, 10880, }, + { 4067, 4437, 4811, 5108, 5536, }, + { 1472, 1367, 1533, 2132, 7352, }, + { 4310, 4284, 4216, 4117, 4057, }, + { 10817, 4587, 2611, 2066, 2037, }, + { 2089, 2427, 4698, 14635, 7517, }, + { 2529, 1561, 1209, 976, 945, }, + { 2908, 3070, 4055, 5862, 6448, }, + { 2676, 2861, 3115, 3295, 3408, }, + { 2932, 14330, 6533, 3739, 3462, }, + { 3681, 3079, 2559, 2151, 1903, }, + { 5636, 5316, 4978, 4690, 4425, }, + { 2298, 7228, 6976, 4251, 3347, }, + { 2504, 3421, 6784, 8483, 15064, }, + { 1253, 1180, 1136, 1094, 1076, }, + { 3451, 3524, 3600, 3646, 3707, }, + { 1701, 2030, 6574, 4746, 4451, }, + { 4688, 4751, 4762, 4727, 4722, }, + { 2977, 2363, 1883, 1563, 1399, }, + { 5080, 4685, 4275, 3835, 3513, }, + { 5445, 3828, 2851, 2242, 1948, }, + { 1929, 5037, 17760, 8346, 6300, }, + { 1839, 1782, 1680, 1586, 1534, }, + { 3086, 3472, 4031, 4950, 9695, }, + { 3199, 3052, 2896, 2751, 2622, }, + { 5822, 5782, 5727, 5566, 5478, }, + { 1548, 2234, 6748, 2562, 1722, }, + { 6699, 5216, 4475, 3531, 3028, }, + { 3773, 3628, 3460, 3279, 3155, }, + { 1581, 1672, 2929, 20221, 16432, }, + { 1210, 1215, 1389, 1678, 2177, }, + { 3863, 3886, 3937, 3961, 3989, }, + { 1541, 1745, 1829, 3479, 15563, }, + { 4444, 4952, 5573, 6056, 6545, }, + { 2460, 2397, 2284, 2133, 2041, }, + { 4808, 4676, 4493, 4322, 4213, }, + { 15031, 6644, 3315, 2900, 2885, }, + { 4003, 4760, 6946, 8274, 8401, }, + { 5001, 2495, 1594, 1337, 1365, }, + { 3428, 3706, 4073, 4457, 4670, }, + { 3326, 3277, 3222, 3142, 3088, }, + { 6162, 6317, 6494, 6459, 6530, }, + { 2659, 2599, 2537, 2482, 2546, }, + { 8554, 6902, 5233, 4116, 3650, }, + { 4643, 4099, 3616, 3201, 2895, }, + { 9589, 26630, 15412, 12532, 8715, }, }; const Word16 frac_4sf_fx[NB_SUBFR + 2] = { 4,8,12,16,16,16 }; /* Q4 */ @@ -19715,7 +19715,7 @@ const Word16 ct2[7][13] = /*12*/ { 9, 3, 4, 5, 9, 0, 0, 0, 5, 0, 5, 5, 4}, /*32*/ { 4, 4, 4, 4, 4, 0, 0, 0, 2, 1, 1, 4, 4}, /*48*/ {18, 18, 18, 18, 18, 0, 0, 0, 5, 2, 1, 4, 15}, -}; // Q0 +}; // Q0 const Word16 ct2_fx[7][14] = { /* accepted configurations */ @@ -19992,7 +19992,7 @@ const SCALE_TCX_SETUP scaleTcxTable[SIZE_SCALE_TABLE_TCX] = * Arithmetic coder *----------------------------------------------------------------------------------*/ -const UWord8 ari_lookup_s17_LC[4096] = // Q0 +const UWord8 ari_lookup_s17_LC[4096] = // Q0 { 0x01,0x04,0x29,0x13,0x0A,0x0D,0x05,0x10, 0x10,0x0D,0x00,0x0D,0x2A,0x2A,0x22,0x25, @@ -20508,7 +20508,7 @@ const UWord8 ari_lookup_s17_LC[4096] = // Q0 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A }; -const UWord16 ari_pk_s17_LC_ext[64][18] = // Q0 +const UWord16 ari_pk_s17_LC_ext[64][18] = // Q0 { { 16384, 16368,16337,16231,16143,16115,16059,15916,15793,15710,15586,15472,15367,15302,15201,15107,15020, @@ -20779,7 +20779,7 @@ const Word16 NumRatioBits[2][17] = { 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2 } -}; // Q0 +}; // Q0 /* 7Q8 */ const Word16 Ratios_WB_2_fx[32] = @@ -21330,7 +21330,7 @@ const Coding * const codesTnsCoeffSWBTCX20[] = { codesTnsCoeff0TCX20, codesTnsCo const Coding * const codesTnsCoeffSWBTCX10[] = { codesTnsCoeff0TCX10, codesTnsCoeff1TCX10, codesTnsCoeff2TCX10, codesTnsCoeff3TCX10, codesTnsCoeff4TCX10, codesTnsCoeff5, codesTnsCoeff6, codesTnsCoeff7 }; const Coding * const codesTnsCoeffWBTCX20[] = { codesTnsCoeff0WBTCX20, codesTnsCoeff1WBTCX20, codesTnsCoeff2WB, codesTnsCoeff3WB, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff7 }; -const Word16 nTnsCoeffTables = sizeof(codesTnsCoeffSWBTCX20)/sizeof(codesTnsCoeffSWBTCX20[0]); // Q0 +const Word16 nTnsCoeffTables = sizeof(codesTnsCoeffSWBTCX20)/sizeof(codesTnsCoeffSWBTCX20[0]); // Q0 const Coding codesTnsOrderTCX20[] = { @@ -21366,7 +21366,7 @@ const Coding codesTnsOrder[] = { 8, 0, 1 } /* 0 */ }; -const Word16 nTnsOrderCodes = sizeof(codesTnsOrder)/sizeof(codesTnsOrder[0]); // Q0 +const Word16 nTnsOrderCodes = sizeof(codesTnsOrder)/sizeof(codesTnsOrder[0]); // Q0 const ParamsBitMap tnsSWBTCX20FilterCoeffBitMap = { @@ -21503,22 +21503,22 @@ const ParamsBitMap tnsEnabledOnWhiteSWBTCX10BitMap = */ const Word16 tnsCoeff4[16] = { - -32628/*-0.99573418F Q15*/, /* = sin(-8*(PI/2.0)/(8 + 0.5)) */ - -31517/*-0.96182564F Q15*/, /* = sin(-7*(PI/2.0)/(8 + 0.5)) */ - -29333/*-0.89516329F Q15*/, - -26149/*-0.79801723F Q15*/, - -22076/*-0.67369564F Q15*/, - -17250/*-0.52643216F Q15*/, - -11837/*-0.36124167F Q15*/, - -6021/*-0.18374952F Q15*/, /* = sin(-1*(PI/2.0)/(8 + 0.5)) */ - 0/* 0.00000000F Q15*/, /* = sin(0*(PI/2.0)/(8 + 0.5)) */ - 6813/* 0.20791169F Q15*/, /* = sin(1*(PI/2.0)/(8 - 0.5)) */ - 13328/* 0.40673664F Q15*/, - 19261/* 0.58778525F Q15*/, - 24351/* 0.74314483F Q15*/, - 28378/* 0.86602540F Q15*/, - 31164/* 0.95105652F Q15*/, /* = sin(6*(PI/2.0)/(8 - 0.5)) */ - 32588/* 0.99452190F Q15*/ /* = sin(7*(PI/2.0)/(8 - 0.5)) */ + -32628/*-0.99573418F Q15*/, /* = sin(-8*(PI/2.0)/(8 + 0.5)) */ + -31517/*-0.96182564F Q15*/, /* = sin(-7*(PI/2.0)/(8 + 0.5)) */ + -29333/*-0.89516329F Q15*/, + -26149/*-0.79801723F Q15*/, + -22076/*-0.67369564F Q15*/, + -17250/*-0.52643216F Q15*/, + -11837/*-0.36124167F Q15*/, + -6021/*-0.18374952F Q15*/, /* = sin(-1*(PI/2.0)/(8 + 0.5)) */ + 0/* 0.00000000F Q15*/, /* = sin(0*(PI/2.0)/(8 + 0.5)) */ + 6813/* 0.20791169F Q15*/, /* = sin(1*(PI/2.0)/(8 - 0.5)) */ + 13328/* 0.40673664F Q15*/, + 19261/* 0.58778525F Q15*/, + 24351/* 0.74314483F Q15*/, + 28378/* 0.86602540F Q15*/, + 31164/* 0.95105652F Q15*/, /* = sin(6*(PI/2.0)/(8 - 0.5)) */ + 32588/* 0.99452190F Q15*/ /* = sin(7*(PI/2.0)/(8 - 0.5)) */ }; @@ -21526,7 +21526,7 @@ const Word16 tnsCoeff4[16] = * IGF settings for each bitrate *----------------------------------------------------------------------------------*/ -const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = // Q0 +const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = // Q0 { /* 0: for 9600 kbs WB */ { @@ -21674,7 +21674,7 @@ const Word16 swb_offset_LB_new[IGF_BITRATE_UNKNOWN][IGF_MAX_SFB] = // Q0 } };/*Q0*/ -const Word16 igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2*IGF_MAX_TILES+1] = { // Q0 +const Word16 igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2*IGF_MAX_TILES+1] = { // Q0 { 2, 2, 0, 3, 0}, /* 9600 WB*/ { 2, 2, 0, 3, 0}, /* 13200 WB RF */ { 3, 1, 0, 2, 32, 3, 46}, /* 9600 SWB */ @@ -21715,187 +21715,187 @@ const Word16 igf_tile_offset_table[IGF_BITRATE_UNKNOWN][2*IGF_MAX_TILES+1] = { / const Word16 igf_whitening_TH_ivas_fx[][2][IGF_MAX_TILES] = { - /* 0: for 9600 kbs WB */ - { - /* medium */ { 2949/*0.36f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 11551/*1.41f Q13*/, 11551/*1.41f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 1: for 13200 kbs WB RF */ - { - /* medium */ { 2949/*0.36f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 11551/*1.41f Q13*/, 11551/*1.41f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 2: for 9600 kbs SWB */ - { - /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 3: for 13200 kbs SWB */ - { - /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 4: for 13200 kbs SWB RF */ - { - /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 5: for 16400 kbs SWB */ - { - /* medium */ { 6799/*0.83f Q13*/, 7291/*0.89f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10732/*1.31f Q13*/, 9748/*1.19f Q13*/, 9748/*1.19f Q13*/, 0/*0.f Q13*/} - }, - /* 6: for 24400 kbs SWB*/ - { - /* medium */ { 6636/*0.81f Q13*/, 6963/*0.85f Q13*/, 6963/*0.85f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 11059/*1.35f Q13*/, 10076/*1.23f Q13*/, 10076/*1.23f Q13*/, 0/*0.f Q13*/} - }, - /* 7: for 32000 kbs SWB */ - { - /* medium */ { 7455/*0.91f Q13*/, 6963/*0.85f Q13*/, 6963/*0.85f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10977/*1.34f Q13*/, 11059/*1.35f Q13*/, 11059/*1.35f Q13*/, 0/*0.f Q13*/} - }, - /* 8: for 48000 kbs SWB */ - { - /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 9: for 64000 kbs SWB */ - { - /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 10: for 16400 kbs FB */ - { - /* medium */ { 5161/*0.63f Q13*/, 2212/*0.27f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 12534/*1.53f Q13*/, 10813/*1.32f Q13*/, 5489/*0.67f Q13*/, 0/*0.f Q13*/} - }, - /* 11: for 24400 kbs FB */ - { - /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, - /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} - }, - /* 12: for 32000 kbs FB */ - { - /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, - /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} - }, - /* 13: for 48000 kbs FB */ - { - /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 14: for 64000 kbs FB */ - { - /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 15: for 96000 kbs FB */ - { - /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 16: for 128000 kbs FB */ - { - /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 17: for 13200 kbs WB (stereo) */ - { - /* medium */ {6554/*0.800000 Q13*/, 6144/*0.750000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {12288/*1.500000 Q13*/, 11878/*1.450000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 18: for 16400 kbs WB (stereo) */ - { - - /* medium */ {7373/*0.900000 Q13*/, 6963/*0.850000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {13107/*1.600000 Q13*/, 12288/*1.500000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 19: for 13200 kbs SWB (stereo) */ - { - /* medium */ {7291/*0.890000 Q13*/, 7291/*0.890000 Q13*/, 6554/*0.800000 Q13*/, 6554/*0.800000 Q13*/, }, - /* strong */ {10240/*1.250000 Q13*/, 10240/*1.250000 Q13*/, 9748/*1.190000 Q13*/, 9748/*1.190000 Q13*/, } - }, - /* 20: for 16400 kbs SWB (stereo) */ - { - /* medium */ {8602/*1.050000 Q13*/, 8602/*1.050000 Q13*/, 9011/*1.100000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8602/*1.050000 Q13*/, }, - /* strong */ {13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13517/*1.650000 Q13*/, 13517/*1.650000 Q13*/, 13107/*1.600000 Q13*/, 12288/*1.500000 Q13*/, } - }, - /* 21: for 24400 kbs SWB (stereo) */ - { - /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, }, - /* strong */ {13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, } - }, - /* 22: for 32000 kbs SWB (stereo) */ - { - /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, }, - /* strong */ {14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 13517/*1.650000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, } - }, - /* 23: for 48000 kbs SWB (stereo) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ - { - /* medium */ {6144/*0.750000 Q13*/, 5734/*0.700000 Q13*/, 4096/*0.500000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {10240/*1.250000 Q13*/, 9011/*1.100000 Q13*/, 8192/*1.000000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 24: for 48000 kbs SWB (stereo TCX10) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ - { - /* medium */ {6144/*0.750000 Q13*/, 5734/*0.700000 Q13*/, 4096/*0.500000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {10240/*1.250000 Q13*/, 9011/*1.100000 Q13*/, 8192/*1.000000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 25: for 64000 kbs SWB (stereo) */ - { - /* medium */ {8192/*1.000000 Q13*/, 8192/*1.000000 Q13*/, 9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/ }, - /* strong */ {12288/*1.500000 Q13*/, 12288/*1.500000 Q13*/, 13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/ } - }, - /* 26: for 80000 kbs SWB (stereo) */ - { - /* medium */ {9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 27: for 96000 kbs SWB (stereo) */ - { - /* medium */ {9421/*1.150000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {9748/*1.190000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 28: for 24400 kbs FB (stereo) */ - { - /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, 2785/*0.340000 Q13*/, 2785/*0.340000 Q13*/ }, - /* strong */ {13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, 5325/*0.650000 Q13*/, 5325/*0.650000 Q13*/ } - }, - /* 29: for 32000 kbs FB (stereo) */ - { - /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, 2785/*0.340000 Q13*/, 2785/*0.340000 Q13*/ }, - /* strong */ {14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 13517/*1.650000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, 5325/*0.650000 Q13*/, 5325/*0.650000 Q13*/ } - }, - /* 30: for 48000 kbs FB (stereo) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ - { - /* medium */ {6390/*0.780000 Q13*/, 2540/*0.310000 Q13*/, 2785/*0.340000 Q13*/, 2785/*0.340000 Q13*/ }, - /* strong */ {12206/*1.490000 Q13*/, 11305/*1.380000 Q13*/, 5325/*0.650000 Q13*/, 5325/*0.650000 Q13*/ } - }, - /* 31: for 48000 kbs FB (stereo TCX10) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ - { - /* medium */ {6144/*0.750000 Q13*/, 5734/*0.700000 Q13*/, 4096/*0.500000 Q13*/, 4096/*0.500000 Q13*/ }, - /* strong */ {10240/*1.250000 Q13*/, 9011/*1.100000 Q13*/, 8192/*1.000000 Q13*/, 8192/*1.000000 Q13*/ } - }, - /* 32: for 64000 kbs FB (stereo) */ - { - /* medium */ {8192/*1.000000 Q13*/, 8192/*1.000000 Q13*/, 9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/, 6144/*0.750000 Q13*/ }, - /* strong */ {12288/*1.500000 Q13*/, 12288/*1.500000 Q13*/, 13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/, 8192/*1.000000 Q13*/ } - }, - /* 33: for 80000 kbs FB (stereo) */ - { - /* medium */ {9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/, 6144/*0.750000 Q13*/, 0/*0.000000 Q13*/ }, - /* strong */ {13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/, 8192/*1.000000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 34: for 96000 kbs FB (stereo) */ - { - /* medium */ {7455/*0.910000 Q13*/, 6963/*0.850000 Q13*/ , 0/*0.000000 Q13*/ }, - /* strong */ {10977/*1.340000 Q13*/, 11059/*1.350000 Q13*/, 0/*0.000000 Q13*/ } - }, - /* 35: for 128000 kbs FB (stereo) */ - { - /* medium */ { 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/}, - /* strong */ {23101/*2.820000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/} - } + /* 0: for 9600 kbs WB */ + { + /* medium */ { 2949/*0.36f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 11551/*1.41f Q13*/, 11551/*1.41f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 1: for 13200 kbs WB RF */ + { + /* medium */ { 2949/*0.36f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 11551/*1.41f Q13*/, 11551/*1.41f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 2: for 9600 kbs SWB */ + { + /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 3: for 13200 kbs SWB */ + { + /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 4: for 13200 kbs SWB RF */ + { + /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 5: for 16400 kbs SWB */ + { + /* medium */ { 6799/*0.83f Q13*/, 7291/*0.89f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 10732/*1.31f Q13*/, 9748/*1.19f Q13*/, 9748/*1.19f Q13*/, 0/*0.f Q13*/} + }, + /* 6: for 24400 kbs SWB*/ + { + /* medium */ { 6636/*0.81f Q13*/, 6963/*0.85f Q13*/, 6963/*0.85f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 11059/*1.35f Q13*/, 10076/*1.23f Q13*/, 10076/*1.23f Q13*/, 0/*0.f Q13*/} + }, + /* 7: for 32000 kbs SWB */ + { + /* medium */ { 7455/*0.91f Q13*/, 6963/*0.85f Q13*/, 6963/*0.85f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 10977/*1.34f Q13*/, 11059/*1.35f Q13*/, 11059/*1.35f Q13*/, 0/*0.f Q13*/} + }, + /* 8: for 48000 kbs SWB */ + { + /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 9: for 64000 kbs SWB */ + { + /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 10: for 16400 kbs FB */ + { + /* medium */ { 5161/*0.63f Q13*/, 2212/*0.27f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 12534/*1.53f Q13*/, 10813/*1.32f Q13*/, 5489/*0.67f Q13*/, 0/*0.f Q13*/} + }, + /* 11: for 24400 kbs FB */ + { + /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, + /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} + }, + /* 12: for 32000 kbs FB */ + { + /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, + /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} + }, + /* 13: for 48000 kbs FB */ + { + /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 14: for 64000 kbs FB */ + { + /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 15: for 96000 kbs FB */ + { + /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 16: for 128000 kbs FB */ + { + /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, + /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} + }, + /* 17: for 13200 kbs WB (stereo) */ + { + /* medium */ {6554/*0.800000 Q13*/, 6144/*0.750000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {12288/*1.500000 Q13*/, 11878/*1.450000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 18: for 16400 kbs WB (stereo) */ + { + + /* medium */ {7373/*0.900000 Q13*/, 6963/*0.850000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {13107/*1.600000 Q13*/, 12288/*1.500000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 19: for 13200 kbs SWB (stereo) */ + { + /* medium */ {7291/*0.890000 Q13*/, 7291/*0.890000 Q13*/, 6554/*0.800000 Q13*/, 6554/*0.800000 Q13*/, }, + /* strong */ {10240/*1.250000 Q13*/, 10240/*1.250000 Q13*/, 9748/*1.190000 Q13*/, 9748/*1.190000 Q13*/, } + }, + /* 20: for 16400 kbs SWB (stereo) */ + { + /* medium */ {8602/*1.050000 Q13*/, 8602/*1.050000 Q13*/, 9011/*1.100000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8602/*1.050000 Q13*/, }, + /* strong */ {13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13517/*1.650000 Q13*/, 13517/*1.650000 Q13*/, 13107/*1.600000 Q13*/, 12288/*1.500000 Q13*/, } + }, + /* 21: for 24400 kbs SWB (stereo) */ + { + /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, }, + /* strong */ {13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, } + }, + /* 22: for 32000 kbs SWB (stereo) */ + { + /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, }, + /* strong */ {14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 13517/*1.650000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, } + }, + /* 23: for 48000 kbs SWB (stereo) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ + { + /* medium */ {6144/*0.750000 Q13*/, 5734/*0.700000 Q13*/, 4096/*0.500000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {10240/*1.250000 Q13*/, 9011/*1.100000 Q13*/, 8192/*1.000000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 24: for 48000 kbs SWB (stereo TCX10) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ + { + /* medium */ {6144/*0.750000 Q13*/, 5734/*0.700000 Q13*/, 4096/*0.500000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {10240/*1.250000 Q13*/, 9011/*1.100000 Q13*/, 8192/*1.000000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 25: for 64000 kbs SWB (stereo) */ + { + /* medium */ {8192/*1.000000 Q13*/, 8192/*1.000000 Q13*/, 9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/ }, + /* strong */ {12288/*1.500000 Q13*/, 12288/*1.500000 Q13*/, 13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/ } + }, + /* 26: for 80000 kbs SWB (stereo) */ + { + /* medium */ {9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 27: for 96000 kbs SWB (stereo) */ + { + /* medium */ {9421/*1.150000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {9748/*1.190000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 28: for 24400 kbs FB (stereo) */ + { + /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, 2785/*0.340000 Q13*/, 2785/*0.340000 Q13*/ }, + /* strong */ {13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 13926/*1.700000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, 5325/*0.650000 Q13*/, 5325/*0.650000 Q13*/ } + }, + /* 29: for 32000 kbs FB (stereo) */ + { + /* medium */ {9830/*1.200000 Q13*/, 9830/*1.200000 Q13*/, 9421/*1.150000 Q13*/, 9421/*1.150000 Q13*/, 9011/*1.100000 Q13*/, 8602/*1.050000 Q13*/, 8192/*1.000000 Q13*/, 7373/*0.900000 Q13*/, 2785/*0.340000 Q13*/, 2785/*0.340000 Q13*/ }, + /* strong */ {14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 14746/*1.800000 Q13*/, 13517/*1.650000 Q13*/, 12698/*1.550000 Q13*/, 11878/*1.450000 Q13*/, 9830/*1.200000 Q13*/, 5325/*0.650000 Q13*/, 5325/*0.650000 Q13*/ } + }, + /* 30: for 48000 kbs FB (stereo) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ + { + /* medium */ {6390/*0.780000 Q13*/, 2540/*0.310000 Q13*/, 2785/*0.340000 Q13*/, 2785/*0.340000 Q13*/ }, + /* strong */ {12206/*1.490000 Q13*/, 11305/*1.380000 Q13*/, 5325/*0.650000 Q13*/, 5325/*0.650000 Q13*/ } + }, + /* 31: for 48000 kbs FB (stereo TCX10) */ /* currently not used due to adaptive calculation of thresholds at 48 kbps */ + { + /* medium */ {6144/*0.750000 Q13*/, 5734/*0.700000 Q13*/, 4096/*0.500000 Q13*/, 4096/*0.500000 Q13*/ }, + /* strong */ {10240/*1.250000 Q13*/, 9011/*1.100000 Q13*/, 8192/*1.000000 Q13*/, 8192/*1.000000 Q13*/ } + }, + /* 32: for 64000 kbs FB (stereo) */ + { + /* medium */ {8192/*1.000000 Q13*/, 8192/*1.000000 Q13*/, 9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/, 6144/*0.750000 Q13*/ }, + /* strong */ {12288/*1.500000 Q13*/, 12288/*1.500000 Q13*/, 13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/, 8192/*1.000000 Q13*/ } + }, + /* 33: for 80000 kbs FB (stereo) */ + { + /* medium */ {9830/*1.200000 Q13*/, 10240/*1.250000 Q13*/, 6144/*0.750000 Q13*/, 0/*0.000000 Q13*/ }, + /* strong */ {13107/*1.600000 Q13*/, 13107/*1.600000 Q13*/, 8192/*1.000000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 34: for 96000 kbs FB (stereo) */ + { + /* medium */ {7455/*0.910000 Q13*/, 6963/*0.850000 Q13*/ , 0/*0.000000 Q13*/ }, + /* strong */ {10977/*1.340000 Q13*/, 11059/*1.350000 Q13*/, 0/*0.000000 Q13*/ } + }, + /* 35: for 128000 kbs FB (stereo) */ + { + /* medium */ { 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/}, + /* strong */ {23101/*2.820000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/, 0/*0.000000 Q13*/} + } }; const Word16 igf_whitening_TH[][2][IGF_MAX_TILES] = { @@ -21988,7 +21988,7 @@ const Word16 igf_whitening_TH[][2][IGF_MAX_TILES] = /* IGF SCF arithmetic coder cumulative frequency tables and offsets */ -const Word16 cf_off_se01_tab[10] = { // Q0 +const Word16 cf_off_se01_tab[10] = { // Q0 +1, /* 9.6 kbs B*/ +1, /* 13.2 kbs WB RF B*/ +1, /* 9.6 kbs SWB B*/ @@ -22001,7 +22001,7 @@ const Word16 cf_off_se01_tab[10] = { // Q0 -1 /* 64.0 kbs B*/ }; -const Word16 cf_off_se02_tab[10][IGF_CTX_COUNT] = { // Q0 +const Word16 cf_off_se02_tab[10][IGF_CTX_COUNT] = { // Q0 { +1, +2, +2, +2, +3, +3, +4}, /* 9.6 kbs B*/ { +1, +2, +2, +2, +3, +3, +4}, /* 13.2 kbs WB RF B*/ { +0, +2, +3, +3, +2, +2, +4}, /* 9.6 kbs SWB B*/ @@ -22014,9 +22014,9 @@ const Word16 cf_off_se02_tab[10][IGF_CTX_COUNT] = { // Q0 { +3, +2, +3, +2, +3, +3, +6} /* 64.0 kbs B*/ }; -const Word16 cf_off_se10_tab = -7; // Q0 +const Word16 cf_off_se10_tab = -7; // Q0 -const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = // Q0 +const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = // Q0 { { -5, +0, +0, +0, +0, +0, +0}, { +0, +0, +0, +0, +0, +0, +0}, @@ -22027,7 +22027,7 @@ const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = // Q0 { +0, +1, +0, +0, +3, +0, +3} }; -const UWord16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = // Q0 +const UWord16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { 16384, 16356, 16299, 16185, 15904, 15282, 14669, 13598, 11886, 9541, 6613, 3845, 1799, 606, 153, 32, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; @@ -22046,7 +22046,7 @@ const UWord16 cf_se01_tab[10][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0} /* 64.0 kbs B*/ }; -const UWord16 cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 +const UWord16 cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { { /* 9.6 kbs B */ { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, @@ -22142,12 +22142,12 @@ const UWord16 cf_se02_tab[10][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 /* only needed for >= 48 kbps */ -const UWord16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = // Q0 +const UWord16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { 16384, 15493, 15154, 14810, 14331, 13701, 13086, 12403, 11585, 10923, 10293, 9631, 8943, 8385, 7760, 7182, 6593, 6009, 5540, 5082, 4571, 4133, 3711, 3299, 2887, 2460, 2043, 0 }; -const UWord16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 +const UWord16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = // Q0 { { { 16384, 16313, 16312, 16241, 16206, 16099, 15957, 15386, 14601, 12852, 10282, 7534, 4964, 2966, 1824, 896, 504, 255, 113, 112, 41, 40, 39, 38, 37, 36, 1, 0}, @@ -22583,9 +22583,9 @@ const Word16 SHB_LSF_VQ3_fx[48] =//Q15 -1241, -1225, -976, -52, -98, -216, -422, -599, -688, 127, 137, 0, 52, 301, 412, -278, -422, 9, 199, 137, 72 }; -const Word16 *const cb_LSF_BWE_fx[] = { SHB_LSF_VQ4_fx, SHB_LSF_VQ3_fx }; // Q15 +const Word16 *const cb_LSF_BWE_fx[] = { SHB_LSF_VQ4_fx, SHB_LSF_VQ3_fx }; // Q15 -const Word16 mslvq_SHB_min_bits[] = {14, 12}; /* for 4 bits and 3 bits respectively Q0*/ +const Word16 mslvq_SHB_min_bits[] = {14, 12}; /* for 4 bits and 3 bits respectively Q0*/ const Word16 scales_BWE_fx[] = {//Q13 7634, 13737, @@ -22605,7 +22605,7 @@ const Word16 scales_BWE_fx_new[] = {//Q11 3622, 6606 }; -const Word8 no_lead_BWE[] = { // Q0 +const Word8 no_lead_BWE[] = { // Q0 8, 6, 5, /* 14 bits */ 10,9,5, /* 15 bits*/ 16, 11, 5}; /* 16 bits */ @@ -22628,7 +22628,7 @@ const Word16 scales_BWE_3b_fx_new[] = {//Q11 5765 }; -const Word8 no_lead_BWE_3b[] = { // Q0 +const Word8 no_lead_BWE_3b[] = { // Q0 4, 5, 2, /* 12 bits */ 5, 5, 5, /* 13 bits */ 8, 6, 5 /* 14 bits */ @@ -22650,7 +22650,7 @@ const Word32 LastCoefPred_1bit_fx[36] = {//Q31 11703786, -7301444, 20444044, 22655952, 138448272, 307648512, 9234180 }; -const Word16 config_LSF_BWE[] = { // Q0 +const Word16 config_LSF_BWE[] = { // Q0 4, 16, 1, /* 21 bits */ 4, 16, 1, /* 20 */ 4, 16, 1, /* 19 */ @@ -24235,15 +24235,15 @@ const Word16 dsDiracsTab[65] = const Word16 pwf_fx[17] =//Q12 { - 22938, 16056, 11239, 7868, 5507, 3855, 2699, 1889, - 1322, 926, 648, 454, 317, 222, 156, 109, + 22938, 16056, 11239, 7868, 5507, 3855, 2699, 1889, + 1322, 926, 648, 454, 317, 222, 156, 109, 76 }; const Word32 inverse_table[] =//Q29 { 0, - 134217728, 67108864, 44739242, 33554432, 26843545, 22369621, 19173961, 16777216, 14913080, 13421772, 12201611, 11184810, 10324440, 9586980, 8947848, 8388608, 7895160, 7456540, 7064090, 6710886, 6391320, 6100805, 5835553, 5592405, 5368709, 5162220, 4971026, 4793490, 4628197, 4473924, 4329604, 4194304, 4067203, 3947580, 3834792, 3728270, 3627506, 3532045, 3441480, 3355443, 3273603, 3195660, 3121342, 3050402, 2982616, 2917776, 2855696, 2796202, 2739137, 2684354, 2631720, 2581110, 2532409, 2485513, 2440322, 2396745, 2354696, 2314098, 2274876, 2236962, 2200290, 2164802, 2130440, 2097152, 2064888, 2033601, 2003249, 1973790, 1945184, 1917396, 1890390, 1864135, 1838599, 1813753, 1789569, 1766022, 1743087, 1720740, 1698958, 1677721, 1657008, 1636801, 1617081, 1597830, 1579032, 1560671, 1542732, 1525201, 1508064, 1491308, 1474920, 1458888, 1443201, 1427848, 1412818, 1398101, 1383687, 1369568, 1355734, 1342177, 1328888, 1315860, 1303084, 1290555, 1278264, 1266204, 1254371, 1242756, 1231355, 1220161, 1209168, 1198372, 1187767, 1177348, 1167110, 1157049, 1147160, 1137438, 1127880, 1118481, 1109237, 1100145, 1091201, 1082401, 1073741, 1065220, 1056832, 1048576, 1040447, 1032444, 1024562, 1016800, 1009155, 1001624, 994205, 986895, 979691, 972592, 965595, 958698, 951898, 945195, 938585, 932067, 925639, 919299, 913045, 906876, 900790, 894784, 888859, 883011, 877240, 871543, 865920, 860370, 854889, 849479, 844136, 838860, 833650, 828504, 823421, 818400, 813440, 808540, 803698, 798915, 794187, 789516, 784898, 780335, 775825, 771366, 766958, 762600, 758292, 754032, 749819, 745654, 741534, 737460, 733430, 729444, 725501, 721600, 717741, 713924, 710146, 706409, 702710, 699050, 695428, 691843, 688296, 684784, 681308, 677867, 674460, 671088, 667749, 664444, 661171, 657930, 654720, 651542, 648394, 645277, 642190, 639132, 636102, 633102, 630130, 627185, 624268, 621378, 618514, 615677, 612866, 610080, 607320, 604584, 601873, 599186, 596523, 593883, 591267, 588674, 586103, 583555, 581029, 578524, 576041, 573580, 571139, 568719, 566319, 563940, 561580, 559240, 556920, 554618, 552336, 550072, 547827, 545600, 543391, 541200, 539027, 536870, 534731, 532610, 530504, 528416, 526344, + 134217728, 67108864, 44739242, 33554432, 26843545, 22369621, 19173961, 16777216, 14913080, 13421772, 12201611, 11184810, 10324440, 9586980, 8947848, 8388608, 7895160, 7456540, 7064090, 6710886, 6391320, 6100805, 5835553, 5592405, 5368709, 5162220, 4971026, 4793490, 4628197, 4473924, 4329604, 4194304, 4067203, 3947580, 3834792, 3728270, 3627506, 3532045, 3441480, 3355443, 3273603, 3195660, 3121342, 3050402, 2982616, 2917776, 2855696, 2796202, 2739137, 2684354, 2631720, 2581110, 2532409, 2485513, 2440322, 2396745, 2354696, 2314098, 2274876, 2236962, 2200290, 2164802, 2130440, 2097152, 2064888, 2033601, 2003249, 1973790, 1945184, 1917396, 1890390, 1864135, 1838599, 1813753, 1789569, 1766022, 1743087, 1720740, 1698958, 1677721, 1657008, 1636801, 1617081, 1597830, 1579032, 1560671, 1542732, 1525201, 1508064, 1491308, 1474920, 1458888, 1443201, 1427848, 1412818, 1398101, 1383687, 1369568, 1355734, 1342177, 1328888, 1315860, 1303084, 1290555, 1278264, 1266204, 1254371, 1242756, 1231355, 1220161, 1209168, 1198372, 1187767, 1177348, 1167110, 1157049, 1147160, 1137438, 1127880, 1118481, 1109237, 1100145, 1091201, 1082401, 1073741, 1065220, 1056832, 1048576, 1040447, 1032444, 1024562, 1016800, 1009155, 1001624, 994205, 986895, 979691, 972592, 965595, 958698, 951898, 945195, 938585, 932067, 925639, 919299, 913045, 906876, 900790, 894784, 888859, 883011, 877240, 871543, 865920, 860370, 854889, 849479, 844136, 838860, 833650, 828504, 823421, 818400, 813440, 808540, 803698, 798915, 794187, 789516, 784898, 780335, 775825, 771366, 766958, 762600, 758292, 754032, 749819, 745654, 741534, 737460, 733430, 729444, 725501, 721600, 717741, 713924, 710146, 706409, 702710, 699050, 695428, 691843, 688296, 684784, 681308, 677867, 674460, 671088, 667749, 664444, 661171, 657930, 654720, 651542, 648394, 645277, 642190, 639132, 636102, 633102, 630130, 627185, 624268, 621378, 618514, 615677, 612866, 610080, 607320, 604584, 601873, 599186, 596523, 593883, 591267, 588674, 586103, 583555, 581029, 578524, 576041, 573580, 571139, 568719, 566319, 563940, 561580, 559240, 556920, 554618, 552336, 550072, 547827, 545600, 543391, 541200, 539027, 536870, 534731, 532610, 530504, 528416, 526344, }; const Word16 cos_diff_table[512] =//Q15 @@ -24576,9 +24576,9 @@ const Word32 pow_tilt_32k[64] = { 1029387260, 1121709444, 1222311686, 1331936594, 1451393382, 1581563835, 1723408827, 1877975405 }; -const Word16 L_frame_inv[8] = { 0x4000, 0x369D, 0x3333, 0x2D83, 0x2AAB, 0x28F6, 0, 0x2222 }; // Q14 +const Word16 L_frame_inv[8] = { 0x4000, 0x369D, 0x3333, 0x2D83, 0x2AAB, 0x28F6, 0, 0x2222 }; // Q14 -const Word16 InvIntTable[65] = // Q15 +const Word16 InvIntTable[65] = // Q15 { 0x7FFF, 0x7FFF, 0x4000, 0x2AAB, 0x2000, 0x199A, 0x1555, 0x1249, 0x1000, @@ -24591,7 +24591,7 @@ const Word16 InvIntTable[65] = // Q15 0x023F, 0x0235, 0x022B, 0x0222, 0x0219, 0x0211, 0x0208, 0x0200 }; -const Word16 TecLowBandTable[] = { 0, 2, 4, 6 }; //Q0 +const Word16 TecLowBandTable[] = { 0, 2, 4, 6 }; //Q0 const Word16 TecSC_Fx[] = { 23999/*0.3662f*2.0f Q15*/, 7065/*0.1078f*2.0f Q15*/, 7825/*0.1194f*2.0f Q15*/, @@ -25794,7 +25794,7 @@ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, /*----------------------------------------------------------------------------------* * means of ISFs for WB active speech *----------------------------------------------------------------------------------*/ -const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means Q2.56*/ +const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means Q2.56*/ { 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037 @@ -27915,7 +27915,7 @@ const Word16 cos_scale_tbl_800[800] = { /* Q15 */ 32762, 32763, 32764, 32765, 32765, 32766, 32766, 32766 }; -const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors Q11*/ +const Word16 scales_ivas_fx[][MAX_NO_SCALES * 2] = /* 2 subvectors Q11*/ { { 3129, diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c index 168a96011ce4b8e8affb9cc6a16d3b900b946526..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Common prototypes */ diff --git a/lib_com/stab_est_fx.c b/lib_com/stab_est_fx.c index 15cd254dfb9fbb09fc2dcacf3828682921c94baf..4b553eb5457a243400180d8cfa78b0b02dfe4e1e 100644 --- a/lib_com/stab_est_fx.c +++ b/lib_com/stab_est_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 5309e7ad777915352c43affb12246db259cdf68a..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -443,13 +443,9 @@ typedef struct Word16 CngBandwidth; Word16 flag_noisy_speech; - Word16 likelihood_noisy_speech; /* Q15 */ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG + Word16 likelihood_noisy_speech; /* Q15 */ Word16 coherence_fx[MDCT_ST_DTX_NUM_COHERENCE_BANDS]; /* inter-channel coherence of noise Q15 */ -#else - Word16 coherence_fx; /* inter-channel coherence of noise Q15 */ -#endif - Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ + Word16 no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; @@ -630,12 +626,14 @@ typedef struct ivas_cldfb_filter_bank_struct const Word32 *rot_vec_syn_delay_re_fx; // Q31 const Word32 *rot_vec_syn_delay_im_fx; // Q31 + /* rotation vectors for delay */ const Word32 *rot_vec_ana_re_fx; // Q29 const Word32 *rot_vec_ana_im_fx; // Q29 const Word32 *rot_vec_ana_delay_re_fx; // Q31 const Word32 *rot_vec_ana_delay_im_fx; // Q31 + // Fix variables Word16 *FilterStates; /*!< Pointer to buffer of filter states Q15-FilterStates_eg*/ Word16 FilterStates_e[CLDFB_NO_COL_MAX + 9]; /*!< Filter states time slot exponents */ @@ -645,16 +643,14 @@ typedef struct ivas_cldfb_filter_bank_struct const Word16 *iRotVctr; /*Q(sqrt(1.0/16.00))*/ Word16 filterScale; /*!< filter scale Q0*/ - Word16 synGain; /*!< gain for synthesis filterbank Q0*/ - Word16 anaScalefactor; /*!< Scale factor of analysis cldfb Q0*/ - Word16 synScalefactor; /*!< Scale factor of synthesis cldfb Q0*/ - Word16 outScalefactor; /*!< Scale factor of output data (syn only) Q0*/ - Word16 synFilterHeadroom; /*!< Headroom for states in synthesis cldfb filterbank Q0*/ + Word16 synGain; /*!< gain for synthesis filterbank Q0*/ + Word16 anaScalefactor; /*!< Scale factor of analysis cldfb Q0*/ + Word16 synScalefactor; /*!< Scale factor of synthesis cldfb Q0*/ + Word16 outScalefactor; /*!< Scale factor of output data (syn only) Q0*/ /* memory helper states */ Word16 *memory; // Qx Word32 *memory32; // Q_cldfb_state /*because cldfb_state_fx is word32 which is used to assign values*/ - UWord16 memory_length; /* main filter state */ @@ -665,9 +661,7 @@ typedef struct ivas_cldfb_filter_bank_struct /* other parameters */ Word16 bandsToZero; /* bands not synthesized */ - Word16 nab; /* number of active bands */ - Word16 filtermode; - Word16 scale; /* scaling of frequency domain */ /* Q8 */ + Word16 scale; /* scaling of frequency domain Q8 */ } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 7a5519c04263c79137d724d5abf77cfb8bf6d201..33c5545ce37b4036d4da03314b713530fd1d6377 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -29,22 +29,22 @@ Word32 L_Sqrt_Q0( const Word32 x ); *--------------------------------------------------------------------*/ void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ + const Word16 coder_type, /* i : Coder type */ Word16 noisiness, /* i : noisiness parameter Q0 */ const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q15 */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ - Word16 *exc2, /* i/o: excitation buffer Q_exc */ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q15 */ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q12 */ + Word16 *exc2, /* i/o: excitation buffer Q_exc */ Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q15 */ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ + const Word16 bfi, /* i : Bad frame indicator */ + Word32 *ge_sm, /* i/o: smoothed excitation gain Q_ge */ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q15 */ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q15 */ + Word16 *exc_pe, /* i/o: scale Q_stat_noise Q_stat_noise */ const Word32 bitrate, /* i : core bitrate */ const Word16 bwidth_fx, /* i : input bandwidth */ Word16 *Q_stat_noise, /* i/o: noise scaling */ @@ -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 ); } } @@ -331,26 +331,26 @@ void stat_noise_uv_mod_fx( *--------------------------------------------------------------------*/ void stat_noise_uv_mod_ivas_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter Q=0 */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ - Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi, /* i : Bad frame indicator */ + const Word16 coder_type, /* i : Coder type */ + Word16 noisiness, /* i : noisiness parameter Q=0 */ + const Word16 *lsp_old, /* i : old LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_new, /* i : LSP vector at 4th sfr Q=15*/ + const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ + Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP Q=15*/ - Word16 *noimix_seed, /* i/o: mixture seed Q0 */ - Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ + Word16 *uv_count, /* i/o: unvoiced counter */ + Word16 *act_count, /* i/o: activation counter */ + Word16 lspold_s[], /* i/o: old LSP Q=15*/ + Word16 *noimix_seed, /* i/o: mixture seed Q0 */ + Word16 *st_min_alpha, /* i/o: minimum alpha Q=15*/ Word16 *exc_pe, /* i/o: scale Q_stat_noise Q=Q_stat_noise*/ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : i bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ + const Word32 bitrate, /* i : core bitrate */ + const Word16 bwidth_fx, /* i : i bandwidth */ + Word16 *Q_stat_noise, /* i/o: noise scaling */ + Word16 *Q_stat_noise_ge /* i/o: noise scaling */ ) { Word16 exctilt; /* Q15 */ @@ -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 0e618f7d9f2072231f0b1662e98753fa16869739..525a1db8555a8df2e7f658086fc51a6505d58712 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 @@ -338,18 +338,15 @@ Word16 WB_BWE_gain_pred_fx( * * calc_envelope of low frequency spectrum *-------------------------------------------------------------------*/ + static void calc_norm_envelop_lf_fx( - const Word32 SWB_signal[], - /* i : SWB spectrum */ /* Q12 */ - Word32 *envelope, - /* o : normalized envelope */ /* Q12 */ - Word16 *L_swb_norm, /* i/o : length of envelope */ - const Word16 HQ_mode, - /* i : HQ mode */ /* Q0 */ - const Word16 hq_generic_offset, - /* i : frequency offset for representing hq generic */ /* Q0 */ - Word16 *sfreq, /* i : starting frequency index */ - Word16 *efreq /* i : ending frequency index */ + const Word32 SWB_signal[], /* i : SWB spectrum Q12 */ + Word32 *envelope, /* o : normalized envelope Q12 */ + Word16 *L_swb_norm, /* i/o: length of envelope */ + const Word16 HQ_mode, /* i : HQ mode Q0 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic Q0 */ + Word16 *sfreq, /* i : starting frequency index */ + Word16 *efreq /* i : ending frequency index */ ) { Word16 lookback, env_index, n_freq, n_lag_now, n_lag; @@ -423,6 +420,8 @@ static void calc_norm_envelop_lf_fx( return; } + + /*-------------------------------------------------------------------* * calc_normal_length() * @@ -550,16 +549,18 @@ void calc_normal_length_fx( return; } + /*-------------------------------------------------------------------* * calc_tilt_bwe() * * calculate tilt parameter *-------------------------------------------------------------------*/ -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp, /* i : input signal Q(15 - exp_sp) */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ +/* o : Tilt in Q24 */ +Word32 calc_tilt_bwe_fx( + const Word16 *sp, /* i : input signal Q(15 - exp_sp) */ + const Word16 exp_sp, /* i : Exp of inp signal */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -567,10 +568,8 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 Word16 tmp1, tmp2; const Word16 *ptr; Word16 exp2; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif BASOP_SATURATE_WARNING_OFF_EVS @@ -647,10 +646,13 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 return L_temp; } -Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word32 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal Q(15 - exp_sp) */ - const Word16 N /* i : signal length */ + + +/* o : Tilt in Q24 */ +Word16 calc_tilt_bwe_fx_32( + const Word32 *sp, /* i : input signal */ + const Word16 exp_sp, /* i : Exp of inp signal Q(15 - exp_sp) */ + const Word16 N /* i : signal length */ ) { Word16 i, j; @@ -811,11 +813,12 @@ void calc_norm_envelop_fx( /* _Word16 *Seed, i/o: random generator seed Q15 */ /* _Word16 *prev_flag, i/o: attenu flag of last frame Q0 */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*==========================================================================*/ + void WB_BWE_decoding_fx( const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ Word16 *WB_fenv, /* i : WB frequency envelopes */ @@ -1940,7 +1943,9 @@ return; /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ + void time_envelop_shaping_fx( +#ifndef HARM_FD_BWE Word16 werr[], /* i/o: SHB synthesis Q_synth*/ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ const Word16 L, /* i : frame length */ @@ -2020,6 +2025,9 @@ void time_envelop_shaping_fx( } void time_envelop_shaping_ivas_fx( +#else + const Word16 element_mode, /* i : element mode */ +#endif Word16 werr[], /* i/o: SHB synthesis Q_synth*/ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ const Word16 L, /* i : frame length */ @@ -2036,31 +2044,47 @@ void time_envelop_shaping_ivas_fx( pit = werr; exp_L = norm_s( L ); inv_L = div_s( shl( 1, sub( 14, exp_L ) ), L ); /*Q(29-exp_L) */ + FOR( i = 0; i < SWB_TENV; i++ ) { - Energy_64 = L_deposit_l( 0 ); - FOR( j = 0; j < L / 4; j++ ) +#ifdef HARM_FD_BWE + IF( element_mode == EVS_MONO ) { - Energy_64 = W_mac0_16_16( Energy_64, *pit, *pit ); /*(2*Q_synth) */ - pit++; + Energy = L_deposit_l( 0 ); + FOR( j = 0; j < L / 4; j++ ) + { + Energy = L_mac0_sat( Energy, *pit, *pit ); /*(2*Q_synth) */ + pit++; + } + Energy_Q = shl( ( *Q_synth ), 1 ); + } + ELSE +#endif + { + Energy_64 = L_deposit_l( 0 ); + FOR( j = 0; j < L / 4; j++ ) + { + Energy_64 = W_mac0_16_16( Energy_64, *pit, *pit ); /*(2*Q_synth) */ + pit++; + } + w_tmp = W_norm( Energy_64 ); + Energy_64 = W_shl( Energy_64, w_tmp ); + Energy = W_extract_h( Energy_64 ); /*2*Q_synth + w_tmp -32*/ + Energy_Q = sub( add( shl( ( *Q_synth ), 1 ), w_tmp ), 32 ); } - w_tmp = W_norm( Energy_64 ); - Energy_64 = W_shl( Energy_64, w_tmp ); - Energy = W_extract_h( Energy_64 ); /*2*Q_synth + w_tmp -32*/ - Energy_Q = sub( add( shl( ( *Q_synth ), 1 ), w_tmp ), 32 ); + Energy = Mult_32_16( Energy, inv_L ); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth+w_tmp-32) */ Energy_16 = 0; move16(); - /*exp = 31-(-exp_L+14 +(2*(*Q_synth)+w_tmp-32)); */ + /*exp = 31-(-exp_L+14+Energy_Q); */ exp = sub( 17, sub( Energy_Q, exp_L ) ); IF( Energy != 0 ) { exp = norm_l( Energy ); frac = extract_h( L_shl( Energy, exp ) ); - /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)+w_tmp-32))); */ + /*exp = sub(exp, 30-(-exp_L+14-2+Energy_Q)); */ exp = sub( exp, sub( 30, add( sub( Energy_Q, exp_L ), 14 - 2 ) ) ); - tmp = div_s( 16384, frac ); L_tmp = L_deposit_h( tmp ); Energy = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ diff --git a/lib_com/swb_bwe_com_hr_fx.c b/lib_com/swb_bwe_com_hr_fx.c index 7755ec697b57343c855cfa39f012147fba2cc310..a1d6fe2a0fe474393cc863b5a7206d9dc7a3b4c5 100644 --- a/lib_com/swb_bwe_com_hr_fx.c +++ b/lib_com/swb_bwe_com_hr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 0e6524ce8f3299dd2cb69a4f2bc1b9683986e1e0..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 @@ -927,10 +927,8 @@ void SpectrumSmoothing_fx( Word16 reset_flag; Word16 pp, pk; Word16 exp_norm; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif *Qss = 10; move16(); @@ -2225,10 +2223,8 @@ void ton_ene_est_fx( Word16 temp2_fx, Qtemp2; Word16 temp_fx; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif *QbeL = 3; move16(); diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index bfe9db62d269efef90004808a98090c8691b71ec..8a9aad1a642f3e4037edb48820a834ec6f5926f3 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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,11 @@ void Calc_rc0_h( *rc0 = negate( *rc0 ); move16(); } + + return; } -void Calc_rc0_h_ivas_enc_fx( +static void Calc_rc0_h_ivas_enc_fx( Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ) @@ -868,7 +782,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 +820,8 @@ static void Calc_st_filt_tbe( move16(); } } + + return; } static void Calc_st_filt_tbe_ivas_enc_fx( @@ -946,46 +862,8 @@ static void Calc_st_filt_tbe_ivas_enc_fx( move16(); } } -} - -static void Calc_st_filt_tbe_ivas_dec_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - 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 */ - Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); - /* compute 1st parcor */ - Calc_rc0_h( h, parcor0 ); - - /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); - FOR( i = 1; i < LONG_H_ST; i++ ) - { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); - } - g0 = extract_h( L_shl( L_g0, 14 ) ); - /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) - { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ - FOR( i = 0; i < L_SUBFR16k; i++ ) - { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); - move16(); - } - } + return; } static void filt_mu_fx( @@ -1190,7 +1068,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 +1188,7 @@ void PostShortTerm_ivas_dec_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe_ivas_dec_fx( 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 */ @@ -1327,6 +1205,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 */ @@ -1405,22 +1290,28 @@ void flip_spectrum_and_decimby4_fx( /* CALLED FROM : */ /*==========================================================================*/ +#ifdef HARMONIZE_TBE2 +void GenShapedWBExcitation_fx( +#else 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 ) +#endif + 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 +1369,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 ) ) { @@ -1491,8 +1382,7 @@ void GenShapedWBExcitation_ivas_fx( } ELSE { - autocorr_fx( exc4k, LPC_WHTN_ORDER_WB + 1, R_h, R_l, &Q_R, - L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 ); + autocorr_fx( exc4k, LPC_WHTN_ORDER_WB + 1, R_h, R_l, &Q_R, L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 ); /* Ensure R[0] isn't zero when entering Levinson Durbin */ R_l[0] = s_max( R_l[0], 1 ); @@ -1503,14 +1393,22 @@ void GenShapedWBExcitation_ivas_fx( L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL ); Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); - fir_fx( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k / 4, - LPC_WHTN_ORDER_WB, 0, 3 ); + fir_fx( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k / 4, LPC_WHTN_ORDER_WB, 0, 3 ); /* Ensure pow1 is greater than zero when computing normalization */ +#ifdef HARMONIZE_TBE2 + Word16 Q_pow = Q10; + move16(); + if ( element_mode == EVS_MONO ) + { + Q_pow = Q7; + move16(); + } +#endif max_val = 0; move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1542,7 +1440,11 @@ void GenShapedWBExcitation_ivas_fx( FOR( i = 0; i < L_FRAME16k / 4; i++ ) { L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */ // saturation not possible: excTmp2_frac[i] < MIN_16 - pow1 = L_add_sat( pow1, L_shr( L_tmp, 10 ) ); /* Q22 */ +#ifdef HARMONIZE_TBE2 + pow1 = L_add_sat( pow1, L_shr( L_tmp, Q_pow ) ); /* Q22 */ +#else + pow1 = L_add_sat( pow1, L_shr( L_tmp, 10 ) ); /* Q22 */ +#endif } } @@ -1554,10 +1456,11 @@ 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; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { exc4k_32[i] = Mult_32_16( excNoisyEnv[i], exc4k[i] ); @@ -1581,21 +1484,39 @@ void GenShapedWBExcitation_ivas_fx( exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ move16(); } - n2 = 30 - n2 - ( Q_bwe_exc + 6 ); + n2 = sub( sub( 30, n2 ), add( Q_bwe_exc, 6 ) ); pow22 = 1; move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { L_tmp = L_mult_sat( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */ - pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ +#ifdef HARMONIZE_TBE2 + pow22 = L_add( pow22, L_shr( L_tmp, Q_pow ) ); /* Q22 */ +#else + pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ +#endif } } +#ifdef HARMONIZE_TBE2 + Word16 Q_root = Q19; + move16(); + if ( element_mode == EVS_MONO ) + { + Q_root = Q22; + move16(); + } +#endif + test(); test(); IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /* 0.2 in Q15 */ ) ) ) { +#ifdef HARMONIZE_TBE2 + L_tmp = root_a_over_b_fx( pow1, sub( Q_root, shl( n1, 1 ) ), pow22, sub( Q_root, shl( n2, 1 ) ), &exp ); +#else L_tmp = root_a_over_b_fx( pow1, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); +#endif scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ sc = sub( add( n2, Q_bwe_exc ), 14 ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1627,7 +1548,11 @@ void GenShapedWBExcitation_ivas_fx( Ltemp1 = root_a_fx( L_deposit_h( tmp_vfac ), 31, &exp ); temp1 = round_fx_sat( L_shl_sat( Ltemp1, exp ) ); /* Q15 */ L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ +#ifdef HARMONIZE_TBE2 + Ltemp2 = root_a_over_b_fx( L_tmp, sub( Q_root, shl( n1, 1 ) ), pow22, sub( Q_root, shl( n2, 1 ) ), &exp ); +#else Ltemp2 = root_a_over_b_fx( L_tmp, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); +#endif temp2 = round_fx_sat( L_shl_sat( Ltemp2, exp ) ); /* Q15 */ FOR( j = 0; j < L_FRAME16k / 16; j++ ) { @@ -1635,22 +1560,32 @@ void GenShapedWBExcitation_ivas_fx( L_tmp = L_add_sat( L_tmp, L_shl_sat( L_mult_sat( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ exc4kWhtnd[k] = round_fx_sat( L_tmp ); /* Q_bwe_exc */ move16(); - k++; + k = add( k, 1 ); } } } } - Scale_sig( state_lpc_syn, LPC_SHB_ORDER, -Q2 ); /* Q(Q_bwe_exc) -> Q(Q_bwe_exc - 2) */ +#ifdef HARMONIZE_TBE2 + IF( element_mode == EVS_MONO ) + { + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 ); + } + ELSE +#endif + { + Scale_sig( state_lpc_syn, LPC_SHB_ORDER, -Q2 ); /* Q(Q_bwe_exc) -> Q(Q_bwe_exc - 2) */ - Syn_filt_s( Q2, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 ); + Syn_filt_s( Q2, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 ); - Scale_sig( state_lpc_syn, LPC_SHB_ORDER, Q2 ); /* Q(Q_bwe_exc - 2) -> Q(Q_bwe_exc) */ - Scale_sig( excSHB, L_FRAME16k / 4, Q2 ); /* Q(Q_bwe_exc - 2) -> Q(Q_bwe_exc) */ + Scale_sig( state_lpc_syn, LPC_SHB_ORDER, Q2 ); /* Q(Q_bwe_exc - 2) -> Q(Q_bwe_exc) */ + Scale_sig( excSHB, L_FRAME16k / 4, Q2 ); /* Q(Q_bwe_exc - 2) -> Q(Q_bwe_exc) */ + } return; } +#ifndef HARMONIZE_TBE2 void GenShapedWBExcitation_fx( Word16 *excSHB, /* o : synthesized shaped shb exctiation Q(Q_bwe_exc) */ const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ @@ -1661,6 +1596,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 +1663,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++ ) @@ -1751,7 +1687,7 @@ void GenShapedWBExcitation_fx( L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL ); Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); @@ -1802,7 +1738,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; @@ -1895,7 +1831,7 @@ void GenShapedWBExcitation_fx( return; } - +#endif /*-------------------------------------------------------------------* * GenWBSynth() @@ -2074,6 +2010,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*/ @@ -2162,7 +2099,7 @@ void GenShapedSHBExcitation_fx( L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); @@ -2293,8 +2230,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 +2329,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 +2344,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 +2424,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 } } } @@ -2610,7 +2541,38 @@ ELSE return; } +#ifdef HARMONIZE_TBE2 +static void synthesis_enc_dec( + const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word16 shift, /* i : scaling to apply Q0 */ + const Word16 a[], /* i : LP filter coefficients Q12 */ + const Word16 m, /* i : order of LP filter Q0 */ + const Word16 x[], /* i : input signal Qx */ + Word16 y[], /* o : output signal Qx-s */ + const Word16 l, /* i : size of filtering Q0 */ + Word16 mem[], /* i/o: initial filter states Qx-s */ + const Word16 update_m /* i : update memory flag Q0 : 0 --> no memory update */ + ) /* 1 --> update of memory */ +{ + IF( enc_dec == ENC ) + { + syn_filt_fx( shift, a, m, x, y, l, mem, update_m ); + } + ELSE + { + Syn_filt_s( shift, a, m, x, y, l, mem, update_m ); + } + + return; +} +#endif + +#ifdef HARMONIZE_TBE2 +void GenShapedSHBExcitation_ivas_fx( + const Word16 enc_dec, /* i : encoder/decoder flag */ +#else void GenShapedSHBExcitation_ivas_enc_fx( +#endif 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 */ @@ -2709,6 +2671,20 @@ void GenShapedSHBExcitation_ivas_enc_fx( Word16 delta; Word32 c0_part[NUM_SHB_SUBGAINS], c1_part[NUM_SHB_SUBGAINS], c2_part[NUM_SHB_SUBGAINS], c3_part[NUM_SHB_SUBGAINS], c4_part[NUM_SHB_SUBGAINS], c5_part[NUM_SHB_SUBGAINS]; Word64 W_tmp; +#ifdef HARMONIZE_TBE2 + Word16 Q_temp, Q_exc16kWhtnd; + Word16 chk1; + Word32 chk2; + + Q_temp = 0; + chk1 = 0; + chk2 = 0; + move16(); + move16(); + move32(); + + (void) prev_bfi; +#endif mix_factor = 0; /* Q15 */ move16(); @@ -2737,7 +2713,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); // Q_R } - E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); // Q12 fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); // Q_bwe_exc @@ -2764,20 +2740,43 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* Estimate pow1 associated with Low band nonlinear extended excitation */ /* pow1=0.00001f */ - tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); - W_tmp = W_shl( 21475 /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ - FOR( k = 0; k < L_FRAME16k; k++ ) +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) { - /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ - excTmp2[k] = abs_s( exc16kWhtnd[k] ); - move16(); +#endif + tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); + W_tmp = W_shl( 21475 /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ + excTmp2[k] = abs_s( exc16kWhtnd[k] ); + move16(); - /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ - W_tmp = W_mac_16_16( W_tmp, exc16kWhtnd[k], exc16kWhtnd[k] ); // 2*Q_bwe_exc+1 + /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ + W_tmp = W_mac_16_16( W_tmp, exc16kWhtnd[k], exc16kWhtnd[k] ); // 2*Q_bwe_exc+1 + } + exp = W_norm( W_tmp ); + pow1 = W_extract_h( W_shl( W_tmp, exp ) ); // 2*Q_bwe_exc+1+exp-32 = // tmp+exp + Q_pow1 = add( tmp, exp ); +#ifdef HARMONIZE_TBE2 + } + ELSE + { + tmp = sub( shl( *Q_bwe_exc, 1 ), 31 ); + pow1 = L_shl_sat( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ + excTmp2[k] = abs_s( exc16kWhtnd[k] ); + move16(); + chk1 = s_or( chk1, exc16kWhtnd[k] ); + + /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ + pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ + } + Q_pow1 = shl( *Q_bwe_exc, 1 ); } - exp = W_norm( W_tmp ); - pow1 = W_extract_h( W_shl( W_tmp, exp ) ); // 2*Q_bwe_exc+1+exp-32 = // tmp+exp - Q_pow1 = add( tmp, exp ); +#endif IF( flag_ACELP16k == 0 ) { @@ -2822,6 +2821,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( neg_csfilt_den2[1] = varEnvShape; // Q15 move16(); +#ifndef HARMONIZE_TBE2 test(); test(); test(); @@ -2854,6 +2854,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( move32(); } +#endif IF( MSFlag > 0 ) { // varEnvShape = 0.995f; @@ -2872,6 +2873,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( { Q_excTmp2 = s_min( Q_excTmp2, sub( add( norm_l( *mem_csfilt ), *Q_bwe_exc ), 1 ) ); } + test(); /* Track the low band envelope */ IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) @@ -2949,37 +2951,79 @@ void GenShapedSHBExcitation_ivas_enc_fx( } /* normalize the amplitude of the gaussian excitation to that of the LB exc. */ - Word32 pow22_inv = POW_EXC16k_WHTND_FX_INV_SQRT; // Q31 - move32(); - move32(); - pow22 = POW_EXC16k_WHTND_FX; - Q_pow22 = -6; - move16(); - // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); - Word16 pow1_exp = sub( Q31, Q_pow1 ); - Word32 temp_pow = Sqrt32( pow1, &pow1_exp ); - temp_pow = L_shl( Mpy_32_32( temp_pow, pow22_inv ), pow1_exp ); - /*Word16 out_exp; - Word32 temp_pow1 = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &out_exp); - temp_pow1 = L_shl(temp_pow1, out_exp);*/ - // v_multc_fx_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); - L_tmp = 0; - move32(); - Q_White_exc16k = add( getScaleFactor16( White_exc16k, L_FRAME16k ), norm_l( temp_pow ) ); - FOR( k = 0; k < L_FRAME16k; k++ ) +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) + { +#endif + Word32 pow22_inv = POW_EXC16k_WHTND_FX_INV_SQRT; // Q31 + move32(); + move32(); + pow22 = POW_EXC16k_WHTND_FX; + Q_pow22 = -Q6; + move16(); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); + Word16 pow1_exp = sub( Q31, Q_pow1 ); + Word32 temp_pow = Sqrt32( pow1, &pow1_exp ); + temp_pow = L_shl( Mpy_32_32( temp_pow, pow22_inv ), pow1_exp ); + /*Word16 out_exp; + Word32 temp_pow1 = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &out_exp); + temp_pow1 = L_shl(temp_pow1, out_exp);*/ + // v_multc_fx_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); + L_tmp = 0; + move32(); + Q_White_exc16k = add( getScaleFactor16( White_exc16k, L_FRAME16k ), norm_l( temp_pow ) ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k_32[k] = Mpy_32_16_1( temp_pow, White_exc16k[k] ); // Q31 + Q0 - Q15 = Q16 + move32(); + White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q16 + Q_White_exc16k - Q16 = Q_White_exc16k + move16(); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); + } +#ifdef HARMONIZE_TBE2 + } + ELSE { - White_exc16k_32[k] = Mpy_32_16_1( temp_pow, White_exc16k[k] ); // Q31 + Q0 - Q15 = Q16 + Word32 pow22_inv = POW_EXC16k_WHTND_FX_INV_SQRT_IN_Q49; + move32(); move32(); - White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q16 + Q_White_exc16k - Q16 = Q_White_exc16k + pow22 = POW_EXC16k_WHTND_FX; + Q_pow22 = -Q6; move16(); - L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k); + Word16 pow1_exp = sub( Q31, Q_pow1 ); + Word32 temp_pow = Sqrt32( pow1, &pow1_exp ); + temp_pow = Mpy_32_32( temp_pow, pow22_inv ); + /*Word16 out_exp; + Word32 temp_pow1 = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &out_exp); + temp_pow1 = L_shl(temp_pow1, out_exp);*/ + // v_multc_fx_16_16(White_exc16k, round_fx(temp_pow), White_exc16k, L_FRAME16k); + L_tmp = 0; + move32(); + shift = getScaleFactor16( White_exc16k, L_FRAME16k ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k_32[k] = Mpy_32_16_1( temp_pow, White_exc16k[k] ); + move32(); + White_exc16k[k] = round_fx( L_shl( White_exc16k_32[k], shift ) ); // Q_White_exc16k + move16(); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); + } + Q_White_exc16k = add( shift, sub( 49 - 31, pow1_exp ) ); + Q_temp = norm_l( L_tmp ); + IF( L_tmp == 0 ) + { + Q_temp = 31; + move16(); + } } +#endif } 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 ); @@ -2990,30 +3034,59 @@ void GenShapedSHBExcitation_ivas_enc_fx( move32(); L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } - /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ - /* White_exc16k in Q6 */ - /* calculate pow22 */ - /* pow22=0.00001f */ - tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); - W_tmp = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ - Q_White_exc16k = getScaleFactor32( White_exc16k_32, L_FRAME16k ); - FOR( k = 0; k < L_FRAME16k; k++ ) + /* White_exc16k in Q6 */ +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) { - /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = extract_h( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q_excTmp2 + 6 + Q_White_exc16k - 16 ==> Q_excTmp2 + Q_White_exc16k - 10 - move16(); - /* i: excNoisyEnv in (Q_excTmp2) */ - /* i: White_exc16k in Q6 */ - /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ +#endif + /* calculate pow22 */ + /* pow22=0.00001f */ + tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); + W_tmp = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ + Q_White_exc16k = getScaleFactor32( White_exc16k_32, L_FRAME16k ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k[k] *= excNoisyEnv[k]; */ + White_exc16k[k] = extract_h( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q_excTmp2 + 6 + Q_White_exc16k - 16 ==> Q_excTmp2 + Q_White_exc16k - 10 + move16(); + /* i: excNoisyEnv in (Q_excTmp2) */ + /* i: White_exc16k in Q6 */ + /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ - /* pow22 += White_exc16k[k] * White_exc16k[k]; */ - W_tmp = W_mac0_16_16( W_tmp, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ + W_tmp = W_mac0_16_16( W_tmp, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/ + } + Q_pow22 = W_norm( W_tmp ); + pow22 = W_extract_h( W_shl( W_tmp, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32 + Q_pow22 = sub( add( Q_pow22, shl( sub( add( Q_White_exc16k, Q_excTmp2 ), 10 ), 1 ) ), 32 ); + Q_White_exc16k = add( Q_White_exc16k, sub( Q_excTmp2, 10 ) ); +#ifdef HARMONIZE_TBE2 } - Q_pow22 = W_norm( W_tmp ); - pow22 = W_extract_h( W_shl( W_tmp, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32 - Q_pow22 = sub( add( Q_pow22, shl( sub( add( Q_White_exc16k, Q_excTmp2 ), 10 ), 1 ) ), 32 ); - Q_White_exc16k = add( Q_White_exc16k, sub( Q_excTmp2, 10 ) ); + ELSE + { + /* calculate pow22 */ + /* pow22=0.00001f */ + tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); + Word64 sum = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */ + Q_White_exc16k = getScaleFactor32( White_exc16k_32, L_FRAME16k ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + White_exc16k[k] = extract_h( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q_excTmp2 + 6 + Q_White_exc16k - 16 ==> Q_excTmp2 + Q_White_exc16k - 10 + chk2 = L_or( chk2, White_exc16k_32[k] ); + /* i: excNoisyEnv in (Q_excTmp2) */ + /* i: White_exc16k in Q6 */ + /* o: White_exc16k in (Q_White_exc16k) */ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ + sum = W_mac0_16_16( sum, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/ + move16(); + } + Q_pow22 = W_norm( sum ); + pow22 = W_extract_h( W_shl( sum, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32 + Q_pow22 = sub( add( Q_pow22, shl( sub( add( Q_White_exc16k, Q_excTmp2 ), 10 ), 1 ) ), 32 ); + Q_White_exc16k = add( Q_White_exc16k, sub( Q_excTmp2, 10 ) ); + } +#endif } flag_plosive = 0; @@ -3279,38 +3352,99 @@ void GenShapedSHBExcitation_ivas_enc_fx( /* save buffers for IC-BWE */ // mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k); Copy( exc16kWhtnd, nlExc16k, L_FRAME16k ); // Q_bwe_exc - *nlExc16k_e = sub( 15, *Q_bwe_exc ); +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) + { +#endif + *nlExc16k_e = sub( 15, *Q_bwe_exc ); + move16(); + + + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + Word16 temp_fac = round_fx_sat( L_tmp ); // Q15-exp + + FOR( k = 0; k < L_FRAME16k; k++ ) + { + mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); // Q_White_exc16k+15-exp-15 = Q_White_exc16k-exp + move16(); + } + *mixExc16k_e = sub( 15, sub( Q_White_exc16k, exp ) ); + move16(); +#ifdef HARMONIZE_TBE2 + } + ELSE + { + // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); + /*Word16 temp_fac = divide3232(L_shr(pow1, Q_pow1), pow22); + Word16 temp_fac_exp = 0; + temp_fac = Sqrt16(temp_fac, &temp_fac_exp);*/ + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + Word16 temp_fac = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 + shift = sub( sub( *Q_bwe_exc, NOISE_QADJ ), Q_White_exc16k ); + // v_multc_fx_16_16(White_exc16k,shr(temp_fac, temp_fac_exp) , mixExc16k, L_FRAME16k); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + mixExc16k[k] = mult_r( shl_sat( White_exc16k[k], shift ), temp_fac ); + move16(); + } + } +#endif + } + +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) + { +#endif + Copy( White_exc16k, White_exc16k_FB, L_FRAME16k ); // Q_White_exc16k + prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + *Q_bwe_exc_fb = Q_White_exc16k; + move16(); move16(); - // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k); - L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); - Word16 temp_fac = round_fx_sat( L_tmp ); // Q15-exp + scale_sig( White_exc16k, L_FRAME16k, -1 /* guard bit to prevent saturation in deemph*/ ); + Q_White_exc16k = sub( Q_White_exc16k, 1 ); + + Word16 tbe_demph_fx = shl_sat( *tbe_demph, sub( Q_White_exc16k, *Q_bwe_exc ) ); // Q_White_exc16k + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, &tbe_demph_fx ); + /* i/o: White_exc16k (Q_White_exc16k) */ + /* i: tbe_demph_fx (Q_White_exc16k) */ + *tbe_demph = shr_sat( tbe_demph_fx, sub( Q_White_exc16k, *Q_bwe_exc ) ); + move16(); +#ifdef HARMONIZE_TBE2 + } + ELSE + { + tmp = sub( Q_temp, 3 ); FOR( k = 0; k < L_FRAME16k; k++ ) { - mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); // Q_White_exc16k+15-exp-15 = Q_White_exc16k-exp - move16(); + White_exc16k_FB[k] = White_exc16k[k]; /* Q_White_exc16k */ } - *mixExc16k_e = sub( 15, sub( Q_White_exc16k, exp ) ); + prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; move16(); - } + *Q_bwe_exc_fb = Q_White_exc16k; + move16(); + *tbe_demph = shl_sat( *tbe_demph, sub( Q_White_exc16k, sub( *Q_bwe_exc, NOISE_QADJ ) ) ); + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); + *tbe_demph = shl_sat( *tbe_demph, sub( sub( *Q_bwe_exc, NOISE_QADJ ), Q_White_exc16k ) ); - Copy( White_exc16k, White_exc16k_FB, L_FRAME16k ); // Q_White_exc16k - prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; - *Q_bwe_exc_fb = Q_White_exc16k; - move16(); - move16(); + Q_exc16kWhtnd = getScaleFactor16( exc16kWhtnd, L_FRAME16k ); + Q_exc16kWhtnd = add( Q_exc16kWhtnd, *Q_bwe_exc ); - scale_sig( White_exc16k, L_FRAME16k, -1 /* guard bit to prevent saturation in deemph*/ ); - Q_White_exc16k = sub( Q_White_exc16k, 1 ); + shift = getScaleFactor16( White_exc16k, L_FRAME16k ); - Word16 tbe_demph_fx = shl_sat( *tbe_demph, sub( Q_White_exc16k, *Q_bwe_exc ) ); // Q_White_exc16k + shift = s_min( Q_exc16kWhtnd, add( shift, Q_White_exc16k ) ); + scale_sig( exc16kWhtnd, L_FRAME16k, sub( shift, *Q_bwe_exc ) ); + scale_sig( White_exc16k, L_FRAME16k, sub( shift, Q_White_exc16k ) ); - deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, &tbe_demph_fx ); - /* i/o: White_exc16k (Q_White_exc16k) */ - /* i: tbe_demph_fx (Q_White_exc16k) */ - *tbe_demph = shr_sat( tbe_demph_fx, sub( Q_White_exc16k, *Q_bwe_exc ) ); - move16(); + Q_exc16kWhtnd = Q_White_exc16k = shift; + move16(); + move16(); + *tbe_premph = shl_sat( *tbe_premph, sub( Q_White_exc16k, sub( *Q_bwe_exc, NOISE_QADJ ) ) ); + move16(); + } +#endif test(); IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) ) @@ -3319,12 +3453,28 @@ void GenShapedSHBExcitation_ivas_enc_fx( { /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */ /* old_scale = (float) sqrt( *prev_pow_exc16kWhtnd / pow1 ); */ - old_scale = round_fx_sat( root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ) ); // exp - old_scale = shl( old_scale, s_min( 0, exp ) ); // limit Q factor to 15 - exp = s_max( 0, exp ); +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) + { +#endif + old_scale = round_fx_sat( root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ) ); // exp + old_scale = shl( old_scale, s_min( 0, exp ) ); // limit Q factor to 15 + exp = s_max( 0, exp ); - // new_scale = 1.0f; - new_scale = shr( 32767, exp ); // exp + // new_scale = 1.0f; + new_scale = shr( 32767, exp ); // exp +#ifdef HARMONIZE_TBE2 + } + ELSE + { + L_tmp = root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ); + old_scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15 + + // new_scale = 1.0f; + new_scale = 32767; + move16(); + } +#endif // step_scale = (new_scale - old_scale) / (L_FRAME16k / 2); step_scale = mult_r( sub( new_scale, old_scale ), 205 ); // exp @@ -3345,56 +3495,103 @@ void GenShapedSHBExcitation_ivas_enc_fx( shift = add( exp, sub( *Q_bwe_exc, Q_White_exc16k ) ); /* mixing of LB and gaussian excitation in the first half of the frame */ - FOR( k = 0; k < L_FRAME16k / 2; k++ ) +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) { - /* exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; */ - L_tmp = L_shl_sat( L_mult( fact, mult_r( White_exc16k[k], scale ) ), shift ); // Q_bwe_exc+16 - exc16kWhtnd[k] = mac_r_sat( L_tmp, sub( 32767, fact ), exc16kWhtnd[k] ); // Q_bwe_exc - move16(); +#endif + FOR( k = 0; k < L_FRAME16k / 2; k++ ) + { + /* exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; */ + L_tmp = L_shl_sat( L_mult( fact, mult_r( White_exc16k[k], scale ) ), shift ); // Q_bwe_exc+16 + exc16kWhtnd[k] = mac_r_sat( L_tmp, sub( 32767, fact ), exc16kWhtnd[k] ); // Q_bwe_exc + move16(); - fact = add_sat( fact, step ); // Q15 - scale = add_sat( scale, step_scale ); // exp - } + fact = add_sat( fact, step ); // Q15 + scale = add_sat( scale, step_scale ); // exp + } - shift = sub( *Q_bwe_exc, Q_White_exc16k ); - /* mixing of LB and gaussian excitation in the second half of the frame */ - FOR( ; k < L_FRAME16k; k++ ) + shift = sub( *Q_bwe_exc, Q_White_exc16k ); + /* mixing of LB and gaussian excitation in the second half of the frame */ + FOR( ; k < L_FRAME16k; k++ ) + { + // exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; + L_tmp = L_shl_sat( L_mult( new_fact, White_exc16k[k] ), shift ); // Q_bwe_exc+16 + exc16kWhtnd[k] = mac_r( L_tmp, sub( 32767, new_fact ), exc16kWhtnd[k] ); // Q_bwe_exc + move16(); + } +#ifdef HARMONIZE_TBE2 + } + ELSE { - // exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k]; - L_tmp = L_shl_sat( L_mult( new_fact, White_exc16k[k] ), shift ); // Q_bwe_exc+16 - exc16kWhtnd[k] = mac_r( L_tmp, sub( 32767, new_fact ), exc16kWhtnd[k] ); // Q_bwe_exc - move16(); + FOR( k = 0; k < L_FRAME16k / 2; k++ ) + { + exc16kWhtnd[k] = mac_r( L_mult( fact, mult_r( White_exc16k[k], scale ) ), + sub( 32767, fact ), exc16kWhtnd[k] ); // Q_exc16kWhtnd + move16(); + fact = add_sat( fact, step ); + scale = add_sat( scale, step_scale ); + } + + /* mixing of LB and gaussian excitation in the second half of the frame */ + FOR( ; k < L_FRAME16k; k++ ) + { + exc16kWhtnd[k] = mac_r( L_mult( new_fact, White_exc16k[k] ), + sub( 32767, new_fact ), exc16kWhtnd[k] ); // Q_exc16kWhtnd + move16(); + } } +#endif } - // 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 { test(); IF( EQ_16( coder_type, UNVOICED ) || EQ_16( MSFlag, 1 ) ) { - scale = 0; - move16(); +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) + { +#endif + scale = 0; + move16(); - test(); - IF( pow1 != 0 && pow22 != 0 ) + test(); + IF( pow1 != 0 && pow22 != 0 ) + { + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ + } + + FOR( k = 0; k < L_FRAME16k; k++ ) + { + exc16kWhtnd[k] = mult_r_sat( White_exc16k[k], scale ); // Q_White_exc16k + move16(); + } + + Scale_sig( exc16kWhtnd, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); // Q_bwe_exc +#ifdef HARMONIZE_TBE2 + } + ELSE { L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + test(); + if ( chk1 == 0 && chk2 == 0 ) + { + L_tmp = 0; + move32(); + } scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + exc16kWhtnd[k] = mult_r_sat( White_exc16k[k], scale ); + move16(); + } } +#endif - FOR( k = 0; k < L_FRAME16k; k++ ) - { - exc16kWhtnd[k] = mult_r_sat( White_exc16k[k], scale ); // Q_White_exc16k - move16(); - } - - 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 { @@ -3454,14 +3651,31 @@ void GenShapedSHBExcitation_ivas_enc_fx( temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ } - shift = sub( *Q_bwe_exc, Q_White_exc16k ); - FOR( j = 0; j < lSubFr; j++ ) +#ifdef HARMONIZE_TBE2 + IF( enc_dec == ENC ) { - /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_shl_sat( L_mult( temp2, White_exc16k[k + j] ), shift ); // 16+(Q_bwe_exc) - exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); // Q_bwe_exc - move16(); +#endif + shift = sub( *Q_bwe_exc, Q_White_exc16k ); + FOR( j = 0; j < lSubFr; j++ ) + { + /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ + L_tmp = L_shl_sat( L_mult( temp2, White_exc16k[k + j] ), shift ); // 16+(Q_bwe_exc) + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); // Q_bwe_exc + move16(); + } +#ifdef HARMONIZE_TBE2 } + ELSE + { + FOR( j = 0; j < lSubFr; j++ ) + { + /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ + L_tmp = L_mult( temp2, White_exc16k[k + j] ); + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); + move16(); + } + } +#endif k = add( k, lSubFr ); /* estimate the pre-emph factor */ @@ -3475,16 +3689,28 @@ 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 / Q_exc16kWhtnd } } } +#ifdef HARMONIZE_TBE2 + IF( enc_dec == DEC ) + { + *tbe_premph = shl_sat( *tbe_premph, sub( sub( *Q_bwe_exc, NOISE_QADJ ), Q_White_exc16k ) ); + move16(); + Scale_sig( White_exc16k, L_FRAME16k, sub( sub( *Q_bwe_exc, NOISE_QADJ ), Q_White_exc16k ) ); + Scale_sig( exc16kWhtnd, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); + } +#endif + IF( LT_32( extl_brate, SWB_TBE_2k8 ) ) { +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); +#else syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); +#endif /* i: exc16kWhtnd in Q_bwe_exc */ /* o: excSHB in Q_bwe_exc */ } @@ -3492,7 +3718,11 @@ void GenShapedSHBExcitation_ivas_enc_fx( { set16_fx( zero_mem, 0, LPC_SHB_ORDER ); +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); +#else syn_filt_fx( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); +#endif tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3500,7 +3730,11 @@ void GenShapedSHBExcitation_ivas_enc_fx( syn_shb_ener_sf_q[0] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); move16(); +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); +#else syn_filt_fx( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); +#endif tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3508,7 +3742,11 @@ void GenShapedSHBExcitation_ivas_enc_fx( syn_shb_ener_sf_q[1] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); move16(); +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); +#else syn_filt_fx( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); +#endif tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3516,7 +3754,11 @@ void GenShapedSHBExcitation_ivas_enc_fx( syn_shb_ener_sf_q[2] = add( shl( add( *Q_bwe_exc, tmp ), 1 ), 1 ); move16(); +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); +#else syn_filt_fx( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); +#endif tmp = sub( getScaleFactor16( tempSHB, 80 ), 2 ); Scale_sig( tempSHB, 80, tmp ); syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); @@ -3579,10 +3821,17 @@ void GenShapedSHBExcitation_ivas_enc_fx( } /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + synthesis_enc_dec( enc_dec, 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); +#else syn_filt_fx( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); syn_filt_fx( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); syn_filt_fx( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); syn_filt_fx( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); +#endif /* i: exc16kWhtnd in (Q_bwe_exc) */ /* o: excSHB in (Q_bwe_exc) */ } @@ -3592,9 +3841,13 @@ void GenShapedSHBExcitation_ivas_enc_fx( tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); Scale_sig( fb_tbe_demph, 1, tmp ); +#ifdef HARMONIZE_TBE2 + synthesis_enc_dec( enc_dec, 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); +#else syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); - /* i: White_exc16k_FB in (Q_bwe_exc_fb) */ - /* o: White_exc16k_FB_temp in (Q_bwe_exc_fb) */ +#endif + /* i: White_exc16k_FB in (Q_bwe_exc_fb) / (14-n2)*/ + /* o: White_exc16k_FB_temp in (Q_bwe_exc_fb) / (14-n2)*/ FOR( i = 0; i < 10; i++ ) { @@ -3624,6 +3877,7 @@ void GenShapedSHBExcitation_ivas_enc_fx( return; } +#ifndef HARMONIZE_TBE2 void GenShapedSHBExcitation_ivas_dec_fx( Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ @@ -3649,17 +3903,20 @@ void GenShapedSHBExcitation_ivas_dec_fx( 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 */ - const Word32 bitrate, /* i : bitrate */ - const Word16 prev_bfi, /* i : previous frame was concealed */ - const Word16 element_mode, /* i : element mode */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ - Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ - const Word32 extl_brate, /* i : extension layer bitarte */ - const Word16 MSFlag, /* i : Multi Source flag */ - Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + 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, /* i : bitrate */ + const Word16 prev_bfi, /* i : previous frame was concealed */ + const Word16 element_mode, /* i : element mode */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + Word16 *nlExc16k, /* i/o: NL exc for IC-BWE */ + Word16 *mixExc16k, /* i/o: exc spreading for IC-BWE */ + + + const Word32 extl_brate, /* i : extension layer bitarte */ + const Word16 MSFlag, /* i : Multi Source flag */ + Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */ + Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */ Word16 *prev_mix_factor, /* i/o: mixing factor in the previous frame */ Word16 *Env_error, /* o : error in SHB residual envelope modelling Q0 */ @@ -3754,7 +4011,7 @@ void GenShapedSHBExcitation_ivas_dec_fx( L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); // Q_R } - E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL ); Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); // Q12 fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); // Q_bwe_exc @@ -4006,8 +4263,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 +4650,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 +4671,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 +4751,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 } } } @@ -4645,6 +4898,7 @@ void GenShapedSHBExcitation_ivas_dec_fx( *prev_mix_factor = mix_factor; return; } +#endif /*====================================================================================*/ /* FUNCTION : void GenSHBSynth_fx() */ @@ -4966,7 +5220,6 @@ void ScaleShapedSHB_fx( } } - Q_gFr_norm = norm_l( frame_gain ); if ( frame_gain == 0 ) { @@ -5204,19 +5457,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 +5479,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 +5577,6 @@ void ScaleShapedWB_fx( } } - max_val = 0; move16(); FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) @@ -5425,6 +5678,7 @@ void ScaleShapedWB_fx( return; } + /*-------------------------------------------------------------------* * non_linearity() * @@ -5433,7 +5687,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 +5697,6 @@ static Word32 non_linearity_scaled_copy( Word16 i; Word32 L_tmp; - IF( en_abs ) { FOR( i = 0; i < j; i++ ) @@ -5495,6 +5748,7 @@ static Word32 non_linearity_scaled_copy( move32(); } } + return prev_scale; } @@ -5502,12 +5756,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 +5771,6 @@ static Word32 non_linearity_scaled_copy_ivas( Word16 i; Word32 L_tmp; - IF( en_abs ) { FOR( i = 0; i < j; i++ ) @@ -5605,6 +5858,7 @@ static Word32 non_linearity_scaled_copy_ivas( move32(); } } + return prev_scale; } @@ -5631,15 +5885,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 +5915,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 +5949,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 +5962,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,258 +5974,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 ) ) ) - { - 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 */ - } - ELSE - { - scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ - } - - test(); - IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ) ) + IF( element_mode == EVS_MONO ) { - scale_step = 16384; - move16(); /*Q14 */ - prev_scale = L_shr( scale, 1 ); /*Q30 */ + prev_scale_factor = Mult_32_16( prev_scale, 32 ); } 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 */ - } + 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 */ } - 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; -#ifdef NONBE_1328_FIX_NON_LINEARITY - Word16 sc_factor; -#endif - - 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 */ - } - -#ifdef NONBE_1328_FIX_NON_LINEARITY - 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 */ -#else - test(); - IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ) /*Q30 -> Q31*/, scale /*Q31*/ ) ) -#endif + IF( prev_scale <= 0 || ( GT_32( prev_scale_factor, scale /*Q31*/ ) ) ) { scale_step = 16384; move16(); /* Q14 */ @@ -5980,7 +5994,6 @@ void non_linearity_ivas_fx( } ELSE { - /* Computing log2(scale) */ IF( j == 0 ) { @@ -6017,7 +6030,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(); @@ -6045,16 +6065,19 @@ void non_linearity_ivas_fx( move32(); /* Q31; 0.67 in Q31 */ } -#ifdef NONBE_1328_FIX_NON_LINEARITY - /* 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 */ -#else - IF( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 64 ), scale ) ) -#endif + IF( prev_scale <= 0 || ( GT_32( prev_scale_factor, scale /*Q31*/ ) ) ) { scale_step = 16384; move16(); /*Q14 */ @@ -6098,7 +6121,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(); @@ -6120,25 +6150,56 @@ 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; - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ - j = extract_l( L_shr( L_tmp, 23 ) ); + /* + 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) + */ + + 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 ) ); + } j = s_and( j, 0xff ); - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ - k = extract_l( L_shr( L_tmp, 23 ) ); + 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 ) ); + } + k = s_and( k, 0xff ); WHILE( EQ_16( k, j ) ) { - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ - k = extract_l( L_shr( L_tmp, 23 ) ); + 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 ) ); + } + k = s_and( k, 0xff ); } @@ -6272,6 +6333,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; } @@ -6499,7 +6561,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]; @@ -6547,7 +6608,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 ); @@ -6609,7 +6669,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]; @@ -6647,6 +6706,8 @@ void elliptic_bpf_48k_generic_fx( return; } + + /*-------------------------------------------------------------------* * synthesise_fb_high_band() * @@ -6667,9 +6728,9 @@ void synthesise_fb_high_band_fx( Word16 Q_fb_exc, Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ const Word32 fb_exc_energy, /* i : full band excitation energy */ - const Word16 ratio, /* i : energy ratio */ + const Word16 ratio, /* i : energy ratio */ const Word16 L_frame, /* i : ACELP frame length */ - const Word16 bfi, /* i : fec flag */ + const Word16 bfi, /* i : fec flag */ Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ Word16 bpf_memory_Q[], @@ -6703,20 +6764,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 ); @@ -6799,15 +6852,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 */ @@ -6871,7 +6927,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 */ @@ -6947,6 +7002,7 @@ void Estimate_mix_factors_fx( return; } + /*======================================================================================*/ /* FUNCTION : prep_tbe_exc_fx() */ /*--------------------------------------------------------------------------------------*/ @@ -6996,7 +7052,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/syn_12k8_fx.c b/lib_com/syn_12k8_fx.c index 86d4c6ef76bbc06a53d7f2bee16af0a546b985ea..7edf3a44b7378c4f9aef61fe7d534ad5b7432013 100644 --- a/lib_com/syn_12k8_fx.c +++ b/lib_com/syn_12k8_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -8,29 +8,29 @@ /*===========================================================================*/ -/* FUNCTION : syn_12k8_fx() */ +/* FUNCTION : syn_12k8_fx() */ /*---------------------------------------------------------------------------*/ -/* PURPOSE : perform the synthesis filtering 1/A(z). */ +/* PURPOSE : perform the synthesis filtering 1/A(z). */ /*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) st_fx->L_frame :length of the frame */ -/* _ (Word16[]) Aq : LP filter coefficients Q12 */ -/* _ (Word16) exc : input signal Q_exc */ -/* _ (Word16) update_m : update memory flag: 0-->no memory update */ -/* 1 --> update of memory */ -/* _ (Word16) Q_exc : Excitation scaling */ -/* _ (Word16) Q_syn : Synthesis scaling */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) st_fx->L_frame :length of the frame */ +/* _ (Word16[]) Aq : LP filter coefficients Q12 */ +/* _ (Word16) exc : input signal Q_exc */ +/* _ (Word16) update_m : update memory flag: 0-->no memory update */ +/* 1 --> update of memory */ +/* _ (Word16) Q_exc : Excitation scaling */ +/* _ (Word16) Q_syn : Synthesis scaling */ /*---------------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS : */ +/* INPUT OUTPUT ARGUMENTS : */ /*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) synth : initial filter states Q_syn */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) synth : initial filter states Q_syn */ /*---------------------------------------------------------------------------*/ /* _ (Word16[]) st_fx->mem_syn2_fx: initial filter states Q_syn */ /*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*===========================================================================*/ void syn_12k8_fx( Word16 L_frame, diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index cfa254042c6c823b921156e0265d369e40ffffa4..08d040662b5285d9ab95e507d6498ad3cfc07b20 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index 3abd527ca8bfa8b8690066da37fd978afd1aadb9..f74aea076c12bb762ec5a364a63e4d852ef22e07 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index a584de16a44a3c19fffa68bb3f4127f40be88e20..71fd2b6553235c5b48b628be7571d01d1dd5de65 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" @@ -106,7 +106,7 @@ void tcx_ltp_get_lpc( move16(); } - E_LPC_lev_dur( r_h, r_l, A, NULL, order, NULL ); + E_LPC_lev_dur_fx( r_h, r_l, A, NULL, order, NULL ); } void tcx_ltp_get_lpc_fx( @@ -199,7 +199,7 @@ void tcx_ltp_get_lpc_fx( move16(); } - E_LPC_lev_dur_fx( r_h, r_l, A, NULL, order, NULL ); + E_LPC_lev_dur_fx_32( r_h, r_l, A, NULL, order, NULL ); } static void tcx_ltp_get_zir( @@ -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++ ) { @@ -428,7 +433,7 @@ static void tcx_ltp_synth_filter( Word16 gain, /* Q15 */ Word16 pitch_res, /* Q0 */ Word16 *zir, /* can be NULL */ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ Word16 filtIdx /* Q0 */ ) { @@ -649,8 +654,8 @@ static void tcx_ltp_synth_filter32( Word16 pitch_fr, /* Q0 */ Word16 gain, /* Q15 */ Word16 pitch_res, /* Q0 */ - Word32 *zir, /* can be NULL Qx*/ - Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ + Word32 *zir, /* can be NULL Qx*/ + Word16 fade, /* 0=normal, +1=fade-in, -1=fade-out Q0*/ Word16 filtIdx /* Q0 */ ) { diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index 475a0079c74117488f23cebe48365dd3d8e611d1..4fd016729f51dde64c070c963f22a3d129a4e74f 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -233,14 +233,14 @@ void TCX_MDCT_Inverse( FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ + y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ move16(); } FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ + y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ move16(); } @@ -249,7 +249,7 @@ void TCX_MDCT_Inverse( Word16 f; f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); - y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ move16(); y[l + m + R2 - 1 - i] = f; move16(); @@ -290,13 +290,13 @@ void TCX_MDST_Inverse_fx( FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ move16(); } FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ move16(); } @@ -367,12 +367,12 @@ void TCX_MDXT_Inverse_fx( FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end exp(fac_e)*/ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end exp(fac_e)*/ } FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end exp(fac_e)*/ + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end exp(fac_e)*/ move16(); } @@ -381,7 +381,7 @@ void TCX_MDXT_Inverse_fx( f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); - y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ move16(); y[l + m + R2 - 1 - i] = f; diff --git a/lib_com/tcx_mdct_window_fx.c b/lib_com/tcx_mdct_window_fx.c index 285bbbf0a2a40d4eafaebd461083c5563c8fe440..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 @@ -31,13 +31,12 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include #include "options.h" -#include #include "cnst.h" #include "prot_fx.h" #include "rom_com.h" @@ -66,7 +65,6 @@ void mdct_window_sine_IVAS_updated( window[i].v.im = table[i].v.im; /* Qx */ move16(); } - // PMT("getSineWindowTable needs to be updated for IVAS") } ELSE { @@ -133,7 +131,6 @@ void mdct_window_sine( window[i].v.im = table[i].v.im; /* Qx */ move16(); } - // PMT("getSineWindowTable needs to be updated for IVAS") } } diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index a6b32f31040b2c362336ad848a422d6b3b622a40..7caf1b778ce27abfde805f9f00b2d31f29065e77 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -1973,7 +1973,7 @@ void tcx_noise_filling_with_shift( *--------------------------------------------------------------*/ -void InitTnsConfigs( +void InitTnsConfigs_fx( const Word16 bwidth, /*Q0*/ const Word16 L_frame, /*Q0*/ STnsConfig tnsConfig[2][2], @@ -1984,27 +1984,10 @@ void InitTnsConfigs( { IF( GT_32( total_brate, ACELP_32k ) ) { - InitTnsConfiguration( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); + InitTnsConfiguration_fx( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); } - 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*/ ) -{ - IF( GT_32( total_brate, ACELP_32k ) ) - { - InitTnsConfiguration_ivas_fx( bwidth, shr( L_frame, 1 ), &tnsConfig[0][0], igfStopFreq, total_brate, element_mode, MCT_flag ); - } - 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 ); + 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 ); } void SetTnsConfig( diff --git a/lib_com/tec_com_fx.c b/lib_com/tec_com_fx.c index 0a37504df957bc577c8fc9eed3c64c0b4fa17de3..5760b56b38cc56e06b8560d15f9e24ca0d47cb52 100644 --- a/lib_com/tec_com_fx.c +++ b/lib_com/tec_com_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c old mode 100755 new mode 100644 index 54e6478d45df63fd6324ce70b84f20528e9523b5..fe6f5d8ef55c8711bd30b0e721127a7c8f8bc36b --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -72,132 +72,8 @@ static void ITF_GetFilterParameters_fx( Word32 rxx[], const Word16 maxOrder, Wor /* Interface functions */ /********************************/ -/** Init TNS configuration. - * Fills STnsConfig structure with sensible content. - * @param nSampleRate Sampling rate of the input. - * @param nFrameLength Frame length. - * @param pTnsConfig TNS configuration to be initialized. - * @return 0 on success, otherwise 1. - */ -void InitTnsConfiguration( - const Word16 bwidth, - const Word16 frameLength, - STnsConfig *pTnsConfig, - const Word16 igfStopFreq, - const Word32 total_brate, - const Word16 element_mode, - const Word16 is_mct ) -{ - Word16 iFilter = 0; - move16(); - Word16 *startLineFilter; - Word32 L_tmp; - Word32 nSampleRate; - Word16 s1; - Word16 s2; - (void) ( element_mode ); - (void) ( is_mct ); - nSampleRate = bwMode2fs[bwidth]; - move32(); - startLineFilter = &pTnsConfig->iFilterBorders[1]; - - /* Sanity checks */ - assert( ( nSampleRate > 0 ) && ( frameLength > 0 ) && ( pTnsConfig != NULL ) ); - test(); - test(); - IF( ( nSampleRate <= 0 ) || ( frameLength <= 0 ) || ( pTnsConfig == NULL ) ) - { - return /*TNS_FATAL_ERROR*/; - } - - - /* Initialize TNS filter flag and maximum order */ - move16(); - pTnsConfig->maxOrder = TNS_MAX_FILTER_ORDER; - - IF( LE_32( total_brate, ACELP_32k ) ) - { - move16(); - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParametersIGF32kHz_LowBR ) / sizeof( tnsParametersIGF32kHz_LowBR[0] ); - pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; - } - ELSE - { - test(); - IF( GT_32( nSampleRate, 32000 ) && EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) - { - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters48kHz_grouped ) / sizeof( tnsParameters48kHz_grouped[0] ); - move16(); - pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; - } - ELSE - IF( GT_32( nSampleRate, INT_FS_16k ) ) - { - { - - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters32kHz ) / sizeof( tnsParameters32kHz[0] ); - - move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz; - - if ( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ - { - move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; - } - } - } - ELSE - { - IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ - { - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters16kHz_grouped ) / sizeof( tnsParameters16kHz_grouped[0] ); - pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; - } - ELSE - { - move16(); - move16(); - pTnsConfig->nMaxFilters = sizeof( tnsParameters16kHz ) / sizeof( tnsParameters16kHz[0] ); - pTnsConfig->pTnsParameters = tnsParameters16kHz; - } - } - } - - assert( pTnsConfig->nMaxFilters <= TNS_MAX_NUM_OF_FILTERS ); - - /* Set starting MDCT line for each filter based on the starting frequencies from the TNS table */ - - FOR( iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++ ) - { - assert( pTnsConfig->pTnsParameters[iFilter].startLineFrequency < nSampleRate / 2 ); - assert( nSampleRate <= 96000 ); - move16(); - startLineFilter[iFilter] = divide3232( L_mult0( frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency ), L_shl( nSampleRate, 14 ) ); - } - - IF( igfStopFreq > 0 ) - { - L_tmp = L_mult( frameLength, igfStopFreq ); - s1 = sub( norm_l( L_tmp ), 1 ); - s2 = norm_l( nSampleRate ); - - move16(); - pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl( L_tmp, s1 ), extract_h( L_shl( nSampleRate, s2 ) ) ), sub( WORD16_BITS - 1, sub( s2, s1 ) ) ); - } - ELSE - { - move16(); - pTnsConfig->iFilterBorders[0] = frameLength; - } - return; /*TNS_NO_ERROR;*/ -} -void InitTnsConfiguration_ivas_fx( +void InitTnsConfiguration_fx( const Word16 bwidth, /*Q0*/ const Word16 frameLength, /*Q0*/ STnsConfig *pTnsConfig, @@ -235,7 +111,7 @@ void InitTnsConfiguration_ivas_fx( IF( LE_32( total_brate, ACELP_32k ) ) { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParametersIGF32kHz_LowBR ), sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParametersIGF32kHz_LowBR ) / sizeof( tnsParametersIGF32kHz_LowBR[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } ELSE @@ -243,7 +119,7 @@ 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*/ + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters48kHz_grouped ) / sizeof( tnsParameters48kHz_grouped[0] ) ); /*Q0*/ move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } @@ -259,7 +135,7 @@ 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*/ + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters32kHz_Stereo ) / sizeof( tnsParameters32kHz_Stereo[0] ) ); /*Q0*/ move16(); IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { @@ -274,7 +150,7 @@ void InitTnsConfiguration_ivas_fx( { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters32kHz ), sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters32kHz ) / sizeof( tnsParameters32kHz[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters32kHz; @@ -289,13 +165,13 @@ void InitTnsConfiguration_ivas_fx( IF( EQ_32( nSampleRate, L_mult0( 100, frameLength ) ) ) /* sub-frame length is <= 10 ms */ { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz_grouped ), sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters16kHz_grouped ) / sizeof( tnsParameters16kHz_grouped[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } ELSE { move16(); - pTnsConfig->nMaxFilters = (UWord8) idiv1616( sizeof( tnsParameters16kHz ), sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ + pTnsConfig->nMaxFilters = (UWord8) ( sizeof( tnsParameters16kHz ) / sizeof( tnsParameters16kHz[0] ) ); /*Q0*/ pTnsConfig->pTnsParameters = tnsParameters16kHz; } } diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 1be575c2410063c75a5b55b0cc2d6a3976fcc634..4e48897453d0bea78a7e599fa1973d53b47a1899 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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -39,7 +39,6 @@ #include #include "options.h" #include "stl.h" -#include #include "cnst.h" #include "prot_fx.h" #include "basop_util.h" @@ -72,31 +71,6 @@ Word16 own_random( return ( *seed ); } -/*--------------------------------------------------------------------- - * norm_ul_float() - * - *---------------------------------------------------------------------*/ - -Word16 norm_ul_float( UWord32 UL_var1 ) -{ - Word16 var_out; - - if ( UL_var1 == 0 ) - { - var_out = 0; - } - else - { - for ( var_out = 0; UL_var1 < (UWord32) 0x80000000U; var_out++ ) - { - UL_var1 <<= 1; - } - } - BASOP_CHECK(); - - return ( var_out ); -} - /*--------------------------------------------------------------------- * sum_s() @@ -359,68 +333,6 @@ void set_l( return; } -/*---------------------------------------------------------------------* - * set_zero() - * - * Set a vector vec[] of dimension lvec to zero - *---------------------------------------------------------------------*/ - -void set_zero( - float *vec, /* o : input vector */ - const Word16 lvec /* i : length of the vector */ -) -{ - Word16 i; - - for ( i = 0; i < lvec; i++ ) - { - *vec++ = 0.0f; - } - - return; -} - - -/*---------------------------------------------------------------------* - * mvr2r() - * mvs2s() - * mvr2d() - * mvd2r() - * - * Transfer the contents of vector x[] to vector y[] - *---------------------------------------------------------------------*/ - -void mvr2r( - const float x[], /* i : input vector */ - float y[], /* o : output vector */ - const Word16 n /* i : vector size */ -) -{ - Word16 i; - - if ( n <= 0 ) - { - /* cannot transfer vectors with size 0 */ - return; - } - - if ( y < x ) - { - for ( i = 0; i < n; i++ ) - { - y[i] = x[i]; - } - } - else - { - for ( i = n - 1; i >= 0; i-- ) - { - y[i] = x[i]; - } - } - - return; -} void mvs2s( const Word16 x[], /* i : input vector */ @@ -879,26 +791,6 @@ void v_multc_fx_16_16( return; } -/*-------------------------------------------------------------------* - * usdequant() - * - * Uniform scalar de-quantizer routine - * - * Applies de-quantization based on scale and round operations. - *-------------------------------------------------------------------*/ - -float usdequant( - const Word16 idx, /* i : quantizer index */ - const float qlow, /* i : lowest codebook entry (index 0) */ - const float delta /* i : quantization step */ -) -{ - float g; - - g = idx * delta + qlow; - - return ( g ); -} void sort( UWord16 *x, /* i/o: Vector to be sorted */ @@ -925,192 +817,6 @@ void sort( return; } -#define WMC_TOOL_SKIP - -// conversion functions: -Word32 float_to_fix( float number, Word32 Q ) -{ - assert( Q >= 0 ); - if ( number == 1.0f && Q == Q31 ) - { - return ONE_IN_Q31; - } - if ( isnan( number ) ) - { - number = 0; - } - assert( fabs( number ) < pow( 2, 31 - Q ) ); - Word32 ret = (Word32) ( number * ( (UWord32) 1 << Q ) ); - return ret; -} - -float fix_to_float( - Word32 number, - Word32 Q ) -{ - assert( Q >= 0 ); - float ret = (float) number / ( (UWord32) 1 << Q ); - return ret; -} - -Word16 float_to_fix16( - float number, - Word16 Q ) -{ - assert( Q >= 0 ); - IF( isnan( number ) ) - return 0; - if ( number == 1.0f && Q == Q15 ) - return MAX16B; - if ( number == -1.0f && Q == Q15 ) - return MIN16B; - assert( fabs( number ) < pow( 2, 15 - Q ) ); - Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) ); - return ret; -} - -Word16 float_to_fix16_thrld( float number, Word16 Q ) -{ - assert( Q >= 0 ); - if ( number == 1.0f && Q == Q15 ) - return MAX16B; - float limit = (float) pow( 2, 15 - Q ); - /*Add threshold*/ - if ( number > MAX16B_FLT ) - { - number = MAX16B_FLT; - } - else if ( number < MIN16B_FLT ) - { - number = MIN16B_FLT; - } - assert( number <= limit && number >= -limit ); - Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) ); - return ret; -} - -float fix16_to_float( Word16 number, Word16 Q ) -{ - assert( Q >= 0 ); - float ret = (float) number / ( (UWord16) 1 << Q ); - return ret; -} - -// Float to 32-bit Mantissa and Exponent -void f2me( float n, Word32 *mantissa, Word16 *expo ) -{ - Word32 e; - float mf = (float) frexp( n, &e ); - *expo = (Word16) e; - *mantissa = float_to_fix( mf, Q31 ); -} - -// 32-bit Mantissa and Exponent to Float -float me2f( Word32 m, Word16 expo ) -{ - float mf = fix_to_float( m, Q31 ); - return (float) ldexp( mf, expo ); -} - -// Float buffer to 32-bit mantissa buffer and common exponent. -void f2me_buf( const float *x, Word32 *m, Word16 *e, const Word32 n ) -{ - Word16 max_e = -32, tmp_e; - Word32 i; - - for ( i = 0; i < n; i++ ) - { - f2me( x[i], &m[i], &tmp_e ); - max_e = ( max_e > tmp_e ) ? max_e : tmp_e; - } - - for ( i = 0; i < n; i++ ) - { - f2me( x[i], &m[i], &tmp_e ); - m[i] = L_shr( m[i], max_e - tmp_e ); - } - - *e = max_e; -} - -// 32-bit Mantissa buffer and exponent into float buffer. -void me2f_buf( const Word32 *m, const Word16 e, float *out, const Word32 n ) -{ - for ( int i = 0; i < n; i++ ) - { - out[i] = me2f( m[i], e ); - } -} - -// Float to 16-bit Mantissa and Exponent -void f2me_16( float n, Word16 *mantissa, Word16 *expo ) -{ - Word32 e; - float mf = (float) frexp( n, &e ); - *expo = (Word16) e; - *mantissa = float_to_fix16( mf, 15 ); -} - -// 16-bit Mantissa and Exponent to Float -float me2f_16( Word16 m, Word16 expo ) -{ - float mf = fix16_to_float( m, 15 ); - return (float) ldexp( mf, expo ); -} - -// Float buffer to 16-bit mantissa buffer and common exponent. -void f2me_buf_16( const float *x, Word16 *m, Word16 *e, const Word32 n ) -{ - Word16 max_e = -16, tmp_e; - Word32 i; - - for ( i = 0; i < n; i++ ) - { - f2me_16( x[i], &m[i], &tmp_e ); - max_e = ( max_e > tmp_e ) ? max_e : tmp_e; - } - - for ( i = 0; i < n; i++ ) - { - f2me_16( x[i], &m[i], &tmp_e ); - m[i] = shr( m[i], max_e - tmp_e ); - } - - *e = max_e; -} - -// 16-bit Mantissa buffer and exponent into float buffer. -void me2f_buf_16( const Word16 *m, const Word16 e, float *out, const Word32 n ) -{ - for ( int i = 0; i < n; i++ ) - { - out[i] = me2f_16( m[i], e ); - } -} -void f2fix( float *var_flt, Word32 *var_fix, Word32 expo ) -{ - *var_fix = (Word32) ( *var_flt * pow( 2, 31 - expo ) ); -} - -void fix2f( Word32 *var_fix, float *var_flt, Word32 expo ) -{ - float mf = fix_to_float( *var_fix, 31 ); - *var_flt = (float) ldexp( mf, expo ); -} - -void f2fix_16( float *var_flt, Word16 *var_fix, Word32 expo ) -{ - *var_fix = (Word16) ( *var_flt * pow( 2, 15 - expo ) ); -} - -void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo ) -{ - float mf = fix16_to_float( *var_fix, 15 ); - *var_flt = (float) ldexp( mf, expo ); -} - -#undef WMC_TOOL_SKIP - /*-------------------------------------------------------------------* * usdequant_fx() @@ -1890,7 +1596,7 @@ Word16 mean_fx( ) { Word16 tmp; - // PMT("TBV : this function could be written differently to minimize the risk of saturation"); + /* this function could be written differently to minimize the risk of saturation */ tmp = sum16_fx( vec_fx, lvec_fx ); tmp = mult_r( tmp, div_s( 1, lvec_fx ) ); @@ -2465,10 +2171,8 @@ Flag conv_fx( Word16 i, n; Word32 L_sum; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif y[0] = mult_r( x[0], h[0] ); move16(); FOR( n = 1; n < L; n++ ) @@ -2668,7 +2372,7 @@ void Vr_subt( *-------------------------------------------------------------------*/ /* o: index of the winning codevector */ -Word16 vquant_ivas_fx( +Word16 vquant_fx_32( Word32 x[], /* i: vector to quantize Q25 */ const Word32 x_mean[], /* i: vector mean to subtract (0 if none) Q25 */ Word32 xq[], /* o: quantized vector Q25 */ @@ -4253,10 +3957,8 @@ Word32 Calc_Energy_Autoscaled( Word16 temp, temp2; Word32 L_temp, L_Energy; Word16 i, j; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif Overflow = 0; move16(); @@ -4950,10 +4652,8 @@ Word16 dot_prod_satcontr( Word16 shift, q, ener, i; Word32 L_tmp; Word16 *pt1, *pt2; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif Copy( x, tmp_tab_x, len ); /* OPTIMIZE !!!!! the copy into local table is not necessary */ Copy( y, tmp_tab_y, len ); /* could be reworked to do a 1st iteration with the original x[] and y[] */ diff --git a/lib_com/trans_direct_fx.c b/lib_com/trans_direct_fx.c index 6a3cdf108733bc3601d87d7398f6686087eae3cf..c84cd9efad4c495df32efee54db2a27c02a2faa0 100644 --- a/lib_com/trans_direct_fx.c +++ b/lib_com/trans_direct_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -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 36678487a263a9b9737b86959583bc4456ec0a83..34d424f26e0bcdebff96c44bcc3584ff2f2f725c 100644 --- a/lib_com/trans_inv_fx.c +++ b/lib_com/trans_inv_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -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_com/vlpc_2st_com_fx.c b/lib_com/vlpc_2st_com_fx.c index 3fcdf144d6b599ec643c6156e59d1475175697f9..6f930f08f8aeeb7a8a7937360d1b32022f9969e4 100644 --- a/lib_com/vlpc_2st_com_fx.c +++ b/lib_com/vlpc_2st_com_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -10,8 +10,8 @@ void lsf_weight_2st( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ - Word16 *w, /* output: weighting function (0Q15*1.28) */ + const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ + Word16 *w, /* output: weighting function (0Q15*1.28) */ const Word16 mode /* input: operational mode Q0 */ ) { diff --git a/lib_com/weight_a_fx.c b/lib_com/weight_a_fx.c index 8a6caf04ab365a3dd2661f9d425cf2d4da053ea7..cb537a7d6ffed300a3f4d0b7fed2039150224a4c 100644 --- a/lib_com/weight_a_fx.c +++ b/lib_com/weight_a_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -35,21 +35,21 @@ void weight_a_subfr_fx( } /*==============================================================================*/ -/* FUNCTION : void weight_a_lc_fx ( ) */ +/* FUNCTION : void weight_a_lc_fx ( ) */ /*------------------------------------------------------------------------------*/ /* PURPOSE : Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i)*/ /*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* const Word16 a[], i: LP filter coefficients Q12 */ -/* const Word16 *gammatbl, i: weighting factor Q15 */ -/* const Word16 m i: order of LP filter Q0 */ +/* INPUT ARGUMENTS : */ +/* const Word16 a[], i: LP filter coefficients Q12 */ +/* const Word16 *gammatbl, i: weighting factor Q15 */ +/* const Word16 m i: order of LP filter Q0 */ /*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 ap[], o: weighted LP filter coefficients Q12 */ +/* OUTPUT ARGUMENTS : */ +/* Word16 ap[], o: weighted LP filter coefficients Q12 */ /*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ +/* RETURN ARGUMENTS : */ /*------------------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ +/* CALLED FROM : TX/RX */ /*==============================================================================*/ void weight_a_lc_fx( const Word16 a[], /* i: LP filter coefficients Q12 */ @@ -131,9 +131,9 @@ void weight_a_fx( * E_LPC_a_weight_inv * * Parameters: - * a I: LP filter coefficients Q12 + * a I: LP filter coefficients Q12 * ap O: weighted LP filter coefficients Q12 - * inv_gamma I: inverse weighting factor Q14 + * inv_gamma I: inverse weighting factor Q14 * m I: order of LP filter * * Function: diff --git a/lib_com/weight_fx.c b/lib_com/weight_fx.c index eb3f19bf75acbf822d1eae8eda0eada67887cd71..87335d88d2b397603cca51110d616bd485c08f04 100644 --- a/lib_com/weight_fx.c +++ b/lib_com/weight_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -15,9 +15,9 @@ *--------------------------------------------------------------------------*/ static void sfm2mqb_fx( - Word16 spe[], /* i : sub-vectors Q0*/ - Word16 spe2q[], /* o : pbands Q0*/ - const Word16 nb_sfm /* i : number of norms Q0*/ + Word16 spe[], /* i : sub-vectors Q0*/ + Word16 spe2q[], /* o : pbands Q0*/ + const Word16 nb_sfm /* i : number of norms Q0*/ ) { Word16 tmp, i; @@ -117,9 +117,9 @@ static void sfm2mqb_fx( *--------------------------------------------------------------------------*/ static void mqb2sfm_fx( - Word16 spe2q[], /* i : pbands Q0*/ - Word16 spe[], /* o : sub-vectors Q0*/ - const Word16 lnb_sfm /* i : number of norms Q0*/ + Word16 spe2q[], /* i : pbands Q0*/ + Word16 spe[], /* o : sub-vectors Q0*/ + const Word16 lnb_sfm /* i : number of norms Q0*/ ) { Word16 i; diff --git a/lib_com/wi_fx.c b/lib_com/wi_fx.c index 58f1a813dbe3dbedee9c399945703c5e18605b79..189a48e3b0ecc039668a17bd7cd9717f44f539f3 100644 --- a/lib_com/wi_fx.c +++ b/lib_com/wi_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -45,7 +45,6 @@ ivas_error DTFS_new_fx( DTFS_STRUCTURE *dtfs_fx = NULL; dtfs_fx = (DTFS_STRUCTURE *) calloc( 1, sizeof( DTFS_STRUCTURE ) ); - // PMT("verif mem alloc") IF( dtfs_fx == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n" ) ); @@ -3088,9 +3087,6 @@ ivas_error WIsyn_fx( /* Adjust the phase offset and wrap it between 0 and 2pi */ - // PMT("NEED a complete verification of mem flow and assignment") - - IF( EQ_16( flag, 2 ) ) { L_temp = L_shr( L_mult( tmp_fx, I ), 1 ); /* Q15 */ diff --git a/lib_com/window_fx.c b/lib_com/window_fx.c index 8f8652543413f3f68b9aa1165cc921dbb9931a9d..df92abadeb50e9014c2cb14b27afb51a78c07458 100644 --- a/lib_com/window_fx.c +++ b/lib_com/window_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -31,7 +31,7 @@ void ham_cos_window( assert( n1 >= 102 ); /* if n1 is too low -> overflow in div_l */ - /* cte = PI2/(Float32)(2*n1 - 1); */ + /* cte = PI2/(Float32)(2*n1 - 1); */ BASOP_SATURATE_WARNING_OFF_EVS cte = L_deposit_l( div_l( PI2_10Q21, sub( shl( n1, 1 ), 1 ) ) ); /*0Q15*/ BASOP_SATURATE_WARNING_ON_EVS @@ -39,7 +39,7 @@ void ham_cos_window( move32(); FOR( i = 0; i < n1; i++ ) { - /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc); */ + /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc); */ BASOP_SATURATE_WARNING_OFF_EVS fh[i] = sub_sat( P54_0Q15, mult_r( getCosWord16( round_fx_sat( L_shl_sat( cc, 9 ) ) ), P92_0Q15 ) ); /*0Q15*/ move16(); @@ -48,7 +48,7 @@ void ham_cos_window( } assert( n2 >= 26 ); /* if n2 is too low -> overflow in div_l */ - /* cte = PI2/(Float32)(4*n2 - 1); */ + /* cte = PI2/(Float32)(4*n2 - 1); */ cte = L_deposit_l( div_l( PI2_11Q20, sub( shl( n2, 2 ), 1 ) ) ); /*0Q15*/ cc = 0; move32(); @@ -57,7 +57,7 @@ void ham_cos_window( BASOP_SATURATE_WARNING_OFF_EVS FOR( i = n1; i < n1 + n2; i++ ) { - /* fh_f[i] = (Float32)cos(cc); */ + /* fh_f[i] = (Float32)cos(cc); */ fh[i] = shl_sat( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1 ); /*0Q15*/ move16(); cc = L_add( cc, cte ); diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 2948e725ecdb0ca7d1add2a05b91500c4b2b8aaa..1ca29f82ade4802ed92b381927d4fd3bd242d490 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ diff --git a/lib_com/wtda_fx.c b/lib_com/wtda_fx.c index 7943a87c5fc11a276127169b3e0dd8ee8f88895a..c285d88839db98375e926999334b926e69f695ff 100644 --- a/lib_com/wtda_fx.c +++ b/lib_com/wtda_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include 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 acf372565408b238d2a86c40b85a396f5660b5ae..2fc562d0be3c8238a8050ece13f2b9ef5a4caebb 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -267,13 +267,13 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( { IF( s_and( idx1, 1 ) ) /* update first context */ { - c[p1] = update_mixed_context( c[p1], a ); + c[p1] = update_mixed_context_fx( c[p1], a ); move16(); } IF( s_and( idx2, 1 ) ) /* update second context */ { - c[p2] = update_mixed_context( c[p2], b ); + c[p2] = update_mixed_context_fx( c[p2], b ); move16(); } } @@ -557,14 +557,14 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( IF( s_and( idx1, 1 ) ) { /* update first context */ - c[p1] = update_mixed_context( c[p1], a ); + c[p1] = update_mixed_context_fx( c[p1], a ); move16(); } IF( s_and( idx2, 1 ) ) { /* update second context */ - c[p2] = update_mixed_context( c[p2], b ); + c[p2] = update_mixed_context_fx( c[p2], b ); move16(); } } @@ -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 c90530d5dc23b5316d00bbf860197b4377ec78be..641f6005913ec14383212465558f765c5cd7975c 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -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/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 4ad39acf07dc69641254ba62662576843789d78e..497e76ec8fc7568f18097ac25642d5a55244396e 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -750,7 +750,6 @@ static void ivas_peakfinder_fx( } ELSE { - // PMTE () ii = -1; /* First point is a peak */ move16(); IF( GE_16( len, 2 ) ) @@ -1359,7 +1358,6 @@ static void ivas_spec_ana_fx( } ELSE { - // PMTE() window_corr = w_hamm[0]; move16(); window_corr_step = idiv1616( w_hamm[0], hamm_len2 ); @@ -1384,7 +1382,6 @@ static void ivas_spec_ana_fx( } ELSE { - // PMTE() window_corr = w_hamm[0]; move16(); window_corr_step = idiv1616( w_hamm[0], hamm_len2 ); @@ -2142,11 +2139,8 @@ static void ivas_subst_spec_fx( im = *pImX; move16(); tmp = sub_sat( mult_r( re, cos_F ), mult_r( im, sin_F ) ); -#ifdef FIX_2170_ASSERT_IN_FFT3 im = add_sat( mult_r( re, sin_F ), mult_r( im, cos_F ) ); -#else - im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); -#endif + IF( LT_16( alpha[k], 32766 ) ) { alpha_local = mag_chg_local; @@ -2770,7 +2764,6 @@ static void rec_wtda_fx( Word16 g; Word16 tbl_delta; - // PMTE() xsubst_ = rec_buf + output_frame; Lprot2 = shr( Lprot, 1 ); @@ -4069,7 +4062,6 @@ static void ivas_fec_noise_filling_fx( const Word16 *p_mdct_ola; Word16 alignment_point; - // PMTE() L20 = extract_h( L_mult( 1639, L ) ); /*L/20 */ IF( element_mode == EVS_MONO ) { diff --git a/lib_dec/FEC_adapt_codebook_fx.c b/lib_dec/FEC_adapt_codebook_fx.c index 24ddc6463b456cab77b31fec330af17b6b00b081..5428d057beff1ae7925cc2b19b65b12d76be8500 100644 --- a/lib_dec/FEC_adapt_codebook_fx.c +++ b/lib_dec/FEC_adapt_codebook_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 595e750f49e710ae9d93a00654cc8aed40850b8d..f968ccb9039e0b0e48468fdfa4c71cac64f846fa 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 574e2e14f9e209a4cef2a1ea22b86bcbf3971dcd..fe2780a8600c7dc9457102ef016ee65929d384a1 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/FEC_lsf_estim_fx.c b/lib_dec/FEC_lsf_estim_fx.c index ba248598c260a255f0b466f861cd2d4538b58d58..ddf1f7df6fcde1af14d40dcb7448aba17bab9272 100644 --- a/lib_dec/FEC_lsf_estim_fx.c +++ b/lib_dec/FEC_lsf_estim_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -16,11 +16,11 @@ *-------------------------------------------------------------------*/ void FEC_lsf2lsp_interp( - Decoder_State *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes Q12 */ + Decoder_State *st, /* i/o: Decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + Word16 *Aq, /* o : calculated A(z) for 4 subframes Q12 */ Word16 *lsf, /* o : estimated LSF vector Qlog2(2.56)*/ - Word16 *lsp /* o : estimated LSP vector Q15* */ + Word16 *lsp /* o : estimated LSP vector Q15* */ ) { diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 4ea25cd857b2ed36ddbceda1a6f27dc1cbaafa9d..066afccf9d46d7c2f8cd86f0febf8bd626e80c58 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -9,30 +9,30 @@ /*========================================================================*/ -/* FUNCTION : FEC_pitch_estim_fx() */ +/* FUNCTION : FEC_pitch_estim_fx() */ /*------------------------------------------------------------------------*/ -/* PURPOSE : Estimation of pitch for FEC */ -/* */ +/* PURPOSE : Estimation of pitch for FEC */ +/* */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) st_fx->Opt_AMR_WB: flag indicating AMR-WB IO mode */ -/* _ (Word16) st_fx->L_frame_fx: length of the frame */ -/* _ (Word16) st_fx->clas_dec: frame classification */ -/* _ (Word16) st_fx->last_good: last good clas information */ -/* _ (Word16[]) pitch : pitch values for each subframe Q6 */ -/* _ (Word16[]) old_pitch_buf:pitch values for each subframe Q6 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) st_fx->Opt_AMR_WB: flag indicating AMR-WB IO mode */ +/* _ (Word16) st_fx->L_frame_fx: length of the frame */ +/* _ (Word16) st_fx->clas_dec: frame classification */ +/* _ (Word16) st_fx->last_good: last good clas information */ +/* _ (Word16[]) pitch : pitch values for each subframe Q6 */ +/* _ (Word16[]) old_pitch_buf:pitch values for each subframe Q6 */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ -/* _ (Word16[]) st_fx->bfi_pitch : initial synthesis filter states */ +/* _ (Word16[]) st_fx->bfi_pitch : initial synthesis filter states */ /* _ (Word16) st_fx->bfi_pitch_frame: LP filter E of last */ /* _ (Word16) st_fx->upd_cnt_fx: update counter */ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void FEC_pitch_estim_fx( const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 7f4586083e938d9eecb623b325a54dcecad9e71a..a0e0b3981f01b78f7c96a4c19ca2867a4fe8242d 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -13,41 +13,41 @@ #define SCLSYN_LAMBDA ( 9830 /*0.3f Q15*/ ) /*========================================================================*/ -/* FUNCTION : FEC_scale_syn_fx() */ +/* FUNCTION : FEC_scale_syn_fx() */ /*------------------------------------------------------------------------*/ -/* PURPOSE : Smooth the speech energy evolution when */ -/* recovering after a BAD frame */ +/* PURPOSE : Smooth the speech energy evolution when */ +/* recovering after a BAD frame */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame : length of the frame */ -/* _ (Word16) *update_flg : indication about resynthesis */ -/* _ (Word16) st_fx->clas_dec: frame classification */ -/* _ (Word16) last_good : last good frame classification */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) L_frame : length of the frame */ +/* _ (Word16) *update_flg : indication about resynthesis */ +/* _ (Word16) st_fx->clas_dec: frame classification */ +/* _ (Word16) last_good : last good frame classification */ /* _ (Word16[]) synth : synthesized speech at Fs = 12k8 Hz Q_syn */ -/* _ (Word16[]) pitch : pitch values for each subframe Q0 */ -/* _ (Word32) L_enr_old :energy at the end of previous frame Q0 */ -/* _ (Word16) L_enr_q : transmitted energy for current frame Q0 */ -/* _ (Word16) coder_type : coder type */ +/* _ (Word16[]) pitch : pitch values for each subframe Q0 */ +/* _ (Word32) L_enr_old :energy at the end of previous frame Q0 */ +/* _ (Word16) L_enr_q : transmitted energy for current frame Q0 */ +/* _ (Word16) coder_type : coder type */ /* _ (Word16) st_fx->prev_bfi_fx: previous frame BFI */ /* _ (Word16) st_fx->last_core_brate_fx: previous frame core bitrate */ -/* _ (Word16[]) mem_tmp : temp. initial synthesis filter states Q_syn */ -/* _ (Word16) Q_exc : quantized LSPs from frame end */ -/* _ (Word16) Q_syn : quantized LSPs from frame end */ +/* _ (Word16[]) mem_tmp : temp. initial synthesis filter states Q_syn */ +/* _ (Word16) Q_exc : quantized LSPs from frame end */ +/* _ (Word16) Q_syn : quantized LSPs from frame end */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc : excitation signal without enhancement Q_exc */ -/* _ (Word16[]) exc2 : excitation signal with enhancement Q_exc */ -/* _ (Word16[]) Aq : LP filter coefs (can be modified if BR) Q12 */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc : excitation signal without enhancement Q_exc */ +/* _ (Word16[]) exc2 : excitation signal with enhancement Q_exc */ +/* _ (Word16[]) Aq : LP filter coefs (can be modified if BR) Q12 */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ -/* _ (Word16[]) st_fx->mem_syn2 : initial synthesis filter states Q_syn */ +/* _ (Word16[]) st_fx->mem_syn2 : initial synthesis filter states Q_syn */ /* _ (Word16) st_fx->old_enr_LP : LP filter E of last Q5 */ -/* good voiced frame */ +/* good voiced frame */ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void FEC_scale_syn_fx( @@ -242,7 +242,7 @@ void FEC_scale_syn_fx( pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); /*Q0*/ L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); /*Q14*/ } - /*pitch_dist /= (float)(NB_SUBFR-1); */ + /*pitch_dist /= (float)(NB_SUBFR-1); */ pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 /*1/(float)(NB_SUBFR-1) in Q15*/ ); /*Q4*/ /*mean_pitch /= (float)(NB_SUBFR);*/ mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); /*Q4*/ diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index d1ec20b0b88a35f8e3217eb632e085cbaabf384f..fe643376858fc44c1117d3175da2ba38ebf0738d 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index bfb0b0428e6dd9b3d5413d014e0c7b08dea19ae4..be1245c9ec8b32dccd9694c6b0e0b5dba58da923 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #define _USE_MATH_DEFINES @@ -85,7 +85,6 @@ void ivas_DetectTonalComponents_fx( { nBands = FDNS_NPTS; move16(); - // PMT("add nBands argument to mdct_shaping_16") mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); @@ -447,19 +446,15 @@ static void getEnvelope( assert( ( nFilterLength >= 7 ) && ( nFilterLength <= 23 ) && ( nFilterLength % 2 == 1 ) ); - sum = L_deposit_l( 0 ); level = 31089 /*LEVEL_ABOVE_ENVELOPE Q12*/; /*Q12*/ move16(); FOR( i = 0; i < n2; i++ ) { -#ifdef FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC sum = L_add_sat( sum, powerSpec[i] ); /*powerSpec_exp*/ -#else - sum = L_add( sum, powerSpec[i] ); /*powerSpec_exp*/ -#endif } + /* No need for PTR_INIT for powerSpec[i+n2] as we continue from the previous loop */ FOR( i = 0; i < n1; i++ ) { diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 00d6ce926a97d88692e32fce0752f5ab116279f7..7b06d4b0d64a521878f81473c42df863e9c031f4 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 @@ -31,11 +31,10 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include -#include #include "options.h" #include "cnst.h" #include "rom_com.h" @@ -54,9 +53,9 @@ ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ Word16 synth_fx16[], /* o : synthesis Q_syn2*/ - Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ + Word32 save_hb_synth_fx32[], /* o : HB synthesis Q0*/ 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 +74,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. */ @@ -124,7 +122,7 @@ ivas_error acelp_core_dec_fx( ivas_error error; Word32 bpf_error_signal_fx[L_FRAME16k]; Word16 bpf_error_signal_16fx[L_FRAME16k]; - Word16 Q_real; + Word16 Q_real, scf; Word32 max_real, max_imag, max_val; set32_fx( bpf_error_signal_fx, 0, L_FRAME16k ); @@ -207,7 +205,7 @@ 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 */ + 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 */ 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 +967,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 +1034,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 ); } /*---------------------------------------------------------------* @@ -1757,9 +1755,8 @@ ivas_error acelp_core_dec_fx( IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); - resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); + resampleCldfb( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); IF( st->ini_frame > 0 ) { @@ -1898,6 +1895,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; @@ -2010,7 +2008,7 @@ ivas_error acelp_core_dec_fx( } } - IF( save_hb_synth_fx16 != NULL ) + IF( save_hb_synth_fx32 != NULL ) { /* save and then zero-out lowband */ max_real = 0; @@ -2051,7 +2049,7 @@ 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 ); + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx32, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); /* restore lowband */ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) @@ -2084,12 +2082,16 @@ ivas_error acelp_core_dec_fx( } max_val = L_max( max_real, max_imag ); Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; + scf = L_norm_arr( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length ); + scf = s_min( scf, sub( Q_real, Q11 ) ); + Q_real = add( scf, Q11 ); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real } - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) + + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, scf ); // Q10 - > (Q_real-1) st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); move16(); @@ -2101,7 +2103,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 { @@ -2189,12 +2191,10 @@ 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 - IF( st->element_mode > EVS_MONO ) - { - Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ - } + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 + Copy_Scale_sig_16_32_no_sat( psyn_fx, output_fx32, st->L_frame, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 st->Q_syn2 = 0; move16(); } @@ -2215,16 +2215,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 { @@ -2275,12 +2266,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 ); @@ -2307,17 +2298,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; @@ -2329,15 +2311,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 4b1e04e08b067331f0afb55cab6cb98ce8085391..dd477874f1de42f56209d021d5f2a4edca6a9cde 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 d5a3cf71a2f35b0b650407150d408758869ea412..3806f8c2a920021b5ce46b0a7d6d7d62c7539b25 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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; } @@ -339,9 +339,7 @@ ivas_error amr_wb_dec_fx( st_fx->bfi_pitch_frame = L_FRAME; move16(); } -#ifdef _DIFF_FLOAT_FIX_ - PMT( "the code below has been removed in IVAS float (or moved somewhere else), is it ok?" ) -#endif + IF( NE_16( st_fx->last_core, AMR_WB_CORE ) ) { /* reset the unvoiced/audio signal improvement memories */ @@ -350,7 +348,7 @@ ivas_error amr_wb_dec_fx( Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 2, M + 1 ), M + 1 ); /*Q12*/ Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 3, M + 1 ), M + 1 ); /*Q12*/ } - /*End of _DIFF_FLOAT_FIX_*/ + test(); if ( EQ_16( st_fx->last_bwidth, NB ) && st_fx->ini_frame != 0 ) { @@ -854,10 +852,8 @@ ivas_error amr_wb_dec_fx( IF( NE_16( i_mult( st_fx->cldfbAna->usb, st_fx->cldfbAna->no_col ), L_FRAME ) ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( INT_FS_FX ); - - resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); + resampleCldfb( st_fx->cldfbAna, INT_FS_FX, L_FRAME, 0 ); + resampleCldfb( st_fx->cldfbBPF, INT_FS_FX, L_FRAME, 0 ); IF( st_fx->ini_frame > 0 ) { @@ -997,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_dec_fx.c b/lib_dec/ari_dec_fx.c index 3aabbdaa58cbcdda0a7c83d962eb9297c8a8608f..c9912eba88aba8924e815edf22b4cdb5a65cd286 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -19,7 +19,7 @@ Word32 ari_decode_overflow_fx( Tastat *s ) } /** - * \brief Start ArCo decoding + * \brief Start ArCo decoding * * \param[i/o] st * \param[o] s diff --git a/lib_dec/ari_hm_dec_fx.c b/lib_dec/ari_hm_dec_fx.c index 51949328c550ed6428311ee6c78ec5efc42c53fd..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 2919210dc2aab107d81789eb08cf8149730fb927..e91ac4ed0201b33814a3989abcd89222a50a3e8e 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -27,11 +27,9 @@ static Word16 tcx_arith_decode_fx( Tastat as; Word16 exp_k; Word16 tmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Word32 Q; Word64 W_tmp; move32(); -#endif bp = ari_start_decoding_14bits_prm_fx( prm, 0, &as ); diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index a8ba2bfc3612253b30e153d2cb22f863afe3d4a4..4e4735b8336dfb321e7cfa1345ac72ed332711d8 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -23,13 +23,13 @@ static void read_cv_fx( Decoder_State *st, UWord16 *I, Word16 *kv, Word16 nq, Wo *-----------------------------------------------------------------*/ void AVQ_demuxdec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1] Q0*/ - Word16 *nb_bits, /* i/o: number of allocated bits Q0*/ - const Word16 Nsv, /* i : number of subvectors Q0*/ - Word16 nq[], /* i/o: AVQ nq index Q0*/ - Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution Q0*/ - Word16 trgtSvPos /* i : target SV for AVQ bit savings Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1] Q0*/ + Word16 *nb_bits, /* i/o: number of allocated bits Q0*/ + const Word16 Nsv, /* i : number of subvectors Q0*/ + Word16 nq[], /* i/o: AVQ nq index Q0*/ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution Q0*/ + Word16 trgtSvPos /* i : target SV for AVQ bit savings Q0*/ ) { Word16 i, j, bits, tmp; @@ -329,9 +329,9 @@ void AVQ_demuxdec_fx( *-----------------------------------------------------------------*/ void AVQ_dec_lpc( - Word16 *indx, /* input: index[] (4 bits per words) Q0*/ - Word16 *nvecq, /* output: vector quantized Q0*/ - Word16 Nsv /* input: number of subvectors (lg=Nsv*8) Q0*/ + Word16 *indx, /* input: index[] (4 bits per words) Q0*/ + Word16 *nvecq, /* output: vector quantized Q0*/ + Word16 Nsv /* input: number of subvectors (lg=Nsv*8) Q0*/ ) { Word16 i, l, n, nq, nk, pos, ival, c[8], kv[8]; diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index bb2158057b63e82df5cfe08b5efba649baf0a148..d2558f47c1f1bc9a5ff1b5dca78acb5763eeff17 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -40,12 +40,12 @@ void bass_psfilter_init_fx( hBPF->pst_mem_deemp_err_fx = 0; /* 0 in Q_syn2-1 */ move16(); hBPF->pst_lp_ener_fx = 0; - move16(); /*0 in Q8 */ + move16(); /*0 in Q8 */ set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); set16_fx( hBPF->Track_on_hist, 0, L_TRACK_HIST ); set16_fx( hBPF->vibrato_hist, 0, L_TRACK_HIST ); - set16_fx( hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST ); /* 80 in Q4 */ - hBPF->psf_att_fx = 32767; /* 1.0 in Q15 */ + set16_fx( hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST ); /* 80 in Q4 */ + hBPF->psf_att_fx = 32767; /* 1.0 in Q15 */ move16(); return; @@ -80,17 +80,17 @@ void bass_psfilter_init_fx( /*=========================================================================*/ void bass_psfilter_fx( - BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag Q0*/ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) Q_syn2-1*/ - const Word16 L_frame, /* i : length of the last frame Q0*/ - Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] Q6*/ - const Word16 bpf_off, /* i : do not use BPF when set to 1 Q0*/ - Word16 v_stab_fx, /* i : stability factor Q15*/ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor Q15*/ - const Word16 coder_type, /* i : coder_type Q0*/ + BPF_DEC_HANDLE hBPF, /* i/o: BPF data handle */ + const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag Q0*/ + Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) Q_syn2-1*/ + const Word16 L_frame, /* i : length of the last frame Q0*/ + Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] Q6*/ + const Word16 bpf_off, /* i : do not use BPF when set to 1 Q0*/ + Word16 v_stab_fx, /* i : stability factor Q15*/ + Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor Q15*/ + const Word16 coder_type, /* i : coder_type Q0*/ Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) Qx*/ + Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) Qx*/ ) { Word16 i, j, i_subfr, T, exp, exp2; @@ -685,9 +685,9 @@ void bass_psfilter_fx( /* CALLED FROM : TX/RX */ /*==============================================================================*/ -static Word16 Pit_track_fx( /* o : Pitch */ - Word16 syn[], /* i : synthesis [-PIT_MAX..L_SUBFR] st_fx->Q_syn2 */ - Word16 T /* i : pitch period (>= PIT_MIN) Q0 */ +static Word16 Pit_track_fx( /* o : Pitch */ + Word16 syn[], /* i : synthesis [-PIT_MAX..L_SUBFR] st_fx->Q_syn2 */ + Word16 T /* i : pitch period (>= PIT_MIN) Q0 */ ) { Word16 T2; @@ -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 dec4a7adfc69062048f09c452fcfcff62b4baae2..56d2bd29c3e33ac9724922d7936ab0c301c0c909 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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() @@ -699,7 +695,7 @@ void CNG_dec_fx( void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + 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 */ @@ -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,15 +739,15 @@ 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*/ + 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 */ ) { 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 aa86fc624108f4423398bb03bc4946f162b63375..a75acb7e198934463e7992d686ba1727a82e4c44 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -240,7 +240,7 @@ void open_decoder_LPD_fx( IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ if ( st->tcxonly == 0 ) @@ -357,7 +357,7 @@ void open_decoder_LPD_fx( test(); IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) { - Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */ set16_fx( st->syn, 0, M ); /* Q_syn */ } @@ -1113,10 +1113,10 @@ void acelp_plc_mdct_transition_fx( } void open_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate Q0*/ - const Word32 last_total_brate, /* i : last total bitrate Q0*/ - const Word16 bwidth, /* i : audio bandwidth Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 last_total_brate, /* i : last total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ const Word16 last_element_mode, /* i : last element mode Q0*/ const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization Q0*/ @@ -1978,7 +1978,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_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index 2eee8cd9f23e005d13c210b15d5cbfaad80865ef..d844e666b1b6bcec91a7bc17b6496825a0867360 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -11,7 +11,7 @@ void reconfig_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ + Decoder_State *st, /* i/o: decoder state structure */ const Word16 bits_frame, /* i : bit budget Q0*/ const Word16 bwidth, /* i : audio bandwidth Q0*/ const Word32 total_brate, /* i : total bitrate Q0*/ diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 90379c732ac7df169ca5a03eba2624a84d2eac84..5c824532e509ffcadec103225bc849184731f1e0 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -133,7 +133,7 @@ void mode_switch_decoder_LPD_fx( IF( ( st->hTcxCfg->fIsTNSAllowed != 0 ) && st->hIGFDec != NULL ) { - 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*/ ); + 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*/ ); } } } @@ -236,13 +236,13 @@ void mode_switch_decoder_LPD_fx( } void mode_switch_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bwidth, /* i : audio bandwidth Q0*/ - const Word32 total_brate, /* i : total bitrate Q0*/ - const Word32 last_total_brate, /* i : last frame total bitrate Q0*/ - const Word16 frame_size_index, /* i : index determining the frame size Q0*/ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 last_element_mode, /* i : last element mode Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 last_total_brate, /* i : last frame total bitrate Q0*/ + const Word16 frame_size_index, /* i : index determining the frame size Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -377,7 +377,7 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hTcxCfg->fIsTNSAllowed && st->hIGFDec != NULL && st->hTcxCfg != NULL ) { - InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); + InitTnsConfigs_fx( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag ); 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 162e45812e34fc8f984f705eaf8b8a3a876d65b2..b8f4cc63f126f5fbef8fc1dd48013db3d982e251 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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,1000 +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(); - } - } - - - 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(); - } + /* 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(); + } - /* 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(); @@ -1185,81 +179,44 @@ ivas_error core_switching_post_dec_fx( 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->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( +ivas_error core_switching_post_dec_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*/ + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q11*/ + Word32 output_mem_fx32[], /* i : OLA memory from last TCX/HQ frame Qx*/ 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 +259,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 +271,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 +295,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 +325,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 +438,7 @@ 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 */ + Scale_sig32( output_fx, L_FRAME48k, Q10 - Q11 ); /* Q10 */ core_switch_lb_upsamp_fx( st_fx, output_fx ); } @@ -1539,7 +496,7 @@ ivas_error core_switching_post_dec_ivas_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = - Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ + Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -1557,7 +514,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 +545,7 @@ ivas_error core_switching_post_dec_ivas_fx( FOR( i = 0; i < delta; i++ ) { st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] = - Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */ + Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */ move32(); IF( LT_16( alpha, sub( 32767, tmp ) ) ) { @@ -1605,6 +561,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,9 +607,10 @@ ivas_error core_switching_post_dec_ivas_fx( hHQ_core->Q_old_wtda = Qtmp; move16(); } - IF( output_mem_fx != NULL ) + Word16 output_mem_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )]; + IF( output_mem_fx32 != NULL ) { - Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */ + 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 } *Qsynth = Qtmp; move16(); @@ -1723,6 +681,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 +801,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 +876,7 @@ ivas_error core_switching_post_dec_ivas_fx( return error; } + /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * @@ -1993,9 +960,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 +1046,26 @@ static void core_switch_lb_upsamp_fx( no_col = s_min( no_col, temp ); } - Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( L_FRAME48k, imult1616( no_col, st->cldfbSyn->no_channels ) ), 4 - 10 ); /* Q4 */ + 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 */ /* 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 */ + Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */ } + Scale_sig32( output, imult1616( no_col, st->cldfbSyn->no_channels ), Q11 - Q4 ); /* Q11 */ + 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 +1149,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 +1188,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 +1202,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 +1217,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 +1245,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 +1293,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 +1316,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 +1441,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 +1477,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 +1556,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 +1568,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 +1579,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 +1599,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 +1638,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 +1664,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 +1688,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 +1706,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 +1723,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 +1742,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 +1756,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 +1779,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 +1843,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 +1880,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 +1900,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 +1908,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 +1919,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 +1977,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 +1985,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 +2100,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/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index 4d1c101c05441b731f8d866b3d1b8e5cc92c40e3..c9a35c181692332fca1e9078f4f584dc7a0a28d4 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/dec2t32_fx.c b/lib_dec/dec2t32_fx.c index 71b284562a16e1b7ab05e9547303093f111cb285..77ded3a34da5976e506f7e771c248f70def3edf2 100644 --- a/lib_dec/dec2t32_fx.c +++ b/lib_dec/dec2t32_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -8,28 +8,28 @@ /*==========================================================================*/ -/* FUNCTION : void dec_acelp_2t32_fx () */ +/* FUNCTION : void dec_acelp_2t32_fx () */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * 12 bits algebraic codebook decoder. */ -/* * 2 track x 32 positions per track = 64 samples. */ -/* * 12 bits --> 2 pulses in a frame of 64 samples. */ -/* * All pulses can have two (2) possible amplitudes: +1 or -1. */ -/* * Each pulse can have 32 possible positions. */ -/* * See cod2t32.c for more details of the algebraic code. */ +/* PURPOSE : */ +/* * 12 bits algebraic codebook decoder. */ +/* * 2 track x 32 positions per track = 64 samples. */ +/* * 12 bits --> 2 pulses in a frame of 64 samples. */ +/* * All pulses can have two (2) possible amplitudes: +1 or -1. */ +/* * Each pulse can have 32 possible positions. */ +/* * See cod2t32.c for more details of the algebraic code. */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _Word16 i_subfr, i : subframe index */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*==========================================================================*/ void dec_acelp_2t32_fx( @@ -72,24 +72,24 @@ void dec_acelp_2t32_fx( } /*==========================================================================*/ -/* FUNCTION : void dec_acelp_1t64_fx () */ +/* FUNCTION : void dec_acelp_1t64_fx () */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : * 7 bits algebraic codebook. */ -/* * 1 track x 64 positions per track = 64 samples. */ +/* PURPOSE : * 7 bits algebraic codebook. */ +/* * 1 track x 64 positions per track = 64 samples. */ /* * The pulse can have 64 possible positions and two (2) possible amplitudes: +1 or -1.*/ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _Word16 i_subfr, i : subframe index */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*==========================================================================*/ void dec_acelp_1t64_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index ee6ef65a6ce3aa2b91e1020f51ad5f12405baa84..23313262ce1b2ac1f9c9e08a59df85e9114a1686 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -22,32 +22,32 @@ static void fcb_decode_PI_fx( Word32 code_index, Word16 sector_6p[], Word16 puls /*==========================================================================*/ -/* FUNCTION : void dec_acelp_4t64_fx () */ +/* FUNCTION : void dec_acelp_4t64_fx () */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * 20, 36 bits algebraic codebook decoder. */ -/* * 4 tracks x 16 positions per track = 64 samples. */ -/* * 20 bits --> 4 pulses in a frame of 64 samples. */ -/* * 36 bits --> 8 pulses in a frame of 64 samples. */ -/* * All pulses can have two (2) possible amplitudes: +1 or -1. */ -/* * Each pulse can have sixteen (16) possible positions. */ -/* * See cod4t64.c for more details of the algebraic code. */ +/* PURPOSE : */ +/* * 20, 36 bits algebraic codebook decoder. */ +/* * 4 tracks x 16 positions per track = 64 samples. */ +/* * 20 bits --> 4 pulses in a frame of 64 samples. */ +/* * 36 bits --> 8 pulses in a frame of 64 samples. */ +/* * All pulses can have two (2) possible amplitudes: +1 or -1. */ +/* * Each pulse can have sixteen (16) possible positions. */ +/* * See cod4t64.c for more details of the algebraic code. */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _Word16 i_subfr i : subframe index */ /* _Word16 nbbits i : number of bits per codebook */ /* _Word16 FCB_5Sx4T_fla i : 5Sx4Track flag for PI */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ +/* OUTPUT ARGUMENTS : */ +/* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ /* _Word16 index_buf_4T[] o : 5Sx4Track buffer for PI */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*==========================================================================*/ void dec_acelp_4t64_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -871,8 +871,6 @@ void dec_acelp_fast_fx( move16(); set16_fx( code, 0, L_subfr ); - st->total_num_bits = extract_l( st->total_brate / FRAMES_PER_SEC ); - IF( EQ_16( L_subfr, L_SUBFR ) ) { config = PulseConfTable[cdk_index]; diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 6a06df2678b6e665c8bc76554d4def55120bf8da..0bc96a369d3551a2a9e869b5b34e8a8e4a82bbb6 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -36,11 +36,7 @@ void decoder_LPD_fx( ) { Word16 *param_lpc; -#ifdef FIX_1320_STACK_CPE_DECODER Word16 synth_buf[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M]; -#else - Word16 synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; -#endif Word16 *synth; Word16 synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB; @@ -118,11 +114,7 @@ void decoder_LPD_fx( synth = synth_buf + hTcxDec->old_synth_len; /*st->old_synth: Q_0*/ Copy( hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len ); -#ifdef FIX_1320_STACK_CPE_DECODER set16_fx( synth, 0, L_FRAME_PLUS_INTERNAL + M ); -#else - set16_fx( synth, 0, L_FRAME_PLUS + M ); -#endif synthFB = synth_bufFB + hTcxDec->old_synth_lenFB; Copy( hTcxDec->old_synthFB_fx, synth_bufFB, hTcxDec->old_synth_lenFB ); @@ -564,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 { @@ -935,19 +927,17 @@ void decoder_LPD_fx( Qexc = E_UTIL_f_preemph3( buf, st->preemph_fac, L_LP, &tmp, 1 ); autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); lag_wind( r_h, r_l, M, INT_FS_FX, LAGW_WEAK ); - E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_lev_dur_fx( 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 8453a16cf1e309bfee4336387e866b86300949a9..ac137b37c99be1174fcc91f5a549d265eeeff808 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*BASOp version info: This file is up to date with trunk rev. 39929 */ @@ -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_fx.c b/lib_dec/dec_acelp_fx.c index e7f8c98ce7332dc3283ce290c5851eca31e78850..c07ba25a64db73f54e71cdf00458f31cd56c889e 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 3ff22158846d47df64e98b4e00fcaf84eb034bd9..1eccbfeab0344714846a2e1d48fb2330596446d6 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -209,15 +209,14 @@ static void decode_frame_type_fx( Decoder_State *st ) /* Reconf Core */ mode_switch_decoder_LPD_fx( st, st->bwidth, st->total_brate, frame_size_index ); + /* Reconf CLDFB */ IF( NE_16( i_mult( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) { - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, 50 ) ); - - resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); IF( LE_16( st->L_frame, L_FRAME16k ) ) { - resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); } } IF( EQ_16( st->bwidth, NB ) ) @@ -480,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 c5b08a784c0f3fa6cd8fd63f925dbc23dc60c16e..af6c706f707b26fa9080b21007ba168478c7c1cc 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 53da3c36ad2a3f5d5a22780dfdd8b70f32881537..e1a3917df5d5f1e1885f1db2cc5c36e825e02ab5 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -46,7 +46,7 @@ ivas_error decod_gen_voic_fx( Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) @@ -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 5687f3b79073903ff34970148ea2cdeab3520cc2..5e02f9913af51236c2fd65bef4eb000879738288 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -1,9 +1,8 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #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 */ @@ -184,7 +183,6 @@ void transf_cdbk_dec_fx( test(); IF( st_fx->element_mode > EVS_MONO && ( st_fx->coder_type != INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { - // PMT("Fixed point taking accound of the scaling needs to be done here ") IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); @@ -199,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 * @@ -239,27 +238,27 @@ void transf_cdbk_dec_fx( } /*==========================================================================*/ -/* FUNCTION : Word16 gain_dequant_fx () */ +/* FUNCTION : Word16 gain_dequant_fx () */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * Returns decoded gain quantized between the specified */ -/* * range using the specified number of levels. */ +/* PURPOSE : */ +/* * Returns decoded gain quantized between the specified */ +/* * range using the specified number of levels. */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 index i: quantization index */ -/* Word16 min_val i : value of lower limit */ -/* Word16 max_val i : value of upper limit */ -/* Word16 bits i : number of bits to dequantize */ +/* INPUT ARGUMENTS : */ +/* Word16 index i: quantization index */ +/* Word16 min_val i : value of lower limit */ +/* Word16 max_val i : value of upper limit */ +/* Word16 bits i : number of bits to dequantize */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *expg o : */ +/* OUTPUT ARGUMENTS : */ +/* _Word16 *expg o : */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* Word16 gain Q0 */ +/* RETURN ARGUMENTS : */ +/* Word16 gain Q0 */ /*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*==========================================================================*/ Word16 gain_dequant_fx( /* o: decoded gain */ Word16 index, /* i: quantization index */ diff --git a/lib_dec/dec_nelp_fx.c b/lib_dec/dec_nelp_fx.c index fe882ffbc223da0e8ad788eaa2f5603090219d89..130b486ac70addbec3b8f18b9c6d35b67791e210 100644 --- a/lib_dec/dec_nelp_fx.c +++ b/lib_dec/dec_nelp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -17,8 +17,8 @@ /* _ (Word16[]) tmp_noise_fx : long term temporary noise energy */ /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe(Q6) */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ /* _ (Word16) bfi : frame error rate */ /*-----------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ @@ -29,11 +29,11 @@ /* _ (Word16[]) tmp_noise_fx : long term temporary noise energy (Q0) */ /* _ (Word16[]) pitch_buf_fx : floating pitch values for each - subframe (Q6) */ + subframe (Q6) */ /* _ (Word16[]) st_fx->dispMem : Noise enhancer - phase dispersion - algorithm memory (Q14) */ -/* _ (Word16) st_fx->tilt_code : tilt of code (Q15) */ -/* _ (Word16) st_fx->prev_gain_pit_dec */ + algorithm memory (Q14) */ +/* _ (Word16) st_fx->tilt_code : tilt of code (Q15) */ +/* _ (Word16) st_fx->prev_gain_pit_dec */ /*-----------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index ad80b53f8d27e3de7c0b4ee9a7c3201f3b6d14e4..83818d1c9aae785f8534622fa770f1b6dc283cc1 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -8,26 +8,26 @@ #include "prot_fx.h" /* Function prototypes */ /*==========================================================================*/ -/* FUNCTION : void dec_pit_exc_fx() */ +/* FUNCTION : void dec_pit_exc_fx() */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : Decode pitch only contribution */ +/* PURPOSE : Decode pitch only contribution */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ +/* _ (Word16) coder_type : coding type Q0 */ /* _ (Word16) nb_subfr_fx :Number of subframe considered */ /* _ (Word16) Es_pred_fx :predicted scaled innov. energy */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation Q12 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ +/* _ (Word16*) code_fx : innovation Q12 */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /* Decoder_State_fx *st_fx : decoder state structure */ -/* _ (Word16*) exc_fx : adapt. excitation exc */ +/* _ (Word16*) exc_fx : adapt. excitation exc */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==========================================================================*/ void dec_pit_exc_fx( @@ -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 7c1e949cafbbe6f74bc782e2b6c27b78303719aa..1a568cbf9a109fabc600841fc3ed3afab2f9aad7 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" @@ -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_ppp_fx.c b/lib_dec/dec_ppp_fx.c index 4b3f4f554ec8100ae08fb5f6f7bac0383f398224..37277b06fce12d2060d84f1abbe99342cdb8e94b 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -8,43 +8,43 @@ #include "prot_fx.h" /* Function prototypes */ /*===================================================================*/ -/* FUNCTION : void decod_ppp_fx () */ +/* FUNCTION : void decod_ppp_fx () */ /*-------------------------------------------------------------------*/ -/* PURPOSE : decode highly voiced frames using PPP */ +/* PURPOSE : decode highly voiced frames using PPP */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ const Word16 Aq_fx[] - Q12 12k8 Lp coefficient */ -/* _ Word16 bfi_fx - Q0 bad frame indicator */ +/* _ const Word16 Aq_fx[] - Q12 12k8 Lp coefficient */ +/* _ Word16 bfi_fx - Q0 bad frame indicator */ /*-------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ +/* _ Decoder_State_fx *st_fx: */ /* _ lastLgainD_fx - Q11 */ /* _ lastHgainD_fx - Q11 */ /* _ lasterbD_fx - Q13 */ /*-------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lsp_old_fx - Q15 */ -/* _ st_fx->dtfs_dec_xxxx */ -/* _ a nd b in st_fx->dtfs_dec_Q */ -/* rest all in Q0 */ +/* _ Decoder_State_fx *st_fx: */ +/* _ lsp_old_fx - Q15 */ +/* _ st_fx->dtfs_dec_xxxx */ +/* _ a nd b in st_fx->dtfs_dec_Q */ +/* rest all in Q0 */ /* _ gainp_ppp Q14 */ /* _ FadeScale_fx - Q15 */ /* _ tilt_code_fx - Q15 */ -/* _ prev_tilt_code_dec_fx - Q15 */ +/* _ prev_tilt_code_dec_fx - Q15 */ /* _ prev_gain_pit_dec_fx - Q14 */ /* _ dm_fx.prev_state - Q0 */ /* _ dm_fx.prev_gain_code - Q16 */ /* _ .dm_fx.prev_gain_pit - Q14 */ -/* _ prev_gain_pit_dec - Q14 */ -/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ -/* _ Word16 *exc_fx - Q_exc current non-enhanced excitation */ -/* _ Word16 *exc2_fx - Q_exc current enhanced excitation */ +/* _ prev_gain_pit_dec - Q14 */ +/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ +/* _ Word16 *exc_fx - Q_exc current non-enhanced excitation */ +/* _ Word16 *exc2_fx - Q_exc current enhanced excitation */ /*-------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ -/* _ None */ +/* _ None */ /*-------------------------------------------------------------------*/ -/* CALLED FROM : RX */ +/* CALLED FROM : RX */ /*===================================================================*/ ivas_error decod_ppp_fx( @@ -54,7 +54,7 @@ ivas_error decod_ppp_fx( Word16 *exc_fx, /* i/o: current non-enhanced excitation */ Word16 *exc2_fx, /* i/o: current enhanced excitation */ Word16 bfi, /* i : bad frame indicator */ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ Word16 *voice_factors, /* o : voicing factors */ Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ ) diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index 16e588396b547fb2f56c6e88a6f44d616bbed3bc..420c20dbfb65afb13addc582fa0acac280d00d82 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -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 ) ) { @@ -394,7 +394,13 @@ void getTCXparam_fx( } ELSE { +#ifdef HARMONIZE_READ_DECODE_TNS + + ReadTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); +#else + ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); +#endif // HARMONIZE_READ_DECODE_TNS } hTcxDec->tnsActive[k] = 0; // Q0 move16(); @@ -1003,7 +1009,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 ) ) @@ -1351,7 +1357,11 @@ void dec_prm_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) ); +#ifdef HARMONIZE_READ_DECODE_TNS + ReadTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); +#else ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); +#endif // HARMONIZE_READ_DECODE_TNS j = add( j, nTnsParams ); // Q0 } @@ -1675,8 +1685,13 @@ void dec_prm_fx( test(); test(); SetTnsConfig( st->hTcxCfg, 0, ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ); - +#ifdef HARMONIZE_READ_DECODE_TNS + ReadTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); +#else ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); +#endif // DEBUG + + j = add( j, nTnsParams ); } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a8db9f9cc43b08f7499839611e2dac97a8589c12..0b954c17c41712a68c250b803f9d1ea0431944ea 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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" @@ -82,12 +81,10 @@ void decoder_tcx_fx( Word16 L_spec_con; TCX_LTP_DEC_HANDLE hTcxLtpDec; TCX_DEC_HANDLE hTcxDec; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; Flag Carry = 0; move32(); move32(); -#endif temp_concealment_method = 0; move16(); @@ -300,11 +297,17 @@ void decoder_tcx_fx( IF( ( bfi == 0 ) && ( hTcxCfg->fIsTNSAllowed != 0 ) ) { cast16(); - +#ifdef HARMONIZE_READ_DECODE_TNS + fUseTns = (Word8) DecodeTnsData_fx( hTcxCfg->pCurrentTnsConfig, + prm_tns, + &tnsSize, + &tnsData ); +#else fUseTns = (Word8) DecodeTnsData( hTcxCfg->pCurrentTnsConfig, prm_tns, &tnsSize, &tnsData ); +#endif // HARMONIZE_READ_DECODE_TNS } ELSE { @@ -1078,6 +1081,8 @@ void decoder_tcx_fx( Word16 predictionGain; /* not counted */ predictionGain = 0; move16(); + Q_A_itf = 15; + move16(); FOR( j = startLine; j < endLine; j++ ) { @@ -2734,14 +2739,14 @@ static void TCX_MDCT_Inverse_qwin_fx( FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ + y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ move16(); } FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ + y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ move16(); } @@ -2750,7 +2755,7 @@ static void TCX_MDCT_Inverse_qwin_fx( Word16 f; f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); - y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ move16(); y[l + m + R2 - 1 - i] = f; move16(); @@ -2800,13 +2805,13 @@ static void TCX_MDST_Inverse_qwin_fx( FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ move16(); } FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ move16(); } @@ -2885,12 +2890,12 @@ static void TCX_MDXT_Inverse_qwin_fx( FOR( i = 0; i < L2; i++ ) { - y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end exp(fac_e)*/ + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end exp(fac_e)*/ } FOR( i = 0; i < R2; i++ ) { - y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end exp(fac_e)*/ + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end exp(fac_e)*/ move16(); } @@ -2899,7 +2904,7 @@ static void TCX_MDXT_Inverse_qwin_fx( f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); - y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ move16(); y[l + m + R2 - 1 - i] = f; @@ -3972,14 +3977,9 @@ void decoder_tcx_ivas_fx( Word16 prm[], Word16 A_fx[], // Q: 14 - norm_s(A_fx[0]) Word16 Aind[], // Q: 14 - norm_s(Aind[0]) -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Word16 synth_fx[], Word16 synthFB_fx[], Word16 *synth_q, -#else - Word16 synth_fx[], // Q_syn - Word16 synthFB_fx[], // Q_syn -#endif const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) @@ -4029,6 +4029,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 ); @@ -4050,8 +4051,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 ) @@ -4069,9 +4070,6 @@ void decoder_tcx_ivas_fx( move16(); q_winFB = st->Q_syn; move16(); -#ifndef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - assert( q_win == 0 ); -#endif Scale_sig( synth_fx, L_frame_glob, sub( q_win, st->Q_syn ) ); // Scaling to Q_syn Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_winFB, st->Q_syn ) ); // Scaling to Q_syn @@ -4080,17 +4078,12 @@ void decoder_tcx_ivas_fx( fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); /* Scaling up again */ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); q_min = s_min( q_min, st->Q_syn ); Scale_sig( synth_fx, L_frame_glob, sub( q_min, q_win ) ); Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_min, q_winFB ) ); *synth_q = q_min; -#else - Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); - Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_winFB ) ); -#endif // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); @@ -4213,7 +4206,12 @@ void decoder_tcx_invQ_fx( test(); IF( !bfi && hTcxCfg->fIsTNSAllowed ) { +#ifdef HARMONIZE_READ_DECODE_TNS + *fUseTns = DecodeTnsData_fx( hTcxCfg->pCurrentTnsConfig, prm_tns, &tnsSize, tnsData ); +#else *fUseTns = DecodeTnsData_ivas_fx( hTcxCfg->pCurrentTnsConfig, prm_tns, &tnsSize, tnsData ); +#endif // HARMONIZE_READ_DECODE_TNS + move16(); } ELSE @@ -4727,12 +4725,10 @@ void decoder_tcx_noisefilling_fx( Word32 total_brate; Word32 tmp32; Word16 *pInfoTCXNoise; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); Flag Carry = 0; move32(); -#endif total_brate = ( (Word16) EQ_16( st->element_mode, IVAS_CPE_MDCT ) ? st->element_brate : st->total_brate ); move32(); /*-----------------------------------------------------------------* @@ -5662,7 +5658,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 4bee037ef79bbf8673525ed0be6110a3f61922d4..20d5f4b22bfec94ffa76a46023927e9d4511f8bc 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -12,29 +12,27 @@ #define Q16_30 ( 30 << Q16 ) /*======================================================================*/ -/* FUNCTION : decod_tran_fx() */ +/* FUNCTION : decod_tran_fx() */ /*----------------------------------------------------------------------*/ -/* PURPOSE : Decode transition (TC) frames */ -/* */ +/* PURPOSE : Decode transition (TC) frames */ +/* */ /*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q12 */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ +/* GLOBAL INPUT ARGUMENTS : */ +/* _ (Struct) st_fx : decoder static memory */ +/* _ (Word16) L_frame_fx : length of the frame Q0 */ +/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ +/* _ (Word16) coder_type : coding type Q12 */ +/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ +/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ +/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ /*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ /*-----------------------------------------------------------------------*/ - - /*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*=======================================================================*/ void decod_tran_fx( @@ -89,6 +87,7 @@ void decod_tran_fx( move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10 + /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ @@ -120,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; @@ -144,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 { @@ -167,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 ); + 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_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 ); - - 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(); @@ -221,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 ) ) @@ -246,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 f1ba21979228b1e0634efef8bf139c511869fc4f..83e5666b4f44ad691d655fdaa355ce364695ff40 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -1,10 +1,12 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + 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 */ + + static void gain_dec_gacelp_uv_fx( Word16 index, /* i : Quantization index vector Q0 */ Word16 *code, /* i : algebraic code excitation Q9 */ @@ -26,17 +28,17 @@ static void gain_dec_gacelp_uv_fx( *-------------------------------------------------------------------*/ void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ Word16 *gain_buf ) { Word16 gain_pit_fx; /* Quantized pitch gain */ @@ -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 0bc7794dc7b8322b5e9f670b889945c80aebebdf..055f1325f884406f175cbf35e8ecc5d54ef82375 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 4be63062f666f69a378635d29c244b182a670ae1..9080fd5aa2693b1a960bedf79275a55cd42b6be2 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -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/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index d4f3daeb8f4e5c60cb1a2ca4656029f3d3471c54..7a5175fb857c49f66b166f2a4c6d1e3f567fd65e 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index 20408c23c8f53d4d3e6ae6a1313d82885dcb97a7..06e14650431b03a5e7fbc3e133b918e4a3119d9b 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*VERSIONINFO: File up to date with trunk rev. 39929*/ diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 2c197d23d2645f71fe02088996c11b3beef14b04..9c73fcdf621c51f911ec6caad69db369dac2e119 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -18,10 +18,8 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch /*Q16*/, Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i; Word64 W_acc; Word32 L_tmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL move32(); move32(); -#endif W_acc = 0; @@ -56,10 +54,8 @@ static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr /*Q0*/, Wor Word16 i, cnt, tmp16, tmp_e, tmp2_e; Word64 W_acc; Word32 L_tmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL move16(); move16(); -#endif W_acc = 0; @@ -105,11 +101,7 @@ void con_tcx_fx( Word16 pre_emph_buf; Word16 hp_filt[L_FIR_FER2]; Word16 alpha; -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Word16 tmp_deemph, gain, gainCNG, gain_inov, scf; -#else - Word16 tmp_deemph, gain, gainCNG, gain_inov; -#endif Word16 *pt_exc, *pt1_exc; Word16 Tc, tmpSeed; Word16 fUseExtrapolatedPitch; @@ -194,16 +186,10 @@ void con_tcx_fx( IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE mem = shl( synth[( -( ( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ -#else - mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ -#endif move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ -#endif st->Mode2_lp_gainc = L_deposit_l( 0 ); st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/ @@ -222,7 +208,7 @@ void con_tcx_fx( lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); /* Levinson Durbin */ - E_LPC_lev_dur( r_h, r_l, A_local, NULL, M, NULL ); + E_LPC_lev_dur_fx( r_h, r_l, A_local, NULL, M, NULL ); /* copy for multiple frame loss */ Copy( A_local, st->old_Aq_12_8_fx, M + 1 ); /*Q12*/ @@ -242,17 +228,11 @@ void con_tcx_fx( ELSE { /* apply pre-emphasis to the signal */ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ -#else - mem = synth[( -L_frame - 1 )]; /*Q0*/ -#endif move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ -#endif - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) @@ -782,9 +762,8 @@ void con_tcx_fx( * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; /*Q_syn*/ - Copy( synth - M, buf, M ); /*Q_syn*/ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness { scf = norm_s( tmp_deemph ); @@ -800,10 +779,6 @@ void con_tcx_fx( scf = 0; move16(); } -#else - new_Q = sub( Q_exc, 3 ); - new_Q = s_max( new_Q, -1 ); -#endif tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; @@ -814,8 +789,7 @@ void con_tcx_fx( move16(); Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness + IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness { if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) { @@ -829,9 +803,6 @@ void con_tcx_fx( } st->Q_syn_factor = 0; move16(); -#else - tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ -#endif st->Q_syn = Q_syn; move16(); diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 85cad33ee600fc8b6f629d43d1a6355a4987393a..efe8aa965db7cba30a334469326fa52d453b8cc2 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*This file is up to date with trunk rev 36531*/ diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 6fafb882af7de7721d889c8100c24690714fdad5..22224f35e2971f2f6f73905f26500b318529b930 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*This BASOP port is up to date with trunk rev. 36554*/ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 9d9a273ac96c0b554aa710fc4c8f817b99f8c1a1..8e28dc546dec062e6312996c594534b9c502bd0f 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index d0231395bfe12568540c4073b5ab68db4475bd5a..0fa4c43f34a472eba36ba7ac35e99ef6c7c13034 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include /* Debug prototypes */ @@ -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 @@ -370,7 +370,11 @@ ivas_error evs_dec_fx( ELSE IF( EQ_16( st_fx->extl, WB_BWE ) && st_fx->bws_cnt == 0 ) { /* WB BWE decoder */ +#ifdef HARM_FD_BWE + hb_synth_fx_exp = wb_bwe_dec_fx( st_fx, NULL, synth_fx, hb_synth_fx, 0, output_frame, voice_factors_fx, pitch_buf_fx, &Qpostd ); /*Q0*/ +#else hb_synth_fx_exp = wb_bwe_dec_fx( synth_fx, hb_synth_fx, output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); /*Q0*/ +#endif } /*---------------------------------------------------------------------* @@ -408,7 +412,7 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); + 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 IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) || @@ -843,7 +847,7 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); } } Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ @@ -1020,10 +1024,8 @@ ivas_error evs_dec_fx( /* check if the CLDFB works on the right sample rate */ IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) ) { - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); - - resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 0 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 0 ); } st_fx->cldfbSyn->bandsToZero = 0; @@ -1376,7 +1378,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 { @@ -1385,7 +1388,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 756a39e9b1d8b54f76c911ecaafeab3d8efaa845..471600ca384bdf57eb243d35a22f4ea120904fde 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1,19 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ -#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 */ - 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 @@ -587,10 +500,8 @@ Word16 ApplyFdCng_fx( Word16 lsp_cng[M]; HANDLE_FD_CNG_DEC hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL move16(); move16(); -#endif Word16 L_frame, last_L_frame; hFdCngDec = st->hFdCngDec; @@ -1184,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(); } } @@ -1795,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(); } } @@ -1873,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(); @@ -1896,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(); } } @@ -2510,7 +2421,6 @@ void generate_comfort_noise_dec_fx( /* Warning fix */ s = 0; move16(); - // PMTE(); /*IVAS CODE need to be added */ /* pointer initialization */ @@ -2865,8 +2775,8 @@ void generate_comfort_noise_dec_fx( E_UTIL_deemph2( NOISE_HEADROOM, - noise, /* I/O: signal Qx */ - preemph_fac, /* I: deemphasis factor Qx */ + noise, /* I/O: signal Qx */ + preemph_fac, /* I: deemphasis factor Qx */ N, /* I: vector size */ &tmp /* I/O: memory (signal[-1]) Qx */ ); @@ -2931,20 +2841,12 @@ void generate_comfort_noise_dec_ivas_fx( temp = 0; move16(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG c1 = Sqrt16( hFdCngCom->coherence_fx[0], &temp ); /*Q15 - temp*/ -#else - c1 = Sqrt16( hFdCngCom->coherence_fx, &temp ); /*Q15 - temp*/ -#endif - c1 = shl( c1, temp ); /*Q15*/ + c1 = shl( c1, temp ); /*Q15*/ temp = 0; move16(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx[0] ), &temp ); /*Q15 - temp*/ -#else - c2 = Sqrt16( sub( MAX_16, hFdCngCom->coherence_fx ), &temp ); /*Q15 - temp*/ -#endif - c2 = shl( c2, temp ); /*Q15*/ + c2 = shl( c2, temp ); /*Q15*/ temp = getScaleFactor32( fftBuffer, FFTLEN ); scale_sig32( fftBuffer, FFTLEN, temp ); /*Q31 - hFdCngCom->fftBuffer_exp + temp*/ @@ -2971,12 +2873,8 @@ void generate_comfort_noise_dec_ivas_fx( { test(); test(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG test(); IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT && NE_16( nchan_out, 1 ) ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) -#else - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) -#endif { rand_gauss_fx( &tmp1, seed, Q15 ); rand_gauss_fx( &tmp2, seed2, Q15 ); @@ -3012,7 +2910,6 @@ void generate_comfort_noise_dec_ivas_fx( } ptr_i = ptr_r + 1; /*Q31 - fftBuffer_exp*/ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( nchan_out, 1 ) ) { @@ -3149,66 +3046,6 @@ void generate_comfort_noise_dec_ivas_fx( } } -#else - FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) - { - /* Real part in FFT bins */ - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) - { - rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ - rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ - *ptr_r = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ - move32(); - fftBuffer_temp_exp[idx] = Q16; - move16(); - } - ELSE - { - rand_gauss_fx( ptr_r, seed, Q15 ); /*Q15*/ - fftBuffer_temp_exp[idx] = Q16; - move16(); - } - - sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ - ( *ptr_r ) = Mpy_32_32( ( *ptr_r ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ - move32(); - fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); - move16(); - idx = add( idx, 1 ); - ptr_r += 2; - - /* Imaginary part in FFT bins */ - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) - { - rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ - rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ - *ptr_i = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); /*Q15*/ - move32(); - fftBuffer_temp_exp[idx] = Q16; - move16(); - } - ELSE - { - rand_gauss_fx( ptr_i, seed, Q15 ); /*Q15*/ - fftBuffer_temp_exp[idx] = Q16; - move16(); - } - sqrtNoiseLevel_exp = sub( cngNoiseLevel_exp, 1 ); - sqrtNoiseLevel = Sqrt32( *ptr_level, &sqrtNoiseLevel_exp ); /*Q31 - sqrtNoiseLevel_exp*/ - ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), sqrtNoiseLevel ); /*Q15 - sqrtNoiseLevel_exp*/ - move32(); - fftBuffer_temp_exp[idx] = add( fftBuffer_temp_exp[idx], sqrtNoiseLevel_exp ); - move16(); - idx = add( idx, 1 ); - ptr_i += 2; - } -#endif - /* Remaining FFT bins are set to zero */ set32_fx( fftBuffer + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); set16_fx( fftBuffer_temp_exp + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); @@ -3318,12 +3155,10 @@ void generate_comfort_noise_dec_ivas_fx( /* Generate Gaussian random noise in real and imaginary parts of the CLDFB bands Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each band */ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* * Note: for the stereo DTX noise mixing, c1 and c2 at this point are set to the value calculated for the last band * as all the coherence bands are in the FFT region, we do not need the special handling here */ -#endif test(); IF( bufferReal != NULL && ( LT_16( hFdCngCom->numCoreBands, hFdCngCom->regularStopBand ) ) ) @@ -3340,12 +3175,8 @@ void generate_comfort_noise_dec_ivas_fx( FOR( i = 0; i < hFdCngCom->numSlots; i++ ) { /* Real part in CLDFB band */ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG test(); IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( nchan_out, 1 ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) -#else - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) -#endif { rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ @@ -3368,12 +3199,8 @@ void generate_comfort_noise_dec_ivas_fx( move16(); /* Imaginary part in CLDFB band */ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG test(); IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( nchan_out, 1 ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) -#else - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && st->cng_ism_flag ) ) -#endif { rand_gauss_fx( &tmp1, seed, Q15 ); /*Q15*/ rand_gauss_fx( &tmp2, seed2, Q15 ); /*Q15*/ @@ -3584,8 +3411,8 @@ void generate_comfort_noise_dec_ivas_fx( E_UTIL_deemph2( NOISE_HEADROOM, - noise, /* I/O: signal Qx */ - preemph_fac, /* I: deemphasis factor Qx */ + noise, /* I/O: signal Qx */ + preemph_fac, /* I: deemphasis factor Qx */ N, /* I: vector size */ &tmp /* I/O: memory (signal[-1]) Qx */ ); @@ -3720,21 +3547,13 @@ void generate_comfort_noise_dec_hf_ivas_fx( s = 0; move16(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG c1 = Sqrt16( hFdCngCom->coherence_fx[sub( MDCT_ST_DTX_NUM_COHERENCE_BANDS, 1 )], &s ); /*Q15 - s*/ -#else - c1 = Sqrt16( hFdCngCom->coherence_fx, &s ); /*Q15 - s*/ -#endif - c1 = shl( c1, s ); // Q15 + c1 = shl( c1, s ); // Q15 s = 0; move16(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx[sub( MDCT_ST_DTX_NUM_COHERENCE_BANDS, 1 )] ), &s ); /*Q15 - s*/ -#else - c2 = Sqrt16( sub( MAX16B, hFdCngCom->coherence_fx ), &s ); /*Q15 - s*/ -#endif - c2 = shl( c2, s ); // Q15 + c2 = shl( c2, s ); // Q15 } sn = 0; @@ -3839,8 +3658,6 @@ void generate_masking_noise_fx( Word32 *fftBuffer; Word16 *seed; - // PMTE(); /*IVAS CODE need to be added */ - /* pointer initializations */ cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ fftBuffer = hFdCngCom->fftBuffer; /*Q31 - hFdCngCom->fftBuffer_exp*/ @@ -3977,8 +3794,6 @@ void generate_masking_noise_fx( assert( hFdCngCom->olapBufferSynth2 != NULL ); SynthesisSTFT( hFdCngCom->fftBuffer, fftBufferExp, maskingNoise, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, 0, NULL, -1 /*st->element_mode*/, -1 /*nchan_out*/ ); - // PMT("parameters need update") - /* add some comfort noise on top of decoded signal */ IF( hFdCngCom->frameSize > length ) @@ -4054,7 +3869,6 @@ void generate_masking_noise_mdct_fx( Word32 *cngNoiseLevel; Word16 *seed; - // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); @@ -4215,7 +4029,6 @@ void generate_masking_noise_mdct_ivas_fx( Word32 *cngNoiseLevel; Word16 *seed; - // PMTE(); /*IVAS CODE need to be added */ /* pointer initializations */ cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ seed = &( hFdCngCom->seed ); @@ -5172,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 */ @@ -5406,7 +5219,6 @@ void FdCngDecodeMDCTStereoSID_fx( Scale_sig32( ms_ptr_fx[ch], N, shift ); // Q20 } -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG tmp32 = sts[1]->total_brate; sts[1]->total_brate = L_add( sts[1]->total_brate, 800 /* 16 * FRAMES_PER_SEC */ ); /* read the four additional coherence values */ @@ -5419,9 +5231,6 @@ void FdCngDecodeMDCTStereoSID_fx( sts[1]->hFdCngDec->hFdCngCom->coherence_fx[b] = sts[0]->hFdCngDec->hFdCngCom->coherence_fx[b]; } sts[1]->total_brate = tmp32; -#else - dtx_read_padding_bits_fx( sts[1], mult( sub( IVAS_SID_5k2, 4400 ), ONE_BY_FRAMES_PER_SEC_Q15 ) ); -#endif IF( sts[0]->hFdCngDec->hFdCngCom->no_side_flag ) { @@ -5606,7 +5415,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac ); } -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG + FOR( i = 0; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ ) { sts[0]->hFdCngDec->hFdCngCom->coherence_fx[i] = 0; @@ -5615,13 +5424,6 @@ void FdCngDecodeDiracMDCTStereoSID_fx( move16(); } -#else - sts[0]->hFdCngDec->hFdCngCom->coherence_fx = 0; - move16(); - sts[1]->hFdCngDec->hFdCngCom->coherence_fx = 0; - move16(); -#endif - IF( EQ_16( hCPE->nchan_out, 1 ) ) { /* create proper M noise shape in channel zero after gains have been applied */ diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index e001521bf8c87f4b57d4899b2a366b76f8f4667f..551e04205f4030c9b5c74c55883e0f286a580299 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -9,24 +9,24 @@ /*===========================================================================*/ -/* FUNCTION : Es_pred_dec_fx() */ +/* FUNCTION : Es_pred_dec_fx() */ /*---------------------------------------------------------------------------*/ -/* PURPOSE : Decoding of scaled predicted innovation energy to be */ -/* used in all subframes */ +/* PURPOSE : Decoding of scaled predicted innovation energy to be */ +/* used in all subframes */ /*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) coder_type : coder type */ -/* _ (Word32) core_brate : core bitrate */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) coder_type : coder type */ +/* _ (Word32) core_brate : core bitrate */ /* _ (Word16*) Es_pred_qua_nb_fx : Gain quantization - quantization table */ -/* for scaled innovation energy prediciton Q8*/ +/* for scaled innovation energy prediciton Q8*/ /*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) Es_pred : predicited scaled innovation energy Q8 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) Es_pred : predicited scaled innovation energy Q8 */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*===========================================================================*/ void Es_pred_dec_fx( Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ @@ -35,9 +35,6 @@ void Es_pred_dec_fx( const Word16 no_ltp /* i : no LTP flag */ ) { -#ifdef IVAS_GAIN_MOD - PMT( "Verify if Es_pred_dec_fx should use noltp parameters" ) -#endif IF( no_ltp == 0 ) { SWITCH( nb_bits ) @@ -66,30 +63,30 @@ void Es_pred_dec_fx( } } /*======================================================================================*/ -/* FUNCTION : void gain_dec_tc_fx () */ +/* FUNCTION : void gain_dec_tc_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 */ +/* 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 */ +/* 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 : */ +/* INPUT/OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*======================================================================================*/ void gain_dec_tc_fx( @@ -116,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 *-----------------------------------------------------------------*/ @@ -135,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*/ @@ -150,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 */ @@ -157,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(); + } } /*-----------------------------------------------------------------* @@ -182,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;*/ @@ -329,40 +219,40 @@ void gain_dec_tc_ivas_fx( } /*======================================================================================*/ -/* FUNCTION : gain_dec_mless_fx() */ +/* FUNCTION : gain_dec_mless_fx() */ /*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Decoding of pitch and codebook gains without updating long term energies */ +/* PURPOSE : Decoding of pitch and codebook gains without updating long term energies */ /*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate_fx : core bitrate */ -/* _ (Word16) L_frame_fx : length of the frame */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) i_subfr_fx : subframe index */ -/* _ (Word16) tc_subfr_fx : TC subframe index */ -/* _ (Word16*[]) code_fx : algebraic code excitation (Q12) */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy (Q8) */ +/* INPUT ARGUMENTS : */ +/* _ (Word32) core_brate_fx : core bitrate */ +/* _ (Word16) L_frame_fx : length of the frame */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) i_subfr_fx : subframe index */ +/* _ (Word16) tc_subfr_fx : TC subframe index */ +/* _ (Word16*[]) code_fx : algebraic code excitation (Q12) */ +/* _ (Word16) Es_pred_fx : predicted scaled innov. energy (Q8) */ /*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) gain_pit_fx : quantized pitch gain (Q14) */ -/* _ (Word32*) gain_code_fx : quantized codebook gain (Q16) */ -/* _ (Word16*) gain_inov_fx : gain of the innovation (used for normalization) (Q12) */ -/* _ (Word32*) norm_gain_code_fx : norm. gain of the codebook excitation (Q16) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) gain_pit_fx : quantized pitch gain (Q14) */ +/* _ (Word32*) gain_code_fx : quantized codebook gain (Q16) */ +/* _ (Word16*) gain_inov_fx : gain of the innovation (used for normalization) (Q12) */ +/* _ (Word32*) norm_gain_code_fx : norm. gain of the codebook excitation (Q16) */ /*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ - -/* _ None */ +/* _ None */ /*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*======================================================================================*/ + void gain_dec_mless_fx( - 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 */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ + 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 */ + const Word16 tc_subfr_fx, /* i : TC subframe index */ const Word16 *code_fx, /* i : algebraic code excitation */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ @@ -435,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 */ @@ -471,7 +362,6 @@ void gain_dec_mless_fx( qua_table_fx = gain_qua_mless_6b_fx; /*Q14*/ if ( st_fx->element_mode > EVS_MONO ) { - // PMT("gain_qua_mless_6b_stereo to fixed point") qua_table_fx = gain_qua_mless_6b_stereo_fx; /*Q14*/ } BREAK; @@ -533,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 *-----------------------------------------------------------------*/ @@ -545,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 */ @@ -576,30 +468,29 @@ void gain_dec_mless_fx( } /*==================================================================================*/ -/* FUNCTION : gain_dec_lbr_fx() */ +/* FUNCTION : gain_dec_lbr_fx() */ /*----------------------------------------------------------------------------------*/ -/* PURPOSE : Decoding of pitch and codebook gains in ACELP at 6.6 and 7.5 kbps */ +/* PURPOSE : Decoding of pitch and codebook gains in ACELP at 6.6 and 7.5 kbps */ /*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : core bitrate */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) i_subfr : subframe index */ -/* _ (Word16*[]) code_fx : algebraic excitation (Q12) */ +/* INPUT ARGUMENTS : */ +/* _ (Word32) core_brate : core bitrate */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) i_subfr : subframe index */ +/* _ (Word16*[]) code_fx : algebraic excitation (Q12) */ /*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) gain_pit_fx : quantized pitch gain (Q14) */ -/* _ (Word32*) gain_code_fx : quantized codebook gain (Q16) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) gain_pit_fx : quantized pitch gain (Q14) */ +/* _ (Word32*) gain_code_fx : quantized codebook gain (Q16) */ /* _ (Word16*) gain_inov_fx : gain of the innovation (used for normalization) (Q12) */ -/* _ (Word32*) norm_gain_code_fx : norm. gain of the codebook excitation (Q12) */ +/* _ (Word32*) norm_gain_code_fx : norm. gain of the codebook excitation (Q12) */ /*----------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ None */ /*----------------------------------------------------------------------------------*/ - -/* _ None */ +/* _ None */ /*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==================================================================================*/ void gain_dec_lbr_fx( @@ -622,7 +513,7 @@ void gain_dec_lbr_fx( Word16 expg, expg2, e_tmp, exp_gcode0, f_tmp, frac, tmp_fx; const Word16 *b_fx, *cdbk_fx = 0; /* Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode); */ + *gain_inov = 1.0f / (float)sqrt(Ecode); */ Word16 shift_L_subfr; shift_L_subfr = 6; move16(); // for *cdbk_fx @@ -656,6 +547,7 @@ void gain_dec_lbr_fx( * calculate prediction of gcode * search for the best codeword *-----------------------------------------------------------------*/ + test(); IF( i_subfr == 0 ) { @@ -704,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) @@ -781,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 */ @@ -819,7 +711,6 @@ void gain_dec_lbr_fx( if ( EQ_16( nBits, 7 ) ) { cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ - // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } /* calculate predicted gain */ @@ -855,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 */ @@ -886,13 +778,11 @@ void gain_dec_lbr_fx( n_pred = 8; move16(); - cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ IF( EQ_16( nBits, 7 ) ) { cdbk_fx = gp_gamma_4sfr_7b_fx; /*Q14*/ - // PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) } /* calculate predicted gain */ @@ -977,7 +867,7 @@ void gain_dec_lbr_fx( /* PURPOSE : Update of LP pitch and code gains (FEC) */ /* */ /*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _ (Word16) i_subfr : subframe number Q0 */ /* _ (Word16) gain_pit : Decoded gain pitch Q14 */ /* _ (Word32) norm_gain_code : Normalised gain code Q16 */ @@ -992,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 */ @@ -1125,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(); @@ -1203,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(); @@ -1253,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) @@ -1392,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*/ @@ -1410,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*/ @@ -1423,6 +1202,7 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Select the gain quantization table *-----------------------------------------------------------------*/ + nbits = 7; move16(); t_qua_gain = t_qua_gain7b_fx; @@ -1459,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 */ @@ -1481,6 +1262,7 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Decode code gain *-----------------------------------------------------------------*/ + qua_en = t_qua_gain[( index2 + 1 )]; move16(); @@ -1504,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 ); @@ -1523,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 802cc3b41038f32049ae632f56b2f476905625ba..0d38c40bcae3b2bb344d92d0a21cb4c379361fca 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -23,23 +23,23 @@ static void dec_2pos_fx( Word16 index, Word16 *ind1, Word16 *ind2, Word16 *sign1 * - find the excitation *---------------------------------------------------------------------*/ void gaus_dec_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* o : unvoiced excitation Q12 */ - Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ - Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ - Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ - Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ - Word16 *voice_fac, /* o : estimated voicing factor Q15 */ - Word16 *gain_pit, /* o : pitch gain Q14 */ - Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ - Word16 *exc, /* o : excitation signal frame */ - Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ - Word16 *exc2, /* o : Scaled excitation signal frame */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 i_subfr, /* i : subframe index */ + Word16 *code, /* o : unvoiced excitation Q12 */ + Word32 *L_norm_gain_code, /* o : gain of normalized gaussian excitation Q16 */ + Word16 *lp_gainp, /* i/o : lp filtered pitch gain(FER) Q14 */ + Word16 *lp_gainc, /* i/o : lp filtered code gain (FER) Q3 */ + Word16 *inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word16 *tilt_code, /* o : synthesis excitation spectrum tilt Q15 */ + Word16 *voice_fac, /* o : estimated voicing factor Q15 */ + Word16 *gain_pit, /* o : pitch gain Q14 */ + Word16 *pt_pitch_1, /* o : floating pitch buffer Q6 */ + Word16 *exc, /* o : excitation signal frame */ + Word32 *L_gain_code, /* o : gain of the gaussian excitation Q16 */ + Word16 *exc2, /* o : Scaled excitation signal frame */ Word16 *bwe_exc_fx, - Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ - Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ + Word16 *sQ_exc, /* i/o : Excitation scaling factor (Decoder state) */ + Word16 *sQsubfr /* i/o : Past excitation scaling factors (Decoder State) */ ) { Word16 i, exp, gain_code; @@ -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_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index 4a0bf352fab3e016e426fa83dbf34ed89d4259ee..326c2f91976fd0087b8b6bdc60edd852091dd4d1 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -76,8 +76,8 @@ static void NoiseFill_fx( static void Ener_per_band_fx( const Word16 exc_diff_fx[], /* i : target signal exp(exc_diff_exp)*/ - const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ - Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16*/ + const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ + Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16*/ ) { const Word16 *ptr16; @@ -172,10 +172,10 @@ static void Apply_gain_fx( *-------------------------------------------------------------------*/ static void normalize_spec_fx( - Word16 fac_up_fx, /* i : Core bitrate (Q8)*/ - Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8)*/ - const Word16 L_frame, /* i : Section lenght Q0*/ - const Word16 Q_out /* i : Q of fy_norm_fx[] */ + Word16 fac_up_fx, /* i : Core bitrate (Q8)*/ + Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8)*/ + const Word16 L_frame, /* i : Section lenght Q0*/ + const Word16 Q_out /* i : Q of fy_norm_fx[] */ ) { Word16 idx, j; @@ -211,7 +211,7 @@ static void gs_dec_amr_wb_fx( Word16 dct_out_fx[], /* o : dct of pitch only excitation Q_dct_out*/ Word16 Q_dct_out, /* o : Exponent of dct_out_fx */ const Word16 pitch_fx[], /* i : pitch buffer Q6*/ - const Word16 voice_fac, /* i : gain pitch Q15*/ + const Word16 voice_fac, /* i : gain pitch Q15*/ const Word16 clas, /* i : signal frame class Q0*/ const Word16 coder_type /* i : coder type Q0*/ ) @@ -340,33 +340,31 @@ static void gs_dec_amr_wb_fx( * unvoiced and audio signals (used only in AMR-WB IO mode) *-------------------------------------------------------------------*/ void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class Q0*/ - const Word16 coder_type, /* i : coder type Q0*/ - const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ - Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ const Word16 locattack, /* i : Flag for a detected attack Q0*/ Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ - const Word16 Q_syn, /* i : Synthesis scaling */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ - const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ - const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ - const Word16 last_coder_type /* i : Last coder_type Q0*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ ) { Word16 i, exp_a, exp_b, exp_diff, j; Word16 dct_exc_in_fx[L_FRAME], dct_exc_out_fx[L_FRAME]; Word16 Aq_orig[NB_SUBFR * ( M + 1 )], enr_LP_old, enr_LP_new; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif /*------------------------------------------------------------* * Condition to enter the section on excitation modification diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index a17ca6febc6d7d9d75e208bbad1b35fe0d75aa29..0338c76b8d5c343893751b028a3096437e946699 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -9,30 +9,30 @@ #include "prot_fx.h" #include "ivas_cnst.h" /*=========================================================================*/ -/* FUNCTION : void decod_audio_fx(); */ +/* FUNCTION : void decod_audio_fx(); */ /*-------------------------------------------------------------------------*/ -/* PURPOSE : Decode audio (AC) frames */ +/* PURPOSE : Decode audio (AC) frames */ /*-------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) Aq : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16[]) Aq : LP filter coefficient Q12 */ +/* _ (Word16) coder_type : coding type Q0 */ /* _(Word16) Q_exc :Q format of excitation */ /*-------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx : decoder memory structure */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ +/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ +/*-------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* Decoder_State *st_fx : decoder memory structure */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ +/*-------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*=========================================================================*/ void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ + Decoder_State *st_fx, /* i/o: decoder static memory */ Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ const Word16 *Aq, /* i : LP filter coefficient Q12*/ Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ @@ -41,7 +41,7 @@ void decod_audio_fx( Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ @@ -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 ); /*---------------------------------------------------------------* @@ -395,7 +400,6 @@ void decod_audio_fx( move16(); } } - // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ @@ -470,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 ); @@ -487,17 +490,19 @@ 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 *----------------------------------------------------------------------*/ - 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 ); + 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 ); /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -531,39 +536,40 @@ void decod_audio_fx( return; } + /*==========================================================================*/ -/* FUNCTION : void gsc_dec_fx () */ +/* FUNCTION : void gsc_dec_fx () */ /*--------------------------------------------------------------------------*/ /* PURPOSE : Generic audio signal decoder */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* _ (Word16) pit_band_idx : bin position of the cut-off frequency Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ +/* _ (Word16) coder_type : coding type Q0 */ /* _ (Word16) bits_used : Number of bit used before frequency Q Q0 */ /* _ (Word16) nb_subfr : Number of subframe considered Q0 */ -/* _ (Word16) Qexc : Q format of exc_dct_in */ +/* _ (Word16) Qexc : Q format of exc_dct_in */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx:Decoder State Structure */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* Decoder_State *st_fx:Decoder State Structure */ /* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Qexc*/ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ +/* RETURN ARGUMENTS : */ +/* _None */ /*==========================================================================*/ void gsc_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - const Word16 coder_type, /* i : coding type Q0*/ - Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ) @@ -596,6 +602,7 @@ void gsc_dec_fx( /*--------------------------------------------------------------------------------------* * Initialization *--------------------------------------------------------------------------------------*/ + bit = bits_used; move16(); @@ -656,14 +663,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(); @@ -850,10 +850,10 @@ void gsc_dec_fx( * Estimate noise level *--------------------------------------------------------------------------------------*/ - 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 ); + 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 ); exc_dct_in[0] = 0; move16(); @@ -861,13 +861,14 @@ void gsc_dec_fx( return; } + /*-------------------------------------------------------------------* * GSC_dec_init() * * Initialize GSC decoder state structure *-------------------------------------------------------------------*/ -void GSC_dec_init( +void GSC_dec_init_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { @@ -881,37 +882,11 @@ void GSC_dec_init( move16(); move16(); - set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME ); - set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME ); - set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); - set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN ); /*Q12*/ - - hGSCDec->last_ener_fx = 0; - move16(); - set16_fx( hGSCDec->last_bitallocation_band, 0, 6 ); - - hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - return; -} - -void GSC_dec_init_ivas_fx( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ -) -{ - hGSCDec->seed_tcx = 15687; /* Q0 */ - move16(); - hGSCDec->cor_strong_limit = 1; - move16(); - set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); - hGSCDec->noise_lev = NOISE_LEVEL_SP0; - move16(); set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k ); - hGSCDec->Last_GSC_pit_band_idx = 0; - move16(); - - set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k ); /*Q12*/ set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k ); + set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN16k ); + set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k ); /*Q12*/ + hGSCDec->last_ener_fx = 0; move16(); set16_fx( hGSCDec->last_bitallocation_band, 0, 6 ); diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index aa6c041cc8a32bd60ca02d6a60903c588a6d19f0..2efea77b0c58de186f43de7ca73af3df8a88e3b7 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -12,9 +12,9 @@ /* Huffman decoding for indices of quantized norms */ /*--------------------------------------------------------------------------*/ void hdecnrm_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* i : number of norms Q0*/ - Word16 *index ) /* o : indices of quantized norms Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 numNorms, /* i : number of norms Q0*/ + Word16 *index ) /* o : indices of quantized norms Q0*/ { Word16 i, j, k, n, m; Word16 temp; @@ -169,8 +169,8 @@ void hdecnrm_context_fx( void hdecnrm_resize_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs Q0*/ - Word16 *index /* (o) norm quantization index vector Q0*/ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ) { Word16 i, j, k, m; @@ -294,9 +294,9 @@ void huff_dec_fx( *--------------------------------------------------------------------------*/ void hdecnrm_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms Q0*/ - Word16 *index /* o : indices of quantized norms Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 N, /* i : number of norms Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ) { Word16 i, j, k, n, m; diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 06ab1d95af82ccc90b7c1d8d3810c860bfc29606..153b760804e41756ed7400e9d6731de8e8332579 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -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 ); @@ -79,15 +78,16 @@ 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*/ + 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*/ + 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,14 +119,15 @@ 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*/ - 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 */ + 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; @@ -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) - *-----------------------------------------------------------------*/ + L_tmp = Isqrt_lc( L_tmp, &exp1 ); + scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ - 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 */ + /*-----------------------------------------------------------------* + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz - *-----------------------------------------------------------------*/ + hp400_12k8_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); - /*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 ); - /* 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 ); + /*scale *= fac;*/ + tmp = mult_r( scale, tmp ); } - 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 */ - } - 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 ); + exp1 = add( exp1, 6 ); /* tmp exponent */ - p_Aq += ( M + 1 ); /* Q12 */ - } + ener = shr( ener, 1 ); /* to avoid the assertion in div_s() further*/ + exp2 = add( exp2, 1 ); - return; -} + tmp = div_s( ener, tmp ); + exp1 = sub( exp2, exp1 ); -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; - - /*-----------------------------------------------------------------* - * generate white noise vector - *-----------------------------------------------------------------*/ + scale = Sqrt16( tmp, &exp1 ); /* scale exponent = exp1 */ - Random_Fill( &hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3 ); /* 3 = Shift Right by 3 */ + /*-----------------------------------------------------------------* + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ - /* o: HF_exc in Q(-3) */ + hp400_12k8_ivas_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); - /*-----------------------------------------------------------------* - * 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 - - /*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 */ - - 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,12 +377,13 @@ 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*/ - Word16 mem[], /* i/o: memory (size=30) exp*/ - Word16 fact, /* i : multiply factor Q0*/ - Word16 exp /* i : Mem Exponent */ + Word16 signal[], /* i/o: signal Qx*/ + Word16 lg, /* i : length of input Q0*/ + Word16 mem[], /* i/o: memory (size=30) exp*/ + Word16 fact, /* i : multiply factor Q0*/ + Word16 exp /* i : Mem Exponent */ ) { Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; @@ -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,21 +517,21 @@ 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*/ - const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ + const Word16 *Aq, /* i : quantized Az : Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz : Q_exc*/ + Word16 *synth, /* i/o: synthesis signal at 12.8k : Q_syn*/ Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) Q0*/ - Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ - Word16 fmerit, /* i : classify parameter from FEC : Q14*/ + Word16 *synth_out, /* i/o: output signal at output Fs : Q_out*/ + Word16 fmerit, /* i : classify parameter from FEC : Q14*/ const Word16 *hf_gain, /* i : decoded HF gain Q0*/ - const Word16 *voice_factors, /* i : voicing factors : Q15*/ - const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ - const Word16 *lsf_new, /* i : ISF vector : Q2*/ + const Word16 *voice_factors, /* i : voicing factors : Q15*/ + const Word16 pitch_buf[], /* i : pitch buffer : Q5*/ + const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8*/ + const Word16 *lsf_new, /* i : ISF vector : Q2*/ const Word16 Q_exc, /* i : exc scaling */ const Word16 Q_out /* i : Q_syn2-1 */ ) @@ -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,20 +1076,22 @@ 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*/ - const Word16 Ap[], /* i : quantized Aq : Q12*/ - Word16 exc16k[], /* i : excitation at 16 kHz : qhf*/ + const Word32 core_brate, /* i : core bitrate : Q0*/ + const Word16 output_subfr, /* i : output sub-frame length : Q0*/ + const Word16 Ap[], /* i : quantized Aq : Q12*/ + Word16 exc16k[], /* i : excitation at 16 kHz : qhf*/ Word16 synth_out[], /* i/o: synthesis signal at output Fs : Q_out*/ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ - Word16 p_r, /* i : sub-frame gain : Q12*/ - Word16 HF_corr_gain, /* i : HF gain index : Q14*/ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ + Word16 p_r, /* i : sub-frame gain : Q12*/ + Word16 HF_corr_gain, /* i : HF gain index : Q14*/ Word16 til, /* Q14 */ Word16 voice_factors, /* Q14 */ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qexc*/ + const Word16 exc[], /* i : excitation at 12.8 kHz : Qexc*/ const Word16 Q_exc, /*exc scaling*/ const Word16 Q_out, /*synth_out scaling*/ Word16 qhf /*exc16k scaling*/ @@ -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,19 +1302,21 @@ 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*/ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ - Word16 Ap[], /* o : extended LPC coefficents, Q12*/ - Word16 *sub_gain, /* o : sub-frame gain, Q12*/ - Word16 tilt0, /* i : spectrum tilt, Q14*/ - Word16 tilt, /* i : spectrum tilt, Q13*/ - Word16 voice_factor /* i : voice factor, Q15*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ + Word16 Ap[], /* o : extended LPC coefficents, Q12*/ + Word16 *sub_gain, /* o : sub-frame gain, Q12*/ + Word16 tilt0, /* i : spectrum tilt, Q14*/ + Word16 tilt, /* i : spectrum tilt, Q13*/ + Word16 voice_factor /* i : voice factor, Q15*/ ) { @@ -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_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index 4bbe3c5bc06e392d746c60b807bdf084474cebed..d6df6e4f50103475295230f4c8012e7dabdc61ec 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index 06bf8289760e2f3d5f64f8d1a70f7be084b1844e..55c8bb8a0fe2fb4eaa0725531ba05bb89248dfdd 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index e30fb0ec22cc962b64d9c472ae20a9fd65bde639..8a8ee02361ab42ab4bf7b2fb0643df8a910beade 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -468,8 +468,8 @@ 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 ) + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ +) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; Word16 i, j, flag_uv, num_Sb, nb_sfm; @@ -484,15 +484,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 +504,15 @@ void ivas_hq_core_dec_fx( Word16 mdctWindowLength; Word16 mdctWindowLengthFB; Word16 tmp_e; - Word16 tmp_out[L_FRAME48k]; + Word16 output[L_FRAME16k]; + Word16 Q_output; + + Q_output = 0; + move16(); + *Q_synth = 0; + move16(); + st_fx->Q_syn_factor = 0; + move16(); /*-------------------------------------------------------------------------- * Initializations @@ -519,11 +525,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 +570,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 +623,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 +638,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 +663,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 +712,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) *--------------------------------------------------------------------------*/ @@ -862,7 +846,7 @@ void ivas_hq_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); /* q_wtda + 12 */ IF( !core_switching_flag ) { - st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ + st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ move16(); } } @@ -910,47 +894,10 @@ 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 ); } - *Q_output = Q_audio; + Q_output = Q_audio; 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 +920,7 @@ void ivas_hq_core_dec_fx( IF( st_fx->element_mode > EVS_MONO ) { /* LB synthesis for potential switch to ACELP */ - 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 ); + 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 ); } test(); test(); @@ -986,28 +933,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 +959,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 +982,13 @@ 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 */ - 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 */ - } + 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 ) ); + return; } diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 5011dcf86f35da45f47522514903eafdad35afd7..c00b7711d744a181a67d8f39de9df61b7badf672 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 27b352cd34e29cf546dd68ac15ff087d2f1a8311..30a7d4f4ae9ca4fc66f9917ef120cb2bf155e698 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -18,7 +18,7 @@ void ivas_hq_pred_hb_bws_fx( const Word16 *ynrm, /* i : norm quantization index vector Q0*/ const Word16 length, /* i : frame length Q0*/ const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -71,7 +71,7 @@ void hq_pred_hb_bws_fx( const Word16 *ynrm, /* i : norm quantization index vector Q0*/ const Word16 length, /* i : frame length Q0*/ const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -133,7 +133,7 @@ void ivas_hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag Q0 */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -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(); @@ -229,7 +230,7 @@ void ivas_hq_hr_dec_fx( hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure */ IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -399,7 +400,7 @@ void hq_hr_dec_fx( Word16 *is_transient, /* o : transient flag Q0 */ Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag Q0 */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -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 */ @@ -492,10 +494,10 @@ void hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ + hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ + bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index e8c7b365ebe4c3b019c777cd716f0f594bf16a49..3fe586a26d3bf9fc7a11127f7413c3ab695e4818 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -287,7 +287,7 @@ void hq_lr_dec_fx( exp_norm = norm_s( gqlevs_fx ); gqbits_fx = sub( 14, exp_norm ); /* Q0 */ - bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ + bit_budget_fx = sub( sub( num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ pbits_fx = 0; @@ -583,7 +583,7 @@ void hq_lr_dec_fx( } ELSE IF( *is_transient_fx == 0 && EQ_16( inner_frame, L_FRAME16k ) ) { - bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ FOR( i = 0; i < 2; i++ ) { @@ -884,12 +884,12 @@ void hq_lr_dec_fx( } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT Q12*/ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT Q12*/ } } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB Q12*/ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB Q12*/ } test(); @@ -928,10 +928,10 @@ void hq_lr_dec_fx( *--------------------------------------------------------------------------------------*/ static Word16 small_symbol_dec_tran_fx( - Decoder_State *st_fx, /* i/o: decoder state structure Q0*/ - Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ - const Word16 bands, /* i : number of bands Q0*/ - const Word16 is_transient /* i : transient flag Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure Q0*/ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { Word16 i, bits; @@ -1240,9 +1240,9 @@ static Word16 band_energy_dequant_fx( static Word16 p2a_threshold_dequant_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *p2a_flags, /* o : tonaly indicator Q0*/ - const Word16 bands, /* i : number of subbands Q0*/ - const Word16 p2a_bands /* i : number of subbnads for computing tonality Q0*/ + Word16 *p2a_flags, /* o : tonaly indicator Q0*/ + const Word16 bands, /* i : number of subbands Q0*/ + const Word16 p2a_bands /* i : number of subbnads for computing tonality Q0*/ ) { Word16 j, k; diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 686882fd3ed748598f9fb81d41058d6e384a3739..fba40748cd832d65b1b32a2a3ea0aac9ee6229a1 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 @@ -1483,10 +1483,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in Word16 dS_e[IGF_MAX_SFB]; Word32 energyTmp[24]; Word16 Hr; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL move16(); move16(); -#endif /* initialize variables */ @@ -1840,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(); @@ -2509,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(); @@ -4256,10 +4254,8 @@ void init_igf_dec( hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; -#ifdef FIX_1385_INIT_IGF_STOP_FREQ hIGFDec->infoIGFStopFreq = 0; move16(); -#endif return; } diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index 6478b3f92c60fc290385bd2e50e6df9c137494ca..a8aa13e73dbb8f46754bc72183918a2cc77c489f 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 7a89118c3b041bd77316c322d945cd0f125aead9..b8a5fe6de63c1dd49f8d29605942b44899021687 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -1,844 +1,58 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "basop_util.h" -#include "ivas_prot_fx.h" - -/*----------------------------------------------------------------------* - * init_decoder() - * - * Initialization of static variables for the decoder - *----------------------------------------------------------------------*/ - -ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan /* i : channel ID */ -) -{ - Word16 i; - ivas_error error; - - error = IVAS_ERR_OK; - move16(); - Word16 newCldfbBands; - st_fx->total_num_bits = -1; - move16(); - - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - - st_fx->codec_mode = MODE1; - move16(); - st_fx->last_codec_mode = MODE1; - move16(); - st_fx->core = ACELP_CORE; - move16(); - st_fx->L_frame = L_FRAME; - move16(); - st_fx->extl = -1; - move16(); - st_fx->total_brate = 8000; - move16(); - st_fx->last_total_brate = -1; - move16(); - st_fx->last_total_brate_ber = -1; - move32(); - st_fx->core_brate = 8000; - move16(); - st_fx->ini_frame = 0; - move16(); - st_fx->bwidth = NB; - move16(); - st_fx->extl_brate = 0; - move16(); - - - st_fx->last_coder_type = GENERIC; - move16(); - st_fx->last_L_frame = st_fx->L_frame; - move16(); - st_fx->last_core_brate = st_fx->core_brate; - move16(); - - st_fx->last_core = -1; - move16(); - st_fx->last_extl = st_fx->extl; - move16(); - - - /* LSF initilaizations */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - - set16_fx( st_fx->mem_MA_fx, 0, M ); - - st_fx->dm_fx.prev_state = 0; // Q0 - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); // Q16 - FOR( i = 2; i < 8; i++ ) - { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; // Q14 - move16(); - } - - st_fx->tilt_code_fx = 0; // Q15 - move16(); - st_fx->gc_threshold_fx = L_deposit_l( 0 ); // Q16 - st_fx->last_good = UNVOICED_CLAS; - move16(); - st_fx->clas_dec = UNVOICED_CLAS; - move16(); - - st_fx->lp_gainp_fx = 0; // Q14 - move16(); - st_fx->lp_gainc_fx = 0; // Q3 - move16(); - - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); // Q_exc - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); - - st_fx->mem_deemph_fx = 0; // Q_syn - move16(); - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); - } - - fd_bwe_dec_init_fx( st_fx->hBWE_FD ); - } - ELSE - { - st_fx->hBWE_FD = NULL; - } - - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); - } - - st_fx->igf = 0; - move16(); - init_igf_dec( st_fx->hIGFDec ); - } - ELSE - { - st_fx->hIGFDec = NULL; - } - - /*-----------------------------------------------------------------* - * HR SWB BWE parameters - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); - } - - hr_bwe_dec_init( st_fx->hBWE_FD_HR ); - } - ELSE - { - st_fx->hBWE_FD_HR = NULL; - } - set16_fx( st_fx->mem_syn1_fx, 0, M ); - set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; // Q15 - move16(); - st_fx->stab_fac_smooth_fx = 0; // Q15 - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); // Q0 - set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); - set16_fx( st_fx->mem_syn3_fx, 0, M ); - - - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - st_fx->mid_lsf_int = 0; - move16(); - st_fx->safety_net = 0; - move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - st_fx->last_voice_factor_fx = 0; // Q6 - move16(); - - - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); - } - - GSC_dec_init( st_fx->hGSCDec ); - } - ELSE - { - st_fx->hGSCDec = NULL; - } - - /*-----------------------------------------------------------------* - * parameters for fast recovery (WI) - *-----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); - } - - set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); - set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); - } - ELSE - { - st_fx->hWIDec = NULL; - } - - /* NB post-filter */ - /*-----------------------------------------------------------------* - * NB/formant post-filter - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); - } - - Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; // Q8 - move16(); - } - ELSE - { - st_fx->hPFstat = NULL; - } - st_fx->psf_lp_noise_fx = 0; // Q8 - move16(); - - /* FEC */ - st_fx->scaling_flag = 0; - move16(); - st_fx->lp_ener_FEC_av = 500000; // Q0 - move32(); - st_fx->lp_ener_FEC_max = 500000; // Q0 - move32(); - st_fx->prev_bfi = 0; - move16(); - st_fx->lp_ener_FER_fx = 15360; // Q8 - move16(); /*60 in Q8*/ - st_fx->old_enr_LP = 0; // Q5 - move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); // Q6 - st_fx->enr_old_fx = L_deposit_l( 0 ); // Q0 - st_fx->bfi_pitch_fx = L_SUBFR_Q6; - move16(); - st_fx->bfi_pitch_frame = L_SUBFR; - move16(); - set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - st_fx->last_con_tcx = 0; - move16(); - - FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; // Q16 - move32(); /*15Q16*/ - } - - st_fx->upd_cnt = MAX_UPD_CNT; - move16(); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - - st_fx->seed_acelp = RANDOM_INITSEED; - move16(); - st_fx->seed = RANDOM_INITSEED; - move16(); - st_fx->nbLostCmpt = 0; - move16(); - st_fx->decision_hyst = 0; - move16(); - - - /* Stationary noise UV modification */ - st_fx->unv_cnt = 0; - move16(); - st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ - st_fx->uv_count = 0; - move16(); - st_fx->act_count = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); // Q15 - st_fx->noimix_seed = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 32767; // Q15 - move16(); /*1; Q15*/ - st_fx->exc_pe_fx = 0; // Q_stat_noise - move16(); - st_fx->Q_stat_noise = 31; - move16(); - /*-----------------------------------------------------------------* - * LD music post-filter - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); - } - - music_postfilt_init( st_fx->hMusicPF ); - } - ELSE - { - st_fx->hMusicPF = NULL; - } - - /* CNG and DTX */ - test(); - test(); - test(); - IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) - { - IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); - } - - td_cng_dec_init_fx( st_fx ); - } - ELSE - { - st_fx->hTdCngDec = NULL; - } - st_fx->cng_type = -1; - move16(); - st_fx->first_CNG = 0; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); // Q15 - - st_fx->CNG_mode = -1; - move16(); - st_fx->last_active_brate = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame = L_FRAME; - move16(); - - - st_fx->last_vad_fx = 0; - move16(); - - /* HF (6-7kHz) BWE */ - move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; // Q of ge_sm_fx - move16(); - st_fx->cngTDLevel = 0; - move16(); - st_fx->cngTDLevel_e = 0; - move16(); - - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || ( st_fx->element_mode == EVS_MONO ) ) ) - { - IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); - } - - /* HQ core initialization */ - HQ_core_dec_init_fx( st_fx->hHQ_core ); - - IF( st_fx->element_mode == EVS_MONO ) - { - /* HQ NB FEC initialization */ - IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); - } - HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); - } - ELSE - { - st_fx->hHQ_nbfec = NULL; - } - } - ELSE - { - st_fx->hHQ_core = NULL; - st_fx->hHQ_nbfec = NULL; - } - st_fx->Qprev_synth_buffer_fx = 15; - move16(); - st_fx->old_bfi_cnt = 0; - move16(); - st_fx->prev_old_bfi = 0; - move16(); - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); - IF( st_fx->element_mode == EVS_MONO ) - { - set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); - } - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ - - /* TCX-LTP */ - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); - } - } - ELSE - { - st_fx->hTcxLtpDec = NULL; - } - - /* TCX core */ - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); - } - - set16_fx( st_fx->hTcxDec->FBTCXdelayBuf, 0, 111 ); - - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); - } - ELSE - { - st_fx->hTcxDec = NULL; - } - /* TCX config. data structure */ - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); - } - } - ELSE - { - st_fx->hTcxCfg = NULL; - } - - /* Tonal MDCT concealment data structure */ - - if ( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); - } - - st_fx->prev_coder_type = GENERIC; - move16(); - - move16(); - st_fx->tilt_wb_fx = 0; // Q11 - move16(); - - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); - st_fx->old_bwe_delay = -1; /*Q0*/ - move16(); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); - } - - td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); - - st_fx->prev_Q_bwe_exc = 31; - move16(); - } - ELSE - { - st_fx->hBWE_TD = NULL; - } - - st_fx->tilt_swb_fx = 0; // Q24 - move16(); - st_fx->tilt_wb_fx = 0; // Q11 - move16(); - - st_fx->prev_ener_shb_fx = 0; // Q1 - move16(); - st_fx->prev_enerLH_fx = 0; // Q1 - move16(); - st_fx->enerLH_fx = L_deposit_l( 0 ); - st_fx->enerLL_fx = L_deposit_l( 0 ); - st_fx->prev_enerLL_fx = 0; - move16(); - st_fx->prev_fractive = 0; - move16(); - st_fx->prev_bws_cnt = 0; - move16(); - st_fx->bws_cnt = N_WS2N_FRAMES; - move16(); - st_fx->bws_cnt1 = N_NS2W_FRAMES; - move16(); - st_fx->attenu_fx = 3277; // Q15 - move16(); - st_fx->last_inner_frame = L_FRAME8k; - move16(); - st_fx->last_bwidth = 0; - move16(); - - /*-----------------------------------------------------------------* - * channel-aware mode parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - - st_fx->use_partial_copy = 0; - move16(); - st_fx->prev_use_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - st_fx->rf_flag_last = 0; - st_fx->prev_rf_frame_type = 0; - move16(); - st_fx->next_coder_type = 0; - move16(); - - st_fx->rf_target_bits = 0; - move16(); - - st_fx->rf_indx_nelp_fid = 0; - move16(); - st_fx->rf_indx_nelp_iG1 = 0; - move16(); - st_fx->rf_indx_nelp_iG2[0] = 0; - move16(); - st_fx->rf_indx_nelp_iG2[1] = 0; - move16(); - st_fx->rf_indx_tbeGainFr = 0; - move16(); - - /*----------------------------------------------------------------------------------* - * AMR-WB IO mode parameters - *----------------------------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); - } - - /* AMR-WB IO init */ - amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); - - /* AMR-WB IO HF synth init */ - hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); - } - ELSE - { - st_fx->hAmrwb_IO = NULL; - } - /*-----------------------------------------------------------------* - * HF (6-7kHz) (zero) BWE parameters - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); - } - - hf_synth_init_fx( st_fx->hBWE_zero ); - /* TBV Hack for bit exactness with 26.452, Issue should be corrected there as the the reset is not perform on all values of mem_hp400_fx*/ - set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); - } - ELSE - { - st_fx->hBWE_zero = NULL; - } - - /* HF synth init */ - hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); - - - st_fx->bpf_off = 0; - move16(); - /*-----------------------------------------------------------------* - * Bass post-filter parameters - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); - } - - bass_psfilter_init_fx( st_fx->hBPF ); - } - ELSE - { - st_fx->hBPF = NULL; - } - /*-----------------------------------------------------------------* - * FD BPF & resampling tools parameters - *-----------------------------------------------------------------*/ - /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ), IVAS_ERR_OK ) ) - { - return error; - } - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move32(); - st_fx->last_active_bandsToZero_bwdec = 0; - st_fx->perc_bwddec = 0; - st_fx->last_flag_filter_NB = 0; - st_fx->active_frame_cnt_bwddec = 0; - st_fx->total_frame_cnt_bwddec = 0; - set16_fx( st_fx->flag_buffer, 0, 20 ); - st_fx->avg_nrg_LT = 0; - - st_fx->Ng_ener_ST_fx = -13056; - move16(); /*-51 IN Q8*/ - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); /*1 in Q12*/ - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); - } - - sc_vbr_dec_init( st_fx->hSC_VBR ); - } - ELSE - { - st_fx->hSC_VBR = NULL; - } - - st_fx->last_ppp_mode_dec = 0; - move16(); - st_fx->old_ppp_mode = 0; - move16(); - st_fx->ppp_mode_dec = 0; - move16(); - st_fx->last_nelp_mode_dec = 0; - move16(); - st_fx->nelp_mode_dec = 0; - move16(); - st_fx->prev_gain_pit_dec_fx = 0; - move16(); - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - st_fx->vbr_hw_BWE_disable_dec = 0; - move16(); - st_fx->last_vbr_hw_BWE_disable_dec = 0; - move16(); - - /*-----------------------------------------------------------------* - * Mode 2 initialization - *-----------------------------------------------------------------*/ - - IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); - } - - st_fx->enablePlcWaveadjust = 0; - move16(); - - /* Init Decoder */ - open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); - - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - st_fx->m_old_frame_type = ACTIVE_FRAME; - move16(); - - - newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); - - resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 1 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 1 ); - - test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) - { - /* Create FD_CNG instance */ - - IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* Init FD-CNG */ - initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); - } - ELSE - { - st_fx->hFdCngDec = NULL; - } - - st_fx->lp_noise = -167772160l /*-20.f Q23*/; - move32(); - st_fx->force_lpd_reset = 0; - move16(); - - /*-----------------------------------------------------------------* - * initialzie Q values - *-----------------------------------------------------------------*/ - - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_exc = 8; - st_fx->prev_Q_exc = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - st_fx->prev_Q_syn = 0; - move16(); - - FOR( i = 0; i < L_Q_MEM; i++ ) - { - st_fx->Q_subfr[i] = 8; - move16(); - } - - st_fx->prev_Q_exc_fr = 0; - move16(); - st_fx->prev_Q_syn_fr = 0; - move16(); - - /*----------------------------------------------------------------------------------* - * Stereo/IVAS parameters - *----------------------------------------------------------------------------------*/ - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - move16(); - st_fx->element_mode = EVS_MONO; /* element mode */ - move16(); - st_fx->element_brate = -1; /* element bitrate */ - move16(); - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - move16(); - st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ - move16(); +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ -#ifdef DEBUGGING - st_fx->id_element = -1; /* element ID */ -#endif - st_fx->extl_orig = -1; /* extension layer */ - move16(); - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ - move16(); +/*==================================================================================== + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 + ====================================================================================*/ - return error; -} +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "stl.h" /* required for wmc_tool */ +#include "basop_util.h" +#include "ivas_prot_fx.h" /*----------------------------------------------------------------------* - * init_decoder_ivas_fx() + * init_decoder() * - * Initialization of static variables for the IVAS decoder + * Initialization of static variables for the decoder *----------------------------------------------------------------------*/ -ivas_error init_decoder_ivas_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan, /* i : channel ID */ - const MC_MODE mc_mode /* i : MC mode */ +ivas_error init_decoder_fx( + Decoder_State *st_fx, /* o : Decoder static variables structure */ + const Word16 idchan, /* i : channel ID */ + const MC_MODE mc_mode /* i : MC mode */ ) { Word16 i; @@ -877,12 +91,23 @@ ivas_error init_decoder_ivas_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; @@ -1072,7 +297,7 @@ ivas_error init_decoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init_ivas_fx( st_fx->hGSCDec ); + GSC_dec_init_fx( st_fx->hGSCDec ); } ELSE { @@ -1098,10 +323,10 @@ ivas_error init_decoder_ivas_fx( st_fx->hWIDec = NULL; } - /* NB post-filter */ /*-----------------------------------------------------------------* * NB/formant post-filter *-----------------------------------------------------------------*/ + test(); test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) @@ -1144,6 +369,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * LD music post-filter *-----------------------------------------------------------------*/ + test(); test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) @@ -1210,7 +436,6 @@ ivas_error init_decoder_ivas_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 ) { @@ -1418,32 +643,56 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + + IF( st_fx->element_mode == EVS_MONO ) { /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) { return error; } /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - st_fx->cldfbAna = NULL; - st_fx->cldfbBPF = NULL; - } + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + /* open analysis for max. SR 48kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) - { - return error; + /* open analysis BPF for max. SR 16kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + st_fx->cldfbAna = NULL; + st_fx->cldfbBPF = NULL; + } + + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } } st_fx->cldfbSynHB = NULL; @@ -1604,6 +853,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * Mode 2 initialization *-----------------------------------------------------------------*/ + IF( ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) @@ -1628,18 +878,24 @@ ivas_error init_decoder_ivas_fx( st_fx->hTECDec = NULL; } - /* Init Decoder */ - Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); + IF( st_fx->element_mode == EVS_MONO ) + { + open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); + } + ELSE + { + Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); + } /* PLC mode initialization */ st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; @@ -1651,11 +907,19 @@ ivas_error init_decoder_ivas_fx( st_fx->m_old_frame_type = ACTIVE_FRAME; move16(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( st_fx->element_mode == EVS_MONO ) { - resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + } + ELSE + { + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + } } /*-----------------------------------------------------------------* @@ -1668,14 +932,13 @@ ivas_error init_decoder_ivas_fx( IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { /* Create FD_CNG instance */ - IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } /* Init FD-CNG */ - initFdCngDec_ivas_fx( st_fx, st_fx->cldfbSyn->scale ); + initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); } ELSE { @@ -1740,6 +1003,7 @@ ivas_error init_decoder_ivas_fx( * * Initialization of static variables for pre-echo *----------------------------------------------------------------------*/ + void reset_preecho_dec_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) @@ -1771,34 +1035,13 @@ void destroy_cldfb_decoder_fx( Decoder_State *st_fx /* o: Decoder static variables structure */ ) { - /* CLDFB BPF & resampling tools */ - - /* delete analysis for max. SR 16kHz */ - deleteCldfb( &st_fx->cldfbAna ); - - /* delete analysis BPF for max. SR 16kHz */ - deleteCldfb( &st_fx->cldfbBPF ); - - /* delete synthesis for output SR */ - deleteCldfb( &st_fx->cldfbSyn ); + deleteCldfb_fx( &st_fx->cldfbAna ); /* delete analysis for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbSyn ); /* delete synthesis for output SR */ + deleteCldfb_fx( &st_fx->cldfbSynHB ); deleteFdCngDec_fx( &st_fx->hFdCngDec ); return; } - -void destroy_cldfb_decoder_ivas_fx( - Decoder_State *st /* o : Decoder static variables structure */ -) -{ - /* CLDFB BPF & resampling tools */ - deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ - deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ - deleteCldfb_ivas_fx( &st->cldfbSyn ); /* delete synthesis at output sampling rate */ - deleteCldfb_ivas_fx( &st->cldfbSynHB ); - - deleteFdCngDec_fx( &st->hFdCngDec ); - - return; -} diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 1ab1efe8fa8c587a2494997818d9694b6cc63a71..21e70e083045a138a72ac4a8a909e9654abe63c4 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -13,7 +13,7 @@ /* PURPOSE : Decode the algebraic innovation and do pitch sharpening */ /* */ /*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* 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 */ @@ -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 ae955c5edb8e8abb653d57d33c6706d95c93ce28..5a208446f04a1724fe1d1493f14478cdbf6b1217 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,23 +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; -#ifdef FIX_1320_STACK_CPE_DECODER Word16 flag_bwe_bws, flaf_swb_tbe; Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL }; -#else - Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; -#endif - 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]; @@ -105,16 +93,10 @@ ivas_error ivas_core_dec_fx( ivas_error error; Word32 L_tmp; Word16 Q_synth; - Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; 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; @@ -122,6 +104,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 *-----------------------------------------------------------------*/ @@ -294,11 +281,10 @@ ivas_error ivas_core_dec_fx( } set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); + set32_fx( output_32_fx[n], 0, L_FRAME48k ); set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); -#ifdef FIX_1320_STACK_CPE_DECODER bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ -#endif /*------------------------------------------------------------------* * Decision matrix (selection of technologies) @@ -447,7 +433,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 @@ -460,9 +446,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; } @@ -481,23 +465,9 @@ ivas_error ivas_core_dec_fx( * HQ core decoding *---------------------------------------------------------------------*/ - set16_fx( output_16_fx[n], 0, L_FRAME48k ); /* this is needed for instances like L_norm_arr( p_output_fx[i], L_FRAME48k ) */ - IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ - Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; - Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; - - IF( save_hb_synth_32_fx ) - { - save_hb_synth_16_fx = save_hb_synth_fx_arr; - } - ELSE - { - save_hb_synth_16_fx = NULL; - } - IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, Q11 - Q10 ); // Q11 @@ -522,7 +492,12 @@ ivas_error ivas_core_dec_fx( Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); // Qx } -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_32( st->last_core, TCX_10_CORE ) || EQ_32( st->last_core, TCX_20_CORE ) ) || // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized ( hCPE != NULL && ( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( ( EQ_32( sts[0]->last_core, TCX_10_CORE ) || EQ_32( sts[0]->last_core, TCX_20_CORE ) ) ) ) ) ) // In this case, sts[1] gets its value from sts[0]. { @@ -531,14 +506,12 @@ ivas_error ivas_core_dec_fx( } st->Q_syn_factor = 0; move16(); -#endif - 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 ) ) + + 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 ) ) { return error; } - 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 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 */ @@ -561,16 +534,12 @@ ivas_error ivas_core_dec_fx( IF( save_hb_synth_32_fx ) { - Copy_Scale_sig_16_32_DEPREC( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); // Q11 + Scale_sig32( save_hb_synth_32_fx, output_frame, Q11 ); // Q0 -> Q11 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 ) ) @@ -606,12 +575,7 @@ ivas_error ivas_core_dec_fx( move32(); } - 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 ); -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, sub( Q11, st->Q_syn_factor ) ); // Q11 -#else - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, Q11 ); // Q11 -#endif + 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 ); IF( st->hTcxDec ) { @@ -629,28 +593,9 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ - Word16 Q_output; - - Q_output = 0; - move16(); - Q_synth = 0; - move16(); -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - st->Q_syn_factor = 0; - move16(); -#endif - - ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); + 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] ); - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); // Q11 -#ifdef FIX_1947_DEC_HIGH_MLD_FOR_STEREO2MONO - 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 -#else - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); // Q0 - Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); // Q0 -#endif } /*---------------------------------------------------------------------* @@ -828,32 +773,7 @@ ivas_error ivas_core_dec_fx( *---------------------------------------------------------------------*/ /*core_switching_post_dec*/ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Q_synth = add( sub( 15, e_sig[0] ), st->Q_syn_factor ); -#else - Q_synth = sub( 15, e_sig[0] ); -#endif - - /*------------------fix-to-fix-end-----------------------*/ - - Word16 output_mem_16_fx[L_FRAME48k]; - Word16 *p_output_mem_16; - - IF( p_output_mem_fx != NULL ) - { - p_output_mem_16 = output_mem_16_fx; - Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), -Q11 ); // Q(q_output_mem_fx-11) - } - ELSE - { - p_output_mem_16 = NULL; - set16_fx( output_mem_16_fx, 0, NS2SA_FX2( st->output_Fs, 3125000 ) ); - } - - Scale_sig32( output_32_fx[n], L_FRAME48k, Q4 - Q11 ); // Q4 - - /*size of synth is choosen as delay comp to start with*/ - /*-------------------cldfb-start-------------------------*/ IF( st->cldfbSyn != NULL ) { @@ -862,11 +782,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(); @@ -918,7 +833,7 @@ 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 ) ) + 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 ) ) { return error; } @@ -948,7 +863,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 ) { @@ -959,7 +874,6 @@ 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 } - Scale_sig32( output_32_fx[n], L_FRAME48k, ( Q11 - Q4 ) ); // Q11 /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -1000,10 +914,14 @@ ivas_error ivas_core_dec_fx( * WB BWE decoding *---------------------------------------------------------------------*/ - Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; - Word16 Q_syn_hb, sf; + Word16 Q_hb_synth_fx, Q_synth_fx; + Word16 Q_syn_hb; + + Q_hb_synth_fx = 0; + move16(); + Q_synth_fx = Q_synth; + move16(); -#ifdef FIX_1320_STACK_CPE_DECODER flaf_swb_tbe = 0; move16(); test(); @@ -1019,23 +937,8 @@ ivas_error ivas_core_dec_fx( flaf_swb_tbe = 1; move16(); } -#endif - - sf = getScaleFactor32( output_32_fx[n], L_FRAME48k ); - - Q_input = 0; - move16(); - if ( LT_16( sf, 5 ) ) - { - Q_input = sub( sf, 5 ); - } - Q_hb_synth_fx = 0; - move16(); - Q_synth_fx = Q_synth; - 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 + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 test(); test(); test(); @@ -1045,7 +948,7 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ - 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 ); + 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 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 ) { @@ -1054,19 +957,18 @@ ivas_error ivas_core_dec_fx( ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) { /* WB BWE decoder */ - 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 ); +#ifdef HARM_FD_BWE + Q_hb_synth_fx = 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_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 ); +#endif } /* Memories Re-Scaling */ -#ifdef FIX_1320_STACK_CPE_DECODER IF( !flaf_swb_tbe ) { -#endif 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 -#ifdef FIX_1320_STACK_CPE_DECODER } -#endif - 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 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 ) @@ -1083,45 +985,22 @@ ivas_error ivas_core_dec_fx( * SWB(FB) BWE decoding *---------------------------------------------------------------------*/ -#ifdef FIX_1320_STACK_CPE_DECODER test(); test(); test(); test(); flag_bwe_bws = ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && st->bfi == 0 ); move16(); -#endif Q_white_exc = 0; move16(); -#ifdef FIX_1320_STACK_CPE_DECODER test(); test(); IF( flaf_swb_tbe ) -#else - 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 ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) -#endif { /* SWB TBE decoder */ - ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); + swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx @@ -1136,14 +1015,10 @@ ivas_error ivas_core_dec_fx( /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { - 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 ); + 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 ); } } -#ifdef FIX_1320_STACK_CPE_DECODER ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || flag_bwe_bws ) -#else - ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) -#endif { /* SWB BWE decoder */ Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); @@ -1153,7 +1028,6 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_32_16( hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); // old_wtda_swb_fx_exp } -#ifdef FIX_1320_STACK_CPE_DECODER test(); test(); test(); @@ -1161,7 +1035,6 @@ ivas_error ivas_core_dec_fx( { set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); } -#endif /*---------------------------------------------------------------------* * FEC - recovery after lost HQ core (smoothing of the BWE component) @@ -1201,22 +1074,17 @@ 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 */ - 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( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); // 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_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_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); + swb_CNG_dec_fx( st, synth_16_fx[n], hb_synth_16_fx[n], sid_bw[n], -Q2 ); 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 @@ -1231,15 +1099,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(); @@ -1253,38 +1117,6 @@ ivas_error ivas_core_dec_fx( } } -#ifndef FIX_1320_STACK_CPE_DECODER - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - /*----------------------------------------------------------------* - * BFI waveform adjustment - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) - { - tmps = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); - IF( st->hTonalMDCTConc->q_lastPcmOut != 0 ) - { - Scale_sig( st->hTonalMDCTConc->secondLastPcmOut, shr( st->hPlcInfo->L_frameTCX, 1 ), negate( st->hTonalMDCTConc->q_lastPcmOut ) ); - Scale_sig( st->hTonalMDCTConc->lastPcmOut, st->hPlcInfo->L_frameTCX, negate( st->hTonalMDCTConc->q_lastPcmOut ) ); - st->hTonalMDCTConc->q_lastPcmOut = 0; - move16(); - } - waveform_adj2_fix( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); - - st->hPlcInfo->Pitch_fx = 0; - move16(); - } - } -#endif /*----------------------------------------------------------------* * Transition and synchronization of BWE components *----------------------------------------------------------------*/ @@ -1303,21 +1135,8 @@ ivas_error ivas_core_dec_fx( } ELSE { -#ifndef FIX_1320_STACK_CPE_DECODER - test(); - IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) - { - /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); - } - ELSE - { -#endif - /* TBE on top of ACELP@16kHz */ - tmps = NS2SA_FX2( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); -#ifndef FIX_1320_STACK_CPE_DECODER - } -#endif + /* TBE on top of ACELP@16kHz */ + tmps = NS2SA_FX2( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } /* Smooth transitions when switching between different technologies */ @@ -1542,12 +1361,7 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); -#ifdef FIX_1320_STACK_CPE_DECODER IF( st->hTcxDec != NULL && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) -#else - test(); - IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) -#endif { Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; move16(); @@ -1588,7 +1402,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 e91b7f8b019ea3870f92f3a80e9822050b2b6581..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 @@ -578,7 +578,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport_old, 1 ) && EQ_16( numCldfbAnalyses_old, 2 ) && GT_16( st_ivas->nchan_transport, 1 ) ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[1] ) ); + deleteCldfb_fx( &( st_ivas->cldfbAnaDec[1] ) ); numCldfbAnalyses_old = sub( numCldfbAnalyses_old, 1 ); } /* resample CLDFB analysis instances */ @@ -596,7 +596,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* delete superfluous CLDFB synthesis instances */ FOR( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbAnaDec[i] ) ); } } ELSE IF( LT_16( numCldfbAnalyses_old, numCldfbAnalyses ) ) @@ -616,7 +616,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* delete superfluous CLDFB synthesis instances */ FOR( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbSynDec[i] ) ); } } ELSE IF( LT_16( numCldfbSyntheses_old, numCldfbSyntheses ) ) diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index cfb6c615b1b4941cb117e88e585208d78491e3c0..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 /*--------------------------------------------------------------------------* @@ -51,9 +48,7 @@ static void read_stereo_mode_and_bwidth_fx( CPE_DEC_HANDLE hCPE, const Decoder_S static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE ); -#ifdef FIX_1320_STACK_CPE_DECODER static ivas_error stereo_dft_dec_main( CPE_DEC_HANDLE hCPE, const Word32 ivas_total_brate, const Word16 n_channels, Word32 *p_res_buf_fx, Word32 *output[], Word32 outputHB[][L_FRAME48k], const Word16 output_frame, const Word32 output_Fs ); -#endif /*--------------------------------------------------------------------------* @@ -75,12 +70,7 @@ ivas_error ivas_cpe_dec_fx( Word16 last_bwidth; Word16 tdm_ratio_idx; Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */ -#ifdef FIX_1320_STACK_CPE_DECODER - Word32 *res_buf_fx = NULL; /* Q8 */ -#else - Word16 q_res_buf; - Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ -#endif + Word32 *res_buf_fx = NULL; /* Q8 */ CPE_DEC_HANDLE hCPE; STEREO_DFT_CONFIG_DATA_HANDLE hConfigDft; Decoder_State **sts; @@ -91,10 +81,6 @@ ivas_error ivas_cpe_dec_fx( error = IVAS_ERR_OK; move32(); -#ifndef FIX_1320_STACK_CPE_DECODER - q_res_buf = Q8; - move16(); -#endif push_wmops( "ivas_cpe_dec" ); @@ -353,10 +339,8 @@ ivas_error ivas_cpe_dec_fx( } ELSE { -#ifdef FIX_1320_STACK_CPE_DECODER res_buf_fx = outputHB_fx[0]; /* note: temporarily reused buffer */ -#endif test(); IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { @@ -619,177 +603,10 @@ ivas_error ivas_cpe_dec_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hConfigDft->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { -#ifdef FIX_1320_STACK_CPE_DECODER IF( NE_32( ( error = stereo_dft_dec_main( hCPE, ivas_total_brate, n_channels, res_buf_fx, output, outputHB_fx, output_frame, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } -#else - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft - set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX ); - set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); - - /* core decoder */ - IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - // Scaling of DFT's - Word16 shift; - Word32 tmp1, tmp2; - Word16 shift1, shift2; - maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 ); - maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 ); - - IF( tmp1 == 0 ) - { - shift1 = Q31; - move16(); - } - ELSE - { - shift1 = norm_l( tmp1 ); - } - IF( tmp2 == 0 ) - { - shift2 = Q31; - move16(); - } - ELSE - { - shift2 = norm_l( tmp2 ); - } - shift = s_min( shift1, shift2 ); - - IF( NE_16( shift, 31 ) ) - { - shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q17 ); /* Q17 for guard bits */ - - IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) - { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift - hCPE->hStereoDft->q_dft = shift; - move16(); - } - } - ELSE - { - hCPE->hStereoDft->q_dft = Q8; - move16(); - } - - /* DFT Stereo residual decoding */ - test(); - IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st_ivas->bfi ) - { - Word16 q; - Word16 q_out_DFT[2]; - - q = Q11; - move16(); - - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6 - - stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] ); - - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16 - - Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11 - - q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft; - move16(); - move16(); - - stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT ); - - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft - } - - /* DFT stereo CNG */ - { - Word16 q_dft; - - q_dft = hCPE->hStereoDft->q_dft; - move16(); - - stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft ); - } - - /* decoding */ - IF( EQ_16( hCPE->nchan_out, 1 ) ) - { - IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) - { - hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; - move16(); - FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) - { - hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; - move16(); - } - hCPE->hStereoDft->first_frame = 0; - move16(); - } - - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft - hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata ); - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15 - hCPE->hStereoDft->q_res_cod_mem_fx = Q15; - move16(); - } - ELSE - { - { - IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) - { - hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; - move16(); - FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) - { - hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; - move16(); - } - hCPE->hStereoDft->first_frame = 0; - move16(); - } - - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft - hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; - move16(); - } - stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); - scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15 - hCPE->hStereoDft->q_res_cod_mem_fx = Q15; - move16(); - } - - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft - hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; - move16(); - } - - /* synthesis iFFT */ - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame ); - } - - // delete below - FOR( n = 0; n < hCPE->nchan_out; n++ ) - { - Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 - hCPE->q_output_mem_fx[n] = Q11; - move16(); - } -#endif } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { @@ -893,7 +710,6 @@ ivas_error ivas_cpe_dec_fx( return error; } -#ifdef FIX_1320_STACK_CPE_DECODER /*------------------------------------------------------------------------- * stereo_dft_dec_main() @@ -1068,11 +884,7 @@ static ivas_error stereo_dft_dec_main( FOR( n = 0; n < hCPE->nchan_out; n++ ) { -#ifdef FIX_1330_JBM_MEMORY - Scale_sig32( output[n], output_frame, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft -#else - Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft -#endif + Scale_sig32( output[n], output_frame, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; move16(); @@ -1086,11 +898,7 @@ static ivas_error stereo_dft_dec_main( FOR( n = 0; n < hCPE->nchan_out; n++ ) { -#ifdef FIX_1330_JBM_MEMORY - Scale_sig32( output[n], output_frame, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 -#else - Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 -#endif + Scale_sig32( output[n], output_frame, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 hCPE->q_output_mem_fx[n] = Q11; move16(); @@ -1099,7 +907,6 @@ static ivas_error stereo_dft_dec_main( return IVAS_ERR_OK; } -#endif /*------------------------------------------------------------------------- * create_cpe_dec_fx() @@ -1312,7 +1119,7 @@ ivas_error create_cpe_dec( st->is_ism_format = 0; move16(); - IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_decoder_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) { return error; } 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..0e34d75707154579cd15452c1bbf4a7c9ee173fd --- /dev/null +++ b/lib_dec/ivas_dec_render_fx.c @@ -0,0 +1,2341 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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]; + Word16 n, n_render_timeslots, n_ch_cldfb, ch; + 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 ); + + 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 3eac102a3dc4106b994df9b258ab6eb37d4a4f25..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 @@ -46,11 +46,7 @@ * Read ACELP signaling bits from the bitstream * Set extension layers *-----------------------------------------------------------------*/ -#ifndef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG -static Word16 get_next_index_4_by_15[16] = { - 0, 2184, 4369, 6553, 8738, 10922, 13107, 15291, 17476, 19660, 21845, 24029, 26214, 28398, 30583, 32767 -}; -#endif + void ivas_decision_matrix_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 *sharpFlag, /* o : formant sharpening flag */ @@ -119,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 { @@ -130,12 +129,9 @@ void ivas_decision_matrix_dec_fx( { /* read channel coherence */ Word16 index; + index = get_next_indice_fx( st, 4 ); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG st->hFdCngDec->hFdCngCom->coherence_fx[0] = get_next_index_4_by_15[index]; -#else - st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index]; -#endif move16(); /* read flag for no side noise shape */ diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index c9d9b2c384f8caa3808c5f58f4e2618817e58440..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(); @@ -2076,12 +2074,8 @@ void ivas_dirac_dec_render_fx( move16(); SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word32 *output_fx_local[MAX_OUTPUT_CHANNELS]; -#ifdef FIX_RENDERER_STACK Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; -#else - Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; -#endif hSpatParamRendCom = st_ivas->hSpatParamRendCom; @@ -2089,11 +2083,7 @@ void ivas_dirac_dec_render_fx( FOR( ch = 0; ch < nchan_intern; ch++ ) { output_fx_local[ch] = output_fx_local_buff[ch]; -#ifdef FIX_RENDERER_STACK p_output_fx[ch] = output_fx[ch]; -#else - set_zero_fx( output_fx_local[ch], nSamplesAsked ); -#endif } slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL @@ -2122,7 +2112,6 @@ void ivas_dirac_dec_render_fx( FOR( ch = 0; ch < nchan_intern; ch++ ) { -#ifdef FIX_RENDERER_STACK /* move to output */ test(); test(); @@ -2132,26 +2121,12 @@ void ivas_dirac_dec_render_fx( } p_output_fx[ch] += n_samples_sf; -#else - output_fx_local[ch] += n_samples_sf; -#endif } /* update combined orientation access index */ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } -#ifndef FIX_RENDERER_STACK - FOR( ch = 0; ch < nchan_intern; ch++ ) - { - test(); - test(); - IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) - { - Copy32( output_fx_local_buff[ch], output_fx[ch], *nSamplesRendered ); - } - } -#endif /* clang-format off */ IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) { @@ -2175,7 +2150,6 @@ void ivas_dirac_dec_render_fx( /* clang-format on */ -#ifdef FIX_1319_STACK_SBA_DECODER /*------------------------------------------------------------------------- * Local functions to perform binaural rendering with optimized stack *------------------------------------------------------------------------*/ @@ -2189,9 +2163,6 @@ static void binRenderer_split_fx( Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Rotated Binaural signals */ Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - const Word16 slot_idx_start, -#endif const Word16 num_freq_bands, const Word16 nchan_out ) { @@ -2224,16 +2195,11 @@ static void binRenderer_split_fx( { FOR( ch = 0; ch < nchan_out; ch++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_Push( hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], Cldfb_RealBuffer_Binaural_loc[pos_idx][ch][slot_idx], Cldfb_ImagBuffer_Binaural_loc[pos_idx][ch][slot_idx], num_freq_bands ); -#else - Copy32( Cldfb_RealBuffer_Binaural_loc[pos_idx][ch][slot_idx], hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], num_freq_bands ); - Copy32( Cldfb_ImagBuffer_Binaural_loc[pos_idx][ch][slot_idx], hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], num_freq_bands ); -#endif } } } @@ -2266,7 +2232,6 @@ static void binRenderer_fx( return; } -#endif /*------------------------------------------------------------------------- @@ -2279,14 +2244,8 @@ void ivas_dirac_dec_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/ const Word16 nchan_transport, /* i : number of transport channels */ -#ifdef FIX_1319_STACK_SBA_DECODER Word32 *pppQMfFrame_ts_re_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX], - Word32 *pppQMfFrame_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX] -#else - Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/ - Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/ -#endif -) + Word32 *pppQMfFrame_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX] ) { Word16 i, ch, idx_in, idx_lfe; DIRAC_DEC_HANDLE hDirAC; @@ -2297,17 +2256,10 @@ void ivas_dirac_dec_render_sf_fx( Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx; /*CLDFB: last output channels reserved to LFT for CICPx*/ -#ifdef FIX_1319_STACK_SBA_DECODER Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_RealBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; -#else - Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; -#endif Word16 index = 0, num_freq_bands = 0; move16(); move16(); @@ -2324,13 +2276,6 @@ void ivas_dirac_dec_render_sf_fx( Word16 surCohRatio_q_fx = 0, temp_q = 0; move16(); move16(); -#ifndef FIX_1319_STACK_SBA_DECODER - Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; -#endif -#ifndef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES - Word16 cldfb_buf_q; -#endif Word16 offset = 0, buff_len = 0; move16(); move16(); @@ -2822,19 +2767,11 @@ void ivas_dirac_dec_render_sf_fx( { q_temp_cldfb = Q11; move16(); -#ifdef FIX_1319_STACK_SBA_DECODER cldfbAnalysis_ts_fx_fixed_q( &( st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ), Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */ Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */ hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_temp_cldfb ); -#else - cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], - Cldfb_RealBuffer_Temp_fx[ch][slot_idx], - Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, - st_ivas->cldfbAnaDec[ch], &q_temp_cldfb ); -#endif } q_cldfb = q_temp_cldfb; move16(); @@ -2842,15 +2779,7 @@ void ivas_dirac_dec_render_sf_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#ifdef FIX_1319_STACK_SBA_DECODER -#ifdef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Binaural_fx[0], Cldfb_ImagBuffer_Binaural_fx[0], &q_cldfb, hSpatParamRendCom->num_freq_bands, subframe_idx ); -#else - ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Binaural_fx[0], Cldfb_ImagBuffer_Binaural_fx[0], &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); -#endif -#else - ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); -#endif } } @@ -2883,13 +2812,8 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < nchan_transport; ch++ ) { -#ifdef FIX_1319_STACK_SBA_DECODER Copy32( Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); Copy32( Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); -#else - Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); - Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); -#endif } } ELSE @@ -3085,6 +3009,7 @@ void ivas_dirac_dec_render_sf_fx( /*-----------------------------------------------------------------* * Compute DirAC parameters at decoder side *-----------------------------------------------------------------*/ + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) { Copy( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); @@ -3092,7 +3017,8 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) + test(); + IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); @@ -3780,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(); } @@ -3858,7 +3784,6 @@ void ivas_dirac_dec_render_sf_fx( } /* Perform binaural rendering, output in Q6 format */ -#ifdef FIX_1319_STACK_SBA_DECODER test(); IF( 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 ) ) { @@ -3877,56 +3802,21 @@ void ivas_dirac_dec_render_sf_fx( } binRenderer_split_fx( st_ivas->hBinRenderer, st_ivas->hSplitBinRend, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx], - Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - slot_idx_start, -#endif - hSpatParamRendCom->num_freq_bands, st_ivas->hDecoderConfig->nchan_out ); + Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hSpatParamRendCom->num_freq_bands, st_ivas->hDecoderConfig->nchan_out ); } ELSE { binRenderer_fx( st_ivas->hBinRenderer, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx], Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx ); } -#else - IF( 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 ) ) - { - IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL ) - { - FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ ) - { - Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands ); - Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands ); - } - } - st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config; - move16(); - } - } - - /*Binaural output in Q6 format*/ - ivas_binRenderer_fx( st_ivas->hBinRenderer, - ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, - st_ivas->hCombinedOrientationData, - hSpatParamRendCom->subframe_nbslots[subframe_idx], - Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, - Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q ); -#endif /* Inverse CLDFB*/ FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands]; -#ifdef FIX_1319_STACK_SBA_DECODER Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME]; Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME]; -#else - Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; -#endif FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i]; @@ -3972,13 +3862,8 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { -#ifdef FIX_1319_STACK_SBA_DECODER Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME]; Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME]; -#else - Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; -#endif Word16 outchannels; idx_in = 0; 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 dff92f4e4b92fbaa66580d5f1a546857e70a8303..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,6 +108,8 @@ 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; + Word16 Opt_tsm; + UWord16 *bit_stream_orig; AUDIO_CONFIG signaled_config; ivas_error error; @@ -122,6 +121,8 @@ ivas_error ivas_dec_get_format_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); + Opt_tsm = st_ivas->hDecoderConfig->Opt_tsm; + move16(); bit_stream_orig = st_ivas->bit_stream; /*-------------------------------------------------------------------* @@ -142,10 +143,20 @@ ivas_error ivas_dec_get_format_fx( !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_ISM_FORMAT ) ) && !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } } /*-------------------------------------------------------------------* @@ -183,10 +194,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } } st_ivas->nchan_ism = nchan_ism; @@ -210,10 +231,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); + } } /* read Ambisonic (SBA) order */ @@ -224,10 +255,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } } sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, sba_order ); @@ -235,10 +276,21 @@ ivas_error ivas_dec_get_format_fx( } ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { + UWord8 masaRestartCandidate; + masaRestartCandidate = 0; + move16(); + /* read number of MASA transport channels */ k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( st_ivas->bit_stream[k - 1] ) { + test(); + if ( st_ivas->nchan_transport == 1 && Opt_tsm ) + { + masaRestartCandidate = 1; + move16(); + } + st_ivas->nchan_transport = 2; move16(); element_mode_flag = 1; @@ -246,6 +298,13 @@ ivas_error ivas_dec_get_format_fx( } ELSE { + test(); + if ( st_ivas->nchan_transport == 2 && Opt_tsm ) + { + masaRestartCandidate = 1; + move16(); + } + st_ivas->nchan_transport = 1; move16(); } @@ -279,14 +338,31 @@ ivas_error ivas_dec_get_format_fx( element_mode_flag = 1; move16(); } + ELSE IF( masaRestartCandidate > 0 ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } } st_ivas->nchan_ism = nchan_ism; @@ -305,10 +381,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } } st_ivas->nchan_ism = nchan_ism; @@ -323,10 +409,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } } st_ivas->nchan_ism = nchan_ism; @@ -354,10 +450,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } } st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); @@ -384,10 +490,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); + fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); + } } st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), ivas_total_brate ); @@ -486,10 +602,20 @@ ivas_error ivas_dec_get_format_fx( test(); IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { + IF( Opt_tsm ) + { + st_ivas->restartNeeded = 1; + move16(); + + return IVAS_ERR_OK; + } + ELSE + { #ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } } st_ivas->nchan_ism = nchan_ism; @@ -1010,6 +1136,7 @@ ivas_error ivas_dec_setup( * Initialize decoder in the first good frame based on IVAS format * and number of transport channels *-------------------------------------------------------------------*/ + test(); IF( st_ivas->ini_frame == 0 && NE_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) { @@ -1381,10 +1508,8 @@ ivas_error ivas_init_decoder_front( move32(); st_ivas->mc_mode = MC_MODE_NONE; move32(); -#ifdef FIX_1384_MSAN_ivas_spar_dec_open st_ivas->sid_format = SID_FORMAT_NONE; move16(); -#endif st_ivas->sba_dirac_stereo_flag = 0; move16(); @@ -1432,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; } @@ -1445,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; } @@ -1455,7 +1580,6 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ - test(); test(); test(); @@ -1498,10 +1622,8 @@ ivas_error ivas_init_decoder_fx( Word16 i, n, k; Word16 sce_id, cpe_id; Word16 numCldfbAnalyses, numCldfbSyntheses; - Word16 granularity, n_channels_transport_jbm; -#ifdef FIX_1330_JBM_MEMORY + Word16 granularity, n_channels_transport; Word16 nchan_out_buff; -#endif Word32 output_Fs, ivas_total_brate, tmp_br, tmp32; Word32 delay_ns; AUDIO_CONFIG output_config; @@ -1531,7 +1653,12 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { test(); - IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + { + hDecoderConfig->nchan_out = 1; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { hDecoderConfig->nchan_out = CPE_CHANNELS; } @@ -1665,16 +1792,76 @@ ivas_error ivas_init_decoder_fx( } } - /*--------------------------------------------------------------------* - * Allocate and initialize HRTF Statistics handle - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------------* + * Allocate and initialize HRTF Statistics handle, get default reverb values + *--------------------------------------------------------------------------*/ IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( NE_32( ( error = ivas_HRTF_statistics_init_fx( &st_ivas->hHrtfStatistics, output_Fs ) ), IVAS_ERR_OK ) ) + /* Init HRTF statistics */ + /* 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; } + + /* Get default reverb values based on format, if custom values were not given */ + IF( EQ_16( st_ivas->hDecoderConfig->Opt_RendConfigCustom, 0 ) ) + { + IVAS_DefaultReverbSize defaultReverbSize; + SWITCH( st_ivas->hDecoderConfig->room_size ) + { + case IVAS_ROOM_SIZE_AUTO: + SWITCH( st_ivas->ivas_format ) + { + case ISM_FORMAT: + defaultReverbSize = DEFAULT_REVERB_LARGE; + move32(); + BREAK; + case SBA_FORMAT: + defaultReverbSize = DEFAULT_REVERB_SMALL; + move32(); + BREAK; + case MASA_FORMAT: + defaultReverbSize = DEFAULT_REVERB_SMALL; + move32(); + BREAK; + case MC_FORMAT: + defaultReverbSize = DEFAULT_REVERB_MEDIUM; + move32(); + BREAK; + case MASA_ISM_FORMAT: + defaultReverbSize = DEFAULT_REVERB_MEDIUM; + move32(); + BREAK; + case SBA_ISM_FORMAT: + defaultReverbSize = DEFAULT_REVERB_MEDIUM; + move32(); + BREAK; + default: + defaultReverbSize = DEFAULT_REVERB_LARGE; + move32(); + } + BREAK; + case IVAS_ROOM_SIZE_SMALL: + defaultReverbSize = DEFAULT_REVERB_SMALL; + move32(); + BREAK; + case IVAS_ROOM_SIZE_MEDIUM: + defaultReverbSize = DEFAULT_REVERB_MEDIUM; + move32(); + BREAK; + case IVAS_ROOM_SIZE_LARGE: + default: + defaultReverbSize = DEFAULT_REVERB_LARGE; + move32(); + BREAK; + } + IF( NE_32( error = ivas_render_config_change_defaults( st_ivas->hRenderConfig, defaultReverbSize ), IVAS_ERR_OK ) ) + { + return error; + } + } } /*-----------------------------------------------------------------* @@ -2587,7 +2774,8 @@ ivas_error ivas_init_decoder_fx( test(); test(); test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( hDecoderConfig->Opt_Headrotation || hDecoderConfig->Opt_ExternalOrientation ) ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( hDecoderConfig->Opt_Headrotation || hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) ) { IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { @@ -2672,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; } @@ -2832,7 +3020,8 @@ ivas_error ivas_init_decoder_fx( } /*-----------------------------------------------------------------* - * LFE handles for rendering after rendering to adjust LFE delay to filter delay + * LFE handles for rendering after rendering to adjust LFE delay to + * filter delay *-----------------------------------------------------------------*/ test(); @@ -2890,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; } @@ -2911,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; } @@ -2922,32 +3111,11 @@ ivas_error ivas_init_decoder_fx( * Allocate output audio buffers *-----------------------------------------------------------------*/ -#ifdef FIX_1330_JBM_MEMORY nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, ivas_total_brate ); IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff, hDecoderConfig->Opt_tsm, st_ivas->hTcBuffer ) ) != IVAS_ERR_OK ) { return error; } -#else -#ifdef FIX_NCHAN_BUFFERS - k = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, ivas_total_brate ); - FOR( n = 0; n < k; n++ ) -#else - FOR( n = 0; n < ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, ivas_total_brate ); n++ ) -#endif - { - /* note: these are intra-frame heap memories */ - IF( ( st_ivas->p_output_fx[n] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for output audio buffer!\n" ) ); - } - set32_fx( st_ivas->p_output_fx[n], 0, 48000 / FRAMES_PER_SEC ); - } - FOR( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) - { - st_ivas->p_output_fx[n] = NULL; - } -#endif return error; } @@ -2963,14 +3131,7 @@ void destroy_core_dec_fx( DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ ) { - IF( EQ_16( hCoreCoder->element_mode, EVS_MONO ) ) - { - destroy_cldfb_decoder_fx( hCoreCoder ); - } - ELSE - { - destroy_cldfb_decoder_ivas_fx( hCoreCoder ); - } + destroy_cldfb_decoder_fx( hCoreCoder ); IF( hCoreCoder->hGSCDec != NULL ) { @@ -3187,13 +3348,16 @@ void ivas_initialize_handles_dec( st_ivas->hRenderConfig = NULL; st_ivas->hExtOrientationData = NULL; st_ivas->hCombinedOrientationData = NULL; + st_ivas->acousticEnvironmentsCount = 0; + move16(); + st_ivas->pAcousticEnvironments = NULL; st_ivas->hSplitBinRend = NULL; for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) { st_ivas->hTdRendHandles[i] = NULL; } - /* JBM handles */ + st_ivas->hTcBuffer = NULL; st_ivas->hJbmMetadata = NULL; @@ -3224,7 +3388,7 @@ void ivas_destroy_dec_fx( { IF( st_ivas->cldfbAnaDec[i] != NULL ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbAnaDec[i] ) ); } } @@ -3232,7 +3396,7 @@ void ivas_destroy_dec_fx( { IF( st_ivas->cldfbSynDec[i] != NULL ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbSynDec[i] ) ); } } @@ -3378,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 ); @@ -3403,11 +3556,18 @@ 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 ) ); + /* Acoustic environments */ + IF( st_ivas->pAcousticEnvironments != NULL ) + { + free( st_ivas->pAcousticEnvironments ); + st_ivas->pAcousticEnvironments = NULL; + } + /* Limiter struct */ ivas_limiter_close_fx( &( st_ivas->hLimiter ) ); @@ -3418,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 ) { @@ -3430,15 +3590,7 @@ void ivas_destroy_dec_fx( /* output audio buffers */ FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { -#ifdef FIX_1330_JBM_MEMORY st_ivas->p_output_fx[i] = NULL; -#else - IF( st_ivas->p_output_fx[i] != NULL ) - { - free( st_ivas->p_output_fx[i] ); - st_ivas->p_output_fx[i] = NULL; - } -#endif } /* main IVAS handle */ @@ -3773,29 +3925,29 @@ static ivas_error doSanityChecks_IVAS( return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" ); } - /* Verify stereo output configuration */ - IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_ISM1 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_ISM2 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_ISM3 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_ISM4 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_MASA1 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_MASA2 ) ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Wrong output configuration specified for Stereo!" ); - } + return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified!" ); } - /* Verify output configuration for other formats */ - ELSE + + test(); + test(); + IF( ( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) || EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) && + ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) { - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified!" ); - } + return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified!" ); } test(); diff --git a/lib_dec/ivas_ism_dec_fx.c b/lib_dec/ivas_ism_dec_fx.c index 5d8e1f7054a0567714f4466a7322e80cf69c4727..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,15 +55,8 @@ 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; -#ifdef FIX_1330_JBM_MEMORY Word16 nchan_out_buff; -#else - Word16 nchan_out_buff, nchan_out_buff_old; -#endif nCPE_old = st_ivas->nCPE; move16(); @@ -78,9 +71,6 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); st_ivas->ism_mode = ism_mode; move16(); -#ifndef FIX_1330_JBM_MEMORY - nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); -#endif IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { @@ -131,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 ) ) { @@ -146,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 ) ) @@ -309,31 +299,22 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( return error; } -#ifndef FIX_1330_JBM_MEMORY /*-----------------------------------------------------------------* - * output audio buffers - *-----------------------------------------------------------------*/ - - nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); - - IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) - { - return error; - } -#endif - /*-----------------------------------------------------------------* - * 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(); @@ -346,34 +327,33 @@ 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 ); } -#ifdef FIX_1330_JBM_MEMORY /*-----------------------------------------------------------------* * output audio buffers @@ -384,7 +364,6 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( { return error; } -#endif return IVAS_ERR_OK; } 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 54cc5da15e24d25f025530478d84a4674a0c5ad2..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(); @@ -1248,47 +1245,33 @@ void ivas_ism_metadata_sid_dec_fx( { IF( EQ_16( ch, *sce_id_dtx ) ) { -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG FOR( i = 0; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ ) { hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[i] = 32767; } -#else - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = 32767; // 1.0f in Q15 - move16(); -#endif CONTINUE; } idx = get_next_indice_fx( st0, nBits_coh ); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[0] = get_next_index_4_by_15[idx]; // Q15 move16(); + FOR( i = 1; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ ) { hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[i] = hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[0]; move16(); } -#else - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, sub( ( shl( 1, nBits_coh ) ), 1 ) ); // Q15 - move16(); -#endif } } IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) { -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG FOR( i = 0; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ ) { hSCE[*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[i] = hSCE[!*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[i]; move16(); } -#else - hSCE[*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = hSCE[!*sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx; - move16(); -#endif } /*----------------------------------------------------------------* diff --git a/lib_dec/ivas_ism_param_dec_fx.c b/lib_dec/ivas_ism_param_dec_fx.c index 6af94ea97a7efca424d9449a686046f953daaa08..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(); @@ -942,9 +941,6 @@ void ivas_ism_dec_digest_tc_fx( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) ) { Word16 i; -#ifndef NONBE_1412_AVOID_ROUNDING_AZ_ELEV - Word32 azimuth_fx, elevation_fx; -#endif /* we have a full frame interpolator, adapt it */ /* for BE testing */ @@ -983,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(); @@ -1013,12 +1010,6 @@ void ivas_ism_dec_digest_tc_fx( } ELSE { -#ifndef NONBE_1412_AVOID_ROUNDING_AZ_ELEV - // TODO tmu review when #215 is resolved - azimuth_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->edited_azimuth_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22 - elevation_fx = L_shr( L_add( st_ivas->hIsmMetaData[i]->edited_elevation_fx, 2097152 ), Q22 ); // Q0 ,2097152 = .5f in Q22 -#endif - test(); test(); test(); @@ -1033,9 +1024,7 @@ void ivas_ism_dec_digest_tc_fx( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) && EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ) && st_ivas->hCombinedOrientationData == NULL ) { -#ifdef NONBE_1412_AVOID_ROUNDING_AZ_ELEV Word32 elevation_fx = st_ivas->hIsmMetaData[i]->edited_elevation_fx; -#endif if ( st_ivas->hIntSetup.is_planar_setup ) { /* If no elevation support in output format, then rendering should be done with zero elevation */ @@ -1045,17 +1034,9 @@ void ivas_ism_dec_digest_tc_fx( IF( st_ivas->hEFAPdata != NULL ) { -#ifndef NONBE_1412_AVOID_ROUNDING_AZ_ELEV - azimuth_fx = L_shl( azimuth_fx, Q22 ); // Q22 - elevation_fx = L_shl( elevation_fx, Q22 ); // Q22 -#endif - -#ifdef NONBE_1412_AVOID_ROUNDING_AZ_ELEV efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmMetaData[i]->edited_azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); -#else - efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); -#endif + // TODO: align Q values properly IF( NE_32( st_ivas->hIsmMetaData[i]->edited_gain_fx, ONE_IN_Q29 ) ) { @@ -1069,13 +1050,8 @@ void ivas_ism_dec_digest_tc_fx( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /*get HOA gets for direction (ACN/SN3D)*/ -#ifdef FIX_2193_ISM_GAINS_WITH_OE Word16 azi = round_fx( L_shr( st_ivas->hIsmMetaData[i]->edited_azimuth_fx, Q22 - Q16 ) ); // Q0 Word16 ele = round_fx( L_shr( st_ivas->hIsmMetaData[i]->edited_elevation_fx, Q22 - Q16 ) ); // Q0 -#else - Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); // Q0 - Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); // Q0 -#endif ivas_dirac_dec_get_response_fx( azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order, Q30 ); @@ -1117,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; @@ -1251,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 ); @@ -1838,11 +1814,8 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( IF( st_ivas->hISMDTX.dtx_flag ) { Word32 energy_ratio_fx; /* Q30 */ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG + energy_ratio_fx = L_mult0( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx[0] ); /* Q15 + Q15 -> Q30 */ -#else - energy_ratio_fx = L_mult0( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx, st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx ); /* Q15 + Q15 -> Q30 */ -#endif hSpatParamRendCom->numSimultaneousDirections = 1; move16(); diff --git a/lib_dec/ivas_ism_renderer_fx.c b/lib_dec/ivas_ism_renderer_fx.c index 85d333c94ea8f504218d68e940f131902fe812d1..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,32 +209,18 @@ 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 ); } -#ifndef FIX_1330_JBM_MEMORY - IF( st_ivas->hDecoderConfig->Opt_tsm ) + FOR( i = 0; i < num_objects; i++ ) { - FOR( i = 0; i < num_objects; i++ ) - { - p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; // Q11 - } + Copy32( &output_fx[i][tc_offset], tc_local_fx[i], n_samples_to_render ); + p_tc_fx[i] = tc_local_fx[i]; } - ELSE - { -#endif - FOR( i = 0; i < num_objects; i++ ) - { - Copy32( &output_fx[i][tc_offset], tc_local_fx[i], n_samples_to_render ); - p_tc_fx[i] = tc_local_fx[i]; - } -#ifndef FIX_1330_JBM_MEMORY - } -#endif FOR( i = 0; i < nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) { @@ -247,11 +231,11 @@ void ivas_ism_render_sf_fx( { Word16 n_samples_in_subframe; - n_samples_in_subframe = st_ivas->hTcBuffer->n_samples_granularity * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx]; + n_samples_in_subframe = imult1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->subframe_nbslots[subframe_idx] ); 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(); } @@ -262,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 ); } @@ -421,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 */ ) { @@ -470,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 */ ) { @@ -501,22 +485,17 @@ 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*/ -#ifdef FIX_1330_JBM_MEMORY - const Word16 subframes_rendered /* i : number of subframes rendered */ -#else - const Word16 subframes_rendered, /* i : number of subframes rendered */ - const Word16 slots_rendered /* i : number of CLDFB slots rendered */ -#endif + 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 */ ) { VBAP_HANDLE hVBAPdata; @@ -565,34 +544,16 @@ void ivas_omasa_separate_object_render_jbm_fx( move16(); } -#ifndef FIX_1330_JBM_MEMORY - offsetSamples = i_mult( slots_rendered, hSpatParamRendCom->slot_size ); -#endif FOR( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) { output_fx_local[j] = output_fx[j]; } -#ifndef FIX_1330_JBM_MEMORY - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - FOR( obj = 0; obj < num_objects; obj++ ) - { - input_fx[obj] = &st_ivas->hTcBuffer->tc_fx[obj + 2][offsetSamples]; - move32(); - } - } - ELSE + FOR( obj = 0; obj < num_objects; obj++ ) { -#endif - FOR( obj = 0; obj < num_objects; obj++ ) - { - input_fx[obj] = input_fx_in[obj]; - move32(); - } -#ifndef FIX_1330_JBM_MEMORY + input_fx[obj] = input_fx_in[obj]; + move32(); } -#endif slots_to_render = idiv1616( nSamplesRendered, hSpatParamRendCom->slot_size ); first_sf = 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 7426801bc2c53071cb61467b0f21c63c068bba62..0000000000000000000000000000000000000000 --- a/lib_dec/ivas_jbm_dec_fx.c +++ /dev/null @@ -1,4754 +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 - } -#ifdef NONBE_1324_TC_BUFFER_MEMOERY_KEEP - st_ivas->hCPE[0]->q_output_mem_fx[0] = output_q; - st_ivas->hCPE[0]->q_output_mem_fx[1] = output_q; -#endif - } - } - 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*/ -#ifndef JBM_MEMORY_OPT - , - Word32 *data /* i : transport channels */ -#endif -) -{ -#ifdef JBM_MEMORY_OPT - Word32 tmp_buf_fx[MAX_JBM_L_FRAME48k]; - Word32 *p_data_fx[FOA_CHANNELS + MAX_NUM_OBJECTS]; -#else - Word32 data_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k]; /* buffer for transport channels that will be directly converted with the CLDFB */ - Word32 *p_data_fx[MAX_CLDFB_DIGEST_CHANNELS]; -#endif - Word16 n, n_render_timeslots, n_ch_cldfb; -#ifdef FIX_1330_JBM_MEMORY - Word16 ch, offset, len_offset; -#else - Word16 ch; -#endif - 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 ) - { -#ifdef JBM_MEMORY_OPT - 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 ); - -#ifdef FIX_1330_JBM_MEMORY - /* 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]; -#ifdef FIX_1330_JBM_MEMORY_FIX - st_ivas->p_output_fx[ch] = hTcBuffer->tc_fx[ch]; -#endif - 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_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 ); - } - } -#else - Word16 n_samples_still_available, m; - Word16 n_ch_full_copy; - Word16 n_ch_res_copy; - - FOR( n = 0; n < n_ch_cldfb; n++ ) - { - p_data_fx[n] = &data_fx[n][0]; - } - - 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 ); - - FOR( ch = 0; ch < n_ch_full_copy; ch++ ) - { - set32_fx( hTcBuffer->tc_fx[ch], 0, hTcBuffer->n_samples_discard ); - Copy32( hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available ); - FOR( m = 0; m < nSamplesForRendering; m++ ) - { - hTcBuffer->tc_fx[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * hTcBuffer->nchan_transport_jbm + ch]; - move32(); - } - } - - IF( n_ch_res_copy > 0 ) - { - FOR( ; ch < hTcBuffer->nchan_transport_jbm; ch++ ) - { - Copy32( hTcBuffer->tc_fx[ch], p_data_fx[ch], n_samples_still_available ); - - FOR( m = 0; m < nSamplesForRendering; m++ ) - { - p_data_fx[ch][n_samples_still_available + m] = data[m * hTcBuffer->nchan_transport_jbm + ch]; - move32(); - } - Copy32( p_data_fx[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual ); - } - } -#endif - - 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(); - } - -#ifdef FIX_NCHAN_BUFFERS -#ifdef JBM_MEMORY_OPT - ch = s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); -#else - ch = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#endif - FOR( n = 0; n < ch; n++ ) -#else - FOR( n = 0; n < ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) -#endif - { - 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 ) - { -#ifdef JBM_MEMORY_OPT - FOR( n = 0; n < MAX_INTERN_CHANNELS; n++ ) -#else - FOR( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ ) -#endif - { - 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 - *----------------------------------------------------------------*/ - 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 ) ) - { - 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 ) ); - - ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); - } - ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - /* Rendering */ - IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) - { - *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - move16(); - - ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - } - } - 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 */ - { - *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - move16(); - - 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 ) ) - { - *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - move16(); - - 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 */ -#ifdef FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT - ivas_osba_stereo_add_channels_fx( p_tc_fx, p_output_fx, st_ivas->hSbaIsmData->gain_bed_fx, nchan_out, st_ivas->nchan_ism, *nSamplesRendered ); -#else - 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 ); -#endif - } - 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(); - *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - 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 -#ifndef FIX_1330_JBM_MEMORY - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor - } -#endif - } - } - 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 ) ) - { -#ifdef FIX_1330_JBM_MEMORY - 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 ) -#else - 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, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) -#endif - { - return error; - } - } - ELSE - { -#ifdef FIX_1330_JBM_MEMORY - 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 ) ) -#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, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ), - IVAS_ERR_OK ) ) -#endif - { - return error; - } - - // Todo main-pc update: This might be needed also in the split rendering path -#ifndef FIX_1330_JBM_MEMORY - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - IF( NE_16( exp, *st_ivas->hCrendWrapper->p_io_qfactor ) ) - { - FOR( i = 0; i < nchan_in; i++ ) - { - scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( *st_ivas->hCrendWrapper->p_io_qfactor, exp ) ); - } - } - } -#endif - 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 - } -#ifndef FIX_1330_JBM_MEMORY - IF( st_ivas->hDecoderConfig->Opt_tsm && crendInPlaceRotation ) - { - n = 0; - move16(); - } -#endif - - 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 ) ) - { - *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - move16(); - - 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 ) ) - { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - 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 - FOR( i = 0; i < st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; i++ ) - { - Copy32( p_output_fx[i], st_ivas->hSplitBinRend->hMultiBinCldfbData->output_fx[i], *nSamplesRendered ); - } -#endif - } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - ELSE - { -#endif - nchan_out_syn_output = nchan_out; - move16(); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - } -#endif - - 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; - -#ifdef JBM_MEMORY_OPT - /* 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 ); -#ifdef FIX_2174_JBM_BASOP_ALIGNMENT - set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, sub( hTcBuffer->n_samples_granularity, n_samples_to_render ) ); -#else - set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render ); -#endif - } -#else - /* render what is still there with zero padding */ - FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) - { - /* move it at the beginning of the TC buffer with zero padding */ - Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch_idx], n_samples_to_render ); - set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render ); - Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered + n_samples_to_render, hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_granularity, n_samples_still_available ); - } -#endif - - /* 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 ) ) - { - /*TODO :To be tested : no stream entering---------------------------------------*/ - /* 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 ) ) - { - /*TODO :To be tested : no stream entering*/ - 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; - } - *st_ivas->hCrendWrapper->p_io_qfactor = 11; - move16(); - - 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 ); - } - 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]; -#ifdef NONBE_1302_FIX_OMASA_JBM_FLUSH - Word16 last_dirac_md_idx; - UWord16 nSamplesAvailableNext; - ISM_MODE ism_mode_orig; - RENDERER_TYPE renderer_type_orig; - Word32 ivas_total_brate; -#endif - - /* 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*/ - } - -#ifdef NONBE_1302_FIX_OMASA_JBM_FLUSH - /* 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( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) ) - { - return error; - } -#endif - } - } - 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 = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); - nMaxSlotsPerSubframe = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e ); - nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, 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(); - IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) ) - { - num_tc = st_ivas->hDecoderConfig->nchan_out; - move16(); - } - ELSE IF( EQ_16( 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( 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 ); - } - } - } - 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(); - } - - 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; -} - -#ifdef JBM_MEMORY_OPT - -/*--------------------------------------------------------------------------* - * 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 ); -#ifdef FIX_1330_JBM_MEMORY - n_samp_full = s_max( n_samp_full, L_FRAME48k ); /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': ensure minimal length */ -#endif -#ifdef FIX_2174_JBM_BASOP_ALIGNMENT - n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); -#else - n_samp_residual = add( hTcBuffer->n_samples_granularity, 1 ); -#endif - } - ELSE - { - n_samp_full = extract_l( Mpy_32_32( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - n_samp_residual = 0; - move16(); - } - -#ifdef FIX_2174_JBM_BASOP_ALIGNMENT - nsamp_to_allocate = imult1616( s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ), n_samp_full ); -#else - nsamp_to_allocate = s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ) * n_samp_full; -#endif - - 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(); -#ifdef FIX_2174_JBM_BASOP_ALIGNMENT - FOR( ch_idx = 0; ch_idx < s_max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); ch_idx++ ) -#else - FOR( ch_idx = 0; ch_idx < max( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full ); ch_idx++ ) -#endif - { - 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; - } - } - -#ifdef FIX_1330_JBM_MEMORY - hTcBuffer->tc_buffer2_fx = NULL; - -#endif - 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; - } - } -#ifdef FIX_1330_JBM_MEMORY - - IF( hTcBuffer->tc_buffer2_fx != NULL ) - { - free( hTcBuffer->tc_buffer2_fx ); - hTcBuffer->tc_buffer2_fx = NULL; - } -#endif - } - - return; -} -#endif - -/*--------------------------------------------------------------------------* - * 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 */ -) -{ -#ifndef JBM_MEMORY_OPT - Word16 nsamp_to_allocate; -#endif - DECODER_TC_BUFFER_HANDLE hTcBuffer; - Word16 nMaxSlotsPerSubframe; -#ifdef JBM_MEMORY_OPT - ivas_error error; -#else - Word16 nchan_residual; - Word16 ch_idx; -#endif - Word16 tmp, tmp_e; - Word32 tmp32; - - /*-----------------------------------------------------------------* - * 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(); -#ifndef JBM_MEMORY_OPT - nchan_residual = sub( nchan_transport_internal, nchan_full ); -#endif - 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(); -#ifndef JBM_MEMORY_OPT - nsamp_to_allocate = 0; - move16(); -#endif - - tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); // Q0 - tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &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 ); - -#ifdef JBM_MEMORY_OPT - 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; - } -#else - { - Word16 n_samp_full, n_samp_residual; - Word32 offset; - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - n_samp_full = add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) ); - n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); - } - ELSE - { - /* n_samp_full = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */ - n_samp_full = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - n_samp_residual = 0; - move16(); - } - - nsamp_to_allocate = mult0( hTcBuffer->nchan_buffer_full, n_samp_full ); - nsamp_to_allocate = add( nsamp_to_allocate, mult0( nchan_residual, n_samp_residual ) ); - - IF( nsamp_to_allocate == 0 ) - { - hTcBuffer->tc_buffer_fx = NULL; - - FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - } - ELSE - { - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - /* note: the maximum buffer length is for OSBA DISC mode with ISMs -> 15*(1920+239)=32385 samples */ - 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" ) ); - } - set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate ); - - offset = 0; - move16(); - FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; - offset = L_add( offset, n_samp_full ); - } - FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; - offset = L_add( offset, n_samp_residual ); - } - FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - } - ELSE - { - hTcBuffer->tc_buffer_fx = NULL; - } - } - } -#endif - - 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 */ -) -{ -#ifdef NONBE_1324_TC_BUFFER_MEMOERY_KEEP - 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]; -#endif -#ifdef JBM_MEMORY_OPT - ivas_error error; -#else - Word16 nsamp_to_allocate, n_samp_full, n_samp_residual, offset, nchan_residual; - Word16 ch_idx; -#endif - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - move16(); - -#ifdef NONBE_1324_TC_BUFFER_MEMOERY_KEEP - 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 ); - } - } - -#endif - /* if granularity changes, adapt subframe_nb_slots */ - IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) ) - { - Word16 nMaxSlotsPerSubframeNew; - - nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); // 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(); -#ifndef JBM_MEMORY_OPT - nchan_residual = sub( nchan_transport_internal, nchan_full ); -#endif - hTcBuffer->n_samples_granularity = n_samples_granularity; - move16(); - -#ifdef JBM_MEMORY_OPT - /* 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; - } -#else - /* realloc buffers */ - IF( hTcBuffer->tc_buffer_fx != NULL ) - { - free( hTcBuffer->tc_buffer_fx ); - hTcBuffer->tc_buffer_fx = NULL; - } - - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - n_samp_full = ( add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) ) ); - n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 ); - } - ELSE - { - n_samp_full = extract_l( Mult_32_16( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); - n_samp_residual = 0; - move16(); - } - - nsamp_to_allocate = imult1616( hTcBuffer->nchan_buffer_full, n_samp_full ); - nsamp_to_allocate = add( nsamp_to_allocate, imult1616( nchan_residual, n_samp_residual ) ); - - IF( nsamp_to_allocate == 0 ) - { - hTcBuffer->tc_buffer_fx = NULL; - FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - } - ELSE - { - IF( st_ivas->hDecoderConfig->Opt_tsm ) - { - 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" ) ); - } - set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate ); - - offset = 0; - move16(); - FOR( ch_idx = 0; ch_idx < 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 < hTcBuffer->nchan_transport_internal; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset]; - offset = add( offset, n_samp_residual ); - } - FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ ) - { - hTcBuffer->tc_fx[ch_idx] = NULL; - } - } - ELSE - { - hTcBuffer->tc_buffer_fx = NULL; - } - } -#endif - -#ifdef NONBE_1324_TC_BUFFER_MEMOERY_KEEP - /* 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 ); - } - -#endif - 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++ ) - { -#ifdef FIX_1330_JBM_MEMORY - output_fx[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered; - move32(); -#else - Copy32( st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered, output_fx[ch_idx], *nSamplesRendered ); -#endif - } - - 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 */ -) -{ -#ifndef JBM_MEMORY_OPT - Word16 i; -#endif - IF( *phTcBuffer != NULL ) - { -#ifdef JBM_MEMORY_OPT - ivas_jbm_dec_tc_audio_deallocate_fx( *phTcBuffer ); -#else - - FOR( i = 0; i < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; i++ ) - { - ( *phTcBuffer )->tc_fx[i] = NULL; - } - - IF( ( *phTcBuffer )->tc_buffer_fx != NULL ) - { - free( ( *phTcBuffer )->tc_buffer_fx ); - ( *phTcBuffer )->tc_buffer_fx = NULL; - } -#endif - - 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, exp, 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_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); - tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp ); - nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); // 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, &exp ); - nSlotsAvailable = shr( tmp, sub( 15, exp ) ); // 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; - 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_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; - 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, 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(); - } - -#ifdef NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES - 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 - } - } - } -#endif - - 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 - } - } - 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 ); - // TODO: check if tis is a bug in main already - } - - 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..f99237f46004c3ec097b169c1b868af2dade4c2d 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" @@ -1002,10 +1001,18 @@ void ivas_lfe_tdplc_fx( Copy_Scale_sig_32_16( rec_frame_fx, rec_frame_16_fx, LFE_PLC_RECLEN, -Q5 ); // Q0 Word16 Q_new_inp, mem_decim_size, size_modified; +#ifndef FIX_2410_HARM_MODIF_FS size_modified = modify_Fs_ivas_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); +#else + size_modified = modify_Fs_fx( prevsynth_16_fx + LFE_PLC_BUFLEN - LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FDEL / LFE_PLC_DSF, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); +#endif Scale_sig( rec_frame_us_16_fx, size_modified, negate( Q_new_inp ) ); /* scaling back to Q0 */ +#ifndef FIX_2410_HARM_MODIF_FS size_modified = modify_Fs_ivas_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); +#else + size_modified = modify_Fs_fx( rec_frame_16_fx, LFE_PLC_RECLEN, LFE_PLC_FS, rec_frame_us_16_fx, 48000, mem_fx, 0, &Q_new_inp, &mem_decim_size ); +#endif Scale_sig( rec_frame_us_16_fx, size_modified, negate( Q_new_inp ) ); /* scaling back to Q0 */ /*samples are generated with 48k sampling rate 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 2b6ccf1efb578897cbea67f372004e34c2f05577..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; } @@ -1422,7 +1423,7 @@ static ivas_error init_lfe_synth_data_fx( /* Ring buffer for the filterbank of the LFE synthesis. * The filterbank is using moving average lowpass filter with the crossover of 120 Hz. */ /* bufferSize = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES ); */ - bufferSize = extract_l( Mpy_32_32_r( output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); + bufferSize = extract_l( Mpy_32_16_1( output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); IF( ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer_fx = (Word32 *) malloc( bufferSize * sizeof( Word32 ) ) ) == NULL ) { @@ -1689,13 +1690,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( Decoder_State **sts; UWord32 ivas_total_brate, last_ivas_total_brate; Word16 numCldfbAnalyses_old, numCldfbSyntheses_old; -#ifdef FIX_NCHAN_BUFFERS -#ifdef FIX_1330_JBM_MEMORY Word16 nchan_out_buff; -#else - Word16 nchan_out_buff_old, nchan_out_buff; -#endif -#endif ivas_error error; Word32 ism_total_brate; Word16 pos_idx; @@ -1704,11 +1699,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( move32(); last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; move32(); -#ifdef FIX_NCHAN_BUFFERS -#ifndef FIX_1330_JBM_MEMORY - nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); -#endif -#endif test(); test(); @@ -1947,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; @@ -1955,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(); @@ -1976,7 +1966,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( } ELSE { -#ifdef FIX_NCHAN_BUFFERS tc_nchan_to_allocate = BINAURAL_CHANNELS; move16(); test(); @@ -1985,9 +1974,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; move16(); } -#else - tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); -#endif } test(); @@ -2021,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; } @@ -2054,7 +2042,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( } } -#ifdef FIX_NCHAN_BUFFERS /*-----------------------------------------------------------------* * output audio buffers *-----------------------------------------------------------------*/ @@ -2063,17 +2050,12 @@ ivas_error ivas_masa_dec_reconfigure_fx( IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) /* note: switching with OMASA is addressed in ivas_omasa_dec_config() */ { nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); -#ifdef FIX_1330_JBM_MEMORY 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 ) -#else - IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) -#endif { return error; } } -#endif return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index 619d1e3f8c6db25396df32809790b736cc4e3602..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 /*-----------------------------------------------------------------------* @@ -461,7 +456,8 @@ ivas_error ivas_param_mc_dec_open_fx( test(); 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 || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + 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 || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) ) { IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL ) { @@ -527,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; } @@ -1524,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; @@ -1646,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 ); @@ -2203,16 +2199,11 @@ void ivas_param_mc_dec_render_fx( { FOR( ch = 0; ch < nchan_out_cldfb; ch++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], hParamMC->num_freq_bands ); -#else - Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands ); - Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands ); -#endif } } } @@ -2617,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; @@ -3151,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 ); @@ -3404,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 fd0bb54ccf39fe069de97dd955abdd04af703f69..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; @@ -381,7 +377,11 @@ ivas_error ivas_mc_paramupmix_dec_open( } /* Head or external rotation */ - 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 || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + test(); + test(); + 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 || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) ) { IF( ( hMCParamUpmix->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL ) @@ -399,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 ) { @@ -412,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(); @@ -435,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; } @@ -496,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 */ @@ -561,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]; @@ -591,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; @@ -901,16 +901,11 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], maxBand ); -#else - Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_index_start, slot_idx )], maxBand ); - Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_index_start, slot_idx )], maxBand ); -#endif } } } 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 f11cc8ac5084d040af6027368ce03a90ef9ae040..dd889e83b3c2ab415635b729a742bcb0c5feb988 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,36 @@ 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 + test(); + IF( !st_ivas->bfi && NE_16( hCPE->hCoreCoder[n]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + { + 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,16 +354,6 @@ ivas_error ivas_mct_dec_fx( } /* Postprocessing for ACELP/MDCT core switching and synchronization */ - Word16 output_mem_fx[L_FRAME48k]; - IF( hCPE->output_mem_fx[1] != NULL ) - { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA_FX2( sts[n]->output_Fs, 3125000 ), -Q11 ); - } - ELSE - { - set16_fx( output_mem_fx, 0, NS2SA_FX2( sts[n]->output_Fs, 3125000 ) ); - } - Word16 Q_synth = sub( 15, e_sig[n] ); move16(); @@ -366,7 +367,8 @@ 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 ) ) + + 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 ) ) { return error; } @@ -383,7 +385,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 +704,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,23 +900,18 @@ 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; -#ifdef FIX_1330_JBM_MEMORY Word16 nchan_out_buff; -#else - Word16 nchan_out_buff_old, nchan_out_buff; -#endif + hTcBuffer = st_ivas->hTcBuffer; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); nchan_transport_old = st_ivas->nchan_transport; move16(); -#ifndef FIX_1330_JBM_MEMORY - nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); -#endif last_mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ /* temporally set the current mc_mode back to the previous one to make sure the following call to @@ -956,45 +953,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 ) ) { @@ -1375,7 +1372,8 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_binRenderer_close_fx( &st_ivas->hBinRenderer ); test(); - IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + test(); + IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) ) { efap_free_data_fx( &st_ivas->hEFAPdata ); } @@ -1531,16 +1529,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; @@ -1550,7 +1545,6 @@ static ivas_error ivas_mc_dec_reconfig_fx( 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 ) ) { -#ifdef FIX_NCHAN_BUFFERS tc_nchan_allocate_new = BINAURAL_CHANNELS; move16(); test(); @@ -1563,10 +1557,6 @@ static ivas_error ivas_mc_dec_reconfig_fx( { tc_nchan_allocate_new = add( tc_nchan_allocate_new, 1 ); } -#else - tc_nchan_allocate_new = BINAURAL_CHANNELS * 2; - move16(); -#endif tc_nchan_full_new = tc_nchan_allocate_new; move16(); } @@ -1603,39 +1593,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 ); } } @@ -1644,11 +1635,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( *-----------------------------------------------------------------*/ nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); -#ifdef FIX_1330_JBM_MEMORY - 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 ) -#else - IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) -#endif + 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 b951258852201ff1da3b8077675d4bf8cfc2e630..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" @@ -185,6 +180,13 @@ static void dec_prm_tcx_sidebits_fx( move16(); } + /* for first frame reset last_core to initialization value for better error-robustness*/ + IF( EQ_16( st->ini_frame, 0 ) ) + { + st->last_core = TCX_20_CORE; + move16(); + } + getTCXWindowing_ivas_fx( st->core, st->last_core, st->element_mode, st->hTcxCfg, st0 ); st->hTcxDec->kernel_type[0] = st->hTcxDec->kernel_type[1] = MDCT_IV; @@ -699,9 +701,7 @@ void ivas_mdct_core_invQ_fx( set16_fx( bitsRead, 0, CPE_CHANNELS ); tmp_concealment_method = 0; move16(); -#ifdef FIX_1387_INIT_PRM_SQQ prm_sqQ = NULL; /* set prm_sqQ to NULL - in case of bfi == 1 it's not set or needed, but it triggers sanitizers */ -#endif FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -1104,11 +1104,7 @@ void ivas_mdct_core_reconstruct_fx( Word16 L_frame_global[CPE_CHANNELS], L_frame_globalTCX[CPE_CHANNELS]; /* Synth */ -#ifdef FIX_1320_STACK_CPE_DECODER Word16 synth_buf_fx[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M]; -#else - Word16 synth_buf_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; -#endif Word16 *synth_fx; Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB_fx; @@ -1179,11 +1175,7 @@ void ivas_mdct_core_reconstruct_fx( } q_syn = st->hTcxDec->q_old_synth; move16(); -#ifdef FIX_1320_STACK_CPE_DECODER set16_fx( synth_fx, 0, L_FRAME_PLUS_INTERNAL + M ); -#else - set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); -#endif set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); IF( st->core != ACELP_CORE ) { @@ -1273,11 +1265,7 @@ void ivas_mdct_core_reconstruct_fx( // norm(synth_buf) >= q_syn - q_win // norm(synth_buf) + q_win >= q_syn -#ifdef FIX_1320_STACK_CPE_DECODER sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS_INTERNAL ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); -#else - sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); -#endif q_syn = add( sub( sf, 1 ), s_min( q_win, q_winFB ) ); st->Q_syn = q_syn; move16(); @@ -1287,12 +1275,8 @@ void ivas_mdct_core_reconstruct_fx( sf = s_min( getScaleFactor16( st->hHQ_core->old_out_fx, L_FRAME48k ), getScaleFactor16( st->hHQ_core->old_out_LB_fx, L_FRAME32k ) ); st->Q_syn = add( sf, s_min( q_win, q_winFB ) ); -#ifdef FIX_1320_STACK_CPE_DECODER Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS_INTERNAL ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn -#else - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn -#endif - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn // Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->syn, M + 1, sub( st->Q_syn, q_win ) ); @@ -1422,16 +1406,9 @@ void ivas_mdct_core_reconstruct_fx( Copy_Scale_sig_16_32_no_sat( st->p_bpf_noise_buf, st->p_bpf_noise_buf_32, st->L_frame, Q11 ); // Q0 -> Q11 } -#ifndef FIX_938_COMPILER_WARNING - IF( signal_outFB_fx[ch] != NULL ) - { -#endif - Copy( synthFB_fx, signal_outFB_fx[ch], st->hTcxDec->L_frameTCX ); - e_sig[ch] = sub( 15, q_syn + st->Q_syn_factor ); - move16(); -#ifndef FIX_938_COMPILER_WARNING - } -#endif + Copy( synthFB_fx, signal_outFB_fx[ch], st->hTcxDec->L_frameTCX ); + e_sig[ch] = sub( 15, q_syn + st->Q_syn_factor ); + move16(); /* updates */ st->last_voice_factor_fx = 0; @@ -1701,7 +1678,6 @@ void ivas_mdct_core_tns_ns_fx( q_x = add( q_x, 1 ); } -#ifdef NONBE_FIX_1376_MDCT_CONCEALMENT /* 2025-09-07, mul: in case of PLC, applying SNS up to L_spec might not be enough: In case the transition frame from DTX after an inactive period is lost, L_spec is assumed to represent a regular TCX frame, @@ -1709,9 +1685,6 @@ void ivas_mdct_core_tns_ns_fx( in case this is not necessary, x[] is filled with zeros, and the multiplication is not causing any additional harm */ v_multc_fx( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sub( s_max( L_spec[ch], L_frameTCX[ch] ), st->hTcxCfg->psychParamsCurrent->nBins ) ); -#else - v_multc_fx( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sub( L_spec[ch], st->hTcxCfg->psychParamsCurrent->nBins ) ); -#endif q_2 = sub( add( q_x, q_sns_int_scf ), 31 ); Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, sub( q_2, q_x ) ); diff --git a/lib_dec/ivas_mono_dmx_renderer_fx.c b/lib_dec/ivas_mono_dmx_renderer_fx.c index 6c64eee816fc5cfbb4db6c676a09e080e004d4bc..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" @@ -317,10 +313,10 @@ void ivas_mono_stereo_downmix_mcmasa_fx( *------------------------------------------------------------------------*/ void ivas_apply_non_diegetic_panning_fx( - Word32 *input_f_fx, /* i : non-diegetic object */ - Word32 *output_fx[], /* o: core-coder transport mono channel/stereo output */ - const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain Q15*/ - const Word16 output_frame /* i : output frame length per channel Q11*/ + Word32 *input_f_fx, /* i : non-diegetic object (mono channel) */ + Word32 *output_fx[], /* o : stereo output channels */ + const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain Q15*/ + const Word16 output_frame /* i : output frame length per channel */ ) { Word16 pan_left_fx, pan_right_fx; 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 30f307731929f1f28f8c7ad8f9ff2fad660f5219..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,32 +32,22 @@ #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" /*------------------------------------------------------------------------- * Local constants *------------------------------------------------------------------------*/ -#ifdef FIX_2082_FP_LEFTOVERS_OMASA_DEC #define MULT_17_DIV_20_Q15 27853 /* (Word16) ( ( 17.0/20.0 ) * 2^15 + 0.5 ) */ #define MULT_1_DIV_CLDFB_NO_COL_MAX_Q15 2048 /* (Word16) ( ( 1.0 / CLDFB_NO_COL_MAX ) * 2^15 + 0.5 ) */ #define ONEMINUX_EXT_RENDER_IIR_FAC_Q31 107374182 /* (Word32) ( ( 1.0 - 0.95 ) * 2^31 + 0.5f ); 0.95 is EXT_RENDER_IIR_FAC */ #define EXT_RENDER_IIR_FAC_Q31 2040109465 /* (Word32) ( 0.95 * 2^31 + 0.5 ) */ -#else -#define EXT_RENDER_IIR_FAC 0.95f -#define MULT_17_DIV_20_Q15 ( Word16 )( ( 17.0 / 20.0f ) * pow( 2, 15 ) + 0.5f ) -#define MULT_1_DIV_CLDFB_NO_COL_MAX_Q15 ( Word16 )( ( 1.0 / CLDFB_NO_COL_MAX ) * pow( 2, 15 ) + 0.5f ) -#define ONEMINUX_EXT_RENDER_IIR_FAC_Q31 ( Word32 )( ( 1.0f - EXT_RENDER_IIR_FAC ) * pow( 2, 31 ) + 0.5f ) -#define EXT_RENDER_IIR_FAC_Q31 ( Word32 )( EXT_RENDER_IIR_FAC * pow( 2, 31 ) + 0.5f ) -#endif // Calculated as (Word16)(((1.0f / (50 * MAX_PARAM_SPATIAL_SUBFRAMES)) * pow(2, 15)) + 0.5f) #define OMASA_DELAYFRAMES_PER_SEC_Q15 (Word16) 164 // Q15 @@ -354,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; @@ -497,11 +491,7 @@ ivas_error ivas_omasa_dec_config_fx( Word32 brate_SCE, brate_CPE; ISM_MODE ism_mode_old; IVAS_FORMAT ivas_format_orig; -#ifdef FIX_1330_JBM_MEMORY Word16 nchan_out_buff; -#else - Word16 nchan_out_buff, nchan_out_buff_old; -#endif ivas_error error; RENDERER_TYPE old_renderer_type; @@ -522,10 +512,6 @@ ivas_error ivas_omasa_dec_config_fx( st_ivas->ivas_format = st_ivas->last_ivas_format; move16(); ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); -#ifndef FIX_1330_JBM_MEMORY - nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); - move16(); -#endif st_ivas->ivas_format = ivas_format_orig; move16(); @@ -670,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(); @@ -681,7 +667,7 @@ ivas_error ivas_omasa_dec_config_fx( { set_s( hMasaIsmData->azimuth_ism_fx[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); set_s( hMasaIsmData->elevation_ism_fx[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); - FOR( int16_t sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ ) + FOR( Word16 sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ ) { set_l( hMasaIsmData->energy_ratio_ism_fx[obj_idx][sf], 0, CLDFB_NO_CHANNELS_MAX ); } @@ -726,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 ); } } @@ -747,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; } @@ -755,9 +741,8 @@ 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 ); } -#ifdef NONBE_1324_TC_BUFFER_MEMOERY_KEEP IF( EQ_32( old_renderer_type, RENDERER_MONO_DOWNMIX ) ) { @@ -769,7 +754,6 @@ ivas_error ivas_omasa_dec_config_fx( Scale_sig32( hTcBuffer->tc_buffer_old_fx[k], n_samples_still_available, st_ivas->hCPE[0]->q_output_mem_fx[0] - Q11 ); } } -#endif } IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) @@ -834,11 +818,7 @@ ivas_error ivas_omasa_dec_config_fx( *-----------------------------------------------------------------*/ nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ); -#ifdef FIX_1330_JBM_MEMORY 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 ) -#else - IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -1099,108 +1079,74 @@ 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; -#ifndef FIX_1330_JBM_MEMORY - Word16 slots_rendered; -#endif Word16 n; Word32 data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; -#ifndef FIX_1330_JBM_MEMORY + *nSamplesRendered = s_min( nSamplesAsked, st_ivas->hTcBuffer->n_samples_available ); + test(); - IF( !st_ivas->hDecoderConfig->Opt_tsm ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#endif - *nSamplesRendered = s_min( nSamplesAsked, st_ivas->hTcBuffer->n_samples_available ); + Copy32( &output_fx[CPE_CHANNELS][st_ivas->hTcBuffer->n_samples_rendered], data_separated_objects[0], *nSamplesRendered ); - test(); - IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) - { - Copy32( &output_fx[CPE_CHANNELS][st_ivas->hTcBuffer->n_samples_rendered], data_separated_objects[0], *nSamplesRendered ); - -#ifdef NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES - IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) -#else -#ifdef FIX_1330_JBM_MEMORY - IF( !st_ivas->hDecoderConfig->Opt_tsm && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) -#else IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) -#endif -#endif + { + /* Gain separated object, if edited */ + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - /* Gain separated object, if edited */ - FOR( n = 0; n < st_ivas->nchan_ism; n++ ) + test(); + IF( st_ivas->hMasaIsmData->ism_gain_is_edited[n] && EQ_16( st_ivas->hMasaIsmData->idx_separated_ism, n ) ) { - test(); - IF( st_ivas->hMasaIsmData->ism_gain_is_edited[n] && EQ_16( st_ivas->hMasaIsmData->idx_separated_ism, n ) ) - { - v_multc_fx_16( data_separated_objects[0], st_ivas->hMasaIsmData->gain_ism_edited_fx[n], data_separated_objects[0], *nSamplesRendered ); // Q = 8 - Scale_sig32( data_separated_objects[0], *nSamplesRendered, Q3 ); // Q = 11 - } + v_multc_fx_16( data_separated_objects[0], st_ivas->hMasaIsmData->gain_ism_edited_fx[n], data_separated_objects[0], *nSamplesRendered ); // Q = 8 + Scale_sig32( data_separated_objects[0], *nSamplesRendered, Q3 ); // Q = 11 } } } - ELSE + } + ELSE + { + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - FOR( n = 0; n < st_ivas->nchan_ism; n++ ) - { - Copy32( &output_fx[n + CPE_CHANNELS][st_ivas->hTcBuffer->n_samples_rendered], data_separated_objects[n], *nSamplesRendered ); - - /* Gain discrete objects, if edited */ -#ifdef NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES - IF( st_ivas->hMasaIsmData->ism_gain_is_edited[n] ) -#else -#ifdef FIX_1330_JBM_MEMORY - IF( !st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hMasaIsmData->ism_gain_is_edited[n] ) -#else + Copy32( &output_fx[n + CPE_CHANNELS][st_ivas->hTcBuffer->n_samples_rendered], data_separated_objects[n], *nSamplesRendered ); + + /* Gain discrete objects, if edited */ IF( st_ivas->hMasaIsmData->ism_gain_is_edited[n] ) -#endif -#endif - { - v_multc_fx_16( data_separated_objects[n], st_ivas->hMasaIsmData->gain_ism_edited_fx[n], data_separated_objects[n], *nSamplesRendered ); // Q = 8 - Scale_sig32( data_separated_objects[n], *nSamplesRendered, Q3 ); // Q = 11 - } + { + v_multc_fx_16( data_separated_objects[n], st_ivas->hMasaIsmData->gain_ism_edited_fx[n], data_separated_objects[n], *nSamplesRendered ); // Q = 8 + Scale_sig32( data_separated_objects[n], *nSamplesRendered, Q3 ); // Q = 11 } + } - /* Gain MASA part, if edited in G192. MASA gaining with VOIP is done in ivas_dec_prepare_renderer() */ -#ifdef FIX_1330_JBM_MEMORY - IF( !st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hMasaIsmData->masa_gain_is_edited ) -#else - IF( st_ivas->hMasaIsmData->masa_gain_is_edited ) -#endif + /* Gain MASA part, if edited in G192. MASA gaining with VOIP is done in ivas_dec_prepare_renderer() */ + IF( !st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hMasaIsmData->masa_gain_is_edited ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) { - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - v_multc_fx_16( output_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, output_fx[n], *nSamplesRendered ); // Q = 8 - Scale_sig32( output_fx[n], *nSamplesRendered, Q3 ); // Q = 11 - } + v_multc_fx_16( output_fx[n], st_ivas->hMasaIsmData->gain_masa_edited_fx, output_fx[n], *nSamplesRendered ); // Q = 8 + Scale_sig32( output_fx[n], *nSamplesRendered, Q3 ); // Q = 11 } } -#ifndef FIX_1330_JBM_MEMORY } -#endif subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; move16(); -#ifndef FIX_1330_JBM_MEMORY - slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; - move16(); -#endif ivas_dirac_dec_render_fx( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_fx ); @@ -1209,11 +1155,7 @@ void ivas_omasa_dirac_rend_jbm_fx( scale_sig32( st_ivas->hIsmRendererData->prev_gains_fx[ind1], MAX_OUTPUT_CHANNELS, -1 ); // Q30 -> Q29 } -#ifdef FIX_1330_JBM_MEMORY - ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects, output_fx, subframes_rendered ); -#else - ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects, output_fx, subframes_rendered, slots_rendered ); -#endif + 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++ ) { @@ -1227,30 +1169,23 @@ 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; ivas_error error; Word32 *p_sepobj_fx[BINAURAL_CHANNELS]; // Q11 Word32 data_separated_objects_fx[BINAURAL_CHANNELS][L_FRAME48k]; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *re, *im; -#else - Word16 slot_idx_start; - - slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered; - move16(); -#endif FOR( n = 0; n < BINAURAL_CHANNELS; n++ ) { @@ -1310,15 +1245,10 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( Scale_sig32( Cldfb_RealBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) ); Scale_sig32( Cldfb_ImagBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, sub( slot_idx, cldfb_slots ) ); + v_add_fx( re, Cldfb_RealBuffer, re, num_cldfb_bands ); v_add_fx( im, Cldfb_ImagBuffer, im, num_cldfb_bands ); -#else - /* note: this intentionally differs from OSBA by: no scaling by 0.5 */ - v_add_fx( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][slot_idx_start + slot_idx], Cldfb_RealBuffer, st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][slot_idx_start + slot_idx], num_cldfb_bands ); - v_add_fx( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][slot_idx_start + slot_idx], Cldfb_ImagBuffer, st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][slot_idx_start + slot_idx], num_cldfb_bands ); -#endif } } } @@ -2200,19 +2130,11 @@ void ivas_omasa_render_objects_from_mix_fx( outSlotImPr = &( outIm[n][slot][0] ); move32(); move32(); -#ifdef FIX_2092_ASSERT_IN_OMASA_RENDER mantissa_exp_to_qvalue( &outRe_exp[n][slot][0], &outRe[n][slot][0], Q20 + Q2, nBins ); // + Q2: add two bits headroom to prevent overflow in cldfbSynthesis_ivas_fx(). mantissa_exp_to_qvalue( &outIm_exp[n][slot][0], &outIm[n][slot][0], Q20 + Q2, nBins ); cldfbSynthesis_ivas_fx( &outSlotRePr, &outSlotImPr, &rendered_objects[n][index], nBins, 0, 1 + Q2, st_ivas->cldfbSynDec[index2] ); -#else - mantissa_exp_to_qvalue( &outRe_exp[n][slot][0], &outRe[n][slot][0], Q20, nBins ); - mantissa_exp_to_qvalue( &outIm_exp[n][slot][0], &outIm[n][slot][0], Q20, nBins ); - - cldfbSynthesis_ivas_fx( &outSlotRePr, &outSlotImPr, &rendered_objects[n][index], - nBins, 0, 1, st_ivas->cldfbSynDec[index2] ); -#endif } } diff --git a/lib_dec/ivas_osba_dec_fx.c b/lib_dec/ivas_osba_dec_fx.c index 07570b86697e4ffdcd7694ef93e5308b8348e327..b3bf1b1c2a849da7f053bfac56f3439a7ef383e9 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; @@ -137,14 +137,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( Word32 output_separated_objects_fx[BINAURAL_CHANNELS][L_FRAME48k]; Word32 *p_sepobj_fx[BINAURAL_CHANNELS]; Word16 channel_offset; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *re, *im; -#else - Word16 slot_idx_start; - - slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered; - move16(); -#endif FOR( Word16 i = 0; i < BINAURAL_CHANNELS; i++ ) { @@ -168,9 +161,6 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( IF( 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 ) ) { Word16 slot_idx, num_cldfb_bands, nchan_transport_orig; -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - Word16 b; -#endif Word16 cldfb_slots; Word32 Cldfb_RealBuffer[CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer[CLDFB_NO_CHANNELS_MAX]; @@ -198,6 +188,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( sub( st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->p_filter_length, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->no_channels ), sub( q_cldfb, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->Q_cldfb_state ) ); st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->Q_cldfb_state = q_cldfb; + FOR( slot_idx = 0; slot_idx < cldfb_slots; slot_idx++ ) { q_cldfb = q_in; @@ -206,22 +197,10 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( Scale_sig32( Cldfb_RealBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) ); Scale_sig32( Cldfb_ImagBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, sub( slot_idx, cldfb_slots ) ); + v_add_fx( re, Cldfb_RealBuffer, re, num_cldfb_bands ); v_add_fx( im, Cldfb_ImagBuffer, im, num_cldfb_bands ); -#else - FOR( b = 0; b < num_cldfb_bands; b++ ) - { - st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][slot_idx_start + slot_idx][b] = - L_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], Cldfb_RealBuffer[b] ); - move32(); - - st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][slot_idx_start + slot_idx][b] = - L_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], Cldfb_ImagBuffer[b] ); - move32(); - } -#endif } } } @@ -296,69 +275,35 @@ ivas_error ivas_osba_render_sf_fx( ) { Word16 n; -#ifdef FIX_1330_JBM_MEMORY Word32 output_sba[MAX_OUTPUT_CHANNELS][L_FRAME48k]; Word32 *p_output_sba[MAX_OUTPUT_CHANNELS]; -#else - Word32 output_ism[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 *p_output_ism[MAX_OUTPUT_CHANNELS]; -#endif ivas_error error; FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { -#ifdef FIX_1330_JBM_MEMORY p_output_sba[n] = output_sba[n]; -#else - p_output_ism[n] = &output_ism[n][0]; -#endif } -#ifndef FIX_1330_JBM_MEMORY - if ( !st_ivas->hDecoderConfig->Opt_tsm ) - { - Word16 tc_offset; - tc_offset = st_ivas->hTcBuffer->n_samples_rendered; - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - v_shr( &p_output[n][tc_offset], Q11 - Q11, &output_ism[n][tc_offset], nSamplesAsked ); // Q11 - } - } -#endif -#ifdef FIX_1330_JBM_MEMORY IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output_sba ) ) != IVAS_ERR_OK ) -#else - IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output ) ), IVAS_ERR_OK ) ) -#endif { return error; } IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { -#ifdef FIX_1330_JBM_MEMORY ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered ); -#else - ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_ism, *nSamplesRendered ); -#endif } FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) { IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { -#ifdef FIX_1330_JBM_MEMORY v_add_fx_no_hdrm( p_output[n], p_output_sba[n], p_output[n], *nSamplesRendered ); -#else - v_add_fx_no_hdrm( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered ); -#endif } -#ifdef FIX_1330_JBM_MEMORY ELSE { Copy32( p_output_sba[n], p_output[n], *nSamplesRendered ); } -#endif } return IVAS_ERR_OK; @@ -374,7 +319,11 @@ ivas_error ivas_osba_render_sf_fx( void ivas_osba_stereo_add_channels_fx( Word32 *tc_fx[], /* i : transport channels */ Word32 *output_fx[], /* i/o: output channels */ +#ifdef FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT + const Word32 gain, /* i : gain bed value */ +#else const Word32 gain_bed_fx, /* i : gain bed value */ +#endif const Word16 nchan_out, /* i : number of output channels */ const Word16 nchan_ism, /* i : number of ISM channels */ #ifndef FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT @@ -388,10 +337,9 @@ void ivas_osba_stereo_add_channels_fx( #ifndef FIX_2196_UNREACHABLE_CODE_IN_OSBA_STEREO_OUTPUT IF( EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { -#endif Word32 gain = gain_bed_fx; move32(); - +#endif test(); IF( NE_32( gain, ONE_IN_Q29 ) && GT_32( gain, 0 ) ) { 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 1958cea41b4de72853657e0f826a601d5e96ed33..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 @@ -43,6 +43,7 @@ * * Select and configure IVAS renderer parameters *-------------------------------------------------------------------------*/ + void ivas_renderer_select( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -70,7 +71,8 @@ void ivas_renderer_select( *-----------------------------------------------------------------*/ test(); - IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + test(); + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = -1; move16(); @@ -87,7 +89,17 @@ void ivas_renderer_select( test(); test(); test(); - IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) + { + *renderer_type = RENDERER_NON_DIEGETIC_DOWNMIX; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) + { + *renderer_type = RENDERER_DISABLE; + move16(); + } + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { @@ -163,7 +175,8 @@ void ivas_renderer_select( } test(); - IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + test(); + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) { nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); test(); @@ -220,7 +233,8 @@ void ivas_renderer_select( test(); test(); test(); - IF( ( EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) + test(); + IF( ( EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { *renderer_type = RENDERER_BINAURAL_OBJECTS_TD; move16(); @@ -239,7 +253,8 @@ void ivas_renderer_select( } test(); - IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) + test(); + IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) { /* force HOA3 domain for rotation*/ *internal_config = IVAS_AUDIO_CONFIG_HOA3; @@ -268,23 +283,29 @@ 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 ) ) { - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { *renderer_type = RENDERER_NON_DIEGETIC_DOWNMIX; move16(); } - } - ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) - { - test(); - test(); - IF( NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + 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, 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( st_ivas->ivas_format, ISM_FORMAT ) ) { @@ -629,25 +650,17 @@ RENDERER_TYPE ivas_renderer_secondary_select_fx( test(); test(); test(); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP test(); 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_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) -#else - 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_BINAURAL ) ) -#endif { renderer_type = RENDERER_BINAURAL_OBJECTS_TD; move32(); } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) -#else - ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) -#endif { renderer_type = RENDERER_BINAURAL_OBJECTS_TD; move32(); 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 ae0ccf31ce837c7488dc9683bad2da8e4fd0a18e..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 */ @@ -85,10 +82,10 @@ const Word16 dft_alpha_s2_b2_fx[STEREO_DFT_BAND_MAX] = }; const Word32 dft_bpf_weights_fx[] = { - 1073784832, 1068033792, 1050938752, 1022962432, 984855360, 937628928, 882514816, 820918592, 754369152, - 684457792, 612788736, 540921088, 470318240, 402303136, 338025728, 278428768, 224238096, 175948704, 133830104, - 97937064, 68129992, 44097504, 25391846, 11456825, 1667521, 4637491, 8128225, 9447854, 9195525, 7903813, - 6026913, 3934190, 1908039, 148176, 1226213, 2159294, 2654289, 2754147, 2529735, 2071248 + 1073784832, 1068033792, 1050938752, 1022962432, 984855360, 937628928, 882514816, 820918592, 754369152, + 684457792, 612788736, 540921088, 470318240, 402303136, 338025728, 278428768, 224238096, 175948704, 133830104, + 97937064, 68129992, 44097504, 25391846, 11456825, 1667521, 4637491, 8128225, 9447854, 9195525, 7903813, + 6026913, 3934190, 1908039, 148176, 1226213, 2159294, 2654289, 2754147, 2529735, 2071248 }; const Word32 dft_ap_gains_fx[5][3] = @@ -119,76 +116,76 @@ const Word16 dft_res_pred_weights_fx[][STEREO_DFT_BAND_MAX] = const Word16 dft_win232ms_8k_fx[75] = { - 343, 1029, 1714, 2399, 3083, 3766, 4447, 5126, 5802, 6476, 7148, 7816, 8480, 9141, 9798, 10451, 11099, 11742, 12381, 13013, 13640, 14261, 14876, 15484, 16085, 16680, 17267, - 17846, 18418, 18981, 19537, 20083, 20621, 21150, 21669, 22179, 22680, 23170, 23650, 24120, 24579, 25028, 25465, 25891, 26306, 26710, 27101, 27481, 27849, 28204, 28547, 28878, - 29196, 29501, 29793, 30072, 30338, 30591, 30830, 31056, 31268, 31466, 31651, 31822, 31978, 32121, 32250, 32364, 32464, 32550, 32622, 32680, 32723, 32751, 32766 + 343, 1029, 1714, 2399, 3083, 3766, 4447, 5126, 5802, 6476, 7148, 7816, 8480, 9141, 9798, 10451, 11099, 11742, 12381, 13013, 13640, 14261, 14876, 15484, 16085, 16680, 17267, + 17846, 18418, 18981, 19537, 20083, 20621, 21150, 21669, 22179, 22680, 23170, 23650, 24120, 24579, 25028, 25465, 25891, 26306, 26710, 27101, 27481, 27849, 28204, 28547, 28878, + 29196, 29501, 29793, 30072, 30338, 30591, 30830, 31056, 31268, 31466, 31651, 31822, 31978, 32121, 32250, 32364, 32464, 32550, 32622, 32680, 32723, 32751, 32766 }; const Word16 dft_win232ms_12k8_fx[120] = { - 214, 643, 1072, 1500, 1929, 2357, 2784, 3211, 3638, 4064, 4489, 4914, 5337, 5760, 6182, 6602, 7022, 7440, 7857, 8273, 8687, 9100, 9512, 9921, 10329, 10735, 11140, - 11542, 11942, 12341, 12737, 13131, 13523, 13913, 14300, 14684, 15067, 15446, 15823, 16197, 16569, 16938, 17303, 17666, 18026, 18382, 18736, 19086, 19433, 19777, - 20117, 20454, 20787, 21117, 21443, 21766, 22084, 22399, 22711, 23018, 23321, 23620, 23916, 24207, 24494, 24777, 25055, 25330, 25599, 25865, 26126, 26383, 26635, - 26882, 27125, 27364, 27597, 27826, 28050, 28270, 28484, 28694, 28898, 29098, 29293, 29482, 29667, 29847, 30021, 30190, 30355, 30514, 30667, 30816, 30959, 31097, - 31229, 31357, 31478, 31595, 31706, 31811, 31912, 32006, 32095, 32179, 32257, 32330, 32397, 32458, 32514, 32565, 32610, 32649, 32683, 32711, 32733, 32750, 32761, 32767 + 214, 643, 1072, 1500, 1929, 2357, 2784, 3211, 3638, 4064, 4489, 4914, 5337, 5760, 6182, 6602, 7022, 7440, 7857, 8273, 8687, 9100, 9512, 9921, 10329, 10735, 11140, + 11542, 11942, 12341, 12737, 13131, 13523, 13913, 14300, 14684, 15067, 15446, 15823, 16197, 16569, 16938, 17303, 17666, 18026, 18382, 18736, 19086, 19433, 19777, + 20117, 20454, 20787, 21117, 21443, 21766, 22084, 22399, 22711, 23018, 23321, 23620, 23916, 24207, 24494, 24777, 25055, 25330, 25599, 25865, 26126, 26383, 26635, + 26882, 27125, 27364, 27597, 27826, 28050, 28270, 28484, 28694, 28898, 29098, 29293, 29482, 29667, 29847, 30021, 30190, 30355, 30514, 30667, 30816, 30959, 31097, + 31229, 31357, 31478, 31595, 31706, 31811, 31912, 32006, 32095, 32179, 32257, 32330, 32397, 32458, 32514, 32565, 32610, 32649, 32683, 32711, 32733, 32750, 32761, 32767 }; const Word16 dft_win232ms_16k_fx[150] = { - 171, 514, 857, 1200, 1543, 1886, 2228, 2570, 2912, 3254, 3595, 3936, 4277, 4617, 4956, 5295, 5633, 5971, 6308, 6644, 6980, 7315, 7649, 7982, 8315, 8646, 8977, 9306, - 9635, 9962, 10288, 10614, 10938, 11261, 11582, 11903, 12222, 12539, 12856, 13171, 13484, 13796, 14106, 14415, 14723, 15029, 15333, 15635, 15936, 16235, 16532, 16827, - 17121, 17412, 17702, 17990, 18276, 18559, 18841, 19121, 19399, 19674, 19947, 20219, 20487, 20754, 21019, 21281, 21540, 21798, 22053, 22305, 22556, 22803, 23048, 23291, - 23531, 23769, 24003, 24236, 24465, 24692, 24916, 25138, 25357, 25573, 25786, 25996, 26204, 26408, 26610, 26809, 27004, 27197, 27387, 27574, 27758, 27939, 28117, 28291, - 28463, 28631, 28797, 28959, 29118, 29273, 29426, 29575, 29722, 29864, 30004, 30140, 30273, 30403, 30529, 30652, 30772, 30888, 31001, 31110, 31216, 31319, 31418, 31514, - 31606, 31695, 31780, 31862, 31940, 32015, 32087, 32155, 32219, 32280, 32337, 32390, 32441, 32487, 32530, 32570, 32605, 32638, 32666, 32692, 32713, 32731, 32745, 32756, - 32763, 32767 + 171, 514, 857, 1200, 1543, 1886, 2228, 2570, 2912, 3254, 3595, 3936, 4277, 4617, 4956, 5295, 5633, 5971, 6308, 6644, 6980, 7315, 7649, 7982, 8315, 8646, 8977, 9306, + 9635, 9962, 10288, 10614, 10938, 11261, 11582, 11903, 12222, 12539, 12856, 13171, 13484, 13796, 14106, 14415, 14723, 15029, 15333, 15635, 15936, 16235, 16532, 16827, + 17121, 17412, 17702, 17990, 18276, 18559, 18841, 19121, 19399, 19674, 19947, 20219, 20487, 20754, 21019, 21281, 21540, 21798, 22053, 22305, 22556, 22803, 23048, 23291, + 23531, 23769, 24003, 24236, 24465, 24692, 24916, 25138, 25357, 25573, 25786, 25996, 26204, 26408, 26610, 26809, 27004, 27197, 27387, 27574, 27758, 27939, 28117, 28291, + 28463, 28631, 28797, 28959, 29118, 29273, 29426, 29575, 29722, 29864, 30004, 30140, 30273, 30403, 30529, 30652, 30772, 30888, 31001, 31110, 31216, 31319, 31418, 31514, + 31606, 31695, 31780, 31862, 31940, 32015, 32087, 32155, 32219, 32280, 32337, 32390, 32441, 32487, 32530, 32570, 32605, 32638, 32666, 32692, 32713, 32731, 32745, 32756, + 32763, 32767 }; const Word16 dft_win232ms_32k_fx[300] = { - 85, 257, 428, 600, 772, 943, 1115, 1286, 1457, 1629, 1800, 1971, 2143, 2314, 2485, 2656, 2827, 2998, 3169, 3339, 3510, 3681, 3851, 4021, 4192, 4362, 4532, 4701, 4871, - 5041, 5210, 5380, 5549, 5718, 5887, 6055, 6224, 6392, 6560, 6728, 6896, 7064, 7231, 7399, 7566, 7732, 7899, 8065, 8232, 8398, 8563, 8729, 8894, 9059, 9224, 9388, 9553, - 9717, 9880, 10044, 10207, 10370, 10532, 10695, 10857, 11019, 11180, 11341, 11502, 11662, 11823, 11982, 12142, 12301, 12460, 12618, 12777, 12934, 13092, 13249, 13406, - 13562, 13718, 13874, 14029, 14184, 14338, 14492, 14646, 14799, 14952, 15105, 15257, 15408, 15560, 15710, 15861, 16011, 16160, 16309, 16458, 16606, 16754, 16901, 17048, - 17194, 17340, 17485, 17630, 17774, 17918, 18062, 18204, 18347, 18489, 18630, 18771, 18911, 19051, 19191, 19329, 19468, 19605, 19743, 19879, 20015, 20151, 20286, 20420, - 20554, 20688, 20820, 20953, 21084, 21215, 21346, 21476, 21605, 21734, 21862, 21989, 22116, 22242, 22368, 22493, 22618, 22741, 22865, 22987, 23109, 23231, 23351, 23471, - 23591, 23709, 23828, 23945, 24062, 24178, 24293, 24408, 24522, 24636, 24749, 24861, 24972, 25083, 25193, 25302, 25411, 25519, 25626, 25733, 25839, 25944, 26048, 26152, - 26255, 26357, 26459, 26560, 26660, 26759, 26858, 26956, 27053, 27149, 27245, 27340, 27434, 27528, 27620, 27712, 27803, 27894, 27984, 28072, 28161, 28248, 28334, 28420, - 28505, 28589, 28673, 28756, 28837, 28918, 28999, 29078, 29157, 29235, 29312, 29388, 29464, 29538, 29612, 29685, 29758, 29829, 29900, 29969, 30038, 30106, 30174, 30240, - 30306, 30371, 30435, 30498, 30560, 30622, 30682, 30742, 30801, 30859, 30917, 30973, 31029, 31083, 31137, 31190, 31242, 31294, 31344, 31394, 31442, 31490, 31537, 31583, - 31629, 31673, 31717, 31759, 31801, 31842, 31882, 31921, 31960, 31997, 32033, 32069, 32104, 32138, 32171, 32203, 32234, 32265, 32294, 32323, 32351, 32377, 32403, 32428, - 32453, 32476, 32498, 32520, 32540, 32560, 32579, 32597, 32614, 32630, 32645, 32660, 32673, 32686, 32697, 32708, 32718, 32727, 32735, 32742, 32749, 32754, 32758, 32762, - 32765, 32766, 32767 + 85, 257, 428, 600, 772, 943, 1115, 1286, 1457, 1629, 1800, 1971, 2143, 2314, 2485, 2656, 2827, 2998, 3169, 3339, 3510, 3681, 3851, 4021, 4192, 4362, 4532, 4701, 4871, + 5041, 5210, 5380, 5549, 5718, 5887, 6055, 6224, 6392, 6560, 6728, 6896, 7064, 7231, 7399, 7566, 7732, 7899, 8065, 8232, 8398, 8563, 8729, 8894, 9059, 9224, 9388, 9553, + 9717, 9880, 10044, 10207, 10370, 10532, 10695, 10857, 11019, 11180, 11341, 11502, 11662, 11823, 11982, 12142, 12301, 12460, 12618, 12777, 12934, 13092, 13249, 13406, + 13562, 13718, 13874, 14029, 14184, 14338, 14492, 14646, 14799, 14952, 15105, 15257, 15408, 15560, 15710, 15861, 16011, 16160, 16309, 16458, 16606, 16754, 16901, 17048, + 17194, 17340, 17485, 17630, 17774, 17918, 18062, 18204, 18347, 18489, 18630, 18771, 18911, 19051, 19191, 19329, 19468, 19605, 19743, 19879, 20015, 20151, 20286, 20420, + 20554, 20688, 20820, 20953, 21084, 21215, 21346, 21476, 21605, 21734, 21862, 21989, 22116, 22242, 22368, 22493, 22618, 22741, 22865, 22987, 23109, 23231, 23351, 23471, + 23591, 23709, 23828, 23945, 24062, 24178, 24293, 24408, 24522, 24636, 24749, 24861, 24972, 25083, 25193, 25302, 25411, 25519, 25626, 25733, 25839, 25944, 26048, 26152, + 26255, 26357, 26459, 26560, 26660, 26759, 26858, 26956, 27053, 27149, 27245, 27340, 27434, 27528, 27620, 27712, 27803, 27894, 27984, 28072, 28161, 28248, 28334, 28420, + 28505, 28589, 28673, 28756, 28837, 28918, 28999, 29078, 29157, 29235, 29312, 29388, 29464, 29538, 29612, 29685, 29758, 29829, 29900, 29969, 30038, 30106, 30174, 30240, + 30306, 30371, 30435, 30498, 30560, 30622, 30682, 30742, 30801, 30859, 30917, 30973, 31029, 31083, 31137, 31190, 31242, 31294, 31344, 31394, 31442, 31490, 31537, 31583, + 31629, 31673, 31717, 31759, 31801, 31842, 31882, 31921, 31960, 31997, 32033, 32069, 32104, 32138, 32171, 32203, 32234, 32265, 32294, 32323, 32351, 32377, 32403, 32428, + 32453, 32476, 32498, 32520, 32540, 32560, 32579, 32597, 32614, 32630, 32645, 32660, 32673, 32686, 32697, 32708, 32718, 32727, 32735, 32742, 32749, 32754, 32758, 32762, + 32765, 32766, 32767 }; const Word16 dft_win232ms_48k_fx[450] = { - 57, 171, 285, 400, 514, 629, 743, 857, 972, 1086, 1200, 1315, 1429, 1543, 1657, 1772, 1886, 2000, 2114, 2228, 2342, 2456, 2570, 2684, 2798, 2912, 3026, 3140, 3254, 3368, - 3482, 3595, 3709, 3823, 3936, 4050, 4163, 4277, 4390, 4503, 4617, 4730, 4843, 4956, 5069, 5182, 5295, 5408, 5521, 5633, 5746, 5858, 5971, 6083, 6196, 6308, 6420, 6532, - 6644, 6756, 6868, 6980, 7092, 7203, 7315, 7426, 7538, 7649, 7760, 7871, 7982, 8093, 8204, 8315, 8425, 8536, 8646, 8756, 8867, 8977, 9087, 9196, 9306, 9416, 9525, 9635, - 9744, 9853, 9962, 10071, 10180, 10288, 10397, 10505, 10614, 10722, 10830, 10938, 11045, 11153, 11261, 11368, 11475, 11582, 11689, 11796, 11903, 12009, 12115, 12222, 12328, - 12434, 12539, 12645, 12750, 12856, 12961, 13066, 13171, 13275, 13380, 13484, 13588, 13692, 13796, 13900, 14003, 14106, 14210, 14313, 14415, 14518, 14621, 14723, 14825, - 14927, 15029, 15130, 15231, 15333, 15434, 15534, 15635, 15735, 15836, 15936, 16036, 16135, 16235, 16334, 16433, 16532, 16631, 16729, 16827, 16925, 17023, 17121, 17218, - 17315, 17412, 17509, 17606, 17702, 17798, 17894, 17990, 18085, 18181, 18276, 18371, 18465, 18559, 18654, 18748, 18841, 18935, 19028, 19121, 19214, 19306, 19399, 19491, - 19582, 19674, 19765, 19857, 19947, 20038, 20128, 20219, 20308, 20398, 20487, 20577, 20665, 20754, 20843, 20931, 21019, 21106, 21194, 21281, 21367, 21454, 21540, 21626, - 21712, 21798, 21883, 21968, 22053, 22137, 22221, 22305, 22389, 22472, 22556, 22638, 22721, 22803, 22885, 22967, 23048, 23130, 23210, 23291, 23371, 23451, 23531, 23611, - 23690, 23769, 23847, 23925, 24003, 24081, 24159, 24236, 24313, 24389, 24465, 24541, 24617, 24692, 24767, 24842, 24916, 24991, 25064, 25138, 25211, 25284, 25357, 25429, - 25501, 25573, 25644, 25715, 25786, 25856, 25926, 25996, 26066, 26135, 26204, 26272, 26340, 26408, 26476, 26543, 26610, 26676, 26743, 26809, 26874, 26940, 27004, 27069, - 27133, 27197, 27261, 27324, 27387, 27450, 27512, 27574, 27636, 27697, 27758, 27819, 27879, 27939, 27998, 28058, 28117, 28175, 28233, 28291, 28349, 28406, 28463, 28519, - 28575, 28631, 28687, 28742, 28797, 28851, 28905, 28959, 29012, 29065, 29118, 29170, 29222, 29273, 29325, 29376, 29426, 29476, 29526, 29575, 29624, 29673, 29722, 29769, - 29817, 29864, 29911, 29958, 30004, 30050, 30095, 30140, 30185, 30229, 30273, 30317, 30360, 30403, 30445, 30487, 30529, 30571, 30612, 30652, 30692, 30732, 30772, 30811, - 30850, 30888, 30926, 30964, 31001, 31038, 31074, 31110, 31146, 31181, 31216, 31251, 31285, 31319, 31352, 31385, 31418, 31450, 31482, 31514, 31545, 31576, 31606, 31636, - 31666, 31695, 31724, 31752, 31780, 31808, 31835, 31862, 31889, 31915, 31940, 31966, 31991, 32015, 32040, 32063, 32087, 32110, 32132, 32155, 32176, 32198, 32219, 32239, - 32260, 32280, 32299, 32318, 32337, 32355, 32373, 32390, 32408, 32424, 32441, 32457, 32472, 32487, 32502, 32516, 32530, 32544, 32557, 32570, 32582, 32594, 32605, 32617, - 32627, 32638, 32648, 32657, 32666, 32675, 32684, 32692, 32699, 32706, 32713, 32720, 32726, 32731, 32736, 32741, 32745, 32749, 32753, 32756, 32759, 32761, 32763, 32765, - 32766, 32767, 32767 + 57, 171, 285, 400, 514, 629, 743, 857, 972, 1086, 1200, 1315, 1429, 1543, 1657, 1772, 1886, 2000, 2114, 2228, 2342, 2456, 2570, 2684, 2798, 2912, 3026, 3140, 3254, 3368, + 3482, 3595, 3709, 3823, 3936, 4050, 4163, 4277, 4390, 4503, 4617, 4730, 4843, 4956, 5069, 5182, 5295, 5408, 5521, 5633, 5746, 5858, 5971, 6083, 6196, 6308, 6420, 6532, + 6644, 6756, 6868, 6980, 7092, 7203, 7315, 7426, 7538, 7649, 7760, 7871, 7982, 8093, 8204, 8315, 8425, 8536, 8646, 8756, 8867, 8977, 9087, 9196, 9306, 9416, 9525, 9635, + 9744, 9853, 9962, 10071, 10180, 10288, 10397, 10505, 10614, 10722, 10830, 10938, 11045, 11153, 11261, 11368, 11475, 11582, 11689, 11796, 11903, 12009, 12115, 12222, 12328, + 12434, 12539, 12645, 12750, 12856, 12961, 13066, 13171, 13275, 13380, 13484, 13588, 13692, 13796, 13900, 14003, 14106, 14210, 14313, 14415, 14518, 14621, 14723, 14825, + 14927, 15029, 15130, 15231, 15333, 15434, 15534, 15635, 15735, 15836, 15936, 16036, 16135, 16235, 16334, 16433, 16532, 16631, 16729, 16827, 16925, 17023, 17121, 17218, + 17315, 17412, 17509, 17606, 17702, 17798, 17894, 17990, 18085, 18181, 18276, 18371, 18465, 18559, 18654, 18748, 18841, 18935, 19028, 19121, 19214, 19306, 19399, 19491, + 19582, 19674, 19765, 19857, 19947, 20038, 20128, 20219, 20308, 20398, 20487, 20577, 20665, 20754, 20843, 20931, 21019, 21106, 21194, 21281, 21367, 21454, 21540, 21626, + 21712, 21798, 21883, 21968, 22053, 22137, 22221, 22305, 22389, 22472, 22556, 22638, 22721, 22803, 22885, 22967, 23048, 23130, 23210, 23291, 23371, 23451, 23531, 23611, + 23690, 23769, 23847, 23925, 24003, 24081, 24159, 24236, 24313, 24389, 24465, 24541, 24617, 24692, 24767, 24842, 24916, 24991, 25064, 25138, 25211, 25284, 25357, 25429, + 25501, 25573, 25644, 25715, 25786, 25856, 25926, 25996, 26066, 26135, 26204, 26272, 26340, 26408, 26476, 26543, 26610, 26676, 26743, 26809, 26874, 26940, 27004, 27069, + 27133, 27197, 27261, 27324, 27387, 27450, 27512, 27574, 27636, 27697, 27758, 27819, 27879, 27939, 27998, 28058, 28117, 28175, 28233, 28291, 28349, 28406, 28463, 28519, + 28575, 28631, 28687, 28742, 28797, 28851, 28905, 28959, 29012, 29065, 29118, 29170, 29222, 29273, 29325, 29376, 29426, 29476, 29526, 29575, 29624, 29673, 29722, 29769, + 29817, 29864, 29911, 29958, 30004, 30050, 30095, 30140, 30185, 30229, 30273, 30317, 30360, 30403, 30445, 30487, 30529, 30571, 30612, 30652, 30692, 30732, 30772, 30811, + 30850, 30888, 30926, 30964, 31001, 31038, 31074, 31110, 31146, 31181, 31216, 31251, 31285, 31319, 31352, 31385, 31418, 31450, 31482, 31514, 31545, 31576, 31606, 31636, + 31666, 31695, 31724, 31752, 31780, 31808, 31835, 31862, 31889, 31915, 31940, 31966, 31991, 32015, 32040, 32063, 32087, 32110, 32132, 32155, 32176, 32198, 32219, 32239, + 32260, 32280, 32299, 32318, 32337, 32355, 32373, 32390, 32408, 32424, 32441, 32457, 32472, 32487, 32502, 32516, 32530, 32544, 32557, 32570, 32582, 32594, 32605, 32617, + 32627, 32638, 32648, 32657, 32666, 32675, 32684, 32692, 32699, 32706, 32713, 32720, 32726, 32731, 32736, 32741, 32745, 32749, 32753, 32756, 32759, 32761, 32763, 32765, + 32766, 32767, 32767 }; const Word16 dft_win_8k_fx[70] = { - 367, 1102, 1837, 2570, 3303, 4033, 4762, 5488, 6212, 6932, 7649, 8362, 9071, 9775, 10474, 11168, 11857, 12539, 13215, 13885, 14547, 15203, 15850, 16490, 17121, 17743, - 18357, 18961, 19556, 20141, 20716, 21281, 21834, 22377, 22909, 23428, 23937, 24433, 24916, 25388, 25846, 26292, 26724, 27143, 27548, 27939, 28316, 28679, 29027, 29361, - 29680, 29984, 30273, 30547, 30805, 31048, 31275, 31487, 31682, 31862, 32026, 32173, 32305, 32420, 32518, 32601, 32666, 32716, 32749, 32765 + 367, 1102, 1837, 2570, 3303, 4033, 4762, 5488, 6212, 6932, 7649, 8362, 9071, 9775, 10474, 11168, 11857, 12539, 13215, 13885, 14547, 15203, 15850, 16490, 17121, 17743, + 18357, 18961, 19556, 20141, 20716, 21281, 21834, 22377, 22909, 23428, 23937, 24433, 24916, 25388, 25846, 26292, 26724, 27143, 27548, 27939, 28316, 28679, 29027, 29361, + 29680, 29984, 30273, 30547, 30805, 31048, 31275, 31487, 31682, 31862, 32026, 32173, 32305, 32420, 32518, 32601, 32666, 32716, 32749, 32765 }; diff --git a/lib_dec/ivas_sba_dec_fx.c b/lib_dec/ivas_sba_dec_fx.c index 793ed74d41975a096287520710b216ab6d029ddc..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 *-------------------------------------------------------------------*/ @@ -118,12 +118,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( Word32 ivas_total_brate; Word32 last_ivas_total_brate; Word16 num_channels, num_md_sub_frames; -#ifdef FIX_1330_JBM_MEMORY Word16 nchan_out_buff; -#else - Word16 nchan_out_buff, nchan_out_buff_old; - Word16 sba_analysis_order_old_flush; -#endif DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; ISM_MODE ism_mode_old; @@ -136,19 +131,12 @@ ivas_error ivas_sba_dec_reconfigure_fx( move32(); last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; move32(); -#ifndef FIX_1330_JBM_MEMORY - sba_analysis_order_old_flush = st_ivas->sba_analysis_order; - move16(); -#endif /*-----------------------------------------------------------------* * Set SBA high-level parameters * Save old SBA high-level parameters *-----------------------------------------------------------------*/ -#ifndef FIX_1330_JBM_MEMORY - nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, sba_analysis_order_old_flush, last_ivas_total_brate ); -#endif ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -192,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 ) ) @@ -597,9 +585,8 @@ ivas_error ivas_sba_dec_reconfigure_fx( } /*-----------------------------------------------------------------* - * JBM TC buffers + * TC buffer *-----------------------------------------------------------------*/ - { Word16 tc_nchan_to_allocate; Word16 tc_nchan_tc; @@ -607,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(); @@ -659,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 ) ) { @@ -707,11 +695,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( *-----------------------------------------------------------------*/ nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ -#ifdef FIX_1330_JBM_MEMORY IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff, hDecoderConfig->Opt_tsm, st_ivas->hTcBuffer ) ) != IVAS_ERR_OK ) -#else - IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -849,7 +833,6 @@ ivas_error ivas_sba_dec_render_fx( hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); /*Q0*/ -#ifdef FIX_NCHAN_BUFFERS IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { nchan_out = s_max( nchan_internal, st_ivas->hDecoderConfig->nchan_out ); @@ -858,17 +841,14 @@ ivas_error ivas_sba_dec_render_fx( { nchan_out = s_max( nchan_internal, sub( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ) ); } -#ifdef FIX_1372_OSBA_OBJECT_EDITING ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { nchan_out = BINAURAL_CHANNELS; move16(); } -#endif } nchan_out = s_min( nchan_out, ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); -#endif FOR( ch = 0; ch < nchan_out; ch++ ) { output_fx_local[ch] = output_fx[ch]; /*Q11*/ 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 d9f7b26be0676b936f9d11c681b3001ed0332488..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() * @@ -212,6 +212,32 @@ void ivas_mc2sba_fx( } +/*-------------------------------------------------------------------------* + * ivas_stereo2sba() + * + * stereo signal is transformed into SBA in TD domain + *-------------------------------------------------------------------------*/ + +void ivas_stereo2sba_fx( + Word32 *input_fx[], /* i : core-coder transport stereo channels */ + Word32 *output_fx[], /* o : SBA output channels */ + const Word16 output_frame /* i : output frame length per channel */ +) +{ + Word16 n; + Word32 tmp; + + FOR( n = 0; n < output_frame; n++ ) + { + tmp = input_fx[0][n]; + output_fx[0][n] = L_shr( L_add( tmp, input_fx[1][n] ), 1 ); /* W = 0.5 * ( L + R ) */ + output_fx[1][n] = L_shr( L_sub( tmp, input_fx[1][n] ), 1 ); /* Y = 0.5 * ( L - R ) */ + } + + return; +} + + /*-------------------------------------------------------------------------* * ivas_param_mc_mc2sba_cldfb() * diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 6e1893015fec3992e084426df2874572579b5d15..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; @@ -416,22 +418,9 @@ ivas_error create_sce_dec( move16(); } - // if (st_ivas->mode == IVAS_DEC_MODE_EVS) - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - error = init_decoder_fx( st, EVS_MONO ); - IF( error ) - { - return error; - } - } - ELSE + IF( ( error = init_decoder_fx( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) { - error = init_decoder_ivas_fx( st, 0, st_ivas->mc_mode ); - IF( error ) - { - return error; - } + return error; } IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) ) 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 4161c57facdaa66619ea97e3f328f5a9977d1d6a..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; } @@ -1683,25 +1679,15 @@ void ivas_spar_dec_upmixer_sf_fx( ) { Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; -#ifdef FIX_1319_STACK_SBA_DECODER Word32 *cldfb_in_ts_re_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX]; Word32 *cldfb_in_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX]; -#else - Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; - Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; -#endif Word16 i, b, ts, out_ch, in_ch; Word16 num_spar_bands, spar_band, nchan_transport; Word16 num_in_ingest, split_band; Word16 slot_size, slot_idx_start; Word16 md_idx; -#ifdef FIX_1319_STACK_SBA_DECODER Word32 *p_tc_fx[HOA3_CHANNELS]; Word32 Pcm_tmp_fx[HOA3_CHANNELS][2 /* Re, Im*/ * L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; -#else - Word32 *p_tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 Pcm_tmp_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; -#endif Word16 numch_out_dirac; Word32 mixer_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word16 b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -1745,13 +1731,7 @@ void ivas_spar_dec_upmixer_sf_fx( p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[( i + nchan_ism )] + prod; /*Q11*/ } -#ifdef FIX_1372_OSBA_OBJECT_EDITING IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) -#else - test(); - test(); - IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) -#endif { FOR( i = 0; i < nchan_ism; i++ ) { @@ -1793,21 +1773,13 @@ void ivas_spar_dec_upmixer_sf_fx( * Prepare CLDFB buffers *---------------------------------------------------------------------*/ -#ifdef FIX_1319_STACK_SBA_DECODER set_zero_fx( &Pcm_tmp_fx[0][0], HOA3_CHANNELS * 2 * L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES ); -#else - set_zero_fx( &Pcm_tmp_fx[0][0], ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ) * L_FRAME48k ); -#endif /* set-up pointers */ IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { /* at this point, output channels are used as intermediate procesing buffers */ -#ifdef FIX_1319_STACK_SBA_DECODER FOR( in_ch = 0; in_ch < HOA3_CHANNELS; in_ch++ ) -#else - FOR( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; in_ch++ ) -#endif { FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { 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 4a464705d34a23d136a8b5b5c7573e95112b349a..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 @@ -870,37 +870,18 @@ typedef struct renderer_struct * IVAS decoder specific ISAR wrapper structures *----------------------------------------------------------------------------------*/ -#ifndef FIX_1119_SPLIT_RENDERING_VOIP typedef struct { - Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 output_fx[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k]; - -} ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA, *ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE; - -#endif -typedef struct -{ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][2 * CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* Double space to account for TSM */ Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][2 * CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; -#else - Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; -#endif IVAS_AUDIO_CONFIG config; } ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA, *ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA_HANDLE; typedef struct { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP TD_RINGBUF_HANDLE hMultiBinTdData; ISAR_CLDFB_RINGBUF_HANDLE hMultiBinCldfbData[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; -#else - ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE hMultiBinCldfbData; /*scratch buffer for frame by frame processing*/ -#endif ISAR_SPLIT_REND_BITS_HANDLE hSplitRendBits; /*scratch buffer for frame by frame processing*/ SPLIT_REND_WRAPPER splitrend; ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA_HANDLE hCldfbDataOut; /*buffer to store cldfb data before binauralization*/ @@ -1012,30 +993,23 @@ 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 { -#ifdef JBM_MEMORY_OPT Word32 *tc_buffer_old_fx[MAX_INTERN_CHANNELS]; /* TC audio samples not rendered in the previous frame */ -#endif - Word32 *tc_buffer_fx; /* the buffer itself */ -#ifdef JBM_MEMORY_OPT - Word32 *tc_fx[MAX_INTERN_CHANNELS]; /* pointers into the buffer to the beginning of each tc */ -#else - Word32 *tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* pointers into the buffer to the beginning of each tc Q11 for ivas */ -#endif - 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 */ + Word32 *tc_buffer_fx; /* the buffer itself */ + Word32 *tc_fx[MAX_INTERN_CHANNELS]; /* pointers into the buffer to the beginning of each tc */ + 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; @@ -1044,12 +1018,15 @@ typedef struct decoder_tc_buffer_structure Word16 num_slots; Word16 n_samples_discard; /* number of samples to discard from the beginning of the output */ -#ifdef FIX_1330_JBM_MEMORY Word32 *tc_buffer2_fx; /* non-scaled buffer of output audio - needed only when '*tc_buffer* is not long enough */ -#endif } DECODER_TC_BUFFER, *DECODER_TC_BUFFER_HANDLE; + +/*----------------------------------------------------------------------------------* + * JBM metadata structure + *----------------------------------------------------------------------------------*/ + typedef struct jbm_metadata_structure { Word16 sf_write_idx; @@ -1086,6 +1063,7 @@ typedef struct decoder_config_structure Word16 Opt_HRTF_binary; /* indicates whether HRTF binary file is used */ Word16 Opt_Headrotation; /* indicates whether head-rotation is used */ Word16 Opt_RendConfigCustom; /* indicates whether Renderer configuration custom setup is used */ + IVAS_ROOM_SIZE_T room_size; /* Selected room size */ IVAS_HEAD_ORIENT_TRK_T orientation_tracking; /* indicates orientation tracking type */ Word16 Opt_non_diegetic_pan; /* indicates diegetic or not */ Word16 non_diegetic_pan_gain_fx; /* non diegetic panning gain, Q15 */ @@ -1095,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; @@ -1199,22 +1177,25 @@ typedef struct Decoder_Struct MASA_ISM_DATA_HANDLE hMasaIsmData; /* OMASA rendering handle */ SBA_ISM_DATA_HANDLE hSbaIsmData; /* OSBA rendering handle */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcousticEnvironments; /* Acoustic environment array */ + Word16 acousticEnvironmentsCount; /* Number of acoustic environments in the array*/ + Word16 flag_omasa_brate; 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; - Word16 ism_extmeta_active; /* Extended metadata active in decoder */ - Word16 ism_extmeta_cnt; /* Change frame counter for extended metadata */ + Word16 ism_extmeta_active; /* Extended metadata active in decoder */ + Word16 ism_extmeta_cnt; /* Change frame counter for extended metadata */ #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR Word16 flushing; #endif + Word16 restartNeeded; /* Flag to signal decoder restart */ } Decoder_Struct; diff --git a/lib_dec/ivas_stereo_adapt_GR_dec_fx.c b/lib_dec/ivas_stereo_adapt_GR_dec_fx.c index 2bade4786e8c8fde9f33e95ff0cbdeaaedc95ffb..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 @@ -46,9 +46,9 @@ /*! r: number of bits read */ static Word16 read_GR2( - const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ - Word16 *ind, /* o : parameters read Q0*/ - const Word16 len /* i : number of params to be read Q0*/ + const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ + Word16 *ind, /* o : parameters read Q0*/ + const Word16 len /* i : number of params to be read Q0*/ ) { Word16 i; @@ -103,9 +103,9 @@ static Word16 read_GR2( /*! r: number of bits read */ static Word16 read_GR1( - const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ - Word16 *ind, /* o : parameters read Q0*/ - const Word16 len /* i : number of params to be read Q0*/ + const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ + Word16 *ind, /* o : parameters read Q0*/ + const Word16 len /* i : number of params to be read Q0*/ ) { Word16 i; @@ -159,9 +159,9 @@ static Word16 read_GR1( /*! r: number of bits read */ Word16 read_GR0( - const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ - Word16 *ind, /* o : parameters read Q0*/ - const Word16 len /* i : number of params to be read Q0*/ + const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ + Word16 *ind, /* o : parameters read Q0*/ + const Word16 len /* i : number of params to be read Q0*/ ) { Word16 i; @@ -240,11 +240,11 @@ static ivas_error find_map( *---------------------------------------------------------------------*/ static void decode_adapt_GR_indices1( - const Word16 *ind, /* i : array of input encoded symbols Q0*/ - const Word16 len, /* i : number of parameters to decode Q0*/ - const Word16 no_symb, /* i : number of possible symbols in GR coding Q0*/ - Word16 *out, /* o : array of decoded parameters Q0*/ - const Word16 *map0 /* i : initial mapping array for the adaptive GR Q0*/ + const Word16 *ind, /* i : array of input encoded symbols Q0*/ + const Word16 len, /* i : number of parameters to decode Q0*/ + const Word16 no_symb, /* i : number of possible symbols in GR coding Q0*/ + Word16 *out, /* o : array of decoded parameters Q0*/ + const Word16 *map0 /* i : initial mapping array for the adaptive GR Q0*/ ) { const Word16 *map; @@ -279,8 +279,8 @@ static void decode_adapt_GR_indices1( /*! r: read value */ Word16 get_value( - const UWord16 *bit_stream, /* i : bitstream Q0*/ - const Word16 nbits /* i : number of bits to be read Q0*/ + const UWord16 *bit_stream, /* i : bitstream Q0*/ + const Word16 nbits /* i : number of bits to be read Q0*/ ) { Word16 i; @@ -358,12 +358,12 @@ Word16 read_BS_GR( /*! r: number of bits read */ Word16 read_BS_adapt_GR_sg( - const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ - const Word16 nb, /* i : starting position in bitstream Q0*/ - Word16 *ind1, /* o : decoded side gain values Q0*/ - const Word16 len, /* i : number of params to be read Q0*/ - Word16 *GR_ord, /* o : GR order used (read from bitstream) Q0*/ - const Word16 *map0 /* i : initial map Q0*/ + const UWord16 *bit_stream, /* i : bitstream to be read Q0*/ + const Word16 nb, /* i : starting position in bitstream Q0*/ + Word16 *ind1, /* o : decoded side gain values Q0*/ + const Word16 len, /* i : number of params to be read Q0*/ + Word16 *GR_ord, /* o : GR order used (read from bitstream) Q0*/ + const Word16 *map0 /* i : initial map Q0*/ ) { Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], ord; diff --git a/lib_dec/ivas_stereo_cng_dec_fx.c b/lib_dec/ivas_stereo_cng_dec_fx.c index 1f0cff11077368b5c1310c38e19172fc40cb71ae..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" @@ -76,15 +74,15 @@ static void stereo_dft_generate_comfort_noise_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ - const Word16 last_element_mode, /* i : last element mode Q0*/ - Decoder_State *st, /* i/o: Core coder decoder state */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + Decoder_State *st, /* i/o: Core coder decoder state */ Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ - Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ - const Word16 targetGain, /* i : ICA target gain Q13*/ - const Word16 chan, /* i : channel number Q0*/ - const Word16 output_frame, /* i : output frame size Q0*/ - Word16 q_dft /* i : Q of DFT */ + Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ + const Word16 targetGain, /* i : ICA target gain Q13*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + Word16 q_dft /* i : Q of DFT */ ) { Word16 i, j, k; @@ -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(); @@ -870,11 +870,11 @@ static void stereo_dft_generate_comfort_noise_fx( * DFT stereo CNG *-------------------------------------------------------------------*/ void stereo_dtf_cng_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ - const Word16 output_frame, /* i : output frame size Q0*/ - Word16 q_dft /* i : Q factor of the DFT data */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers q_dft*/ + const Word16 output_frame, /* i : output frame size Q0*/ + Word16 q_dft /* i : Q factor of the DFT data */ ) { Decoder_State **sts; @@ -918,7 +918,7 @@ void stereo_dtf_cng_fx( void stereo_cng_dec_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { IF( GT_32( hCPE->hCoreCoder[0]->core_brate, SID_2k40 ) ) @@ -982,8 +982,8 @@ void stereo_cng_compute_PScorr_fx( Word16 *output_Q, Word32 *c_PS_LT_fx, Word16 Q_c_PS_LT_fx, - const Word16 L_frame_0, /* i : L_frame channel 0 Q0*/ - const Word16 L_frame_1 /* i : L_frame channel 1 Q0*/ + const Word16 L_frame_0, /* i : L_frame channel 0 Q0*/ + const Word16 L_frame_1 /* i : L_frame channel 1 Q0*/ ) { Word16 i; @@ -1105,7 +1105,7 @@ void stereo_cng_compute_PScorr_fx( *-------------------------------------------------------------------*/ static void stereo_cng_compute_LRcorr_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ const Word16 output_frame, /* i : Output frame length Q0*/ const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ @@ -1309,8 +1309,8 @@ static void stereo_cng_compute_LRcorr_fx( static void FindEmEs_fx( const Word32 *ch1_fx, /* i : Left channel OUTPUT_Q*/ const Word32 *ch2_fx, /* i : right channel OUTPUT_Q*/ - const Word16 len, /* i : length Q0*/ - Word32 *lt_es_em_fx /* i/o: LT energy ratio Q24*/ + const Word16 len, /* i : length Q0*/ + Word32 *lt_es_em_fx /* i/o: LT energy ratio Q24*/ ) { Word16 i; @@ -1385,10 +1385,10 @@ static void FindEmEs_fx( *-------------------------------------------------------------------*/ void stereo_cna_update_params_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ - const Word16 output_frame, /* i : Output frame length Q0*/ - const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -1614,8 +1614,8 @@ void stereo_cna_update_params_fx( *-------------------------------------------------------------------*/ void stereo_cng_init_dec_fx( - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ - const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 Q0*/ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 Q0*/ ) { hStereoCng->prev_sid_nodata = 0; diff --git a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c index 6a369a14c407a2563ad115ff7986e406db292264..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" @@ -74,11 +72,11 @@ void stereo_dft_dmx_out_reset_fx( *-------------------------------------------------------------------------*/ void stereo_dft_unify_dmx_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers hStereoDft->qDFT*/ - Word32 *input_mem, /* i/o: mem of buffer DFT analysis Q11*/ - const Word16 prev_sid_nodata /* i : Previous SID/No data indicator Q0*/ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers hStereoDft->qDFT*/ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis Q11*/ + const Word16 prev_sid_nodata /* i : Previous SID/No data indicator Q0*/ ) { Word16 i, k, b, N_div; diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 186306209fbe39d48451785efa1ef1a9043410ab..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" @@ -220,11 +216,7 @@ void stereo_dft_dec_reset_fx( { set32_fx( hStereoDft->smooth_buf_fx[i], 0, SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); } -#ifdef FIX_2176_ASSERT_DEC_MAP_PARAMS_DIRAC2STEREO hStereoDft->q_smooth_buf_fx = Q6; -#else - hStereoDft->q_smooth_buf_fx = Q7; -#endif move16(); set16_fx( hStereoDft->smooth_fac_fx[0], 0, SBA_DIRAC_STEREO_NUM_BANDS ); set16_fx( hStereoDft->smooth_fac_fx[1], 0, SBA_DIRAC_STEREO_NUM_BANDS ); @@ -277,9 +269,9 @@ void stereo_dft_dec_reset_fx( *-------------------------------------------------------------------------*/ static void stereo_dft_dec_open_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 output_Fs, /* i : output sampling rate Q0*/ - const Word16 nchan_transport /* i : number of transport channels Q0*/ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { /*Sizes*/ @@ -370,11 +362,11 @@ static void stereo_dft_dec_open_fx( *------------------------------------------------------------------------*/ ivas_error stereo_dft_dec_create_fx( - STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word32 element_brate, /* i : element bitrate Q0*/ - const Word32 output_Fs, /* i : output sampling rate Q0*/ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ - const Word16 nchan_transport /* i : number of transport channels Q0*/ + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { STEREO_DFT_DEC_DATA_HANDLE hStereoDft_loc; @@ -602,9 +594,9 @@ static void stereo_dft_dequantize_res_gains_f_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_update_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const Word16 output_frame, /* i : output frame length Q0*/ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC Q0*/ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC Q0*/ ) { Word16 b, i, k_offset; @@ -734,14 +726,14 @@ void stereo_dft_dec_destroy_fx( void stereo_dft_dec_analyze_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 *input_fx, /* i : input signal q*/ - Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ - const Word16 chan, /* i : channel number Q0*/ - const Word16 input_frame, /* i : input frame size Q0*/ - const Word16 output_frame, /* i : output frame size Q0*/ - const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ - const Word16 k_offset, /* i : offset of DFT Q0*/ - const Word16 delay, /* i : delay in samples FOR input signal Q0*/ + const Word32 *input_fx, /* i : input signal q*/ + Word32 out_DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers q_out_DFT*/ + const Word16 chan, /* i : channel number Q0*/ + const Word16 input_frame, /* i : input frame size Q0*/ + const Word16 output_frame, /* i : output frame size Q0*/ + const DFT_STEREO_DEC_ANA_TYPE ana_type, /* i : type of signal to analyse */ + const Word16 k_offset, /* i : offset of DFT Q0*/ + const Word16 delay, /* i : delay in samples FOR input signal Q0*/ Word16 *q, Word16 *q_out_DFT ) { @@ -1090,11 +1082,11 @@ void stereo_dft_dec_analyze_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_synthesize_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers qDFT*/ - const Word16 chan, /* i : channel number Q0*/ - Word32 output[L_FRAME48k], /* o : output synthesis signal qDFT*/ - const Word16 output_frame /* i : output frame length Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i : DFT buffers qDFT*/ + const Word16 chan, /* i : channel number Q0*/ + Word32 output[L_FRAME48k], /* o : output synthesis signal qDFT*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 i, k; @@ -1704,10 +1696,10 @@ void stereo_dft_dec_smooth_parameters_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_res_fx( - CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ + CPE_DEC_HANDLE hCPE, /* i/o: decoder CPE handle */ Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer q_res*/ - Word16 q_res, /* i : q fact of residural buffer */ - Word32 *output /* o : output Q16*/ + Word16 q_res, /* i : q fact of residural buffer */ + Word32 *output /* o : output Q16*/ ) { Word16 i; @@ -1797,7 +1789,7 @@ void stereo_dft_dec_res_fx( IF( prev_bfi ) { /* Ramp up BPF contribution for the first good frame */ - step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); /* Q15 */ + step = (Word16) ( 0x00CD ); // ( 1.0f / L_FRAME8k ); /* Q15 */ move16(); fac = negate( step ); FOR( i = 0; i < L_FRAME8k; i++ ) @@ -1837,18 +1829,18 @@ void stereo_dft_dec_res_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - Decoder_State *st0, /* i/o: decoder state structure */ - Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers qDFT*/ - Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure Q0*/ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ - const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC Q0*/ - ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ - const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation Q0*/ - const Word32 output_Fs, /* i : Fs for delay calculation Q0*/ - const Word16 nchan_transport, /* i : number of transpor channels Q0*/ - const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + Decoder_State *st0, /* i/o: decoder state structure */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers qDFT*/ + Word32 *input_mem, /* i/o: mem of buffer DFT analysis */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC Q0*/ + const Word16 sba_mono_flag, /* i : signal mono output for SBA DirAC Q0*/ + ivas_spar_md_dec_state_t *hMdDec, /* i : SPAR MD handle for upmixing */ + const Word16 cross_fade_start_offset, /* i : SPAR mixer delay compensation Q0*/ + const Word32 output_Fs, /* i : Fs for delay calculation Q0*/ + const Word16 nchan_transport, /* i : number of transpor channels Q0*/ + const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ ) { Word16 i, k, b, N_div, stop; @@ -2867,13 +2859,13 @@ static void stereo_dft_dequantize_ipd_fx( * *-------------------------------------------------------------------------*/ void stereo_dft_generate_res_pred_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ const Word16 samp_ratio, /* i : sampling ratio Q15*/ Word32 *pDFT_DMX, /* i : downmix signal qDFT*/ Word32 *DFT_PRED_RES, /* o : residual prediction signal qDFT*/ Word32 *pPredGain, /* i : residual prediction gains Q31*/ - const Word16 k, /* i : subframe index Q0*/ - Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal qDFT*/ + const Word16 k, /* i : subframe index Q0*/ + Word32 *ap_filt_DMX, /* i : enhanced stereo filling signal qDFT*/ Word16 *stop, /* o : last FD stereo filling bin Q0*/ const Word16 bfi /* i : BFI flag Q0*/ ) @@ -3657,9 +3649,9 @@ static void stereo_dft_adapt_sf_delay_fx( } void stereo_dft_dec_sid_coh_fx( Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands Q0*/ - Word16 *coh_fx, /* i/o: coherence Q15*/ - Word16 *nb_bits /* i/o: number of bits read Q0*/ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh_fx, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ ) { Word16 alpha_fx; @@ -3683,10 +3675,10 @@ void stereo_dft_dec_sid_coh_fx( IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS - STEREO_DFT_PRED_NBITS ) > 0 ) { /* Read coherence from bitstream */ - coh_pred_index = get_next_indice_fx( st, STEREO_DFT_PRED_NBITS ); /* Read predictor index Q0*/ + coh_pred_index = get_next_indice_fx( st, STEREO_DFT_PRED_NBITS ); /* Read predictor index Q0*/ ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_PRED_NBITS ); - alpha_index = get_next_indice_fx( st, STEREO_DFT_N_COH_ALPHA_BITS ); /* Read alpha index Q0*/ + alpha_index = get_next_indice_fx( st, STEREO_DFT_N_COH_ALPHA_BITS ); /* Read alpha index Q0*/ ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS ); alpha_step = 0; @@ -3727,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 */ { @@ -3771,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 */ @@ -3789,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() * @@ -3803,17 +3800,17 @@ void stereo_dft_dequantize_itd_fx( *-------------------------------------------------------------------------*/ void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ - Word32 *total_brate, /* o : total bitrate Q0*/ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth Q0*/ - const Word16 output_frame, /* i : output frame length Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ - Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ Word16 *coh_fx, /* i/o: Coherence Q15*/ - const Word16 ivas_format /* i : ivas format Q0*/ + const Word16 ivas_format /* i : ivas format Q0*/ ) { Word32 sg_tmp_fx[STEREO_DFT_BAND_MAX]; @@ -4078,7 +4075,7 @@ void stereo_dft_dec_read_BS_fx( IF( !hStereoDft->frame_sid_nodata ) { itd_mode = get_next_indice_fx( st, STEREO_DFT_ITD_MODE_NBITS ); /* Q0 */ - ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit Q0*/ + ( *nb_bits ) = add( ( *nb_bits ), STEREO_DFT_ITD_MODE_NBITS ); /*ITD mode flag: 1bit Q0*/ move16(); hStereoDft->itd_fx[k + k_offset] = 0; move32(); @@ -4396,7 +4393,7 @@ void stereo_dft_dec_read_BS_fx( test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_16( ivas_format, MASA_FORMAT ) ) { - *nb_bits = (Word16) Mult_32_16( L_sub( element_brate, SID_2k40 ), INV_FRAME_PER_SEC_Q15 ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; Q0*/ + *nb_bits = extract_l( Mult_32_16( L_sub( element_brate, SID_2k40 ), INV_FRAME_PER_SEC_Q15 ) ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; Q0*/ move16(); } { diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 607892b2a07dc5500749c1a7f975330b19001507..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 * ---------------------------------------------------------------*/ @@ -58,17 +57,17 @@ * ---------------------------------------------------------------*/ void stereo_dft_res_ecu_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ Word32 *pDFT_RES, /* i/o: residual signal hStereoDft->q_dft*/ Word32 *const DFT_PRED_RES, /* i/o: residual prediction signal hStereoDft->q_dft*/ - const Word16 k, /* i : Subframe index Q0*/ - const Word16 output_frame, /* i : Output frame length Q0*/ - const Word16 prev_bfi, /* i : Previous BFI Q0*/ - const Word32 dmx_nrg, /* i : Down-mix energy Qx*/ - Word16 *num_plocs, /* i/o: Number of peak locations Q0*/ - Word16 *plocs, /* i/o: Peak locations (bin) Q0*/ - Word32 *plocsi, /* i/o: Peak locations (fractional) Qx*/ - Word32 *input_mem /* o : Residual DFT buffer input mem Q11*/ + const Word16 k, /* i : Subframe index Q0*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 prev_bfi, /* i : Previous BFI Q0*/ + const Word32 dmx_nrg, /* i : Down-mix energy Qx*/ + Word16 *num_plocs, /* i/o: Number of peak locations Q0*/ + Word16 *plocs, /* i/o: Peak locations (bin) Q0*/ + Word32 *plocsi, /* i/o: Peak locations (fractional) Qx*/ + Word32 *input_mem /* o : Residual DFT buffer input mem Q11*/ ) { Word32 res_buf[L_FRAME8k] = { 0 }; @@ -182,7 +181,7 @@ void stereo_dft_res_ecu_fx( /*! r: interpolated maximum position */ Word32 imax_pos_fx( - const Word32 *y /* i : Input vector for peak interpolation Qx*/ + const Word32 *y /* i : Input vector for peak interpolation Qx*/ ) { Word32 posi, y1, y2, y3, y3_y1, y2i; @@ -451,7 +450,7 @@ static void ivas_peakfinder_fx( move16(); leftMin = x[ii]; /* Qx */ move32(); - peakLoc[*cInd] = tempLoc; /* Add peak to index Q0*/ + peakLoc[*cInd] = tempLoc; /* Add peak to index Q0*/ move16(); peakMag[*cInd] = tempMag; /* Q0 */ move32(); @@ -544,17 +543,17 @@ static void ivas_peakfinder_fx( * ---------------------------------------------------------------*/ void stereo_dft_res_subst_spec_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ - Word32 *pDFT_RES, /* i/o: residual signal qDFT*/ - const Word32 *const DFT_PRED_RES, /* i : residual prediction signal qDFT*/ - const Word16 time_offs, /* i : Time offset for phase adjustment Q0*/ - const Word16 L_res, /* i : bandwidth of residual signal Q0*/ - const Word16 L_ana, /* i : Length of FFT analysis Q0*/ - const Word16 k, /* i : Subframe index Q0*/ - Word16 *num_plocs, /* i/o: Number of peak locations Q0*/ - Word16 *plocs, /* i/o: Peak locations (bin) Q0*/ - Word32 *plocsi, /* i/o: Peak locations (fractional) Qx*/ - const Word16 analysis_flag /* i : Flag for running peak analysis Q0*/ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + Word32 *pDFT_RES, /* i/o: residual signal qDFT*/ + const Word32 *const DFT_PRED_RES, /* i : residual prediction signal qDFT*/ + const Word16 time_offs, /* i : Time offset for phase adjustment Q0*/ + const Word16 L_res, /* i : bandwidth of residual signal Q0*/ + const Word16 L_ana, /* i : Length of FFT analysis Q0*/ + const Word16 k, /* i : Subframe index Q0*/ + Word16 *num_plocs, /* i/o: Number of peak locations Q0*/ + Word16 *plocs, /* i/o: Peak locations (bin) Q0*/ + Word32 *plocsi, /* i/o: Peak locations (fractional) Qx*/ + const Word16 analysis_flag /* i : Flag for running peak analysis Q0*/ ) { Word16 i, idx; @@ -730,11 +729,11 @@ void stereo_dft_res_subst_spec_fx( * ---------------------------------------------------------------*/ void stereo_dft_res_ecu_burst_att_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: Decoder DFT stereo handle */ Word32 *pDFT_RES, /* i/o: residual signal /att. residual qDFT*/ - const Word32 dmx_nrg, /* i : dmx energy of current frame Qx*/ - const Word16 L_res, /* i : Bandwidth of residual Q0*/ - const Word16 L_ana /* i : Length of FFT analysis Q0*/ + const Word32 dmx_nrg, /* i : dmx energy of current frame Qx*/ + const Word16 L_res, /* i : Bandwidth of residual Q0*/ + const Word16 L_ana /* i : Length of FFT analysis Q0*/ ) { Word32 fac; @@ -769,9 +768,9 @@ void stereo_dft_res_ecu_burst_att_fx( /*! r: total energy of downmix with maximum swb bandwidth max */ Word32 stereo_dft_dmx_swb_nrg_fx( - const Word32 *dmx_k0, /* i : first subframe spectrum q0*/ - const Word32 *dmx_k1, /* i : second subframe spectrum q1*/ - const Word16 frame_length, /* i : frame lanegth Q0*/ + const Word32 *dmx_k0, /* i : first subframe spectrum q0*/ + const Word32 *dmx_k1, /* i : second subframe spectrum q1*/ + const Word16 frame_length, /* i : frame lanegth Q0*/ const Word16 q0, const Word16 q1 ) { @@ -785,33 +784,20 @@ Word32 stereo_dft_dmx_swb_nrg_fx( { FOR( i = 0; i < frame_length / 2; i++ ) { -#ifdef FIX_2166_ASSERT_OSBA_PLC_STEREO_OUT dmx_nrg = L_add( dmx_nrg, L_shr( L_add( Madd_32_32( Mpy_32_32( dmx_k0[2 * i], dmx_k0[2 * i] ), dmx_k0[2 * i + 1], dmx_k0[2 * i + 1] ), Madd_32_32( Mpy_32_32( dmx_k1[2 * i], dmx_k1[2 * i] ), dmx_k1[2 * i + 1], dmx_k1[2 * i + 1] ) ), 1 ) ); /* Q0 */ -#else - dmx_nrg = L_add( dmx_nrg, - L_add( Madd_32_32( Mpy_32_32( dmx_k0[2 * i], dmx_k0[2 * i] ), dmx_k0[2 * i + 1], dmx_k0[2 * i + 1] ), - Madd_32_32( Mpy_32_32( dmx_k1[2 * i], dmx_k1[2 * i] ), dmx_k1[2 * i + 1], dmx_k1[2 * i + 1] ) ) ); /* Q0 */ -#endif } } ELSE { FOR( i = 0; i < frame_length / 2; i++ ) { -#ifdef FIX_2166_ASSERT_OSBA_PLC_STEREO_OUT dmx_nrg = L_add( dmx_nrg, L_shr( L_add( L_shl( Madd_32_32( Mpy_32_32( dmx_k0[2 * i], dmx_k0[2 * i] ), dmx_k0[2 * i + 1], dmx_k0[2 * i + 1] ), q0 ), L_shl( Madd_32_32( Mpy_32_32( dmx_k1[2 * i], dmx_k1[2 * i] ), dmx_k1[2 * i + 1], dmx_k1[2 * i + 1] ), q1 ) ), 1 ) ); /*3*q0 - 31*/ -#else - dmx_nrg = L_add( dmx_nrg, - L_add( L_shl( Madd_32_32( Mpy_32_32( dmx_k0[2 * i], dmx_k0[2 * i] ), dmx_k0[2 * i + 1], dmx_k0[2 * i + 1] ), q0 ), - L_shl( Madd_32_32( Mpy_32_32( dmx_k1[2 * i], dmx_k1[2 * i] ), dmx_k1[2 * i + 1], dmx_k1[2 * i + 1] ), q1 ) ) ); /*3*q0 - 31*/ - -#endif } } diff --git a/lib_dec/ivas_stereo_eclvq_dec_fx.c b/lib_dec/ivas_stereo_eclvq_dec_fx.c index df7158c85caa580a15df7c9797e95d5edbe6b3a0..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 @@ -209,7 +209,7 @@ void ECSQ_decode_fx( } ELSE { - count0 = left0 * ECSQ_tab_inverse[left0 + left1]; /* left0 * round(ECSQ_PROB_TOTAL / (left0 + left1)) Q0*/ + count0 = left0 * ECSQ_tab_inverse[left0 + left1]; /* left0 * round(ECSQ_PROB_TOTAL / (left0 + left1)) Q0*/ sym = rc_uni_dec_read_bit_prob_fast( rc_st_dec, count0, ECSQ_PROB_BITS ); /* Q0 */ } 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 73cf9ccd0c779ab296f375a180d893068f3020a2..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" @@ -53,7 +50,7 @@ * ---------------------------------------------------------------*/ void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *synth_fx[CPE_CHANNELS], /* i/o: output synth qsynth*/ const Word16 output_frame /* i : length of a frame per channel Q0*/ ) @@ -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 */ @@ -314,9 +311,9 @@ void stereo_tca_dec_fx( #define MAX_TARGET_GAIN_Q29 1904890240 void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ - const Word16 output_frame /* i : frame length Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ ) { STEREO_TCA_DEC_HANDLE hStereoTCA; @@ -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 d5b289acfa39f8888e9dee25efef36f0a41ee389..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,15 +112,21 @@ 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 */ - Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ + Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Q_white_exc*/ - const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ - const Word16 output_frame, /* i : frame length Q0 */ - Word16 *Q_syn, /* i : Q of synth and synthRef buffers */ - const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */ + const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 output_frame, /* i : frame length Q0 */ + Word16 *Q_syn, /* i : Q of synth and synthRef buffers */ + const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */ ) { Word16 i, j, k, nbSubFr; @@ -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 */ @@ -314,7 +324,7 @@ void stereo_icBWE_dec_fx( icbweM2Ref_fx = extract_h( L_add( ONE_IN_Q30, temp ) ); // Q14 gsMapping_fx = extract_h( L_sub( ONE_IN_Q30, temp ) ); // Q14 - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0 + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0 winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ alpha_fx = winSlope_fx; /* Q15 */ move16(); @@ -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() * @@ -935,10 +939,10 @@ void stereo_icBWE_dec_fx( *-------------------------------------------------------------------*/ void stereo_icBWE_decproc_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis Q11*/ Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis Q11*/ - const Word16 last_core, /* i : last core, primary channel Q0*/ + const Word16 last_core, /* i : last core, primary channel Q0*/ const Word16 last_bwidth, /* i : last bandwidth Q0*/ const Word16 output_frame /* i : frame length Q0*/ ) @@ -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 eebfa267cf08cec433419553c956cd95fda23383..8df5a33faf571f9672c4a544f314d51cd86dba07 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,9 +377,12 @@ void stereo_mdct_core_dec_fx( } } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + IF( !bfi ) { - Copy_Scale_sig_16_32_DEPREC( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); /* Q16 */ + 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 */ + } } /*--------------------------------------------------------------------------------* @@ -508,10 +515,10 @@ void stereo_mdct_core_dec_fx( *--------------------------------------------------------------------*/ static void apply_dmx_weights_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum Q11*/ - Word16 transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch Q0*/ - Word16 transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch Q0*/ + Word16 transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch Q0*/ + Word16 transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch Q0*/ ) { Word16 b, k, l, i, ch; @@ -546,7 +553,7 @@ static void apply_dmx_weights_fx( { /* use TCX20 band config for TCX20 in both channels and mixed frames */ sfbConf = &hCPE->hStereoMdct->stbParamsTCX20; - nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 Q0*/ + nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 Q0*/ move16(); move16(); move16(); diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c b/lib_dec/ivas_stereo_mdct_stereo_dec_fx.c index efea57f4daaf084e5dcd8fe0f32c14a8d9bd9340..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" @@ -66,12 +64,12 @@ static void inverseBwMS_fx( const Word16 startLine, const Word16 stopLine, Word3 *-------------------------------------------------------------------*/ void parse_stereo_from_bitstream( - STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo decoder structure */ - Decoder_State **sts, /* i/o: decoder state structure */ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ - const Word16 isSBAStereoMode, /* i : flag core coding for SBA Q0*/ - Decoder_State *st0, /* i/o: decoder state structure for Bstr */ - Word16 ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask Q0*/ + STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo decoder structure */ + Decoder_State **sts, /* i/o: decoder state structure */ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + const Word16 isSBAStereoMode, /* i : flag core coding for SBA Q0*/ + Decoder_State *st0, /* i/o: decoder state structure for Bstr */ + Word16 ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask Q0*/ ) { Word16 i, k, nSubframes, mdct_stereo_mode; @@ -237,7 +235,7 @@ void parse_stereo_from_bitstream( IF( !mct_on ) { - hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels Q0*/ + hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels Q0*/ move16(); hStereoMdct->split_ratio = extract_l( get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ) ); /* Q0 */ @@ -256,11 +254,11 @@ void parse_stereo_from_bitstream( *-------------------------------------------------------------------*/ static void inverseBwMS_fx( - const Word16 startLine, /* i : start line of sfb Q0*/ - const Word16 stopLine, /* i : stop line of sfb Q0*/ - Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ - Word32 x1[], /* i/o: side/right channel coefficients Qx*/ - const Word32 norm_fac /* i : normalization factor Q31*/ + const Word16 startLine, /* i : start line of sfb Q0*/ + const Word16 stopLine, /* i : stop line of sfb Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { Word16 j; @@ -287,10 +285,10 @@ static void inverseBwMS_fx( *-------------------------------------------------------------------*/ void inverseMS_fx( - const Word16 L_frame, /* i : frame length Q0*/ - Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ - Word32 x1[], /* i/o: side/right channel coefficients Qx*/ - const Word32 norm_fac /* i : normalization factor Q31*/ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { inverseBwMS_fx( 0, L_frame, x0, x1, norm_fac ); @@ -307,20 +305,20 @@ void inverseMS_fx( void stereo_decoder_tcx_fx( STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: MDCT stereo decoder structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ - Word32 *spec_r_0[NB_DIV], /* i/o: spectrum right channel Qx*/ - Word32 *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] Qx*/ - Word32 *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] Qx*/ - const Word16 mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono Q0*/ - const Word16 core_l, /* i : core for left channel (TCX20/TCX10) Q0*/ - const Word16 core_r, /* i : core for right channel (TCX20/TCX10) Q0*/ - const Word16 igf, /* i : flag for IGF activity Q0*/ - const Word16 L_frameTCX_l, /* i : TCX frame length of left channel Q0*/ - const Word16 L_frameTCX_r, /* i : TCX frame length of right channel Q0*/ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ - const Word16 last_core_l, /* i : last core for left channel Q0*/ - const Word16 last_core_r, /* i : last core for right channel Q0*/ - const Word16 tmp_plc_upmix /* i : indicates temp upmix for PLC decision Q0*/ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + Word32 *spec_r_0[NB_DIV], /* i/o: spectrum right channel Qx*/ + Word32 *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] Qx*/ + Word32 *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] Qx*/ + const Word16 mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono Q0*/ + const Word16 core_l, /* i : core for left channel (TCX20/TCX10) Q0*/ + const Word16 core_r, /* i : core for right channel (TCX20/TCX10) Q0*/ + const Word16 igf, /* i : flag for IGF activity Q0*/ + const Word16 L_frameTCX_l, /* i : TCX frame length of left channel Q0*/ + const Word16 L_frameTCX_r, /* i : TCX frame length of right channel Q0*/ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + const Word16 last_core_l, /* i : last core for left channel Q0*/ + const Word16 last_core_r, /* i : last core for right channel Q0*/ + const Word16 tmp_plc_upmix /* i : indicates temp upmix for PLC decision Q0*/ ) { Word16 i, k, sfb, nSubframes; @@ -495,10 +493,10 @@ void stereo_decoder_tcx_fx( *-------------------------------------------------------------------*/ void initMdctStereoDecData_fx( - STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const Word16 igf, /* i : flag indicating IGF activity Q0*/ - const H_IGF_GRID igfGrid, /* i : IGF grid configuration Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ + STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ + const H_IGF_GRID igfGrid, /* i : IGF grid configuration Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ const Word16 bwidth /* i : audio bandwidth Q0*/ ) { @@ -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 ) @@ -634,11 +632,7 @@ void synchonize_channels_mdct_sid_fx( move16(); sts[1]->bwidth = sts[0]->bwidth; move16(); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG sts[0]->hFdCngDec->hFdCngCom->coherence_fx[0] = sts[1]->hFdCngDec->hFdCngCom->coherence_fx[0]; /* coherence is stored in sts[1] - see ivas_decision_matrix_dec() */ -#else - sts[0]->hFdCngDec->hFdCngCom->coherence_fx = sts[1]->hFdCngDec->hFdCngCom->coherence_fx; /* coherence is stored in sts[1] - see ivas_decision_matrix_dec() */ -#endif move16(); sts[0]->hFdCngDec->hFdCngCom->no_side_flag = sts[1]->hFdCngDec->hFdCngCom->no_side_flag; move16(); @@ -907,9 +901,9 @@ void updateBuffersForDmxMdctStereo_fx( *-------------------------------------------------------------------*/ void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output q_out*/ - const Word16 output_frame /* i : output frame length Q0*/ + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 crossfade_len, i; diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 76041da3972c25556d65eb30efb00b2fc0fc9bb1..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" /*-------------------------------------------------------------------* @@ -158,7 +155,7 @@ static ivas_error allocate_CoreCoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init_ivas_fx( st->hGSCDec ); + GSC_dec_init_fx( st->hGSCDec ); } IF( st->hPFstat == NULL ) @@ -307,8 +304,8 @@ static void deallocate_CoreCoder_fx( /* CLDFB BPF & resampling tools */ IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ - deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ + deleteCldfb_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ + deleteCldfb_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -343,13 +340,13 @@ static void cpy_tcx_ltp_data_fx( move16(); /* (int16_t) ( ( TCXLTP_MAX_DELAY * output_Fs ) / 48000 ) */ sz = extract_l( Mpy_32_32_r( TCXLTP_MAX_DELAY * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); /* Q0 */ - Copy( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ + Copy( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ Copy32( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); /* exp(exp_tcxltp_mem_in) */ hTcxLtpDecNew->exp_tcxltp_mem_in = hTcxLtpDecOld->exp_tcxltp_mem_in; /* exp(exp_tcxltp_mem_in) */ move16(); /* (int16_t) ( ( L_FRAME48k * output_Fs ) / 48000 ) */ sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); /* Q0 */ - Copy( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ + Copy( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ Copy32( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); /* exp(exp_tcxltp_mem_in) */ hTcxLtpDecNew->exp_tcxltp_mem_out = hTcxLtpDecOld->exp_tcxltp_mem_out; /* exp(exp_tcxltp_mem_in) */ move16(); @@ -365,13 +362,13 @@ static void cpy_tcx_ltp_data_fx( *-------------------------------------------------------------------*/ ivas_error stereo_memory_dec_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ - CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ - const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ - const Word32 output_Fs, /* i : output sampling rate Q0*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const MC_MODE mc_mode, /* i : MC mode */ - const Word16 nchan_transport /* i : number of transport channels Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { DEC_CORE_HANDLE st; @@ -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,11 +756,11 @@ 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 ) ) { - st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() Q0*/ + st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() Q0*/ move16(); } @@ -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 ); } } } @@ -1151,12 +1149,12 @@ void synchro_synthesis_fx( test(); IF( GE_32( hCPE->last_element_brate, IVAS_32k ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo Q0*/ + dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo Q0*/ move16(); } ELSE IF( LE_32( hCPE->last_element_brate, IVAS_24k4 ) && GT_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - dft_mono_brate_switch = 1; /* switch to residual coding mode Q0*/ + dft_mono_brate_switch = 1; /* switch to residual coding mode Q0*/ move16(); } } @@ -1745,7 +1743,7 @@ void stereo_switching_dec( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && GE_32( hCPE->element_brate, IVAS_32k ) && LE_32( hCPE->last_element_brate, IVAS_24k4 ) ) { - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ set32_fx( hCPE->output_mem_fx[0], 0, dft32ms_ovl ); } test(); @@ -1753,7 +1751,7 @@ void stereo_switching_dec( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && hCPE->hCoreCoder[0]->ini_frame > 0 ) { /* windowing the OLA memory */ - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) @@ -1951,10 +1949,8 @@ void stereo_switching_dec( Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); /* Q_exc */ sts[1]->Q_exc = sts[0]->Q_exc; move16(); -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE sts[1]->Q_syn_factor = sts[0]->Q_syn_factor; move16(); -#endif sts[1]->Q_exc_cng = sts[0]->Q_exc_cng; move16(); sts[1]->prev_Q_exc = sts[0]->prev_Q_exc; @@ -2084,7 +2080,7 @@ void stereo_td2dft_update_fx( sts = hCPE->hCoreCoder; ovl = NS2SA_FX2( i_mult( sts[n]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ move16(); hq_delay_comp = NS2SA_FX2( sts[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); @@ -2228,8 +2224,8 @@ void stereo_mdct2dft_update_fx( st = hCPE->hCoreCoder[0]; - fade_len = extract_l( Mpy_32_32( imult3216( st->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ - fade_len_LB = extract_l( Mpy_32_32( imult3216( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, st->L_frame ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + fade_len = extract_l( Mpy_32_32( imult3216( st->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + fade_len_LB = extract_l( Mpy_32_32( imult3216( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, st->L_frame ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ SWITCH( st->output_Fs ) { @@ -2389,7 +2385,7 @@ static Word32 ncross_corr_self_fx( *-------------------------------------------------------------------*/ void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ const Word16 output_frame /* i : output frame lenght Q0*/ ) diff --git a/lib_dec/ivas_stereo_td_dec_fx.c b/lib_dec/ivas_stereo_td_dec_fx.c index 7169e31e2042379f1a720f2460ea0189a92441c5..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" @@ -63,13 +60,13 @@ void stereo_td_init_dec_fx( hStereoTD->tdm_LRTD_flag = 0; move16(); // hStereoTD->prevSP_ratio = 0.5f; - hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 /* Q15 */ + hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 /* Q15 */ move16(); // hStereoTD->SP_ratio_LT = 0.0f; hStereoTD->SP_ratio_LT_fx = 0; move32(); // hStereoTD->c_LR_LT = 0.5f; - hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 /* Q31 */ + hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 /* Q31 */ move32(); hStereoTD->flag_skip_DMX = 0; @@ -216,7 +213,7 @@ void tdm_configure_dec_fx( move16(); } - sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() Q0*/ + sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() Q0*/ move16(); sts[1]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* Q0 */ move16(); @@ -519,7 +516,7 @@ Word32 inv_time[960 + 1] = { }; static void tdm_upmix_fade_fx( Word32 Left_fx[], /* o : left channel Qx*/ - Word32 Right_fx[], /* o : right channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ const Word32 LR_ratio_mem_fx, /* i : last mixing ratio Q31*/ @@ -627,11 +624,11 @@ static void tdm_upmix_fade_fx( void stereo_tdm_combine_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ - const Word16 output_frame, /* i : Number of samples Q0*/ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ - const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -681,7 +678,7 @@ void stereo_tdm_combine_fx( } ELSE { - stereo_tdm_coder_type = 1; /* mode 2 : SM scheme Q0*/ + stereo_tdm_coder_type = 1; /* mode 2 : SM scheme Q0*/ move16(); } } diff --git a/lib_dec/ivas_svd_dec_fx.c b/lib_dec/ivas_svd_dec_fx.c index e904281b6ace1a7c00503e14c45e6e6d36a5c675..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 *-----------------------------------------------------------------------*/ @@ -106,14 +109,14 @@ static Word32 maxWithSign_fx( ); static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word16 *secDiag_fx_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ + Word16 *secDiag_fx_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ const Word32 eps_x, /* i : eps_x_e*/ const Word16 eps_x_e /* i : */ ); @@ -155,16 +158,16 @@ static Word32 GivensRotation_fx( Word16 *out_e ); static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : Q0*/ - const Word16 currentIndex, /* i : Q0*/ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ + const Word16 startIndex, /* i : Q0*/ + const Word16 currentIndex, /* i : Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ); /*------------------------------------------------------------------------- @@ -174,11 +177,11 @@ static void ApplyQRTransform_fx( *-------------------------------------------------------------------------*/ void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector Qx*/ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ - const Word16 nRows, /* i : number of rows of the matrix Q0*/ - const Word16 mCols, /* i : number of columns of the matrix Q0*/ - const Word16 transpose /* i : flag indication transposition Q0*/ + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ ) { Word16 i, j; @@ -231,10 +234,10 @@ void mat2svdMat_fx( *---------------------------------------------------------------------*/ void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ - Word32 *mat, /* o : matrix as column ordered vector Qx*/ - const Word16 nRows, /* i : number of rows of the matrix Q0*/ - const Word16 mCols /* i : number of columns of the matrix Q0*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ ) { Word16 i, j; @@ -261,12 +264,12 @@ void svdMat2mat_fx( Word16 svd_fx( Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ Word16 InputMatrix_e, - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) singularValues_fx_e*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* o : singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) singularValues_fx_e*/ Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ) { Word16 iCh, jCh; @@ -368,14 +371,14 @@ Word16 svd_fx( *-------------------------------------------------------------------------*/ static Word16 BidagonalDiagonalisation_fx( - Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ + Word32 singularVectors_Left_fx[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_fx_e*/ Word32 singularValues_fx[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_fx_e*/ Word32 secDiag_fx[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_fx_e*/ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ - Word16 *secDiag_new_e, /* i/o: */ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) */ + Word16 *secDiag_new_e, /* i/o: */ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC, /* i : number of columns in the matrix to be decomposed Q0*/ const Word32 eps_x, /* i : eps_x_e*/ const Word16 eps_x_e /* i : */ ) @@ -539,16 +542,16 @@ static Word16 BidagonalDiagonalisation_fx( *-------------------------------------------------------------------------*/ static void ApplyQRTransform_fx( - Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ - Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ - Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ - Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ + Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* i/o: left singular vectors (U) singularValues_e*/ + Word32 singularValues[MAX_OUTPUT_CHANNELS], /* i/o: singular values vector (S) singularValues_e*/ + Word32 singularVectors_Right[][MAX_OUTPUT_CHANNELS], /* i/o: right singular vectors (V) singularValues_e*/ + Word32 secDiag[MAX_OUTPUT_CHANNELS], /* i/o: secDiag_e*/ Word16 singularValues_e[MAX_OUTPUT_CHANNELS], Word16 secDiag_e[MAX_OUTPUT_CHANNELS], - const Word16 startIndex, /* i : Q0*/ - const Word16 currentIndex, /* i : Q0*/ - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ + const Word16 startIndex, /* i : Q0*/ + const Word16 currentIndex, /* i : Q0*/ + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ ) { Word32 temp; @@ -1221,7 +1224,7 @@ static void singularVectorsAccumulationRight_fx( Word16 norm_y_e, temp_exp1, sing_right_exp[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; /* Processing */ - nChannels = nChannelsC; /* nChannelsC Q0*/ + nChannels = nChannelsC; /* nChannelsC Q0*/ /* avoid compiler warning */ t_ii = secDiag[nChannels - 1]; /* exp(secDiag_e[nChannels - 1]) */ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 6ee4bfe1899b36e77e6d4878d8e367ee5d6aaacf..4a57618e57dd713ff8f1a14070ff0393bfcbfa13 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,31 +33,29 @@ #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() * * Initialize stereo TCX decoder *-------------------------------------------------------------*/ void stereo_tcx_init_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 last_element_mode /* i : element mode of previous frame Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode /* i : element mode of previous frame Q0*/ ) { TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; @@ -190,18 +188,18 @@ 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*/ - 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*/ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode, /* i : last element mode Q0*/ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const Word16 nchan_out, /* i : number of output channels Q0*/ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + Word32 *signal_out_32_fx, /* o : synthesis @internal_Fs, Q11*/ + 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*/ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel Q0*/ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const Word16 nchan_out, /* i : number of output channels Q0*/ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { Word16 i, k; @@ -226,20 +224,15 @@ void stereo_tcx_core_dec_fx( Word16 pit_gain_fx[NB_SUBFR16k]; /*Synth*/ -#ifdef FIX_1320_STACK_CPE_DECODER Word16 synth_buf_fx[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M]; -#else - Word16 synth_buf_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; -#endif Word16 *synth_fx; Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB_fx; -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Word16 synth_q[2]; -#endif Word32 psd_fx[L_FRAME16k]; Word32 psd_part_fx[NPART_SHAPING]; Word16 psd_part_e; + Word16 signal_out_fx[L_FRAME48k]; TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -269,7 +262,7 @@ void stereo_tcx_core_dec_fx( total_nbbits = extract_l( Mpy_32_32_r( st->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); bitsRead = 0; move16(); - LSF_Q_prediction = -1; /* to avoid compilation warnings Q0*/ + LSF_Q_prediction = -1; /* to avoid compilation warnings Q0*/ move16(); IF( frameMode == FRAMEMODE_NORMAL ) @@ -305,11 +298,7 @@ void stereo_tcx_core_dec_fx( synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); /* q_old_synth - st->Q_syn */ Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); /* q_old_synthFB */ -#ifdef FIX_1320_STACK_CPE_DECODER set16_fx( synth_fx, 0, L_FRAME_PLUS_INTERNAL + M ); -#else - set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); -#endif set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); /*--------------------------------------------------------------------------------* @@ -337,13 +326,13 @@ void stereo_tcx_core_dec_fx( st->core = GetPLCModeDecision_ivas_fx( st ); /* Q0 */ move16(); } -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - IF( st->core != ACELP_CORE ) + + if ( st->core != ACELP_CORE ) { st->Q_syn_factor = 0; move16(); } -#endif + /*--------------------------------------------------------------------------------* * LPC envelope decoding *--------------------------------------------------------------------------------*/ @@ -357,23 +346,8 @@ void stereo_tcx_core_dec_fx( { Word16 tcx_lpc_cdk; -#ifdef FIX_1384_MSAN_stereo_tcx_core_enc tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); move16(); -#else - test(); - test(); - IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) - { - tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); /* Q0 */ - move16(); - } - ELSE - { - tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); /* Q0 */ - move16(); - } -#endif Copy( st->lsf_old_fx, &lsf_fx[0], M ); /* Q2.56 */ Copy( st->lsp_old_fx, &lsp_fx[0], M ); /* Q15 */ @@ -404,7 +378,7 @@ void stereo_tcx_core_dec_fx( FOR( k = 0; k < st->numlpc; ++k ) { - Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2 Q15*/ + Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2 Q15*/ Copy( &lsf_fx[( k + 1 ) * M], &lsfnew_uw_fx[k * M], M ); /* Q2.56 */ } } @@ -498,14 +472,6 @@ void stereo_tcx_core_dec_fx( E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } -#ifndef FIX_1384_MSAN_stereo_tcx_core_enc - test(); - if ( st->enablePlcWaveadjust && bfi ) - { - st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); /* Q0 */ - move16(); - } -#endif /*--------------------------------------------------------------------------------* * TD-TCX concealment *--------------------------------------------------------------------------------*/ @@ -604,13 +570,10 @@ void stereo_tcx_core_dec_fx( } /* TCX decoder */ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], &synth_q[0], bfi, 0, sba_dirac_stereo_flag ); + st->Q_syn_factor = sub( synth_q[0], st->Q_syn ); st->Q_syn = synth_q[0]; -#else - decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], bfi, 0, sba_dirac_stereo_flag ); -#endif } /*--------------------------------------------------------------------------------* @@ -639,7 +602,6 @@ void stereo_tcx_core_dec_fx( } /* TCX decoder */ -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * ( hTcxDec->L_frameTCX / 2 )], &synth_q[k], bfi, k, sba_dirac_stereo_flag ); } @@ -656,10 +618,6 @@ void stereo_tcx_core_dec_fx( q_shift = sub( q_min, synth_q[1] ); scale_sig( &synth_fx[shr( st->L_frame, 1 )], shr( st->L_frame, 1 ), q_shift ); scale_sig( &synthFB_fx[shr( hTcxDec->L_frameTCX, 1 )], shr( hTcxDec->L_frameTCX, 1 ), q_shift ); -#else - decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * ( hTcxDec->L_frameTCX / 2 )], bfi, k, sba_dirac_stereo_flag ); - } -#endif } /*--------------------------------------------------------------------------------* @@ -669,51 +627,12 @@ void stereo_tcx_core_dec_fx( test(); IF( EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, TCX_20_CORE ) ) { -#ifndef FIX_1384_MSAN_stereo_tcx_core_enc - test(); - test(); - IF( st->enablePlcWaveadjust || /* bfi */ - ( GE_32( st->last_total_brate, HQ_48k ) && /* recovery */ - EQ_16( st->last_codec_mode, MODE2 ) ) ) - { - IF( st->hTonalMDCTConc->q_lastPcmOut != 0 ) - { - Scale_sig( st->hTonalMDCTConc->secondLastPcmOut, shr( hTcxDec->L_frameTCX, 1 ), negate( st->hTonalMDCTConc->q_lastPcmOut ) ); - Scale_sig( st->hTonalMDCTConc->lastPcmOut, hTcxDec->L_frameTCX, negate( st->hTonalMDCTConc->q_lastPcmOut ) ); - st->hTonalMDCTConc->q_lastPcmOut = 0; - move16(); - } - /* waveform adjustment */ - concealment_signal_tuning_fx( st, bfi, synthFB_fx, st->last_core_bfi ); - - test(); - test(); - test(); - IF( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch_fx && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) ) - { - lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); - - if ( !bfi && st->prev_bfi ) - { - st->hPlcInfo->Pitch_fx = 0; - move16(); - } - } - } -#endif IF( !bfi && st->hTonalMDCTConc != NULL ) { -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, st->Q_syn, hTcxDec->L_frameTCX ); -#else - TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, 0, hTcxDec->L_frameTCX ); -#endif } -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, st->Q_syn, Aq_fx, bfi, 0 ); -#else - decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, 0, Aq_fx, bfi, 0 ); -#endif IF( EQ_16( st->core, TCX_20_CORE ) ) { @@ -800,8 +719,8 @@ void stereo_tcx_core_dec_fx( IF( EQ_16( bfi, 1 ) ) { - Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery Q15*/ - Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery Q15*/ + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery Q15*/ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery Q15*/ } ELSE { @@ -829,19 +748,22 @@ void stereo_tcx_core_dec_fx( E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); autocorr_fx( buf, M, r_h, r_l, &q_r, L_LP, Assym_window_W16fx, 0, 0 ); lag_wind( r_h, r_l, M, INT_FS_12k8, LAGW_WEAK ); - E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_lev_dur_fx( r_h, r_l, A, NULL, M, NULL ); E_LPC_a_lsp_conversion( A, lsptmp, &lspnew_uw_fx[0], M ); Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 0 ); 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 ) ) @@ -875,13 +797,6 @@ void stereo_tcx_core_dec_fx( IF( !bfi ) { -#ifndef FIX_1384_MSAN_stereo_tcx_core_enc - if ( st->enablePlcWaveadjust ) - { - st->hPlcInfo->nbLostCmpt = 0; - move16(); - } -#endif IF( param[1 + NOISE_FILL_RANGES] != 0 ) { Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ @@ -955,7 +870,6 @@ void stereo_tcx_core_dec_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - Word32 signal_out_32_fx[L_FRAME48k]; 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 ); @@ -971,15 +885,17 @@ void stereo_tcx_core_dec_fx( } } + Copy_Scale_sig_16_32_DEPREC( signal_out_fx, signal_out_32_fx, st->L_frame, sub( Q11, st->Q_syn_factor ) ); + pop_wmops(); return; } static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 last_element_mode, /* i : element mode of previous frame Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : element mode of previous frame Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -1020,9 +936,9 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( return; } static void dec_prm_tcx_ivas_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Word16 param[], /* o : decoded parameters Q0*/ - Word16 param_lpc[], /* o : LPC parameters Q0*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param[], /* o : decoded parameters Q0*/ + Word16 param_lpc[], /* o : LPC parameters Q0*/ Word16 *total_nbbits, /* i/o: number of bits / decoded bits Q0*/ const Word16 last_element_mode, /* i : last element mode Q0*/ Word16 *bitsRead /* o : number of read bits Q0*/ @@ -1062,14 +978,9 @@ static void dec_prm_tcx_ivas_fx( getTCXMode_ivas_fx( st, st, 0 /* <- MCT_flag */ ); /* last_core for error concealment */ -#ifdef FIX_1384_MSAN_stereo_tcx_core_enc IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) -#else - test(); - IF( !st->use_partial_copy && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) -#endif { - st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core Q0*/ + st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core Q0*/ move16(); test(); @@ -1112,25 +1023,18 @@ static void dec_prm_tcx_ivas_fx( } } -#ifndef FIX_1384_MSAN_stereo_tcx_core_enc - IF( !st->use_partial_copy ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { -#endif - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - getTCXWindowing_ivas_fx( st->core, st->last_core, st->element_mode, st->hTcxCfg, st ); - } - st->flagGuidedAcelp = 0; - move16(); + getTCXWindowing_ivas_fx( st->core, st->last_core, st->element_mode, st->hTcxCfg, st ); + } + st->flagGuidedAcelp = 0; + move16(); - if ( st->dec_glr ) - { - st->dec_glr_idx = -1; - move16(); - } -#ifndef FIX_1384_MSAN_stereo_tcx_core_enc + if ( st->dec_glr ) + { + st->dec_glr_idx = -1; + move16(); } -#endif /*--------------------------------------------------------------------------------* * LPC parameters @@ -1145,7 +1049,6 @@ static void dec_prm_tcx_ivas_fx( * TCX20/10 parameters *--------------------------------------------------------------------------------*/ -#ifdef FIX_1384_MSAN_stereo_tcx_core_enc getTCXparam_fx( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 ); IF( LT_16( sub( *total_nbbits, bitsRead[0] ), sub( st->next_bit_pos, start_bit_pos ) ) ) @@ -1158,26 +1061,6 @@ static void dec_prm_tcx_ivas_fx( bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); /* Q0 */ move16(); -#else - IF( st->use_partial_copy == 0 ) - { - getTCXparam_fx( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 ); - } - - IF( !st->use_partial_copy ) - { - IF( LT_16( sub( *total_nbbits, bitsRead[0] ), sub( st->next_bit_pos, start_bit_pos ) ) ) - { - st->BER_detect = 1; - move16(); - st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); /* Q0 */ - move16(); - } - - bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); /* Q0 */ - move16(); - } -#endif return; } diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 59543f4da0928f1846ae0ef222f1c2158a030fbc..916329e66cc4f890b44b393331d3d02465993943 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" @@ -48,14 +46,14 @@ *-------------------------------------------------------------------*/ void tdm_low_rate_dec_fx( - Decoder_State *st, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ + Decoder_State *st, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -105,10 +103,6 @@ void tdm_low_rate_dec_fx( attack_flag = 0; move16(); - move16(); - move16(); - move16(); - move16(); /*--------------------------------------------------------------------------------------* * GSC decoder *--------------------------------------------------------------------------------------*/ @@ -154,12 +148,12 @@ 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 *----------------------------------------------------------------------*/ - pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame ); - + pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame, 0 ); /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -205,15 +199,15 @@ void tdm_low_rate_dec_fx( void decod_gen_2sbfr_fx( Decoder_State *st, /* i/o: decoder static memory */ const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ ) { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ @@ -250,15 +244,12 @@ void decod_gen_2sbfr_fx( error = 0; move16(); - move16(); - move16(); - move16(); /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq = Aq; /* pointer to interpolated LPC parameters Q12*/ - pt_pitch = pitch_buf; /* pointer to the pitch buffer Q6*/ + p_Aq = Aq; /* pointer to interpolated LPC parameters Q12*/ + pt_pitch = pitch_buf; /* pointer to the pitch buffer Q6*/ FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR ) { @@ -272,12 +263,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 +289,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 +297,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 8d5bcb6d44d5b17eadaff2eec26c3649476e19b8..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef JBM_JB4_CIRCULARBUFFER_H diff --git a/lib_dec/jbm_jb4_circularbuffer_fx.c b/lib_dec/jbm_jb4_circularbuffer_fx.c index 0eeb1cb1f7cd4dc14409ac0bc9278e73f3a90b85..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/jbm_jb4_inputbuffer.h b/lib_dec/jbm_jb4_inputbuffer.h index 76eb3512393b68b48ae22d6673dbd7725353227e..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /** \file jbm_jb4_inputbuffer.h RTP input buffer with fixed capacity. */ diff --git a/lib_dec/jbm_jb4_inputbuffer_fx.c b/lib_dec/jbm_jb4_inputbuffer_fx.c index f8de8e76533ac614e74e6599a07bfed488de9459..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /** \file jbm_jb4_inputbuffer.c RTP input buffer with fixed capacity. */ diff --git a/lib_dec/jbm_jb4_jmf.h b/lib_dec/jbm_jb4_jmf.h index e92c629a813a55855fbc72fdd88275c8a0f12543..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /** \file jbm_jb4_jmf.h jitter measure fifo - a fifo used for windowed measure of network status */ diff --git a/lib_dec/jbm_jb4_jmf_fx.c b/lib_dec/jbm_jb4_jmf_fx.c index 765de8ed31ef09f5027ad5b5816750775b00c2f2..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /** \file jbm_jb4_jmf.c jitter measure fifo - a fifo used for windowed measure of network status */ diff --git a/lib_dec/jbm_jb4sb.h b/lib_dec/jbm_jb4sb.h index acc44ad32611f646884873a9fab5b231165ffd80..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /** \file jbm_jb4sb.h EVS Jitter Buffer Management Interface */ diff --git a/lib_dec/jbm_jb4sb_fx.c b/lib_dec/jbm_jb4sb_fx.c index eccd8cb030efc927998ef6e1cb2d373e5833c901..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! \file jbm_jb4sb.c EVS Jitter Buffer Management Interface */ @@ -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 98dd104c270fac938feced5ac51495e2103eabf6..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! @file jbm_pcmdsp_apa.h Adaptive Playout for Audio (apa). */ @@ -50,14 +50,9 @@ */ /* size of IO buffers (a_in[], a_out[]) for apa_exec() */ -#ifdef JBM_MEMORY_OPT #define APA_BUF_PER_CHANNEL ( IVAS_MAX_FRAME_SIZE * 2 ) /* == twice the max. frame length */ #define APA_MAX_NUM_CHANNELS ( 12 ) /* == MAX_TRANSPORT_CHANNELS */ -#else -#define APA_BUF_PER_CHANNEL ( IVAS_MAX_FRAME_SIZE * 3 ) -#define APA_MAX_NUM_CHANNELS 16 -#endif -#define APA_BUF ( APA_BUF_PER_CHANNEL * APA_MAX_NUM_CHANNELS ) +#define APA_BUF ( APA_BUF_PER_CHANNEL * APA_MAX_NUM_CHANNELS ) /* min/max sampling rate [Hz] */ #define APA_MIN_RATE 1000 diff --git a/lib_dec/jbm_pcmdsp_apa_fx.c b/lib_dec/jbm_pcmdsp_apa_fx.c index bc9ef573f8339baec7b10a82e745e8852cc3d8a8..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 @@ -31,14 +31,13 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! @file jbm_pcmdsp_apa.c Adaptive Playout for Audio (apa). */ /* system headers */ #include -#include #include #include #include @@ -127,11 +126,8 @@ struct apa_state_t UWord16 qualityred; /* quality reduction threshold */ UWord16 qualityrise; /* quality rising for adaptive quality thresholds */ -#ifdef FIX_2173_UBSAN_IN_JBM_PCMDSP_APA Word16 last_pitch; /* last pitch/sync position */ -#else - UWord16 last_pitch; /* last pitch/sync position */ -#endif + UWord16 bad_frame_count; /* # frames before quality threshold is lowered */ UWord16 good_frame_count; /* # scaled frames */ @@ -694,11 +690,7 @@ UWord8 apa_exec_fx( ) { UWord16 i; -#ifdef JBM_MEMORY_OPT - 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 */ -#else - Word16 frm_in[APA_BUF]; /* TODO(mcjbm): this buffer could be smaller - always allocates space for 16 channels */ -#endif + Word16 frm_in[APA_BUF_PER_CHANNEL]; /* NOTE: this buffer could be smaller if alocated dynamically based on the actual sampling rate */ UWord16 l_frm_out; Word16 l_rem; Word32 dl_scaled, dl_copied, l_frm_out_target; @@ -914,11 +906,7 @@ UWord8 apa_exec_ivas_fx( ) { UWord16 i; -#ifdef JBM_MEMORY_OPT Word16 frm_in[APA_BUF]; /* NOTE: this buffer could be smaller if alocated dynamically based on the actual sampling rate and number of channels */ -#else - Word16 frm_in[APA_BUF]; /* TODO(mcjbm): this buffer could be smaller - always allocates space for 16 channels */ -#endif UWord16 l_frm_out; Word16 l_rem; Word32 dl_scaled, dl_copied, l_frm_out_target; @@ -927,11 +915,7 @@ UWord8 apa_exec_ivas_fx( Word16 Q_a_out; Word16 Q_a_out_init_old; -#ifdef FIX_APA_EXECS_SCALING Q_a_out = add( getScaleFactor32_copy( a_in, l_in ), Q11 - Q16 - Q1 ); -#else - Q_a_out = add( getScaleFactor32_copy( a_in, L_mult0( ps->num_channels, APA_BUF_PER_CHANNEL ) ), Q11 - Q16 - Q1 ); -#endif Q_a_out_init_old = Q_a_out; /* store the possible scaling of a_in, to be re-used in the next frame */ move16(); statsResetThreshold = 1637; @@ -1008,11 +992,7 @@ UWord8 apa_exec_ivas_fx( Scale_sig( ps->buf_out_fx, ps->buf_out_capacity, sub( Q_a_out, ps->Q_buf_out ) ); // Q_buf_out -> Q_a_out IF( EQ_32( ps->scale, 100 ) ) { -#ifdef FIX_APA_EXECS_SCALING FOR( i = 0; i < ps->l_frm; i++ ) -#else - FOR( i = 0; i < ps->num_channels * APA_BUF_PER_CHANNEL; i++ ) -#endif { a_out[i] = a_in[i]; // Q11 move32(); @@ -1024,11 +1004,7 @@ UWord8 apa_exec_ivas_fx( { Word16 *frm_in_ptr = &( frm_in[ps->l_frm] ); -#ifdef FIX_APA_EXECS_SCALING FOR( i = 0; i < ps->l_frm; i++ ) -#else - FOR( i = 0; i < ps->num_channels * APA_BUF_PER_CHANNEL; i++ ) -#endif { a_tmp[i] = extract_h( L_shl( a_in[i], add( Q_a_out, Q5 ) ) ); // Q_a_out move16(); @@ -1078,11 +1054,7 @@ UWord8 apa_exec_ivas_fx( } } -#ifdef FIX_APA_EXECS_SCALING FOR( i = 0; i < l_frm_out; i++ ) -#else - FOR( i = 0; i < ps->num_channels * APA_BUF_PER_CHANNEL; i++ ) -#endif { a_out[i] = L_shl( a_tmp[i], sub( Q11, Q_a_out ) ); // Q0 -> Q11 move32(); @@ -1396,11 +1368,7 @@ static Word8 logarithmic_search_fx( const apa_state_t *ps, DO { -#ifdef FIX_2173_UBSAN_IN_JBM_PCMDSP_APA coeff_max = INT32_MIN; /* will always be overwritten with result of first correlation */ -#else - coeff_max = 0x80000000; /* will always be overwritten with result of first correlation */ -#endif move32(); FOR( i = s_start; i < s_start + inlen; i += css * ps->num_channels ) diff --git a/lib_dec/jbm_pcmdsp_fifo.h b/lib_dec/jbm_pcmdsp_fifo.h index 45acb98beb77a35bcec234fe4f0363b321a85041..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! @file jbm_pcmdsp_fifo.h Ringbuffer (FIFO) with fixed capacity for audio samples. */ diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 7adbcd65f697dda25e8bd76e672d84b00edf3c27..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! @file jbm_pcmdsp_similarityestimation.h Algorithms for correlation and similarity estimation. */ diff --git a/lib_dec/jbm_pcmdsp_similarityestimation_fx.c b/lib_dec/jbm_pcmdsp_similarityestimation_fx.c index 25d8d2d8b2a6cf5389566db6164d33ea4a71fac8..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 @@ -31,14 +31,13 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! @file jbm_pcmdsp_similarityestimation.c Algorithms for correlation and similarity estimation. */ /* 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 9c6f10408254cfed60dcb9ec51c633a4d6fcf688..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ /*! @file jbm_jbm_pcmdsp_window.h Window functions. */ diff --git a/lib_dec/jbm_pcmdsp_window_fx.c b/lib_dec/jbm_pcmdsp_window_fx.c index 8572586c3b3edc085ca8796e08477c65cddb875c..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 @@ -31,10 +31,9 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ -#include #include #include #include "options.h" diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index ecc5f6fe01a50d55b5156784ae951993658b3092..3773990a1f55df3b3d9e1dd0201615ebb13fd001 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index e911a5fca55eddc30366d708ed6168467813b2ee..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 @@ -37,6 +37,7 @@ #include #include "typedef.h" + /*---------------------------------------------------------------------* * Decoder enums *---------------------------------------------------------------------*/ @@ -111,13 +112,14 @@ 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 */ 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 */ @@ -150,9 +152,6 @@ ivas_error IVAS_DEC_ReadFormat( ivas_error IVAS_DEC_GetSamplesDecoder( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - const Word16 isSplitRend, /* i : split rendering enabled flag */ -#endif ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ ); @@ -206,12 +205,14 @@ ivas_error IVAS_DEC_GetCldfbSamples( Word16 *nOutSamples /* o : number of samples per channel written to output buffer */ ); -Word16 IVAS_DEC_is_split_rendering_enabled( +/*! r: decoder error code */ +ivas_error IVAS_DEC_is_split_rendering_enabled( IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ Word16 *isSplitRend /* o : flag to indicate if split rendering is enabled */ ); -Word16 IVAS_DEC_is_split_rendering_coded_out( +/*! r: decoder error code */ +ivas_error IVAS_DEC_is_split_rendering_coded_out( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ Word16 *isSplitCoded /* o : flag to indicate if split rendering is enabled */ ); @@ -283,7 +284,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( #ifdef VARIABLE_SPEED_DECODING ivas_error IVAS_DEC_EnableTsm( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ ); ivas_error IVAS_DEC_TSM_SetQuality( @@ -307,7 +308,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples( const UWord32 systemTimestamp_ms /* i : current system timestamp */ ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ @@ -323,7 +323,6 @@ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( bool *parametersAvailableForEditing, /* o : indicates whether objects editing is available */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ ); -#endif ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ @@ -332,13 +331,20 @@ ivas_error IVAS_DEC_Flush( Word16 *nSamplesFlushed /* o : number of samples flushed */ ); +ivas_error IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + bool *restartNeeded /* o : flag to signal decoder restart */ +); + + + /* Setter functions - apply changes to decoder configuration */ /*! r: error code */ ivas_error IVAS_DEC_EnableVoIP( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 jbmSafetyMargin, /* i : allowed delay reserve for JBM, in milliseconds */ - const IVAS_DEC_INPUT_FORMAT inputFormat /* i : format of the input bitstream */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const Word16 jbmSafetyMargin, /* i : allowed delay reserve for JBM, in milliseconds */ + const IVAS_DEC_INPUT_FORMAT inputFormat /* i : format of the input bitstream */ ); /*! r: error code */ @@ -346,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( @@ -366,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 */ ); @@ -446,6 +447,17 @@ ivas_error IVAS_DEC_HRTF_binary_close( const IVAS_BIN_RENDERER_TYPE binaural_renderer_old /* i : previous binaural renderer type */ ); +ivas_error IVAS_DEC_AddAcousticEnvironment( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i: Room acoustic configuration */ +); + +ivas_error IVAS_DEC_GetAcousticEnvironment( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + UWord16 aeID, /* i : Acoustic environment ID */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o : Room acoustic environment data pointer */ +); + /*! r: error code*/ ivas_error IVAS_DEC_GetRenderConfig( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ @@ -477,9 +489,10 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( ); /*! r: true if decoder has no data in VoIP jitter buffer */ -bool IVAS_DEC_VoIP_IsEmpty( +ivas_error IVAS_DEC_VoIP_IsEmpty( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 nSamplesAsked + const Word16 nSamplesAsked, /* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ ); ivas_error IVAS_DEC_VoIP_Get_CA_offset( @@ -495,6 +508,13 @@ ivas_error IVAS_DEC_GetJbmData( ); #endif +ivas_error IVAS_DEC_FeedPiDataToDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_PIDATA_TS *piData, /* i : PI data received in rtp packet */ + UWord32 numPiData /* i : number of PI data received in rtp packet */ +); + + /* Utility functions */ /*! r: pointer to an error message string */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index ae2027e1093cc08edf740f5cce3a4bae4e0150c2..cbf28203793ef8e8b8876e4b530c97a315ad1297 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 @@ -31,9 +31,6 @@ *******************************************************************************************************/ #include "lib_dec.h" -#include -#include -#include #include "ivas_cnst.h" #include "ivas_prot_rend_fx.h" #include "prot_fx.h" @@ -44,7 +41,6 @@ #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" -#include #include #include "wmc_auto.h" @@ -85,9 +81,6 @@ struct IVAS_DEC Word16 tsm_max_scaling; Word16 timeScalingDone; /* have we done already one TSM in a 20ms frame? */ Word16 tsm_quality; /*Q14*/ -#ifndef JBM_MEMORY_OPT - Word32 *apaExecBuffer_fx; /* Buffer for APA scaling */ -#endif PCMDSP_APA_HANDLE hTimeScaler; bool needNewFrame; bool hasBeenFedFrame; @@ -116,23 +109,17 @@ static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, c static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas ); static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, Word16 *bitstream_format_internal, Word16 *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, UWord8 *nTransportChannels, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); -#else -static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, UWord8 *nTransportChannels, const Word16 isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); -#endif static ivas_error apa_setup( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const UWord16 nTransportChannels ); -static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP -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 ); -#endif -static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered ); static ivas_error isar_set_split_rend_setup( ISAR_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, const ISAR_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); 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( 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 ); /*---------------------------------------------------------------------* @@ -166,9 +153,6 @@ ivas_error IVAS_DEC_Open( hIvasDec = *phIvasDec; hIvasDec->hVoIP = NULL; -#ifndef JBM_MEMORY_OPT - hIvasDec->apaExecBuffer_fx = NULL; -#endif hIvasDec->hTimeScaler = NULL; hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; @@ -244,44 +228,45 @@ ivas_error IVAS_DEC_Open( /* initialize pointers to handles to NULL */ ivas_initialize_handles_dec( st_ivas ); + st_ivas->restartNeeded = 0; + 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(); @@ -292,17 +277,14 @@ ivas_error IVAS_DEC_Open( move16(); move16(); move16(); - move16(); - move16(); - move16(); - move16(); - move16(); + return IVAS_ERR_OK; } return IVAS_ERR_WRONG_PARAMS; } + /*-------------------------------------------------------------------------* * isar_set_split_rend_setup() * @@ -324,13 +306,14 @@ static ivas_error isar_set_split_rend_setup( splitRendBits->codec_frame_size_ms = 0; splitRendBits->isar_frame_size_ms = 0; splitRendBits->lc3plus_highres = 0; - -#ifndef TMP_FIX_SPLIT_REND - IF( ( hSplitBinRend->hMultiBinCldfbData = (ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" ); - } -#endif + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); ISAR_PRE_REND_GetMultiBinPoseData( hSplitBinConfig, &hSplitBinRend->splitrend.multiBinPoseData, ( hCombinedOrientationData != NULL ) ? hCombinedOrientationData->sr_pose_pred_axis : DEFAULT_AXIS ); @@ -342,6 +325,7 @@ static ivas_error isar_set_split_rend_setup( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * init_decoder_config() * @@ -353,12 +337,14 @@ static void init_decoder_config( ) { hDecoderConfig->Opt_AMR_WB = 0; + hDecoderConfig->output_Fs = -1; hDecoderConfig->nchan_out = 1; hDecoderConfig->output_config = IVAS_AUDIO_CONFIG_INVALID; hDecoderConfig->Opt_LsCustom = 0; hDecoderConfig->Opt_HRTF_binary = 0; hDecoderConfig->Opt_Headrotation = 0; hDecoderConfig->Opt_RendConfigCustom = 0; + hDecoderConfig->room_size = IVAS_ROOM_SIZE_AUTO; hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE; hDecoderConfig->Opt_non_diegetic_pan = 0; hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15 @@ -369,6 +355,7 @@ static void init_decoder_config( hDecoderConfig->Opt_aeid_on = 0; hDecoderConfig->Opt_ObjEdit_on = 0; move16(); + move32(); move16(); move16(); move16(); @@ -412,23 +399,18 @@ void IVAS_DEC_Close( ( *phIvasDec )->hVoIP = NULL; } - /* destroy Split binaural renderer (ISAR) handle */ - ivas_destroy_handle_isar( &( *phIvasDec )->st_ivas->hSplitBinRend ); - IF( ( *phIvasDec )->st_ivas ) { + /* destroy Split binaural renderer (ISAR) handle */ + ivas_destroy_handle_isar( &( *phIvasDec )->st_ivas->hSplitBinRend ); + + /* destroy IVAS decoder handles */ ivas_destroy_dec_fx( ( *phIvasDec )->st_ivas ); ( *phIvasDec )->st_ivas = NULL; } apa_exit( &( *phIvasDec )->hTimeScaler ); -#ifndef JBM_MEMORY_OPT - IF( ( *phIvasDec )->apaExecBuffer_fx != NULL ) - { - free( ( *phIvasDec )->apaExecBuffer_fx ); - } -#endif IF( ( *phIvasDec )->flushbuffer != NULL ) { free( ( *phIvasDec )->flushbuffer ); @@ -507,22 +489,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 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; @@ -547,8 +530,21 @@ ivas_error IVAS_DEC_Configure( test(); test(); test(); - IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && !( ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MONO ) && non_diegetic_pan_enabled == false ) || - ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_STEREO ) && non_diegetic_pan_enabled ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && + ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_INVALID ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM1 ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM2 ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM3 ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM4 ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MASA1 ) || + EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MASA2 ) ) ) { return IVAS_ERR_WRONG_MODE; } @@ -585,12 +581,13 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->orientation_tracking = orientation_tracking; hDecoderConfig->Opt_HRTF_binary = (Word16) hrtfReaderEnabled; hDecoderConfig->Opt_RendConfigCustom = (Word16) renderConfigEnabled; + hDecoderConfig->room_size = roomSize; hDecoderConfig->Opt_non_diegetic_pan = (Word16) non_diegetic_pan_enabled; hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15 hDecoderConfig->Opt_delay_comp = (Word16) delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = (Word16) dpidEnabled; - IF( NE_32( (Word32) acousticEnvironmentId, 65535 ) ) + IF( NE_32( (UWord16) acousticEnvironmentId, IVAS_DEFAULT_AEID ) ) { hDecoderConfig->Opt_aeid_on = TRUE; } @@ -612,18 +609,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(); @@ -677,7 +680,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; @@ -690,35 +693,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(); @@ -728,48 +719,50 @@ ivas_error IVAS_DEC_SetRenderFramesize( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + 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(); } - hIvasDec->st_ivas->hDecoderConfig->render_framesize = render_framesize; - move16(); - return IVAS_ERR_OK; } /*---------------------------------------------------------------------* - * 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; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*---------------------------------------------------------------------* * get_render_frame_size_samples( ) * @@ -781,17 +774,18 @@ static Word16 get_render_frame_size_samples( ) { Word16 tmp; - tmp = (Word16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 ); - IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) + tmp = extract_l( Mpy_32_16_1( hDecoderConfig->output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + + 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 ); } @@ -799,12 +793,13 @@ static Word16 get_render_frame_size_samples( { tmp = 0; } + return tmp; } -#endif + /*---------------------------------------------------------------------* - * IVAS_DEC_GetGetRenderFramesizeSamples( ) + * IVAS_DEC_GetRenderFramesizeSamples( ) * * Get render framesize in samples *---------------------------------------------------------------------*/ @@ -814,10 +809,6 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( Word16 *render_framesize /* o : render framesize in samples Q0 */ ) { -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - Word16 tmp; -#endif - test(); test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL ) @@ -825,33 +816,13 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP *render_framesize = get_render_frame_size_samples( hIvasDec->st_ivas->hDecoderConfig ); -#else - tmp = (Word16) Mpy_32_16_1( hIvasDec->st_ivas->hDecoderConfig->output_Fs, INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 ); - - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) - { - *render_framesize = tmp; - } - ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) - { - *render_framesize = shl( tmp, 1 ); - } - ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) - { - *render_framesize = shl( tmp, 2 ); - } - ELSE - { - *render_framesize = 0; - } -#endif move16(); return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeMs( ) * @@ -870,12 +841,13 @@ 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; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetReferencesUpdateFrequency( ) * @@ -894,17 +866,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(); @@ -913,30 +885,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( ) @@ -1046,13 +994,11 @@ ivas_error IVAS_DEC_FeedFrame_Serial( { ivas_error error; -#ifdef FIX_1388_MSAN_ivas_init_decoder test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#endif IF( !hIvasDec->isInitialized ) { @@ -1060,24 +1006,15 @@ ivas_error IVAS_DEC_FeedFrame_Serial( * In IVAS mode, initialization is done in ivas_dec(). */ IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { -#ifdef FIX_1388_MSAN_ivas_init_decoder hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00; move32(); + hIvasDec->st_ivas->transport_config = IVAS_AUDIO_CONFIG_MONO; + move32(); -#endif IF( NE_32( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - Word32 ivas_total_brate = hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate; - move32(); - test(); - IF( ( EQ_16( hIvasDec->st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_16( hIvasDec->st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) - { - MC_LS_SETUP mc_ls_setup; - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( hIvasDec->st_ivas->transport_config ); - hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup ); - } test(); IF( hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL ) @@ -1090,13 +1027,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = imult3216( hIvasDec->hVoIP->hCurrentDataUnit->dataSize, FRAMES_PER_SEC ); move32(); } -#ifndef FIX_1388_MSAN_ivas_init_decoder - ELSE - { - hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00; - move32(); - } -#endif + hIvasDec->isInitialized = true; move16(); } @@ -1166,7 +1097,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( return IVAS_ERR_OK; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + /*---------------------------------------------------------------------* * isar_get_frame_size( ) * @@ -1184,16 +1115,16 @@ 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( ar_div( output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); - nSamplesPerChannel = imult1616( nSamplesPerChannel, st_ivas->hDecoderConfig->render_framesize ); + nSamplesPerChannel = extract_l( Mpy_32_16_1( output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + nSamplesPerChannel = imult1616( nSamplesPerChannel, st_ivas->hDecoderConfig->render_num_subframes ); } ELSE { - nSamplesPerChannel = extract_l( ar_div( output_Fs, FRAMES_PER_SEC ) ); + nSamplesPerChannel = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); } return nSamplesPerChannel; @@ -1213,10 +1144,6 @@ static ivas_error isar_render_poses( bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) { -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - // Note for reviewers: Code in this function was moved and adapted from IVAS_DEC_GetSplitBinauralBitstream, - // see #else branch of FIX_1119_SPLIT_RENDERING_VOIP there for reference -#endif Word16 pcmBuf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES * L_FRAME48k]; Decoder_Struct *st_ivas; ivas_error error; @@ -1242,8 +1169,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 ); } @@ -1279,10 +1210,6 @@ static ivas_error isar_generate_metadata_and_bitstream( Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS] /* o : Q-format of each channel of p_head_pose_buf */ ) { -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - // Note for reviewers: Code in this function was moved and adapted from IVAS_DEC_GetSplitBinauralBitstream, - // see #else branch of FIX_1119_SPLIT_RENDERING_VOIP there for reference -#endif ivas_error error; ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; Word16 max_band; @@ -1308,15 +1235,15 @@ static ivas_error isar_generate_metadata_and_bitstream( move16(); } - n_samples_in_cldfb_slot = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - assert( nSamples % n_samples_in_cldfb_slot == 0 ); - num_cldfb_slots = int_div_s_x( nSamples, n_samples_in_cldfb_slot ); - - num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; - move16(); - IF( cldfb_in_flag ) { + n_samples_in_cldfb_slot = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + assert( nSamples % n_samples_in_cldfb_slot == 0 ); + num_cldfb_slots = int_div_s_x( nSamples, n_samples_in_cldfb_slot ); + + num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; + move16(); + FOR( i = 0; i < imult1616( BINAURAL_CHANNELS, num_poses ); ++i ) { FOR( j = 0; j < num_cldfb_slots; ++j ) @@ -1336,8 +1263,12 @@ static ivas_error isar_generate_metadata_and_bitstream( ELSE { ivas_TD_RINGBUF_PopChannels( st_ivas->hSplitBinRend->hMultiBinTdData, p_head_pose_buf, nSamples ); - } + num_cldfb_slots = 0; // just to avoid compilation warning + num_poses = 0; // just to avoid compilation warning + move16(); + move16(); + } IF( st_ivas->hBinRendererTd != NULL ) { @@ -1402,7 +1333,6 @@ static ivas_error isar_generate_metadata_and_bitstream( { /*TD input*/ /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/ - /* local float2fix, to be removed */ num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; move16(); @@ -1439,7 +1369,6 @@ static ivas_error isar_generate_metadata_and_bitstream( return IVAS_ERR_OK; } -#endif /* FIX_1119_SPLIT_RENDERING_VOIP */ /*---------------------------------------------------------------------* @@ -1458,7 +1387,7 @@ ivas_error IVAS_DEC_GetSamplesRenderer( { ivas_error error; UWord16 nSamplesRendered, nSamplesRendered_loop; - UWord16 nOutChannels; + UWord8 nOutChannels; Decoder_Struct *st_ivas; nSamplesRendered = 0; @@ -1519,11 +1448,12 @@ ivas_error IVAS_DEC_GetSamplesRenderer( move16(); move16(); move16(); + return IVAS_ERR_OK; } - test(); /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */ + test(); IF( !hIvasDec->isInitialized && st_ivas->bfi ) { hIvasDec->hasBeenFedFrame = false; @@ -1540,11 +1470,7 @@ ivas_error IVAS_DEC_GetSamplesRenderer( hIvasDec->hasBeenFedFrame = false; /* check for possible flushed samples from a rate switch */ -#ifdef FIX_2174_JBM_BASOP_ALIGNMENT IF( GT_16( hIvasDec->nSamplesFlushed, 0 ) ) -#else - IF( GE_16( hIvasDec->nSamplesFlushed, 0 ) ) -#endif { /* note: offset (rendered samples) is always 0 */ Copy( hIvasDec->flushbuffer, pcmBuf, imult1616( hIvasDec->nSamplesFlushed, nOutChannels ) ); @@ -1556,7 +1482,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; } @@ -1591,14 +1517,13 @@ ivas_error IVAS_DEC_GetSamplesRenderer( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetSplitBinauralBitstream( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ - ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ - Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* o : indication that the decoder needs a new frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + Word16 *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ + Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ + bool *needNewFrame /* o : indication that the decoder needs a new frame */ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Decoder_Struct *st_ivas; ivas_error error; Word32 head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k]; @@ -1658,373 +1583,94 @@ 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, (int16_t *) pcmBuf_out ); + ivas_syn_output_fx( p_head_pose_buf, Q11, numSamplesPerChannelToOutput, st_ivas->hDecoderConfig->nchan_out, pcmBuf_out ); } -#else - Decoder_Struct *st_ivas; - AUDIO_CONFIG output_config; - Word32 output_Fs; - Word32 *pOutput[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES]; - Word32 Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 numSamplesPerChannelToDecode; - Word16 i, j, k; + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * ivas_dec_setup_all() + * + * Set-up all decoder parts: IVAS decoder, ISAR + *---------------------------------------------------------------------*/ + +static ivas_error ivas_dec_setup_all( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +) +{ ivas_error error; - ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; - Word16 max_band; - Word16 pcm_out_flag; - Word16 td_input; - Word16 numPoses; - Word16 slots_rendered, slots_rendered_new; - Word16 ro_md_flag; - IVAS_QUATERNION Quaternion; - test(); - IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; + *nTransportChannels = 1; + move16(); } + ELSE + { + Decoder_Struct *st_ivas; - st_ivas = hIvasDec->st_ivas; - output_config = st_ivas->hDecoderConfig->output_config; - output_Fs = st_ivas->hDecoderConfig->output_Fs; - numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC ); // TODO remove division - - *needNewFrame = false; - hSplitBinRend = st_ivas->hSplitBinRend; + st_ivas = hIvasDec->st_ivas; - FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; i++ ) - { - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) + /* Setup IVAS split rendering */ + IF( splitRendBits != NULL ) { - FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) + IF( ( error = isar_set_split_rend_setup( st_ivas->hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) { - Cldfb_RealBuffer_Binaural[i][j][k] = 0; - Cldfb_ImagBuffer_Binaural[i][j][k] = 0; - move32(); - move32(); + return error; } } - } - FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; i++ ) - { - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) + /*----------------------------------------------------------------* + * IVAS decoder setup + * - read IVAS format signaling + * - read IVAS format specific signaling + * - initialize decoder in the first frame based on IVAS format and number of transport channels + * - reconfigure the decoder when the number of TC or IVAS total bitrate change + *----------------------------------------------------------------*/ + + IF( EQ_16( st_ivas->bfi, 0 ) ) { - set32_fx( hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + error = IVAS_ERR_OK; // this is just to help the clang-formatting keep alignments + IF( ( error = ivas_dec_setup( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - - numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; - move16(); - - /* init flush buffer for rate switch if not already initizalized */ - IF( hIvasDec->flushbuffer == NULL ) - { - hIvasDec->flushbuffer = (void *) malloc( numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float ) ); - set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); - } - IF( NE_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) && - ( EQ_32( st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) || - EQ_16( st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) ) - { - numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC ); // TODO remove division - numSamplesPerChannelToDecode = (Word16) ( numSamplesPerChannelToDecode / MAX_PARAM_SPATIAL_SUBFRAMES ); // TODO remove division - numSamplesPerChannelToDecode *= (Word16) st_ivas->hDecoderConfig->render_framesize; + *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_rend; move16(); - move16(); - } - IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 ) - { - return IVAS_ERR_WRONG_PARAMS; - } + /*-----------------------------------------------------------------* + * ISAR: + * - initialize ISAR handle at the first frame + * - reconfigure the ISAR handle in case of bitrate switching (renderer might change) + *-----------------------------------------------------------------*/ - test(); - IF( st_ivas->hTcBuffer == NULL || hIvasDec->hasBeenFedFrame ) - { - slots_rendered = 0; - } - ELSE - { - /* this is needed for OMASA-DISC, because the td-rend granularity is 240 samples at 48kHz, leading to wrong slot count. */ test(); - IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + IF( EQ_16( st_ivas->ini_frame, 0 ) && splitRendBits != NULL ) { - slots_rendered = st_ivas->hTcBuffer->n_samples_rendered / NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // TODO remove division + IF( ( error = ivas_dec_init_split_rend( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - ELSE + + test(); + IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - slots_rendered = st_ivas->hTcBuffer->n_samples_rendered / st_ivas->hTcBuffer->n_samples_granularity; - } - } - - /* Decode and render */ - IF( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, numSamplesPerChannelToDecode, pcmBuf_out, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) - { - return error; - } - - IF( !hIvasDec->hasBeenFedFirstGoodFrame ) - { - return IVAS_ERR_OK; - } - - FOR( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i ) - { - pOutput[i] = hSplitBinRend->hMultiBinCldfbData->output_fx[i]; - move32(); - } - - IF( st_ivas->hTcBuffer == NULL ) - { - slots_rendered_new = 0; - move16(); - } - ELSE - { - /* this is needed for OMASA-DISC, because the td-rend granularity is 240 samples at 48kHz, leading to wrong slot count. */ - IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) - { - slots_rendered_new = st_ivas->hTcBuffer->n_samples_rendered / NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // TODO remove division - } - ELSE - { - slots_rendered_new = st_ivas->hTcBuffer->n_samples_rendered / st_ivas->hTcBuffer->n_samples_granularity; // TODO remove division - } - } - - FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); ++i ) - { - FOR( j = slots_rendered; j < slots_rendered_new; ++j ) - { - Copy32( hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[i][j], Cldfb_RealBuffer_Binaural[i][j - slots_rendered], CLDFB_NO_CHANNELS_MAX ); - Copy32( hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[i][j], Cldfb_ImagBuffer_Binaural[i][j - slots_rendered], CLDFB_NO_CHANNELS_MAX ); - } - } - - max_band = (Word16) ( ( BINAURAL_MAXBANDS * output_Fs ) / 48000 ); // TODO remove division - move16(); - pcm_out_flag = ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0; - td_input = st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC; - - IF( st_ivas->hBinRendererTd != NULL ) - { - ro_md_flag = 1; - move16(); - } - ELSE - { - ro_md_flag = 0; - move16(); - } - - IF( st_ivas->hHeadTrackData != NULL ) - { - Quaternion = st_ivas->hHeadTrackData->Quaternions[0]; - } - ELSE - { - Quaternion.w_fx = -12582912; - Quaternion.x_fx = 0; - Quaternion.y_fx = 0; - Quaternion.z_fx = 0; - } - Word16 q1 = 31, q2 = 31, Q_buff; - Word16 Q_out[CLDFB_NO_COL_MAX]; - Q_out[0] = 31; - Word16 num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; - - FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); i++ ) - { - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) - { - q1 = s_min( q1, L_norm_arr( Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) ); - q2 = s_min( q2, L_norm_arr( Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) ); - } - } - Q_buff = s_min( q1, q2 ); - FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); i++ ) - { - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) - { - scale_sig32( Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff ); - scale_sig32( Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff ); - } - } - Q_buff = add( Q_buff, Q6 ); - - IF( NE_16( td_input, 0 ) ) - { - /*TD input*/ - /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/ - /* local float2fix, to be removed */ - num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; - - FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i ) - { - Q_out[0] = s_min( Q_out[0], L_norm_arr( pOutput[i], L_FRAME48k ) ); - } - - FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i ) - { - scale_sig32( pOutput[i], L_FRAME48k, Q_out[0] ); - } - Q_out[0] = add( Q_out[0], Q11 ); - Q_out[1] = Q_out[0]; - } - - IF( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( &hSplitBinRend->splitrend, - Quaternion, - st_ivas->hRenderConfig->split_rend_config.splitRendBitRate, - st_ivas->hRenderConfig->split_rend_config.codec, - st_ivas->hRenderConfig->split_rend_config.isar_frame_size_ms, - st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms, - splitRendBits, - Cldfb_RealBuffer_Binaural, - Cldfb_ImagBuffer_Binaural, - max_band, pOutput, 1, !td_input, pcm_out_flag, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* convert to int16 with limiting for BINAURAL_SPLIT_PCM */ - IF( pcm_out_flag ) - { - FOR( j = 0; j < BINAURAL_CHANNELS; j++ ) - { - scale_sig32( pOutput[j], numSamplesPerChannelToDecode, sub( Q11, Q_out[j] ) ); // Q11 - } - IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) - { -#ifndef DISABLE_LIMITER - ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 ); -#endif - } - else - { - ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 ); - } - - ivas_syn_output_fx( pOutput, Q11, numSamplesPerChannelToDecode, st_ivas->hDecoderConfig->nchan_out, (Word16 *) pcmBuf_out ); - } - -#ifndef TMP_FIX_SPLIT_REND - free( st_ivas->hSplitBinRend->hMultiBinCldfbData ); -#endif -#endif - - return IVAS_ERR_OK; -} - - -/*---------------------------------------------------------------------* - * ivas_dec_setup_all() - * - * Set-up all decoder parts: IVAS decoder, ISAR - *---------------------------------------------------------------------*/ - -static ivas_error ivas_dec_setup_all( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - const Word16 isSplitRend, /* i : split rendering enabled flag */ -#endif - ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ -) -{ - ivas_error error; - - IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) - { - IF( EQ_16( (Word16) hIvasDec->st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) - { - *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; - } - ELSE - { - *nTransportChannels = 1; - } - move16(); - } - ELSE - { - Decoder_Struct *st_ivas; - - st_ivas = hIvasDec->st_ivas; - - /* Setup IVAS split rendering */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - IF( splitRendBits != NULL ) -#else - IF( isSplitRend ) -#endif - { - IF( ( error = isar_set_split_rend_setup( st_ivas->hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /*----------------------------------------------------------------* - * IVAS decoder setup - * - read IVAS format signaling - * - read IVAS format specific signaling - * - initialize decoder in the first frame based on IVAS format and number of transport channels - * - reconfigure the decoder when the number of TC or IVAS total bitrate change - *----------------------------------------------------------------*/ - - IF( EQ_16( st_ivas->bfi, 0 ) ) - { - error = IVAS_ERR_OK; // this is just to help the clang-formatting keep alignments - IF( ( error = ivas_dec_setup( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; - move16(); - - /*-----------------------------------------------------------------* - * ISAR: - * - initialize ISAR handle at the first frame - * - reconfigure the ISAR handle in case of bitrate switching (renderer might change) - *-----------------------------------------------------------------*/ - - test(); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - IF( EQ_16( st_ivas->ini_frame, 0 ) && splitRendBits != NULL ) -#else - IF( st_ivas->ini_frame == 0 && isSplitRend ) -#endif - { - IF( ( error = ivas_dec_init_split_rend( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - test(); - IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - IF( ( error = ivas_dec_reconfig_split_rend( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = ivas_dec_reconfig_split_rend( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } } @@ -2112,10 +1758,13 @@ ivas_error IVAS_DEC_GetFormat( move32(); test(); - if ( EQ_32( *format, IVAS_DEC_BS_MASA ) && EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( *format, IVAS_DEC_BS_MASA ) && hIvasDec->st_ivas->hMasa != NULL ) { - *format = IVAS_DEC_BS_MASA_ISM; - move32(); + IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) + { + *format = IVAS_DEC_BS_MASA_ISM; + move32(); + } } return IVAS_ERR_OK; @@ -2139,7 +1788,7 @@ static Word16 getOutputBufferSize( IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, ( RENDERER_MAX_OUTPUT_CHANNELS + IVAS_MAX_NUM_OBJECTS ) ), INV_FRAME_PER_SEC_Q15 ) ); + return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ) ), INV_FRAME_PER_SEC_Q15 ) ); } ELSE IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { @@ -2227,10 +1876,10 @@ ivas_error IVAS_DEC_GetNumOutputChannels( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetObjectMetadata( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_ISM_METADATA *metadata, /* o : struct where metadata decoded in most recently decoded frame will be written */ - const UWord16 zero_flag, /* i : if this flag is enabled, this function outputs a zero-initialized metadata struct */ - const UWord16 objectIdx /* i : index of the queried object */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_ISM_METADATA *metadata, /* o : struct where metadata decoded in most recently decoded frame will be written */ + const UWord16 zero_flag, /* i : if this flag is enabled, this function outputs a zero-initialized metadata struct */ + const UWord16 objectIdx /* i : index of the queried object */ ) { Decoder_Struct *st_ivas; @@ -2378,7 +2027,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; @@ -2663,7 +2312,7 @@ ivas_error IVAS_DEC_FeedCustomLsData( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfTDrendHandle( ) * - * + * Get TD binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfTDrendHandle( @@ -2687,7 +2336,7 @@ ivas_error IVAS_DEC_GetHrtfTDrendHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfCRendHandle( ) * - * + * Get Crend binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfCRendHandle( @@ -2711,7 +2360,7 @@ ivas_error IVAS_DEC_GetHrtfCRendHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfFastConvHandle( ) * - * + * Get FastConv binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfFastConvHandle( @@ -2735,7 +2384,7 @@ ivas_error IVAS_DEC_GetHrtfFastConvHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfParamBinHandle( ) * - * + * Get Parametric binaural renderer handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetHrtfParamBinHandle( @@ -2759,13 +2408,12 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfStatisticsHandle( ) * - * + * Get HRTF statistics (room effect) binaural renderer handle *---------------------------------------------------------------------*/ 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(); @@ -2809,7 +2457,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; } @@ -2891,7 +2539,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(); @@ -2904,8 +2552,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 ); @@ -2923,6 +2569,246 @@ ivas_error IVAS_DEC_HRTF_binary_close( } +/*---------------------------------------------------------------------* + * IVAS_DEC_AddAcousticEnvironment( ) + * + * Adds acoustic environment configuration + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_AddAcousticEnvironment( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i : Room acoustic configuration */ +) +{ + Word16 n; + Decoder_Struct *st_ivas; + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAE = NULL; + + test(); + test(); + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || ( hIvasDec->st_ivas->acousticEnvironmentsCount > 0 && hIvasDec->st_ivas->pAcousticEnvironments == NULL ) ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + + /* Check if already there */ + FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) + { + IF( st_ivas->pAcousticEnvironments[n].aeID == roomAcousticsConfig.aeID ) + { + move32(); + pAE = &st_ivas->pAcousticEnvironments[n]; + break; + } + } + + /* If not found */ + IF( pAE == NULL ) + { + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *ppAE = malloc( ( st_ivas->acousticEnvironmentsCount + 1 ) * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) ); + + IF( ppAE == NULL ) + { + return IVAS_ERR_FAILED_ALLOC; + } + + FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) + { + pAE = &ppAE[n]; + pAE->aeID = st_ivas->pAcousticEnvironments[n].aeID; + pAE->nBands = st_ivas->pAcousticEnvironments[n].nBands; + pAE->acousticPreDelay_fx = st_ivas->pAcousticEnvironments[n].acousticPreDelay_fx; + pAE->inputPreDelay_fx = st_ivas->pAcousticEnvironments[n].inputPreDelay_fx; + + Copy32( st_ivas->pAcousticEnvironments[n].pFc_input_fx, pAE->pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( st_ivas->pAcousticEnvironments[n].pAcoustic_rt60_fx, pAE->pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( st_ivas->pAcousticEnvironments[n].pAcoustic_dsr_fx, pAE->pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 + + pAE->use_er = st_ivas->pAcousticEnvironments[n].use_er; + + move16(); + move16(); + move32(); + move32(); + move16(); + + IF( EQ_16( pAE->use_er, 1 ) ) + { + pAE->lowComplexity = st_ivas->pAcousticEnvironments[n].lowComplexity; + move32(); + + pAE->dimensions.x_fx = st_ivas->pAcousticEnvironments[n].dimensions.x_fx; + pAE->dimensions.y_fx = st_ivas->pAcousticEnvironments[n].dimensions.y_fx; + pAE->dimensions.z_fx = st_ivas->pAcousticEnvironments[n].dimensions.z_fx; + move32(); + move32(); + move32(); + + pAE->ListenerOrigin.x_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.x_fx; + pAE->ListenerOrigin.y_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.y_fx; + pAE->ListenerOrigin.z_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.z_fx; + move32(); + move32(); + move32(); + + Copy32( st_ivas->pAcousticEnvironments[n].AbsCoeff_fx, pAE->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + } + } + + free( st_ivas->pAcousticEnvironments ); + st_ivas->pAcousticEnvironments = ppAE; + + n = st_ivas->acousticEnvironmentsCount++; + pAE = &st_ivas->pAcousticEnvironments[n]; + move32(); + move16(); + move32(); + } + + pAE->aeID = roomAcousticsConfig.aeID; + pAE->nBands = roomAcousticsConfig.nBands; + pAE->acousticPreDelay_fx = roomAcousticsConfig.acousticPreDelay_fx; + pAE->inputPreDelay_fx = roomAcousticsConfig.inputPreDelay_fx; + + Copy32( roomAcousticsConfig.pFc_input_fx, pAE->pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( roomAcousticsConfig.pAcoustic_rt60_fx, pAE->pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( roomAcousticsConfig.pAcoustic_dsr_fx, pAE->pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 + + pAE->use_er = roomAcousticsConfig.use_er; + + move16(); + move16(); + move32(); + move32(); + move16(); + + IF( EQ_16( pAE->use_er, 1 ) ) + { + pAE->lowComplexity = roomAcousticsConfig.lowComplexity; + move32(); + + pAE->dimensions.x_fx = roomAcousticsConfig.dimensions.x_fx; + pAE->dimensions.y_fx = roomAcousticsConfig.dimensions.y_fx; + pAE->dimensions.z_fx = roomAcousticsConfig.dimensions.z_fx; + move32(); + move32(); + move32(); + + pAE->ListenerOrigin.x_fx = roomAcousticsConfig.ListenerOrigin.x_fx; + pAE->ListenerOrigin.y_fx = roomAcousticsConfig.ListenerOrigin.y_fx; + pAE->ListenerOrigin.z_fx = roomAcousticsConfig.ListenerOrigin.z_fx; + move32(); + move32(); + move32(); + + Copy32( roomAcousticsConfig.AbsCoeff_fx, pAE->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * IVAS_DEC_GetAcousticEnvironment( ) + * + * Gets acoustic environment configuration with a given ID + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_GetAcousticEnvironment( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + UWord16 aeID, /* i : Acoustic environment ID */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o : Room acoustic environment data pointer */ +) +{ + Word16 n, m; + Word16 found = 0; + move16(); + Decoder_Struct *st_ivas; + + test(); + IF( hIvasDec == NULL || pAcEnv == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + move32(); + + /* In case of default AE ID, select the first one available */ + test(); + IF( aeID == (UWord16) IVAS_DEFAULT_AEID && st_ivas->acousticEnvironmentsCount > 0 ) + { + aeID = st_ivas->pAcousticEnvironments[0].aeID; + move32(); + } + + FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) + { + IVAS_ROOM_ACOUSTICS_CONFIG_DATA ae = st_ivas->pAcousticEnvironments[n]; + move32(); + IF( aeID == ae.aeID ) + { + found = 1; + pAcEnv->aeID = aeID; + pAcEnv->nBands = ae.nBands; + pAcEnv->inputPreDelay_fx = ae.inputPreDelay_fx; + move16(); + move16(); + move16(); + move32(); + + FOR( m = 0; m < pAcEnv->nBands; m++ ) + { + pAcEnv->pFc_input_fx[m] = ae.pFc_input_fx[m]; + pAcEnv->pAcoustic_rt60_fx[m] = ae.pAcoustic_rt60_fx[m]; + pAcEnv->pAcoustic_dsr_fx[m] = ae.pAcoustic_dsr_fx[m]; + move32(); + move32(); + move32(); + } + + /* If ER are allocated then propagate parameters */ + pAcEnv->use_er = ae.use_er; + move16(); + + IF( ae.use_er != 0 ) + { + pAcEnv->lowComplexity = ae.lowComplexity; + move32(); + + pAcEnv->dimensions.x_fx = ae.dimensions.x_fx; + pAcEnv->dimensions.y_fx = ae.dimensions.y_fx; + pAcEnv->dimensions.z_fx = ae.dimensions.z_fx; + move32(); + move32(); + move32(); + + pAcEnv->ListenerOrigin.x_fx = ae.ListenerOrigin.x_fx; + pAcEnv->ListenerOrigin.y_fx = ae.ListenerOrigin.y_fx; + pAcEnv->ListenerOrigin.z_fx = ae.ListenerOrigin.z_fx; + move32(); + move32(); + move32(); + + Copy32( ae.AbsCoeff_fx, pAcEnv->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + } + } + } + + IF( found == 0 ) + { + return IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING; + } + ELSE + { + return IVAS_ERR_OK; + } +} + + /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * @@ -2939,6 +2825,8 @@ static ivas_error copyRendererConfigStruct( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + hRCout->roomAcoustics.aeID = hRCin->roomAcoustics.aeID; + move16(); hRCout->roomAcoustics.nBands = hRCin->roomAcoustics.nBands; hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx; hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx; @@ -3017,9 +2905,132 @@ ivas_error IVAS_DEC_GetDefaultRenderConfig( * Set renderer configuration (acoustic environment) parameters *---------------------------------------------------------------------*/ -ivas_error IVAS_DEC_FeedRenderConfig( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +ivas_error IVAS_DEC_FeedRenderConfig( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +) +{ + RENDER_CONFIG_HANDLE hRenderConfig; + Decoder_Struct *st_ivas; + ivas_error error; + + test(); + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hRenderConfig = hIvasDec->st_ivas->hRenderConfig; + st_ivas = hIvasDec->st_ivas; + + hRenderConfig->roomAcoustics.aeID = renderConfig.roomAcoustics.aeID; + move16(); + hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands; + hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx; + hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx; + + hRenderConfig->roomAcoustics.use_er = 0; + move16(); + move16(); + move16(); + move32(); + move32(); + IF( EQ_16( renderConfig.roomAcoustics.use_er, 1 ) ) + { + hRenderConfig->roomAcoustics.use_er = renderConfig.roomAcoustics.use_er; + hRenderConfig->roomAcoustics.lowComplexity = renderConfig.roomAcoustics.lowComplexity; + hRenderConfig->roomAcoustics.dimensions = renderConfig.roomAcoustics.dimensions; + hRenderConfig->roomAcoustics.ListenerOrigin = renderConfig.roomAcoustics.ListenerOrigin; + + Copy32( renderConfig.roomAcoustics.AbsCoeff_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + move16(); + move32(); + } + + Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 + + /* Re-initialize reverb instance if already available */ + + /* TD renderer Jot reverberator */ + IF( st_ivas->hReverb != NULL ) + { + IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* CREND Jot reverberator */ + test(); + test(); + IF( st_ivas->hCrendWrapper != NULL && st_ivas->hCrendWrapper->hCrend[0] != NULL && st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL ) + { + IF( ( error = ivas_reverb_open_fx( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* Parametric renderer reverberator */ + test(); + IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->hReverb != NULL ) + { + ivas_binaural_reverb_close_fx( &( st_ivas->hDiracDecBin[0]->hReverb ) ); + + IF( ( error = ivas_binaural_reverb_init_fx( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* FastConv renderer reverberator */ + test(); + IF( st_ivas->hBinRenderer != NULL && st_ivas->hBinRenderer->hReverb != NULL ) + { + ivas_binaural_reverb_close_fx( &( st_ivas->hBinRenderer->hReverb ) ); + + IF( ( error = ivas_binaural_reverb_init_fx( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hBinRenderer->conv_band, hIvasDec->st_ivas->hBinRenderer->timeSlots, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); + Copy32( renderConfig.distAtt_fx, hRenderConfig->distAtt_fx, 3 ); + + hRenderConfig->split_rend_config = renderConfig.split_rend_config; + + /* Overwrite any pose correction settings if 0 DOF (no pose correction) was selected */ + IF( hRenderConfig->split_rend_config.dof == 0 ) + { + hRenderConfig->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; + move16(); + } + + IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, hRenderConfig ) ) + { + IF( ( error = isar_split_rend_validate_config( &hRenderConfig->split_rend_config, ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * feedAcousticEnvPI( ) + * + * Set acoustic environment from the PI data + *---------------------------------------------------------------------*/ + +static ivas_error feedAcousticEnvPI( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_PIDATA_ACOUSTIC_ENV hAcoustEnvPI /* i : Render configuration struct */ ) { RENDER_CONFIG_HANDLE hRenderConfig; @@ -3035,32 +3046,74 @@ ivas_error IVAS_DEC_FeedRenderConfig( hRenderConfig = hIvasDec->st_ivas->hRenderConfig; st_ivas = hIvasDec->st_ivas; - - hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands; - hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx; - hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx; - - hRenderConfig->roomAcoustics.use_er = 0; - move16(); - move16(); - move16(); move32(); move32(); - IF( EQ_16( renderConfig.roomAcoustics.use_er, 1 ) ) + + /* Ignore if AE ID already in use */ + IF( EQ_16( hRenderConfig->roomAcoustics.aeID, hAcoustEnvPI.aeid ) ) { - hRenderConfig->roomAcoustics.use_er = renderConfig.roomAcoustics.use_er; - hRenderConfig->roomAcoustics.lowComplexity = renderConfig.roomAcoustics.lowComplexity; - hRenderConfig->roomAcoustics.dimensions = renderConfig.roomAcoustics.dimensions; - hRenderConfig->roomAcoustics.ListenerOrigin = renderConfig.roomAcoustics.ListenerOrigin; + return IVAS_ERR_OK; + } - Copy32( renderConfig.roomAcoustics.AbsCoeff_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + /* Attempt to load the one already available */ + IF( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, hAcoustEnvPI.aeid, &hRenderConfig->roomAcoustics ) ) == IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING ) + { + /* Add the new compact room environment */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA acEnv; + + acEnv.aeID = hAcoustEnvPI.aeid; + acEnv.nBands = IVAS_PI_AE_NUM_BANDS; + move16(); move16(); + + acEnv.pFc_input_fx[IVAS_PI_AE_LOW] = IVAS_PI_AE_LOW_FREQ * 0x10000; /* Q16 */ + acEnv.pFc_input_fx[IVAS_PI_AE_MID] = IVAS_PI_AE_MID_FREQ * 0x10000; + acEnv.pFc_input_fx[IVAS_PI_AE_HIGH] = IVAS_PI_AE_HIGH_FREQ * 0x10000; + move32(); + move32(); move32(); - } - Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 - Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 - Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 + acEnv.pAcoustic_rt60_fx[IVAS_PI_AE_LOW] = hAcoustEnvPI.rt60_fx[IVAS_PI_AE_LOW]; + acEnv.pAcoustic_rt60_fx[IVAS_PI_AE_MID] = hAcoustEnvPI.rt60_fx[IVAS_PI_AE_MID]; + acEnv.pAcoustic_rt60_fx[IVAS_PI_AE_HIGH] = hAcoustEnvPI.rt60_fx[IVAS_PI_AE_HIGH]; + acEnv.inputPreDelay_fx = ( ( hAcoustEnvPI.rt60_fx[IVAS_PI_AE_MID] * 0x00CCCCC ) >> 26 ); /* Q26 RT60[MID] / 10 -> Q27 */ + move32(); + move32(); + move32(); + move32(); + + acEnv.pAcoustic_dsr_fx[IVAS_PI_AE_LOW] = hAcoustEnvPI.dsr_fx[IVAS_PI_AE_LOW]; + acEnv.pAcoustic_dsr_fx[IVAS_PI_AE_MID] = hAcoustEnvPI.dsr_fx[IVAS_PI_AE_MID]; + acEnv.pAcoustic_dsr_fx[IVAS_PI_AE_HIGH] = hAcoustEnvPI.dsr_fx[IVAS_PI_AE_HIGH]; + move32(); + move32(); + move32(); + + acEnv.use_er = hAcoustEnvPI.availEarlyReflections; + move16(); + + IF( hAcoustEnvPI.availEarlyReflections ) + { + hRenderConfig->roomAcoustics.dimensions.x_fx = hAcoustEnvPI.roomDimensions.x_fx; + hRenderConfig->roomAcoustics.dimensions.y_fx = hAcoustEnvPI.roomDimensions.y_fx; + hRenderConfig->roomAcoustics.dimensions.z_fx = hAcoustEnvPI.roomDimensions.z_fx; + move32(); + move32(); + move32(); + + Copy32( hAcoustEnvPI.absorbCoeffs_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + } + + IF( ( error = IVAS_DEC_AddAcousticEnvironment( hIvasDec, acEnv ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, hAcoustEnvPI.aeid, &hRenderConfig->roomAcoustics ) ) != IVAS_ERR_OK ) + { + return error; + } + } /* Re-initialize reverb instance if already available */ @@ -3078,50 +3131,33 @@ ivas_error IVAS_DEC_FeedRenderConfig( test(); IF( st_ivas->hCrendWrapper != NULL && st_ivas->hCrendWrapper->hCrend[0] != NULL && st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL ) { - IF( ( error = ivas_reverb_open_fx( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_reverb_open_fx( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } } - /* FB reverberator */ + /* Parametric renderer reverberator */ test(); IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->hReverb != NULL ) { ivas_binaural_reverb_close_fx( &( st_ivas->hDiracDecBin[0]->hReverb ) ); - IF( ( error = ivas_binaural_reverb_init_fx( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_binaural_reverb_init_fx( &( st_ivas->hDiracDecBin[0]->hReverb ), st_ivas->hHrtfStatistics, st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; } } + /* FastConv renderer reverberator */ test(); - /* Fastconv CLDFB reverberator */ IF( st_ivas->hBinRenderer != NULL && st_ivas->hBinRenderer->hReverb != NULL ) { ivas_binaural_reverb_close_fx( &( st_ivas->hBinRenderer->hReverb ) ); - IF( ( error = ivas_binaural_reverb_init_fx( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hBinRenderer->conv_band, hIvasDec->st_ivas->hBinRenderer->timeSlots, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); - Copy32( renderConfig.distAtt_fx, hRenderConfig->distAtt_fx, 3 ); - - hRenderConfig->split_rend_config = renderConfig.split_rend_config; - - /* Overwrite any pose correction settings if 0 DOF (no pose correction) was selected */ - IF( hRenderConfig->split_rend_config.dof == 0 ) - { - hRenderConfig->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; - } - - IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, hRenderConfig ) ) - { - IF( ( error = isar_split_rend_validate_config( &hRenderConfig->split_rend_config, ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_binaural_reverb_init_fx( &( st_ivas->hBinRenderer->hReverb ), st_ivas->hHrtfStatistics, st_ivas->hBinRenderer->conv_band, st_ivas->hBinRenderer->timeSlots, + &( hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; } @@ -3134,7 +3170,7 @@ ivas_error IVAS_DEC_FeedRenderConfig( /*---------------------------------------------------------------------* * IVAS_DEC_GetDelay( ) * - * + * Return IVAS decoder delay in nanoseconds *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetDelay( @@ -3432,7 +3468,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF( !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == 0 ) { return IVAS_ERR_TSM_NOT_ENABLED; } @@ -3592,7 +3628,6 @@ ivas_error IVAS_DEC_ReadFormat( { ivas_error error; Decoder_Struct *st_ivas; - IVAS_FORMAT ivas_format_old; ISM_MODE ism_mode_old; MC_MODE mc_mode_old; Word16 nchan_transport_old; @@ -3606,7 +3641,6 @@ ivas_error IVAS_DEC_ReadFormat( } st_ivas = hIvasDec->st_ivas; - ivas_format_old = st_ivas->ivas_format; ism_mode_old = st_ivas->ism_mode; mc_mode_old = st_ivas->mc_mode; nchan_transport_old = st_ivas->nchan_transport; @@ -3616,7 +3650,6 @@ ivas_error IVAS_DEC_ReadFormat( renderer_type_sec_old = ivas_renderer_secondary_select_fx( st_ivas ); move32(); move32(); - move32(); move16(); move32(); move32(); @@ -3638,12 +3671,9 @@ ivas_error IVAS_DEC_ReadFormat( return error; } - test(); - test(); - test(); - IF( NE_32( ivas_format_old, st_ivas->ivas_format ) && GT_16( st_ivas->ini_frame, 0 ) && ( NE_32( st_ivas->ivas_format, MASA_FORMAT ) && NE_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) ) + IF( EQ_16( st_ivas->restartNeeded, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "IVAS format switching is not allowed." ) ); + return IVAS_ERR_OK; } /* Select binaural renderer */ @@ -3722,7 +3752,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(); @@ -3759,7 +3789,6 @@ ivas_error IVAS_DEC_ReadFormat( return IVAS_ERR_OK; } -#ifdef JBM_MEMORY_OPT /*---------------------------------------------------------------------* * apa_exec_evs_wrapper( ) @@ -3774,7 +3803,7 @@ static ivas_error apa_exec_evs_wrapper( { Word16 ch; UWord16 apa_buff_len; - Word16 tmp_apaExecBuffer[CPE_CHANNELS * APA_BUF / APA_MAX_NUM_CHANNELS]; /* in EVS, 2 output channels */ + Word16 tmp_apaExecBuffer[APA_BUF_PER_CHANNEL]; DECODER_TC_BUFFER_HANDLE hTcBuffer; test(); @@ -3805,19 +3834,16 @@ static ivas_error apa_exec_evs_wrapper( return IVAS_ERR_OK; } -#endif + /*---------------------------------------------------------------------* * IVAS_DEC_GetSamplesDecoder( ) * - * Main function to decode transport channels, do TSM and feed to renderer. + * Main function to run setup, decode transport channels, do TSM and feed to renderer. *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetSamplesDecoder( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ -#ifndef FIX_1119_SPLIT_RENDERING_VOIP - const Word16 isSplitRend, /* i : split rendering enabled flag */ -#endif + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ ) { @@ -3841,12 +3867,8 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } st_ivas = hIvasDec->st_ivas; -#ifdef JBM_MEMORY_OPT test(); isInitialized_voip = hIvasDec->hTimeScaler != NULL; -#else - isInitialized_voip = hIvasDec->apaExecBuffer_fx != NULL; -#endif test(); IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */ @@ -3855,11 +3877,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( * Setup all decoder parts (IVAS decoder, ISAR) *-----------------------------------------------------------------*/ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP IF( NE_32( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, splitRendBits ) ), IVAS_ERR_OK ) ) -#else - IF( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -3877,7 +3895,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; } @@ -3911,50 +3929,16 @@ ivas_error IVAS_DEC_GetSamplesDecoder( return IVAS_ERR_UNKNOWN; } -#ifdef JBM_MEMORY_OPT /* convert deinterleaved decoded TC audio channels buffer to an interleaved one */ - ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, nTransportChannels, hIvasDec->nSamplesFrame, st_ivas->hTcBuffer->tc_buffer_fx ); -#else - ivas_syn_output_f_fx( st_ivas->p_output_fx, hIvasDec->nSamplesFrame, nTransportChannels, hIvasDec->apaExecBuffer_fx ); -#endif + ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, st_ivas->hTcBuffer->tc_buffer_fx, nTransportChannels, hIvasDec->nSamplesFrame ); IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { -#ifdef JBM_MEMORY_OPT apa_exec_evs_wrapper( hIvasDec, nTransportChannels, &nTimeScalerOutSamples ); -#else - Word16 tmp_apaExecBuffer[APA_BUF]; - FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) - { -#ifdef JBM_MEMORY_OPT - tmp_apaExecBuffer[i] = extract_l( L_shr( st_ivas->hTcBuffer->tc_buffer_fx[i], Q11 ) ); // Q0 -#else - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 -#endif - } - - IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) - { - return IVAS_ERR_UNKNOWN; - } - - FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) - { -#ifdef JBM_MEMORY_OPT - st_ivas->hTcBuffer->tc_buffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 -#else - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 -#endif - } -#endif } ELSE { -#ifdef JBM_MEMORY_OPT IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, st_ivas->hTcBuffer->tc_buffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, st_ivas->hTcBuffer->tc_buffer_fx, &nTimeScalerOutSamples ) != 0 ) -#else - IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer_fx, &nTimeScalerOutSamples ) != 0 ) -#endif { return IVAS_ERR_UNKNOWN; } @@ -3964,11 +3948,9 @@ ivas_error IVAS_DEC_GetSamplesDecoder( nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels ); hIvasDec->timeScalingDone = 1; move16(); -#ifdef JBM_MEMORY_OPT /* convert interleaved time-scaled TC audio channels buffer to deinterleaved one */ - 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 + ivas_buffer_interleaved_to_deinterleaved_fx( st_ivas->hTcBuffer->tc_buffer_fx, st_ivas->p_output_fx, nTransportChannels, nSamplesTcsScaled ); } else { @@ -3979,20 +3961,12 @@ ivas_error IVAS_DEC_GetSamplesDecoder( * Feed decoded transport channels samples to the renderer *-----------------------------------------------------------------*/ -#ifdef JBM_MEMORY_OPT - ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples ); -#else - ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ); -#endif + ivas_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples ); IF( st_ivas->hDecoderConfig->Opt_tsm ) { /* feed residual samples to TSM for the next call */ -#ifdef FIX_2174_JBM_BASOP_ALIGNMENT IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 ) -#else - IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 ) -#endif { return IVAS_ERR_UNKNOWN; } @@ -4033,10 +4007,8 @@ ivas_error IVAS_DEC_GetSamplesDecoder( move32(); hIsmMetaData[obj]->edited_radius_fx = hIsmMetaData[obj]->radius_fx; move32(); -#ifdef FIX_2148_OBJ_EDIT_ISSUE_WITH_OSBA hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29; move32(); -#endif } if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) @@ -4071,12 +4043,13 @@ ivas_error IVAS_DEC_GetSamplesDecoder( /*---------------------------------------------------------------------* * IVAS_DEC_GetEditableParameters( ) * - * + * Get editable metadata parameters *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetEditableParameters( - IVAS_DEC_HANDLE hIvasDec, - IVAS_EDITABLE_PARAMETERS *hIvasEditableParameters ) + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_EDITABLE_PARAMETERS *hIvasEditableParameters /* o : object editing parameters handle */ +) { Word16 obj, dirac_read_idx; Decoder_Struct *st_ivas; @@ -4160,7 +4133,7 @@ ivas_error IVAS_DEC_GetEditableParameters( move32(); hIvasEditableParameters->ism_metadata[obj].radius_fx = 0; move16(); - hIvasEditableParameters->ism_metadata[obj].gain_fx = ONE_IN_Q29; // TODO check Q-value + hIvasEditableParameters->ism_metadata[obj].gain_fx = ONE_IN_Q29; move32(); hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = 0; move16(); @@ -4262,12 +4235,13 @@ ivas_error IVAS_DEC_GetEditableParameters( /*---------------------------------------------------------------------* * IVAS_DEC_SetEditableParameters( ) * - * Main function to decode to PCM data + * Set editable metadata parameters *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_SetEditableParameters( - IVAS_DEC_HANDLE hIvasDec, - IVAS_EDITABLE_PARAMETERS hIvasEditableParameters ) + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_EDITABLE_PARAMETERS hIvasEditableParameters /* i : object editing parameters handle */ +) { Word16 dirac_read_idx, obj; Decoder_Struct *st_ivas; @@ -4322,16 +4296,32 @@ ivas_error IVAS_DEC_SetEditableParameters( move32(); st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; move32(); - st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; - move32(); + IF( GT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MAX_Q29 ) ) + { + st_ivas->hIsmMetaData[obj]->edited_gain_fx = EDIT_GAIN_MAX_Q29; + move32(); + } + ELSE + { + st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; + move32(); + } st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag; move16(); } IF( EQ_32( ism_mode, ISM_SBA_MODE_DISC ) ) { - st_ivas->hSbaIsmData->gain_bed_fx = hIvasEditableParameters.gain_bed_fx; - move32(); + IF( GT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MAX_Q29 ) ) + { + st_ivas->hSbaIsmData->gain_bed_fx = EDIT_GAIN_MAX_Q29; + move32(); + } + ELSE + { + st_ivas->hSbaIsmData->gain_bed_fx = hIvasEditableParameters.gain_bed_fx; + move32(); + } } } ELSE IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) @@ -4345,14 +4335,29 @@ ivas_error IVAS_DEC_SetEditableParameters( move32(); st_ivas->hParamIsmDec->edited_elevation_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].elevation_fx; move32(); + IF( st_ivas->hMasaIsmData != NULL ) { - st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 -> Q12 - move32(); + /* Limit gain edit to a range of +12dB to -24dB with parametric ISM mode */ + IF( GT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MAX_Q29 ) ) + { + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MAX_Q12; // Q12 + move16(); + } + ELSE IF( LT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MIN_Q29 ) ) + { + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MIN_Q12; // Q12 + move16(); + } + ELSE + { + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 -> Q12 + move16(); + } - /* Detect direction editing in Param-ISM mode */ - IF( GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ), OMASA_AZI_EDIT_THR_FX ) || - GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->elevation_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ), OMASA_ELE_EDIT_THR_FX ) ) + /* Detect direction editing in Param-ISM mode */ + IF( GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ), OMASA_AZI_EDIT_THR_Q22 ) || // | azi_orig[obj] - azi_edit[obj] | > azi_threshold + GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->elevation_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ), OMASA_ELE_EDIT_THR_Q22 ) ) // | ele_orig[obj] - ele_edit[obj] | > ele_threshold { st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; } @@ -4363,7 +4368,7 @@ ivas_error IVAS_DEC_SetEditableParameters( move16(); /* Detect gain editing in Param-ISM mode */ - IF( GT_16( abs_s( sub( ONE_IN_Q12, shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check Q values + IF( GT_16( abs_s( sub( ONE_IN_Q12, shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_Q12 ) ) // | 1.0f - gain_edit[obj] | > gain_threshold { st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1; } @@ -4447,8 +4452,8 @@ ivas_error IVAS_DEC_SetEditableParameters( threshold_ele = delta_theta_masa_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 3]; test(); - IF( ( GT_32( L_shl( abs_s( sub( new_azi, st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_azi ) ) || - ( GT_32( L_shl( abs_s( sub( new_ele, st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_ele ) ) ) + IF( ( GT_32( L_shl( abs_s( sub( new_azi, st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_azi ) ) || // | azi_edit[obj] - azi_orig[obj] | > azi_threshold + ( GT_32( L_shl( abs_s( sub( new_ele, st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_ele ) ) ) // | ele_edit[obj] - ele_orig[obj] | > ele_threshold { /* at least one of the threshold is exceeded, so use new direction value and set editing detection flag */ st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi; @@ -4468,8 +4473,8 @@ ivas_error IVAS_DEC_SetEditableParameters( { /* detect editing in ISM_MASA_MODE_DISC mode */ test(); - IF( L_abs( L_sub( st_ivas->hIsmMetaData[obj]->azimuth_fx, hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ) > OMASA_AZI_EDIT_THR_FX || - L_abs( L_sub( st_ivas->hIsmMetaData[obj]->elevation_fx, hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ) > OMASA_ELE_EDIT_THR_FX ) + IF( L_abs( L_sub( st_ivas->hIsmMetaData[obj]->azimuth_fx, hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ) > OMASA_AZI_EDIT_THR_Q22 || // | azi_orig[obj] - azi_edit[obj] | > azi_threshold + L_abs( L_sub( st_ivas->hIsmMetaData[obj]->elevation_fx, hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ) > OMASA_ELE_EDIT_THR_Q22 ) // | ele_orig[obj] - ele_edit[obj] | > ele_threshold { st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi; move32(); @@ -4486,11 +4491,27 @@ ivas_error IVAS_DEC_SetEditableParameters( } /* compare pre-edit gain and the edited one to detect editing */ - IF( GT_16( abs_s( sub( shr( extract_h( st_ivas->hIsmMetaData[obj]->edited_gain_fx ), Q1 ), shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check incoming Q value + IF( GT_16( abs_s( sub( shr( extract_h( st_ivas->hIsmMetaData[obj]->edited_gain_fx ), Q1 ), shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_Q12 ) ) // | gain_edit[obj] - gain_orig[obj] | > gain_threshold { st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1; - st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 --> Q12 - move16(); + + /* Limit gain edit to a range of +12dB to -24dB with parametric OMASA mode */ + test(); + IF( GT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MAX_Q29 ) ) + { + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MAX_Q12; + move16(); + } + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && LT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MIN_Q29 ) ) + { + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MIN_Q12; + move16(); + } + ELSE + { + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 --> Q12 + move16(); + } } ELSE { @@ -4506,35 +4527,56 @@ ivas_error IVAS_DEC_SetEditableParameters( move32(); st_ivas->hIsmMetaData[obj]->edited_elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx; move32(); - st_ivas->hIsmMetaData[obj]->edited_yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx; - move32(); - st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; - move32(); - st_ivas->hIsmMetaData[obj]->edited_radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx; - move32(); -#ifndef NONBE_FIX_1172_OBJ_EDIT_JBM - st_ivas->hIsmMetaData[obj]->azimuth_fx = hIvasEditableParameters.ism_metadata[obj].azimuth_fx; - move32(); - st_ivas->hIsmMetaData[obj]->elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx; - move32(); - st_ivas->hIsmMetaData[obj]->yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx; - move32(); - st_ivas->hIsmMetaData[obj]->pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; - move32(); - st_ivas->hIsmMetaData[obj]->radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx; - move32(); -#endif - st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; // TODO: check incoming Q value - move32(); + + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) + { + st_ivas->hIsmMetaData[obj]->edited_yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx; + move16(); + st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; + move16(); + st_ivas->hIsmMetaData[obj]->edited_radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx; + move16(); + } + + test(); + IF( GT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MAX_Q29 ) ) + { + st_ivas->hIsmMetaData[obj]->edited_gain_fx = EDIT_GAIN_MAX_Q29; + } + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && LT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MIN_Q29 ) ) + { + st_ivas->hIsmMetaData[obj]->edited_gain_fx = EDIT_GAIN_MIN_Q29; + } + ELSE + { + st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; + } + st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag; move16(); } } - IF( GT_16( abs_s( sub( shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ), ONE_IN_Q12 ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check Q value + IF( GT_16( abs_s( sub( shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ), ONE_IN_Q12 ) ), OMASA_GAIN_EDIT_THR_Q12 ) ) // | gain_bed - 1.0f | > gain_threshold { - st_ivas->hMasaIsmData->gain_masa_edited_fx = shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ); // TODO: check type - move32(); + /* Limit gain edit to a range of +12dB to -24dB with parametric OMASA mode */ + test(); + IF( GT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MAX_Q29 ) ) + { + st_ivas->hMasaIsmData->gain_masa_edited_fx = EDIT_GAIN_MAX_Q12; + move16(); + } + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && LT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MIN_Q29 ) ) + { + st_ivas->hMasaIsmData->gain_masa_edited_fx = EDIT_GAIN_MIN_Q12; + move16(); + } + ELSE + { + st_ivas->hMasaIsmData->gain_masa_edited_fx = shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ); + move16(); + } + st_ivas->hMasaIsmData->masa_gain_is_edited = 1; } ELSE @@ -4577,8 +4619,6 @@ ivas_error IVAS_DEC_PrepareRenderer( } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - /*---------------------------------------------------------------------* * ivas_dec_voip_get_samples_common( ) * @@ -4588,23 +4628,13 @@ ivas_error IVAS_DEC_PrepareRenderer( static ivas_error ivas_dec_voip_get_samples_common -#else -/*---------------------------------------------------------------------* - * IVAS_DEC_VoIP_GetSamples( ) - * - * Main function to decode one frame in VoIP - *---------------------------------------------------------------------*/ -ivas_error IVAS_DEC_VoIP_GetSamples -#endif ( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i : type for the decoded PCM resolution */ - Word16 *pcmBuf, /* o : output synthesis signal */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i : type for the decoded PCM resolution */ + Word16 *pcmBuf, /* o : output synthesis signal */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */ Word32 **p_head_pose_buf, /* i : PCM buffer with head-pose data */ -#endif #ifdef SUPPORT_JBM_TRACEFILE JbmTraceFileWriterFn jbmWriterFn, void *jbmWriter, @@ -4646,7 +4676,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples return IVAS_ERR_WRONG_PARAMS; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP test(); test(); IF( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || @@ -4655,7 +4684,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#endif /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ WHILE( LT_16( *nSamplesRendered, nSamplesPerChannel ) ) @@ -4669,7 +4697,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples IF( hIvasDec->hasBeenFedFirstGoodFrame ) { /* check if the TC buffer already exists, otherweise nothing is buffered anyway */ - IF( st_ivas->hTcBuffer != NULL ) { nSamplesBuffered = sub( st_ivas->hTcBuffer->n_samples_buffered, st_ivas->hTcBuffer->n_samples_rendered ); @@ -4707,7 +4734,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples dbgwrite( &scale, sizeof( uint32_t ), 1, 1, "./res/JBM_scale.dat" ); dbgwrite( &maxScaling, sizeof( uint32_t ), 1, 1, "./res/JBM_maxScale.dat" ); #endif - /* avoid time scaling multiple times in one sound card slot */ + /* avoid time scaling multiple times within one 20ms frame*/ IF( NE_64( scale, 100U ) ) { IF( hIvasDec->timeScalingDone ) @@ -4826,11 +4853,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples test(); IF( hIvasDec->nSamplesAvailableNext == 0 || EQ_16( hIvasDec->nSamplesAvailableNext, hIvasDec->nSamplesFrame ) ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP IF( NE_32( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, splitRendBits ) ), IVAS_ERR_OK ) ) -#else - IF( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -4839,6 +4862,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples move16(); *parametersAvailableForEditing = true; move16(); + return IVAS_ERR_OK; } } @@ -4854,7 +4878,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples } } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP IF( splitRendBits != NULL ) { /* Render head poses from time-scaled transport channels */ @@ -4863,63 +4886,48 @@ ivas_error IVAS_DEC_VoIP_GetSamples return error; } } - ELSE - { -#endif + ELSE{ /* render IVAS frames directly to the output buffer */ - IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) - { + IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ){ return error; - } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - } -#endif - - *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); - update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); } } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - IF( hIvasDec->hasDecodedFirstGoodFrame && splitRendBits != NULL ) + *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); + update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); +} +} + +IF( hIvasDec->hasDecodedFirstGoodFrame &&splitRendBits != NULL ) +{ + Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; + Word16 i; + + /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */ + IF( NE_32( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, Q_out ) ), IVAS_ERR_OK ) ) { - Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; - Word16 i; + return error; + } - /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */ - IF( NE_32( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, Q_out ) ), IVAS_ERR_OK ) ) + /* Synthesise PCM output if split PCM */ + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { - return error; + scale_sig32( p_head_pose_buf[i], *nSamplesRendered, sub( Q11, Q_out[i] ) ); // Q11 } - /* Synthesise PCM output if split PCM */ - IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - 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, (int16_t *) pcmBuf ); - } + ivas_syn_output_fx( p_head_pose_buf, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); } -#endif +} - return IVAS_ERR_OK; +return IVAS_ERR_OK; } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSamples( ) @@ -4987,6 +4995,7 @@ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( Word32 *pp_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES]; ivas_error error = IVAS_ERR_UNKNOWN; Word16 nSamplesPerChannel = 0; + move16(); IF( NE_32( ( error = IVAS_DEC_GetRenderFramesizeSamples( hIvasDec, &nSamplesPerChannel ) ), IVAS_ERR_OK ) ) { @@ -5015,7 +5024,6 @@ ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream( parametersAvailableForEditing, systemTimestamp_ms ); } -#endif /*---------------------------------------------------------------------* @@ -5067,7 +5075,6 @@ ivas_error IVAS_DEC_Flush( ivas_error error; UWord16 nSamplesToRender; UWord16 nSamplesFlushedLocal; - nSamplesFlushedLocal = 0; // temp. hack test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) @@ -5091,34 +5098,65 @@ ivas_error IVAS_DEC_Flush( move16(); test(); - IF( GT_16( nSamplesToRender, 0 ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, (Word16) MONO_FORMAT ) ) + IF( GT_16( nSamplesToRender, 0 ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, (Word16) MONO_FORMAT ) ) + { + error = ivas_dec_render_fx( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); + } + ELSE + { + *nSamplesFlushed = 0; + move16(); + } + +#ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR + hIvasDec->st_ivas->flushing = 0; + move16(); +#endif + + return error; +} + + +/*---------------------------------------------------------------------* + * IVAS_DEC_isRestartNeeded( ) + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + bool *restartNeeded /* o : flag to signal decoder restart */ +) +{ + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { - error = ivas_jbm_dec_render_fx( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); + return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - ELSE + + *restartNeeded = false; + move16(); + if ( EQ_16( hIvasDec->st_ivas->restartNeeded, 1 ) ) { - *nSamplesFlushed = 0; + *restartNeeded = true; move16(); } -#ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR - hIvasDec->st_ivas->flushing = 0; - move16(); -#endif - - return error; + return IVAS_ERR_OK; } /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_IsEmpty( ) * - * + * Returns 'true' if decoder has no data in VoIP jitter buffer *---------------------------------------------------------------------*/ -bool IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 nSamplesAsked ) +ivas_error IVAS_DEC_VoIP_IsEmpty( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const Word16 nSamplesAsked, /* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ +) { test(); IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL ) @@ -5126,8 +5164,16 @@ bool IVAS_DEC_VoIP_IsEmpty( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + *isEmpty = false; + move16(); test(); - return ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) ); + if ( ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 ) && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) ) + { + *isEmpty = true; + move16(); + } + + return IVAS_ERR_OK; } @@ -5183,8 +5229,8 @@ static void ivas_destroy_handle_VoIP_fx( return; } - #ifdef SUPPORT_JBM_TRACEFILE + /*---------------------------------------------------------------------* * store_JbmData() * @@ -5261,7 +5307,6 @@ ivas_error IVAS_DEC_GetJbmData( #endif - /*---------------------------------------------------------------------* * IVAS_DEC_GetErrorMessage( ) * @@ -5289,7 +5334,7 @@ static ivas_error printConfigInfo_dec( const bool quietModeEnabled ) { ivas_error error; - Word8 config_str[50]; + Word8 config_str[200]; AUDIO_CONFIG output_config; /*-----------------------------------------------------------------* @@ -5337,12 +5382,21 @@ static ivas_error printConfigInfo_dec( IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) { fprintf( stdout, "Output configuration: mono EVS bit-exact decoding to stereo\n" ); - float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 ); + float non_diegetic_pan_gain = (float) ( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx ) / (float) ( 1LL << Q15 ); fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f ); } ELSE { - fprintf( stdout, "Output configuration: mono EVS bit-exact decoding\n" ); + output_config = st_ivas->hDecoderConfig->output_config; + IF( NE_16( (Word16) output_config, IVAS_AUDIO_CONFIG_MONO ) ) + { + get_channel_config( output_config, &config_str[0] ); + fprintf( stdout, "Output configuration: mono EVS bit-exact decoding rendering to %s\n", config_str ); + } + ELSE + { + fprintf( stdout, "Output configuration: mono EVS bit-exact decoding\n" ); + } } } ELSE @@ -5400,7 +5454,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 ) { @@ -5445,7 +5499,7 @@ static ivas_error printConfigInfo_dec( IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) { - float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 ); + float non_diegetic_pan_gain = (float) ( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx ) / (float) ( 1LL << Q15 ); fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f ); } @@ -5525,9 +5579,8 @@ static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas ) { DEC_CORE_HANDLE *hCoreCoder; - Word16 mixer_left_fx, mixer_right_fx; - Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; - Word16 ch, i, nOutSamples; + Word32 *p_output_fx[1]; + Word16 i, nOutSamples; Word16 output_16[L_FRAME48k]; ivas_error error; @@ -5541,10 +5594,7 @@ static ivas_error evs_dec_main_fx( mdct_switching_dec_fx( hCoreCoder[0] ); - FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) - { - p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0 - } + p_output_fx[0] = st_ivas->p_output_fx[0]; /* run the main EVS decoding routine */ IF( EQ_16( hCoreCoder[0]->codec_mode, MODE1 ) ) @@ -5596,34 +5646,11 @@ static ivas_error evs_dec_main_fx( st_ivas->BER_detect = hCoreCoder[0]->BER_detect; move16(); - 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 */ - } - IF( st_ivas->hDecoderConfig->Opt_tsm ) + /*if ( st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )*/ { - /* BE workaround: in order to keep EVS bit-exact wrt. TS 26.443, convert 'float' output data to 'short' before the TSM */ // TODO: verify if it is still needed and if it works well for EVS stereo panning output -#ifdef JBM_MEMORY_OPT - Word32 pcm_buf_local[CPE_CHANNELS * L_FRAME48k]; -#else - Word32 pcm_buf_local[L_FRAME48k]; -#endif - - FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) - { -#ifdef JBM_MEMORY_OPT - ivas_buffer_deinterleaved_to_interleaved_fx( &p_output_fx[ch], st_ivas->hDecoderConfig->nchan_out, nOutSamples, pcm_buf_local ); -#else - ivas_syn_output_f_fx( &p_output_fx[ch], nOutSamples, 1, pcm_buf_local ); -#endif - - Copy32( pcm_buf_local, p_output_fx[ch], nOutSamples ); - } + /* BE workaround: in order to keep EVS bit-exact wrt. TS 26.443, convert 'float' output data to 'short' before the TSM */ + /* not applicable in BASOP */ } return IVAS_ERR_OK; @@ -5675,6 +5702,7 @@ static ivas_error input_format_API_to_internal( move16(); move16(); + return IVAS_ERR_OK; } @@ -5690,9 +5718,6 @@ static ivas_error apa_setup( const bool isInitialized_voip, const UWord16 nTransportChannels ) { -#ifndef JBM_MEMORY_OPT - Word16 apa_buffer_size; -#endif UWord16 l_ts; l_ts = (UWord16) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity; @@ -5706,12 +5731,6 @@ static ivas_error apa_setup( Word32 startQuality; startQuality = L_shl( L_deposit_l( hIvasDec->tsm_quality ), Q2 ); /* Q14 --> Q16*/ -#ifndef JBM_MEMORY_OPT - apa_buffer_size = APA_BUF_PER_CHANNEL; - - move16(); - /* get current renderer type*/ -#endif hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) ) @@ -5741,6 +5760,7 @@ static ivas_error apa_setup( move16(); move16(); + test(); test(); test(); @@ -5761,14 +5781,6 @@ static ivas_error apa_setup( return IVAS_ERR_INIT_ERROR; } } -#ifndef JBM_MEMORY_OPT - IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); - } - - set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); -#endif } ELSE { @@ -5776,16 +5788,6 @@ static ivas_error apa_setup( { return IVAS_ERR_INIT_ERROR; } -#ifndef JBM_MEMORY_OPT - apa_buffer_size = APA_BUF_PER_CHANNEL; - move16(); - free( hIvasDec->apaExecBuffer_fx ); - IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); - } - set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); -#endif } hIvasDec->nTransportChannelsOld = nTransportChannels; @@ -5807,7 +5809,8 @@ ivas_error IVAS_DEC_GetSplitRendBitstreamHeader( ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o : pointer to pose correction mode */ Word16 *pIsar_frame_size_ms, /* o : pointer to ISAR frame size setting */ Word16 *pCodec_frame_size_ms, /* o : pointer to codec frame size setting */ - Word16 *pLc3plusHighRes ) + Word16 *pLc3plusHighRes /* o : pointer to LC3plus High-Res setting */ +) { test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) @@ -5896,9 +5899,7 @@ static ivas_error ivas_create_handle_isar( ) { ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word16 i; -#endif IF( ( hSplitBinRend = (ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_WRAPPER ) ) ) == NULL ) { @@ -5907,17 +5908,14 @@ static ivas_error ivas_create_handle_isar( isar_init_split_rend_handles( &hSplitBinRend->splitrend ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP hSplitBinRend->hMultiBinTdData = NULL; FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { hSplitBinRend->hMultiBinCldfbData[i] = NULL; } -#else - hSplitBinRend->hMultiBinCldfbData = NULL; -#endif hSplitBinRend->hCldfbDataOut = NULL; hSplitBinRend->numTdSamplesPerChannelCached = 0; + move16(); *hSplitBinRend_out = hSplitBinRend; @@ -5935,17 +5933,15 @@ static void ivas_destroy_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend /* i/o: ISAR split binaural rendering handle */ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word16 i; -#endif IF( *hSplitBinRend != NULL ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP IF( ( *hSplitBinRend )->hMultiBinTdData != NULL ) { ivas_TD_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinTdData ); } + FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { IF( ( *hSplitBinRend )->hMultiBinCldfbData[i] != NULL ) @@ -5953,12 +5949,6 @@ static void ivas_destroy_handle_isar( ivas_CLDFB_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinCldfbData[i] ); } } -#else -#ifdef TMP_FIX_SPLIT_REND - free( ( *hSplitBinRend )->hMultiBinCldfbData ); - ( *hSplitBinRend )->hMultiBinCldfbData = NULL; -#endif -#endif ISAR_PRE_REND_close( &( *hSplitBinRend )->splitrend, NULL ); @@ -5982,7 +5972,8 @@ static void ivas_destroy_handle_isar( * *---------------------------------------------------------------------*/ -Word16 IVAS_DEC_is_split_rendering_enabled( +/*! r: decoder error code */ +ivas_error IVAS_DEC_is_split_rendering_enabled( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ Word16 *isSplitRend /* o : flag to indicate if split rendering is enabled */ ) @@ -6024,6 +6015,9 @@ static ivas_error ivas_dec_reconfig_split_rend( cldfb_in_flag = 0; move16(); + test(); + test(); + test(); 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_BINAURAL_PARAMETRIC ) || @@ -6038,6 +6032,10 @@ static ivas_error ivas_dec_reconfig_split_rend( isCldfbNeeded = 0; move16(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { @@ -6069,6 +6067,7 @@ static ivas_error ivas_dec_reconfig_split_rend( move16(); } + test(); test(); IF( EQ_16( isCldfbNeeded, 1 ) && hSplitRendWrapper->hCldfbHandles == NULL ) { @@ -6077,7 +6076,7 @@ static ivas_error ivas_dec_reconfig_split_rend( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB handles\n" ) ); } - num_ch = i_mult( MAX_HEAD_ROT_POSES, BINAURAL_CHANNELS ); + num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; move16(); FOR( ch = 0; ch < num_ch; ch++ ) { @@ -6106,13 +6105,13 @@ static ivas_error ivas_dec_reconfig_split_rend( } ELSE IF( EQ_16( isCldfbNeeded, 0 ) && hSplitRendWrapper->hCldfbHandles != NULL ) { - num_ch = i_mult( MAX_HEAD_ROT_POSES, BINAURAL_CHANNELS ); + num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; move16(); FOR( ch = 0; ch < num_ch; ch++ ) { IF( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ); + deleteCldfb_fx( &hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ); hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL; move32(); } @@ -6122,7 +6121,7 @@ static ivas_error ivas_dec_reconfig_split_rend( { IF( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ); + deleteCldfb_fx( &hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ); hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] = NULL; move32(); } @@ -6133,6 +6132,11 @@ static ivas_error ivas_dec_reconfig_split_rend( move32(); } + test(); + test(); + test(); + test(); + test(); IF( ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) /* td-rend not needed? */ @@ -6152,7 +6156,6 @@ static ivas_error ivas_dec_reconfig_split_rend( } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*-------------------------------------------------------------------* * ivas_dec_split_rend_cldfb_in() * @@ -6178,7 +6181,6 @@ static Word16 ivas_dec_split_rend_cldfb_in( return 0; } } -#endif /*-------------------------------------------------------------------* @@ -6194,38 +6196,21 @@ static ivas_error ivas_dec_init_split_rend( ivas_error error; Word16 cldfb_in_flag, pcm_out_flag; Word16 mixed_td_cldfb_flag; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word16 i, num_poses; ISAR_SPLIT_REND_ROT_AXIS head_rot_axis; -#endif - pcm_out_flag = ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0; - cldfb_in_flag = 0; + pcm_out_flag = 0; move16(); - -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - cldfb_in_flag = ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ); -#else - -#ifdef TMP_FIX_SPLIT_REND - /* note: this is intra-frame heap memory */ - IF( ( st_ivas->hSplitBinRend->hMultiBinCldfbData = (ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" ); - } -#endif - - 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_BINAURAL_PARAMETRIC ) || - EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - cldfb_in_flag = 1; + pcm_out_flag = 1; move16(); } -#endif + cldfb_in_flag = 0; + move16(); + + cldfb_in_flag = ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP head_rot_axis = DEFAULT_AXIS; move32(); if ( st_ivas->hHeadTrackData != NULL ) @@ -6233,6 +6218,7 @@ static ivas_error ivas_dec_init_split_rend( head_rot_axis = st_ivas->hHeadTrackData->sr_pose_pred_axis; move32(); } + ISAR_PRE_REND_GetMultiBinPoseData( &st_ivas->hRenderConfig->split_rend_config, &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, head_rot_axis ); num_poses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses; @@ -6257,11 +6243,8 @@ static ivas_error ivas_dec_init_split_rend( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" ); } } -#else - - ISAR_PRE_REND_GetMultiBinPoseData( &st_ivas->hRenderConfig->split_rend_config, &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->sr_pose_pred_axis : DEFAULT_AXIS ); -#endif + test(); IF( EQ_16( cldfb_in_flag, 1 ) && ( EQ_16( st_ivas->hSplitBinRend->splitrend.multiBinPoseData.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) ) ) { IF( ( st_ivas->hSplitBinRend->hCldfbDataOut = (ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA ) ) ) == NULL ) @@ -6272,6 +6255,10 @@ static ivas_error ivas_dec_init_split_rend( mixed_td_cldfb_flag = 0; move16(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { @@ -6279,7 +6266,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; @@ -6292,7 +6279,8 @@ static ivas_error ivas_dec_init_split_rend( * Return flag to indicate if split rendering is enabled *---------------------------------------------------------------------*/ -Word16 IVAS_DEC_is_split_rendering_coded_out( +/*! r: decoder error code */ +ivas_error IVAS_DEC_is_split_rendering_coded_out( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ Word16 *isSplitCoded /* o : flag to indicate if split rendering is enabled */ ) @@ -6321,3 +6309,218 @@ Word16 IVAS_DEC_is_split_rendering_coded_out( return IVAS_ERR_OK; } + + +/*---------------------------------------------------------------------* + * feedSinglePIorientation( ) + * + * Feed a single orientation PI data to external orientation handle. + *---------------------------------------------------------------------*/ + +static ivas_error feedSinglePIorientation( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ + IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ +) +{ + Word16 i; + ivas_error error; + Decoder_Struct *st_ivas; + IVAS_QUATERNION savedInvOrientation; + + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + + IF( isOrientationSaved ) + { + IF( !st_ivas->hExtOrientationData ) + { + IF( NE_32( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_num_subframes ), IVAS_ERR_OK ) ) + { + return error; + } + } + + 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_num_subframes ), IVAS_ERR_OK ) ) + { + return error; + } + } + + QuaternionInverse_fx( *savedOrientation, &savedInvOrientation ); + + /* use the new PI orientation or the previously saved orientation in processing */ + FOR( i = 0; i < st_ivas->hExtOrientationData->num_subframes; i++ ) + { + QuaternionProduct_fx( st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, + &st_ivas->hExtOrientationData->Quaternions[i] ); + st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; + move16(); + } + + hIvasDec->updateOrientation = true; + move16(); + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * setDiegeticInput( ) + * + * Set isDiegeticInput flag for combined orientation handle based on PI data. + *---------------------------------------------------------------------*/ + +static void setDiegeticInputPI( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const bool *diegeticPIValues /* i : diegetic values for the input stream */ +) +{ + Word16 i; + + IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) + { + FOR( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) + { + hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; + move16(); + } + + hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; + move16(); + } + + 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( ) + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_FeedPiDataToDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_PIDATA_TS *piData, /* i : PI data received in rtp packet */ + UWord32 numPiData /* i : number of PI data received in rtp packet */ +) +{ + UWord32 i; + Decoder_Struct *st_ivas; + ivas_error error = IVAS_ERR_OK; + move32(); + + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + + FOR( i = 0; i < numPiData; i++ ) + { + UWord32 piDataType = piData->data.noPiData.piDataType; + move32(); + + SWITCH( piDataType ) + { + case IVAS_PI_SCENE_ORIENTATION: + { + IVAS_QUATERNION *quat = &piData->data.scene.orientation; +#ifdef DEBUGGING + fprintf( stdout, "PI_SCENE_ORIENTATION : %f, %f, %f, %f\n", + fixedToFloat( quat->w_fx, Q15 ), + fixedToFloat( quat->x_fx, Q15 ), + fixedToFloat( quat->y_fx, Q15 ), + fixedToFloat( quat->z_fx, Q15 ) ); +#endif + error = feedSinglePIorientation( hIvasDec, true, quat ); + } + BREAK; + + case IVAS_PI_DEVICE_ORIENTATION_COMPENSATED: + { + IVAS_QUATERNION *quat = &piData->data.deviceCompensated.orientation; +#ifdef DEBUGGING + fprintf( stdout, "PI_DEVICE_ORIENTATION : %f, %f, %f, %f\n", + fixedToFloat( quat->w_fx, Q15 ), + fixedToFloat( quat->x_fx, Q15 ), + fixedToFloat( quat->y_fx, Q15 ), + fixedToFloat( quat->z_fx, Q15 ) ); +#endif + error = feedSinglePIorientation( hIvasDec, true, quat ); + } + BREAK; + + case IVAS_PI_ACOUSTIC_ENVIRONMENT: + { + UWord16 aeid; + aeid = piData->data.acousticEnv.aeid; + move16(); +#ifdef DEBUGGING + fprintf( stdout, "PI_ACOUSTIC_ENVIRONMENT : AEID : %d\n", aeid ); +#endif + test(); + test(); + IF( piData->data.acousticEnv.availLateReverb && st_ivas->hRenderConfig != NULL && aeid != st_ivas->hRenderConfig->roomAcoustics.aeID ) + { + error = feedAcousticEnvPI( hIvasDec, piData->data.acousticEnv ); + } + } + BREAK; + + case IVAS_PI_DIEGETIC_TYPE: + { +#ifdef DEBUGGING + fprintf( stdout, "PI_DIEGETIC_TYPE : %d, %d, %d, %d, %d\n", piData->data.digeticIndicator.isDiegetic[0], piData->data.digeticIndicator.isDiegetic[1], piData->data.digeticIndicator.isDiegetic[2], piData->data.digeticIndicator.isDiegetic[3], piData->data.digeticIndicator.isDiegetic[4] ); +#endif + setDiegeticInputPI( hIvasDec, piData->data.digeticIndicator.isDiegetic ); + } + BREAK; + + default: + { + /* NOT HANDLED PI DATA - DO NOTHING */ + } + BREAK; + } + + IF( NE_32( error, IVAS_ERR_OK ) ) + { + return error; + } + + piData++; + } + + return IVAS_ERR_OK; +} diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index 2358bfa79f97eced178fd2e6f1fd0da489bce2b7..0ce010cebc579ba4be26a60f625a63a56f7b65f7 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -9,27 +9,26 @@ /*======================================================================*/ /* FUNCTION : lp_filt_exc_dec_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Low-pass filtering of the adaptive exctitation */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) i_subfr : subframe index Q0 */ +/*----------------------------------------------------------------------*/ +/* PURPOSE : Low-pass filtering of the adaptive exctitation */ +/* */ +/*----------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word32) core_brate : Core bitrate Q0 */ +/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ +/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) i_subfr : subframe index Q0 */ /* _ (Word16) L_subfr : subframe size Q0 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/* _ (Word16 *) exc : excitation buffer Q0 */ -/*-----------------------------------------------------------------------*/ - -/* */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/*----------------------------------------------------------------------*/ +/* INPUT OUTPUT ARGUMENTS */ +/* _ (Word16 *) exc : excitation buffer Q0 */ +/*----------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ /*=======================================================================*/ void lp_filt_exc_dec_fx( diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index ec45dbae965bd56524cd22c57877730bb79a7afe..32c8c99581caeac996bc96bdbd233d9afb94c2a3 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -108,8 +108,8 @@ void lsf_dec_fx( Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ) { Word16 i; @@ -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*/ @@ -290,7 +292,6 @@ void lsf_dec_fx( test(); IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) { - // PMT("To be verified") IF( EQ_16( st_fx->active_cnt, 1 ) ) { Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ @@ -299,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) *------------------------------------------------------------------*/ @@ -364,13 +366,13 @@ void lsf_dec_fx( void lsf_end_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 mode2_flag, /* Q0 */ - const Word16 coder_type_org, /* i : coding type Q0*/ - const Word16 bwidth, /* i : input signal bandwidth Q0*/ - const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ - Word16 *lpc_param, /* i : LPC parameters Q0*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *nb_indices, /* o : number of indices Q0*/ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices, /* o : number of indices Q0*/ const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ) { @@ -808,10 +810,10 @@ void lsf_end_dec_fx( /* _ None */ /*========================================================================*/ void lsf_mid_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 lsp_new[], /* i : quantized LSPs from frame endS Q15*/ - Word16 coder_type, /* i : Coder type Q0*/ - Word16 lsp_mid[] /* o : quantized LSPs Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 1b5d79c6824596fad3684066b2e2f67ebca9a257..71d57c29993f71199482d5acc239ab4e0beb3d98 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -159,12 +159,12 @@ Word16 lsf_bctcvq_decprm( /* Returns: number of indices */ Word16 D_lsf_tcxlpc( - const Word16 indices[], /* i : VQ indices Q0*/ - Word16 lsf_q[], /* o : quantized LSF Q1*/ - Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ - Word16 narrowband, /* i : narrowband flag Q0*/ - Word16 cdk, /* i : codebook selector Q0*/ - Word16 mem_MA[] /* i : MA memory Q1*/ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ) { Word16 i; @@ -258,7 +258,7 @@ Word16 dec_lsf_tcxlpc( Word16 lsf_q_ind[M]; Word16 *flag; - flag = *indices; /* Save pointer Q0*/ + flag = *indices; /* Save pointer Q0*/ *flag = 0; move16(); /* Set flag to disabled */ ++*indices; diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index c088dd82663b8faa30514363b931ccd27ba39001..ff9c44bcdd4a32ccaabcfb29f89110cc31ca6c14 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 87d7e9cf3eceace20afd4016fc328a96eff25bfc..80fa60560198ea9f2cda772a64713847c1d1ec66 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -112,7 +112,6 @@ static void peak_vq_dec_fx( set16_fx( pvq_inp_vector, 0, HVQ_PVQ_BUF_LEN ); assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); - // PMT("max_peaks equation needs to be converted") max_peaks = extract_l( Mpy_32_32( ( L_add( imult3216( core_brate, HVQ_PEAKS_PER_DELTA ), HVQ_PEAKS_PER_DELTA_OFFS ) ), 282564 ) ); /* 1 / HVQ_PEAKS_BPS_DELTA in Q31 = 282564*/ bin_th = HVQ_THRES_BIN_24k; move16(); diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index d490dce4a4e6152ec857f8cefa7f8e08344f8444..dc3e6277d09bbf8cbd05a263b8610fb8faa3f0ad 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -298,7 +298,7 @@ void Mode2_delta_pit_dec( /* PURPOSE : calculate pitch value */ /* */ /*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* 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 */ diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index 5d6e397b0c6de34d9660a5c93915a26884056c3b..d6608cb33fc8a69d59f6f606156dae6f31c49443 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index b593c99c57227b019d4d837b9dd5a82e70929298..8bf9380b3fbe89ad809c452874a919b35cb61be8 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 00a333798ef26d9645b5c3a480cbe7c0dc267443..a9254f68c0e43d7b976d7e0bf1535a5e915fbdc9 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -202,29 +202,29 @@ static void DTFS_dequant_cw_fx( } } /*===================================================================*/ -/* FUNCTION : void ppp_quarter_decoder_fx () */ +/* FUNCTION : void ppp_quarter_decoder_fx () */ /*-------------------------------------------------------------------*/ -/* PURPOSE : */ +/* PURPOSE : */ /*-------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ Word16 bfi_fx - Q0 bad frame indicator */ -/* _ const Word16 *curr_lpc_fx - Q12 current frame LPC */ -/* _ Word16 *exc_fx - Q0 previous frame excitation */ -/* _ Word16 prevCW_lag_fx - Q0 Previous lag */ -/* _ (struct DTFS_fx) PREV_CW_D_FX : prototype in polar domain */ +/* _ Word16 bfi_fx - Q0 bad frame indicator */ +/* _ const Word16 *curr_lpc_fx - Q12 current frame LPC */ +/* _ Word16 *exc_fx - Q0 previous frame excitation */ +/* _ Word16 prevCW_lag_fx - Q0 Previous lag */ +/* _ (struct DTFS_fx) PREV_CW_D_FX : prototype in polar domain */ /* (Word16) lag: length of prototype in time domain */ /* (Word16 []) a: amplitude of harmonics, normalized */ /* (Word16) Q: norm factor of a */ /*-------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ Word16 *pitch - Q6 floating pitch values for each subframe */ -/* _ Word16 *out_fx - Q0 residual signal */ +/* _ Decoder_State_fx *st_fx: */ +/* _ Word16 *pitch - Q6 floating pitch values for each subframe */ +/* _ Word16 *out_fx - Q0 residual signal */ /*-------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lsp_old_fx - Q15 */ -/* _ st_fx->dtfs_dec_xxxx */ +/* _ Decoder_State_fx *st_fx: */ +/* _ lsp_old_fx - Q15 */ +/* _ st_fx->dtfs_dec_xxxx */ /* _ gainp_ppp Q14 */ /* _ lastLgainD_fx - Q11 */ /* _ lastHgainD_fx - Q11 */ @@ -233,24 +233,24 @@ static void DTFS_dequant_cw_fx( /* (Word16) lag: length of prototype in time domain */ /* (Word16 []) a: amplitude of harmonics, normalized */ /* (Word16) Q: norm factor of a */ -/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ -/* _ Word16 *exc_fx - Q0 previous frame excitation */ +/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ +/* _ Word16 *exc_fx - Q0 previous frame excitation */ /*-------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ -/* _ None */ +/* _ None */ /*-------------------------------------------------------------------*/ -/* CALLED FROM : RX */ +/* CALLED FROM : RX */ /*===================================================================*/ ivas_error ppp_quarter_decoder_fx( - DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ + DTFS_STRUCTURE *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ + Word16 prevCW_lag_fx, /* i : Previous lag */ + Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ + Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ + Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ + Word16 bfi, /* i : FER flag */ Word16 *S_fx, /* i : sine table, Q15 */ Word16 *C_fx, /* i : cosine table, Q15 */ - DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ + DTFS_STRUCTURE PREV_CW_D_FX, /* i : Previous DTFS */ Decoder_State *st_fx ) { DTFS_STRUCTURE *PREVDTFS_FX; diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index c507c134424edb72054d9510813c4169992a0748..96595be9abd67706f1504eb4e1e25cd311236a9d 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index 3bd3e12d1817d431a8b74f84105a5fe9da14963b..cf815e4e974729bed273748767bc954adc84103d 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index e63435f5b5a96163243d3ca186d01c25f123c0f6..fc68dee3521021ed909c631a209cef8c762db8d6 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/re8_dec_fx.c b/lib_dec/re8_dec_fx.c index e6c35e29339fc8dc0f9080434b1ab8ed19f6f9e9..7c88bea92d8ca67b5a0cfcaea50bc578d3915c94 100644 --- a/lib_dec/re8_dec_fx.c +++ b/lib_dec/re8_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/rom_dec.h b/lib_dec/rom_dec.h index 0d1c8d4f5d2a301d175a982aae197a51005a20c8..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef ROM_DEC_H diff --git a/lib_dec/rom_dec_fx.c b/lib_dec/rom_dec_fx.c index 0493e48ebf551cf23c70a032a36725ad572877e1..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index c226d8b9a68830300eec9c433d781875fde11569..cce198e33850939caae17e89a855e7aa2fb3ab84 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 8a8d6b09398d2b46219b6a3f740db980b33a879b..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef STAT_DEC_H @@ -1032,7 +1032,6 @@ typedef struct Decoder_State Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ - Word16 total_num_bits; /* == st->total_brate / 50 */ Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ Word32 output_Fs; /* output sampling rate */ Word16 output_frame_fx; /* Output frame length Q0*/ @@ -1259,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*/ @@ -1310,11 +1308,7 @@ typedef struct Decoder_State Word16 Q_syn; Word16 Q_syn2; Word16 Q_syn_cng; -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE Word16 Q_syn_factor; // This q_factor is used to avoid using fix Q0 for synth[] at the output of con_tcx_ivas_fx() and ivas_core_dec_fx(). For con_tcx_ivas_fx, it is used for two consecutive TCX concealment processes and It cannot be greater than 0. -#else - Word16 Q_syn_factor; // This q_factor is used to avoid using fixed Q0 for synth[] at the output of con_tcx_ivas_fx(). It is then used for two consecutive TCX concealment processes. It cannot be greater than 0. -#endif Word16 prev_Q_syn; Word16 prev_Q_bwe_exc; diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index c87e30ffec5f0f1cd5c6cb17b5562769100885bd..6972e4dd3bb8d90aedc26354a21d5b55d59e5e8c 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 42d2a9cc4a2e8015773e402e81b9751400538e11..f7c6e8c1683693611fcae1b97bae35b8b0bbe84a 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -354,9 +354,13 @@ Word16 WB_BWE_gain_deq_fx( *-------------------------------------------------------------------*/ /* o : Q_syn_hb */ +#ifdef HARM_FD_BWE +Word16 wb_bwe_dec_fx( +#else Word16 ivas_wb_bwe_dec_fx( +#endif Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word32 output_fx32[], /* o : synthesis @internal Fs Q11*/ 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,8 @@ 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]; + Word16 output[L_FRAME16k]; + Word16 Q_input, sf; Word16 scl, new_input_fx_exp; Word16 i; FD_BWE_DEC_HANDLE hBWE_FD; @@ -380,17 +386,26 @@ 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 ) { - /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ - /* IVAS_fmToDo: delay output[] by 1.25ms ? */ + 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 + lerp( output, ysynth_fx, L_FRAME16k, st_fx->L_frame ); wtda_fx( ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k ); + *Qpost = sub( new_input_fx_exp, 15 ); move16(); direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); @@ -399,14 +414,14 @@ Word16 ivas_wb_bwe_dec_fx( ELSE { wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); + *Qpost = sub( new_input_fx_exp, 15 ); move16(); - /* DCT of the ACELP core synthesis */ direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); ysynth_frame_size = output_frame; } + /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp ); /* Possible to Upscale? */ @@ -420,13 +435,23 @@ Word16 ivas_wb_bwe_dec_fx( } Copy_Scale_sig32_16( ysynth_32, ysynth_fx, ysynth_frame_size, scl ); Q_syn = add( sub( new_input_fx_exp, 16 ), scl ); + IF( !st_fx->bfi ) { IF( st_fx->extl_brate > 0 ) { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->hBWE_FD->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + hBWE_FD->last_wb_bwe_ener_fx = mult_r( add_sat( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384)) + } + ELSE +#endif + { + hBWE_FD->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); + } move16(); } ELSE @@ -462,6 +487,7 @@ Word16 ivas_wb_bwe_dec_fx( move16(); } } + test(); IF( NE_16( st_fx->last_extl, WB_BWE ) || st_fx->bfi ) { @@ -515,7 +541,7 @@ Word16 ivas_wb_bwe_dec_fx( return Q_syn_hb; } - +#ifndef HARM_FD_BWE Word16 wb_bwe_dec_fx( Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ @@ -655,7 +681,7 @@ Word16 wb_bwe_dec_fx( return Q_syn_hb; } - +#endif /*-------------------------------------------------------------------* * swb_bwe_gain_deq() @@ -940,21 +966,19 @@ Word16 swb_bwe_dec_fx( /*---------------------------------------------------------------------* * SWB BWE decoding *---------------------------------------------------------------------*/ + /* windowing of the ACELP core synthesis */ new_input_fx_exp = *Qpost; move16(); - { - wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &hBWE_FD->old_wtda_swb_fx_exp, - ALDO_WINDOW, - ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); - *Qpost = sub( new_input_fx_exp, 15 ); - move16(); - /* DCT of the ACELP core synthesis */ - direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); - } + wtda_fx( synth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, + &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); + + *Qpost = sub( new_input_fx_exp, 15 ); + move16(); + /* DCT of the ACELP core synthesis */ + direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); + /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp ); /* Possible to Upscale? */ @@ -1127,7 +1151,11 @@ Word16 swb_bwe_dec_fx( } /* time envelope shaping when the current frame is TRANSIENT frame */ +#ifdef HARM_FD_BWE + time_envelop_shaping_fx( st_fx->element_mode, hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); +#else time_envelop_shaping_fx( hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); +#endif Q_syn_hb = sub( Q_syn_hb, 3 ); hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3]; @@ -1227,9 +1255,9 @@ void fd_bwe_dec_init_fx( } /*-------------------------------------------------------------------* - * WB_BWE_gain_deq() + * swb_bwe_dec_fx32() * - * Decoding of WB parameters + * SWB BWE decoder, 32-bit variant *-------------------------------------------------------------------*/ @@ -1273,11 +1301,10 @@ Word16 swb_bwe_dec_fx32( /*---------------------------------------------------------------------* * SWB BWE decoding *---------------------------------------------------------------------*/ + test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { - /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */ - /* todo - delay output[] by 1.25ms ? */ L_lerp_fx_q11( output_fx, ysynth_fx32, L_FRAME16k, st_fx->L_frame ); /* windowing of the ACELP core synthesis */ @@ -1298,6 +1325,7 @@ Word16 swb_bwe_dec_fx32( /* DCT of the ACELP core synthesis */ new_input_fx_exp = 11; move16(); + /* DCT of the ACELP core synthesis */ direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); ysynth_frame_size = output_frame; move16(); @@ -1493,7 +1521,11 @@ Word16 swb_bwe_dec_fx32( } /* time envelope shaping when the current frame is TRANSIENT frame */ +#ifdef HARM_FD_BWE + time_envelop_shaping_fx( st_fx->element_mode, hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); +#else time_envelop_shaping_ivas_fx( hb_synth_fx16, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); +#endif Q_syn_hb = sub( Q_syn_hb, 3 ); diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index ff4d8bee65b694e9b56f26b48f8324857768f25f..813a26ea6aa28f4b5493fa3eae45d16421eafcb7 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index c0565dd75b636dc91be2e8f116a3ad43cb70515e..c7c94adacf19b8170e9f3c4c9a44f0a259362ef6 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index f1bea2e23ae5d4881ba271800091405b8fb3529a..60f22396ea4bd113e91eafb998228fbd351a5a72 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1,23 +1,19 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + 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 *-----------------------------------------------------------------*/ -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 ); - +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 ); 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 +23,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 +215,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 +254,17 @@ static void rescale_genSHB_mem_dec( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); + hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); + hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); 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 +272,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 +312,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 +339,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 +359,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 +467,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 +594,21 @@ 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 : */ /*==========================================================================*/ -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 */ + +void 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, /* 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 +643,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 */ @@ -751,8 +761,7 @@ void ivas_wb_tbe_dec_fx( 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 ); + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ ); } } ELSE @@ -835,9 +844,19 @@ 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++ ) + IF( st_fx->element_mode == EVS_MONO ) + { + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } + } + ELSE { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + 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 +867,14 @@ void ivas_wb_tbe_dec_fx( { Q_bwe_exc = norm_l( Lmax ); } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); + IF( st_fx->element_mode == EVS_MONO ) + { + Q_bwe_exc = sub( Q_bwe_exc, 1 ); + } + ELSE + { + 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 +891,81 @@ 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 ) + 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 { - 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 ) ); + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } + sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + 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 + { + 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_TBE2 + 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 + 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 + { + 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 ); + } +#endif curr_pow = 0; move32(); @@ -915,8 +984,14 @@ 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 ); + 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 + { + 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 +1007,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 +1015,19 @@ void ivas_wb_tbe_dec_fx( max = 0; move16(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) + 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 { - 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 +1069,7 @@ void ivas_wb_tbe_dec_fx( } test(); - test(); - IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) + IF( !st_fx->bfi && st_fx->prev_bfi ) { IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) { @@ -1063,13 +1146,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 +1265,19 @@ 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 ) ); + 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 + { + 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 @@ -1239,88 +1335,267 @@ void ivas_wb_tbe_dec_fx( } -void wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* o : WB synthesis/final synthesis */ - Word16 *Q_synth ) +/*======================================================================================*/ +/* FUNCTION : void swb_tbe_dec_fx () */ +/*--------------------------------------------------------------------------------------*/ +/* PURPOSE : SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module */ +/*--------------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _(Word16) coder_type : coding type */ +/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ +/* _(Word16[]) voice_factors :voicing factors Q15 */ +/* _(Word16*) Q_white_exc :Q Format of White Exc */ +/* _(Word16*) Q_synth :Q Format of Synthesis */ +/*--------------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _(Word16*)synth : SHB synthesis/final synthesis Q_white_exc */ +/* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ +/*--------------------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ 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 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ + Word16 Q_exc, + const Word16 voice_factors[], /* i : voicing factors */ + const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ + Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ + Word16 *Q_white_exc, + Word16 *synth, /* o : SHB synthesis/final synthesis */ + Word16 *Q_synth, + Word16 *pitch_buf /* i : pitch buffer Q6 */ +) { Word16 i; - Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; - Word16 shaped_wb_excitation_frac[L_FRAME16k / 4]; - Word16 bwe_exc_extended_16[L_FRAME32k + 40]; - Word16 exc4kWhtnd[L_FRAME16k / 4]; - Word16 lsf_wb[LPC_SHB_ORDER_WB], lpc_wb[LPC_SHB_ORDER_WB + 1], GainShape[NUM_SHB_SUBFR]; + Word16 shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD]; + Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; + Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; Word32 GainFrame; - Word16 error[L_FRAME16k]; - Word16 synth_frac[L_FRAME16k]; - Word16 upsampled_synth[L_FRAME48k]; - Word32 prev_pow, curr_pow, curr_frame_pow; + Word16 error[L_FRAME32k]; + Word32 L_ener; + Word16 ener; + Word16 is_fractive; + Word32 prev_pow, curr_pow, Lscale; + Word16 scale; + Word16 exp, tmp; + Word16 j, cnt; + Word16 n_mem, n_mem2, Qx, sc; + Word16 n_mem3; + Word32 Lmax, L_tmp; + Word16 frac; + + Word32 L_tmp1, L_tmp2; + Word16 expa, expb; + Word16 fraca, fracb; + Word16 GainShape_tmp[NUM_SHB_SUBGAINS]; + Word16 Q_bwe_exc; + Word16 Q_shb; + Word16 vf_modified[NB_SUBFR16k]; + Word16 stemp; + + Word16 tilt_swb_fec; + Word16 Q_bwe_exc_fb; + + Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; + Word16 lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )]; + const Word16 *ptr_lsp_interp_coef; + Word32 shb_ener_sf_32; + Word16 shb_res_gshape[NB_SUBFR16k]; + Word16 mixFactors; + Word16 vind; + Word16 shb_res_dummy[L_FRAME16k]; + Word16 shaped_shb_excitationTemp[L_FRAME16k]; + Word32 ener_tmp[NUM_SHB_SUBGAINS]; + Word16 pitch_fx; + Word16 l_subframe_fx; + Word16 formant_fac; + Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; + Word16 refl[M]; + Word16 tilt_para; + Word16 tmp1, tmp2; + Word16 f_fx, inc_fx; + Word32 GainFrame_prevfrm_fx; + + Word16 synth_scale_fx; + Word16 mean_vf; + Word16 exp_ener, inv_ener; + Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ + move32(); + Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; + Word32 curr_frame_pow; Word16 curr_frame_pow_exp; - Word16 temp, scale, n; - Word16 j; + Word32 L_prev_ener_shb; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; - Word16 Q_bwe_exc, Q_bwe_exc_ext, Qx; - Word16 n_mem, cnt; - Word16 max = 0; + /* initializations */ + GainFrame = L_deposit_l( 0 ); + mixFactors = 0; move16(); - Word32 L_tmp, Lacc, Lscale, Lmax = 0; - move32(); - Word16 tmp, exp, sc; - Word16 vf_modified[NB_SUBFR16k]; - Word16 uv_flag = 0; + shb_ener_sf_32 = L_deposit_l( 0 ); + set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); + st_fx->hTdCngDec->shb_dtx_count_fx = 0; move16(); - Word16 dummy = 0; + is_fractive = 0; move16(); - Word32 dummy2[HILBERT_MEM_SIZE]; - Word16 f, inc; - 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 ) + set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ + Q_shb = 0; /* high band target Q factor set to zero */ + move16(); + L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); + tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); + /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ + /* o: tilt_swb_fec in Q11 */ + test(); + if ( st_fx->bfi && st_fx->clas_dec != UNVOICED_CLAS ) { - /* Initialization */ - set16_fx( GainShape, 11469 /*0.35f Q15*/, NUM_SHB_SUBFR ); - GainFrame = 1; - move32(); - + tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; + move16(); + } + + /* WB/SWB bandwidth switching */ + test(); + test(); + IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && ( st_fx->clas_dec == UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( st_fx->prev_fractive == 0 ) && + ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || + ( EQ_16( st_fx->prev_fractive, 1 ) && + GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ + || ( GT_32( L_shr( st_fx->enerLL_fx, 1 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/ + LT_16( st_fx->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/ + ) + { + is_fractive = 0; + move16(); + } + ELSE + { + is_fractive = 1; + move16(); + } + } + + /* WB/SWB bandwidth switching */ + IF( st_fx->bws_cnt > 0 ) + { + f_fx = 1489; /*Q15*/ + move16(); + inc_fx = 1489; /*Q15*/ + move16(); + IF( EQ_16( is_fractive, 1 ) ) + { + Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); + } + ELSE + { + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16(); + f_fx = add( f_fx, inc_fx ); + } + } + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && + !( ( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 ) && L_sub( st_fx->prev_enerLH_fx, ( L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) ) || + ( sub( st_fx->last_core, ACELP_CORE ) != 0 ) || ( ( sub( st_fx->last_core, ACELP_CORE ) == 0 ) && ( L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) ) || ( sub( s_xor( is_fractive, st_fx->prev_fractive ), 1 ) == 0 ) ) + { + set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); + } + ELSE + { + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + { + hBWE_TD->prev_GainShape_fx = 11587; + move16(); + } + set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); + } + + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ + } + ELSE /* No bandwidth switching */ + { + test(); + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) + { + f_fx = 1489; /*Q15*/ + move16(); + inc_fx = 1489; /*Q15*/ + move16(); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + move16(); + f_fx = add( f_fx, inc_fx ); + } + } + IF( !st_fx->bfi ) { - IF( EQ_16( st_fx->use_partial_copy, 1 ) ) + IF( st_fx->use_partial_copy ) { - IF( NE_16( st_fx->last_extl, WB_TBE ) ) + IF( NE_16( st_fx->last_extl, SWB_TBE ) ) { hBWE_TD->GainFrame_prevfrm_fx = 0; - move32(); - hBWE_TD->lsp_prevfrm_fx[0] = 3277 /*0.1f Q15*/; move16(); - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) + f_fx = 1489 /*0.045454f Q15*/; + move16(); + inc_fx = 1489 /*0.045454f Q15*/; + move16(); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); /*Q15*/ + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; move16(); + f_fx = add( f_fx, inc_fx ); } } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { /* Frame gain */ - st_fx->rf_indx_tbeGainFr = s_and( st_fx->rf_indx_tbeGainFr, 0xF ); /* only four LSBs are valid */ - move16(); - Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); + GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); + move32(); /*Q18*/ + L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ + + frac = L_Extract_lc( L_tmp, &exp ); + L_tmp = Pow2( 30, frac ); + GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ test(); test(); test(); test(); test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); /*Q18*/ + GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); } } ELSE @@ -1363,7 +1638,7 @@ void wb_tbe_dec_fx( GainFrame = 2097152; /* 8.0f in Q18 */ move32(); test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) { temp = 26214 /*0.8 Q15*/; move16(); @@ -1372,9 +1647,8 @@ void wb_tbe_dec_fx( default: fprintf( stderr, "RF SWB-TBE gain bits not supported." ); } - IF( EQ_16( st_fx->last_extl, WB_TBE ) ) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) ) { - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } test(); @@ -1384,9 +1658,9 @@ void wb_tbe_dec_fx( test(); test(); test(); - IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) + if ( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) { - GainFrame = Mult_32_16( GainFrame, 9830 ); /*Q18*/ + GainFrame = Mult_32_16( GainFrame, 9830 ); } } } @@ -1394,2947 +1668,1681 @@ void wb_tbe_dec_fx( ELSE { /* de-quantization */ - dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0 ); + 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*/ ); + Q_shb = 0; + move16(); + /* o: shb_ener_sf_32 in (2*Q_shb) */ + /* o: shb_res_gshape in Q14 */ + /* o: GainShape Q15 */ + /* o: GainFrame Q18 */ } } - ELSE + ELSE /* FER concealment of TBE parameters */ { - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) + Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); + + /* Gain shape concealment */ + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ + /* Gradient based GS estimation */ + gradientGainShape( st_fx, GainShape, &GainFrame ); + /* o: GainShape[16] in Q15 */ + /* o: GainFrame in Q18 */ } ELSE { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); /*Q15*/ + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); + move16(); + } + } + IF( GT_16( tilt_swb_fec, ( 8 << 11 ) ) ) /* tilt_swb_fec in Q11 */ + { + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) + { + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ ); + } + ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) + { + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ ); + } + ELSE + { + GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ ); + } + GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping ); + } + ELSE + { + GainFrame = hBWE_TD->GainFrame_prevfrm_fx; + move16(); /* gain locking */ + } + } + + /* FER concealment for 24.4kbps and 32kbps */ + test(); + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + { + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + { + /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ + L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ + tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ + tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ + i = sub( norm_s( tmp1 ), 1 ); + tmp1 = shl( tmp1, i ); /* Qi */ + IF( tmp == 0 ) + { + tmp = 32767 /*1.0f Q15*/; + move16(); /*Q15*/ + } + ELSE + { + scale = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ + scale = s_max( scale, 0 ); + /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ + tmp = shl_sat( scale, sub( sub( 15, exp ), i ) ); /*Q15*/ + } + scale = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ + + test(); + IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || + GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) + { + /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ + shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale ); + + if ( GT_16( st_fx->nbLostCmpt, 1 ) ) + { + /* shb_ener_sf_32 *= 0.5f; */ + shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); + } + } + ELSE + { + /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ + L_tmp = L_mult( scale, scale ); /* Q29 */ + shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 ); + } + } + ELSE + { + test(); + IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || + GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) + { + /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ + shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); + } + ELSE + { + shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); + } + } } - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27853 ); + shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); + mixFactors = hBWE_TD->prev_mixFactors_fx; move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /*Q18*/ + set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, 5 ); /* Q14 */ } ELSE { - GainFrame = hBWE_TD->GainFrame_prevfrm_fx; /*Q18*/ - move32(); + set16_fx( shb_res_gshape, 16384 /*1.0f Q14*/, 5 ); /* Q14 */ } } + } - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) - { - /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; + /* get the gainshape delay */ + Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); + test(); + IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); move16(); } - ELSE + } + ELSE + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; + hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape[i * 4]; move16(); } + } - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - IF( EQ_16( coder_type, VOICED ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ - move16(); - } - } + /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ + /* mean(voice_factors[i], 4); */ + L_tmp = L_mult( voice_factors[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); + mean_vf = mac_r( L_tmp, voice_factors[3], 8192 ); - /* From low band excitation, generate highband excitation */ - Lmax = 0; - move32(); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - IF( Lmax == 0 ) + Copy( voice_factors, vf_modified, NB_SUBFR16k ); + + test(); + IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) + { + FOR( i = 1; i < NB_SUBFR; i++ ) { - Q_bwe_exc = 31; + L_tmp = L_mult( voice_factors[i], 26214 /*0.8f Q15*/ ); + vf_modified[i] = mac_r( L_tmp, voice_factors[i - 1], 6554 /*0.2f Q15*/ ); move16(); } - ELSE + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { - Q_bwe_exc = norm_l( Lmax ); + L_tmp = L_mult( voice_factors[4], 26214 /*0.8f Q15*/ ); + vf_modified[4] = mac_r( L_tmp, voice_factors[3], 6554 /*0.2f Q15*/ ); + move16(); } - Q_bwe_exc = sub( Q_bwe_exc, 1 ); - Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); + } - find_max_mem_wb( st_fx, &n_mem ); + /* convert quantized LSFs to LSPs for interpolation */ + E_LPC_lsf_lsp_conversion( lsf_shb, lsp_shb_2, LPC_SHB_ORDER ); - if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) - { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); - } + test(); + IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) + { + /* SHB LSP values from prev. frame for interpolation */ + Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER ); + } + ELSE + { + /* Use current frame's LSPs; in effect no interpolation */ + Copy( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); + } - test(); - if ( uv_flag && GT_16( Q_bwe_exc, 20 ) ) + test(); + test(); + test(); + IF( ( st_fx->bws_cnt == 0 ) && ( st_fx->bws_cnt1 == 0 ) && ( st_fx->prev_use_partial_copy == 0 ) && ( st_fx->use_partial_copy == 0 ) ) + { + lsf_diff[0] = 16384; + move16(); /*Q15*/ + lsf_diff[LPC_SHB_ORDER - 1] = 16384; + move16(); /*Q15*/ + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - Q_bwe_exc = 20; - move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ + lsf_diff[i] = sub( lsf_shb[i], lsf_shb[i - 1] ); + move16(); } - prev_pow = 0; - move32(); - IF( st_fx->element_mode > EVS_MONO ) - { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); + tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ + tmp1 = mult( 27425, tmp ); + tmp1 = mult( tmp1, tmp ); /*Q10*/ + tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ + tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ + + test(); + IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) { - 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 = 1; i < LPC_SHB_ORDER - 1; i++ ) + { + hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff[i], 1 ); + move16(); + } } - rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) { - 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 ); + test(); + test(); + test(); + test(); + test(); + IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && + !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st_fx->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) + { + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) + { + IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) + { + tmp = mult( 26214, lsf_diff[i] ); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); + test(); + IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ + { + st_fx->BER_detect = 1; + move16(); + tmp = 0; + move16(); + } + ELSE + { + tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + } - Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); + move16(); + } + ELSE + { + tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - 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, vf_modified, uv_flag, st_fx->igf ); + test(); + IF( ( lsf_diff[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ + { + st_fx->BER_detect = 1; + move16(); + tmp = 0; + move16(); + } + ELSE + { + tmp = div_s( tmp, lsf_diff[i] ); + } - curr_pow = 0; - move32(); - IF( st_fx->element_mode > EVS_MONO ) - { - tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0_sat( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ - } + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); + move16(); + } + } + w[0] = w[1]; + move16(); + w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; + move16(); - if ( GT_16( voice_factors[0], 24576 ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + tmp1 = mult( lsp_shb_1[i], sub( 32767, w[i] ) ); + tmp2 = mult( lsp_shb_2[i], w[i] ); + lsp_temp[i] = add( tmp1, tmp2 ); + move16(); + } + } + ELSE + { + Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); + } } - 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 ); + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = tilt_para; + move16(); + } + ELSE + { + Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); + } - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + test(); + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + { + /* ---------- SHB LSP interpolation ---------- */ + ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ + FOR( j = 0; j < 4; j++ ) { - 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(); - } - Lscale = root_a_fx( Lscale, sub( 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 */ + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ + /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ + L_tmp = L_mult( lsp_shb_1[i], ( *ptr_lsp_interp_coef ) ); + lsp_temp[i] = mac_r( L_tmp, lsp_shb_2[i], ( *( ptr_lsp_interp_coef + 1 ) ) ); + move16(); + } + ptr_lsp_interp_coef += 2; - /* 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, - window_wb_fx, subwin_wb_fx, - Q_bwe_exc_ext, st_fx->L_frame, 0, &dummy, dummy, dummy2 ); - - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ - } - - IF( max == 0 ) - { - curr_frame_pow = 1; - move32(); - n = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - shaped_wb_excitation_frac[i] = shl_sat( shaped_wb_excitation[i], n ); /*Q14*/ - move16(); - } - n = sub( 14, n ); - curr_frame_pow = 1; - move32(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - L_tmp = L_mult_sat( shaped_wb_excitation_frac[i], shaped_wb_excitation_frac[i] ); /*Q29*/ - curr_frame_pow = L_add_sat( curr_frame_pow, L_shr( L_tmp, 7 ) ); /*Q22*/ - } - } - curr_frame_pow_exp = add( n, n ); - - IF( GT_16( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ) - { - curr_frame_pow = L_shr( curr_frame_pow, sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ); - curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; - move16(); - } - ELSE - { - hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, hBWE_TD->prev_frame_pow_exp ) ); - move32(); - } - - test(); - IF( !st_fx->bfi && st_fx->prev_bfi ) - { - IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /* Q15 */ - } - ELSE - { - scale = temp = 32767; - move16(); /* Q15 */ - move16(); - } - - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); - FOR( i = 0; i < L_FRAME16k / ( 4 * 8 ); i++ ) - { - shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )] = mult_r( shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )], scale ); - } - IF( temp > 0 ) - { - IF( LT_16( scale, temp ) ) - { - scale = div_s( scale, temp ); - } - ELSE - { - scale = 32767; - move16(); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - hBWE_TD->prev_wb_bwe_frame_pow_fx = curr_frame_pow; - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - - /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */ - max = 0; - move16(); - FOR( cnt = 0; cnt < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; cnt++ ) - { - if ( GT_16( abs_s( shaped_wb_excitation[cnt] ), max ) ) - { - max = abs_s( shaped_wb_excitation[cnt] ); - } - } - Qx = norm_s( max ); - if ( max == 0 ) - { - Qx = 15; - move16(); - } - - Qx = sub( Qx, 1 ); /* 1 bit space for saturation */ - - max = 0; - move16(); - 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 ) ) - { - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - max = s_max( max, abs_s( hBWE_TD->state_32and48k_WB_upsample_fx[i] ) ); - } - } - IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - FOR( i = 0; i < INTERP_3_1_MEM_LEN; i++ ) - { - max = s_max( max, abs_s( hBWE_TD->mem_resamp_HB_fx[i] ) ); - } - } - n_mem = 15; - move16(); - if ( max != 0 ) - { - n_mem = norm_s( max ); - } - n_mem = s_max( n_mem, 0 ); - - if ( GT_16( sub( Qx, hBWE_TD->prev_Qx ), n_mem ) ) - { - Qx = add( hBWE_TD->prev_Qx, n_mem ); - } - - FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) - { - shaped_wb_excitation[i] = shl( shaped_wb_excitation[i], Qx ); - move16(); - } - - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); - move16(); - } - - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); - move16(); - } - - GenWBSynth_fx( shaped_wb_excitation, error, hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx ); - - Copy( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - synth[i] = mult_r( error[i], 21299 ); - move16(); - } - - IF( st_fx->hBWE_FD != NULL ) - { - max = 0; - move16(); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) - { - max = s_max( max, abs_s( synth[cnt] ) ); - } - - IF( max == 0 ) - { - st_fx->hBWE_FD->last_wb_bwe_ener_fx = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) - { - synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ - move16(); - } - n = sub( sub( 14, n ), Qx ); - - Lacc = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ - Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ - } - - L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ - exp = norm_l( L_tmp ); - tmp = round_fx_sat( L_shl( L_tmp, exp ) ); - exp = sub( add( exp, 22 ), 30 ); - tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - st_fx->hBWE_FD->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ - move16(); - } - } - - IF( EQ_32( st_fx->output_Fs, 32000 ) ) /* 32kHz sampling rate, but only WB output - interpolate */ - { - Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, hBWE_TD->prev_Qx ) ); - Interpolate_allpass_steep_fx( synth, hBWE_TD->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); - Copy( upsampled_synth, synth, L_FRAME32k ); - } - ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - 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 - { - f = 5461; - move16(); /* Q15 */ - inc = 5461; - move16(); /* Q15 */ - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - lsf_wb[i] = f; - move16(); /*Q15*/ - f = add_sat( f, inc ); - move16(); - } - GainFrame = 0; /* Q18 */ - move32(); - Qx = 0; - move16(); - Q_bwe_exc = 31; - move16(); - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ - move32(); - hBWE_TD->prev_frame_pow_exp = 0; - move16(); - } - - /* Update previous frame parameters for FEC */ - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) - { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ - } - ELSE - { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ - } - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ - move32(); - - IF( !st_fx->bfi ) - { - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ - move16(); - } - - *Q_synth = Qx; - move16(); - - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - hBWE_TD->prev_Qx = Qx; - move16(); - - return; -} - - -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_dec_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type : coding type */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/* _(Word16*) Q_synth :Q Format of Synthesis */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)synth : SHB synthesis/final synthesis Q_white_exc */ -/* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ 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 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ - Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, - Word16 *synth, /* o : SHB synthesis/final synthesis */ - Word16 *Q_synth, - Word16 *pitch_buf /* i : pitch buffer Q6 */ -) -{ - Word16 i; - Word16 shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD]; - Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; - Word32 GainFrame; - Word16 error[L_FRAME32k]; - Word32 L_ener; - Word16 ener; - Word16 is_fractive; - Word32 prev_pow, curr_pow, Lscale; - Word16 scale; - Word16 exp, tmp; - Word16 j, cnt; - Word16 n_mem, n_mem2, Qx, sc; - Word16 n_mem3; - Word32 Lmax, L_tmp; - Word16 frac; - - Word32 L_tmp1, L_tmp2; - Word16 expa, expb; - Word16 fraca, fracb; - Word16 GainShape_tmp[NUM_SHB_SUBGAINS]; - Word16 Q_bwe_exc; - Word16 Q_shb; - Word16 vf_modified[NB_SUBFR16k]; - Word16 stemp; - - Word16 tilt_swb_fec; - Word16 Q_bwe_exc_fb; - - Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; - Word16 lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )]; - const Word16 *ptr_lsp_interp_coef; - Word32 shb_ener_sf_32; - Word16 shb_res_gshape[NB_SUBFR16k]; - Word16 mixFactors; - Word16 vind; - Word16 shb_res_dummy[L_FRAME16k]; - Word16 shaped_shb_excitationTemp[L_FRAME16k]; - Word32 ener_tmp[NUM_SHB_SUBGAINS]; - Word16 pitch_fx; - Word16 l_subframe_fx; - Word16 formant_fac; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; - Word16 tmp1, tmp2; - Word16 f_fx, inc_fx; - Word32 GainFrame_prevfrm_fx; - - Word16 synth_scale_fx; - Word16 mean_vf; - Word16 exp_ener, inv_ener; - Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ - move32(); - Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; - Word32 curr_frame_pow; - Word16 curr_frame_pow_exp; - Word32 L_prev_ener_shb; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - /* initializations */ - GainFrame = L_deposit_l( 0 ); - mixFactors = 0; - move16(); - shb_ener_sf_32 = L_deposit_l( 0 ); - set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); - st_fx->hTdCngDec->shb_dtx_count_fx = 0; - move16(); - is_fractive = 0; - move16(); - set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ - Q_shb = 0; /* high band target Q factor set to zero */ - move16(); - L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); - tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); - /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ - /* o: tilt_swb_fec in Q11 */ - test(); - if ( st_fx->bfi && st_fx->clas_dec != UNVOICED_CLAS ) - { - tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; - move16(); - } - - /* WB/SWB bandwidth switching */ - test(); - test(); - IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && ( st_fx->clas_dec == UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( st_fx->prev_fractive == 0 ) && - ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || - ( EQ_16( st_fx->prev_fractive, 1 ) && - GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ - || ( GT_32( L_shr( st_fx->enerLL_fx, 1 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/ - LT_16( st_fx->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/ - ) - { - is_fractive = 0; - move16(); - } - ELSE - { - is_fractive = 1; - move16(); - } - } - - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt > 0 ) - { - f_fx = 1489; /*Q15*/ - move16(); - inc_fx = 1489; /*Q15*/ - move16(); - IF( EQ_16( is_fractive, 1 ) ) - { - Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - } - ELSE - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && - !( ( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 ) && L_sub( st_fx->prev_enerLH_fx, ( L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) ) || - ( sub( st_fx->last_core, ACELP_CORE ) != 0 ) || ( ( sub( st_fx->last_core, ACELP_CORE ) == 0 ) && ( L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) ) || ( sub( s_xor( is_fractive, st_fx->prev_fractive ), 1 ) == 0 ) ) - { - set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); - } - ELSE - { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) - { - hBWE_TD->prev_GainShape_fx = 11587; - move16(); - } - set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); - } - - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ - } - ELSE /* No bandwidth switching */ - { - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) - { - f_fx = 1489; /*Q15*/ - move16(); - inc_fx = 1489; /*Q15*/ - move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - - IF( !st_fx->bfi ) - { - IF( st_fx->use_partial_copy ) - { - IF( NE_16( st_fx->last_extl, SWB_TBE ) ) - { - hBWE_TD->GainFrame_prevfrm_fx = 0; - move16(); - f_fx = 1489 /*0.045454f Q15*/; - move16(); - inc_fx = 1489 /*0.045454f Q15*/; - move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); - - IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) - { - /* Frame gain */ - GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); - move32(); /*Q18*/ - L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) - { - /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); - } - } - ELSE - { - temp = 0; - move16(); - /* Frame gain */ - SWITCH( st_fx->rf_indx_tbeGainFr ) - { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - move32(); - if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 2: - GainFrame = 1048576; /* 4.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 3: - GainFrame = 2097152; /* 8.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - default: - fprintf( stderr, "RF SWB-TBE gain bits not supported." ); - } - IF( EQ_16( st_fx->last_extl, SWB_TBE ) ) - { - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); - } - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) ) - { - test(); - test(); - test(); - test(); - if ( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) - { - GainFrame = Mult_32_16( GainFrame, 9830 ); - } - } - } - } - ELSE - { - - /* de-quantization */ - 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 ); - Q_shb = 0; - move16(); - /* o: shb_ener_sf_32 in (2*Q_shb) */ - /* o: shb_res_gshape in Q14 */ - /* o: GainShape Q15 */ - /* o: GainFrame Q18 */ - } - } - ELSE /* FER concealment of TBE parameters */ - { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - - /* Gain shape concealment */ - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /* Gradient based GS estimation */ - gradientGainShape( st_fx, GainShape, &GainFrame ); - /* o: GainShape[16] in Q15 */ - /* o: GainFrame in Q18 */ - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); - move16(); - } - } - IF( GT_16( tilt_swb_fec, ( 8 << 11 ) ) ) /* tilt_swb_fec in Q11 */ - { - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ ); - } - ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ ); - } - ELSE - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ ); - } - GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping ); - } - ELSE - { - GainFrame = hBWE_TD->GainFrame_prevfrm_fx; - move16(); /* gain locking */ - } - } - - /* FER concealment for 24.4kbps and 32kbps */ - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ - L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ - tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ - tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ - i = sub( norm_s( tmp1 ), 1 ); - tmp1 = shl( tmp1, i ); /* Qi */ - IF( tmp == 0 ) - { - tmp = 32767 /*1.0f Q15*/; - move16(); /*Q15*/ - } - ELSE - { - scale = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ - scale = s_max( scale, 0 ); - /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ - tmp = shl_sat( scale, sub( sub( 15, exp ), i ) ); /*Q15*/ - } - scale = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ - - test(); - IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || - GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) - { - /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale ); - - if ( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - /* shb_ener_sf_32 *= 0.5f; */ - shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); - } - } - ELSE - { - /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ - L_tmp = L_mult( scale, scale ); /* Q29 */ - shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 ); - } - } - ELSE - { - test(); - IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || - GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) - { - /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); - } - ELSE - { - shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); - } - } - } - - shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); - mixFactors = hBWE_TD->prev_mixFactors_fx; - move16(); - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, 5 ); /* Q14 */ - } - ELSE - { - set16_fx( shb_res_gshape, 16384 /*1.0f Q14*/, 5 ); /* Q14 */ - } - } - } - - /* get the gainshape delay */ - Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); - test(); - IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape[i * 4]; - move16(); - } - } - - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors[i], 4); */ - L_tmp = L_mult( voice_factors[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); - mean_vf = mac_r( L_tmp, voice_factors[3], 8192 ); - - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - - test(); - IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mult( voice_factors[i], 26214 /*0.8f Q15*/ ); - vf_modified[i] = mac_r( L_tmp, voice_factors[i - 1], 6554 /*0.2f Q15*/ ); - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - L_tmp = L_mult( voice_factors[4], 26214 /*0.8f Q15*/ ); - vf_modified[4] = mac_r( L_tmp, voice_factors[3], 6554 /*0.2f Q15*/ ); - move16(); - } - } - - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion( lsf_shb, lsp_shb_2, LPC_SHB_ORDER ); - - test(); - IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER ); - } - ELSE - { - /* Use current frame's LSPs; in effect no interpolation */ - Copy( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); - } - - test(); - test(); - test(); - IF( ( st_fx->bws_cnt == 0 ) && ( st_fx->bws_cnt1 == 0 ) && ( st_fx->prev_use_partial_copy == 0 ) && ( st_fx->use_partial_copy == 0 ) ) - { - lsf_diff[0] = 16384; - move16(); /*Q15*/ - lsf_diff[LPC_SHB_ORDER - 1] = 16384; - move16(); /*Q15*/ - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - lsf_diff[i] = sub( lsf_shb[i], lsf_shb[i - 1] ); - move16(); - } - - a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); - tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ - tmp1 = mult( 27425, tmp ); - tmp1 = mult( tmp1, tmp ); /*Q10*/ - tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ - tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff[i], 1 ); - move16(); - } - } - - IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && - !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st_fx->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) - { - tmp = mult( 26214, lsf_diff[i] ); - - test(); - IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - } - - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - ELSE - { - tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - - test(); - IF( ( lsf_diff[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s( tmp, lsf_diff[i] ); - } - - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - } - w[0] = w[1]; - move16(); - w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; - move16(); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult( lsp_shb_1[i], sub( 32767, w[i] ) ); - tmp2 = mult( lsp_shb_2[i], w[i] ); - lsp_temp[i] = add( tmp1, tmp2 ); - move16(); - } - } - ELSE - { - Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); - } - } - - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = tilt_para; - move16(); - } - ELSE - { - Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); - } - - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ - L_tmp = L_mult( lsp_shb_1[i], ( *ptr_lsp_interp_coef ) ); - lsp_temp[i] = mac_r( L_tmp, lsp_shb_2[i], ( *( ptr_lsp_interp_coef + 1 ) ) ); - move16(); - } - ptr_lsp_interp_coef += 2; - - /* convert from lsp to lsf */ - /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - - tmp = i_mult( j, LPC_SHB_ORDER + 1 ); - /* convert LSPs to LP coefficients */ - E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf + tmp, lpc_shb_sf + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf[tmp] ), 2 ) ); - } - } - /*ELSE*/ - { - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb[0] ), 2 ) ); /* Q12 */ - } - - /* Save the SWB LSP values from current frame for interpolation */ - Copy( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); - /* lsp_shb_2_fx in Q15 */ - - /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ - hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; - move32(); - hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; - move32(); - hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; - move32(); - hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; - move16(); - hBWE_TD->prev_mixFactors_fx = mixFactors; - move16(); - - /* SWB CNG/DTX - update memories */ - if ( st_fx->hTdCngDec != NULL ) - { - Copy( st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - Copy( lsf_shb, st_fx->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - } - - /* vind = (short)(mixFactors*8.0f); */ - vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ - /* i: mixFactors in Q15 */ - /* o: vind in Q0 */ - - /* Determine formant PF strength */ - formant_fac = swb_formant_fac_fx( lpc_shb[1], &hBWE_TD->tilt_mem_fx ); - /* o: formant_fac in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = 0; - move32(); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if ( Lmax == 0 ) - { - Q_bwe_exc = 31; - move16(); - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_dec( st_fx, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ - - tmp = add( st_fx->prev_Q_bwe_exc, n_mem ); - if ( GT_16( Q_bwe_exc, tmp ) ) - { - Q_bwe_exc = tmp; - move16(); - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_dec( st_fx, sc ); - } - - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - 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 ); - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); - - /* save the previous Q factor (32-bit) of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; - move16(); - - IF( GT_32( st_fx->total_brate, ACELP_32k ) ) - { - FOR( j = 0; j < 4; j++ ) - { - Copy( lpc_shb, &lpc_shb_sf[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); - } - } - - /* 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, - &( 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 ); - - *Q_white_exc = Q_bwe_exc_fb; - move16(); - IF( EQ_16( st_fx->extl, FB_TBE ) ) - { - hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - } - /* rescale the TBE post proc memory */ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - /* TD BWE post-processing */ - PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac ); - } - Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ - - tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ - curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - if ( GT_16( voice_factors[0], 24576 /*0.75f Q15*/ ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl( Q_bwe_exc, 1 ), prev_pow, shl( Q_bwe_exc, 1 ), &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - IF( exp < 0 ) - { - Lscale = L_shl( Lscale, exp ); - exp = 0; - move16(); - } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - temp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ - temp = sub( 32767 /*1.0f Q15*/, temp ); - Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - ELSE - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - temp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ - temp = sub( 32767 /*1.0f Q15*/, temp ); - Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; - L_ener = 0; - move32(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = 0; - move32(); - ener_tmp[i] = 0; - move32(); - { - Word64 tmp64 = 0; - move64(); - FOR( j = 0; j < l_subframe_fx; j++ ) - { - tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )], shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )] ); /* 2*Q_bwe_exc */ - } - L_tmp = W_sat_l( tmp64 ); - } - - L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - ener_tmp[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ - move32(); - L_ener = L_add_sat( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ - } - } - ener = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt > 0 ) - { - ener = mult( ener, 11587 ); - /*bandwidth switching should be updated*/ - if ( GT_16( st_fx->tilt_swb_fx, 16384 ) ) - { - st_fx->prev_fractive = 1; - move16(); - } - - IF( is_fractive == 0 ) - { - IF( GT_16( st_fx->tilt_wb_fx, 2048 ) ) /*assuming st_fx->tilt_wb_fx in Q11*/ - { - st_fx->tilt_wb_fx = 2048; - move16(); - } - ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 ) ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - test(); - if ( EQ_16( st_fx->prev_fractive, 1 ) && GT_16( st_fx->tilt_wb_fx, 1024 ) ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - } - ELSE - { - IF( GT_16( st_fx->tilt_wb_fx, 8192 ) ) - { - IF( st_fx->prev_fractive == 0 ) - { - st_fx->tilt_wb_fx = 8192; - move16(); - } - ELSE - { - st_fx->tilt_wb_fx = 16384; - move16(); - } - } - ELSE - { - st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); - move16(); - } - } - - IF( ener != 0 ) - { - L_tmp = L_shl( L_mult0( ener, st_fx->tilt_wb_fx ), sub( st_fx->Q_syn2, 14 ) ); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ - exp_ener = norm_s( ener ); - tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ - - test(); - IF( GT_32( L_tmp, st_fx->enerLH_fx ) ) /*st_fx->Q_syn2*/ - { - st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ - move16(); - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ - } - ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) - { - st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ - move16(); - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ - } - L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ - } - ELSE - { - GainFrame_prevfrm_fx = 0; - move32(); - } - - IF( EQ_16( is_fractive, 1 ) ) - { - GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 10 ); - } - ELSE - { - GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 8 ); - } - - test(); - IF( EQ_16( s_and( is_fractive, st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) - { - GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ - } - ELSE - { - test(); - test(); - test(); - test(); - IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st_fx->prev_fractive ) == 0 ) ) - { - GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); - } - ELSE - { - test(); - IF( ( is_fractive == 0 ) && EQ_16( st_fx->prev_fractive, 1 ) ) - { - L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ - L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ - GainFrame = L_add( Mult_32_32( GainFrame, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */ - } - ELSE - { - GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame ), 1 ) ); /* 18 */ - } - } - } - - GainFrame = Mult_32_16( GainFrame, i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ) ); /*Q18*/ - } - ELSE - { - if ( st_fx->bws_cnt1 > 0 ) - { - GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ - } - IF( GE_16( st_fx->nbLostCmpt, 1 ) ) - { - ener = s_max( 1, ener ); - exp_ener = norm_s( ener ); - tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp)*/ - prev_ener_ratio_fx = L_shr_sat( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ - } - - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->clas_dec != UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && - ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) - { - IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame, 19661 ) ); /*18*/ - } - ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); - } - ELSE - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - - test(); - IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) - { - exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); - tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ - tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/ - tmp = extract_h( L_shl( L_mult0( tmp, st_fx->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */ - GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ - } - } - ELSE IF( ( ( st_fx->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) - { - test(); - IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) - { - GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ - } - ELSE - { - GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ - } - } - ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) - { - test(); - IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ); - } - ELSE - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - } - } - } - st_fx->prev_fractive = is_fractive; - move16(); - - /* Adjust the subframe and frame gain of the synthesized shb signal */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - /* pitch = 0.25f*sum_s(pitch_buf, 4); */ - L_tmp = L_mult( pitch_buf[0], 8192 ); - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mac( L_tmp, pitch_buf[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */ - } - pitch_fx = round_fx( L_tmp ); /* Q6 */ - } - ELSE - { - /* pitch_fx = 0.2f*sum_s(pitch_buf, 5); */ - L_tmp = L_mult( pitch_buf[0], 6554 ); - FOR( i = 1; i < NB_SUBFR16k; i++ ) - { - L_tmp = L_mac( L_tmp, pitch_buf[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */ - } - pitch_fx = round_fx( L_tmp ); /* Q6 */ - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->prev_coder_type, coder_type ) && NE_16( coder_type, UNVOICED ) ) || ( LE_32( st_fx->total_brate, ACELP_16k40 ) && ( EQ_16( st_fx->prev_coder_type, coder_type ) || ( EQ_16( st_fx->prev_coder_type, VOICED ) && EQ_16( coder_type, GENERIC ) ) || ( EQ_16( st_fx->prev_coder_type, GENERIC ) && EQ_16( coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st_fx->extl, FB_TBE ) ) - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - GainShape_tmp[i] = GainShape[i * 4]; /* Q15 */ - move16(); - } - - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ - L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ - L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ - tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); - L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ - IF( GT_32( L_tmp1, L_tmp2 ) ) - { - /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ - /* tmp = L_tmp2/ener_tmp_fx[i]*/ - L_tmp = L_tmp2; - move32(); - if ( L_tmp2 < 0 ) - { - L_tmp = L_negate( L_tmp2 ); - } - - expb = norm_l( L_tmp ); - fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); - expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ - - expa = norm_l( ener_tmp[i] ); - fraca = extract_h( L_shl( ener_tmp[i], expa ) ); - expa = sub( 30, expa ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); - expb = sub( expb, scale ); - - tmp = div_s( fracb, fraca ); - exp = sub( sub( expb, expa ), 1 ); - tmp = shl( tmp, exp ); - GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ - move16(); - } - - hBWE_TD->prev_ener_fx = ener_tmp[i]; - move32(); - hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; - move16(); - hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; - move16(); - } - FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) - { - Word16 idx = 0; - move16(); - IF( i != 0 ) - { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); - } - GainShape[i] = GainShape_tmp[idx]; - move16(); - } - } - ELSE - { - hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; - move16(); - } - - - /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ - hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - /* Scale the shaped excitation */ - ScaleShapedSHB_fx( SHB_OVERLAP_LEN, - shaped_shb_excitation, /* i/o: Q_bwe_exc */ - hBWE_TD->syn_overlap_fx, - GainShape, /* Q15 */ - GainFrame, /* Q18 */ - window_shb_fx, - subwin_shb_fx, - &Q_bwe_exc, &Qx, n_mem3, hBWE_TD->prev_Q_bwe_syn2 ); - - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ - } - - IF( max == 0 ) - { - curr_frame_pow = 0; - move16(); - n = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ - move16(); - } - - curr_frame_pow = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ - } - } - curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - - - tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); - IF( tmp > 0 ) /* shifting prev */ - { - IF( GT_16( tmp, 32 ) ) - { - hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); - move16(); - tmp = 32; - move16(); - } - hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - } - ELSE /* shifting curr */ - { - IF( LT_16( tmp, -32 ) ) - { - curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); - tmp = -32; - move16(); - } - curr_frame_pow = L_shr( curr_frame_pow, -tmp ); - curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; - move16(); - } - test(); - IF( !st_fx->bfi && st_fx->prev_bfi ) - { - L_tmp = L_shr( curr_frame_pow, 4 ); - L_tmp = Mult_32_16( L_tmp, 17476 ); - - test(); - test(); - IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && - ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st_fx->prev_coder_type, UNVOICED ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - } - ELSE - { - scale = temp = 32767; - move16(); /*Q15*/ - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - move16(); - GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); - move16(); - FOR( i = 0; i < L_FRAME16k / 8; i++ ) - { - shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )], scale ); - move16(); - } - - IF( temp > 0 ) - { - /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) - and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ - IF( LT_16( scale, temp ) ) - { - scale = div_s( scale, temp ); - } - ELSE - { - scale = 32767; - move16(); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - /* adjust the FEC frame energy */ - IF( st_fx->bfi ) - { - scale = temp = 4096; - move16(); /*Q12*/ - - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && - NE_16( st_fx->prev_coder_type, UNVOICED ) && - ( st_fx->last_good != UNVOICED_CLAS ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = shl_sat( mult_r( GainShape[2 * j], scale ), 3 ); - move16(); /* 15 +12 +3-15 =15*/ - GainShape[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape[add( 2 * j, 1 )], scale ), 3 ); - move16(); - FOR( i = 0; i < 40; i++ ) - { - shaped_shb_excitation[add( i, j * 40 )] = shl_sat( mult_r( shaped_shb_excitation[add( i, j * 40 )], scale ), 3 ); - move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ - } + /* convert from lsp to lsf */ + /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - IF( temp > 0 ) - { - IF( LT_16( scale, temp ) ) - { - scale = shr( div_s( scale, temp ), 3 ); - } - ELSE - { - tmp1 = sub( norm_s( scale ), 1 ); - tmp2 = norm_s( temp ); - scale = div_s( shl( scale, tmp1 ), shl( temp, tmp2 ) ); - scale = shr( scale, add( sub( tmp1, tmp2 ), 3 ) ); - } - } - ELSE - { - scale = 0; - move16(); - } + tmp = i_mult( j, LPC_SHB_ORDER + 1 ); + /* convert LSPs to LP coefficients */ + E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); + /* Bring the LPCs to Q12 */ + Copy_Scale_sig( lpc_shb_sf + tmp, lpc_shb_sf + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf[tmp] ), 2 ) ); } } + /*ELSE*/ + { + /* for 13.2 and 16.4kbps */ + E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb[0] ), 2 ) ); /* Q12 */ + } - hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; + /* Save the SWB LSP values from current frame for interpolation */ + Copy( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); + /* lsp_shb_2_fx in Q15 */ + + /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ + hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; + move32(); + hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; + move32(); + hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; + move16(); + hBWE_TD->prev_mixFactors_fx = mixFactors; move16(); + /* SWB CNG/DTX - update memories */ + if ( st_fx->hTdCngDec != NULL ) { - Word64 prev_ener_shb64 = 0; - move64(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ - } - L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); + Copy( st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ + Copy( lsf_shb, st_fx->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ } - /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ - L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ - st_fx->prev_ener_shb_fx = 0; - move16(); + /* vind = (short)(mixFactors*8.0f); */ + vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ + /* i: mixFactors in Q15 */ + /* o: vind in Q0 */ - IF( L_prev_ener_shb != 0 ) - { - exp = norm_l( L_prev_ener_shb ); - tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); - exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); + /* Determine formant PF strength */ + formant_fac = swb_formant_fac_fx( lpc_shb[1], &hBWE_TD->tilt_mem_fx ); + /* o: formant_fac in Q15 */ - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - move16(); + /* -------- start of memory rescaling -------- */ + /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ + Lmax = 0; + move32(); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ - L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ - tmp = 0; - move16(); - IF( L_tmp != 0 ) + Q_bwe_exc = norm_l( Lmax ); + if ( Lmax == 0 ) { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); + Q_bwe_exc = 31; + move16(); + } + Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ + find_max_mem_dec( st_fx, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ + + tmp = add( st_fx->prev_Q_bwe_exc, n_mem ); + if ( GT_16( Q_bwe_exc, tmp ) ) + { + Q_bwe_exc = tmp; + move16(); } - set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn2 ); + sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); IF( sc != 0 ) { - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); - move16(); - } + rescale_genSHB_mem_dec( st_fx, sc ); + } - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); - move32(); - } - } - IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); - } - IF( EQ_32( st_fx->output_Fs, 16000 ) ) + /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); + + 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 ); + + /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); + + /* save the previous Q factor (32-bit) of the buffer */ + st_fx->prev_Q_bwe_exc = Q_bwe_exc; + move16(); + + Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ + + /* -------- end of rescaling memories -------- */ + Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; + move16(); + + IF( GT_32( st_fx->total_brate, ACELP_32k ) ) + { + FOR( j = 0; j < 4; j++ ) { - Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); + Copy( lpc_shb, &lpc_shb_sf[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); } } - /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ - /* o: error in (Qx) */ - GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); + /* 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, 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 ); - /* resample SHB synthesis (if needed) and scale down */ - synth_scale_fx = 32767; - move16(); /* 1.0 in Q15 */ - if ( EQ_16( st_fx->codec_mode, MODE1 ) ) + *Q_white_exc = Q_bwe_exc_fb; + move16(); + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - synth_scale_fx = 29491; - move16(); /* 0.9 in Q15 */ + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + move16(); + } + ELSE + { + /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. + 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ + hBWE_TD->prev_Q_bwe_exc_fb = 51; + move16(); + } + /* rescale the TBE post proc memory */ + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); + move16(); + } + + FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) + { + /* TD BWE post-processing */ + PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac ); + } + Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ + + tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 ); + prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) + { + prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ + curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + } + + if ( GT_16( voice_factors[0], 24576 /*0.75f Q15*/ ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ + } + + Lscale = root_a_over_b_fx( curr_pow, shl( Q_bwe_exc, 1 ), prev_pow, shl( Q_bwe_exc, 1 ), &exp ); + + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) + { + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); + } + IF( exp < 0 ) + { + Lscale = L_shl( Lscale, exp ); + exp = 0; + move16(); + } + /* + code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues + thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations + */ + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + { + temp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ + temp = sub( 32767 /*1.0f Q15*/, temp ); + Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); + } + } + ELSE + { + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + { + temp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ + temp = sub( 32767 /*1.0f Q15*/, temp ); + Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); + } } - IF( EQ_32( st_fx->output_Fs, 48000 ) ) + /* Update SHB excitation */ + Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ + + l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; + L_ener = 0; + move32(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - IF( EQ_32( st_fx->extl, FB_TBE ) ) + L_tmp = 0; + move32(); + ener_tmp[i] = 0; + move32(); { - tmp = norm_l( GainFrame ); - if ( GainFrame == 0 ) + Word64 tmp64 = 0; + move64(); + FOR( j = 0; j < l_subframe_fx; j++ ) { - tmp = 31; - move16(); + tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )], shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )] ); /* 2*Q_bwe_exc */ } - L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ + L_tmp = W_sat_l( tmp64 ); + } - tmp1 = 0; + L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ + IF( L_tmp != 0 ) + { + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + ener_tmp[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ + move32(); + L_ener = L_add_sat( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ + } + } + ener = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ + /* WB/SWB bandwidth switching */ + IF( st_fx->bws_cnt > 0 ) + { + ener = mult( ener, 11587 ); + /*bandwidth switching should be updated*/ + if ( GT_16( st_fx->tilt_swb_fx, 16384 ) ) + { + st_fx->prev_fractive = 1; move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) + } + + IF( is_fractive == 0 ) + { + IF( GT_16( st_fx->tilt_wb_fx, 2048 ) ) /*assuming st_fx->tilt_wb_fx in Q11*/ { - Word16 idx = 0; - IF( i != 0 ) - { - idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); - } - L_tmp1 = Mult_32_16( L_tmp, GainShape[idx] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + st_fx->tilt_wb_fx = 2048; move16(); - tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); } - - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ - move16(); - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) + ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 ) ) { - tmp = 15; + st_fx->tilt_wb_fx = 1024; move16(); } - - FOR( i = 0; i < L_FRAME16k; i++ ) + test(); + if ( EQ_16( st_fx->prev_fractive, 1 ) && GT_16( st_fx->tilt_wb_fx, 1024 ) ) { - White_exc16k[i] = shl( White_exc16k[i], sub( tmp, 1 ) ); + st_fx->tilt_wb_fx = 1024; move16(); } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); - move16(); } - - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + ELSE { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( GT_16( st_fx->tilt_wb_fx, 8192 ) ) { - error[i] = mult_r( error[i], synth_scale_fx ); + IF( st_fx->prev_fractive == 0 ) + { + st_fx->tilt_wb_fx = 8192; + move16(); + } + ELSE + { + st_fx->tilt_wb_fx = 16384; + move16(); + } + } + ELSE + { + st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); move16(); } } - interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); - } - ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) - { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + IF( ener != 0 ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + L_tmp = L_shl( L_mult0( ener, st_fx->tilt_wb_fx ), sub( st_fx->Q_syn2, 14 ) ); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ + exp_ener = norm_s( ener ); + tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ + + test(); + IF( GT_32( L_tmp, st_fx->enerLH_fx ) ) /*st_fx->Q_syn2*/ { - synth[i] = mult_r( synth_scale_fx, error[i] ); - move16(); /*Qx*/ + st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ + move16(); + /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ } - } - ELSE - { - Copy( error, synth, L_FRAME32k ); - } - } - ELSE IF( EQ_32( st_fx->output_Fs, 16000 ) ) - { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) + ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) { - error[i] = mult_r( error[i], synth_scale_fx ); + st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ move16(); + /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } + L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ + GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + } + ELSE + { + GainFrame_prevfrm_fx = 0; + move32(); } - Decimate_allpass_steep_fx( error, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); - } - - /* Update previous frame parameters for FEC */ - Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; - move16(); - - if ( !st_fx->bfi ) - { - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ - move16(); - } - } - ELSE - { - IF( !st_fx->bfi ) - { - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; - move16(); - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ - move16(); - } - } - - hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; - move32(); - hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; - move32(); - *Q_synth = Q_bwe_exc; - move16(); - hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; - move16(); - hBWE_TD->prev_Qx = Q_bwe_exc; - move16(); - - return; -} - -static void gradientGainShape( - Decoder_State *st_fx, - Word16 *GainShape, - Word32 *GainFrame ) -{ - Word16 i, j, tmp; - Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; - Word16 GainGrad0[3]; - Word16 GainGrad1[3]; - Word16 GainGradFEC[4]; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ - FOR( j = 0; j < 3; j++ ) - { - GainGrad0[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 1], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j], 1 ) ); - move16(); /* Q14 */ - GainGrad1[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 5], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j + 4], 1 ) ); - move16(); /* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); - move16(); /* Q14 */ - } - - /* gradient for the first gainshape */ - test(); - test(); - test(); - IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || - ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) - { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); - move16(); /* Q14 */ - } - ELSE - { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); - move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); - move16(); /* Q14 */ - } - - /* get the first gainshape template */ - test(); - test(); - IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) - { - GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), GainGradFEC[0] ); - move16(); - } - ELSE IF( GainGradFEC[0] > 0 ) - { - GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); - move16(); /* Q14 */ - } - ELSE - { - GainShapeTemp[0] = shr( hBWE_TD->GainShape_Delay_fx[7], 1 ); - move16(); /* Q14 */ - } - - /*Get the second the third and the fourth gainshape template*/ - - tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ - tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ - - test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) ) - { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + IF( EQ_16( is_fractive, 1 ) ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); - move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); - move16(); + GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 10 ); } - } - ELSE - { + ELSE + { + GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 8 ); + } + test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) ) + IF( EQ_16( s_and( is_fractive, st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); - move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); - move16(); /* Q14 */ - } + GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ } ELSE { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + test(); + test(); + test(); + test(); + IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st_fx->prev_fractive ) == 0 ) ) { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); - move16(); - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); - move16(); + GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); + } + ELSE + { + test(); + IF( ( is_fractive == 0 ) && EQ_16( st_fx->prev_fractive, 1 ) ) + { + L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ + L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ + GainFrame = L_add( Mult_32_32( GainFrame, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */ + } + ELSE + { + GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame ), 1 ) ); /* 18 */ + } } } - } - /* Get the gainshape and gain frame for the current frame*/ - test(); - test(); - test(); - IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) ) + GainFrame = Mult_32_16( GainFrame, i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ) ); /*Q18*/ + } + ELSE { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + if ( st_fx->bws_cnt1 > 0 ) { - FOR( j = 0; j < 4; j++ ) - { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ + GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ + } + IF( GE_16( st_fx->nbLostCmpt, 1 ) ) + { + ener = s_max( 1, ener ); + exp_ener = norm_s( ener ); + tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp)*/ + prev_ener_ratio_fx = L_shr_sat( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ + } - IF( GT_16( 8192, tmp ) ) + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) + { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->clas_dec != UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && + ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) + { + IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ { - GainShape[i * 4 + j] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame, 19661 ) ); /*18*/ + } + ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame ) ) + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); } ELSE { - GainShape[i * 4 + j] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); + } + + test(); + IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) + { + exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); + tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ + tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/ + tmp = extract_h( L_shl( L_mult0( tmp, st_fx->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */ + GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } } + ELSE IF( ( ( st_fx->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); + } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); - move16(); - } - ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { - FOR( j = 0; j < 4; j++ ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) { - IF( LT_16( GainShapeTemp[i], 16384 ) ) + test(); + IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); - move16(); + GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ } ELSE { - GainShape[i * 4 + j] = 32767; - move16(); + GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ + } + } + ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) + { + test(); + IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ); + } + ELSE + { + GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); - move16(); } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) + st_fx->prev_fractive = is_fractive; + move16(); + + /* Adjust the subframe and frame gain of the synthesized shb signal */ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + /* pitch = 0.25f*sum_s(pitch_buf, 4); */ + L_tmp = L_mult( pitch_buf[0], 8192 ); + FOR( i = 1; i < NB_SUBFR; i++ ) { - FOR( j = 0; j < 4; j++ ) + L_tmp = L_mac( L_tmp, pitch_buf[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */ + } + pitch_fx = round_fx( L_tmp ); /* Q6 */ + } + ELSE + { + /* pitch_fx = 0.2f*sum_s(pitch_buf, 5); */ + L_tmp = L_mult( pitch_buf[0], 6554 ); + FOR( i = 1; i < NB_SUBFR16k; i++ ) + { + L_tmp = L_mac( L_tmp, pitch_buf[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */ + } + pitch_fx = round_fx( L_tmp ); /* Q6 */ + } + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->prev_coder_type, coder_type ) && NE_16( coder_type, UNVOICED ) ) || ( LE_32( st_fx->total_brate, ACELP_16k40 ) && ( EQ_16( st_fx->prev_coder_type, coder_type ) || ( EQ_16( st_fx->prev_coder_type, VOICED ) && EQ_16( coder_type, GENERIC ) ) || ( EQ_16( st_fx->prev_coder_type, GENERIC ) && EQ_16( coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st_fx->extl, FB_TBE ) ) + { + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + GainShape_tmp[i] = GainShape[i * 4]; /* Q15 */ + move16(); + } + + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ + L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ + L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ + tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); + L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ + IF( GT_32( L_tmp1, L_tmp2 ) ) { - GainShape[add( i * 4, j )] = GainShapeTemp[i]; + /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ + /* tmp = L_tmp2/ener_tmp_fx[i]*/ + L_tmp = L_tmp2; + move32(); + if ( L_tmp2 < 0 ) + { + L_tmp = L_negate( L_tmp2 ); + } + + expb = norm_l( L_tmp ); + fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); + expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ + + expa = norm_l( ener_tmp[i] ); + fraca = extract_h( L_shl( ener_tmp[i], expa ) ); + expa = sub( 30, expa ); + + scale = shr( sub( fraca, fracb ), 15 ); + fracb = shl( fracb, scale ); + expb = sub( expb, scale ); + + tmp = div_s( fracb, fraca ); + exp = sub( sub( expb, expa ), 1 ); + tmp = shl( tmp, exp ); + GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ move16(); } + + hBWE_TD->prev_ener_fx = ener_tmp[i]; + move32(); + hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; + move16(); + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; + move16(); + } + FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) + { + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + GainShape[i] = GainShape_tmp[idx]; + move16(); } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); - move16(); } ELSE { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - IF( LT_16( GainShapeTemp[i], 16384 ) ) - { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); - move16(); - } - ELSE - { - GainShape[i * 4 + j] = 32767; - move16(); - } - } - } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; move16(); } - *GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ - move32(); -} - -/*-------------------------------------------------------------------* - * Dequant_lower_LSF() - * - * Dequantized the lower LSFs - *-------------------------------------------------------------------*/ + /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; + move16(); -static void Dequant_lower_LSF_fx( - const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs Q15*/ -) -{ - Word16 i; + /* Scale the shaped excitation */ + ScaleShapedSHB_fx( SHB_OVERLAP_LEN, + shaped_shb_excitation, /* i/o: Q_bwe_exc */ + hBWE_TD->syn_overlap_fx, + GainShape, /* Q15 */ + GainFrame, /* Q18 */ + window_shb_fx, + subwin_shb_fx, + &Q_bwe_exc, &Qx, n_mem3, hBWE_TD->prev_Q_bwe_syn2 ); - lsf_q[0] = lsf_q_cb_fx[0][lsf_idx[0]]; + max = 0; move16(); - FOR( i = 1; i < NUM_Q_LSF; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ - move16(); + max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ } - return; -} - -/*-------------------------------------------------------------------* - * Map_higher_LSF() - * - * Map the higher LSFs from the lower LSFs - *-------------------------------------------------------------------*/ - -static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ - const Word16 m, /* i : Mirroring point Q15*/ - const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ -) -{ - Word16 lsf_map[NUM_MAP_LSF]; - Word16 grid[NUM_MAP_LSF]; - Word16 last_q_lsf; - Word16 lsf_smooth[NUM_MAP_LSF]; - Word16 offset; - Word16 i; - Word16 scale; - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) + IF( max == 0 ) { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ + curr_frame_pow = 0; + move16(); + n = 0; move16(); } - - IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) + ELSE { - offset = lsf_map[0]; /*Q15*/ + n = norm_s( max ); + max = 0; move16(); - scale = div_s( sub( MAX_LSF_FX, m ), m ); - FOR( i = 0; i < NUM_MAP_LSF; i++ ) + FOR( i = 0; i < L_FRAME16k; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ + shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ move16(); } - } - - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ - move16(); - scale = sub( MAX_LSF_FX, last_q_lsf ); - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ - move16(); + curr_frame_pow = 0; + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ + curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ + } } + curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - FOR( i = 0; i < NUM_MAP_LSF; i++ ) + + tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); + IF( tmp > 0 ) /* shifting prev */ { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ + IF( GT_16( tmp, 32 ) ) + { + hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); + move16(); + tmp = 32; + move16(); + } + hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); + move32(); + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) + ELSE /* shifting curr */ { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ + IF( LT_16( tmp, -32 ) ) + { + curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); + tmp = -32; + move16(); + } + curr_frame_pow = L_shr( curr_frame_pow, -tmp ); + curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } - - return; -} - - -static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ - const Word16 m_idx, /* i : Mirror point index Q0 */ - Word16 *m /* i : Mirroring point Q15*/ -) -{ - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ - move16(); - - return; -} - - -static Word16 dotp_loc( - const Word16 x[], /* i : vector x[] Qx */ - const Word32 y[], /* i : vector y[] Qy */ - const Word16 n /* i : vector length */ -) -{ - 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++ ) + test(); + IF( !st_fx->bfi && st_fx->prev_bfi ) { - suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ - } - suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - - return extract_h( suma ); /*Qx + Qy - 16*/ -} + L_tmp = L_shr( curr_frame_pow, 4 ); + L_tmp = Mult_32_16( L_tmp, 17476 ); -void ivas_dequantizeSHBparams_fx_9_1( - Decoder_State *st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16 *Q_lsf, /* o : SHB LSF from de-quantization Q15*/ - Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ - Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ - Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15 */ - Word16 *Q_shb_res_gshape, /* o : Q14 */ - Word16 *Q_mixFactors, /* o : Q15 */ - Word16 *MSFlag ) -{ - Word16 i, j, idxLSF, idxSubGain, idxFrameGain; - Word16 Q_combined_gains[NUM_SHB_SUBFR / 4]; - Word16 lsf_q[LPC_SHB_ORDER]; - Word16 lsf_idx[NUM_Q_LSF]; - Word16 m_idx, grid_idx; - Word16 m; - Word32 L_tmp; - Word16 tmp, frac, exp; - Word16 idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; - Word16 temp_shb_ener_sf_fx; - TD_BWE_DEC_HANDLE hBWE_TD; + test(); + test(); + IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && + ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st_fx->prev_coder_type, UNVOICED ) ) + { + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - UWord32 Idx_lvq; - Word16 Idx, Idx_pred; - Word16 num_bits_lvq; - Word16 out[LATTICE_DIM]; - const Word16 *cb_stage; - Word16 predictor_bits; - Word16 nbits = NUM_BITS_SHB_MSLVQ; - move16(); - hBWE_TD = st_fx->hBWE_TD; + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ + } + ELSE + { + scale = temp = 32767; + move16(); /*Q15*/ + } + FOR( j = 0; j < 8; j++ ) + { + GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); + move16(); + GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); + move16(); + FOR( i = 0; i < L_FRAME16k / 8; i++ ) + { + shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )], scale ); + move16(); + } - /* LSFs */ + IF( temp > 0 ) + { + /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) + and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ + IF( LT_16( scale, temp ) ) + { + scale = div_s( scale, temp ); + } + ELSE + { + scale = 32767; + move16(); + } + } + ELSE + { + scale = 0; + move16(); + } + } + } - IF( EQ_16( extl, WB_TBE ) ) + /* adjust the FEC frame energy */ + IF( st_fx->bfi ) { - IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) + scale = temp = 4096; + move16(); /*Q12*/ + + IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && + NE_16( st_fx->prev_coder_type, UNVOICED ) && + ( st_fx->last_good != UNVOICED_CLAS ) ) { - idxFrameGain = hBWE_TD->gFrame_WB; - move16(); - idxLSF = hBWE_TD->lsf_WB; - move16(); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } - ELSE + ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); - idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_LBR_WB_LSF ); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } - - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); - set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - Copy32( SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1 ); } - ELSE + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { - *uv_flag = (Word16) get_next_indice_fx( st_fx, 1 ); - move16(); - idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain ); - idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_WB_LSF ); - Copy( wb_bwe_lsfvq_cbook_8bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_WB ), Q_lsf, LPC_SHB_ORDER_WB ); - Copy( HBCB_SubGain5bit_fx + i_mult( idxSubGain, NUM_SHB_SUBFR / 4 ), Q_combined_gains, NUM_SHB_SUBFR / 4 ); - - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + test(); + test(); + test(); + test(); + test(); + IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) { - - L_tmp = L_mult( Q_combined_gains[i], 21771 ); /*Q26 0.166096 in Q17 */ - L_tmp = L_shr( L_tmp, 10 ); - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ - move16(); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } - - FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) + ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && + ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { - Q_subgain[i] = Q_combined_gains[i / 2]; // Q15 - move16(); - Q_subgain[i + 1] = Q_combined_gains[i / 2]; // Q15 - move16(); + L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); + L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ + scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } - - /* frame gain */ - Copy32( SHBCB_FrameGain64_fx + idxFrameGain, Q_framegrain, 1 ); } - } - ELSE /* SWB TBE DEC */ - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + FOR( j = 0; j < 8; j++ ) { - idxSubGain = hBWE_TD->idxSubGains; - move16(); - idxFrameGain = hBWE_TD->idxFrameGain; + GainShape[2 * j] = shl_sat( mult_r( GainShape[2 * j], scale ), 3 ); + move16(); /* 15 +12 +3-15 =15*/ + GainShape[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape[add( 2 * j, 1 )], scale ), 3 ); move16(); - } - ELSE - { - idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + FOR( i = 0; i < 40; i++ ) { - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); + shaped_shb_excitation[add( i, j * 40 )] = shl_sat( mult_r( shaped_shb_excitation[add( i, j * 40 )], scale ), 3 ); + move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ + } + + IF( temp > 0 ) + { + IF( LT_16( scale, temp ) ) + { + scale = shr( div_s( scale, temp ), 3 ); + } + ELSE + { + tmp1 = sub( norm_s( scale ), 1 ); + tmp2 = norm_s( temp ); + scale = div_s( shl( scale, tmp1 ), shl( temp, tmp2 ) ); + scale = shr( scale, add( sub( tmp1, tmp2 ), 3 ) ); + } } ELSE { - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + scale = 0; + move16(); } } + } - /* Multi Source Flag */ - test(); - test(); - IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) + hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; + move32(); + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; + move16(); + + { + Word64 prev_ener_shb64 = 0; + move64(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - *MSFlag = (Word16) get_next_indice_fx( st_fx, STEREO_ICBWE_MSFLAG_BITS ); - move16(); + prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ } - ELSE + L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); + } + + /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ + L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ + st_fx->prev_ener_shb_fx = 0; + move16(); + + IF( L_prev_ener_shb != 0 ) + { + exp = norm_l( L_prev_ener_shb ); + tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); + exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ + move16(); + } + /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ + L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ + tmp = 0; + move16(); + IF( L_tmp != 0 ) + { + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ + } + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ + + /* rescale the memories if Q_bwe_exc is different from previous frame */ + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn2 ); + IF( sc != 0 ) + { + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - *MSFlag = 0; + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); move16(); } - IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; - move16(); - } - ELSE + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - idx_shb_fr_gain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); + move32(); } - temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ + } + IF( EQ_32( st_fx->output_Fs, 48000 ) ) + { + Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); + } + IF( EQ_32( st_fx->output_Fs, 16000 ) ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); + } + } + /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ + /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ + /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ + /* o: error in (Qx) */ + GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - /* *Q_shb_ener_sf = 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 Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2( 14, frac ); - *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /*exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - move32(); + Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); + + /* resample SHB synthesis (if needed) and scale down */ + synth_scale_fx = 32767; + move16(); /* 1.0 in Q15 */ + if ( EQ_16( st_fx->codec_mode, MODE1 ) ) + { + synth_scale_fx = 29491; + move16(); /* 0.9 in Q15 */ + } + + IF( EQ_32( st_fx->output_Fs, 48000 ) ) + { + IF( EQ_32( st_fx->extl, FB_TBE ) ) + { + tmp = norm_l( GainFrame ); + if ( GainFrame == 0 ) + { + tmp = 31; + move16(); + } + L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ - FOR( i = 0; i < 5; i++ ) + tmp1 = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; - move16(); - } - ELSE + Word16 idx = 0; + IF( i != 0 ) { - idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); - move16(); + idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); } - Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); + L_tmp1 = Mult_32_16( L_tmp, GainShape[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ move16(); - /* o: Q_shb_res_gshape in Q14 */ + tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ + move16(); + tmp = norm_s( tmp1 ); + if ( tmp1 == 0 ) { - idx_mixFac = hBWE_TD->idx_mixFac; + tmp = 15; move16(); } - ELSE + + FOR( i = 0; i < L_FRAME16k; i++ ) { - idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); + White_exc16k[i] = shl( White_exc16k[i], sub( tmp, 1 ) ); + move16(); } - *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); move16(); - /* o: Q_mixFactors in Q15 */ } - ELSE + + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - *Q_shb_ener_sf = L_deposit_l( 0 ); - move32(); - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + FOR( i = 0; i < L_FRAME32k; i++ ) { - idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); - *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); + error[i] = mult_r( error[i], synth_scale_fx ); move16(); } - ELSE + } + + interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); + } + ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) { - *Q_mixFactors = 0; + synth[i] = mult_r( synth_scale_fx, error[i] ); + move16(); /*Qx*/ + } + } + ELSE + { + Copy( error, synth, L_FRAME32k ); + } + } + ELSE IF( EQ_32( st_fx->output_Fs, 16000 ) ) + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error[i] = mult_r( error[i], synth_scale_fx ); move16(); } - set16_fx( Q_shb_res_gshape, 0, 5 ); } - /* LSFs */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) && EQ_16( st_fx->codec_mode, MODE1 ) ) + Decimate_allpass_steep_fx( error, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); + } + + /* Update previous frame parameters for FEC */ + Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + { + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; + move16(); /*Q18*/ + hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; + move16(); + + if ( !st_fx->bfi ) { - set16_fx( lsf_idx, 0, 5 ); - lsf_idx[0] = (Word16) get_next_indice_fx( st_fx, 8 ); + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); - grid_idx = 0; + } + } + ELSE + { + IF( !st_fx->bfi ) + { + hBWE_TD->GainFrame_prevfrm_fx = GainFrame; + move16(); /*Q18*/ + hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - m_idx = 0; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); + } + } - Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); + hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; + move32(); + hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; + move32(); + *Q_synth = Q_bwe_exc; + move16(); + hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; + move16(); + hBWE_TD->prev_Qx = Q_bwe_exc; + move16(); + + return; +} + +static void gradientGainShape( + Decoder_State *st_fx, + Word16 *GainShape, + Word32 *GainFrame ) +{ + Word16 i, j, tmp; + Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; + Word16 GainGrad0[3]; + Word16 GainGrad1[3]; + Word16 GainGradFEC[4]; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + + /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ + FOR( j = 0; j < 3; j++ ) + { + GainGrad0[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 1], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j], 1 ) ); + move16(); /* Q14 */ + GainGrad1[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 5], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j + 4], 1 ) ); + move16(); /* Q14 */ + GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); + move16(); /* Q14 */ + } + + /* gradient for the first gainshape */ + test(); + test(); + test(); + IF( ( ( GT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( GT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) || + ( ( LT_16( shr( GainGrad1[2], 1 ), GainGrad1[1] ) ) && ( LT_16( shr( GainGrad1[1], 1 ), GainGrad1[0] ) ) ) ) + { + GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); + move16(); /* Q14 */ + } + ELSE + { + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + move16(); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + move16(); /* Q14 */ + } + + /* get the first gainshape template */ + test(); + test(); + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) + { + GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), GainGradFEC[0] ); + move16(); + } + ELSE IF( GainGradFEC[0] > 0 ) + { + GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + move16(); /* Q14 */ + } + ELSE + { + GainShapeTemp[0] = shr( hBWE_TD->GainShape_Delay_fx[7], 1 ); + move16(); /* Q14 */ + } + + /*Get the second the third and the fourth gainshape template*/ + + tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ + tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ + + test(); + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) ) + { + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + { + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); + move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + move16(); } - ELSE IF( ( st_fx->rf_flag == 0 ) && !( ( ( st_fx->element_mode == EVS_MONO ) && EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && st_fx->rf_flag_last ) ) ) ) ) + } + ELSE + { + test(); + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) ) { - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { - /* read multi-stage LVQ quantizer */ - IF( GE_16( nbits, 19 ) ) - { - cb_stage = cb_LSF_BWE_fx[0]; - move16(); - } - ELSE - { - cb_stage = cb_LSF_BWE_fx[1]; - move16(); - } - set16_fx( lsf_q, 0, LPC_SHB_ORDER ); - - /* VQ part */ - num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; - Idx = get_next_indice_fx( st_fx, num_bits_lvq ); - v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); - - /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); - predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; - Idx_pred = 0; + GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); + move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + move16(); /* Q14 */ + } + } + ELSE + { + FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + { + GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); move16(); + GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); + move16(); + } + } + } - IF( EQ_16( num_bits_lvq, 16 ) ) - { - /* MSLVQ part */ - Idx_lvq = L_add( get_next_indice_fx( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice_fx( st_fx, 1 ), 15 ) ); - deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); - } - ELSE - { - /* MSLVQ part */ - Idx_lvq = get_next_indice_fx( st_fx, num_bits_lvq ); - deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, extract_l( LT_16( nbits, 19 ) ) ); - } - - /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ - v_add_16( lsf_q, out, lsf_q, LATTICE_DIM ); /* quantized mean removed data for first 8 dim*/ + /* Get the gainshape and gain frame for the current frame*/ + test(); + test(); + test(); + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ - /* predict last 2 components */ - IF( predictor_bits == 0 ) + IF( GT_16( 8192, tmp ) ) { - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM ); - move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM ); - move16(); + GainShape[i * 4 + j] = shl( tmp, 2 ); + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); - move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); - move16(); - } - - IF( LT_16( nbits, NUM_BITS_SHB_MSLVQ ) ) - { - Idx_pred = (Word16) get_next_indice_fx( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); + GainShape[i * 4 + j] = 32767; + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } - - v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); - v_sort( lsf_q, 0, LPC_SHB_ORDER - 1 ); } - ELSE + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); + } + ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) { - /* LSFs */ - test(); - test(); - test(); - IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = hBWE_TD->lsf_idx[i]; - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); - move16(); - } - } - } - Dequant_lower_LSF_fx( lsf_idx, lsf_q ); - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - m_idx = hBWE_TD->m_idx; + GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); - } - - Dequant_mirror_point_fx( lsf_q, m_idx, &m ); - - /* safety check in case of bit errors */ - IF( GT_16( m, MAX_LSF_FX ) ) - { - st_fx->BER_detect = 1; - move16(); - m = MAX_LSF_FX - 1; + GainShape[i * 4 + j] = 32767; move16(); } - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + } + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); + } + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + GainShape[add( i * 4, j )] = GainShapeTemp[i]; + move16(); + } + } + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + move16(); + } + ELSE + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + FOR( j = 0; j < 4; j++ ) + { + IF( LT_16( GainShapeTemp[i], 16384 ) ) { - grid_idx = hBWE_TD->grid_idx; + GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); - } - - Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); - } - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /* safety check in case of bit errors */ - IF( GT_16( lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX ) ) - { - st_fx->BER_detect = 1; - move16(); - lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; + GainShape[i * 4 + j] = 32767; move16(); } - Q_lsf[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); - move16(); } } - ELSE + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + move16(); + } + + *GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ + move32(); +} + +/*-------------------------------------------------------------------* + * Dequant_lower_LSF() + * + * Dequantized the lower LSFs + *-------------------------------------------------------------------*/ + + +static void Dequant_lower_LSF_fx( + const Word16 lsf_idx[], /* i : LSF indices */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ +) +{ + Word16 i; + + lsf_q[0] = lsf_q_cb_fx[0][lsf_idx[0]]; + move16(); + FOR( i = 1; i < NUM_Q_LSF; i++ ) + { + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ + move16(); + } + + return; +} + +/*-------------------------------------------------------------------* + * Map_higher_LSF() + * + * Map the higher LSFs from the lower LSFs + *-------------------------------------------------------------------*/ + +static void Map_higher_LSF_fx( + Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) +{ + Word16 lsf_map[NUM_MAP_LSF]; + Word16 grid[NUM_MAP_LSF]; + Word16 last_q_lsf; + Word16 lsf_smooth[NUM_MAP_LSF]; + Word16 offset; + Word16 i; + Word16 scale; + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ + move16(); + } + + IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) + { + offset = lsf_map[0]; /*Q15*/ + move16(); + scale = div_s( sub( MAX_LSF_FX, m ), m ); + FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - set16_fx( lsf_idx, 0, 5 ); - Copy( hBWE_TD->lsf_idx, lsf_idx, 5 ); - grid_idx = 0; - move16(); - m_idx = 0; + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); - Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); } + } + + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ + move16(); + scale = sub( MAX_LSF_FX, last_q_lsf ); + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ + move16(); + } + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ + move16(); + } + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ + move16(); + } + + return; +} + - space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); +static void Dequant_mirror_point_fx( + const Word16 lsf_q[], /* i/o : Quantized lower LSFs Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) +{ + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ + move16(); - /* Dequantize subgain indices */ - j = i_mult( idxSubGain, NUM_SHB_SUBGAINS ); - move16(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ + return; +} - L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 12 ); - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_subgain[i] = shl( tmp, add( exp, 1 ) ); /*Q15*/ - move16(); - } - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) - { - Word16 idx = 0; - move16(); - IF( i != 0 ) - { - idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); - } - Q_subgain[i] = Q_subgain[idx]; - move16(); - } +static Word16 dotp_loc( + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ +) +{ + Word16 i; + Word32 suma; + Word16 guarded_bits = find_guarded_bits_fx( n ); - /* Frame gain */ - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - *Q_framegrain = L_mac( SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX ); - move32(); - } - ELSE - { - *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); - move32(); - } /*Q18*/ - L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - move32(); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ + + FOR( i = 1; i < n; i++ ) + { + suma = L_add( suma, L_shr( Mpy_32_16_1( y[i], x[i] ), guarded_bits ) ); /*Qx + Qy - guarded_bits*/ } + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return; + return extract_h( suma ); /*Qx + Qy - 16*/ } -/*==========================================================================*/ -/* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Dequantize super highband spectral envolope */ -/* temporal gains and frame gain */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 extl i : extension layer */ -/* _Word32 extl_brate i : extensiuon layer bitrate */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *Q_lsf, o : SHB LSF from de-quantization Q15 */ -/* _Word16 *Q_subgain, o : SHB subframe gains from de-quantization Q15*/ -/* _Word32 *Q_framegrain o : SHB frame gain from de-quantization Q18 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ +/*-------------------------------------------------------------------* + * dequantizeSHBparams() + * + * Dequantize super highband spectral envolope, temporal gains and frame gain + *-------------------------------------------------------------------*/ -static void dequantizeSHBparams_fx_9_1( +static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ Word32 extl_brate, /* i : extensiuon layer bitrate */ @@ -4342,10 +3350,10 @@ static void dequantizeSHBparams_fx_9_1( Word16 *Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ Word32 *Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ Word16 *uv_flag, /* o : unvoiced flag*/ - Word32 *Q_shb_ener_sf, /* o : Q15*/ - Word16 *Q_shb_res_gshape, /* o : Q14*/ - Word16 *Q_mixFactors /* o : Q15*/ -) + Word32 *Q_shb_ener_sf, /* o : Q15 */ + Word16 *Q_shb_res_gshape, /* o : Q14 */ + Word16 *Q_mixFactors, /* o : Q15 */ + Word16 *MSFlag ) { Word16 i, j, idxLSF, idxSubGain, idxFrameGain; Word16 Q_combined_gains[NUM_SHB_SUBFR / 4]; @@ -4358,6 +3366,15 @@ static void dequantizeSHBparams_fx_9_1( Word16 idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; Word16 temp_shb_ener_sf_fx; TD_BWE_DEC_HANDLE hBWE_TD; + + UWord32 Idx_lvq; + Word16 Idx, Idx_pred; + Word16 num_bits_lvq; + Word16 out[LATTICE_DIM]; + const Word16 *cb_stage; + Word16 predictor_bits; + Word16 nbits = NUM_BITS_SHB_MSLVQ; + move16(); hBWE_TD = st_fx->hBWE_TD; /* LSFs */ @@ -4366,10 +3383,18 @@ static void dequantizeSHBparams_fx_9_1( { IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) { - idxFrameGain = hBWE_TD->gFrame_WB; - move16(); - idxLSF = hBWE_TD->lsf_WB; - move16(); + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idxFrameGain = hBWE_TD->gFrame_WB; + move16(); + idxLSF = hBWE_TD->lsf_WB; + move16(); + } + ELSE + { + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + idxLSF = (Word16) get_next_indice_fx( st_fx, NUM_BITS_LBR_WB_LSF ); + } Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -4400,9 +3425,9 @@ static void dequantizeSHBparams_fx_9_1( FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) { - Q_subgain[i] = Q_combined_gains[i / 2]; + Q_subgain[i] = Q_combined_gains[i / 2]; // Q15 move16(); - Q_subgain[i + 1] = Q_combined_gains[i / 2]; + Q_subgain[i + 1] = Q_combined_gains[i / 2]; // Q15 move16(); } @@ -4422,11 +3447,31 @@ static void dequantizeSHBparams_fx_9_1( ELSE { idxSubGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); + } + ELSE + { + idxFrameGain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + } } + /* Multi Source Flag */ test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + test(); + IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) + { + *MSFlag = (Word16) get_next_indice_fx( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + move16(); + } + ELSE + { + *MSFlag = 0; + move16(); + } + + IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) { IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { @@ -4440,126 +3485,218 @@ static void dequantizeSHBparams_fx_9_1( temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ - /* *Q_shb_ener_sf = 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 Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2( 14, frac ); - *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /* exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - move32(); + /* *Q_shb_ener_sf = 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 Q12+Q13+1 = Q26 */ + L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = Pow2( 14, frac ); + *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /*exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + move32(); + + FOR( i = 0; i < 5; i++ ) + { + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; + move16(); + } + ELSE + { + idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); + move16(); + } + Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], + 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ + 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ + ); + move16(); + /* o: Q_shb_res_gshape in Q14 */ + } + + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + idx_mixFac = hBWE_TD->idx_mixFac; + move16(); + } + ELSE + { + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); + } + *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); + move16(); + /* o: Q_mixFactors in Q15 */ + } + ELSE + { + *Q_shb_ener_sf = L_deposit_l( 0 ); + move32(); + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); + *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); + move16(); + } + ELSE + { + *Q_mixFactors = 0; + move16(); + } + set16_fx( Q_shb_res_gshape, 0, 5 ); + } + + /* LSFs */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) && EQ_16( st_fx->codec_mode, MODE1 ) ) + { + set16_fx( lsf_idx, 0, 5 ); + lsf_idx[0] = (Word16) get_next_indice_fx( st_fx, 8 ); + move16(); + grid_idx = 0; + move16(); + m_idx = 0; + move16(); + + Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); + } + ELSE IF( ( st_fx->rf_flag == 0 ) && !( ( ( st_fx->element_mode == EVS_MONO ) && EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && st_fx->rf_flag_last ) ) ) ) ) + { + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + /* read multi-stage LVQ quantizer */ + IF( GE_16( nbits, 19 ) ) + { + cb_stage = cb_LSF_BWE_fx[0]; + move16(); + } + ELSE + { + cb_stage = cb_LSF_BWE_fx[1]; + move16(); + } + set16_fx( lsf_q, 0, LPC_SHB_ORDER ); + + /* VQ part */ + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; + Idx = get_next_indice_fx( st_fx, num_bits_lvq ); + v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); + + /* MSLVQ part */ + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2] ); + predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; + Idx_pred = 0; + move16(); + + IF( EQ_16( num_bits_lvq, 16 ) ) + { + /* MSLVQ part */ + Idx_lvq = L_add( get_next_indice_fx( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice_fx( st_fx, 1 ), 15 ) ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); + } + ELSE + { + /* MSLVQ part */ + Idx_lvq = get_next_indice_fx( st_fx, num_bits_lvq ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, extract_l( LT_16( nbits, 19 ) ) ); + } + + /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ + v_add_16( lsf_q, out, lsf_q, LATTICE_DIM ); /* quantized mean removed data for first 8 dim*/ - FOR( i = 0; i < 5; i++ ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + /* predict last 2 components */ + IF( predictor_bits == 0 ) { - idx_res_gs[i] = hBWE_TD->idx_res_gs[i]; + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM ); + move16(); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM ); move16(); } ELSE { - idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); + Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); + move16(); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); move16(); } - Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); - move16(); - /* o: Q_shb_res_gshape in Q14 */ - } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - idx_mixFac = hBWE_TD->idx_mixFac; - move16(); + IF( LT_16( nbits, NUM_BITS_SHB_MSLVQ ) ) + { + Idx_pred = (Word16) get_next_indice_fx( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); + } + + v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); + v_sort( lsf_q, 0, LPC_SHB_ORDER - 1 ); } ELSE { - idx_mixFac = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); - } - *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); - move16(); - /* o: Q_mixFactors in Q15 */ - } - ELSE - { - *Q_shb_ener_sf = L_deposit_l( 0 ); - move32(); - *Q_mixFactors = 0; - move16(); - set16_fx( Q_shb_res_gshape, 0, 5 ); - } - - /* LSFs */ - - - test(); - test(); - test(); - test(); - test(); - IF( ( ( st_fx->rf_flag == 0 ) ) && !( ( EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && EQ_16( st_fx->rf_flag_last, 1 ) ) ) ) ) ) - - { - /* LSFs */ - test(); - test(); - test(); - IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + /* LSFs */ + test(); + test(); + test(); + IF( EQ_32( extl_brate, SWB_TBE_1k6 ) || EQ_32( extl_brate, FB_TBE_1k8 ) || EQ_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, FB_TBE_3k0 ) ) { - FOR( i = 0; i < NUM_Q_LSF; i++ ) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - lsf_idx[i] = hBWE_TD->lsf_idx[i]; - move16(); + FOR( i = 0; i < NUM_Q_LSF; i++ ) + { + lsf_idx[i] = hBWE_TD->lsf_idx[i]; + move16(); + } + } + ELSE + { + FOR( i = 0; i < NUM_Q_LSF; i++ ) + { + lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); + move16(); + } } } + Dequant_lower_LSF_fx( lsf_idx, lsf_q ); + + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + m_idx = hBWE_TD->m_idx; + move16(); + } ELSE { - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = (Word16) get_next_indice_fx( st_fx, lsf_q_num_bits[i] ); - move16(); - } + m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); } - } - Dequant_lower_LSF_fx( lsf_idx, lsf_q ); - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - m_idx = hBWE_TD->m_idx; - move16(); - } - ELSE - { - m_idx = (Word16) get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); - } + Dequant_mirror_point_fx( lsf_q, m_idx, &m ); - Dequant_mirror_point_fx( lsf_q, m_idx, &m ); + /* safety check in case of bit errors */ + IF( GT_16( m, MAX_LSF_FX ) ) + { + st_fx->BER_detect = 1; + move16(); + m = MAX_LSF_FX - 1; + move16(); + } - /* safety check in case of bit errors */ - IF( GT_16( m, MAX_LSF_FX ) ) - { - st_fx->BER_detect = 1; - move16(); - m = MAX_LSF_FX - 1; - move16(); - } + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + grid_idx = hBWE_TD->grid_idx; + move16(); + } + ELSE + { + grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); + } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - grid_idx = hBWE_TD->grid_idx; - move16(); - } - ELSE - { - grid_idx = (Word16) get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); + Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); } - - Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { /* safety check in case of bit errors */ @@ -4594,8 +3731,7 @@ static void dequantizeSHBparams_fx_9_1( { /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ - L_tmp = L_mult( SHBCB_SubGain5bit_fx[j], 27213 ); /*Q28 3.321928 in Q13 */ - j = add( j, 1 ); + L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 12 ); frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ @@ -4618,8 +3754,16 @@ static void dequantizeSHBparams_fx_9_1( } /* Frame gain */ - *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); /*Q18*/ - move32(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + *Q_framegrain = L_mac( SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX ); + move32(); + } + ELSE + { + *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); + move32(); + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); @@ -4630,70 +3774,19 @@ static void dequantizeSHBparams_fx_9_1( return; } + /*-------------------------------------------------------------------* * fb_tbe_dec() * * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ -void fb_tbe_dec_fx( - 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, - Word16 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word16 hb_synth_exp ) - -{ - Word16 i; - Word16 ratio = 0; - move16(); - Word32 fb_exc_energy = 0; - move32(); - Word16 fb_synth[L_FRAME48k]; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st->hBWE_TD; - - /* decode FB slope information */ - test(); - test(); - IF( EQ_16( st->extl, FB_TBE ) && !st->bfi ) - { - IF( EQ_16( st->codec_mode, MODE2 ) ) - { - i = hBWE_TD->idxGain; - move16(); - } - ELSE - { - i = (Word16) get_next_indice_fx( st, 4 ); - } - ratio = shl_sat( 1, i ); - } - ELSE IF( EQ_16( st->extl, FB_TBE ) && st->bfi ) - { - ratio = hBWE_TD->prev_fbbwe_ratio_fx; - move16(); - } - fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); - - /* FB TBE synthesis */ - synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp, - st->element_mode ); - - /* 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++ ) - { - hb_synth[i] = add_sat( hb_synth[i], fb_synth[i] ); - move16(); - } - return; -} -void fb_tbe_dec_ivas_fx( +void fb_tbe_dec_fx( 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, - Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ Word16 Q_fb_synth_ref, @@ -4754,17 +3847,29 @@ 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++ ) + 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 + { + 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,52 +4486,6 @@ static void calc_tilt_bwe_fx_loc( return; } -/*-------------------------------------------------------------------* - * swb_tbe_dec() - * - * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module - *-------------------------------------------------------------------*/ -static void rescale_genSHB_mem_dec_ivas( - Decoder_State *st_fx, - Word16 sf /*Q0*/ -) -{ - Word16 i; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - FOR( i = 0; i < 7; i++ ) - { - hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] = shl( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i], sf ); - move16(); - } - - /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/ - IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); - move16(); - } - } - - hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); - move32(); - - hBWE_TD->tbe_demph_fx = shl_r( hBWE_TD->tbe_demph_fx, sf ); - move16(); - hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); - move16(); - - return; -} static void find_max_mem_dec_m3( Decoder_State *st, @@ -5461,23 +4520,27 @@ static void find_max_mem_dec_m3( *n_mem3 = 15; move16(); } + + return; } + /*-------------------------------------------------------------------* - * ivas_swb_tbe_dec_fx() + * swb_tbe_dec_ivas_fx() * * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ -void ivas_swb_tbe_dec_fx( + +void swb_tbe_dec_ivas_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 +4608,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 +4856,8 @@ void ivas_swb_tbe_dec_fx( ELSE { /* de-quantization */ - 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 ); + 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 ); if ( hStereoICBWE != NULL ) { hStereoICBWE->MSFlag = MSFlag; @@ -6185,7 +5251,7 @@ void ivas_swb_tbe_dec_fx( sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc ); IF( sc != 0 ) { - rescale_genSHB_mem_dec_ivas( st, sc ); + rescale_genSHB_mem_dec( st, sc ); } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ @@ -6214,6 +5280,17 @@ void ivas_swb_tbe_dec_fx( move16(); Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + +#ifdef HARMONIZE_TBE2 + GenShapedSHBExcitation_ivas_fx( DEC, 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, + st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, + shb_res_gshape_fx, shb_res_dummy_fx, &vind, 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->total_brate, st->prev_bfi, + st->element_mode, st->flag_ACELP16k, nlExc16k_fx, NULL, mixExc16k_fx, NULL, st->extl_brate, MSFlag, + NULL, 0, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); +#else GenShapedSHBExcitation_ivas_dec_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, st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, @@ -6222,6 +5299,7 @@ void ivas_swb_tbe_dec_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->total_brate, st->prev_bfi, st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); +#endif *Q_white_exc = Q_bwe_exc_fb; move16(); diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 96ee58142430e2790f438dd817847e3566efc94f..07f356665e4204a5e43e3ec1e3778c21e72196e0 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index c13a8856500971c9c26f4a6b651728c2f4189672..adebdb7039093760ac8c8454f311dc2e72685e10 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include @@ -69,12 +69,6 @@ void tcq_core_LR_dec_fx( Word32 divider = 0; move32(); -#ifndef BASOP_NOGLOB_DECLARE_LOCAL - if ( Overflow == 1 ) - { - Overflow = 0; /* set overflow flag to zero before entering TCQ functions without any message */ - } -#endif /* initialization */ set16_fx( dpath, 0, 280 ); diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index 1a847c6a0dc39ba1d5fdbc8c48bc98b39a00029b..b688fa30ac8b2699478c85b8001ac715e2fdf78a 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index a5df034908245daa19050eef823a8701900c0bfc..44d18ccb2a4dda6daaee40b9b6266bf0fd4473e8 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -21,6 +21,119 @@ typedef Word32 ( *TLinearPredictionFilter )( Word16 order, Word16 const parCoeff /********************************/ /* Interface functions */ /********************************/ + + +#ifdef HARMONIZE_READ_DECODE_TNS +/*---------------------------------------------------------------------* + * ReadTnsData() + * + * + *---------------------------------------------------------------------*/ +void ReadTnsData_fx( + STnsConfig const *pTnsConfig, + Decoder_State *st, + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) +{ + Word16 start_bit_pos; + + move16(); + start_bit_pos = st->next_bit_pos; + + IF( GT_16( pTnsConfig->nMaxFilters, 1 ) ) + { + IF( pTnsConfig->allowTnsOnWhite ) + { + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) + { + ReadFromBitstream_fx( &tnsEnabledOnWhiteSWBTCX10BitMap, 1, st, &stream, pnSize ); + } + ELSE + { + ReadFromBitstream_fx( &tnsEnabledOnWhiteSWBTCX20BitMap, 1, st, &stream, pnSize ); + } + } + ELSE + { + + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) + { + ReadFromBitstream_fx( &tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize ); + } + ELSE + { + ReadFromBitstream_fx( &tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize ); + } + } + } + ELSE + { + ReadFromBitstream_fx( &tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize ); + } + + move16(); + *pnBits = sub( st->next_bit_pos, start_bit_pos ); +} + +/*---------------------------------------------------------------------* + * DecodeTnsData() + * + * + *---------------------------------------------------------------------*/ +Word16 DecodeTnsData_fx( + STnsConfig const *pTnsConfig, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ + STnsData *pTnsData ) +{ + Word16 result; + + ResetTnsData( pTnsData ); + + IF( GT_16( pTnsConfig->nMaxFilters, 1 ) ) + { + + IF( pTnsConfig->allowTnsOnWhite ) + { + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) + { + SetParameters_fx( &tnsEnabledOnWhiteSWBTCX10BitMap, 1, pTnsData, &stream, pnSize ); + } + ELSE + { + SetParameters_fx( &tnsEnabledOnWhiteSWBTCX20BitMap, 1, pTnsData, &stream, pnSize ); + } + } + ELSE + { + + IF( LT_16( pTnsConfig->iFilterBorders[0], 512 ) ) + { + SetParameters_fx( &tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize ); + } + ELSE + { + SetParameters_fx( &tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize ); + } + } + } + ELSE + { + SetParameters_fx( &tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize ); + } + + move16(); + result = FALSE; + if ( pTnsData->nFilters > 0 ) + { + move16(); + result = TRUE; + } + return result; +} +#else /*---------------------------------------------------------------------* * ReadTnsData() * @@ -216,3 +329,6 @@ Word16 DecodeTnsData_ivas_fx( return result; } + + +#endif // HARMONIZE_READ_DECODE_TNS diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index d098eaa15e4e9700ed11759342775554694c8c15..93a5ab064261ff067116cc0ae0b1a43c248c0735 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1,12 +1,9 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + 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] ) ); @@ -3098,7 +3095,15 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e + Word32 cnp; + Word16 cnp_e; + + cnp_e = norm_l( concealment_noise[i] ); + cnp = L_shl( concealment_noise[i], cnp_e ); + cnp = Mpy_32_32( cnp, cnp ); + cnp_e = shl( sub( *concealment_noise_exp, cnp_e ), 1 ); + + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, cnp, cnp_e, &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -3118,7 +3123,15 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e + Word32 cnp; + Word16 cnp_e; + + cnp_e = norm_l( concealment_noise[i] ); + cnp = L_shl( concealment_noise[i], cnp_e ); + cnp = Mpy_32_32( cnp, cnp ); + cnp_e = shl( sub( *concealment_noise_exp, cnp_e ), 1 ); + + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, cnp, cnp_e, &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 00d70785d74a4746fe648ac8c0477c447ff97693..8fb036d2adc76482f9a365e82ff5452b838bb138 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -13,26 +13,24 @@ *----------------------------------------------------------------------*/ static void tc_dec_fx( Decoder_State *st_fx, const Word16 L_frame, Word16 exc[], Word16 *T0, Word16 *T0_frac, const Word16 i_subfr, const Word16 tc_subfr, Word16 *position, Word16 bwe_exc[], Word16 *Q_exc ); /*======================================================================*/ -/* FUNCTION : transition_dec_fx() */ +/* FUNCTION : transition_dec_fx() */ /*----------------------------------------------------------------------*/ -/* PURPOSE : Principal function for TC decoding */ -/* */ +/* PURPOSE : Principal function for TC decoding */ +/* */ /*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ -/*-----------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* GLOBAL INPUT ARGUMENTS : */ +/* _ (Word16) L_frame : length of the frame Q0 */ +/* _ (Word16[]) pitch_buf_fx: floating pitch values for each subframe Q6*/ +/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ void transition_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -635,26 +633,24 @@ void transition_dec_fx( /*======================================================================*/ -/* FUNCTION : tc_dec_fx() */ +/* FUNCTION : tc_dec_fx() */ /*----------------------------------------------------------------------*/ -/* PURPOSE : Principal function for TC decoding */ -/* * Principal function for TC decoding. */ -/* * - constructs glottal codebook contribution */ -/* * - uses pitch sharpening */ -/* * - uses gain_trans */ +/* PURPOSE : Principal function for TC decoding */ +/* * Principal function for TC decoding. */ +/* * - constructs glottal codebook contribution */ +/* * - uses pitch sharpening */ +/* * - uses gain_trans */ /*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Word16) L_frame : length of the frame Q0 */ +/* GLOBAL INPUT ARGUMENTS : */ +/* _ (Word16) L_frame : length of the frame Q0 */ /*----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ /*----------------------------------------------------------------------*/ - - /*----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*======================================================================*/ static void tc_dec_fx( diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 8704c2e078953ece7244675baad1c1e9af417161..27983b42e469050c699741b2e31c1c0e20c55090 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 : fixed point 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 = calc_tilt_bwe_fx_32( 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; // TODO: Duplicate variables - 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/vlpc_1st_dec_fx.c b/lib_dec/vlpc_1st_dec_fx.c index f34372453648c00213cbfcd3a350f3e200309eee..45fd00390aa85c2069a22724090211692c7871ad 100644 --- a/lib_dec/vlpc_1st_dec_fx.c +++ b/lib_dec/vlpc_1st_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index ee3d5ed7659fbf28caebb1ed25e577890e43cf7a..562cce4cf40daa5015e262ba3c37c6e36cbb6081 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index c937a3b2b6c032bb139c98919a65ae6af4f29f9f..2108baad59d767c4900d18562756eae4a0247cab 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index f5155cacfee78d7f9d817a79c846e564104e34ea..1776d31a236c3d7bf2be8f6be3ce7be37bff2e3f 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 051b55981dbd13839f219a50169ddb7967c7f062..f9e2d919c9bb8b47922c61e8e44df86a632b54e3 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -163,8 +163,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( idx = s_min( idx1, idx2 ); /* Q0 */ /* Get context */ - ctx = &c[s_or( p1, p2 )]; /* Q0 */ - /* _DIFF_FLOAT_FIX_ float is using t as UWord16 */ + ctx = &c[s_or( p1, p2 )]; /* Q0 */ t = add( *ctx, rateFlag ); /* Q0 */ if ( GT_16( idx, nt_half ) ) { @@ -308,13 +307,13 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( { IF( s_and( idx1, 1 ) ) /* update first context */ { - c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ + c[p1] = update_mixed_context_fx( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ move16(); } IF( s_and( idx2, 1 ) ) /* update second context */ { - c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ + c[p2] = update_mixed_context_fx( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ move16(); } } @@ -680,13 +679,13 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( { IF( s_and( idx1, 1 ) ) /* update first context */ { - c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ + c[p1] = update_mixed_context_fx( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ move16(); } IF( s_and( idx2, 1 ) ) /* update second context */ { - c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ + c[p2] = update_mixed_context_fx( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ move16(); } } @@ -956,14 +955,14 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( IF( s_and( idx1, 1 ) ) { /* update first context */ - c[p1] = update_mixed_context_ivas_fx( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ + c[p1] = update_mixed_context_fx_32( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ move32(); } IF( s_and( idx2, 1 ) ) { /* update second context */ - c[p2] = update_mixed_context_ivas_fx( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ + c[p2] = update_mixed_context_fx_32( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ move32(); } } @@ -1100,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*/ } @@ -1408,14 +1407,14 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( IF( s_and( idx1, 1 ) ) { /* update first context */ - c[p1] = update_mixed_context_ivas_fx( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ + c[p1] = update_mixed_context_fx_32( c[p1], abs_s( x[a1_i] ) ); /* Q0 */ move32(); } IF( s_and( idx2, 1 ) ) { /* update second context */ - c[p2] = update_mixed_context_ivas_fx( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ + c[p2] = update_mixed_context_fx_32( c[p2], abs_s( x[b1_i] ) ); /* Q0 */ move32(); } } @@ -1565,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 1a813b46205712a942ef65958c6e2c14d19e5e4f..3be0ff74c399dafafe2093c70288201e6cbd9585 100644 --- a/lib_enc/FEC_enc_fx.c +++ b/lib_enc/FEC_enc_fx.c @@ -1,22 +1,21 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #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 */ /*============================================================================*/ -/* FUNCTION : void FEC_encode_fx() */ +/* FUNCTION : void FEC_encode_fx() */ /*----------------------------------------------------------------------------*/ -/* PURPOSE : Encoder supplementary information for FEC */ +/* PURPOSE : Encoder supplementary information for FEC */ /*----------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ +/* INPUT ARGUMENTS : */ /* Word16 *synth i : pointer to synthesized speech for E computation */ /* Word16 coder_type i : type of coder */ /* Word16 clas i : signal clas for current frame */ @@ -25,31 +24,31 @@ /* Word16 L_frame i : Frame length */ /* Word32 total_brate i : total codec bitrate */ /*----------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*----------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /* Word16 *last_pulse_pos i/o: Position of the last pulse */ -/* Encoder_State *st_fx i/o: state structure */ +/* Encoder_State *st_fx i/o: state structure */ /*----------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*----------------------------------------------------------------------------*/ -/* */ +/* */ /*============================================================================*/ void FEC_encode_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_new, /* i : input scaling */ - const Word16 shift /* i : scaling to get 12bits */ + 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_new, /* i : input scaling */ + const Word16 shift /* i : scaling to get 12bits */ ) { Word16 tmpS, index; @@ -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 */ @@ -154,7 +159,7 @@ void FEC_encode_fx( if ( sign == 1 ) { - maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) Q0*/ + 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 ); @@ -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/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index 09acfd5dca1bb7bde7ab0896faee5ba2148c79d1..ef54f1841f3fa8cfd42d8b3eb485820e396d66da 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -19,15 +19,15 @@ *-------------------------------------------------------------------*/ void calc_lf_snr_fx( - Word32 *lf_snr_smooth, /* o : smoothed lf_snr Q25*/ - Word32 *lf_snr, /* o : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr Q25*/ - const Word32 l_speech_snr, /* i : sum of active frames snr Q16*/ - const Word32 l_speech_snr_count, /* i : amount of the active frame Q0*/ - const Word32 l_silence_snr, /* i : sum of the nonactive frames snr Q16*/ - const Word32 l_silence_snr_count, /* i : amount of the nonactive frame Q0*/ + Word32 *lf_snr_smooth, /* o : smoothed lf_snr Q25*/ + Word32 *lf_snr, /* o : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr Q25*/ + const Word32 l_speech_snr, /* i : sum of active frames snr Q16*/ + const Word32 l_speech_snr_count, /* i : amount of the active frame Q0*/ + const Word32 l_silence_snr, /* i : sum of the nonactive frames snr Q16*/ + const Word32 l_silence_snr_count, /* i : amount of the nonactive frame Q0*/ const Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/ const Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/ - const Word16 bw_index /* i : band width index Q0*/ + const Word16 bw_index /* i : band width index Q0*/ ) { @@ -72,14 +72,14 @@ void calc_lf_snr_fx( *-------------------------------------------------------------------*/ void calc_lt_snr_fx( VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *lt_snr_org_fp, /* o : original long time SNR Q25*/ - Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy Q25*/ - Word32 fg_energy, /* i : foreground energy sum Qx*/ - Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/ - Word32 bg_energy, /* i : background energy sum Qx*/ - Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/ - Word16 bw_index, /* i : band width index Q0*/ - Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0 Q10*/ + Word32 *lt_snr_org_fp, /* o : original long time SNR Q25*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy Q25*/ + Word32 fg_energy, /* i : foreground energy sum Qx*/ + Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/ + Word32 bg_energy, /* i : background energy sum Qx*/ + Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/ + Word16 bw_index, /* i : band width index Q0*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0 Q10*/ ) { Word16 tmp_lt_noise_sp_center; @@ -172,9 +172,9 @@ void calc_lt_snr_fx( * *-------------------------------------------------------------------*/ void calc_snr_flux_fx( - Word32 tsnr, /* i : time-domain SNR Q25*/ - Word32 *pre_snr, /* i/o: time-domain SNR storage Q25*/ - Word32 *snr_flux_fp /* o : average tsnr Q25*/ + Word32 tsnr, /* i : time-domain SNR Q25*/ + Word32 *pre_snr, /* i/o: time-domain SNR storage Q25*/ + Word32 *snr_flux_fp /* o : average tsnr Q25*/ ) { Word32 i; @@ -229,12 +229,12 @@ void calc_snr_flux_fx( * *-------------------------------------------------------------------*/ void snr_calc( - VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower */ - Word32 *snr, /* o : frequency domain SNR Q25*/ - Word32 *tsnr, /* o : time domain SNR Q25*/ - const Word32 frame_energy, /* i : current frame energy sacle_sbpower*/ - const Word32 bwidth /* i : audio band width Q0*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower */ + Word32 *snr, /* o : frequency domain SNR Q25*/ + Word32 *tsnr, /* o : time domain SNR Q25*/ + const Word32 frame_energy, /* i : current frame energy sacle_sbpower*/ + const Word32 bwidth /* i : audio band width Q0*/ ) { Word32 i; @@ -371,14 +371,14 @@ void snr_calc( } Word32 construct_snr_thresh_fx( - Word16 sp_center[], /* i : spectral center Q10*/ - Word32 snr_flux, /* i : snr flux Q25*/ - Word32 lt_snr, /* i : long time time domain snr Q25*/ - Word32 l_snr, /* i : long time frequency domain snr Q25*/ - Word32 continuous_speech_num, /* i : amount of continuous speech frames Q0*/ - Word16 continuous_noise_num, /* i : amount of continuous noise frames Q0*/ - Word32 fg_energy_est_start, /* i : whether if estimated energy Q0*/ - Word16 bw_index /* i : band width index Q0*/ + Word16 sp_center[], /* i : spectral center Q10*/ + Word32 snr_flux, /* i : snr flux Q25*/ + Word32 lt_snr, /* i : long time time domain snr Q25*/ + Word32 l_snr, /* i : long time frequency domain snr Q25*/ + Word32 continuous_speech_num, /* i : amount of continuous speech frames Q0*/ + Word16 continuous_noise_num, /* i : amount of continuous noise frames Q0*/ + Word32 fg_energy_est_start, /* i : whether if estimated energy Q0*/ + Word16 bw_index /* i : band width index Q0*/ ) { diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index cdb0d4d34dcbb29a22b41875c877ba088134d278..2168e0e3ac7bb1c27aed46a24252b174116bb3cf 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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,705 +18,27 @@ * * ACELP core encoder *--------------------------------------------------------------------*/ -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*/ - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors Qx*/ - const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame Q15*/ - Word16 vad_hover_flag_fx, /* 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*/ - 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_old_syn*/ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits_fx, /* o : number of unused bits Q0*/ - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const Word16 Q_new, - const Word16 shift ) -{ - Word16 nBits; /* reserved bits */ - Word16 i; - Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ - Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ - Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */ - Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ - Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ - Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ - Word16 Es_pred_fx; /* predicited scaled innovation energy */ - Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ - Word16 tc_subfr_fx, position; /* TC sub-frame indication */ - Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */ - Word16 *bwe_exc_fx; /* excitation for SWB TBE */ - Word16 allow_cn_step_fx; - Word16 int_fs_fx; - Word32 L_epsP[2]; - /* 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 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - Word16 nb_bits; - Word16 indice; - Word16 tmp16; - Word16 enr_index; - Word16 enr; - - Word16 tilt_code_bck_fx; - Word32 gc_threshold_bck_fx; - Word16 clip_var_bck_fx[6]; - Word16 next_force_sf_bck_fx; - Word32 q_env[NUM_ENV_CNG]; - Word16 sid_bw = -1; - Word16 coder_type; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx[L_FRAME16k]; - Word16 ppp_mode, nelp_mode; - Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - Word16 *tdm_Pri_pitch_buf; - Word16 uc_two_stage_flag; - Word16 att; - move16(); - - SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; - DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; - TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - 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; - } - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - Es_pred_fx = 0; - move16(); - - coder_type = st_fx->coder_type; - 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_lpd_old_exc - - IF( hBWE_TD != NULL ) - { - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc - } - ELSE - { - bwe_exc_fx = NULL; - } - - st_fx->bpf_off = 0; - move16(); - test(); - test(); - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) || 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 ) ) - { - /* in case of HQ->ACELP switching, do not apply BPF */ - st_fx->bpf_off = 1; - move16(); - if ( hGSCEnc != NULL ) - { - hGSCEnc->Last_frame_ener_fx = MAX_32; - move32(); - } - } - - /* force safety-net LSFQ in the first frames after CNG segment */ - if ( LE_32( st_fx->last_core_brate, SID_2k40 ) ) - { - st_fx->Nb_ACELP_frames = 0; - move16(); - } - st_fx->Nb_ACELP_frames = add_sat( st_fx->Nb_ACELP_frames, 1 ); // Q0 - move16(); - - int_fs_fx = INT_FS_16k_FX; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - int_fs_fx = INT_FS_FX; - move16(); - } - - tmp_noise_fx = 0; - move16(); - tc_subfr_fx = -1; - move16(); - position = -1; - move16(); - - /* SC-VBR temporary variables */ - mCb1_fx = 0; //-> to be removed - move16(); - pstreaklen_fx = 0; - move16(); - clip_var_fx = 0; - move16(); - mem_w0_bck_fx = 0; - move16(); - streaklimit_fx = 0; - move16(); - - /* channel-aware mode */ - reset_rf_indices_fx( st_fx ); - /* VBR modes */ - IF( st_fx->Opt_SC_VBR ) - { - ppp_mode = hSC_VBR->ppp_mode; - nelp_mode = hSC_VBR->nelp_mode; - move16(); - move16(); - } - ELSE - { - ppp_mode = 0; - nelp_mode = 0; - move16(); - 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 - *-----------------------------------------------------------------*/ - test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) - { - /* in case of switching, do not apply BPF */ - st_fx->bpf_off = 1; - move16(); - - /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */ - st_fx->Nb_ACELP_frames = 1; - move16(); - - /* convert old quantized LSP vector */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); // Q0 - move16(); - } - ELSE - { - st_fx->rate_switching_reset = st_fx->rate_switching_reset_16kHz; // Q0 - move16(); - Copy( st_fx->lsp_old16k_fx, st_fx->lsp_old_fx, M ); // Q15 - } - - /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs_fx ); - - /* interpolation of unquantized ISPs */ - IF( st_fx->rate_switching_reset ) - { - /*extrapolation in case of unstable LSP*/ - int_lsp4_fx( st_fx->L_frame, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); - } - ELSE - { - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); - } - - /* Reset LPC mem */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // x2.56 - set16_fx( st_fx->mem_MA_fx, 0, M ); - - /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); - Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // q_lpd_old_exc - Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); // q_mem_syn - Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); // q_mem_syn - - /* update Aw[] coefficients */ - weight_a_subfr_fx( shr( st_fx->L_frame, 6 ), A_fx, Aw_fx, st_fx->gamma, M ); - } - - test(); - test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->bwidth, NB ) && st_fx->ini_frame != 0 ) - { - st_fx->rate_switching_reset = 1; - move16(); - } - /*----------------------------------------------------------------* - * Encoding of CNG frames - *----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - IF( EQ_16( st_fx->cng_type, LP_CNG ) ) - { - /* 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 ); - /* 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 ); - - /* 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, - &hDtxEnc->first_CNG, &hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step_fx, &hTdCngEnc->last_allow_cn_step, sub( st_fx->prev_Q_new, 1 ), sub( Q_new, 1 ), hTdCngEnc->num_ho, - q_env, hTdCngEnc->lp_env_fx, hTdCngEnc->old_env_fx, hTdCngEnc->exc_mem_fx, hTdCngEnc->exc_mem1_fx, &sid_bw, &hTdCngEnc->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); - } - ELSE - { - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - FdCng_encodeSID_fx( st_fx->hFdCngEnc, st_fx, st_fx->preemph_fac ); - hDtxEnc->last_CNG_L_frame = st_fx->L_frame; - move16(); - } - - generate_comfort_noise_enc_fx( st_fx, Q_new, 1 ); - - FdCng_exc( st_fx->hFdCngEnc->hFdCngCom, &hDtxEnc->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, - hDtxEnc->first_CNG, hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - - Copy( exc2_fx, exc3_fx, st_fx->L_frame ); // Q12 - - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - IF( hTdCngEnc != NULL ) - { - enr = cng_energy_fx( st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/ 0, exc_fx, st_fx->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 ); - - hTdCngEnc->old_enr_index = enr_index; /* Q0 */ - move16(); - } - } - } - /* Reset HO counter in the first SID frame */ - if ( hTdCngEnc != NULL ) - { - hTdCngEnc->burst_ho_cnt = 0; - move16(); - } - /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_new, st_fx->Q_syn ); - - /* reset the encoder */ - CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 0 ); - - /* update st->mem_syn1 for ACELP core switching */ - Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); - - /* update ACELP core synthesis filter memory */ - Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* st_fx->Q_syn */ - - IF( hBWE_FD != NULL ) - { - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame, syn1_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - /* Update MODE2 core switching memory */ - tmp16 = hLPDmem->syn[M]; - move16(); - E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &tmp16 ); - Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); /* st_fx->Q_syn */ - } - - /*----------------------------------------------------------------* - * Encoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * Configure ACELP bit allocation - *-----------------------------------------------------------------*/ - - nb_bits = 0; - st_fx->acelp_cfg.FEC_mode = 0; - uc_two_stage_flag = 0; - move16(); - move16(); - move16(); - test(); - IF( !nelp_mode && !ppp_mode ) - { - 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, st_fx->GSC_noisy_speech, &( 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, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - } - - /*-----------------------------------------------------------------* - * After inactive period, use the most up-to-date ISPs - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( st_fx->hDtxEnc != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) - { - Copy( hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15 - - lsp2lsf_fx( hDtxEnc->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); - } - - /*-----------------------------------------------------------------* - * Reset higher ACELP pre-quantizer in case of switching - *-----------------------------------------------------------------*/ - - IF( !st_fx->use_acelp_preq ) - { - st_fx->mem_deemp_preQ_fx = 0; - move16(); - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - } - - st_fx->use_acelp_preq = 0; - move16(); - - /*-----------------------------------------------------------------* - * LSF Quantization - * A[z] calculation - *-----------------------------------------------------------------*/ - - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - lsf_syn_mem_backup_fx( st_fx, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, &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 ); - - - 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 ); - } - - /*---------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *---------------------------------------------------------------*/ - - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); - calculate_hangover_attenuation_gain_fx( st_fx, &att, vad_hover_flag_fx ); - v_multc_att( res_fx, att, res_fx, st_fx->L_frame ); - - /*-----------------------------------------------------------------* - * Determine TC subframe classification - *-----------------------------------------------------------------*/ - - IF( EQ_16( st_fx->coder_type, TRANSITION ) ) - { - tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch[0], res_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, TRANSITION, -1, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - } - - /*---------------------------------------------------------------* - * Calculation of prediction for scaled innovation energy - * (for memory-less gain quantizer) - *---------------------------------------------------------------*/ - - IF( nb_bits > 0 ) - { - Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame, res_fx, st_fx->voicing_fx, nb_bits, 0, Q_new ); - push_indice( st_fx->hBstr, IND_ES_PRED, indice, nb_bits ); - } - - /*------------------------------------------------------------* - * Encode excitation according to coding type - *------------------------------------------------------------*/ - - test(); - test(); - IF( hSC_VBR->nelp_mode ) - { - /* SC-VBR - NELP frames */ - encod_nelp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, - voice_factors_fx, bwe_exc_fx, Q_new, shift ); - } - ELSE IF( EQ_16( coder_type, UNVOICED ) ) - { - /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, - pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ); - } - ELSE IF( EQ_16( coder_type, TRANSITION ) ) - { - tc_subfr_fx = encod_tran_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new ); /* Q0 */ - } - ELSE IF( hSC_VBR->ppp_mode ) - { - IF( ( error = encod_ppp_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift ) ) != IVAS_ERR_OK ) - { - return error; - } - - IF( hSC_VBR->bump_up ) /* PPP failed, bump up */ - { - /* restore memories of LSF quantizer and synthesis filter */ - lsf_syn_mem_restore_fx( st_fx, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, 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_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 ); - - /* recalculation of LP residual (filtering through A[z] filter) */ - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx ); - - hTdCngEnc->burst_ho_cnt = 0; - move16(); - /* VOICED frames in SC-VBR when bumped up*/ - encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); - } - } - ELSE IF( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_24k40 ) ) ) - { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - encod_audio_fx( st_fx, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, - attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, Q_new, shift ); - } - ELSE - { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - encod_gen_voic_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf, shift, Q_new ); - } - - /* update st->mem_syn1 for ACELP core switching */ - Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* q_mem_syn */ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); - - /* save and delay synthesis to be used by SWB BWE */ - IF( hBWE_FD != NULL ) - { - save_old_syn_fx( st_fx->L_frame, syn_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - /*Update MODE2 core switching memory*/ - Copy( syn_fx, syn1_fx, st_fx->L_frame ); // Q_syn - 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 ) ) - { - L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] ); - move32(); - L_epsP[1] = L_Comp( epsP_h_fx[M], epsP_l_fx[M] ); - move32(); - Copy( exc_fx, exc2_fx, st_fx->L_frame ); // Q_new - stat_noise_uv_enc_fx( st_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag, Q_new ); - } - - /*-----------------------------------------------------------------* - * Encode supplementary information for Frame Error Concealment - *-----------------------------------------------------------------*/ - - FEC_encode_fx( hBstr, st_fx->acelp_cfg, syn_fx, coder_type, st_fx->clas, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos, - st_fx->L_frame, st_fx->total_brate, Q_new, shift ); - - - IF( hBWE_TD != NULL ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 - } - } - } /* end of active inp coding */ - - /*-----------------------------------------------------------------* - * Write ACELP unused bits - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_32( st_fx->core_brate, SID_2k40 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, PPP_NELP_2k80 ) ) - { - /* reserved bits */ - nBits = st_fx->acelp_cfg.ubits; // Q0 - move16(); - - WHILE( nBits > 0 ) - { - i = s_min( nBits, 16 ); // Q0 - push_indice( st_fx->hBstr, IND_UNUSED, 0, i ); - nBits = sub( nBits, i ); // Q0 - } - } - - - /*-----------------------------------------------------------------* - * Apply non linearity in case of SWB TBE - *-----------------------------------------------------------------*/ - IF( hBWE_TD != NULL ) - { - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - - IF( ( EQ_16( st_fx->last_Opt_SC_VBR, 1 ) && st_fx->Opt_SC_VBR == 0 ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - 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 ); - } - test(); - if ( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - } - } - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - updt_enc_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); - - test(); - test(); - 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 ); - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st_fx->lsp_old16k_fx, &( hTdCngEnc->ho_lsp_circ2_fx[( hTdCngEnc->ho_circ_ptr ) * M] ), M ); // Q15 - } - - /* Set 16k LSP flag for CNG buffer */ - hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 0; - move16(); - if ( NE_16( st_fx->L_frame, L_FRAME ) ) - { - hTdCngEnc->ho_16k_lsp[hTdCngEnc->ho_circ_ptr] = 1; - move16(); - } - - /* efficient DTX hangover control */ - IF( GT_16( hTdCngEnc->burst_ho_cnt, 1 ) ) - { - dtx_hangover_control_fx( st_fx, lsp_new_fx ); - } - } - /* SC-VBR update of average data rate */ - test(); - IF( EQ_16( st_fx->vad_flag, 1 ) && ( hSC_VBR != NULL ) ) - { - update_average_rate_fx( hSC_VBR, st_fx->core_brate ); - } - - return error; -} - -/*-------------------------------------------------------------------* - * acelp_core_enc_ivas_fx() - * - * ACELP core encoder - *--------------------------------------------------------------------*/ -ivas_error acelp_core_enc_ivas_fx( - 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*/ - Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ - 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*/ - 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 ) +ivas_error acelp_core_enc_fx( + 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*/ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ + const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/ + Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ + 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*/ + 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 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*/ + const Word16 Q_new, /* i : Scaling factor */ + const Word16 shift /* i : Shift need to obtain 12 bits vectors */ +) { Word16 i, nBits; /* reserved bits */ LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */ @@ -726,14 +47,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 +65,64 @@ 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]; - Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2]; - Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - - 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 ); + /* 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; + Word32 q_env_fx[NUM_ENV_CNG]; - set32_fx( q_env_fx, 0, NUM_ENV_CNG ); - set16_fx( exc2_fx, 0, L_FRAME16k ); 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; + + IF( st->element_mode > EVS_MONO ) { - 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 +138,12 @@ 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 */ - Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // 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 */ + set16_fx( old_exc_fx + L_EXC_MEM, 0, L_EXC - L_EXC_MEM ); IF( st->hBWE_TD != NULL ) { bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ @@ -883,7 +201,9 @@ ivas_error acelp_core_enc_ivas_fx( move16(); /* SC-VBR temporary variables */ - pstreaklen = 0; + mCb1_fx = 0; + move16(); + pstreaklen_fx = 0; move16(); clip_var_fx = 0; move16(); @@ -895,23 +215,24 @@ 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(); 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 +297,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 +329,121 @@ 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 + IF( st->element_mode > EVS_MONO ) + { + 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++ ) + 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 ); - /* 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 */ + st->hTdCngEnc->old_enr_index = enr_index; /* Q0 */ + move16(); + } + } + } + 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( 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 ) + { + 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 +454,31 @@ 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++ ) + IF( st->element_mode == EVS_MONO ) + { + /* 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 { - Scale_sig( &Aq[( M + 1 ) * k], M + 1, sub( norm_s( Aq[( M + 1 ) * k] ), 2 ) ); + 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 +490,56 @@ 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(); + 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 + { + 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 ); + Scale_sig( old_syn_12k8_16k, st->L_frame, sub( sub( Q_new, 1 ), st->Q_syn ) ); // Q_syn + 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] ) ); + 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 + { + 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 { + IF( st->element_mode > EVS_MONO ) + { + 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; @@ -1203,12 +588,13 @@ 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 ); + /* 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 ); 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 +630,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 +662,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 +695,37 @@ 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 ); } } 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 ); } - 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 ); + 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 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 ); + 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 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 +733,34 @@ 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 ); } } 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) */ - 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 ); + 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 { /* 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 ); + 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 ); } /* update mem_syn1_flt for ACELP core switching */ @@ -1384,33 +768,47 @@ 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; - Scale_sig( syn_fx, L_FRAME16k, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn + IF( st->element_mode > EVS_MONO ) + { + Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn + } + /* 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 ) + 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 + { + 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 ); + Scale_sig( old_syn_12k8_16k, st->L_frame, sub( sub( Q_new, 1 ), st->Q_syn ) ); // Q_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( 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] ) ); - + 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 + { + 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 +823,43 @@ 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 ) ) + + 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 + { + 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 ) ); + 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 + { + 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 +872,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 ) ) @@ -1493,7 +908,7 @@ ivas_error acelp_core_enc_ivas_fx( test(); 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 ) ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move16(); @@ -1508,9 +923,16 @@ ivas_error acelp_core_enc_ivas_fx( 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 ) ) ) { /* 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->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->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + 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 + { + 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 +947,45 @@ ivas_error acelp_core_enc_ivas_fx( * Updates *-----------------------------------------------------------------*/ - if ( st->hBWE_TD != NULL ) + IF( st->element_mode > EVS_MONO ) { - st->Q_exc = Q_new; + if ( st->hBWE_TD != NULL ) + { + st->Q_exc = Q_new; + move16(); + } + hLPDmem->q_lpd_old_exc = Q_new; move16(); } updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx ); - st->hLPDmem->q_lpd_old_exc = Q_new; - move16(); 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]; + 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 ); + 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( 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; - move16(); + 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(); + } } - 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 ); + + 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 +1003,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 ) ) { @@ -1584,14 +1012,12 @@ ivas_error acelp_core_enc_ivas_fx( } /* 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 ); } + 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 d790b1866163c7d591cee2c33517f51ac04c834b..b4c10b9acc5795dd1ab5351e9cca00f36055c22e 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 */ @@ -97,7 +94,6 @@ void acelp_core_switch_enc_fx( } } #ifdef FIX_I4_OL_PITCH - PMTE() IF( EQ_16( st_fx->last_codec_mode, MODE1 ) ) { /* in MODE1 T_op is at 12.8 kHz */ @@ -165,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() * @@ -291,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 */ @@ -375,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 ) ) @@ -420,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 */ @@ -433,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, @@ -490,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() @@ -851,163 +527,20 @@ 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]; Word16 shift, q, ener, i; Word32 L_tmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif Copy( x, tmp_tabx, len ); /* qx */ Copy( y, tmp_taby, len ); /* qy */ diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index a9e567fa73a0c502f58bf0cf88caa2a90577f5b3..cd93c7f13973c4ee3e1c3b801b96fba2483e925d 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -1,12 +1,11 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include #include "options.h" -//#include "prot_fx.h" #include "basop_util.h" #include "cnst.h" #include "prot_fx.h" /* Function prototypes */ @@ -104,10 +103,10 @@ Word16 E_ACELP_toeplitz_mul_fx( } void E_ACELP_weighted_code( - const Word16 code[], /* i: code Q9*/ - const Word16 H[], /* i: impulse response Q*/ - Word16 Q, /* i: Q format of H */ - Word16 y[] /* o: weighted code Q9*/ + const Word16 code[], /* i: code Q9*/ + const Word16 H[], /* i: impulse response Q*/ + Word16 Q, /* i: Q format of H */ + Word16 y[] /* o: weighted code Q9*/ ) { Word16 i, j, k, one, n, nz[L_SUBFR]; @@ -153,9 +152,9 @@ void E_ACELP_weighted_code( } void E_ACELP_conv( - const Word16 xn2[], /* i Qx*/ - const Word16 h2[], /* i Q12*/ - Word16 cn2[] /* o Q0*/ + const Word16 xn2[], /* i Qx*/ + const Word16 h2[], /* i Q12*/ + Word16 cn2[] /* o Q0*/ ) { Word16 i, k; @@ -176,36 +175,12 @@ 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*/ - const Word16 sign[], /* i Q0*/ - Word16 code[], /* o Q9*/ - Word16 ind[] /* o Q0*/ + Word16 nb_pulse, /* i Q0*/ + const Word16 codvec[], /* i Q0*/ + const Word16 sign[], /* i Q0*/ + Word16 code[], /* o Q9*/ + Word16 ind[] /* o Q0*/ ) { Word16 i, k, val, index, track, tmp, vec[4]; @@ -225,7 +200,7 @@ void E_ACELP_build_code( FOR( k = 0; k < nb_pulse; ++k ) { - i = codvec[k]; /* read pulse position Q0*/ + i = codvec[k]; /* read pulse position Q0*/ move16(); val = sign[i]; /* read sign Q0*/ move16(); @@ -258,9 +233,9 @@ void E_ACELP_build_code( } void E_ACELP_setup_pulse_search_pos( - const PulseConfig *config, /* i: pulse configuration */ - Word16 k, /* i: interation number Q0*/ - UWord8 ipos[] /* o: pulse search positions Q0*/ + const PulseConfig *config, /* i: pulse configuration */ + Word16 k, /* i: interation number Q0*/ + UWord8 ipos[] /* o: pulse search positions Q0*/ ) { Word16 restpulses, iPulse; diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 76c9930b68d67bb4fe9b5130ed14fee450a07a22..dfc11efcdd3db7f2f959d940b3f7f877e26398d3 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -22,9 +22,10 @@ *--------------------------------------------------------------------*/ void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal Q0*/ - const Word16 n_samples /* i : number of input samples Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_sp[], /* i : input signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ + const Word16 n_samples /* i : number of input samples Q0*/ ) { Word16 i, delay; @@ -107,7 +108,7 @@ void amr_wb_enc_fx( move16(); st->coder_type = GENERIC; move16(); - input_frame = st->input_frame_fx; + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); /* frame length of the input signal */ st->extl = -1; move16(); @@ -135,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 ); @@ -181,7 +182,7 @@ void amr_wb_enc_fx( st->input_fx[i] = 0; move16(); } - hp20( st->input_fx, 1, input_frame, st->mem_hp20_in_fx, st->input_Fs ); + hp20( st->input_fx, 1, input_frame, mem_hp20_in_fx, st->input_Fs ); /*-----------------------------------------------------------------* * switching from ACELP@16k core to AMR-WB IO mode @@ -260,7 +261,12 @@ void amr_wb_enc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ + +#ifndef FIX_2410_HARM_MODIF_FS modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0 ); +#else + modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0, NULL, NULL ); +#endif /* update signal buffer */ Copy( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME ); /* Q0 */ @@ -309,7 +315,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 @@ -331,7 +337,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 @@ -426,10 +432,8 @@ void amr_wb_enc_fx( * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ - noise_est_fx( st, old_pitch1, tmpN, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, - NULL, &sp_div, &Q_sp_div, &non_staX, &harm_flag, - lf_E, &hNoiseEst->harm_cor_cnt, hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor, NULL, - st->ini_frame ); + noise_est_fx( st, old_pitch1, tmpN, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, NULL, &sp_div, &Q_sp_div, &non_staX, &harm_flag, + lf_E, &hNoiseEst->harm_cor_cnt, hNoiseEst->Etot_l_lp_fx, hNoiseEst->Etot_v_h2_fx, &hNoiseEst->bg_cnt, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor, NULL, st->ini_frame ); /*----------------------------------------------------------------* * Change the sampling frequency to 16 kHz, @@ -447,7 +451,11 @@ void amr_wb_enc_fx( } ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { +#ifndef FIX_2410_HARM_MODIF_FS modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0 ); +#else + modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k_fx, 0, NULL, NULL ); +#endif } /*----------------------------------------------------------------* @@ -458,7 +466,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, @@ -522,10 +530,9 @@ void amr_wb_enc_fx( if ( hTdCngEnc != NULL ) { hTdCngEnc->burst_ho_cnt = 0; + move16(); } - move16(); - /*------------------------------------------------------------* * Encode excitation *------------------------------------------------------------*/ @@ -578,7 +585,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 def862b8487fc0a4113e962ec36c919bb9299a1a..743f95af5da98e1d59ab9b33fc8b66c8209901e2 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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*/ ) { @@ -98,7 +98,7 @@ void analy_lp_fx( adapt_lag_wind( r_h, r_l, M, Top[i_subfr], Tnc[i_subfr], Core_sr ); /* Levinson-Durbin */ - E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); + E_LPC_lev_dur_fx( r_h, r_l, A, LepsP, M, NULL ); FOR( i = 0; i <= M; i++ ) { L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); @@ -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 */ @@ -142,17 +142,17 @@ void analy_lp_fx( *-------------------------------------------------------------------*/ void analy_lp_AMR_WB_fx( - const Word16 speech[], /* i : pointer to the speech frame Q_new*/ - Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/ - Word16 A[], /* o : A(z) filter coefficients Q14*/ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 isp_new[], /* o : current frame ISPs Q15*/ - Word16 isp_old[], /* i/o: previous frame unquantized ISPs Q15*/ - 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 speech[], /* i : pointer to the speech frame Q_new*/ + Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/ + Word16 A[], /* o : A(z) filter coefficients Q14*/ + Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/ + Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/ + Word16 isp_new[], /* o : current frame ISPs Q15*/ + Word16 isp_old[], /* i/o: previous frame unquantized ISPs Q15*/ + Word16 isf_new[], /* o : current frame ISPs Q15*/ + Word16 Top, /* i : open loop pitch lag Q0*/ + Word16 Tnc, /* i : open loop pitch gain Qx*/ + const Word16 Q_new, Word16 *Q_r ) { Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ @@ -174,7 +174,7 @@ void analy_lp_AMR_WB_fx( /* Levinson-Durbin */ /*lev_dur( A, r, M, epsP );*/ - E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); + E_LPC_lev_dur_fx( r_h, r_l, A, LepsP, M, NULL ); FOR( i = 0; i <= M; i++ ) { L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 7a1f60e4507f891bef28851339c64eef0eaee578..e7d09c786d06b16f010c79b5529d09ca260195f1 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -1,18 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #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*/; @@ -699,7 +707,7 @@ static void ivas_find_enr( Word16 data[], /* i : fft result */ Word16 q_data, /* i : Q of fft result */ Word32 band[], /* o : per band energy q_band */ - Word16 *q_band, /* o : Q of per band energy */ + Word16 *q_band, /* o : Q of per band energy */ Word32 *ptE, /* o : per bin energy for low frequencies q_ptE */ Word16 *q_ptE, /* o : Q of per bin energy for low frequencies Q0 */ Word64 *LEtot, /* o : total energy q_band+1 */ diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index 29ddd838c69cfb2be54ccfd8d304168190e848bf..0c44f113e95dc5ef0895032792288305ade7fb42 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -63,12 +63,12 @@ Word16 ari_put_bit_plus_follow( ) { assert( bit == 0 || bit == 1 ); - ptr[bp++] = bit; /* send initially a zero or one Q0*/ + ptr[bp++] = bit; /* send initially a zero or one Q0*/ move16(); bit = s_xor( bit, 1 ); /* invert bit to send */ FOR( ; bits_to_follow > 0; bits_to_follow-- ) { - ptr[bp++] = bit; /* send inverted bit Q0*/ + ptr[bp++] = bit; /* send inverted bit Q0*/ move16(); } return bp; @@ -171,7 +171,7 @@ Word16 ari_encode_14bits_ext_fx( /* Output an opposite bit */ /* later if in middle half. */ bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ - low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ high = L_sub( high, ari_q1new ); /* Q0 */ } ELSE @@ -248,7 +248,7 @@ static Word16 ari_encode_14bits_high_low( /* Output an opposite bit */ /* later if in middle half. */ bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ - low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ high = L_sub( high, ari_q1new ); /* Q0 */ } ELSE @@ -532,7 +532,7 @@ static Word16 ari_encode_14bits_high_low_ivas_fx( /* Output an opposite bit */ /* later if in middle half. */ bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ - low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ high = L_sub( high, ari_q1new ); /* Q0 */ } ELSE diff --git a/lib_enc/ari_hm_enc_fx.c b/lib_enc/ari_hm_enc_fx.c index 1917216ef6f3817970040cc0de0cc93c67ea43ce..d70f09062cb44e073e60628be3a0994d0c39cb58 100644 --- a/lib_enc/ari_hm_enc_fx.c +++ b/lib_enc/ari_hm_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 12f3368dce228f49a0bd2c80cf6e180c41caed50..b8c55ee1b82080e409abbe126116fe3d1cac4e74 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index 982b30d323939a75f3478a442cdae07433583ed9..e54dfeda293c25c78b4754231af24600de21acb7 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -1,12 +1,14 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #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/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index c4aeab22d55bbd5cec8b5331bf03525b41462552..083f8d68ed6a09e1b57cf14253695d9fadd9e301 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 49391f60f7d0fc3485c737453dc621b215c9d0c3..2e04b986ff3813d6ba305070632b388d41938a4b 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 */ @@ -55,8 +55,7 @@ void bw_detect_fx( Word16 spect[L_FRAME48k], spect_bin[BWD_N_BINS_MAX]; Word32 spect32[L_FRAME48k], in_win32[BWD_TOTAL_WIDTH]; Word16 e_tmp, f_tmp; - Word32 L_tmp, sum32; - + Word32 L_tmp, sum32, L_tmp_q_shift; Word32 L_tmp1, L_tmp2, L_tmp3; Word16 scale; Word16 ScalFac, ScalFacInv; @@ -76,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 ) ) { @@ -117,27 +120,20 @@ void bw_detect_fx( move32(); /* Q31 */ cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP ); move16(); -#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING if ( cldfb_bin[0] == 0 ) { cldfb_bin[0] = L_deposit_l( 1 ); move32(); } -#else - if ( cldfb_bin[i] == 0 ) - { - cldfb_bin[i] = L_deposit_l( 1 ); - move32(); - } -#endif - L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING - L_tmp = L_add_sat( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#else - L_tmp = L_add_sat( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#endif - cldfb_bin[0] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); - move32(); /* 1/log2(10) */ /* Q25 */ + + L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25 + L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 ); // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + cldfb_bin[0] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */ + move32(); /* 1/log2(10) */ /* Q25 */ /* WB: 4.4 - 7.2 kHz, 8 cldfb-bands, mid band(14) counted twice */ IF( GE_32( st->input_Fs, 16000 ) ) @@ -164,14 +160,14 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING - L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#else - L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#endif - cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); - move32(); /* 1/log2(10) */ /* Q25 */ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25 + L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 ); // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + cldfb_bin[i] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */ + move32(); /* 1/log2(10) */ /* Q25 */ } } @@ -207,14 +203,14 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING - L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#else - L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#endif - cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); - move32(); /* 1/log2(10) */ /* Q25 */ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25 + L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 ); // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + cldfb_bin[i] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */ + move32(); /* 1/log2(10) */ /* Q25 */ } } @@ -244,14 +240,14 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING - L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#else - L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -#endif - cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); - move32(); /* 1/log2(10) */ /* Q25 */ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = Mpy_32_16_1( L_tmp, INV_LOG2_10 ); // instead of adding it to L_tmp_q_shift and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + L_tmp_q_shift = L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ); // This term should be added to L_temp to align it to Q25 + L_tmp_q_shift = Mpy_32_16_1( L_tmp_q_shift, INV_LOG2_10 ); // instead of adding it to L_tmp and then multiplying by INV_LOG2_10 ( to avoid saturation ). + + cldfb_bin[i] = L_add( L_tmp, L_tmp_q_shift ); /* Q25 */ + move32(); /* 1/log2(10) */ /* Q25 */ } } /* cldfb_bin_Exp[] are applied now in cldfb_bin[i] -> don't use again */ @@ -983,7 +979,6 @@ void set_bw_fx( test(); IF( GT_16( element_mode, IVAS_SCE ) ) { - // PMT("this IVAS_SCE section has not been verified ") IF( LT_32( element_brate, MIN_BRATE_SWB_STEREO ) ) { st->bwidth = WB; diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 34be60d8a7c5b6d33502ba91b95184cbf4c4456d..e0b5041c8889edf3e8f39569af44b230830a4692 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1,6 +1,7 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + 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,11 +873,15 @@ 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 ) ) { +#ifndef FIX_2410_HARM_MODIF_FS modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0 ); +#else + modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, hTdCngEnc->exc_mem2_fx, 0, NULL, NULL ); +#endif } fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); @@ -775,49 +905,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 +1031,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 +1097,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 +1119,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 +1234,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 +1251,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 +1334,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 +1351,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,1556 +1373,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(); - // PMT("apply_scale is not implemented") - } - 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; @@ -2733,6 +1405,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(); @@ -2762,10 +1448,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; @@ -2779,10 +1472,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 ) ) { @@ -2812,7 +1505,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 */ ) @@ -2820,29 +1513,23 @@ 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 { /*idx_ener = (int16_t)(0.7f * (0.1f * st->hTdCngEnc->mov_shb_cng_ener / (float)log10(2.0f) + 6.0f) + 0.5f);*/ - // PMT("shb_CNG_encod_fx quantization in missing") /* 6.0 in Q8 -> 1510 */ /* 0.7 in Q15 22938 */ /* ( 1 / log10(2.0) ) * 0.1 in Q15 -> 10886 */ 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; @@ -2903,6 +1590,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 ); @@ -2911,6 +1599,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(); @@ -2926,21 +1615,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]; @@ -2989,7 +1678,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 ) ) { @@ -3003,7 +1691,7 @@ static Word16 shb_DTX_ivas_fx( } ELSE { - att_fx = -1664; // Q8 + att_fx = 1664; /*6.5 in Q8*/ move16(); } @@ -3011,8 +1699,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 @@ -3022,6 +1708,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; @@ -3059,7 +1746,6 @@ static Word16 shb_DTX_ivas_fx( hTdCngEnc->shb_NO_DATA_cnt = add( hTdCngEnc->shb_NO_DATA_cnt, 1 ); update = 0; - move16(); move16(); @@ -3073,7 +1759,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; @@ -3090,6 +1776,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/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index f4dbad642052e26ed32a07cd761cfe209d218211..fa66223cb9679fc3425e43f0b5e4e0f44ed510ee 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_enc/cod4t64_fast_fx.c b/lib_enc/cod4t64_fast_fx.c index 7079f65971792963c9701841da0e9cc00e80bd54..66378d261dde31d4ec7cbcdcff1967607bc1d3a2 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" @@ -43,11 +42,8 @@ * Local constants *-------------------------------------------------------------------*/ -#define BETA_BN1 2.0f -#define BETA_BN2 2.25f - -#define BETA_BN1_FX 2 // Q0 -#define BETA_BN2_FX 9 // Q2 +#define BETA_BN1_FX 2 // 2.0f in Q0 +#define BETA_BN2_FX 9 // 2.25f in Q2 #define L_SUBFR_MAX 2 * L_SUBFR #define MAX_NUM_INTER 5 @@ -77,6 +73,8 @@ static Word16 quant_1p_N1_L_subfr_fx( return index; } + + static Word16 find_best_pulse_fx( const Word16 L_subfr, const Word16 nb_tracks, @@ -112,6 +110,7 @@ static Word16 find_best_pulse_fx( return m; } + /*-------------------------------------------------------------------* * Function acelp_fast() * @@ -120,21 +119,22 @@ static Word16 find_best_pulse_fx( *-------------------------------------------------------------------*/ void acelp_fast_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 cdk_index, /* i : codebook index */ - const Word16 dn_orig[L_SUBFR], - /* i : corr. between target and h[]. */ // Q_dn + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 cdk_index, /* i : codebook index */ + const Word16 dn_orig[L_SUBFR], /* i : corr. between target and h[]. Q_dncn */ +#ifdef OPT_2416_ACELP_FAST + const Word16 Q_dncn, /* i : scaling factor of dn and cn */ +#else Word16 Q_dn, - const Word16 cn[L_SUBFR], - /* i : residual after long term prediction */ // q_cn +#endif + const Word16 cn[L_SUBFR], /* i : residual after long term prediction Q_dncn */ +#ifndef OPT_2416_ACELP_FAST const Word16 q_cn, - const Word16 H[L_SUBFR], - /* i : impulse response of weighted synthesis filter */ // e(norm_s(H[0])+1) - Word16 code[L_SUBFR], - /* o : algebraic (fixed) codebook excitation */ // Q0 - Word16 y[], - /* o : filtered fixed codebook excitation */ // e(norm_s(H[0])+1) - const Word16 L_subfr /* i : subframe length */ +#endif + const Word16 H[L_SUBFR], /* i : impulse response of weighted synthesis filter e(norm_s(H[0])+1) */ + Word16 code[L_SUBFR], /* o : algebraic (fixed) codebook excitation Q0 */ + Word16 y[], /* o : filtered fixed codebook excitation e(norm_s(H[0])+1) */ + const Word16 L_subfr /* i : subframe length */ ) { Word16 i, j, q, bits, bits_track, nb_pos, nb_pulse, track, nb_iter, nb_tracks; @@ -164,8 +164,11 @@ void acelp_fast_fx( Word16 flag = 0; move16(); Word32 temp1, temp2, temp3, temp4, temp5, temp6; +#ifndef OPT_2416_ACELP_FAST Word16 q_temp1, q_temp2; +#endif Word16 scale_temp1, scale_temp2; + /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ @@ -224,7 +227,6 @@ void acelp_fast_fx( codetrackpos = -1; /* to avoid compilation warnings */ move16(); - IF( EQ_16( cdk_index, 14 ) ) { /* 14 bits, 2 pulses, 2 tracks: 11 (used all tracks) */ @@ -296,8 +298,9 @@ void acelp_fast_fx( * Find signal bn[] and sign pre-selection vector sign[]. *-----------------------------------------------------------------*/ +#ifndef OPT_2416_ACELP_FAST exp = sub( Q31, shl( Q_dn, 1 ) ); - +#endif s64 = 0; move64(); FOR( i = 0; i < L_subfr; i++ ) @@ -312,10 +315,13 @@ void acelp_fast_fx( { Word16 new_exp1 = W_norm( s64 ); dndn_fx = W_extract_h( W_shl( s64, new_exp1 ) ); // 2 * Q_dyn + exp1 - 31 +#ifndef OPT_2416_ACELP_FAST dndn_e = sub( 31, sub( add( add( shl( Q_dn, 1 ), 1 ), new_exp1 ), 32 ) ); +#else + dndn_e = sub( 31, sub( add( add( shl( Q_dncn, 1 ), 1 ), new_exp1 ), 32 ) ); +#endif } - cncn_fx = 214748365 /* 0.1f in Q31 */; move32(); cncn_e = 0; @@ -338,7 +344,11 @@ void acelp_fast_fx( { Word16 new_exp1 = W_norm( s64 ); cncn_track[q] = W_extract_h( W_shl( s64, new_exp1 ) ); // 2 * Q_dyn + exp1 - 31 +#ifndef OPT_2416_ACELP_FAST cncn_track_e[q] = sub( 31, sub( add( add( shl( q_cn, 1 ), 1 ), new_exp1 ), 32 ) ); +#else + cncn_track_e[q] = sub( 31, sub( add( add( shl( Q_dncn, 1 ), 1 ), new_exp1 ), 32 ) ); +#endif } cncn_fx = BASOP_Util_Add_Mant32Exp( cncn_fx, cncn_e, cncn_track[q], cncn_track_e[q], &cncn_e ); // Q(cncn_e) } @@ -349,8 +359,14 @@ void acelp_fast_fx( tmp = add( tmp, sub( dndn_e, cncn_e ) ); s_coef_fx = Sqrt16( s_coef_fx, &tmp ); // Q(15 - tmp) +#ifdef OPT_2416_ACELP_FAST + scale_temp1 = sub( Q16, tmp ); + /* Q_dn = q_cn and it doesn't matter */ +#else q_temp1 = add( add( sub( Q15, tmp ), q_cn ), Q1 ); scale_temp1 = sub( q_temp1, Q_dn ); +#endif + FOR( i = 0; i < L_subfr; i++ ) { temp1 = L_mult( s_coef_fx, cn[i] ); // Q(15 - tmp)+q_cn+1 @@ -361,6 +377,15 @@ void acelp_fast_fx( bn_orig_fx[i] = L_add( temp1, temp2 ); // Q_dn move32(); +#ifdef OPT_2416_ACELP_FAST + sign_fx[i] = -1; + move16(); + if ( bn_orig_fx[i] >= 0 ) + { + sign_fx[i] = 1; + move16(); + } +#else IF( bn_orig_fx[i] >= 0 ) { sign_fx[i] = 1; @@ -370,6 +395,7 @@ void acelp_fast_fx( sign_fx[i] = -1; } move16(); +#endif } /*-----------------------------------------------------------------* @@ -398,6 +424,7 @@ void acelp_fast_fx( /*-----------------------------------------------------------------* * Approximate FI[i][j] by alp[abs(i-j)] and compute buffer alp_buf[]. *-----------------------------------------------------------------*/ + q_H = sub( 14, norm_s( H[0] ) ); shift = sub( shl( q_H, 1 ), 6 ); @@ -459,6 +486,29 @@ void acelp_fast_fx( test(); test(); /* skip certain tracks if number of pulses is lower than number of tracks */ +#ifdef OPT_2416_ACELP_FAST /* Just need a negative number, it doesn't need to be scaled */ + IF( EQ_16( nb_pulse, 2 ) && EQ_16( nb_tracks, NB_TRACK_FCB_4T ) ) + { + max_track[NB_TRACK_FCB_4T - 3] = L_deposit_l( -1 ); + move32(); + max_track[NB_TRACK_FCB_4T - 1] = L_deposit_l( -1 ); + move32(); + } + ELSE IF( EQ_16( nb_pulse, 3 ) && EQ_16( codetrackpos, TRACKPOS_FIXED_FIRST ) ) + { + max_track[NB_TRACK_FCB_4T - 1] = L_deposit_l( -1 ); + move32(); + } + + FOR( q = 0; q < nb_tracks; q++ ) + { + i = maximum_32_fx( max_track, nb_tracks, &L_tmp1 ); + track_order[q] = i; + move16(); + max_track[i] = L_deposit_l( -1 ); + move32(); + } +#else IF( EQ_16( nb_pulse, 2 ) && EQ_16( nb_tracks, NB_TRACK_FCB_4T ) ) { max_track[NB_TRACK_FCB_4T - 3] = L_shl( -1, Q_dn ); // Q_dn @@ -480,6 +530,7 @@ void acelp_fast_fx( max_track[i] = L_shl( -1, Q_dn ); // Q_dn move32(); } +#endif track_order[4] = track_order[1]; // Q0 move16(); @@ -618,9 +669,13 @@ void acelp_fast_fx( move64(); FOR( i = track; i < L_subfr; i += nb_tracks ) { +#ifdef OPT_2416_ACELP_FAST + temp3 = L_msu0( L_mult0( Gd, dn_orig[i] ), G, *alp_pos0 ); +#else temp1 = L_mult0( Gd, dn_orig[i] ); temp2 = L_mult0( G, *alp_pos0 ); temp3 = L_sub( temp1, temp2 ); +#endif dn[i] = L_shr( temp3, 6 ); move32(); alp_pos0 += nb_tracks; @@ -628,8 +683,11 @@ void acelp_fast_fx( } exp1 = W_norm( s64 ); dndn_fx = W_extract_h( W_shl( s64, exp1 ) ); // 2 * Q_dyn + exp1 - 31 +#ifndef OPT_2416_ACELP_FAST dndn_e = sub( 31, sub( add( add( shl( Q_dn, 1 ), 1 ), exp1 ), 32 ) ); - +#else + dndn_e = sub( 31, sub( add( add( shl( Q_dncn, 1 ), 1 ), exp1 ), 32 ) ); +#endif IF( dndn_fx == 0 ) { dndn_fx = 214748365 /* 0.1f in Q31 */; @@ -646,10 +704,16 @@ void acelp_fast_fx( move16(); m[1] = track; // Q0 move16(); +#ifdef OPT_2416_ACELP_FAST + scale_temp1 = sub( Q16, exp1 ); + scale_temp2 = Q2; + move16(); +#else q_temp1 = add( add( sub( Q15, exp1 ), q_cn ), 1 ); q_temp2 = add( Q_dn, Q2 ); scale_temp1 = sub( q_temp1, Q_dn ); scale_temp2 = sub( q_temp2, Q_dn ); +#endif FOR( i = track; i < L_subfr; i += nb_tracks ) { temp1 = L_mult( s_coef_fx, cn[i] ); // Q(15 - tmp)+q_cn+1 @@ -684,8 +748,12 @@ void acelp_fast_fx( Gn = add( Gn, i_mult( s[1], dn_orig[m[1]] ) ); // Q_dn Gd32 = Gd; move16(); +#ifdef OPT_2416_ACELP_FAST + Gd32 = L_add( Gd32, L_mac0( alp[0], i_mult( shl( s[0], 1 ), s[1] ), alp[m[0] - m[1]] ) ); // Q6 +#else Gd32 = L_add( Gd32, L_add( alp[0], L_mult0( i_mult( shl( s[0], 1 ), s[1] ), alp[m[0] - m[1]] ) ) ); // Q6 - G = Gn; // Q_dn +#endif + G = Gn; // Q_dn move16(); G1 = i_mult( G, s[1] ); // Q_dn G = i_mult( G, s[0] ); // Q_dn @@ -698,10 +766,15 @@ void acelp_fast_fx( FOR( i = track; i < L_subfr; i += nb_tracks ) { temp1 = imult3216( Gd32, dn_orig[i] ); +#ifdef OPT_2416_ACELP_FAST + temp4 = L_msu0( temp1, G, *alp_pos0 ); + temp4 = L_msu0( temp4, G1, *alp_pos1 ); +#else temp2 = L_mult0( G, *alp_pos0 ); temp3 = L_mult0( G1, *alp_pos1 ); temp4 = L_sub( temp1, temp2 ); temp4 = L_sub( temp4, temp3 ); +#endif dn[i] = L_shr( temp4, 6 ); move32(); alp_pos0 += nb_tracks; @@ -721,10 +794,16 @@ void acelp_fast_fx( Gn = add( Gn, i_mult( s[2], dn_orig[m[2]] ) ); // Q_dn temp1 = alp[0]; move32(); +#ifdef OPT_2416_ACELP_FAST + temp2 = L_mac0( temp1, i_mult( shl( s[0], 1 ), s[2] ), alp[m[0] - m[2]] ); + temp3 = L_mac0( temp2, i_mult( shl( s[1], 1 ), s[2] ), alp[m[1] - m[2]] ); + Gd32 = L_add( Gd32, temp3 ); // Q6 +#else temp2 = L_mult0( i_mult( shl( s[0], 1 ), s[2] ), alp[m[0] - m[2]] ); temp3 = L_mult0( i_mult( shl( s[1], 1 ), s[2] ), alp[m[1] - m[2]] ); Gd32 = L_add( Gd32, L_add( L_add( temp1, temp2 ), temp3 ) ); // Q6 - G = Gn; // Q_dn +#endif + G = Gn; // Q_dn move16(); G1 = i_mult( G, s[1] ); // Q_dn G2 = i_mult( G, s[2] ); // Q_dn @@ -740,12 +819,18 @@ void acelp_fast_fx( { temp1 = imult3216( Gd32, dn_orig[i] ); +#ifdef OPT_2416_ACELP_FAST + temp5 = L_msu0( temp1, G, *alp_pos0 ); + temp5 = L_msu0( temp5, G1, *alp_pos1 ); + temp5 = L_msu0( temp5, G2, *alp_pos2 ); +#else temp2 = L_mult0( G, *alp_pos0 ); temp3 = L_mult0( G1, *alp_pos1 ); temp4 = L_mult0( G2, *alp_pos2 ); temp5 = L_sub( temp1, temp2 ); temp5 = L_sub( temp5, temp3 ); temp5 = L_sub( temp5, temp4 ); +#endif dn[i] = L_shr( temp5, 6 ); move32(); alp_pos0 += nb_tracks; @@ -771,11 +856,19 @@ void acelp_fast_fx( Gn = add( Gn, i_mult( s[3], dn_orig[m[3]] ) ); // Q_dn temp1 = alp[0]; move32(); +#ifdef OPT_2416_ACELP_FAST + temp2 = L_mac0( temp1, i_mult( shl( s[0], 1 ), s[3] ), alp[m[0] - m[3]] ); + temp2 = L_mac0( temp2, i_mult( shl( s[1], 1 ), s[3] ), alp[m[1] - m[3]] ); + temp2 = L_mac0( temp2, i_mult( shl( s[2], 1 ), s[3] ), alp[m[2] - m[3]] ); + + Gd32 = L_add( Gd32, temp2 ); // Q6 +#else temp2 = L_mult0( i_mult( shl( s[0], 1 ), s[3] ), alp[m[0] - m[3]] ); temp3 = L_mult0( i_mult( shl( s[1], 1 ), s[3] ), alp[m[1] - m[3]] ); temp4 = L_mult0( i_mult( shl( s[2], 1 ), s[3] ), alp[m[2] - m[3]] ); Gd32 = L_add( Gd32, L_add( L_add( L_add( temp1, temp2 ), temp3 ), temp4 ) ); // Q6 +#endif G = Gn; move16(); // Q_dn G1 = i_mult( G, s[1] ); // Q_dn @@ -796,6 +889,12 @@ void acelp_fast_fx( FOR( i = track; i < L_subfr; i += nb_tracks ) { temp1 = imult3216( Gd32, dn_orig[i] ); +#ifdef OPT_2416_ACELP_FAST + temp6 = L_msu0( temp1, G, *alp_pos0 ); + temp6 = L_msu0( temp6, G1, *alp_pos1 ); + temp6 = L_msu0( temp6, G2, *alp_pos2 ); + temp6 = L_msu0( temp6, G3, *alp_pos3 ); +#else temp2 = L_mult0( G, *alp_pos0 ); temp3 = L_mult0( G1, *alp_pos1 ); temp4 = L_mult0( G2, *alp_pos2 ); @@ -804,6 +903,7 @@ void acelp_fast_fx( temp6 = L_sub( temp6, temp3 ); temp6 = L_sub( temp6, temp4 ); temp6 = L_sub( temp6, temp5 ); +#endif dn[i] = L_shr( temp6, 6 ); move32(); alp_pos0 += nb_tracks; @@ -825,6 +925,12 @@ void acelp_fast_fx( FOR( i = 0; i < L_subfr; i++ ) { temp1 = imult3216( Gd32, dn_orig[i] ); +#ifdef OPT_2416_ACELP_FAST + temp6 = L_msu0( temp1, G, *alp_pos0 ); + temp6 = L_msu0( temp6, G1, *alp_pos1 ); + temp6 = L_msu0( temp6, G2, *alp_pos2 ); + temp6 = L_msu0( temp6, G3, *alp_pos3 ); +#else temp2 = L_mult0( G, *alp_pos0 ); temp3 = L_mult0( G1, *alp_pos1 ); temp4 = L_mult0( G2, *alp_pos2 ); @@ -833,6 +939,7 @@ void acelp_fast_fx( temp6 = L_sub( temp6, temp3 ); temp6 = L_sub( temp6, temp4 ); temp6 = L_sub( temp6, temp5 ); +#endif dn[i] = L_shr( temp6, 6 ); move16(); alp_pos0++; @@ -886,6 +993,13 @@ void acelp_fast_fx( FOR( j = 0; j < nb_pulse; j++ ) { +#ifdef OPT_2416_ACELP_FAST + p_hn = h_inv - m[j]; + if ( s[j] > 0 ) + { + p_hn = h - m[j]; + } +#else IF( s[j] > 0 ) { p_hn = h - m[j]; @@ -894,7 +1008,7 @@ void acelp_fast_fx( { p_hn = h_inv - m[j]; } - +#endif FOR( i = 0; i < L_subfr; i++ ) { y_tmp[i] = add_sat( y_tmp[i], *p_hn++ ); // q_H @@ -907,8 +1021,11 @@ void acelp_fast_fx( s64 = W_mult0_32_32( crit_num, crit_num ); // 2*Q_dn exp = W_norm( s64 ); crit_num = W_extract_h( W_shl( s64, exp ) ); // 2*Q_dn + exp - 32 +#ifndef OPT_2416_ACELP_FAST q_crit_num = add( shl( Q_dn, 1 ), sub( exp, 32 ) ); - +#else + q_crit_num = add( shl( Q_dncn, 1 ), sub( exp, 32 ) ); +#endif // crit_den = sum2_fx( y_tmp, L_subfr ); // 2*q_H s64 = 0; move64(); @@ -927,6 +1044,15 @@ void acelp_fast_fx( IF( GT_16( exp, exp1 ) ) { +#ifdef OPT_2416_ACELP_FAST + flag = 0; + move16(); + if ( GE_32( L_shr( L_tmp1, sub( exp, exp1 ) ), L_tmp2 ) ) + { + flag = 1; + move16(); + } +#else IF( GE_32( L_shr( L_tmp1, sub( exp, exp1 ) ), L_tmp2 ) ) { flag = 1; @@ -937,9 +1063,19 @@ void acelp_fast_fx( flag = 0; move16(); } +#endif } ELSE { +#ifdef OPT_2416_ACELP_FAST + flag = 0; + move16(); + if ( GE_32( L_tmp1, L_shr( L_tmp2, sub( exp1, exp ) ) ) ) + { + flag = 1; + move16(); + } +#else IF( GE_32( L_tmp1, L_shr( L_tmp2, sub( exp1, exp ) ) ) ) { flag = 1; @@ -950,9 +1086,9 @@ void acelp_fast_fx( flag = 0; move16(); } +#endif } - IF( flag ) { crit_num_max = crit_num; diff --git a/lib_enc/cod4t64_fx.c b/lib_enc/cod4t64_fx.c index 4d342eeb4c72303265286e6401984aeb64037f19..ac494e1604e858bc94d80eaee0a18abc5f543945 100644 --- a/lib_enc/cod4t64_fx.c +++ b/lib_enc/cod4t64_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -760,10 +760,10 @@ static Word16 quant_3p_3N1_fx( ELSE { index = quant_2p_2N1_fx( pos2, pos3, sub( N, 1 ) ); /* index = quant_2p_2N1_fx(pos2, pos3, (N-1)); */ - /* index += (pos2 & nb_pos) << N; */ + /* index += (pos2 & nb_pos) << N; */ index = add( index, shl( (Word16) ( pos2 & nb_pos ), N ) ); logic16(); - /* index += quant_1p_N1_fx(pos1, N) << (2*N); */ + /* index += quant_1p_N1_fx(pos1, N) << (2*N); */ index = add( index, shl( quant_1p_N1_fx( pos1, N ), shl( N, 1 ) ) ); } return ( index ); @@ -799,7 +799,7 @@ static Word32 quant_4p_4N1_fx( IF( ( ( pos1 ^ pos2 ) & nb_pos ) == 0 ) { index = quant_2p_2N1_fx( pos1, pos2, sub( N, 1 ) ); /* index = quant_2p_2N1_fx(pos1, pos2, (N-1)); */ - /* index += (pos1 & nb_pos) << N; */ + /* index += (pos1 & nb_pos) << N; */ index = L_add( index, L_shl( L_deposit_l( (Word16) ( pos1 & nb_pos ) ), N ) ); logic16(); /* index += quant_2p_2N1_fx(pos3, pos4, N) << (2*N); */ diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 5a6e094a23441de7546cf27d688c247dae0b5137..f4b74b351d9928d059ea9a61eb36108a7fe691fc 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 1e01d8c3c621eb7cbfe443bcb8f2f9bc82512a75..ec0a7372d1e0a28d58fdb78a45e2b1bf4a5e4ce0 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -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 @@ -40,10 +39,8 @@ void HBAutocorrelation_fx( Word32 L_tmp, L_sum; Word16 y[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif /*-----------------------------------------------------------* * Windowing * @@ -138,6 +135,8 @@ void HBAutocorrelation_fx( } } +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + void TNSAnalysis_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 L_frame, /* input: frame length */ @@ -220,19 +219,23 @@ void TNSAnalysis_fx( } } } - +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT void TNSAnalysis_ivas_fx( +#else +void TNSAnalysis_fx( +#endif // FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 L_frame, /* i : frame length */ Word16 L_spec, /* i : length of the spectrum */ - Word16 transform_type, /* i : transform type for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ + Word16 transform_type, /* i : transform type for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ Word8 isAfterACELP, /* i : Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ Word32 spectrum[], /* i : MDCT spectrum Q=Qx*/ TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ Word16 ltp_gain, /* i : ltp gain Q=15*/ STnsData *pTnsData, /* o : Tns data */ Word8 *pfUseTns, /* o : Flag indicating if TNS is used */ - Word16 *predictionGain /* o : TNS prediction gain Q=7 */ + Word16 *predictionGain /* o : TNS prediction gain Q=7 */ ) { Word32 buff[8]; @@ -277,8 +280,14 @@ void TNSAnalysis_ivas_fx( } move16(); +#ifdef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + *pfUseTns = (Word8) DetectTnsFilt_fx( hTcxCfg->pCurrentTnsConfig, spectrum, pTnsData, hTranDet, (Word8) NE_16( transform_type, TCX_20 ), ltp_gain, predictionGain ); + +#else *pfUseTns = (Word8) DetectTnsFilt_ivas_fx( hTcxCfg->pCurrentTnsConfig, spectrum, pTnsData, hTranDet, (Word8) NE_16( transform_type, TCX_20 ), ltp_gain, predictionGain ); +#endif // FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + /* If TNS should be used then get the residual after applying it inplace in spectrum */ IF( *pfUseTns != 0 ) { @@ -624,7 +633,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(); @@ -700,7 +711,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; @@ -3620,7 +3633,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(); } @@ -3846,8 +3859,11 @@ void coder_tcx_fx( { SetTnsConfig( hTcxCfg, sub( L_frame_glob, st->L_frame ) == 0, st->last_core == 0 ); - +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT TNSAnalysis_fx( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, hTcxEnc->tnsData, hTcxEnc->fUseTns, &st->hIGFEnc->tns_predictionGain ); +#else + TNSAnalysis_fx( hTcxCfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, st->hTranDet, -32768, hTcxEnc->tnsData, hTcxEnc->fUseTns, &st->hIGFEnc->tns_predictionGain ); +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT } ELSE { @@ -3911,8 +3927,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]; @@ -5093,7 +5109,6 @@ void TNSAnalysisStereo_fx( move16(); move16(); } -#ifdef FIX_1349_TNS_CRASH ELSE { pFilter[0]->filterType = TNS_FILTER_OFF; @@ -5105,7 +5120,6 @@ void TNSAnalysisStereo_fx( move16(); move16(); } -#endif } } } diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index 5fb8322a31d5cf624bfb018ae702b247222d6d8e..684282bdb4db989fab629aeb10529107dcaf0928 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/comvad_decision_fx.c b/lib_enc/comvad_decision_fx.c index 1499bbfce0e51540ecf72e3d742924df9442ebaf..479781d27f81ada362100741eef47eb6c2d2915b 100644 --- a/lib_enc/comvad_decision_fx.c +++ b/lib_enc/comvad_decision_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 28e837f486cc10b95f9852599f2b98002369c087..5e42145521b79d7ded9734a556cb8f8b2e3bf642 100644 --- a/lib_enc/cor_shif_fx.c +++ b/lib_enc/cor_shif_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ diff --git a/lib_enc/core_enc_2div_fx.c b/lib_enc/core_enc_2div_fx.c index fa74ec6b562f88a5e675aba13685de56fa703fdb..45aba6a058e66b7eddb206ed568604586c346529 100644 --- a/lib_enc/core_enc_2div_fx.c +++ b/lib_enc/core_enc_2div_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -275,7 +275,7 @@ void core_encode_twodiv_fx( hTcxEnc->fUseTns[0], st ); - /*_DIFF_FLOAT_FIX_ -> The line below is present in float */ + /*_DIFF_FLOAT_FIX_EVS_IVAS -> The line below is present in float */ // hTcxEnc->measuredBwRatio = 0x4000; /* Calculate target bits */ diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index a7ffcc229c5024799f61277b983e7cb7a9046c0f..23dcd45b1e045f3c67b71541339f573956bfbf6e 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -234,6 +234,8 @@ void init_coder_ace_plus_fx( set16_fx( st->bpf_T, PIT_MIN_12k8, NB_SUBFR16k ); + st->mem_bpf_fx.lp_error = 0; + move16(); st->mem_bpf_fx.noise_shift_old = 0; move16(); @@ -286,7 +288,6 @@ static void init_tcx_fx( (void) MCT_flag; (void) total_brate; (void) last_total_brate; - // PMT("init_tcx_fx needs an entire review to adapt to IVAS") fscaleFB = div_l( L_shl( st->input_Fs, LD_FSCALE_DENOM + 1 ), 12800 ); init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxEnc->L_frameTCX, fscaleFB ); @@ -360,7 +361,7 @@ static void init_tcx_fx( IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /* TCX-LTP */ diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index c26905199f00fb3652f400721a64767fe3d2fb77..a347b086a4f24c973265a4fe8e4de98d73eb88e2 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -247,7 +247,7 @@ void core_encode_openloop_fx( /* reset TBE buffers previous frame frame wasn't ACELP*/ IF( st->last_core != ACELP_CORE ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } @@ -457,21 +457,17 @@ void core_encode_openloop_fx( E_UTIL_f_preemph2( Q_new - 1, buf, st->preemph_fac, L_LP, &tmp ); autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); lag_wind( r_h, r_l, M, INT_FS_FX, LAGW_WEAK ); - E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_lev_dur_fx( 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_reconf_fx.c b/lib_enc/core_enc_reconf_fx.c index 5f01935c73450ea01243bd17fdec3e4114958e80..9f21792e353c441ee0ac0802ccf948cc48756b8a 100644 --- a/lib_enc/core_enc_reconf_fx.c +++ b/lib_enc/core_enc_reconf_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 440c02d049d133739642b664faa1f4021c7eb079..b94c1a0e31bd5e4a836d45ed36170603598cd895 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -109,7 +109,7 @@ void core_coder_mode_switch_fx( move16(); IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { - InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); } st->narrowBand = 0; @@ -173,7 +173,7 @@ void core_coder_mode_switch_fx( ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { /* reset TBE buffers as previous frame wasn't using TBE */ - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } ELSE { @@ -333,7 +333,7 @@ void core_coder_mode_switch_ivas_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { - InitTnsConfigs_ivas_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT ); } @@ -415,7 +415,7 @@ void core_coder_mode_switch_ivas_fx( ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } ELSE { diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index dcf57738a2e71e29ffe3746110370d1aa4dbc5fa..f6aba6f612395a6ef00d9b002f6376151556a4af 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -1,9 +1,8 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include -//#include "prot_fx.h" #include "options.h" #include "cnst.h" /* Common constants */ #include "basop_util.h" @@ -12,64 +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 */ - - // move16(); - // st->last_core = st->core; /* _DIFF_FLOAT_FIX_ not in float -> remove? */ - - 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, @@ -154,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 ); @@ -204,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 */ ) { @@ -230,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(); + } } } @@ -269,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 337e1200bc2e89648068ff2c00f556bfd7378c2a..497f4ad9e4410f381ca3d485ceaff6042686a7c1 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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*/ ) @@ -44,8 +46,6 @@ void core_switching_pre_enc_fx( { IF( hLPDmem != NULL ) { - st_fx->mem_deemph_fx = hLPDmem->syn[M]; - move16(); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); /*hLPDmem->q_mem_syn*/ } @@ -66,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 ) ) { @@ -114,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; @@ -199,16 +200,18 @@ void core_switching_pre_enc_fx( lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); } - st_fx->mem_deemph_fx = 0; /* 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; @@ -240,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(); @@ -254,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(); @@ -295,15 +307,16 @@ 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 */ IF( hBWE_FD != NULL ) { - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); /* TODO : this might not be needed */ + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } + test(); test(); test(); @@ -344,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 { @@ -359,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 ) ) { @@ -380,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; } @@ -389,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 */ ) @@ -419,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; @@ -457,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 ); @@ -484,8 +591,9 @@ void core_switching_post_enc_fx( } ELSE IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - TBEreset_enc_fx( st_fx, st_fx->bwidth ); + TBEreset_enc_fx( st_fx->hBWE_TD, st_fx->last_core, st_fx->bwidth ); } + test(); test(); test(); @@ -496,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; @@ -630,558 +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 ) - { - st_fx->mem_deemph_fx = hLPDmem->syn[M]; - move16(); - 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 ); - } - - st_fx->mem_deemph_fx = 0; - move16(); - /* 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 ) ); /* TODO : this might not be needed */ - } - } - 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, 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/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 21af7bc0a75da31e16fc522af9f3d4562a33cd13..4f0614fba3265c0e0f93e072eadf366dbe6c065f 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" diff --git a/lib_enc/decision_matrix_enc_fx.c b/lib_enc/decision_matrix_enc_fx.c index 6f20edc4f8ba93b90f9e37e9000b58298c404af8..0bf5c8dfa4f56da5c6c13b7d1d4a31210279d221 100644 --- a/lib_enc/decision_matrix_enc_fx.c +++ b/lib_enc/decision_matrix_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -174,6 +174,9 @@ void decision_matrix_enc_fx( } } + /* set inactive coder_type flag in ACELP core to GSC */ + st_fx->inactive_coder_type_flag = 1; + return; } @@ -752,85 +755,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 14a6d6c80b06ee3b070e2e2507b13f6bbf412914..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -48,7 +48,7 @@ /*--------------------------------------------------------------------------*/ /* float x (i) in Q_new input to filter */ /* float y (o) in Q_new +2 output of filter */ -/* float *oldy (i/o) previous output of filter */ +/* float *oldy (i/o) previous output of filter */ /* float *oldx (i/o) in Q_memx previous input of filter */ /* short L (i) in Q_memx +2 length (32 or 48 kHz) */ /*--------------------------------------------------------------------------*/ @@ -116,10 +116,8 @@ Word16 detect_transient_fx( Word32 E_low_fx, E_high_fx; Word16 temp16, Thres_fx = 0; Word16 exp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif shift = 0; move16(); @@ -178,7 +176,7 @@ Word16 detect_transient_fx( E_in_fx = L_add_sat( E_in_fx, Energy_in_fx[blk + 1] ); /*Q0*/ E_out_fx = L_add_sat( E_out_fx, Energy_fx ); /*Q0*/ - Thres_fx = 2185; /*1 /15 Q15*/ + Thres_fx = 2185; /*1 /15 Q15*/ move16(); IF( GT_32( Mult_32_16( Energy_fx, 5461 ), EnergyLT ) ) { @@ -246,7 +244,7 @@ Word16 detect_transient_fx( move16(); } thr = shl( thr, shift ); - /*if(Energy > L_shr(Mult_32_16(EnergyLT,22624),shift_cnt)) //getting in Q0 32*16 = Q_inp1+Q_inp2+1-16 */ + /*if(Energy > L_shr(Mult_32_16(EnergyLT,22624),shift_cnt)) //getting in Q0 32*16 = Q_inp1+Q_inp2+1-16 */ IF( GT_32( Mult_32_16( Energy, thr ), EnergyLT ) ) /*if(Energy > 6.0f * EnergyLT) */ { @@ -256,8 +254,8 @@ Word16 detect_transient_fx( move16(); } } - /*EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; */ - /*0.75f*EnergyLT in Q0 //0.25f*Energy in Q0 */ + /*EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; */ + /*0.75f*EnergyLT in Q0 //0.25f*Energy in Q0 */ EnergyLT = L_add_sat( Mult_32_16( EnergyLT, 24576 /*0.75f in Q15*/ ), Mult_32_16( Energy, shl( 8192 /*0.25 in Q15*/, shift ) ) ); /*2Q_new */ } } @@ -284,7 +282,7 @@ Word16 detect_transient_fx( E_low_fx = L_deposit_l( 0 ); FOR( i = 0; i < position + 1; i++ ) { - /*blk++; */ + /*blk++; */ blk = add( blk, 1 ); E_low_fx = L_add_sat( E_low_fx, Energy_in_fx[i] ); /*Q0*/ } diff --git a/lib_enc/diffcod_fx.c b/lib_enc/diffcod_fx.c index 6a14a27eec3ade5551c7eebb02b38d1c8185dea9..871fd422fef42d0e3e513f23e2c9dfd0a0f90fe4 100644 --- a/lib_enc/diffcod_fx.c +++ b/lib_enc/diffcod_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index fa9da7f420e75fd0fa49db50cfddc897fa044bcf..b6b4e5a3414aca3d9d28c4a8bb1c4edd63c9f3f7 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 */ /*----------------------------------------------------------------------------------*/ @@ -52,603 +52,72 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate, /* _ (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 */ +/* _ (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 */ +/* _ (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(); - } - // PMT("dtx_sce_sba code is missing") - 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; - // PMT( "lp_thresh scaling is to be found" ) - 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 ) { @@ -657,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 && @@ -680,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; @@ -693,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(); @@ -712,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(); @@ -729,6 +210,7 @@ void dtx_fx( ELSE { st_fx->codec_mode = get_codec_mode( st_fx->total_brate ); + move16(); } } } @@ -737,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(); @@ -758,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(); } @@ -802,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(); @@ -821,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(); @@ -832,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 ) ) @@ -864,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 */ @@ -874,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 { @@ -889,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 ) { @@ -930,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 ) ) { @@ -948,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(); } } } @@ -984,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(); @@ -998,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(); @@ -1009,7 +571,6 @@ void dtx_fx( move16(); } - test(); test(); IF( st_fx->Opt_RF_ON && NE_32( st_fx->total_brate, ACELP_13k20 ) ) { @@ -1018,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; @@ -1043,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() * @@ -1203,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*/ @@ -1482,6 +1054,7 @@ void dtx_hangover_control_fx( return; } + /*-------------------------------------------------------------------* * td_cng_enc_init_fx() * @@ -1494,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; @@ -1674,6 +1157,7 @@ void td_cng_enc_init_ivas_fx( return; } + /*-------------------------------------------------------------------* * dtx_enc_init_fx() * @@ -1736,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 ca4c399b0ec345672e3fd2bf5cafd04d0c73bda3..0f4e772534fcb5eb5a9ff452ca4899210a21de8e 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 3498321646e22d98a77ebd738db6e55f43fdee03..b3bd7d112b850a0f708343296bd577beb645013b 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 00a23895508012d62b6ad339087538802e92e716..a5b11f3b06ca27d9da208a793c7c7d8a54d0d14c 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 2bbb7d1544749ff9a11c8173f0324efdee712a2c..e31578c7a3993e639d5bbcce12002687d1f863d4 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 1789813cc38fc8e085b44e88adef94e27333524d..2e1a5019b0358a1056cd07e600984cb0596e86a2 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -1,10 +1,11 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #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 f4e56fdd3a3df11aa797d147cd8b66279e64f1b5..5e1a43a8cde4dcc1150fd16238950a50c4731080 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -43,62 +43,60 @@ static void rem_offset( /*======================================================================*/ -/* FUNCTION : encod_gen_voic_fx() */ +/* FUNCTION : encod_gen_voic_fx() */ /*----------------------------------------------------------------------*/ -/* PURPOSE : encode generic (GC), voiced (VC) and AMR-WB IO frames */ -/* */ +/* PURPOSE : encode generic (GC), voiced (VC) and AMR-WB IO frames */ +/* */ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : encoder static memory */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ - -/* _ (Word16[]) speech_fx : input speech Q0 */ -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16[]) A_fx : unquantized A(z) filter */ -/* with bandwidth expansion Q12 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) T_op_fx : open loop pitch Q0 */ -/* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/ -/* _ (Word16[]) res_fx : residual signal Q_new */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16) shift : shift */ -/* _ (Word16) Q_new : */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ -/* _ (Word16[]) syn_fx :core synthesis Q_new */ -/* _ (Word16[]) voice_factors_fx: voicing factors Q15 */ -/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */ -/*-----------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* INPUT ARGUMENTS : */ +/* _ (Struct) st_fx : encoder static memory */ +/* _ (Word16) L_frame_fx : length of the frame Q0 */ +/* _ (Word16[]) speech_fx : input speech Q0 */ +/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ +/* _ (Word16[]) A_fx : unquantized A(z) filter */ +/* with bandwidth expansion Q12 */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ +/* _ (Word16[]) T_op_fx : open loop pitch Q0 */ +/* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/ +/* _ (Word16[]) res_fx : residual signal Q_new */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ +/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ +/* _ (Word16) shift : shift */ +/* _ (Word16) Q_new : */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ +/* _ (Word16[]) syn_fx :core synthesis Q_new */ +/* _ (Word16[]) voice_factors_fx: voicing factors Q15 */ +/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ 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*/ + 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 */ @@ -112,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*/ @@ -144,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; /*------------------------------------------------------------------* @@ -165,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; @@ -186,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; @@ -227,385 +229,38 @@ 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 ) ) - { - /* in case of AVQ inactive, limit the gain to 0.65 */ - clip_gain_fx = 2; - move16(); - } - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ - - 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 ) ) + IF( st_fx->element_mode == EVS_MONO ) { - 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 - *-----------------------------------------------------------------*/ + 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 ); - 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 ); + 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)*/ - /*-----------------------------------------------------------------* - * 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 - *-----------------------------------------------------------------*/ - - 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 ); - } + 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 ); - /*-----------------------------------------------------------------* - * 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 ); + /* 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 ) ) { - /* 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 */ + /* 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 ); } } - ELSE - { - /*-----------------------------------------------------------------* - * 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 */ - 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 */ - } - } - - /*-----------------------------------------------------------------* - * 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 @@ -615,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 @@ -648,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 *-----------------------------------------------------------------*/ @@ -655,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 @@ -701,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(); /*-----------------------------------------------------------------* @@ -711,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 ); @@ -759,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(); } @@ -778,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 ); } } @@ -800,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 ); @@ -814,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_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index a8ce8de56e07796f11da21da5cdebca2da611ff2..82794098a07a30943cc926d68f25395a3a8a8766 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -114,18 +114,18 @@ void reset_rf_indices_fx( *-------------------------------------------------------------------*/ void coder_acelp_rf_fx( ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type Q0*/ - const Word16 A[], /* input: coefficients 4xAz[M+1] Q12*/ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] Q12*/ - Word16 speech[], /* input: speech[-M..lg] Q_new-1*/ - const Word16 voicing[], /* input: open-loop LTP gain Q15*/ - const Word16 T_op[], /* input: open-loop LTP lag Q0*/ + const Word16 coder_type, /* input: coding type Q0*/ + const Word16 A[], /* input: coefficients 4xAz[M+1] Q12*/ + const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] Q12*/ + Word16 speech[], /* input: speech[-M..lg] Q_new-1*/ + const Word16 voicing[], /* input: open-loop LTP gain Q15*/ + const Word16 T_op[], /* input: open-loop LTP lag Q0*/ Word16 stab_fac, /* Q15 */ Encoder_State *st, - Word16 target_bits, /* i/o : coder memory state Q0*/ - const Word16 rf_frame_type, /* i : rf_frame_type Q0*/ - Word16 *exc_rf, /* i/o: pointer to RF excitation Q_new*/ - Word16 *syn_rf, /* i/o: pointer to RF synthesis Q_new-1*/ + Word16 target_bits, /* i/o : coder memory state Q0*/ + const Word16 rf_frame_type, /* i : rf_frame_type Q0*/ + Word16 *exc_rf, /* i/o: pointer to RF excitation Q_new*/ + Word16 *syn_rf, /* i/o: pointer to RF synthesis Q_new-1*/ Word16 Q_new, Word16 shift ) { @@ -464,7 +464,7 @@ void coder_acelp_rf_fx( Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); /* Q10 */ Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */ Ltmp = L_add_sat( Ltmp, Ltmp2 ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new*/ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new*/ exc_rf[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ move16(); } diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 014ce4603a0a5a1aced83ec0f5f9c174d2232bcd..24bf48838bdb9584f095f79c2f889e114930026f 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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*/ @@ -57,10 +58,8 @@ void transf_cdbk_enc_fx( Word16 Qdct; Word16 avq_bit_sFlag; Word16 trgtSvPos; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif avq_bit_sFlag = 0; move16(); @@ -76,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 */ @@ -101,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 ); } @@ -138,364 +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; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - 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 - *--------------------------------------------------------------*/ - - AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); - /*--------------------------------------------------------------* * 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 ); @@ -791,14 +440,14 @@ static void find_cn_fx( * Transform domain contribution encoding *-----------------------------------------------------------------*/ -/* o: quantization index Q0*/ +/* o: quantization index Q0*/ Word16 gain_quant_fx( - Word32 *gain, /* i : quantized gain Q16*/ - Word16 *gain16, /* o : quantized gain expg*/ - const Word16 c_min, /* i : log10 of lower limit in Q14*/ - const Word16 c_max, /* i : log10 of upper limit in Q13*/ - const Word16 bits, /* i : number of bits to quantize Q0*/ - Word16 *expg /* o : output exponent of gain16 */ + Word32 *gain, /* i : quantized gain Q16*/ + Word16 *gain16, /* o : quantized gain expg*/ + const Word16 c_min, /* i : log10 of lower limit in Q14*/ + const Word16 c_max, /* i : log10 of upper limit in Q13*/ + const Word16 bits, /* i : number of bits to quantize Q0*/ + Word16 *expg /* o : output exponent of gain16 */ ) { Word16 index, levels; diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index c3eb2ae189911eb524d0ed32b015b0a58959554d..5181a08ffc86760cf387885ed8b0953bc65bdbc7 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -12,48 +12,47 @@ #include "basop_util.h" /*==============================================================================*/ -/* FUNCTION : encod_nelp_fx() */ +/* FUNCTION : encod_nelp_fx() */ /*------------------------------------------------------------------------------*/ /* PURPOSE : Encode Unvoiced frames in SC-VBR */ /*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Encoder_State) st_fx: state structure */ -/* _ (Word16[]) speech_fx : input speech Q_new-1 */ -/* _ (Word16[]) Aq_fx : 12k8 Lp coefficient Q12 */ -/* _ (Word16[]) A_fx : unquantized A(z) filter */ -/* with bandwidth expansion Q12 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16[]) res_fx : residual signal Q_new */ -/* _ (Word16*) Q_new : res qformat */ +/* INPUT ARGUMENTS : */ +/* _ (Encoder_State) st_fx: state structure */ +/* _ (Word16[]) speech_fx : input speech Q_new-1 */ +/* _ (Word16[]) Aq_fx : 12k8 Lp coefficient Q12 */ +/* _ (Word16[]) A_fx : unquantized A(z) filter */ +/* with bandwidth expansion Q12 */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16[]) res_fx : residual signal Q_new */ +/* _ (Word16*) Q_new : res qformat */ /* _ (Word16) shift */ /*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) synth_fx : core synthesis */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) synth_fx : core synthesis */ /* _ (Word16[]) tmp_noise_fx: long-term noise energy Q0 */ -/* _ (Word16[]) exc_fx : current non-enhanced excitation Q_new */ -/* _ (Word16[]) exc2_fx : current enhanced excitation Q_new */ -/* _ (Word16[]) pitch_buf_fx: floating pitch values for each subframe Q6 */ +/* _ (Word16[]) exc_fx : current non-enhanced excitation Q_new */ +/* _ (Word16[]) exc2_fx : current enhanced excitation Q_new */ +/* _ (Word16[]) pitch_buf_fx: floating pitch values for each subframe Q6 */ /* _ (Word16*) voice_factors : voicing factors */ /* _ (Word16*) bwe_exc : excitation for SWB TBE */ /*------------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==============================================================================*/ void encod_nelp_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 Q12*/ + const Word16 *speech_fx, /* i : input speech Q_new-1*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ - 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 Q0*/ - 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 *res_fx, /* o : residual signal Q_new*/ + Word16 *synth_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 *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 @@ -172,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 b1ad74b0da240b2627468b5cccd015e687eb9722..f93919b502d49b49f46ede1ff43e4ca18fd14676 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -11,40 +11,39 @@ /*======================================================================*/ -/* FUNCTION : enc_pit_exc_fx() */ +/* FUNCTION : enc_pit_exc_fx() */ /*----------------------------------------------------------------------*/ -/* PURPOSE : Encode pitch only contribution */ -/* */ +/* PURPOSE : Encode pitch only contribution */ +/* */ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : encoder static memory */ -/* _ (Word16[]) speech_fx : input speech Qnew-1 */ -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16[]) A_fx : unquantized A(z) filter */ -/* with bandwidth expansion Q12 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) T_op_fx : open loop pitch Q0 */ -/* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/ -/* _ (Word16[]) res_fx : residual signal Q_new */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ +/* INPUT ARGUMENTS : */ +/* _ (Struct) st_fx : encoder static memory */ +/* _ (Word16[]) speech_fx : input speech Qnew-1 */ +/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ +/* _ (Word16[]) A_fx : unquantized A(z) filter */ +/* with bandwidth expansion Q12 */ +/* _ (Word16) coder_type : coding type */ +/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ +/* _ (Word16[]) T_op_fx : open loop pitch Q0 */ +/* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/ +/* _ (Word16[]) res_fx : residual signal Q_new */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */ +/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ /* _ (Word16[]) *wH1, : Weighted impulses response mask */ -/* _ (Word16) shift : shift */ -/* _ (Word16) Q_new : */ +/* _ (Word16) shift : shift */ +/* _ (Word16) Q_new : */ /*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */ -/* _ (Word16[]) syn_fx :core synthesis */ -/* _ (Word16[]) voice_factors_fx: voicing factors Q15 */ -/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */ +/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */ +/* _ (Word16[]) syn_fx :core synthesis */ +/* _ (Word16[]) voice_factors_fx: voicing factors Q15 */ +/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */ /*-----------------------------------------------------------------------*/ - /*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*=======================================================================*/ void enc_pit_exc_fx( @@ -61,11 +60,11 @@ void enc_pit_exc_fx( Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ Word16 *gpit, /* o : pitch mean gpit Q15*/ - 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 ) + 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*/ + 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 */ @@ -82,7 +81,7 @@ 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 cn[PIT_EXC_L_SUBFR]; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ Word16 *pt_pitch; /* pointer to floating pitch */ Word16 L_subfr; Word16 cum_gpit, gpit_tmp; @@ -104,6 +103,8 @@ 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; + Word16 q_h1 = 0; + move16(); /*------------------------------------------------------------------* * Initialization @@ -226,17 +227,16 @@ void enc_pit_exc_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - cn = NULL; - if ( EQ_16( L_subfr, L_SUBFR ) ) - { - cn = cn1; - move16(); - } + set16_fx( cn, 0, PIT_EXC_L_SUBFR ); p_Aw = Aw; p_Aq = Aq; pt_pitch = pitch_buf; /* pointer to the pitch buffer */ shift_wsp = add( Q_new, shift ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + shift_wsp = sub( shift_wsp, 1 ); + } FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_subfr ) { @@ -250,10 +250,21 @@ 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 */ + 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 + { + 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 */ @@ -266,12 +277,23 @@ 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 */ + 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 + } /*-----------------------------------------------------------------* * 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 ); + 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 + { + 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 @@ -293,7 +315,14 @@ 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*/ + 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 + { + 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*/ @@ -325,14 +354,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 { @@ -341,13 +369,13 @@ 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 *-----------------------------------------------------------------*/ - 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_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 ); } @@ -355,9 +383,17 @@ void enc_pit_exc_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 */ + 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 + { + hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ + } move16(); } ELSE @@ -372,504 +408,44 @@ void enc_pit_exc_fx( IF( use_fcb != 0 ) { - 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 */ - move16(); - } - ELSE - { - 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 */ - move16(); - } - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - - IF( use_fcb != 0 ) - { - FOR( i = 0; i < L_subfr; i++ ) - { - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 + Q_new */ - Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q_new + Q16*/ - exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ - move16(); - } - } - ELSE - { - FOR( i = 0; i < L_subfr; i++ ) - { - - Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ - exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ - } - } - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, hGSCEnc->mem_syn_tmp_fx, 1 ); - - IF( EQ_16( L_subfr, 5 * L_SUBFR ) ) - { - cum_gpit = gpit_tmp; /* Q14 */ - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - - p_Aw += 5 * ( M + 1 ); - p_Aq += 5 * ( M + 1 ); - } - ELSE IF( EQ_16( L_subfr, 5 * L_SUBFR / 2 ) ) - { - IF( i_subfr == 0 ) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */ - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - p_Aw += 2 * ( M + 1 ); - p_Aq += 2 * ( M + 1 ); + Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ } ELSE { - cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */ - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - p_Aw += 3 * ( M + 1 ); - p_Aq += 3 * ( M + 1 ); + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ } - } - ELSE IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) - { - IF( i_subfr == 0 ) + 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 */ + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */ + hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ } ELSE { - cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ } - p_Aw += 2 * ( M + 1 ); - move16(); - p_Aq += 2 * ( M + 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - } - ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) ) - { - cum_gpit = gpit_tmp; /* Q14 */ move16(); - - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - move16(); - pt_pitch++; - *pt_pitch = *( pt_pitch - 1 ); - pt_pitch++; - p_Aw += 4 * ( M + 1 ); - p_Aq += 4 * ( M + 1 ); } ELSE { - IF( i_subfr == 0 ) - { - - cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */ - } - ELSE - { - cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */ - } - - pt_pitch++; - p_Aw += ( M + 1 ); - p_Aq += ( M + 1 ); - } - } - - cum_gpit = shl_sat( cum_gpit, 1 ); /*Q15*/ - *gpit = round_fx( L_mac( L_mult( 3277, *gpit ), 29491, cum_gpit ) ); /*Q15*/ - - return; -} - - -void enc_pit_exc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *speech, /* i : Input speech Q_new-1*/ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *synth, /* i/o: core synthesis Q_new*/ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *gpit, /* o : pitch mean gpit Q15*/ - 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 ) -{ - Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ - Word16 h1[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word16 cn[PIT_EXC_L_SUBFR]; - Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code[2 * L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2[2 * L_SUBFR]; /* Filtered algebraic excitation */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code; /* Gain of code */ - Word16 gain_inov; /* inovation gain */ - Word16 gain_pit; /* Pitch gain */ - Word16 pit_idx, i_subfr; /* tmp variables */ - Word16 T0_min, T0_max; /* pitch variables */ - 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 *pt_pitch; /* pointer to floating pitch */ - Word16 L_subfr; - Word16 cum_gpit, gpit_tmp; - Word32 Local_BR, Pitch_BR; - Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */ - Word32 norm_gain_code; - Word16 pitch_limit_flag; - Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */ - Word32 Ltmp; - Word32 Lgcode; - Word16 gcode16; - Word16 shift_wsp; - Word16 lp_select, lp_flag; - Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ - Word16 q_h1; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - pitch_limit_flag = 1; - move16(); /* always extended pitch Q range */ - use_fcb = 0; - unbits_PI = 0; - move16(); - move16(); - Pitch_CT = GENERIC; - move16(); - set16_fx( cn, 0, PIT_EXC_L_SUBFR ); - test(); - test(); - IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) - { - Local_BR = ACELP_8k00; - Pitch_BR = ACELP_8k00; - move32(); - move32(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_14k80; - move32(); - if ( st_fx->GSC_IVAS_mode > 0 ) - { - Local_BR = ACELP_9k60; - move32(); - } - Pitch_BR = st_fx->core_brate; - move32(); - } - } - ELSE IF( st_fx->GSC_noisy_speech ) - { - Local_BR = ACELP_7k20; - move32(); - Pitch_BR = ACELP_7k20; - move32(); - Pitch_CT = GENERIC; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Pitch_BR = st_fx->core_brate; - move32(); - } - } - ELSE - { - Local_BR = ACELP_7k20; - move32(); - Pitch_BR = st_fx->core_brate; - move32(); - Pitch_CT = AUDIO; - move16(); - - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_13k20; - move32(); - Pitch_CT = GENERIC; - move16(); - } - } - gain_code = 0; - move16(); - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - T0_max = PIT16k_MAX; - T0_min = PIT16k_MIN; - } - ELSE - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - cum_gpit = 0; - move16(); - - L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */ - - lp_flag = st_fx->acelp_cfg.ltf_mode; - move16(); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && - ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || - ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && - EQ_16( L_subfr, L_SUBFR ) ) ) - { - use_fcb = 1; - move16(); - } - ELSE IF( st_fx->GSC_IVAS_mode > 0 && EQ_16( L_subfr, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) - { - use_fcb = 2; - st_fx->acelp_cfg.fcb_mode = 1; - move16(); - move16(); - set16_fx( st_fx->acelp_cfg.gains_mode, 6, NB_SUBFR ); - set16_fx( st_fx->acelp_cfg.pitch_bits, 9, NB_SUBFR ); - set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k ); - } - - *saved_bit_pos = st_fx->next_bit_pos_fx; /* Q0 */ - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - p_Aw = Aw; - p_Aq = Aq; - pt_pitch = pitch_buf; /* pointer to the pitch buffer */ - shift_wsp = add( Q_new, shift ); - - FOR( i_subfr = 0; i_subfr < st_fx->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[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */ - /* condition on target (compared to float) has been put outside the loop */ - - 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*/ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */ - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - - *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 */ - - Scale_sig( h1, L_subfr, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14*/ - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - 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 ); - - /*-----------------------------------------------------------------* - * 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, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */ - - /*-----------------------------------------------------------------* - * Codebook target computation - * (No LP filtering of the adaptive excitation) - *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, st_fx->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 ); - } - - st_fx->hSpMusClas->lowrate_pitchGain = mac_r( L_mult( 29491 /* 0.9 in Q15 */, st_fx->hSpMusClas->lowrate_pitchGain ), 3277 /* 0.1 in Q15 */, gain_pit ); /* Q14 */ - - gpit_tmp = gain_pit; - move16(); /*Q14*/ - test(); - IF( use_fcb > 0 ) - { - /* h2 in Q12 for codebook search */ - /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ - Copy_Scale_sig( h1, h2, L_subfr, sub( -2 - 1, shift ) ); - } - - IF( use_fcb == 0 ) - { - IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) ) + 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 */ + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); - push_indice( hBstr, IND_PIT_IDX, pit_idx, 5 ); + hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ } ELSE { - pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); - push_indice( hBstr, IND_PIT_IDX, pit_idx, 4 ); + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ } - } - ELSE IF( use_fcb == 2 ) - { - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - - inov_encode_ivas_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, Q_new ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - - gain_enc_lbr_fx( st_fx->hBstr, st_fx->acelp_cfg.gains_mode, GENERIC, i_subfr, xn, y1, sub( shift_wsp, 1 ), 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 - { - /*-----------------------------------------------------------------* - * Innovation & gain encoding - *-----------------------------------------------------------------*/ - - inov_encode_ivas_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, Q_new ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - - gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, st_fx->L_frame, i_subfr, -1, xn, y1, sub( shift_wsp, 1 ), y2, code, Es_pred, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - - 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_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_subfr, 0 ); // Q15 move16(); } - ELSE - { - hLPDmem->tilt_code = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - - IF( use_fcb != 0 ) - { - Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); - Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); // Q_new+14+shift - Ltmp = L_negate( Ltmp ); - Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift - Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 - hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ - } - ELSE - { - Ltmp = L_mult( xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift - Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 - hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ - } /*-----------------------------------------------------------------* * Construct adaptive part of the excitation @@ -884,7 +460,7 @@ void enc_pit_exc_ivas_fx( Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 + Q_new */ Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q_new + Q16*/ exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ move16(); } @@ -895,9 +471,8 @@ void enc_pit_exc_ivas_fx( { Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ - move16(); } } @@ -910,7 +485,7 @@ void enc_pit_exc_ivas_fx( IF( EQ_16( L_subfr, 5 * L_SUBFR ) ) { - cum_gpit = gpit_tmp; + cum_gpit = gpit_tmp; /* Q14 */ move16(); pt_pitch++; *pt_pitch = *( pt_pitch - 1 ); @@ -976,7 +551,7 @@ void enc_pit_exc_ivas_fx( } ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) ) { - cum_gpit = gpit_tmp; + cum_gpit = gpit_tmp; /* Q14 */ move16(); pt_pitch++; diff --git a/lib_enc/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c index fca36f460bc3e53cef1ee84cc7ea8e9ebeb26a97..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 Aug 12, 2021. Version 16.3.0 + 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() */ @@ -19,52 +17,54 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); /* PURPOSE : */ /*---------------------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (Word16) speech_fx[], i : input speech Q_new */ -/* _ (Word16) Aq_fx[], i : 12k8 Lp coefficient Q12 */ +/* _ (Word16) speech_fx[], i : input speech Q_new */ +/* _ (Word16) Aq_fx[], i : 12k8 Lp coefficient Q12 */ /* _ (Word16) A_fx[], i : unquantized A(z) filter with bandwidth expansion Q12*/ -/* _ (Word16) coder_type, i : coding type */ -/* _ (Word16) T_op_fx[], i : open loop pitch */ -/* _ (Word16) voicing_fx[], i : voicing Q15 */ -/* _ (Word16) *res_fx, i : residual signal Q_new */ -/* _ (Word16) Q_new i : Q factor for res */ -/* _ (Word16) vadsnr_fx i : SNR for current frame Q7 */ +/* _ (Word16) coder_type, i : coding type */ +/* _ (Word16) T_op_fx[], i : open loop pitch */ +/* _ (Word16) voicing_fx[], i : voicing Q15 */ +/* _ (Word16) *res_fx, i : residual signal Q_new */ +/* _ (Word16) Q_new i : Q factor for res */ +/* _ (Word16) vadsnr_fx i : SNR for current frame Q7 */ /*---------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) *exc2_fx, o : current enhanced excitation Q0 */ -/* _ (Word16) *pitch_buf_fx, o : floating pitch values for each subframe Q6 */ -/* _ (Word16) *synth_fx, o : core synthesis Q-1 */ -/* _ Encoder_State *st_fx: */ -/* _ lastLgainE_fx - Q11 */ -/* _ lastHgainE_fx - Q11 */ -/* _ lasterbE_fx - Q13 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) *exc2_fx, o : current enhanced excitation Q0 */ +/* _ (Word16) *pitch_buf_fx, o : floating pitch values for each subframe Q6 */ +/* _ (Word16) *synth_fx, o : core synthesis Q-1 */ +/* _ Encoder_State *st_fx: */ +/* _ lastLgainE_fx - Q11 */ +/* _ lastHgainE_fx - Q11 */ +/* _ lasterbE_fx - Q13 */ /*---------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Encoder_State *st_fx: */ -/* _ st_fx->dtfs_enc_xxxx */ -/* _ a nd b in st_fx->dtfs_enc_Q */ -/* rest all in Q0 */ -/* - bump_up_fx - Q0 */ -/* _ (Word16) *exc_fx, o : current enhanced excitation Q0 */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _ Encoder_State *st_fx: */ +/* _ st_fx->dtfs_enc_xxxx */ +/* _ a nd b in st_fx->dtfs_enc_Q */ +/* rest all in Q0 */ +/* - bump_up_fx - Q0 */ +/* _ (Word16) *exc_fx, o : current enhanced excitation Q0 */ /*---------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ -/* _ None. */ +/* _ None. */ /*---------------------------------------------------------------------------------------*/ /* 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*/ - 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 *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 ) + 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 Q14*/ + 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*/ + 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 94d869a01c66a9b43a2edbb493330da64dccb8da..e28dd0bf99392be34f6c528b1a6fc31db9afd3c2 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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(); } } @@ -1518,10 +1343,10 @@ void writeTCXparam_fx( *--------------------------------------------------------------------*/ void writeTCXMode_fx( - Encoder_State *st, /* i/o: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - Word16 *nbits_start /* o : nbits start Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + Word16 *nbits_start /* o : nbits start Q0*/ ) { UWord16 index; diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index fd97c8bf44a0642823a3aa3a5cde82a5c6e16f83..10e458fb5710a073f8c2f61cbd3b433e3e228791 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -11,43 +11,43 @@ /*=================================================================================*/ -/* FUNCTION : void encod_tran_fx () */ +/* FUNCTION : void encod_tran_fx () */ /*---------------------------------------------------------------------------------*/ -/* PURPOSE : */ +/* PURPOSE : */ /*---------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* (Word16) L_frame_fx : length of the frame Q0 */ -/* (Word16[]) speech_fx : input speech Q0 */ -/* (Word16[]) Aq_fx : 12k8 Lp coefficient Q12 */ -/* (Word16[]) A_fx : unquantized A(z) filter with bandwidth expansion Q12 */ -/* (Word16) coder_type : coding type Q0 */ -/* (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* (Word16[]) T_op_fx : open loop pitch Q0 */ -/* (Word16[]) voicing_fx : voicing Q15 */ -/* (Word16*) res_fx : residual signal Q_new*/ -/* (Word16) gsc_attack_flag : Flag to indicate when an audio attack is deal with TM*/ -/* (Word16) shift : shift factor */ -/* (Word16[]) Q_new : input scaling */ +/* INPUT ARGUMENTS : */ +/* (Word16) L_frame_fx : length of the frame Q0 */ +/* (Word16[]) speech_fx : input speech Q0 */ +/* (Word16[]) Aq_fx : 12k8 Lp coefficient Q12 */ +/* (Word16[]) A_fx : unquantized A(z) filter with bandwidth expansion Q12 */ +/* (Word16) coder_type : coding type Q0 */ +/* (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ +/* (Word16[]) T_op_fx : open loop pitch Q0 */ +/* (Word16[]) voicing_fx : voicing Q15 */ +/* (Word16*) res_fx : residual signal Q_new*/ +/* (Word16) gsc_attack_flag : Flag to indicate when an audio attack is deal with TM*/ +/* (Word16) shift : shift factor */ +/* (Word16[]) Q_new : input scaling */ /*---------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* (Word16*) voice_factors : voicing factors Q15 */ +/* OUTPUT ARGUMENTS : */ +/* (Word16*) voice_factors : voicing factors Q15 */ /*---------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State *st_fx :Encoder state structure */ -/* (Word16*) syn_fx :core synthesis Qnew */ -/* (Word16*) exc_fx :current non-enhanced excitation Q0 */ -/* (Word16*) exc2_fx :current enhanced excitation Q0 */ -/* (Word16*) pitch_buf_fx :floating pitch values for each subframe Q6 */ -/* (Word16*) bwe_exc_fx :excitation for SWB TBE Q0 */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* Encoder_State *st_fx :Encoder state structure */ +/* (Word16*) syn_fx :core synthesis Qnew */ +/* (Word16*) exc_fx :current non-enhanced excitation Q0 */ +/* (Word16*) exc2_fx :current enhanced excitation Q0 */ +/* (Word16*) pitch_buf_fx :floating pitch values for each subframe Q6 */ +/* (Word16*) bwe_exc_fx :excitation for SWB TBE Q0 */ /*---------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*---------------------------------------------------------------------------------*/ Word16 encod_tran_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 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*/ @@ -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 */ + hLPDmem->tilt_code = est_tilt_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR ); // Q15 } - - /*-----------------------------------------------------------------* - * 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 ); - } - 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 1a531b8bed7810dd5a1bd8abea53ff47792b24e4..160814bc07d2e3c1c319d16d9ca90ebd9b80386c 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -19,23 +19,25 @@ void encod_unvoiced_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech Q_new*/ + 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 *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 ) + 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 */ +) { 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 ); + 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 ); - 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 - *-----------------------------------------------------------------*/ - - /* 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 @@ -356,7 +136,6 @@ void encod_unvoiced_ivas_fx( * Unvoiced subframe processing in two stages *----------------------------------------------------------------*/ - // PMT("The code below needs validation, never been tested") /* No adaptive codebook (UC) */ set16_fx( y1, 0, L_SUBFR ); set16_fx( exc_fx + i_subfr, 0, L_SUBFR ); @@ -367,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 ); @@ -390,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 * @@ -458,7 +256,7 @@ void encod_unvoiced_ivas_fx( Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); /* Q10 */ Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */ Ltmp = L_add_sat( Ltmp, Ltmp2 ); /* Q15 + Q_new */ - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + 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 */ move16(); } diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 308c7cc5d28cf513250c38881da33aa5e04e0194..53cda71c19f689b630b1f9d6a9eebca739785d73 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -17,18 +17,18 @@ * *-------------------------------------------------------------------*/ void est_energy_fx( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band enerBuffer_exp*/ - Word16 enerBuffer_exp, /* i : exponent of energy vector */ - Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly frame_sb_energy_scale*/ - Word32 *frame_energy2_p, /* o : frame energy 2 frame_energy2_Q*/ - Word32 *HB_Power_p, /* o : high frequency energy HB_Power_Q*/ - Word32 *frame_energy_p, /* o : frame energy 1 frame_energy_Q*/ - Word16 *sb_power_Q, /* o : the scaling of sb_power */ - Word16 *frame_energy2_Q, /* o : the scaling of frame_energy */ - Word16 *HB_Power_Q, /* o : the scaling of HB_Power */ - Word16 *frame_energy_Q, /* o : the Scaling of frame_energy */ - Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[] */ - const Word32 bandwidth /* i : band width Q0*/ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band enerBuffer_exp*/ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly frame_sb_energy_scale*/ + Word32 *frame_energy2_p, /* o : frame energy 2 frame_energy2_Q*/ + Word32 *HB_Power_p, /* o : high frequency energy HB_Power_Q*/ + Word32 *frame_energy_p, /* o : frame energy 1 frame_energy_Q*/ + Word16 *sb_power_Q, /* o : the scaling of sb_power */ + Word16 *frame_energy2_Q, /* o : the scaling of frame_energy */ + Word16 *HB_Power_Q, /* o : the scaling of HB_Power */ + Word16 *frame_energy_Q, /* o : the Scaling of frame_energy */ + Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[] */ + const Word32 bandwidth /* i : band width Q0*/ ) { Word32 i, j; @@ -200,11 +200,11 @@ static void update_sb_bg_energy( * *-------------------------------------------------------------------*/ void background_update_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy */ - Word32 frame_energy, /* i : current frame energy scale*/ - Word32 update_flag, /* i : update flag Q0*/ - Word16 music_backgound_f, /* i : background music flag Q0*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy */ + Word32 frame_energy, /* i : current frame energy scale*/ + Word32 update_flag, /* i : update flag Q0*/ + Word16 music_backgound_f, /* i : background music flag Q0*/ Word32 snr /* Q25 */ ) { diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index eafe13f5301876636a605a3c5b5f428abf2df51f..b9c56e401cf126f9496ff5c219dc6da4409fb48d 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -27,27 +27,27 @@ /*======================================================================*/ -/* FUNCTION : Pit_exc_contribution_len_fx() */ +/* FUNCTION : Pit_exc_contribution_len_fx() */ /*----------------------------------------------------------------------*/ /* PURPOSE : Determine up to which band the pit contribution is significant*/ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : encoder static memory */ -/* _ (Word16[]) dct_res : DCT of residual Qnew */ -/* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */ -/* _ (Word16[]) pitch_buf : Pitch per subframe Q6 */ -/* _ (Word16[]) nb_subfr : Number of subframe considered */ -/* _ (Word16) hangover : hangover for the time contribution switching*/ -/* _ (Word16) Qnew : */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) dct_res : DCT of residual Qnew */ -/* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */ -/*-----------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* INPUT ARGUMENTS : */ +/* _ (Struct) st_fx : encoder static memory */ +/* _ (Word16[]) dct_res : DCT of residual Qnew */ +/* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */ +/* _ (Word16[]) pitch_buf : Pitch per subframe Q6 */ +/* _ (Word16[]) nb_subfr : Number of subframe considered */ +/* _ (Word16) hangover : hangover for the time contribution switching*/ +/* _ (Word16) Qnew : */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) dct_res : DCT of residual Qnew */ +/* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */ +/*----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ /* o : bin where pitch contribution is significant */ Word16 Pit_exc_contribution_len_fx( @@ -56,7 +56,7 @@ Word16 Pit_exc_contribution_len_fx( Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/ Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ) { Word16 corr_dct_pit[MBANDS_LOC]; @@ -89,7 +89,15 @@ Word16 Pit_exc_contribution_len_fx( move16(); } - minimum_fx( pitch_buf, nb_subfr, &low_pit ); + 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 + { + minimum_fx( pitch_buf, nb_subfr, &low_pit ); + } + exp1 = norm_s( low_pit ); tmp = shl( low_pit, exp1 ); tmp_dec = 12800; @@ -381,378 +389,14 @@ 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 */ - for ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) + FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) { 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 ) ) - { - if ( pit_contr_idx > 0 ) - { - pit_contr_idx = 1; - move16(); - } - - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) - { - push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); - } - } - ELSE - { - push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); - } - } - ELSE - { - push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); - } - - return last_pit_bin; -} - -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*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ - Word16 Qnew ) -{ - - Word16 corr_dct_pit[MBANDS_LOC]; - Word32 corr_tmp, L_tmp; - Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res; - Word16 freq, i, j; - Word16 last_pit_band, pit_contr_idx, last_pit_bin; - Word32 ener_res; - Word32 ener_pit; - Word16 low_pit, F1st_harm, F8th_harm; - Word16 corr_dct_pit_tmp[MBANDS_LOC]; - Word16 time_flg = 0; - Word16 Len, max_len; - Word16 tmp_dec; - Word16 Mbands_loc = MBANDS_LOC - 2; - Word16 exp1, tmp, exp2; - Word32 L_tmp1, ener_init; - Word16 exp_norm; - Word16 norm; - Word16 val_thrs; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - move16(); - - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Mbands_loc = MBANDS_LOC; - move16(); - } - - minimum_fx( pitch_buf, nb_subfr, &low_pit ); - exp1 = norm_s( low_pit ); - tmp = shl( low_pit, exp1 ); - tmp_dec = 12800; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - tmp_dec = 16000; - move16(); - } - /*F1st_harm = (12800.0f|160000.f)/low_pit;*/ - tmp = div_s( tmp_dec, tmp ); /*15-6-exp1(->9-exp1)*/ - F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/ - - /*F8th_harm = 8.0f*F1st_harm;*/ - F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/ - - freq = 0; - move16(); - ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5) 2*Qnew*/ - FOR( i = 0; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ - { - corr_tmp = L_deposit_l( 0 ); - ener_res = L_add( ener_init, 0 ); - ener_pit = L_add( ener_init, 0 ); - - FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */ - { - tmp_ex = mult_r( dct_pitex[j + freq], 8192 ); - tmp_res = mult_r( dct_res[j + freq], 8192 ); - corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/ - ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/ - ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/ - } - - L_tmp1 = Mult_32_32( ener_res, ener_pit ); - exp2 = norm_l( L_tmp1 ); - L_tmp1 = L_shl( L_tmp1, exp2 ); - exp_norm = sub( 30, exp2 ); - L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm ); - norm = extract_h( L_tmp1 ); /*15-exp_norm*/ - L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm ); - corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/ - - freq = add( freq, mfreq_bindiv_loc[i] ); - } - - val_thrs = 8192; - move16(); /* 0.5 in Q14*/ - /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/ - tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/ - tmp = s_max( tmp, val_thrs ); /*Qnew */ - - corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ - move16(); - - FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */ - { - L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q_new + 16 */ - L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q_new + 16 */ - - tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q_new */ - tmp = s_max( tmp, val_thrs ); /* Q_new */ - - corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ - move16(); - } - tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/ - tmp = s_max( tmp, val_thrs ); /* Q_new */ - corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ - move16(); - - Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); /* Q_new + 1 */ - - L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/ - FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */ - { - L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); /* Q_new + 16 */ - } - av_corr = round_fx( L_tmp1 ); /*Qnew*/ - - /* Find the cut-off freq similarly to HSX */ - last_pit_band = 0; - move16(); - av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/ - - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - /*av_corr *= 1.25f;*/ - av_corr = add( av_corr, shr( av_corr, 2 ) ); - } - test(); - if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/ - } - min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/ - - FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */ - { - ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/ - - IF( LT_16( ftmp, min_corr ) ) - { - last_pit_band = i; - move16(); - min_corr = ftmp; - move16(); - } - } - - IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) ) - { - DO - { - last_pit_band = add( last_pit_band, 1 ); - } - WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) ); - } - if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) - { - last_pit_band = s_max( last_pit_band, 7 ); - } - test(); - test(); - test(); - IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/ - { - last_pit_band = 7 + BAND1k2; - move16(); - } - ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) ) - { - last_pit_band = add( 10, BAND1k2 ); - } - - time_flg = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) ) - { - tmp_dec = 1; - move16(); - } - ELSE - { - tmp_dec = 0; - move16(); - } - - /* Different past and current decision */ - test(); - test(); - test(); - IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) ) - { - IF( *hangover == 0 ) - { - time_flg = tmp_dec; - move16(); - *hangover = HANGOVER_DELAY; - move16(); - } - ELSE - { - time_flg = 0; - move16(); - if ( hGSCEnc->mem_last_pit_band > 0 ) - { - time_flg = 1; - move16(); - } - - ( *hangover ) = sub( ( *hangover ), 1 ); /* Q0 */ - if ( *hangover < 0 ) - { - *hangover = 0; - move16(); - } - } - } - ELSE - { - time_flg = tmp_dec; - move16(); - *hangover = HANGOVER_DELAY; - move16(); - } - - /* Decicison on final length of time contribution */ - pit_contr_idx = 0; - move16(); - test(); - test(); - IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech ) - { - test(); - test(); - /*if(st_fx->core_brate core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 /* 64 in Q6 */ ) ) - { - last_pit_band = add( 9, BAND1k2 ); - if ( EQ_16( st_fx->bwidth, NB ) ) - { - last_pit_band = add( 7, BAND1k2 ); - } - } - ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 /* 128 in Q6 */ ) ) - { - last_pit_band = add( 5, BAND1k2 ); - } - ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - last_pit_band = add( 3, BAND1k2 ); - } - ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) ) - { - last_pit_band = add( BAND1k2, 1 ); - } - last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q15 */ - move16(); - - st_fx->bpf_off = 0; - move16(); - - max_len = sub( st_fx->L_frame, last_pit_bin ); - - if ( EQ_16( st_fx->bwidth, NB ) ) - { - max_len = sub( 160, last_pit_bin ); - } - - Len = 80; - move16(); - if ( LT_16( max_len, 80 ) ) - { - Len = max_len; - move16(); - } - test(); - IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) ) - { - move16(); /*ptr init*/ - FOR( i = 0; i < max_len; i++ ) - { - dct_pitex[i + last_pit_bin] = 0; - move16(); - } - } - ELSE - { - - FOR( i = 0; i < Len; i++ ) - { - dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */ - } - FOR( ; i < max_len; i++ ) - { - dct_pitex[i + last_pit_bin] = 0; - move16(); - } - } - hGSCEnc->mem_last_pit_band = last_pit_band; - move16(); - pit_contr_idx = sub( last_pit_band, BAND1k2 ); - } - ELSE - { - set16_fx( dct_pitex, 0, st_fx->L_frame ); - st_fx->bpf_off = 1; - move16(); - last_pit_bin = 0; - move16(); - last_pit_band = 0; - move16(); - pit_contr_idx = 0; - move16(); - hGSCEnc->mem_last_pit_band = 0; - move16(); - - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k ); - /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ - FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) - { - 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 ) ) diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 8e9a82378ad94cb3d5046e9e4943f57a63ef1be7..8133da6e55207f654fe6f13695de850d71752a75 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -29,10 +29,10 @@ static void configure_core_coder_loc( Encoder_State *st ); *-------------------------------------------------------------------*/ ivas_error evs_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *data, /* i : input signal Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *data, /* i : input signal Q0*/ Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ - const Word16 n_samples /* i : number of input samples Q0*/ + const Word16 n_samples /* i : number of input samples Q0*/ ) { Word16 i, input_frame, delay; @@ -43,8 +43,6 @@ 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 */ @@ -79,9 +77,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,12 +90,11 @@ ivas_error evs_enc_fx( Q_shb_spch = 0; move16(); /* to avoid compiler warnings */ - /*------------------------------------------------------------------* * Initializiation *-----------------------------------------------------------------*/ - input_frame = st->input_frame_fx; + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); st->core = -1; move16(); @@ -176,19 +170,17 @@ 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 ); + 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, + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #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, pitch_orig, A, Aw, 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 ); #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 +252,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 +260,12 @@ ivas_error evs_enc_fx( IF( EQ_16( st->core, ACELP_CORE ) ) { - 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 ); + 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; + } } + /*---------------------------------------------------------------------* * HQ core encoding *---------------------------------------------------------------------*/ @@ -283,6 +278,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 ) ) @@ -314,7 +310,7 @@ ivas_error evs_enc_fx( bwe_exc_extended, voice_factors, pitch_buf, vad_hover_flag, &Q_new, &shift ); #ifndef FIX_I4_OL_PITCH - Copy( pitch_orig, st->pitch, 3 ); /* populate the original OL pitch values back Q0*/ + Copy( pitch_orig, st->pitch, 3 ); /* populate the original OL pitch values back Q0*/ #endif /*---------------------------------------------------------------------* @@ -420,15 +416,18 @@ ivas_error evs_enc_fx( IF( GE_32( st->input_Fs, 16000 ) && ( LT_16( st->bwidth, SWB ) ) ) { /* Common pre-processing for WB TBE and WB BWE */ +#ifdef HARMONIZE_TBE2 + wb_pre_proc_fx( st, EVS_MONO, new_inp_resamp16k, hb_speech ); +#else wb_pre_proc_fx( st, new_inp_resamp16k, hb_speech ); /* o: new_inp_resamp16k at Q = -1 */ +#endif } IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ - wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); - + wb_tbe_enc_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); IF( EQ_16( st->codec_mode, MODE2 ) ) { tbe_write_bitstream_fx( st ); @@ -437,18 +436,27 @@ ivas_error evs_enc_fx( ELSE IF( EQ_16( st->extl, WB_BWE ) ) { /* WB BWE encoder */ +#ifdef HARM_FD_BWE + wb_bwe_enc_fx( st, new_inp_resamp16k ); +#else wb_bwe_enc_fx( st, new_inp_resamp16k, st->coder_type ); +#endif } /*---------------------------------------------------------------------* * SWB(FB) TBE encoding * SWB BWE encoding *---------------------------------------------------------------------*/ + test(); IF( !st->Opt_SC_VBR && GE_32( st->input_Fs, 32000 ) ) { /* Common pre-processing for SWB(FB) TBE and SWB BWE */ +#ifdef HARMONIZE_TBE2 + swb_pre_proc_fx( st, new_swb_speech, shb_speech, realBuffer, imagBuffer, 0, &cldfbScale, NULL ); +#else swb_pre_proc_fx( st, st->input_fx, new_swb_speech, shb_speech, &Q_shb_spch, realBuffer, imagBuffer, &cldfbScale ); +#endif } ELSE IF( GE_32( st->input_Fs, 32000 ) ) { @@ -473,7 +481,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ - fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); + fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc, 0 ); } IF( EQ_16( st->codec_mode, MODE2 ) ) @@ -509,7 +517,11 @@ ivas_error evs_enc_fx( ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) ) { /* SWB BWE encoder */ +#ifdef HARM_FD_BWE + swb_bwe_enc_fx( st, EVS_MONO, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, 0, shb_speech, Q_shb_spch, sub( Q_new, 1 ) ); +#else swb_bwe_enc_fx( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, st->coder_type, Q_shb_spch, sub( Q_new, 1 ) ); +#endif } ELSE IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) { @@ -531,9 +543,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 ) ) { @@ -619,7 +635,6 @@ static void initFrameHeader_loc( Encoder_State *st ) } ELSE { - // PMT("Frame header needs review") FOR( n = 0; n < FRAME_SIZE_NB; n++ ) { IF( EQ_16( FrameSizeConfig[n].frame_bits, st->bits_frame_nominal ) ) @@ -643,9 +658,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 20d18c7796b4dd86b8f12380900ba14952119694..744ed3f924931e0b07e65545a9932e36b2b0f112 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -1,18 +1,16 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #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 /*-------------------------------------------------------------------* @@ -110,7 +108,6 @@ void core_signal_analysis_high_bitrate_fx( } IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - // PMT("tcx_ltp_encode_fx should be verified for IVAS") tcx_ltp_encode_fx( hTcxEnc->tcxltp, (Word8) st->tcxonly, hTcxEnc->tcxMode, L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc, hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc, @@ -178,7 +175,7 @@ void core_signal_analysis_high_bitrate_fx( alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); /* Q0 */ alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); /* Q15 */ } - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame Q0*/ + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame Q0*/ move16(); IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) @@ -188,7 +185,7 @@ void core_signal_analysis_high_bitrate_fx( transform_type[0] = TCX_20; transform_type[1] = TCX_20; move16(); - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame Q0*/ + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -248,7 +245,7 @@ void core_signal_analysis_high_bitrate_fx( move16(); } } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame Q0*/ + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); } IF( NE_16( transform_type[0], TCX_20 ) ) @@ -409,10 +406,19 @@ void core_signal_analysis_high_bitrate_fx( { test(); test(); +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); +#else + TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, + st->hTcxCfg->tcx_coded_lines, + transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ), + spectrum[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + { EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno], param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno ); @@ -427,7 +433,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 ); } /*--------------------------------------------------------------* @@ -447,7 +453,7 @@ void core_signal_analysis_high_bitrate_fx( adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, epsP, M, NULL ); + E_LPC_lev_dur_fx( r_h[frameno], r_l[frameno], A, epsP, M, NULL ); E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M ); } @@ -457,7 +463,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 */ } } @@ -602,7 +608,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 */ @@ -651,7 +657,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); // Q15 } - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame Q0*/ + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame Q0*/ move16(); IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) @@ -662,7 +668,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( move16(); transform_type[1] = TCX_20; move16(); - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame Q0*/ + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -722,7 +728,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( move16(); } } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame Q0*/ + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); } @@ -1135,7 +1141,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(); @@ -1201,11 +1207,19 @@ void core_signal_analysis_high_bitrate_ivas_fx( test(); IF( ( frameno == 0 ) && ( st->last_core == ACELP_CORE ) ) { +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 1, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); +#else + TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 1, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT } ELSE { +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 0, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); +#else + TNSAnalysis_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 0, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL ); +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT } IF( st->hTcxCfg->fIsTNSAllowed ) @@ -1224,7 +1238,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 ); } /*--------------------------------------------------------------* @@ -1245,7 +1259,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, NULL, M, NULL ); + E_LPC_lev_dur_fx( r_h[frameno], r_l[frameno], A, NULL, M, NULL ); E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M ); } @@ -1262,7 +1276,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/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 0bbbdcbd7ea7b30f7e379e0bb65d68f48999bec5..5075dd46cbf3b31293a9fd40614c2c047f775e38 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "wmc_auto.h" @@ -10,9 +10,7 @@ #include "ivas_cnst.h" #include "stl.h" #include "rom_com.h" -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG #include "ivas_rom_com.h" -#endif #include "rom_enc.h" #include "prot_fx.h" #include "prot_fx_enc.h" @@ -38,26 +36,33 @@ extern void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twidd /************************************* * Create an instance of type FD_CNG * *************************************/ -void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) +ivas_error createFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ) { HANDLE_FD_CNG_ENC hs; + ivas_error error; /* Allocate memory */ - hs = (HANDLE_FD_CNG_ENC) calloc( 1, sizeof( FD_CNG_ENC ) ); - move16(); + IF( ( hs = (HANDLE_FD_CNG_ENC) malloc( sizeof( FD_CNG_ENC ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG ENC structure" ); + } + IF( ( error = createFdCngCom_fx( &( hs->hFdCngCom ) ) ) != IVAS_ERR_OK ) + { + return error; + } - createFdCngCom_fx( &( hs->hFdCngCom ) ); *hFdCngEnc = hs; move16(); - return; + return IVAS_ERR_OK; } void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, - Word32 input_Fs, /* Q0 */ - Word16 scale ) + const Word32 input_Fs, /* Q0 */ + const Word16 scale ) { Word16 j; HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; @@ -149,16 +154,11 @@ void initFdCngEnc_fx( hsEnc->msPeriodogBufPtr = 0; move16(); set32_fx( hsEnc->msPsdSecondMoment_fx, 0, NPART ); -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG FOR( Word16 i = 0; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ ) { set32_fx( hsEnc->mem_coherence_fx[i], EPSILON_FX, 4 ); set16_fx( hsEnc->mem_coherence_exp[i], 0, 4 ); } -#else - set32_fx( hsEnc->mem_coherence_fx, EPSILON_FX, 4 ); - set16_fx( hsEnc->mem_coherence_exp, 0, 4 ); -#endif return; } @@ -166,9 +166,11 @@ void initFdCngEnc_fx( /************************************ * Configure FD_CNG * ************************************/ -void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - Word16 bandwidth, /* i: bandwidth Q0*/ - Word32 bitrate /* Q0 */ + +void configureFdCngEnc_fx( + HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ + const Word16 bandwidth, /* i: bandwidth Q0*/ + const Word32 bitrate /* Q0 */ ) { HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; @@ -290,6 +292,8 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); hsCom->frameSize = shr( hsCom->fftlen, 1 ); move16(); + + return; } void configureFdCngEnc_ivas_fx( @@ -427,12 +431,14 @@ void configureFdCngEnc_ivas_fx( return; } + /************************************** * Delete the instance of type FD_CNG * **************************************/ -void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) -{ +void deleteFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ) +{ HANDLE_FD_CNG_ENC hsEnc; hsEnc = *hFdCngEnc; move16(); @@ -443,6 +449,8 @@ void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) *hFdCngEnc = NULL; move16(); } + + return; } @@ -544,7 +552,7 @@ void resetFdCngEnc_fx( Returns: void */ -void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ +void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, @@ -708,17 +716,17 @@ void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in void */ Word16 AdjustFirstSID_fx( - Word16 npart, /* i : number of parts Q0*/ - Word32 *msPeriodog, /* i : pointer to periodog vector msPeriodog_exp */ - Word16 msPeriodog_exp, /* i : exponent of periodog vector */ - Word32 *energy_ho, /* i/o : pointer to energy energy_ho_exp*/ - Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ - Word32 *msNoiseEst, /* i/o : pointer to estimated noise msNoiseEst_exp*/ - Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ - Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise msNoiseEst_old_exp*/ - Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ - Word16 *active_frame_counter, /* i/o : pointer to active frame counter Q0*/ - Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ + Word16 npart, /* i : number of parts Q0*/ + Word32 *msPeriodog, /* i : pointer to periodog vector msPeriodog_exp */ + Word16 msPeriodog_exp, /* i : exponent of periodog vector */ + Word32 *energy_ho, /* i/o : pointer to energy energy_ho_exp*/ + Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ + Word32 *msNoiseEst, /* i/o : pointer to estimated noise msNoiseEst_exp*/ + Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ + Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise msNoiseEst_old_exp*/ + Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ + Word16 *active_frame_counter, /* i/o : pointer to active frame counter Q0*/ + Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ ) { Word16 i, sc, s1, s2, lambda, lambdaM1, invFac; @@ -851,7 +859,7 @@ Word16 AdjustFirstSID_fx( void */ static void msvq_encoder( const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) scaled with 8 bits Q9.7*/ - Word16 u[], /* i : Vector to be encoded (prediction and mean removed) Q9.7*/ + Word16 u[], /* i : Vector to be encoded (prediction and mean removed) Q9.7*/ const Word16 levels[], /* i : Number of levels in each stage Q0*/ Word16 maxC, /* i : Tree search size Q0*/ Word16 stages, /* i : Number of stages Q0*/ @@ -1190,7 +1198,6 @@ void FdCng_encodeSID_fx( HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG stru maxVal = L_add( maxVal, gain ); maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); - // PMT("st must be replaced by hFdCngCom") sidNoiseEst_Exp = 0; move16(); WHILE( maxVal >= 0 ) @@ -2141,7 +2148,7 @@ Word16 cng_energy_ivas_fx( const Word16 element_mode, /* i : element mode Q0*/ const Word16 bwidth, /* i : audio bandwidh Q0*/ const Word16 CNG_mode, /* i : mode for DTX configuration Q0*/ - const Word16 CNG_att, /* i : attenuation factor for CNG Q7*/ + const Word16 CNG_att, /* i : attenuation factor for CNG Q7*/ const Word16 *exc, /* i : input signal Q_new*/ const Word16 len, /* i : vector length */ const Word16 Q_new /* i : Input scaling */ @@ -2198,7 +2205,6 @@ Word16 cng_energy_ivas_fx( test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) || EQ_16( element_mode, IVAS_CPE_TD ) ) { - // PMT(" IVAS CNG ener computing is missing") enr = add( enr, mult( CNG_att, FAC_LOG2_BY10_Q16 ) ); /* Q8 (7+16-15) */ } ELSE IF( NE_16( bwidth, NB ) ) @@ -2229,7 +2235,7 @@ Word16 cng_energy_ivas_fx( } void perform_noise_estimation_enc_ivas_fx( - Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ + Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, @@ -2673,16 +2679,11 @@ void stereoFdCngCoherence_fx( IF( NE_16( last_element_mode, IVAS_CPE_MDCT ) ) { -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG FOR( i = 0; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ ) { set32_fx( sts[0]->hFdCngEnc->mem_coherence_fx[i], EPSILON_FX, 4 ); set16_fx( sts[0]->hFdCngEnc->mem_coherence_exp[i], 0, 4 ); } -#else - set32_fx( sts[0]->hFdCngEnc->mem_coherence_fx, EPSILON_FX, 4 ); - set16_fx( sts[0]->hFdCngEnc->mem_coherence_exp, 0, 4 ); -#endif } test(); test(); @@ -2747,10 +2748,6 @@ void stereoFdCngCoherence_fx( pt_fftL = fft_buf_fx[0]; pt_fftR = fft_buf_fx[1]; -#ifndef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG - mem = sts[0]->hFdCngEnc->mem_coherence_fx; /* exp(sts[0]->hFdCngEnc->mem_coherence_exp) */ - mem_exp = sts[0]->hFdCngEnc->mem_coherence_exp; -#endif /* only estimate coherence in inactive frames (or in the first 50 frames to build an initial value) */ test(); @@ -2761,7 +2758,6 @@ void stereoFdCngCoherence_fx( return; } -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG FOR( i_subfr = 0; i_subfr < 2; i_subfr++ ) { Word16 band_len_cum; @@ -2836,59 +2832,6 @@ void stereoFdCngCoherence_fx( pt_fftR += L_FFT; } -#else - FOR( i_subfr = 0; i_subfr < 2; i_subfr++ ) - { - cr = ci = eL = eR = EPSILON_FX; - move32(); - move32(); - move32(); - move32(); - cr_exp = ci_exp = eL_exp = eR_exp = 0; - move16(); - move16(); - move16(); - move16(); - - cr = BASOP_Util_Add_Mant32Exp( cr, cr_exp, L_add( L_mult( pt_fftL[0], pt_fftR[0] ), L_mult( pt_fftL[L_FFT / 2], pt_fftR[L_FFT / 2] ) ), shl( fft_exp, 1 ), &cr_exp ); /* exp(cr_exp) */ - eL = BASOP_Util_Add_Mant32Exp( eL, eL_exp, L_add( L_mult( pt_fftL[0], pt_fftL[0] ), L_mult( pt_fftL[L_FFT / 2], pt_fftL[L_FFT / 2] ) ), shl( fft_exp, 1 ), &eL_exp ); /* exp(eL_exp) */ - eR = BASOP_Util_Add_Mant32Exp( eR, eR_exp, L_add( L_mult( pt_fftR[0], pt_fftR[0] ), L_mult( pt_fftR[L_FFT / 2], pt_fftR[L_FFT / 2] ) ), shl( fft_exp, 1 ), &eR_exp ); /* exp(eR_exp) */ - - FOR( i = 1; i < L_FFT / 2; i++ ) - { - cr = BASOP_Util_Add_Mant32Exp( cr, cr_exp, L_add( L_mult( pt_fftL[i], pt_fftR[i] ), L_mult( pt_fftL[L_FFT - i], pt_fftR[L_FFT - i] ) ), shl( fft_exp, 1 ), &cr_exp ); /* exp(cr_exp) */ - ci = BASOP_Util_Add_Mant32Exp( ci, ci_exp, L_add( L_mult( -pt_fftL[i], pt_fftR[L_FFT - i] ), L_mult( pt_fftL[L_FFT - i], pt_fftR[i] ) ), shl( fft_exp, 1 ), &ci_exp ); /* exp(ci_exp) */ - eL = BASOP_Util_Add_Mant32Exp( eL, eL_exp, L_add( L_mult( pt_fftL[i], pt_fftL[i] ), L_mult( pt_fftL[L_FFT - i], pt_fftL[L_FFT - i] ) ), shl( fft_exp, 1 ), &eL_exp ); /* exp(eL_exp) */ - eR = BASOP_Util_Add_Mant32Exp( eR, eR_exp, L_add( L_mult( pt_fftR[i], pt_fftR[i] ), L_mult( pt_fftR[L_FFT - i], pt_fftR[L_FFT - i] ) ), shl( fft_exp, 1 ), &eR_exp ); /* exp(eR_exp) */ - } - test(); - test(); - IF( LE_32( sts[0]->ini_frame, 50 ) || ( sts[0]->vad_flag == 0 && sts[1]->vad_flag == 0 ) ) - { - mem[0] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[0], 31129 /*0.95f*/ ), mem_exp[0], Mpy_32_16_1( cr, 1638 /*0.05f*/ ), cr_exp, &mem_exp[0] ); /* exp(mem_exp[0]) */ - move32(); - mem[1] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[1], 31129 /*0.95f*/ ), mem_exp[1], Mpy_32_16_1( ci, 1638 /*0.05f*/ ), ci_exp, &mem_exp[1] ); /* exp(mem_exp[1]) */ - move32(); - mem[2] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[2], 31129 /*0.95f*/ ), mem_exp[2], Mpy_32_16_1( eL, 1638 /*0.05f*/ ), eL_exp, &mem_exp[2] ); /* exp(mem_exp[2]) */ - move32(); - mem[3] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[3], 31129 /*0.95f*/ ), mem_exp[3], Mpy_32_16_1( eR, 1638 /*0.05f*/ ), eR_exp, &mem_exp[3] ); /* exp(mem_exp[3]) */ - move32(); - } - - pt_fftL += L_FFT; - pt_fftR += L_FFT; - } -#endif - -#ifndef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG - Word16 sqr_inp, temp, sqr_out, sqr_inp_exp; - Word32 sqr_inp32 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( mem[0], mem[0] ), shl( mem_exp[0], 1 ), Mpy_32_32( mem[1], mem[1] ), shl( mem_exp[1], 1 ), &sqr_inp_exp ); /* exp(sqr_inp_exp) */ - sqr_inp = BASOP_Util_Divide3232_Scale( sqr_inp32, Mpy_32_32( mem[2], mem[3] ), &temp ); - sqr_inp_exp = add( temp, sub( sqr_inp_exp, add( mem_exp[2], mem_exp[3] ) ) ); - sqr_out = Sqrt16( sqr_inp, &sqr_inp_exp ); - sts[0]->hFdCngEnc->hFdCngCom->coherence_fx = shl_sat( sqr_out, sqr_inp_exp ); // Q15 expected. - move16(); -#endif return; } @@ -3162,11 +3105,7 @@ void FdCngEncodeMDCTStereoSID_fx( } /* quantize channel coherence */ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG coh_idx = mult_r( sts[0]->hFdCngEnc->hFdCngCom->coherence_fx[0], 15 ); -#else - coh_idx = mult_r( sts[0]->hFdCngEnc->hFdCngCom->coherence_fx, 15 ); -#endif coh_idx = s_max( 0, s_min( coh_idx, 15 ) ); /* ---- Write SID bitstream ---- */ @@ -3200,7 +3139,6 @@ void FdCngEncodeMDCTStereoSID_fx( push_indice( sts[ch]->hBstr, IND_ENERGY, gain_idx[ch], 7 ); } -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* write the four additional coherence values */ FOR( Word16 b = 1; b < MDCT_ST_DTX_NUM_COHERENCE_BANDS; b++ ) { @@ -3208,10 +3146,6 @@ void FdCngEncodeMDCTStereoSID_fx( coh_idx = s_max( 0, s_min( coh_idx, 15 ) ); push_indice( sts[1]->hBstr, IND_ENERGY, coh_idx, 4 ); } -#else - /* pad with zeros to reach common SID frame size */ - push_indice( sts[1]->hBstr, IND_ENERGY, 0, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); -#endif return; } @@ -3326,7 +3260,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( extend_dctN_input_fx( ms_ptr_fx[0], dct_target_fx, N[0], tot_sig_ext_fx, FDCNG_VQ_MAX_LEN, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); /* use 18 basis vectors*/ - Copy32( tot_sig_ext_fx, ms_ptr_fx[0], FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 Q23*/ + Copy32( tot_sig_ext_fx, ms_ptr_fx[0], FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 Q23*/ } create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); @@ -3382,7 +3316,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( { pow = L_shl( gain_fx[ch], sub( 8, ms_ptr_e ) ); /* Q31 - ms_ptr_e */ pow = L_add( ms_ptr_fx[ch][p], pow ); /* Q31 - ms_ptr_e */ - pow = Mpy_32_32( pow, 214748365 /* 0.1 in Q31 */ ); /*pow = 0.1 Q31 - ms_ptr_e*/ + pow = Mpy_32_32( pow, 214748365 /* 0.1 in Q31 */ ); /*pow = 0.1 Q31 - ms_ptr_e*/ lr_out_ptr_fx[ch][p] = BASOP_Util_fPow( 10, 31, pow, ms_ptr_e, &e_lr_out[p] ); tmp_e = s_max( tmp_e, e_lr_out[p] ); } @@ -3415,17 +3349,11 @@ void FdCngEncodeDiracMDCTStereoSID_fx( lpc_from_spectrum( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac ); sts[ch]->hDtxEnc->last_CNG_L_frame = sts[ch]->L_frame; } -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG + sts[0]->hFdCngEnc->hFdCngCom->coherence_fx[0] = 0; move16(); sts[1]->hFdCngEnc->hFdCngCom->coherence_fx[0] = 0; move16(); -#else - sts[0]->hFdCngEnc->hFdCngCom->coherence_fx = 0; - move16(); - sts[1]->hFdCngEnc->hFdCngCom->coherence_fx = 0; - move16(); -#endif /* ---- Write SID bitstream ---- */ diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index ca3f50f115a0fb59f9479896ecf11b78c3434f99..9a236731f51865204b2cfdcd8f9a5b65b6aec7fe 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -20,7 +20,7 @@ void find_targets_fx( const Word16 *res, /* i : residual signal Q_new*/ const Word16 L_subfr, /* i : length of vectors for gain quantization Q0*/ const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15*/ + Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ @@ -31,10 +31,8 @@ void find_targets_fx( Word16 scale, scaleq, j, d, s, s2, tmp; Word16 Aqs[M + 1]; Word32 Ltmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif /*------------------------------------------------------------------------* * Find the target vector for excitation search: * @@ -114,7 +112,6 @@ void find_targets_fx( } h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ - // PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") FOR( i = M + 1; i < L_subfr; i++ ) { Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ @@ -168,7 +165,7 @@ void find_targets_ivas_fx( const Word16 *res, /* i : residual signal Q_new*/ const Word16 L_subfr, /* i : length of vectors for gain quantization Q0*/ const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15*/ + Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ Word16 *h1 /* o : impulse response of weighted synthesis filter Q(14 - norm_s(h1[0]))*/ @@ -176,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; @@ -236,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_tilt_fx.c b/lib_enc/find_tilt_fx.c index e267040991aa03cd00a47d929400681729e60a86..56ea1e9dd3f4193c9f93447498e8eba77adad866 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -16,19 +16,19 @@ *-------------------------------------------------------------------*/ void find_tilt_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ + const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth Q0*/ - const Word16 max_band, /* i : maximum critical band Q0*/ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 max_band, /* i : maximum critical band Q0*/ Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise Q16*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ + const Word16 Q_new, /* i : scaling factor */ + Word32 *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise Q16*/ Word16 Opt_vbr_mode /* Q0 */ ) { @@ -216,7 +216,7 @@ void find_tilt_fx( Ltmp = L_shl_sat( ee[i], 3 ); IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { - Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ + Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ ee[i] = L_shl_sat( Ltmp, 3 ); move32(); /* x8 */ } @@ -240,16 +240,16 @@ void find_tilt_fx( * Find LF/HF energy ratio *-------------------------------------------------------------------*/ void find_tilt_ivas_fx( - const Word32 fr_bands[], /* i : energy in frequency bands q_fr_bands*/ - const Word16 q_fr_bands, /* i : Q of fr_bands Q0*/ + const Word32 fr_bands[], /* i : energy in frequency bands q_fr_bands*/ + const Word16 q_fr_bands, /* i : Q of fr_bands Q0*/ const Word32 bckr[], /* i : per band background noise energy estimate q_bckr*/ const Word16 q_bckr, /* i : Q of bckr Q0*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies q_lf_E*/ const Word16 q_lf_E, /* i : Q of lf_E */ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ const Word16 bwidth, /* i : input signal bandwidth */ const Word16 max_band, /* i : maximum critical band */ Word32 hp_E[], /* o : energy in HF Q_new*/ @@ -413,7 +413,7 @@ void find_tilt_ivas_fx( lp_E = W_extract_h( W_shl( sum, q_lp_E ) ); // q_bckr+1+q_lp_E-32 q_lp_E = sub( add( q_lp_E, q_bckr ), Q31 ); - pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame Q_new - 1 */ + pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame Q_new - 1 */ } ELSE /* Other than high-pitched voiced frames */ { @@ -466,7 +466,7 @@ void find_tilt_ivas_fx( Ltmp = L_shl_sat( ee[i], 3 ); /* Q6 */ IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { - Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ + Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ ee[i] = L_shl_sat( Ltmp, 3 ); /* Q6 */ move32(); /* x8 */ } diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 8554b03dd54fadbfadfc9a78ac3b463ef3beb587..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 Aug 12, 2021. Version 16.3.0 + 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 155e499046dd1ead55fbc5fc7bf4f87eb4edd434..a16f1a95c1a0f5fc4fe36566d4d8a53b20136797 100644 --- a/lib_enc/find_wsp_fx.c +++ b/lib_enc/find_wsp_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -14,12 +14,12 @@ * find_wsp_fx * * Parameters: - * Az I: A(z) filter coefficients Q12 + * Az I: A(z) filter coefficients Q12 * speech I: pointer to the denoised speech frame Q_new - preemph_bits * wsp O: pointer to the weighted speech frame Q_new - preemph_bits - * mem_wsp I/O: W(z) denominator memory + * mem_wsp I/O: W(z) denominator memory * preemph_fac I: pre-emphasis factor Q15 - * L_frame I: length of the frame + * L_frame I: length of the frame * lookahead I: length of a look-ahead * L_subfr I: length of the sub-frame * @@ -30,17 +30,17 @@ * void */ void find_wsp_fx( - const Word16 Az[], /* i : A(z) filter coefficients Q12*/ - const Word16 speech[], /* i : pointer to the denoised speech frame Q_new-preemph_bits*/ - Word16 wsp[], /* o : poitnter to the weighted speech frame Q_new-preemph_bits*/ - Word16 *mem_wsp, /* i/o: W(Z) denominator memory Q_new-preemph_bits*/ - const Word16 preemph_fac, /* i : pre - emphasis factor Q15*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 lookahead, /* i : look-ahead Q0*/ - const Word16 L_subfr, /* i : length of subframe Q0*/ - Word16 *Aw, /* o : weighted A(z) filter coefficients Q12*/ - const Word16 gamma, /* i : weighting factor Q15*/ - const Word16 nb_subfr /* i : number of subframes Q0*/ + const Word16 Az[], /* i : A(z) filter coefficients Q12*/ + const Word16 speech[], /* i : pointer to the denoised speech frame Q_new-preemph_bits*/ + Word16 wsp[], /* o : poitnter to the weighted speech frame Q_new-preemph_bits*/ + Word16 *mem_wsp, /* i/o: W(Z) denominator memory Q_new-preemph_bits*/ + const Word16 preemph_fac, /* i : pre - emphasis factor Q15*/ + const Word16 L_frame, /* i : length of the frame Q0*/ + const Word16 lookahead, /* i : look-ahead Q0*/ + const Word16 L_subfr, /* i : length of subframe Q0*/ + Word16 *Aw, /* o : weighted A(z) filter coefficients Q12*/ + const Word16 gamma, /* i : weighting factor Q15*/ + const Word16 nb_subfr /* i : number of subframes Q0*/ ) { Word16 i_subfr, wtmp; @@ -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/frame_spec_dif_cor_rate_fx.c b/lib_enc/frame_spec_dif_cor_rate_fx.c index 9678acdbfee4fb3d927c352c00273b9f5914e39c..54e6148af0ae94641339d7b0a962c83cf7cfd116 100644 --- a/lib_enc/frame_spec_dif_cor_rate_fx.c +++ b/lib_enc/frame_spec_dif_cor_rate_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -20,10 +20,10 @@ * *-------------------------------------------------------------------*/ void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *spec_amp, /* i : spectral amplitude scale*/ - Word16 sacle, /* i : the scaling of spec_amp */ - Word16 f_tonality_rate[3] /* o : tonality rate Qx*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude scale*/ + Word16 sacle, /* i : the scaling of spec_amp */ + Word16 f_tonality_rate[3] /* o : tonality rate Qx*/ ) { diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index e84d09e3cc963572063bfb0d36b435c9a57e6c29..3e3c763230a571a5cd5e0486d3452c7a955585a7 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -32,12 +32,12 @@ static Word16 Find_Opt_gainQ_fx( Word16 *coeff, Word16 *exp_coeff, Word16 *gain_ /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ Word16 L_frame, i : length of the frame Q0 */ -/* _ Word16 *res, i : residual signal Q_new */ +/* _ Word16 *res, i : residual signal Q_new */ /* _ Word16 *voicing, i : normalized correlation in three 1/2frames Q15*/ -/* _ Word16 coder_type, i : coder_type Q0 */ -/* _ Word16 bwidth, i : input signal bandwidth Q0 */ -/* _ Word32 core_brate, i : core bitrate Q0 */ -/* _ Word16 Q_new i : Scaling in speech Q0 */ +/* _ Word16 coder_type, i : coder_type Q0 */ +/* _ Word16 bwidth, i : input signal bandwidth Q0 */ +/* _ Word32 core_brate, i : core bitrate Q0 */ +/* _ Word16 Q_new i : Scaling in speech Q0 */ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ Word16 *Es_pred, o : predicited scaled innovation energy Q8 */ @@ -51,14 +51,14 @@ static Word16 Find_Opt_gainQ_fx( Word16 *coeff, Word16 *exp_coeff, Word16 *gain_ /*==========================================================================*/ void Es_pred_enc_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - Word16 *indice, /* o : indice of quantization Q0*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 *res, /* i : residual signal Q_new*/ - const Word16 *voicing, /* i : normalized correlation in three 1/2frames Q15*/ - const Word16 nb_bits, /* i : allocated number of bits Q0*/ - const Word16 no_ltp, /* i : no_ltp flag Q0*/ - Word16 Q_new /* i : Scaling in speech Q0*/ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ + Word16 *indice, /* o : indice of quantization Q0*/ + const Word16 L_frame, /* i : length of the frame Q0*/ + const Word16 *res, /* i : residual signal Q_new*/ + const Word16 *voicing, /* i : normalized correlation in three 1/2frames Q15*/ + const Word16 nb_bits, /* i : allocated number of bits Q0*/ + const Word16 no_ltp, /* i : no_ltp flag Q0*/ + Word16 Q_new /* i : Scaling in speech Q0*/ ) { Word16 i, i_subfr, size, tmp16, tmp16_2, Q_res; @@ -88,11 +88,11 @@ void Es_pred_enc_fx( FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { /* calculate the energy of residual signal */ - tmp16 = mult_r( res[i_subfr + 0], 8192 /* 1 in Q13 */ ); /* remove 2bits Q_new - 2*/ + tmp16 = mult_r( res[i_subfr + 0], 8192 /* 1 in Q13 */ ); /* remove 2bits Q_new - 2*/ ener_fx = L_mult( tmp16, tmp16 ); FOR( i = 1; i < L_SUBFR; i++ ) { - tmp16 = mult_r( res[i_subfr + i], 8192 /* 1 in Q13 */ ); /* remove 2bits Q_new - 2*/ + tmp16 = mult_r( res[i_subfr + i], 8192 /* 1 in Q13 */ ); /* remove 2bits Q_new - 2*/ ener_fx = L_mac_sat( ener_fx, tmp16, tmp16 ); } @@ -200,24 +200,24 @@ void Es_pred_enc_fx( * - the mean-squared weighted error criterion is used for codebook search *---------------------------------------------------------------------*/ void gain_enc_mless_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 gains_mode[], /* i : gain bits Q0*/ - const Word16 element_mode, /* i : element mode Q0*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 i_subfr, /* i : subframe index Q0*/ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 scaling */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - const Word16 Es_pred, /* i : predicted scaled innovation energy Q8*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 Qx*/ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 gains_mode[], /* i : gain bits Q0*/ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 L_frame, /* i : length of the frame Q0*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + const Word16 *xn, /* i : target vector Q_xn*/ + const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 Q_xn, /* i : xn and y1 scaling */ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16 *code, /* i : algebraic excitation Q9*/ + const Word16 Es_pred, /* i : predicted scaled innovation energy Q8*/ + Word16 *gain_pit, /* o : quantized pitch gain Q14*/ + Word32 *gain_code, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 Qx*/ + const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) Q0*/ ) { @@ -541,21 +541,21 @@ void gain_enc_mless_fx( *---------------------------------------------------------------------*/ void gain_enc_SQ_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, /* i : target vector Q_xn*/ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - const Word16 Es_pred, /* i : predicted scaled innovation energy Q8*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 Qx*/ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) Q0*/ - const Word16 Q_xn /* i : xn and y1 scaling */ + 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, /* i : target vector Q_xn*/ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16 *code, /* i : algebraic excitation Q9*/ + const Word16 Es_pred, /* i : predicted scaled innovation energy Q8*/ + Word16 *gain_pit, /* o : quantized pitch gain Q14*/ + Word32 *gain_code, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 Qx*/ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) Q0*/ + const Word16 Q_xn /* i : xn and y1 scaling */ ) { Word16 index, nBits_pitch, nBits_code; @@ -821,9 +821,9 @@ void gain_enc_SQ_fx( Word16 gain_enc_gaus_fx( Word32 *gain, /* i/o: Code gain to quantize Q16*/ const Word16 bits, /* i : number of bits to quantize Q0*/ - const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8*/ - const Word16 stepSize, /* i : Step size choice Q14*/ - const Word16 inv_stepSize /* i : Step size choice Q15*/ + const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8*/ + const Word16 stepSize, /* i : Step size choice Q14*/ + const Word16 inv_stepSize /* i : Step size choice Q15*/ ) { Word16 index, exp_gain, frac_gain, wtmp; @@ -878,7 +878,7 @@ Word16 gain_enc_gaus_fx( *-----------------------------------------------------------------*/ void gain_enc_tc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + 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*/ @@ -889,7 +889,7 @@ void gain_enc_tc_fx( 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 Q16*/ - const Word16 Q_xn /* i : xn and y1 scaling */ + const Word16 Q_xn /* i : xn and y1 scaling */ ) { Word16 i, index = 0, nBits, num, den, exp_num, exp_den; @@ -1079,8 +1079,8 @@ static Word16 Find_Opt_gainQ_fx( Word32 *gain_code, /* Q16 */ Word16 gcode0, /* exp(exp_gcode0) */ Word16 exp_gcode0, - const Word16 *cdbk, /* i : Codebook used Q14*/ - const Word16 size /* i : size of Codebook used Q0*/ + const Word16 *cdbk, /* i : Codebook used Q14*/ + const Word16 size /* i : size of Codebook used Q0*/ ) { Word16 index, i, j; @@ -1224,7 +1224,7 @@ static Word16 Find_Opt_gainQ_fx( *---------------------------------------------------------------------*/ void gain_enc_lbr_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits Q0*/ const Word16 coder_type, /* i : coding type Q0*/ const Word16 i_subfr, /* i : subframe index Q0*/ @@ -1240,9 +1240,9 @@ void gain_enc_lbr_fx( Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) Q0*/ - const Word16 L_subfr, /* i : subframe length Q0*/ - const Word16 element_mode /* i : mode element Q0*/ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) Q0*/ + const Word16 L_subfr, /* i : subframe length Q0*/ + const Word16 element_mode /* i : mode element Q0*/ ) { Word16 index = 0, size, nBits, n_pred, ctype; @@ -1695,20 +1695,20 @@ void gain_enc_lbr_fx( *-------------------------------------------------------------------*/ void gain_enc_amr_wb_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 Q_xn, /* i : xn and yy1 format */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - const Word32 core_brate, /* i : core bitrate Q0*/ - Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 Qx*/ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) Q0*/ - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) Q10*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 *xn, /* i : target vector Q_xn*/ + const Word16 Q_xn, /* i : xn and yy1 format */ + const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn*/ + const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ + const Word16 *code, /* i : algebraic excitation Q9*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain Q14*/ + Word32 *gain_code, /* o : quantized codebook gain Q16*/ + Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ + Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ + Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 Qx*/ + const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) Q0*/ + Word16 *past_qua_en /* i/o: gain quantization memory (4 words) Q10*/ ) { diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index fb93a67438c063fbda6678e1e59a2dd192073c2e..5c53881cd0943f595f435c5d628ce3646b1cfbb2 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -40,22 +40,22 @@ static void gauss2v_fx( BSTR_ENC_HANDLE hBstr, const Word16 h[], const Word16 xn *-------------------------------------------------------------------*/ Word16 gaus_encode_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*/ + 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*/ ) { Word16 nb_bits, idx; @@ -259,7 +259,7 @@ void gauss2v_fx( Den = extract_h( L_shl( Lden, exp_den ) ); delta = shr_sat( div_s( Num, Den ), sub( exp_num, exp_den ) ); /* Q15 */ - delta = i_mult2( delta, m_sign ); /* Apply sign Q0*/ + delta = i_mult2( delta, m_sign ); /* Apply sign Q0*/ /* index_delta = (short)(FAC_DELTA * fdelta) */ index_delta = shr( delta, SFAC_DELTA ); @@ -601,12 +601,12 @@ void gauss2v_fx( /*---------------------------------------------------------------------* * Put selected codevector positions and signs into quantization index *---------------------------------------------------------------------*/ -static Word16 cod_2pos_fx( /* o : codebook quantization index */ - const Word16 ind1, /* i : index of 1st gaussian vector Q0*/ - const Word16 ind2, /* i : index of 2nd gaussian vector Q0*/ - const Word16 sign1, /* i : sign of 1st gaussian vector Qx*/ - const Word16 sign2, /* i : sign of 2nd gaussian vector Qx*/ - const Word16 n /* i : nb. of codebook vectors Q0*/ +static Word16 cod_2pos_fx( /* o : codebook quantization index */ + const Word16 ind1, /* i : index of 1st gaussian vector Q0*/ + const Word16 ind2, /* i : index of 2nd gaussian vector Q0*/ + const Word16 sign1, /* i : sign of 1st gaussian vector Qx*/ + const Word16 sign2, /* i : sign of 2nd gaussian vector Qx*/ + const Word16 n /* i : nb. of codebook vectors Q0*/ ) { Word16 i1, i2, index, s1, s2; diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index 07b88103b29dc5c0f62fa32ce0c410189941d664..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -68,7 +68,7 @@ * Pitch Gain clipping initializations *-------------------------------------------------------------------*/ void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + Word16 mem[] /* o : memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ ) { mem[0] = DIST_ISF_MAX; @@ -272,10 +272,10 @@ void gp_clip_test_isf_fx( *-------------------------------------------------------------------*/ void gp_clip_test_gain_pit_fx( - const Word16 element_mode, /* i : element mode Q0*/ - const Word32 core_brate, /* i : core bitrate Q0*/ - const Word16 gain_pit, /* i : gain of quantized pitch Q14*/ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14*/ + const Word16 element_mode, /* i : element mode Q0*/ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 gain_pit, /* i : gain of quantized pitch Q14*/ + Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14*/ ) { Word16 gain; @@ -416,10 +416,10 @@ Word16 Mode2_gp_clip_fx( * check the minimum distance of LSFs for pitch gain clipping flag *-------------------------------------------------------------------*/ void gp_clip_test_lsf_fx( - const Word16 element_mode, /* i : element mode Q0*/ - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28*/ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ - const Word16 m /* i : dimension of lsf Q0*/ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28*/ + Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm [2.56x,Q14,Q8,Q0,Q14,Q14]*/ + const Word16 m /* i : dimension of lsf Q0*/ ) { Word16 i; diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 7a0d1a279b608c29f1064fb423549fd401e45548..9f140f84342a4107a9c2f6665e9faeb704081784 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 ); /*-------------------------------------------------------------------* @@ -24,23 +24,24 @@ static Word16 edyn_fx( const Word16 *vec, const Word16 lvec, Word16 Qnew ); *-------------------------------------------------------------------*/ void encod_audio_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 Q12 */ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12 */ - 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 Qx2.56 */ - 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 ) + 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 Q12 */ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12 */ + 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 Qx2.56 */ + 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 */ + 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,7 @@ 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; + Word16 Q_exc; m_mean = 0; move16(); @@ -70,375 +72,19 @@ 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(); - Es_pred = 0; - move16(); - - /*---------------------------------------------------------------* - * Encode GSC IVAS mode - * Encode GSC attack flag (used to reduce possible pre-echo) - * Encode GSC SWB speech flag - *---------------------------------------------------------------*/ - - IF( attack_flag > 0 ) - { - push_indice( hBstr, IND_GSC_ATTACK, 1, 1 ); - } - ELSE - { - push_indice( hBstr, IND_GSC_ATTACK, 0, 1 ); - } - - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( NE_16( st_fx->coder_type, INACTIVE ) && ( ( EQ_16( st_fx->element_mode, EVS_MONO ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || - ( GT_16( st_fx->element_mode, EVS_MONO ) && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) - { - 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 ) ) - { - FOR( i = 0; i < 5; i++ ) - { - test(); - if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 /*6.0 in Q8*/ ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) - { - hGSCEnc->cor_strong_limit = 0; - move16(); - } - } - } - test(); - test(); - test(); - test(); - IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->GSC_noisy_speech && st_fx->GSC_IVAS_mode == 0 ) ) - { - nb_subfr = NB_SUBFR; - move16(); - test(); - test(); - if ( st_fx->GSC_IVAS_mode > 0 && LT_16( st_fx->GSC_IVAS_mode, 3 ) && LT_32( st_fx->core_brate, GSC_L_RATE_STG ) ) - { - nb_subfr = 2; - move16(); - } - hGSCEnc->cor_strong_limit = 0; - move16(); - nb_subfr_flag = 1; - move16(); - } - ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( LE_32( st_fx->core_brate, ACELP_13k20 ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) - { - hGSCEnc->cor_strong_limit = 0; - nb_subfr = SWNB_SUBFR; - nb_subfr_flag = 1; - move16(); - move16(); - move16(); - } - ELSE - { - test(); - test(); - IF( ( hGSCEnc->cor_strong_limit == 0 || EQ_16( st_fx->coder_type, INACTIVE ) ) && GE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - nb_subfr = 2; - move16(); - nb_subfr_flag = 0; - move16(); - hGSCEnc->cor_strong_limit = 0; - move16(); - } - ELSE - { - nb_subfr = SWNB_SUBFR; - move16(); - nb_subfr_flag = 1; - move16(); - } - - test(); - test(); - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) - { - nb_subfr = shl( nb_subfr, 1 ); - nb_subfr_flag = s_or( nb_subfr_flag, 0x2 ); - logic16(); - } - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) - { - push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 2 ); - } - ELSE IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - /* nb_subfr_flag can only have the value 0 or 1 */ - 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 ) ) - { - nb_subfr = NB_SUBFR16k; - move16(); - } - - /*---------------------------------------------------------------* - * Compute adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( !( st_fx->GSC_IVAS_mode > 0 && EQ_16( st_fx->L_frame, i_mult( nb_subfr, 2 * L_SUBFR ) ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && - ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && - ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) - { - IF( ( st_fx->element_mode > EVS_MONO ) ) - { - nb_bits = 5; - move16(); - } - ELSE - { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; - move16(); - } - 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 ); - } - - 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 ); - - /*---------------------------------------------------------------* - * 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++ ) - { - /*m_mean = add(m_mean,edyn_fx( dct_res+i*16, 16, Q_new )); */ - Lm_mean = L_mac( Lm_mean, edyn_fx( dct_res + i * 16, 16, Q_new ), 4096 ); /*Q7*/ - } - m_mean = round_fx( Lm_mean ); /*Q7*/ - IF( GT_16( m_mean, hGSCEnc->mid_dyn_fx ) ) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ - hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 26214, m_mean ), 6554, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ - move16(); + 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 { - /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ - hGSCEnc->mid_dyn_fx = round_fx( L_mac( L_mult( 13107, m_mean ), 19661, hGSCEnc->mid_dyn_fx ) ); /*Q7*/ - move16(); - } - IF( NE_16( st_fx->coder_type, INACTIVE ) ) - { - hGSCEnc->noise_lev = sub( ( NOISE_LEVEL_SP3 + 1 ), usquant_fx( hGSCEnc->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr( GSF_NF_DELTA_FX, 1 ), GSC_NF_STEPS ) ); - move16(); - hGSCEnc->noise_lev = s_min( hGSCEnc->noise_lev, NOISE_LEVEL_SP3 ); - move16(); - } - - hGSCEnc->past_dyn_dec = hGSCEnc->noise_lev; - move16(); - IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP2; - move16(); - IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP0; - move16(); - } - ELSE IF( st_fx->GSC_noisy_speech == 0 ) - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP3; - move16(); - } - } - ELSE IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - hGSCEnc->noise_lev = s_max( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ); - move16(); - push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ), 2 ); - } - ELSE IF( st_fx->GSC_noisy_speech ) - { - hGSCEnc->noise_lev = NOISE_LEVEL_SP3; - move16(); + Copy( hLPDmem->mem_syn, hGSCEnc->mem_syn_tmp_fx, M ); /* hLPDmem->q_mem_syn */ + hGSCEnc->mem_w0_tmp_fx = hLPDmem->mem_w0; move16(); } - ELSE - { - push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP0 ), 3 ); - } - - /*---------------------------------------------------------------* - * Find and encode the last band where the adaptive (pitch) contribution is significant - *---------------------------------------------------------------*/ - - last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); - - IF( last_pit_bin == 0 ) - { - hLPDmem->tilt_code = 0; - move16(); - } - ELSE - { - /*last_pit_bin++;*/ - last_pit_bin = add( last_pit_bin, 1 ); - } - - /*--------------------------------------------------------------------------------------* - * GSC encoder - *--------------------------------------------------------------------------------------*/ - - /* Find the current total number of bits used */ - 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 ) - { - /* add 5 bits for noisiness */ - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); - } - 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 ); - - /*--------------------------------------------------------------------------------------* - * 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 - *--------------------------------------------------------------------------------------*/ - - pre_echo_att_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_new, st_fx->last_coder_type, st_fx->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Update BWE excitation - *--------------------------------------------------------------------------------------*/ - IF( st_fx->hBWE_TD != NULL ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - set16_fx( voice_factors, 0, NB_SUBFR16k ); - interp_code_4over2_fx( exc, bwe_exc, L_FRAME16k ); - } - ELSE - { - set16_fx( voice_factors, 0, NB_SUBFR ); - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - } - } - /*--------------------------------------------------------------------------------------* - * Synthesis - *--------------------------------------------------------------------------------------*/ - - p_Aq = Aq; - FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_SUBFR ) - { - Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); - p_Aq += ( M + 1 ); - } - - /*--------------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------------*/ - - hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ - move16(); - Copy( exc_wo_nf, exc, st_fx->L_frame ); - - return; -} - -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 Q12 */ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12 */ - 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 Qx2.56 */ - Word16 *tmp_noise, /* o : noise energy Q8*/ - 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 *p_Aq; - Word16 i, i_subfr, nb_subfr, last_pit_bin; - Word16 T0_tmp, T0_frac_tmp, nb_subfr_flag; - Word16 tmp_nb_bits_tot = 0; - Word16 Es_pred; - Word16 dct_res[L_FRAME16k], dct_epit[L_FRAME16k]; - Word16 m_mean = 0; - Word16 saved_bit_pos; - Word16 exc_wo_nf[L_FRAME16k]; - Word32 Lm_mean; - Word16 nb_bits; - Word16 indice; - SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; - GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; - - m_mean = 0; - move16(); - tmp_nb_bits_tot = 0; - move16(); - - T0_tmp = 64; - move16(); - T0_frac_tmp = 0; - move16(); - 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 ) ); - move16(); Es_pred = 0; move16(); @@ -449,7 +95,7 @@ void encod_audio_ivas_fx( *---------------------------------------------------------------*/ test(); - if ( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 ) + 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 ); } @@ -463,7 +109,6 @@ void encod_audio_ivas_fx( push_indice( hBstr, IND_GSC_ATTACK, 0, 1 ); } - test(); test(); test(); @@ -476,22 +121,25 @@ void encod_audio_ivas_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 ) ) { FOR( i = 0; i < 5; i++ ) { test(); - if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) + if ( GT_16( abs_s( hSpMusClas->gsc_lt_diff_etot_fx[MAX_LT - i - 1] ), 1536 /*6.0 in Q8*/ ) && EQ_16( hGSCEnc->cor_strong_limit, 1 ) ) { hGSCEnc->cor_strong_limit = 0; move16(); } } } + test(); test(); test(); @@ -548,11 +196,10 @@ void encod_audio_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) && NE_16( st_fx->coder_type, INACTIVE ) ) ) { nb_subfr = shl( nb_subfr, 1 ); - nb_subfr_flag |= 0x2; + nb_subfr_flag = s_or( nb_subfr_flag, 0x2 ); logic16(); } - test(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { push_indice( hBstr, IND_HF_NOISE, nb_subfr_flag, 2 ); @@ -563,6 +210,7 @@ void encod_audio_ivas_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 ) ) { @@ -600,17 +248,20 @@ void encod_audio_ivas_fx( push_indice( hBstr, IND_ES_PRED, indice, nb_bits ); } - 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 ); + 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 ); /*---------------------------------------------------------------* * 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++ ) { @@ -659,12 +310,14 @@ void encod_audio_ivas_fx( ELSE IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { hGSCEnc->noise_lev = s_max( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ); + move16(); push_indice( hBstr, IND_NOISE_LEVEL, sub( hGSCEnc->noise_lev, NOISE_LEVEL_SP2 ), 2 ); } ELSE IF( st_fx->GSC_noisy_speech ) { hGSCEnc->noise_lev = NOISE_LEVEL_SP3; move16(); + move16(); } ELSE { @@ -675,7 +328,7 @@ void encod_audio_ivas_fx( * Find and encode the last band where the adaptive (pitch) contribution is significant *---------------------------------------------------------------*/ - 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 ); + last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &hGSCEnc->pit_exc_hangover, Q_new ); IF( last_pit_bin == 0 ) { @@ -696,12 +349,12 @@ void encod_audio_ivas_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 ) @@ -710,29 +363,34 @@ void encod_audio_ivas_fx( tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); } - Word16 Q_exc = Q_new; + Q_exc = Q_new; move16(); - 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 ); + + 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 ); /*--------------------------------------------------------------------------------------* * iDCT transform *--------------------------------------------------------------------------------------*/ edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); - Scale_sig( exc, st_fx->L_frame, sub( Q_new, Q_exc ) ); edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); - Scale_sig( exc_wo_nf, st_fx->L_frame, sub( Q_new, Q_exc ) ); - Q_exc = Q_new; - move16(); + + 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 ) ); + } + /*--------------------------------------------------------------------------------------* * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ - pre_echo_att_ivas_fx( &hGSCEnc->Last_frame_ener_fx, exc, attack_flag, Q_exc, st_fx->last_coder_type, st_fx->L_frame ); + 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 ); /*--------------------------------------------------------------------------------------* * Update BWE excitation *--------------------------------------------------------------------------------------*/ + IF( st_fx->hBWE_TD != NULL ) { IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) @@ -746,11 +404,12 @@ void encod_audio_ivas_fx( interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); } } + /*--------------------------------------------------------------------------------------* * Synthesis *--------------------------------------------------------------------------------------*/ - p_Aq = Aq; /* Q12 */ + p_Aq = Aq; FOR( i_subfr = 0; i_subfr < st_fx->L_frame; i_subfr += L_SUBFR ) { Syn_filt_s( 1, p_Aq, M, &exc_wo_nf[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 ); @@ -760,50 +419,58 @@ void encod_audio_ivas_fx( /*--------------------------------------------------------------------------------------* * Updates *--------------------------------------------------------------------------------------*/ - Copy_Scale_sig( &hGSCEnc->mem_w0_tmp_fx, &hLPDmem->mem_w0, 1, sub( hLPDmem->q_mem_syn, sub( Q_new, 1 ) ) ); - /*_DIFF_FLOAT_FIX_ The way it is written in the original fix point is that at this point mem_w0 falls back to its original value (before enc_pit_exc, seems not the case in float */ - move16(); - Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_new */ + + 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 + { + hLPDmem->mem_w0 = hGSCEnc->mem_w0_tmp_fx; + move16(); + } + + Copy( exc_wo_nf, exc, st_fx->L_frame ); return; } + /*================================================================================*/ -/* FUNCTION : void gsc_enc_fx () */ +/* FUNCTION : void gsc_enc_fx() */ /*--------------------------------------------------------------------------------*/ /* PURPOSE : Generic audio signal encoder */ /*--------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) res_dct_in : dct of residual signal Q_exc */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) res_dct_in : dct of residual signal Q_exc */ +/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ +/* _ (Word16) coder_type : coding type Q0 */ /* _ (Word16) bits_used : Number of bit used before frequency Q Q0 */ /* _ (Word16) nb_subfr : Number of subframe considered Q0 */ -/* _ (Word16) Qexc : Q format of exc_dct_in */ +/* _ (Word16) Qexc : Q format of exc_dct_in */ /*--------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State *st_fx:Encoder State Structure */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* Encoder_State *st_fx:Encoder State Structure */ /* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Q_exc */ /*--------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ +/* 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*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ - Word16 *tmp_noise, /* o : noise energy Q2*/ - Word16 Q_exc ) + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + Word16 *tmp_noise, /* o : noise energy Q2*/ + Word16 *Q_exc ) { Word16 y2_filt[L_FRAME16k]; Word16 exc_diffQ[L_FRAME16k]; @@ -816,7 +483,7 @@ void gsc_enc_fx( Word16 concat_in[L_FRAME16k]; Word16 concat_out[L_FRAME16k]; Word16 max_ener_band[MBANDS_GN_BITALLOC16k], j; - Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; + Word16 Ener_per_bd_iQ[MBANDS_GN16k]; Word16 last_bin, mean_gain; Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; Word16 bitallocation_exc[2]; @@ -827,6 +494,11 @@ void gsc_enc_fx( Word16 seed_init; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + Word32 L_tmp; + Word16 max_eq = 0; + Word16 Q_concat = Q_PVQ_OUT; + move16(); + move16(); set16_fx( inpulses_fx, 0, NB_SFM ); set16_fx( imaxpulse_fx, 0, NB_SFM ); @@ -862,6 +534,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; @@ -873,11 +546,12 @@ void gsc_enc_fx( move16(); } - Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1 /*, st_fx->L_frame IVAS_CODE*/ ); + Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, *Q_exc, MBANDS_GN, 1, st_fx->L_frame ); /*--------------------------------------------------------------------------------------* * Gain quantizaion *--------------------------------------------------------------------------------------*/ + i = 0; move16(); WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) @@ -898,8 +572,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(); @@ -907,23 +580,33 @@ void gsc_enc_fx( * Frequency encoder *--------------------------------------------------------------------------------------*/ - 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; + 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; 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 ); + 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 + { + 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 ) { @@ -931,6 +614,7 @@ void gsc_enc_fx( push_indice( hBstr, IND_UNUSED, 0, i ); bit = sub( bit, i ); } + /* Reorder Q bands */ seed_init = 0; move16(); @@ -938,6 +622,30 @@ void gsc_enc_fx( move16(); set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k ); + 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 */ + } + } + } + FOR( j = 0; j < nb_subbands; j++ ) { Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); /*Q12*/ @@ -994,338 +702,88 @@ void gsc_enc_fx( * Gain is based on the inter-correlation gain between the pulses found and residual signal *--------------------------------------------------------------------------------------*/ - { - 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 ); - } - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ - - 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, &st_fx->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 ); - - exc_dct_in[0] = 0; - move16(); - - return; -} - - -void gsc_enc_ivas_fx( - Encoder_State *st, /* i/o: State structure */ - Word16 res_dct_in_fx[], - /* i : dct of residual signal */ // Q_exc - Word16 exc_dct_in_fx[], - /* i/o: dct of pitch-only excitation / total excitation */ // Q_exc - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 *lsf_new_fx, /* Qx2.56 */ - /* i : ISFs at the end of the frame */ // Q15 - Word16 *exc_wo_nf_fx, - /* o : excitation (in f domain) without noisefill */ // Q_exc - Word16 *tmp_noise_fx, /* o : long-term noise energy Q8*/ - Word16 *Q_exc ) -{ - Word16 i; - GSC_ENC_HANDLE hGSCEnc; - BSTR_ENC_HANDLE hBstr; - Word16 exc_diffQ_fx[L_FRAME16k]; - Word16 exc_diff_fx[L_FRAME16k]; - Word16 bit; - Word16 nb_subbands; - Word16 pvq_len; - Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; /*Q3*/ - Word16 tmp_band; - Word16 concat_in_fx[L_FRAME16k]; - Word16 concat_out_fx[L_FRAME16k]; - Word16 max_ener_band[MBANDS_GN_BITALLOC16k], j; - Word16 Ener_per_bd_iQ_fx[MBANDS_GN16k]; - Word16 last_bin; - Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; - Word16 bitallocation_exc[2]; - Word16 npulses[NB_SFM]; - Word16 maxpulse[NB_SFM]; - Word16 mean_gain_fx; - Word16 seed_init; - Word32 L_tmp; - Word16 max_eq; - - /*--------------------------------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------------------------------*/ - - hGSCEnc = st->hGSCEnc; - hBstr = st->hBstr; - - bit = bits_used; - move16(); - - test(); - test(); - test(); - if ( st->coder_type == INACTIVE && ( EQ_16( st->tdm_LRTD_flag, 1 ) || EQ_16( st->element_mode, IVAS_SCE ) ) && LE_32( st->core_brate, GSC_LRES_GAINQ_LIMIT ) ) - { - bit = add( bit, GSC_LRES_NB_NITS ); - } - - set16_fx( exc_diffQ_fx, 0, st->L_frame ); - set16_fx( Ener_per_bd_iQ_fx, 0, MBANDS_GN16k ); - - /*--------------------------------------------------------------------------------------* - * Calculate the difference between the residual spectrum and the spectrum of adaptive excitation - * (non valuable temporal content present in exc_dct_in is already zeroed) - *--------------------------------------------------------------------------------------*/ - - v_sub_16( res_dct_in_fx, exc_dct_in_fx, exc_diff_fx, st->L_frame ); /* Q_exc */ - exc_diff_fx[0] = 0; - move16(); - - /*--------------------------------------------------------------------------------------* - * Multiply the difference spectrum with the normalized spectral shape of the residual signal - * 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; - } - ELSE - { - tmp_band = hGSCEnc->mem_last_pit_band; - } - move16(); - - Ener_per_band_comp_ivas_fx( exc_diff_fx, Ener_per_bd_iQ_fx, *Q_exc, MBANDS_GN, 1, st->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Gain quantizaion - *--------------------------------------------------------------------------------------*/ - - i = 0; - move16(); - - WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) - { - IF( LE_32( st->core_brate, brate_intermed_tbl[i] ) ) - { - BREAK; - } - i++; - } - - test(); - test(); - test(); - if ( st->element_mode > EVS_MONO && EQ_16( st->coder_type, AUDIO ) && - LE_32( st->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ - { - i--; - } - - mean_gain_fx = gsc_gainQ_ivas_fx( hBstr, st->element_mode, st->idchan, Ener_per_bd_iQ_fx, Ener_per_bd_iQ_fx, brate_intermed_tbl[i], st->coder_type, st->bwidth, st->L_frame, st->tdm_LRTD_flag, st->core_brate ); - - *tmp_noise_fx = mult( mean_gain_fx, 20480 ); // 20480 => 10 in Q11 - move16(); // Q8 - - /*--------------------------------------------------------------------------------------* - * PVQ encoder - *--------------------------------------------------------------------------------------*/ - - bands_and_bit_alloc_ivas_fx( hGSCEnc->cor_strong_limit, hGSCEnc->noise_lev, st->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ_fx, max_ener_band, bits_per_bands, &nb_subbands, exc_diff_fx, concat_in_fx, &pvq_len, st->coder_type, st->bwidth, st->GSC_noisy_speech, st->L_frame, st->element_mode, st->GSC_IVAS_mode ); - - set16_fx( npulses, 0, NB_SFM ); - - IF( bit == 0 ) - { - set16_fx( concat_out_fx, 0, L_FRAME16k ); - } - ELSE - { - Word16 Q_concat = Q12; - move16(); - bit = sub( bit, pvq_core_enc_ivas_fx( hBstr, concat_in_fx, concat_out_fx, &Q_concat, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, npulses, maxpulse, ACELP_CORE ) ); - } - - /* write unused bits */ - WHILE( bit > 0 ) - { - i = s_min( bit, 16 ); - push_indice( hBstr, IND_UNUSED, 0, i ); - bit = sub( bit, i ); - } - - /* Reorder Q bands */ - last_bin = 0; - move16(); - set16_fx( bitallocation_band, 0, MBANDS_GN_BITALLOC16k ); - seed_init = 0; - move16(); - - max_eq = 0; - move16(); - test(); test(); test(); - test(); - IF( ( ( ( LT_32( st->core_brate, ACELP_7k20 ) && EQ_16( st->GSC_noisy_speech, 1 ) ) || LT_32( st->core_brate, 6000 ) ) && LE_16( st->coder_type, UNVOICED ) ) || GE_16( st->GSC_IVAS_mode, 1 ) ) + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { - j = emaximum_fx( Q12, concat_out_fx, shl( nb_subbands, 4 ), &L_tmp ); - IF( LE_16( add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ), ONE_IN_Q12 ) ) + FOR( i = 64; i < st_fx->L_frame; i++ ) { - max_eq = 32767; /* Q15 */ + exc_diffQ[i] = mult( exc_diffQ[i], max_eq ); /* Q12 */ move16(); } - ELSE - { - max_eq = div_s( ONE_IN_Q12, add( abs_s( concat_out_fx[j] ), 41 /* 0.01f in Q12 */ ) ); /* Q15 */ - } } - - FOR( j = 0; j < nb_subbands; j++ ) + 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 ) ) { - Copy( concat_out_fx + i_mult( j, 16 ), exc_diffQ_fx + i_mult( max_ener_band[j], 16 ), 16 ); /* Q12 */ - - IF( GT_16( max_ener_band[j], last_bin ) ) + FOR( i = 0; i < L_FRAME; i++ ) { - last_bin = max_ener_band[j]; + exc_diffQ[i] = mult( exc_diffQ[i], max_eq ); /* Q12 */ move16(); } - - bitallocation_band[max_ener_band[j]] = 1; - move16(); - - seed_init = add( seed_init, npulses[j] ); - } - test(); - IF( NE_16( st->last_coder_type, AUDIO ) /* First audio frame */ - && NE_16( st->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_enc to UNVOICED */ - { - FOR( j = 0; j < nb_subbands * 16; j++ ) - { - IF( concat_out_fx[j] > 0 ) - { - seed_init = (Word16) L_mult0( seed_init, 8 ); - move16(); - } - IF( concat_out_fx[j] < 0 ) - { - seed_init = (Word16) L_add( seed_init, 3 ); - move16(); - } - } - - hGSCEnc->seed_tcx = seed_init; - move16(); } - - test(); - IF( EQ_32( st->core_brate, ACELP_8k00 ) && st->bwidth != NB ) + ELSE { - bitallocation_exc[0] = 0; - move16(); - bitallocation_exc[1] = 0; - move16(); - - if ( exc_diffQ_fx[L_FRAME8k - 2] != 0 ) - { - bitallocation_exc[0] = 1; - move16(); - } - - if ( exc_diffQ_fx[L_FRAME8k - 1] != 0 ) - { - bitallocation_exc[1] = 1; - move16(); - } + 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 ); } - /*--------------------------------------------------------------------------------------* - * Skip adaptive (pitch) contribution frequency band (no noise added over the adaptive (pitch) contribution) - * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal - * Gain is based on the inter-correlation gain between the pulses found and residual signal - *--------------------------------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech == 1 ) + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) /* This could be harmonized, but won't be BE */ { - FOR( i = 64; i < st->L_frame; i++ ) + 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 ) ) { - exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); /* Q12 */ + 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 IF( st->core_brate < ACELP_7k20 && st->GSC_noisy_speech == 1 && st->coder_type <= UNVOICED ) - { - FOR( i = 0; i < L_FRAME; i++ ) + ELSE { - exc_diffQ_fx[i] = mult( exc_diffQ_fx[i], max_eq ); /* Q12 */ + Scale_sig( exc_dct_in, st_fx->L_frame, sub( Q_exc_new, *Q_exc ) ); /* Q_exc_new */ + *Q_exc = Q_exc_new; move16(); } } - ELSE - { - freq_dnw_scaling_fx( hGSCEnc->cor_strong_limit, st->coder_type, hGSCEnc->noise_lev, st->core_brate, exc_diffQ_fx, Q12, st->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->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_fx, st->L_frame, sub( Q_exc_new, *Q_exc ) ); /* Q_exc_new */ - *Q_exc = Q_exc_new; - move16(); - } /*--------------------------------------------------------------------------------------* * Estimate noise level *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_ivas_fx( st->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ_fx /* Q12 */, &hGSCEnc->seed_tcx, Ener_per_bd_iQ_fx, nb_subfr, exc_dct_in_fx /* Q_exc */, - st->last_coder_type, bitallocation_band, lsf_new_fx /* x2.56 */, hGSCEnc->last_exc_dct_in_fx /* Q_exc */, &hGSCEnc->last_ener_fx /* Q0 */, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st->coder_type, - st->bwidth, exc_wo_nf_fx, Q12, Q_exc, st->GSC_noisy_speech, NULL, st->L_frame, st->element_mode, st->GSC_IVAS_mode ); - exc_dct_in_fx[0] = 0; + 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 ); + + exc_dct_in[0] = 0; move16(); return; } + /*======================================================================*/ -/* FUNCTION : edyn_fx() */ +/* FUNCTION : edyn_fx() */ /*----------------------------------------------------------------------*/ -/* PURPOSE : Calculate energy dynamics in a vector */ -/* (ratio of energy maximum to energy mean) */ -/* */ +/* PURPOSE : Calculate energy dynamics in a vector */ +/* (ratio of energy maximum to energy mean) */ +/* */ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) vec : ratio of max to mean Qnew */ -/* _ (Word16) lvec : input vector */ -/* _ (Word16) Q_new : */ +/* INPUT ARGUMENTS : */ +/* _ (Word16 *) vec : ratio of max to mean Qnew */ +/* _ (Word16) lvec : input vector */ +/* _ (Word16) Q_new : */ /*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) dyn : ratio of energy maximum to energy mean (Q7) */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) dyn : ratio of energy maximum to energy mean (Q7) */ /*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ 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; @@ -1371,6 +829,7 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ dyn = 1280; /* 10.0f in Q7 */ move16(); } + return dyn; /* Q7 */ } @@ -1416,6 +875,5 @@ void GSC_enc_init_fx( hGSCEnc->past_dyn_dec = 0; move16(); - return; } diff --git a/lib_enc/guided_plc_enc_fx.c b/lib_enc/guided_plc_enc_fx.c index 599fc57f290dbd5f0ad4fdbfad43d5af80ea7f37..db33f6c6301524cb28f44dfe811e584af092315c 100644 --- a/lib_enc/guided_plc_enc_fx.c +++ b/lib_enc/guided_plc_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index e833201bc5e2614de96760e317ffa6d0c5d3e91c..84ba1b48438deae3fed33092423cbf1bcfee29fe 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index 1253d55fd8a921fed876c0cc1e033c39158bed6e..07152c84267d8270bb762b7dab56c7f91772ad2f 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 2879997ac5d6e225d7fc434ad1e4728dca32635b..6c4aa6bf4ab9bd8f7398d3d8e6d7807be77d7bf3 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index f033bd685b8e5c1c48bd3485a23bf2b82b560411..bcf0e3945c690e037de9bcebcf7440dc42322468 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index f462ca4dca7662c29fcb215e318cfe98e4c86013..7c5a7884c757ea1d20486bd3448ccba0261f3a83 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 cd58e3b95358314438c169dbcc95f32a5efce782..74a3a15dfe24a4ef7a0d5b1530454c8f28e7ccc9 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 1119656fc3bb66eba83d3d1349870aa17489e4b0..57692bbefc0919f12b67ee156432804c8ae5b14f 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 25dfa2534f78ec58f23306d021f7bf158f818331..72a26b2482533cde5902e0b020ed60d1f0ca799b 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -879,10 +879,8 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value Word16 numf; Word32 SFM32; Word16 invDenom, SFM; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL move32(); move32(); -#endif move32(); num = 0; @@ -3322,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(); } } @@ -4087,12 +4089,12 @@ void IGFEncResetTCX10BitCounter_fx( void IGFEncApplyMono_ivas_fx( Encoder_State *st, /* i : Encoder state */ - Word16 powerSpectrum_len, /* i: length of pPowerSpectrum_fx buffer */ + Word16 powerSpectrum_len, /* i: length of pPowerSpectrum_fx buffer */ const Word16 igfGridIdx, /* i : IGF grid index */ Word32 *pMDCTSpectrum_fx, /* i/o: MDCT spectrum */ - Word16 e_mdct, /* i : exponent of pMDCTspectrum */ + Word16 e_mdct, /* i : exponent of pMDCTspectrum */ Word32 *pPowerSpectrum_fx, /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *e_ps, /* i : exponent of pPowerSpectrum */ + Word16 *e_ps, /* i : exponent of pPowerSpectrum */ const Word16 isTCX20, /* i : flag indicating if the input is TCX20 or TCX10/2xTCX5 */ const Word8 isTNSActive, /* i : flag indicating if the TNS is active */ const Word16 sp_aud_decision0, /* i : first stage switching decision */ @@ -4139,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 ); @@ -4269,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; @@ -4291,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 d83841039876ae0ee371db6fb38771619a87b006..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index ed52349dc034d32523fcd2cc412d5f27b2da50aa..d1341a98af3f27cc8846dcb3db7e735ea9597d7c 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 6d5618ee1aea0b6ec74127325ecc50d71680ec80..f042b4a10c8bb0da3a7bd9dc934dec3b7acb70e8 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1,1055 +1,73 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "stl.h" -#include "ivas_cnst.h" -#include "ivas_error.h" -#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "ivas_prot_fx.h" - - -/*-----------------------------------------------------------------------* - * init_encoder_fx() - * - * Initialization of state variables - *-----------------------------------------------------------------------*/ - -ivas_error init_encoder_fx( - Encoder_State *st_fx, /* i/o: Encoder static variables structure */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID /* i : interval for SID update */ -) -{ - Word16 i; - Word32 L_tmp; - Word16 idchan = 0; /* i : channel ID */ - Word16 vad_only_flag = 0; /* i : channel ID */ - move16(); - move16(); - ISM_MODE ism_mode = ISM_MODE_NONE; - ivas_error error; - - error = IVAS_ERR_OK; - - /*-----------------------------------------------------------------* - * General signal buffers - *-----------------------------------------------------------------*/ - IF( !vad_only_flag ) - { - IF( ( st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); - } - - st_fx->Bin_E_old_fx = st_fx->hSignalBuf->Bin_E_old_fx; - st_fx->mem_decim_fx = st_fx->hSignalBuf->mem_decim_fx; - st_fx->mem_decim16k_fx = st_fx->hSignalBuf->mem_decim16k_fx; - st_fx->old_inp_12k8_fx = st_fx->hSignalBuf->old_inp_12k8_fx; - st_fx->old_inp_16k_fx = st_fx->hSignalBuf->old_inp_16k_fx; - st_fx->buf_speech_enc_pe = st_fx->hSignalBuf->buf_speech_enc_pe; - st_fx->buf_synth = st_fx->hSignalBuf->buf_synth; - st_fx->buf_speech_enc = st_fx->hSignalBuf->buf_speech_enc; - st_fx->buf_wspeech_enc = st_fx->hSignalBuf->buf_wspeech_enc; - - /* initializations */ - set16_fx( st_fx->old_inp_12k8_fx, 0, L_INP_MEM ); /* memory of input signal at 12.8kHz */ - set16_fx( st_fx->old_inp_16k_fx, 0, L_INP_MEM ); - set16_fx( st_fx->mem_decim16k_fx, 0, 2 * L_FILT_MAX ); - set16_fx( st_fx->mem_decim_fx, 0, 2 * L_FILT_MAX ); - set32_fx( st_fx->Bin_E_old_fx, 0, L_FFT / 2 ); - st_fx->q_Bin_E_old = Q31; - move16(); - - st_fx->input_buff_fx = st_fx->hSignalBuf->input_buff; - set16_fx( st_fx->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_buff_fx; - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ); - } - ELSE - { - st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC; - } - } - ELSE - { - st_fx->hSignalBuf = NULL; - st_fx->Bin_E_old_fx = NULL; - st_fx->mem_decim_fx = NULL; - st_fx->mem_decim16k_fx = NULL; - st_fx->old_inp_12k8_fx = NULL; - st_fx->old_inp_16k_fx = NULL; - st_fx->buf_speech_enc_pe = NULL; - st_fx->buf_synth = NULL; - st_fx->buf_speech_enc = NULL; - st_fx->buf_wspeech_enc = NULL; - st_fx->input_buff_fx = NULL; - } - - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - st_fx->last_core = -1; - move16(); - - if ( st_fx->Opt_AMR_WB ) - { - st_fx->last_core = AMR_WB_CORE; - move16(); - } - - st_fx->L_frame = L_FRAME; - move16(); - st_fx->last_coder_type = GENERIC; - move16(); - st_fx->last_total_brate = st_fx->total_brate; - move32(); - st_fx->last_total_brate_cng = -1; - move32(); - st_fx->last_core_brate = st_fx->total_brate; - move32(); - st_fx->extl = -1; - move16(); - st_fx->last_extl = -1; - move16(); - st_fx->last_L_frame = L_FRAME; - move16(); - st_fx->rate_switching_reset = 0; - move16(); - st_fx->rate_switching_reset_16kHz = 0; - move16(); - - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - IF( !vad_only_flag ) - { - IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); - } - } - ELSE - { - st_fx->hBstr = NULL; - } - - - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - st_fx->next_force_safety_net = 0; - move16(); - st_fx->pstreaklen = 0; - move16(); - st_fx->streaklimit_fx = 32767; - move16(); /*1;//Q15 */ - set16_fx( st_fx->mem_MA_fx, 0, M ); - - init_gp_clip_fx( st_fx->clip_var_fx ); - pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit, &st_fx->old_corr_fx ); - - /*-----------------------------------------------------------------* - * AMR-WB IO initialization - *-----------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); - } - - amr_wb_enc_init_fx( st_fx->hAmrwb_IO ); - } - ELSE - { - st_fx->hAmrwb_IO = NULL; - } - st_fx->clas = UNVOICED_CLAS; - move16(); - set16_fx( st_fx->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); - st_fx->mem_deemph_fx = 0; - move16(); - st_fx->mem_preemph_fx = 0; - move16(); - st_fx->mem_preemph16k_fx = 0; - move16(); - st_fx->mem_preemph_enc = 0; - move16(); - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->mem_deemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); - - /* (Decimated) Weighted Speech Memory */ - st_fx->mem_wsp_enc = 0; - move16(); - - st_fx->mem_wsp_fx = 0; - move16(); - st_fx->mem_wsp_q = 0; - move16(); - set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); - st_fx->q_Bin_E = Q31; - move16(); - set16_fx( st_fx->mem_decim2_fx, 0, 3 ); - set16_fx( st_fx->lgBin_E_fx, 0, L_FFT / 2 ); - - st_fx->ini_frame = 0; - move16(); - st_fx->ee_old_fx = 640; - move32(); /*chk //10 in Q6 */ - st_fx->Nb_ACELP_frames = 0; - move16(); - st_fx->audio_frame_cnt = AUDIO_COUNTER_INI; - move16(); /* Initializatin of the audio frame counter mildly into the audio mode */ - - /* adaptive lag window memory */ - st_fx->old_pitch_la = 0; - move16(); - st_fx->old_voicing_la = 0; - move16(); - set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); - - st_fx->old_hpfilt_in_fx = 0; - move16(); - st_fx->old_hpfilt_out_fx = 0; - move16(); - st_fx->EnergyLT_fx = 0; - move32(); - st_fx->prev_Q_new = 0; - move16(); - - - IF( EQ_32( st_fx->input_Fs, 8000 ) ) - { - st_fx->min_band = 1; - move16(); - st_fx->max_band = 16; - move16(); - } - ELSE - { - st_fx->min_band = 0; - move16(); - st_fx->max_band = 19; - move16(); - } - IF( st_fx->Opt_AMR_WB ) - { - Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); - E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M ); - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M, INT_FS_FX ); - } - - Copy( st_fx->lsf_old_fx, st_fx->lsf_old1_fx, M ); - Copy( st_fx->lsp_old1_fx, st_fx->lsp_old_fx, M ); - Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); - Copy( st_fx->lsp_old_fx, st_fx->lspold_enc_fx, M ); - - st_fx->stab_fac_fx = 0; - move16(); - /* Bass post-filter memories - encoder side of MODE2 */ - st_fx->bpf_off = 0; - move16(); - - /* TC mode */ - st_fx->tc_cnt = 0; - move16(); - st_fx->mCb1_fx = 0; - move16(); - - /* AC mode */ - - /*-----------------------------------------------------------------* - * parameters for AC coder type (GSC) - *-----------------------------------------------------------------*/ - - // st_fx->GSC_noisy_speech = 0; - st_fx->GSC_IVAS_mode = 0; - move16(); - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hGSCEnc = (GSC_ENC_HANDLE) malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); - } - - GSC_enc_init_fx( st_fx->hGSCEnc ); - } - ELSE - { - st_fx->hGSCEnc = NULL; - } - - st_fx->last_ener_fx = 0; - move16(); - - st_fx->old_dE1_fx = 0; - move16(); - st_fx->old_ind_deltaMax = 0; - move32(); - set32_fx( st_fx->old_enr_ssf_fx, 0, 2 * NB_SSF ); - st_fx->spike_hyst = -1; - move16(); - st_fx->music_hysteresis_fx = 0; - move16(); /* Counter of frames after AUDIO frame to prevent UC */ - st_fx->last_harm_flag_acelp = 0; - move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - - /* speech/music classifier */ - st_fx->Last_pulse_pos = 0; - move16(); - - st_fx->last_vad_spa_fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * VAD - *-----------------------------------------------------------------*/ - - st_fx->vad_flag = 1; - st_fx->localVAD = 0; - move16(); - move16(); - test(); - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || st_fx->element_mode == EVS_MONO ) && ( !vad_only_flag ) ) - { - if ( ( st_fx->hVAD = (VAD_HANDLE) malloc( sizeof( VAD_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); - } - - wb_vad_init_fx( st_fx->hVAD ); - } - ELSE - { - st_fx->hVAD = NULL; - } - - st_fx->Pos_relE_cnt = 5120; - move16(); /*20.0f*/ - - /* CLDFB-based VAD */ - IF( st_fx->element_mode == EVS_MONO ) - { - if ( ( st_fx->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); - } - - vad_init_fx( st_fx->hVAD_CLDFB ); - } - ELSE - { - st_fx->hVAD_CLDFB = NULL; - } - - - /*-----------------------------------------------------------------* - * Noise estimator - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( /*idchan == 0 ||*/ EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || st_fx->element_mode == EVS_MONO ) - { - if ( ( st_fx->hNoiseEst = (NOISE_EST_HANDLE) malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); - } - noise_est_init_fx( st_fx->hNoiseEst ); - } - ELSE - { - st_fx->hNoiseEst = NULL; - } - - /*-----------------------------------------------------------------* - * Speech/music classifier - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE) malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); - } - - speech_music_clas_init_fx( st_fx->hSpMusClas ); - - st_fx->sp_aud_decision0 = 0; - st_fx->sp_aud_decision1 = 0; - st_fx->sp_aud_decision2 = 0; - move16(); - move16(); - move16(); - } - ELSE - { - st_fx->hSpMusClas = NULL; - } - - st_fx->bckr_tilt_lt = 0; - move32(); - - /* WB, SWB and FB bandwidth detector */ - st_fx->lt_mean_NB_fx = 0; - move16(); - st_fx->lt_mean_WB_fx = 0; - move16(); - st_fx->lt_mean_SWB_fx = 0; - move16(); - st_fx->count_WB = BWD_COUNT_MAX; - move16(); - st_fx->count_SWB = BWD_COUNT_MAX; - move16(); - st_fx->count_FB = BWD_COUNT_MAX; - move16(); - st_fx->bwidth = st_fx->max_bwidth; - move16(); - st_fx->last_input_bwidth = st_fx->bwidth; - move16(); - st_fx->last_bwidth = st_fx->bwidth; - move16(); - st_fx->last_bwidth_cng = st_fx->bwidth; - move16(); - - - move16(); - st_fx->coder_type_raw = VOICED; - st_fx->last_coder_type_raw = st_fx->coder_type_raw; - move16(); - st_fx->is_ism_format = 0; - move16(); - if ( NE_16( ism_mode, ISM_MODE_NONE ) ) - { - st_fx->is_ism_format = 1; - move16(); - } - /* Stationary noise UV modification */ - st_fx->ge_sm_fx = 640; - move32(); /*Q(GE_SHIFT) */ - st_fx->uv_count = 0; - move16(); - st_fx->act_count = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); - st_fx->noimix_seed = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 1; - move16(); - st_fx->exc_pe_fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * DTX - *-----------------------------------------------------------------*/ - - st_fx->lp_speech_fx = 11520; - move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - st_fx->lp_noise_fx = 0; - move16(); - - test(); - test(); - IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->Opt_DTX_ON ) ) - { - if ( ( st_fx->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); - } - dtx_enc_init_fx( st_fx, var_SID_rate_flag, interval_SID ); - } - ELSE - { - st_fx->hDtxEnc = NULL; - } - - st_fx->fd_cng_reset_flag = 0; - move16(); - - IF( st_fx->Opt_DTX_ON ) - { - move16(); - } - - st_fx->cng_type = -1; - move16(); - - - /*-----------------------------------------------------------------* - * LP-CNG - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) - { - IF( ( st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); - } - - td_cng_enc_init_fx( st_fx->hTdCngEnc, st_fx->Opt_DTX_ON, st_fx->max_bwidth ); - } - ELSE - { - st_fx->hTdCngEnc = NULL; - } - - - /*-----------------------------------------------------------------* - * ACELP LPDmem - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); - } - - LPDmem_enc_init_fx( st_fx->hLPDmem ); - } - ELSE - { - st_fx->hLPDmem = NULL; - } - - /* FEC */ - st_fx->last_clas = UNVOICED_CLAS; - move16(); - - FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR_Q6; - move16(); - } - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); - - /*-----------------------------------------------------------------* - * CLDFB Analysis - *-----------------------------------------------------------------*/ - - /* open analysis for input SR */ - if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), st_fx->input_frame_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - - if ( ( error = openCldfb( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels( 16000 ), L_FRAME16k ) ) != IVAS_ERR_OK ) - { - return error; - } - - st_fx->energyCoreLookahead_Fx = 0; - move32(); - st_fx->sf_energyCoreLookahead_Fx = 0; - move16(); - - /* stable short pitch detection */ - st_fx->voicing0_sm_fx = 0; - move16(); - st_fx->voicing_sm_fx = 0; - move16(); - st_fx->LF_EnergyRatio_sm_fx = 128; - move16(); - st_fx->predecision_flag = 0; - move16(); - st_fx->diff_sm_fx = 0; - move32(); - st_fx->energy_sm_fx = 0; - move32(); - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_SC_VBR || st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE) malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); - } - - sc_vbr_enc_init_fx( st_fx->hSC_VBR ); - } - ELSE - { - st_fx->hSC_VBR = NULL; - } - /* PLC encoder */ - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE) malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n" ) ); - } - } - ELSE - { - st_fx->hPlcExt = NULL; - } - /*-----------------------------------------------------------------* - * Temporal Envelope Coding - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hTECEnc = (TEC_ENC_HANDLE) malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); - } - } - ELSE - { - st_fx->hTECEnc = NULL; - } - - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); - } - - fd_bwe_enc_init_fx( st_fx->hBWE_FD ); - } - ELSE - { - st_fx->hBWE_FD = NULL; - } - - st_fx->prev_Q_shb = 0; - move16(); - st_fx->last_Opt_SC_VBR = 0; - move16(); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); - } - - // IF ((error = openCldfb(&st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) - //{ - // return error; - // } - - InitSWBencBuffer_fx( st_fx /*st_fx->hBWE_TD*/ ); - ResetSHBbuffer_Enc_fx( st_fx /*st_fx->hBWE_TD*/ ); - } - ELSE - { - st_fx->hBWE_TD = NULL; - // st_fx->cldfbSynTd = NULL; - } - - test(); - IF( st_fx->Opt_RF_ON || st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hRF = (RF_ENC_HANDLE) malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n" ) ); - } - - /* initialize RF indice buffers */ - reset_rf_indices_fx( st_fx /*->hRF, st_fx->L_frame, &st->rf_target_bits_write*/ ); - } - ELSE - { - st_fx->hRF = NULL; - } - - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); - set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); - - - st_fx->Energy_Old_fx = 0; - move16(); - st_fx->Q_old_wtda = 15; - move16(); - st_fx->EnergyLT_fx = 1; - move32(); - st_fx->EnergyLT_fx_exp = 30; - move16(); /* Set to a High Exponent so it is 1^-30 */ - st_fx->TransientHangOver = 0; - move16(); - - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); - } - - /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ - /*st_fx->hTcxEnc->spectrum[0] = st_fx->hTcxEnc->spectrum_long; - st_fx->hTcxEnc->spectrum[1] = st_fx->hTcxEnc->spectrum_long + N_TCX10_MAX;*/ - - st_fx->hTcxEnc->spectrum_fx[0] = st_fx->hTcxEnc->spectrum_long_fx; - st_fx->hTcxEnc->spectrum_fx[1] = st_fx->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; - - set16_fx( st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k ); - st_fx->hTcxEnc->Q_old_out = 0; - move16(); - /* MDCT selector */ - MDCT_selector_reset_fx( st_fx->hTcxEnc ); - st_fx->hTcxEnc->Q_old_out = 0; - move16(); - - /* MDCT classifier */ - MDCT_classifier_reset_fx( st_fx->hTcxEnc ); - - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); - } - } - ELSE - { - st_fx->hTcxEnc = NULL; - // st_fx->hTcxCfg = NULL; - } - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) - { - IF( ( st_fx->hHQ_core = (HQ_ENC_HANDLE) malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); - } - - HQ_core_enc_init_fx( st_fx->hHQ_core ); - } - ELSE - { - st_fx->hHQ_core = NULL; - } - - st_fx->last_enerBuffer_exp = 0; - move16(); - - /*-----------------------------------------------------------------* - * Channel-aware mode - *-----------------------------------------------------------------*/ - - - test(); - test(); - test(); - IF( st_fx->Opt_RF_ON == 0 || ( NE_16( st_fx->bwidth, WB ) && NE_16( st_fx->bwidth, SWB ) ) || NE_32( st_fx->total_brate, ACELP_13k20 ) ) - { - IF( EQ_16( st_fx->Opt_RF_ON, 1 ) ) - { - printf( "\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n" ); - printf( " Switched to normal mode!\n" ); - st_fx->Opt_RF_ON = 0; - move16(); - st_fx->rf_fec_offset = 0; - move16(); - } - st_fx->rf_mode = 0; - move16(); - } - ELSE - { - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); - } - st_fx->rf_mode_last = st_fx->rf_mode; - move16(); - /* initialize RF indice buffers */ - reset_rf_indices_fx( st_fx ); - - /*-----------------------------------------------------------------* - * MODE2 initialization - *-----------------------------------------------------------------*/ - - st_fx->last_sr_core = i_mult2( st_fx->last_L_frame, 50 ); - move16(); - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); - } - } - ELSE - { - st_fx->hIGFEnc = NULL; - move16(); - } - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - st_fx->igf = getIgfPresent_fx( st_fx->element_mode, st_fx->total_brate, st_fx->bwidth, st_fx->rf_mode ); - } - ELSE - { - st_fx->igf = 0; - move16(); - } - - /* FD-CNG encoder */ - createFdCngEnc_fx( &st_fx->hFdCngEnc ); - initFdCngEnc_fx( st_fx->hFdCngEnc, st_fx->input_Fs, st_fx->cldfbAnaEnc->scale ); - L_tmp = st_fx->total_brate; - move32(); - test(); - if ( st_fx->rf_mode && EQ_32( st_fx->total_brate, ACELP_13k20 ) ) - { - L_tmp = ACELP_9k60; - move32(); - } - configureFdCngEnc_fx( st_fx->hFdCngEnc, st_fx->bwidth, L_tmp ); - - st_fx->last_totalNoise_fx = 0; - move16(); - set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); - st_fx->totalNoise_increase_len = 0; - move16(); - init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/ ); - - IF( ( st_fx->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); - } - - InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, INV_FRAME_PER_SEC_Q15 ) ), - NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), - st_fx->hTranDet ); - - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - set16_fx( st_fx->Q_max, Q_MAX, L_Q_MEM ); - set16_fx( st_fx->Q_max_16k, Q_MAX, L_Q_MEM ); - st_fx->Q_old = 15; - move16(); - st_fx->old_wsp_max = 0; - move16(); - st_fx->old_wsp_shift = 0; - move16(); - st_fx->sharpFlag = 0; - move16(); - - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - move16(); - st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ - move16(); - st_fx->element_mode = EVS_MONO; /* element mode */ - move16(); - st_fx->last_element_mode = st_fx->element_mode; /* element mode */ - move16(); - st_fx->element_brate = -1; /* element bitrate */ - move32(); - // PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - move16(); - // st_fx->coder_type = GENERIC; /* low-rate mode flag */ - - set16_fx( st_fx->pitch, L_SUBFR, 3 ); - set16_fx( st_fx->voicing_fx, 0, 3 ); - - -#ifdef DEBUGGING - st_fx->id_element = -1; /* element ID */ - move16(); -#endif - st_fx->extl_orig = -1; /* extension layer */ - move16(); - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ - move32(); - return error; -} - -/*-----------------------------------------------------------------------* - * LPDmem_enc_init_fx() - * - * Initialization of ACELP LPDmem state variables - *-----------------------------------------------------------------------*/ - -void LPDmem_enc_init_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -) -{ - Word16 i; - - set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - set16_fx( hLPDmem->mem_syn2, 0, M ); - set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); - set16_fx( hLPDmem->mem_syn3, 0, M ); - - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } - return; -} - -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -) -{ - Word16 i; +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ - set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - set16_fx( hLPDmem->mem_syn2, 0, M ); - set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); - set16_fx( hLPDmem->mem_syn3, 0, M ); - hLPDmem->q_lpd_old_exc = Q15; - move16(); - hLPDmem->q_lpd_syn = Q15; - move16(); - hLPDmem->q_mem_syn = Q15; - move16(); - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); +/*==================================================================================== + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 + ====================================================================================*/ - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "stl.h" +#include "ivas_cnst.h" +#include "ivas_error.h" +#include "prot_fx.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "ivas_prot_fx.h" - return; -} /*-----------------------------------------------------------------------* - * destroy_encoder_fx() + * init_encoder() * - * Free memory which was allocated in init_encoder_fx() + * Initialization of state variables *-----------------------------------------------------------------------*/ -void destroy_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ -) -{ - deleteCldfb( &st_fx->cldfbAnaEnc ); - deleteCldfb( &st_fx->cldfbSynTd ); - - deleteFdCngEnc_fx( &st_fx->hFdCngEnc ); - - return; -} - -ivas_error init_encoder_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Encoder_Struct *st_ivas, /* i/o: encoder state structure */ - const Word16 idchan, /* i : channel ID */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID, /* i : interval for SID update */ - const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 element_brate /* i : element bitrate */ +ivas_error init_encoder_fx( + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ ) { - Word16 i; + Word16 i, input_frame; ivas_error error; Word32 igf_brate; - error = IVAS_ERR_OK; - move32(); + /* input_frame = st->input_Fs / FRAMES_PER_SEC */ + input_frame = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*-----------------------------------------------------------------* * General parameters @@ -1112,8 +130,7 @@ ivas_error init_encoder_ivas_fx( st->is_ism_format = 0; move16(); - - IF( NE_16( ism_mode, ISM_MODE_NONE ) ) + if ( NE_16( ism_mode, ISM_MODE_NONE ) ) { st->is_ism_format = 1; move16(); @@ -1153,6 +170,7 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); + init_lvq_fx( st->offset_scale1_fx, st->offset_scale2_fx, st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_fx, st->no_scales_p_fx ); st->next_force_safety_net = 0; move16(); @@ -1163,12 +181,17 @@ ivas_error init_encoder_ivas_fx( move16(); set16_fx( st->mem_MA_fx, 0, M ); + st->mCb1_fx = 0; + move16(); + init_gp_clip_fx( st->clip_var_fx ); + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); + set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); st->exp_old_wsp = 0; move16(); - set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. + set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); st->Q_old_wsp2 = 0; move16(); @@ -1183,14 +206,6 @@ ivas_error init_encoder_ivas_fx( st->exp_mem_preemph_enc = 0; move16(); - st->active_cnt = 0; - move16(); - - st->pst_mem_deemp_err_fx = 0; - move16(); - st->pst_lp_ener_fx = 0; - move16(); - /* AVQ pre-quantizer memory */ st->mem_preemp_preQ_fx = 0; move16(); @@ -1212,10 +227,13 @@ ivas_error init_encoder_ivas_fx( move16(); st->mem_wsp_q = 0; move16(); + set16_fx( st->mem_decim2_fx, 0, 3 ); set32_fx( st->Bin_E_fx, 0, L_FFT ); st->q_Bin_E = Q31; move16(); + set16_fx( st->lgBin_E_fx, 0, L_FFT / 2 ); + st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); st->Nb_ACELP_frames = 0; @@ -1226,6 +244,8 @@ ivas_error init_encoder_ivas_fx( /* adaptive lag window memory */ st->old_pitch_la = 0; move16(); + st->old_voicing_la = 0; + move16(); st->prev_Q_new = 0; move16(); @@ -1314,6 +334,7 @@ ivas_error init_encoder_ivas_fx( move16(); st->Q_stat_noise = 15; move16(); + /* FEC */ st->last_clas = UNVOICED_CLAS; move16(); @@ -1414,21 +435,20 @@ ivas_error init_encoder_ivas_fx( move16(); st->q_old_inp32 = Q31; move16(); - st->old_input_signal_fx = st->input_buff_fx; - st->old_input_signal32_fx = st->input_buff32_fx; - /* st->input_Fs / FRAMES_PER_SEC */ - Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( st->element_mode == EVS_MONO ) { - st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - st->input_fx = st->input_buff_fx + add( frame_length, (Word16) NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input32_fx = st->input_buff32_fx + add( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input_fx = st->input_buff_fx + add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); ///////////////////// input_Fs + st->old_input_signal_fx = st->input_fx - add( NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_frame ); + st->old_input_signal32_fx = st->input_buff32_fx; } ELSE { - // st->input32_fx = st->input_buff32_fx + Mpy_32_32( st->input_Fs, 42949673 ) /* 1/50 in Q31*/; // st->input_Fs / FRAMES_PER_SEC - st->input32_fx = st->input_buff32_fx + frame_length; - st->input_fx = st->input_buff_fx + frame_length; + st->input32_fx = st->input_buff32_fx + input_frame; + st->input_fx = st->input_buff_fx + input_frame; + st->old_input_signal_fx = st->input_buff_fx; + st->old_input_signal32_fx = st->input_buff32_fx; } } ELSE @@ -1460,7 +480,14 @@ ivas_error init_encoder_ivas_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); } - noise_est_init_ivas_fx( st->hNoiseEst ); + IF( st->element_mode == EVS_MONO ) + { + noise_est_init_fx( st->hNoiseEst ); + } + ELSE + { + noise_est_init_ivas_fx( st->hNoiseEst ); + } } ELSE { @@ -1518,7 +545,8 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } - speech_music_clas_init_ivas_fx( st->hSpMusClas ); + speech_music_clas_init_fx( st->element_mode, st->hSpMusClas ); + st->sp_aud_decision0 = 0; move16(); st->sp_aud_decision1 = 0; @@ -1531,7 +559,6 @@ ivas_error init_encoder_ivas_fx( st->hSpMusClas = NULL; } - /*-----------------------------------------------------------------* * WB, SWB and FB bandwidth detector *-----------------------------------------------------------------*/ @@ -1559,15 +586,19 @@ ivas_error init_encoder_ivas_fx( st->bwidth_sw_cnt = 0; move16(); - /*-----------------------------------------------------------------* * DTX *-----------------------------------------------------------------*/ + st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + move16(); st->lp_speech_32fx = 754974720; /*Q24 (45.0) */ /* Initialize the long-term active speech level in dB */ move32(); + st->lp_noise_fx = 0; + move16(); st->lp_noise_32fx = 0; move16(); + st->flag_noisy_speech_snr = 0; move16(); st->fd_cng_reset_flag = 0; @@ -1589,7 +620,7 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } - dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); + dtx_enc_init_fx( st, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ); } ELSE { @@ -1630,7 +661,7 @@ ivas_error init_encoder_ivas_fx( st->rf_mode = 0; move16(); - return error; + return IVAS_ERR_OK; } /*-----------------------------------------------------------------* @@ -1649,7 +680,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - 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 { @@ -1659,24 +690,22 @@ ivas_error init_encoder_ivas_fx( /*-----------------------------------------------------------------* * CLDFB & resampling tools parameters *-----------------------------------------------------------------*/ + test(); test(); test(); IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { /* open analysis for input SR */ - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - - if ( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st->input_Fs ), st->input_frame_fx ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - IF( ( error = openCldfb_ivas_fx( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS, ENC ) ) != IVAS_ERR_OK ) { return error; @@ -1688,10 +717,20 @@ ivas_error init_encoder_ivas_fx( st->cldfbAnaEnc = NULL; } - st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ - move32(); - st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ - move16(); + IF( st->element_mode == EVS_MONO ) + { + st->energyCoreLookahead_Fx = 0; + move32(); + st->sf_energyCoreLookahead_Fx = 0; + move16(); + } + ELSE + { + st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move32(); + st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move16(); + } /*-----------------------------------------------------------------* * SC-VBR parameters @@ -1715,7 +754,6 @@ ivas_error init_encoder_ivas_fx( st->last_Opt_SC_VBR = 0; move16(); - /*-----------------------------------------------------------------* * AMR-WB IO initialization *-----------------------------------------------------------------*/ @@ -1748,7 +786,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } ELSE { @@ -1794,7 +832,7 @@ ivas_error init_encoder_ivas_fx( IF( st->element_mode == EVS_MONO ) { - if ( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels( 16000 ), L_FRAME16k ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) { return error; } @@ -1806,8 +844,8 @@ ivas_error init_encoder_ivas_fx( return error; } } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE { @@ -1828,14 +866,15 @@ ivas_error init_encoder_ivas_fx( } fd_bwe_enc_init_fx( st->hBWE_FD ); - st->Q_old_wtda = 0; - move16(); } ELSE { st->hBWE_FD = NULL; } + st->prev_Q_shb = 0; + move16(); + /*-----------------------------------------------------------------* * HQ core parameters *-----------------------------------------------------------------*/ @@ -1861,6 +900,15 @@ ivas_error init_encoder_ivas_fx( move16(); st->EnergyLT_fx = 0; move32(); + st->Q_old_wtda = 0; + move16(); + IF( st->element_mode == EVS_MONO ) + { + st->EnergyLT_fx = 1; + move32(); + st->Q_old_wtda = 15; + move16(); + } st->Energy_Old_fx = 0; move32(); st->TransientHangOver = 0; @@ -1939,6 +987,7 @@ ivas_error init_encoder_ivas_fx( set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); st->hTcxEnc->spectrum_long_e = 0; move16(); + /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; @@ -2048,7 +1097,6 @@ ivas_error init_encoder_ivas_fx( st->last_sr_core = L_mult0( st->last_L_frame, FRAMES_PER_SEC ); move32(); - /* PLC encoder */ IF( st->element_mode == EVS_MONO ) { @@ -2068,38 +1116,34 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st->totalNoise_increase_len = 0; move16(); - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - IF( hTcxEnc != NULL ) - { - hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - move16(); - } - st->currEnergyHF_fx = 0; - move32(); - st->currEnergyHF_e_fx = 0; - move16(); st->prevEnergyHF_fx = 0; move32(); - /* Initialize TCX */ + IF( st->element_mode == EVS_MONO ) + { + init_coder_ace_plus_fx( st, st->last_total_brate, 0, -10 /*hack*/ ); + } + ELSE + { + /* Initialize Signal Buffers */ + Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); + st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); + move16(); + shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); + Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); + st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); + move16(); - /* Initialize Signal Buffers */ - Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); - st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); - move16(); - shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); - Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); - st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); - move16(); - /* Initialize ACELP */ - init_coder_ace_plus_ivas_fx( st, st->last_total_brate, igf_brate, 0 ); + init_coder_ace_plus_ivas_fx( st, st->last_total_brate, igf_brate, 0 ); + } IF( st->hLPDmem != NULL ) { st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; move16(); } + /*-----------------------------------------------------------------* * FD-CNG encoder *-----------------------------------------------------------------*/ @@ -2110,8 +1154,13 @@ ivas_error init_encoder_ivas_fx( test(); IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - createFdCngEnc_fx( &st->hFdCngEnc ); + IF( ( error = createFdCngEnc_fx( &st->hFdCngEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); + /* initialization for IVAS modes happens in first frame pre-processing */ IF( st->element_mode == EVS_MONO ) { @@ -2129,7 +1178,7 @@ ivas_error init_encoder_ivas_fx( move32(); } - configureFdCngEnc_ivas_fx( st->hFdCngEnc, st->bwidth, total_brate ); + configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, total_brate ); } } ELSE @@ -2146,15 +1195,13 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - Word16 frame_length = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - IF( GT_16( st->element_mode, EVS_MONO ) ) { - InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); + InitTransientDetection_ivas_fx( input_frame, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); + InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); } /*-----------------------------------------------------------------* @@ -2181,10 +1228,60 @@ ivas_error init_encoder_ivas_fx( move16(); st->old_wsp_shift = 0; move16(); - st->sharpFlag = 0; +#ifdef DEBUGGING + st->id_element = -1; /* element ID */ + move16(); +#endif + + return IVAS_ERR_OK; +} + + +/*-----------------------------------------------------------------------* + * LPDmem_enc_init() + * + * Initialization of ACELP LPDmem state variables + *-----------------------------------------------------------------------*/ + +void LPDmem_enc_init_fx( + LPD_state_HANDLE hLPDmem /* i/o: LP memories */ +) +{ + Word16 i; + + set16_fx( hLPDmem->syn, 0, 1 + M ); + set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); + set16_fx( hLPDmem->mem_syn, 0, M ); + set16_fx( hLPDmem->mem_syn1_fx, 0, M ); + set16_fx( hLPDmem->mem_syn2, 0, M ); + set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); + set16_fx( hLPDmem->mem_syn3, 0, M ); + + hLPDmem->q_lpd_old_exc = Q15; + move16(); + hLPDmem->q_lpd_syn = Q15; + move16(); + hLPDmem->q_mem_syn = Q15; + move16(); + + hLPDmem->mem_w0 = 0; + move16(); + hLPDmem->tilt_code = 0; move16(); + hLPDmem->gc_threshold = 0; + move32(); + hLPDmem->dm_fx.prev_state = 0; + move16(); /* This corresponds to st_fx->dispMem in FLP */ + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); + + FOR( i = 2; i < 8; i++ ) + { + hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } - return error; + return; } @@ -2198,8 +1295,8 @@ void destroy_cldfb_encoder_fx( Encoder_State *st /* i/o: Encoder static variables structure */ ) { - deleteCldfb_ivas_fx( &st->cldfbSynTd ); - deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); + deleteCldfb_fx( &st->cldfbSynTd ); + deleteCldfb_fx( &st->cldfbAnaEnc ); deleteFdCngEnc_fx( &st->hFdCngEnc ); diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 536cf1479736567f950faf63cc395d23de7e92c5..da6719f36f1773951fdfef8e53660885eacdac18 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -13,47 +13,46 @@ /*==============================================================================*/ -/* FUNCTION : inov_encode_fx() */ +/* FUNCTION : inov_encode_fx() */ /*------------------------------------------------------------------------------*/ -/* PURPOSE : Encode the algebraic innovation */ +/* PURPOSE : Encode the algebraic innovation */ /*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) core_brate: core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) h2 : weighted filter input response Q12 */ -/* _ (Word16[]) xn2 : target vector Q_new */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) i_subfr : current sub frame indicator Q0 */ -/* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */ -/* _ (Word16) L_subfr : subframe length Q0 */ -/* _ (Word16) clip_gain : adaptive gain clipping flag Q0 */ -/* _ (Word16) gain_pit : adaptive excitation gain Q14 */ -/* _ (Word16) sharpFlag : formant sharpening flag Q0 */ -/* _ (Word16) tc_subfr : TC subframe index Q0 */ -/* _ (Word16) p_Aq : LP filter coefficients Q12 */ -/* _ (Word16) Jopt_flag :joint optimization flag Q0 */ -/* _ (Word16) y1 : Filtered adaptive excitation Q_new */ -/* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */ -/* _ (Word16) cn : target vector in residual domain Q_new */ -/* _ (Word16) tilt_code : tilt of the excitation of previous subframe Q15 */ -/* _ (Word16) pt_pitch : pointer to current subframe fractional pitchQ6 */ -/* _ (Word16) index_buf_4T :5Sx4Track buffer for PI Q0 */ -/* _ (Word16) shift :shift */ -/* _ (Word16) Q_new : */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) core_brate: core bitrate Q0 */ +/* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */ +/* _ (Word16) bwidth : input signal bandwidth Q0 */ +/* _ (Word16) L_frame_fx: length of the frame Q0 */ +/* _ (Word16[]) h2 : weighted filter input response Q12 */ +/* _ (Word16[]) xn2 : target vector Q_new */ +/* _ (Word16) coder_type: coding type Q0 */ +/* _ (Word16) i_subfr : current sub frame indicator Q0 */ +/* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */ +/* _ (Word16) L_subfr : subframe length Q0 */ +/* _ (Word16) clip_gain : adaptive gain clipping flag Q0 */ +/* _ (Word16) gain_pit : adaptive excitation gain Q14 */ +/* _ (Word16) sharpFlag : formant sharpening flag Q0 */ +/* _ (Word16) tc_subfr : TC subframe index Q0 */ +/* _ (Word16) p_Aq : LP filter coefficients Q12 */ +/* _ (Word16) Jopt_flag :joint optimization flag Q0 */ +/* _ (Word16) y1 : Filtered adaptive excitation Q_new */ +/* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */ +/* _ (Word16) cn : target vector in residual domain Q_new */ +/* _ (Word16) tilt_code : tilt of the excitation of previous subframe Q15 */ +/* _ (Word16) pt_pitch : pointer to current subframe fractional pitchQ6 */ +/* _ (Word16) index_buf_4T :5Sx4Track buffer for PI Q0 */ +/* _ (Word16) shift :shift */ +/* _ (Word16) Q_new : */ /*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16) cn : target vector in residual domain Q_new */ -/* _ (Word16) code :algebraic excitation Q9 */ -/* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */ -/* _ (Word16) unbits :number of unused bits for PI Q0 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ +/* _ (Word16) cn : target vector in residual domain Q_new */ +/* _ (Word16) code :algebraic excitation Q9 */ +/* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */ +/* _ (Word16) unbits :number of unused bits for PI Q0 */ /*------------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==============================================================================*/ Word16 inov_encode_fx( @@ -79,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(); @@ -107,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 ) ) + IF( NE_32( st_fx->element_mode, EVS_MONO ) ) { - 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 ) ) - { - test(); - test(); - if ( EQ_32( core_brate, ACELP_8k00 ) && i_subfr == 0 && LT_16( tc_subfr, L_SUBFR ) ) + maximum_abs_16_fx( xn2, L_subfr, &max_xn2 ); + IF( max_xn2 ) { - 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 ); - } - } + Qxn = add( sub( Q_new, 1 ), shift ); } ELSE { - cmpl_flag = 4; + Qxn = 0; 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 ) - { } - ELSE - { - nBits = st_fx->acelp_cfg.fixed_cdk_index[shr( i_subfr, 6 )]; - 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; + Q_new = 0; move16(); - g2 = FORMANT_SHARPENING_G2_16k; - 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(); } /*----------------------------------------------------------------* @@ -415,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; @@ -437,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(); + } } } @@ -585,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 ) { @@ -623,7 +369,11 @@ Word16 inov_encode_ivas_fx( } ELSE { +#ifdef OPT_2416_ACELP_FAST + acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, h2, code, y2, L_subfr ); +#else acelp_fast_fx( hBstr, nBits, dn, Qdn, cn, Qcn, h2, code, y2, L_subfr ); +#endif } } ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 7 ) ) || ( st_fx->idchan == 0 && LE_16( st_fx->acelp_cfg.fixed_cdk_index[idx2], 3 ) ) ) @@ -634,7 +384,11 @@ Word16 inov_encode_ivas_fx( } ELSE { +#ifdef OPT_2416_ACELP_FAST + acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, h2, code, y2, L_SUBFR ); +#else acelp_fast_fx( hBstr, st_fx->acelp_cfg.fixed_cdk_index[idx2], dn, Qdn, cn, Qcn, h2, code, y2, L_SUBFR ); +#endif } } ELSE @@ -684,7 +438,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 d03f58ed5a18ac2a0a88e363816060f8a96e35b8..55956600df3ebf63cd1bf0c056022182efa9ec35 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 @@ -60,13 +56,13 @@ ivas_error ivas_core_enc_fx( Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal Q_new-1*/ Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal Q_new-1*/ Word16 Q_new[], /* i : Q factor of speech buffers */ - Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q*/ + Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q*/ Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes Q12*/ - Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q*/ + 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 : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15*/ + Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15*/ const Word16 vad_hover_flag[], /* i : VAD hanglover flag Q0*/ Word16 attack_flag[], /* i : attack flag (GSC or TC) Q0*/ Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer q_re_im_buf*/ @@ -74,14 +70,14 @@ ivas_error ivas_core_enc_fx( Word16 *q_re_im_buf, /* i : Q factor of re/im CLDFB buffers */ Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer e_old_wsp*/ Word16 e_old_wsp[], /* i : Q factor of old_wsp buffer */ - const Word16 loc_harm[], /* i : harmonicity flag Q0*/ - const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8*/ - const Word16 vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO Q0*/ + const Word16 loc_harm[], /* i : harmonicity flag Q0*/ + const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8*/ + const Word16 vad_flag_dtx[], /* i : 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], /* i : FFT buffer Qx*/ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag Q0*/ - const Word16 ivas_format, /* i : IVAS format Q0*/ + Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag Q0*/ + const Word16 ivas_format, /* i : IVAS format Q0*/ const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ ) { @@ -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,16 @@ ivas_error ivas_core_enc_fx( IF( st->core == ACELP_CORE ) { /* ACELP core encoder */ - 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 ) ) + 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 ) ) { return error; } - 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 } 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 +593,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 +607,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 @@ -665,7 +625,11 @@ ivas_error ivas_core_enc_fx( IF( GE_32( input_Fs, 16000 ) && LT_16( st->bwidth, SWB ) && st->hBWE_TD != NULL ) { /* Common pre-processing for WB TBE and WB BWE */ +#ifdef HARMONIZE_TBE2 + wb_pre_proc_fx( st, last_element_mode, new_inp_resamp16k_fx[n], hb_speech_fx ); +#else wb_pre_proc_ivas_fx( st, last_element_mode, new_inp_resamp16k_fx[n], hb_speech_fx ); +#endif } test(); @@ -673,12 +637,16 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ - 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] ); + 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 IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { /* WB BWE encoder */ +#ifdef HARM_FD_BWE + wb_bwe_enc_fx( st, new_inp_resamp16k_fx[n] ); +#else wb_bwe_enc_ivas_fx( st, new_inp_resamp16k_fx[n] ); +#endif } /*---------------------------------------------------------------------* @@ -686,16 +654,35 @@ 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] */ test(); +#ifdef HARMONIZE_TBE2 + IF( GE_32( input_Fs, 32000 ) && st->hBWE_TD != NULL ) +#else test(); IF( !st->Opt_SC_VBR && GE_32( input_Fs, 32000 ) && st->hBWE_TD != NULL ) +#endif { /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ +#ifdef HARMONIZE_TBE2 + swb_pre_proc_fx( st, new_swb_speech_fx_16, shb_speech_fx, realBuffer_fx[n], imagBuffer_fx[n], q_re_im_buf[n], NULL, hCPE ); +#else /* Scaling cldfb_state_fx */ Word16 q_shift, scf_cldfb; scf_cldfb = L_norm_arr( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length ); @@ -718,10 +705,10 @@ ivas_error ivas_core_enc_fx( scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, q_shift ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer 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 ); +#endif } ELSE IF( GE_32( input_Fs, 32000 ) ) { @@ -731,12 +718,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 +737,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 */ - fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); + fb_tbe_enc_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); } } } 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 ) ); +#ifdef HARM_FD_BWE + swb_bwe_enc_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, 0, sub( Q_new[n], 1 ) ); +#else + 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 ) ); +#endif } 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 +775,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 0a12c05eabe8cc6caa45aa399fb3d67036fcdde4..44f57cf5636030e29e642fa68406b320335e8e38 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,19 +434,28 @@ 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(); IF( EQ_16( element_mode, IVAS_SCE ) ) { +#ifndef FIX_2410_HARM_MODIF_FS new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx_q_inp, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ +#else + new_inp_out_size = modify_Fs_fx( signal_in_fx, input_frame, input_Fs, new_inp_12k8_fx, INT_FS_12k8, st->mem_decim_fx_q_inp, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ +#endif + Scale_sig( new_inp_12k8_fx, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ st->mem_q = st->q_inp; 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*/ +#ifndef FIX_2410_HARM_MODIF_FS + 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 */ +#else + new_inp_out_size = modify_Fs_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 */ +#endif + 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 ) ) { @@ -519,11 +466,19 @@ ivas_error pre_proc_front_ivas_fx( Word16 length_inp = NS2SA_FX2( input_Fs, L_MEM_RECALC_SCH_NS ); Word16 length_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); +#ifndef FIX_2410_HARM_MODIF_FS new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx_q_inp, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ +#else + new_inp_out_size = modify_Fs_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, INT_FS_12k8, st->mem_decim_fx_q_inp, 0, &Q_new_inp, &mem_decim_size ); /* st->q_inp */ +#endif + Scale_sig( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ } +#ifndef FIX_2410_HARM_MODIF_FS new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx_q_inp, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ +#else + new_inp_out_size = modify_Fs_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_12k8_fx - lMemRecalc_12k8, INT_FS_12k8, st->mem_decim_fx_q_inp, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ +#endif st->mem_q = st->q_inp; move16(); Copy( st->mem_decim_fx_q_inp, mem_decim_dummy_fx, 2 * L_FILT_MAX ); /* st->q_inp */ @@ -531,12 +486,20 @@ ivas_error pre_proc_front_ivas_fx( IF( lMemRecalc > 0 ) { +#ifndef FIX_2410_HARM_MODIF_FS new_inp_out_size = modify_Fs_ivas_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ - Scale_sig( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ +#else + new_inp_out_size = modify_Fs_fx( signal_in_fx + sub( input_frame, lMemRecalc ), lMemRecalc, input_Fs, new_inp_12k8_fx + sub( L_FRAME, lMemRecalc_12k8 ), INT_FS_12k8, mem_decim_dummy_fx, ( st->max_bwidth == NB ), &Q_new_inp, &mem_decim_size ); /* st->q_inp */ +#endif + Scale_sig( new_inp_12k8_fx + L_FRAME - lMemRecalc_12k8, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ } set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); +#ifndef FIX_2410_HARM_MODIF_FS 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 + new_inp_out_size = modify_Fs_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 */ +#endif + Scale_sig( new_inp_12k8_fx + L_FRAME, new_inp_out_size, negate( Q_new_inp ) ); /* scaling back to st->q_inp*/ } ELSE /* DFT stereo */ { @@ -581,34 +544,31 @@ 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 ) ) { - Copy_Scale_sig( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, sub( Q_inp_const, st->q_inp ) ); /* memory for TD/DFT stereo switching Q_inp_const*/ + Copy_Scale_sig( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, sub( Q_inp_const, st->q_inp ) ); /* memory for TD/DFT stereo switching Q_inp_const*/ st->mem_preemph_fx_q_inp = st->mem_preemph_DFT_fx_q_inp; /* st->q_inp */ move16(); 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 +583,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 +600,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 +626,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)*/ @@ -714,11 +669,7 @@ ivas_error pre_proc_front_ivas_fx( *Q_new = add( *Q_new, Q_inp_const ); move16(); -#ifndef FIX_2015_PREMPH_SAT_ALT - Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( *Q_new, st->q_inp ) ); /* Q_new */ -#else - Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( add( *Q_new, 1 ), st->q_inp ) ); /* Q_new */ -#endif + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( add( *Q_new, 1 ), st->q_inp ) ); /* Q_new */ Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), sub( *Q_new, st->q_inp ) ); /* Q_new */ cldfbScale.hb_scale = cldfbScale.lb_scale; @@ -783,16 +734,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 ) ) @@ -808,7 +749,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 @@ -819,7 +760,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(); @@ -876,7 +816,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(); @@ -887,18 +826,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 @@ -925,6 +852,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * FD-CNG Noise Estimator *----------------------------------------------------------------*/ + IF( st->hFdCngEnc != NULL ) { resetFdCngEnc_fx( st ); @@ -976,6 +904,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 ) ) @@ -994,7 +923,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(); @@ -1008,6 +937,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ + test(); test(); test(); @@ -1024,7 +954,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 */ @@ -1081,6 +1013,7 @@ ivas_error pre_proc_front_ivas_fx( /*----------------------------------------------------------------* * LP analysis *----------------------------------------------------------------*/ + Word16 stab_fac_fx; Word16 Q_r[2]; set16_fx( Q_r, 0, 2 ); @@ -1129,6 +1062,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 */ @@ -1147,7 +1081,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(); @@ -1181,6 +1115,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(); @@ -1194,8 +1129,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 ) ) @@ -1230,6 +1166,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 @@ -1299,6 +1236,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(); @@ -1306,6 +1244,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 @@ -1320,23 +1259,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 * @@ -1352,7 +1278,7 @@ ivas_error pre_proc_front_ivas_fx( * TC frame selection *-----------------------------------------------------------------*/ - st->clas = signal_clas_ivas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ + st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); /* Q0 */ move16(); select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); @@ -1366,6 +1292,7 @@ ivas_error pre_proc_front_ivas_fx( /*-----------------------------------------------------------------* * Collect stereo classifier features *-----------------------------------------------------------------*/ + IF( hStereoClassif != NULL ) { Word16 max_e_Etot; @@ -1380,6 +1307,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 ) ); @@ -1389,23 +1317,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 ) @@ -1454,6 +1370,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 ) ) { @@ -1510,6 +1427,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; @@ -1543,15 +1461,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(); @@ -1612,23 +1525,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) @@ -1644,29 +1540,29 @@ 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)*/ + Word32 enerBuffer_dft_fx[], /* o : energy buffer() exp(enerBuffer_dft_e)*/ const Word16 no_channels, /* i : no. of used CLDFB channels Q0*/ const Word32 input_Fs, /* i : input sampling rate Q0*/ Word16 enerBuffer_dft_e[] ) @@ -1733,5 +1629,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 5246e2026918bdef1b32fcd08c32b165c0e9bd8e..9134f304d468ebe8463f19727c0195d3474d3993 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; @@ -527,7 +515,7 @@ ivas_error pre_proc_ivas_fx( sr_core_tmp = L_max( INT_FS_16k, st->sr_core ); } - L_look = NS2SA_FX2( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) Q0*/ + L_look = NS2SA_FX2( sr_core_tmp, ACELP_LOOK_NS ); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) Q0*/ move16(); inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look; @@ -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,29 +664,31 @@ 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*/ - Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_old_inp_16k*/ + Word16 new_inp_resamp16k_out_fx[], /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE Q_old_inp_16k*/ const Word16 input_frame, /* i : frame length Q0*/ const Word16 last_element_mode, /* i : last element mode Q0*/ const Word32 sr_core, /* i : core-coder sampling rate Q0*/ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r*/ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r*/ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes Q14*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ + Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes Q14*/ 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(); } @@ -812,13 +789,21 @@ ivas_error ivas_compute_core_buffers_fx( } ELSE IF( EQ_32( input_Fs, 32000 ) || EQ_32( input_Fs, 48000 ) ) { +#ifndef FIX_2410_HARM_MODIF_FS size_modified = modify_Fs_ivas_fx( signal_in_fx, input_frame, input_Fs, new_inp_16k_fx, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ - Scale_sig( new_inp_16k_fx, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#else + size_modified = modify_Fs_fx( signal_in_fx, input_frame, input_Fs, new_inp_16k_fx, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ +#endif + Scale_sig( new_inp_16k_fx, 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 ); /* Q(-1) */ set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX ); +#ifndef FIX_2410_HARM_MODIF_FS size_modified = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), 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 ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#else + size_modified = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ +#endif + Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) @@ -843,24 +828,40 @@ ivas_error ivas_compute_core_buffers_fx( Word16 length_16k = NS2SA_FX2( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); move16(); - Copy( signal_in_fx - lMemRecalc - length_inp - 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */ + Copy( signal_in_fx - lMemRecalc - length_inp - 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), st->mem_decim16k_fx, 2 * NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ) ); /* st->q_inp */ +#ifndef FIX_2410_HARM_MODIF_FS size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k_fx - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ - Scale_sig( new_inp_16k_fx - lMemRecalc_16k - length_16k, size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#else + size_modified = modify_Fs_fx( signal_in_fx - lMemRecalc - length_inp, length_inp, input_Fs, new_inp_16k_fx - lMemRecalc_16k - length_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ +#endif + 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 */ +#ifndef FIX_2410_HARM_MODIF_FS + 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 */ +#else + size_modified = modify_Fs_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 */ +#endif + 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 */ +#ifndef FIX_2410_HARM_MODIF_FS + 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 */ +#else + size_modified = modify_Fs_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 */ +#endif + 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 ); +#ifndef FIX_2410_HARM_MODIF_FS size_modified = modify_Fs_ivas_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), 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 ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ +#else + size_modified = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ +#endif + Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ } } ELSE IF( st->idchan == 0 ) @@ -939,25 +940,18 @@ 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) */ + 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) */ st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; /* Q(-1) */ move16(); @@ -968,13 +962,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 +978,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 +995,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 +1005,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 +1023,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 +1034,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 ); @@ -1071,26 +1056,12 @@ ivas_error ivas_compute_core_buffers_fx( } st->Q_max_16k[i] = shift; move16(); -#ifndef FIX_2015_PREMPH_SAT_ALT - Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); -#else Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, add( *Q_new, 1 ) ); -#endif 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(); @@ -1113,7 +1084,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 ) ) @@ -1149,11 +1119,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 ); } /*-----------------------------------------------------------------* @@ -1163,20 +1139,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 ) ) ); @@ -1193,15 +1168,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 019361561b527f2a72eb22c1044df820d56e0067..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*/ @@ -135,7 +136,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( tmp = 0; move16(); } - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } } @@ -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(); @@ -372,7 +373,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( q_input_buff[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_old_inp32; move16(); } - destroy_sce_enc_fx( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); + destroy_sce_enc_fx( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 28c2992ffb8e86842e51ed30e2ee9e73895b0963..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" @@ -62,13 +59,13 @@ static void stereo_mode_combined_format_enc_fx( const Encoder_Struct *st_ivas, C *-------------------------------------------------------------------*/ ivas_error ivas_cpe_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier Q0*/ - Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx)*/ - Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx)*/ - Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ - const Word16 input_frame, /* i : input frame length per channel Q0*/ - const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier Q0*/ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx)*/ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx)*/ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel Q0*/ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ Word16 Q_new_out[] ) { CPE_ENC_HANDLE hCPE; @@ -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 ); @@ -206,8 +206,8 @@ ivas_error ivas_cpe_enc_fx( IF( st_ivas->hMCT == NULL ) /*already updated before CPE call*/ { - sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD Q0*/ - sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD Q0*/ + sts[n]->input_bwidth = sts[n]->last_input_bwidth; /* updated in BWD Q0*/ + sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD Q0*/ move16(); move16(); } @@ -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(); @@ -691,7 +702,7 @@ ivas_error ivas_cpe_enc_fx( stereo_dft_enc_analyze_fx( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT_fx, hCPE->hStereoDft->DFT_fx_e, hCPE->input_mem_fx, hCPE->q_input_mem ); - sts[0]->total_brate = L_mult0( add( sts[0]->bits_frame_nominal, 10 ), FRAMES_PER_SEC ); /* add small overhead; st[0]->total_brate used in coder_type_modif() Q0*/ + sts[0]->total_brate = L_mult0( add( sts[0]->bits_frame_nominal, 10 ), FRAMES_PER_SEC ); /* add small overhead; st[0]->total_brate used in coder_type_modif() Q0*/ /* Update DFT Stereo memories */ stereo_dft_enc_update_fx( hCPE->hStereoDft, max_bwidth ); @@ -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 ) { @@ -827,8 +835,8 @@ ivas_error ivas_cpe_enc_fx( stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, sts[0]->input32_fx, &out_start_ind, &out_end_ind, 0, input_Fs, input_Fs, 0, NULL ); - scale_sig32( sts[0]->input32_fx - input_frame, add( out_start_ind, input_frame ), sub( Q15, sts[0]->q_old_inp32 ) ); // scaling initial part of the input buffer - scale_sig32( sts[0]->input32_fx + out_end_ind, sub( input_frame, out_end_ind ), sub( Q15, sts[0]->q_inp32 ) ); // scaling initial part of the input buffer + Scale_sig32( sts[0]->input32_fx - input_frame, add( out_start_ind, input_frame ), sub( Q15, sts[0]->q_old_inp32 ) ); // scaling initial part of the input buffer + Scale_sig32( sts[0]->input32_fx + out_end_ind, sub( input_frame, out_end_ind ), sub( Q15, sts[0]->q_inp32 ) ); // scaling initial part of the input buffer sts[0]->q_inp32 = Q15; sts[0]->q_old_inp32 = Q15; move16(); @@ -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*/ @@ -988,12 +989,10 @@ ivas_error ivas_cpe_enc_fx( * Core codec configuration *----------------------------------------------------------------*/ -#ifdef FIX_1411_IGF_CRASH_BW_SWITCHING test(); test(); IF( NE_32( sts[0]->core_brate, SID_2k40 ) && NE_32( sts[0]->core_brate, FRAME_NO_DATA ) ) /* Reconfigurations not needed with DTX*/ { -#endif test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && st_ivas->hMCT == NULL ) { @@ -1034,13 +1033,9 @@ ivas_error ivas_cpe_enc_fx( test(); test(); test(); -#ifdef FIX_1411_IGF_CRASH_BW_SWITCHING test(); test(); IF( ( NE_32( hCPE->last_element_brate, hCPE->element_brate ) || NE_16( hCPE->element_mode, hCPE->last_element_mode ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( sts[0]->bits_frame_nominal, last_bits_frame_nominal ) ) || NE_16( sts[n]->last_bwidth, sts[n]->bwidth ) || EQ_32( sts[n]->last_core_brate, SID_2k40 ) || EQ_32( sts[n]->last_core_brate, FRAME_NO_DATA ) ) && ( EQ_16( n, 0 ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) -#else - IF( ( NE_32( hCPE->last_element_brate, hCPE->element_brate ) || NE_16( hCPE->element_mode, hCPE->last_element_mode ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( sts[0]->bits_frame_nominal, last_bits_frame_nominal ) ) || NE_16( sts[n]->last_bwidth, sts[n]->bwidth ) ) && ( n == 0 || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) -#endif { Word16 igf; Word16 bw; @@ -1055,20 +1050,15 @@ ivas_error ivas_cpe_enc_fx( } igf = getIgfPresent_fx( sts[n]->element_mode, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), bw, sts[n]->rf_mode ); /* Q0 */ move16(); -#ifdef FIX_1413_IGF_INIT_PRINTOUT + IF( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), bw, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK ) -#else - IF( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK ) -#endif { return error; } } } -#ifdef FIX_1411_IGF_CRASH_BW_SWITCHING } -#endif /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ FOR( n = 0; n < n_CoreChannels; n++ ) @@ -1107,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] ); } } @@ -1135,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 ); @@ -1195,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 } @@ -1461,17 +1455,17 @@ ivas_error create_cpe_enc_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ + st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } ELSE { - st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ + st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() Q0*/ move32(); } st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; move16(); - IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( st, st_ivas, n, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_decision_matrix_enc_fx.c b/lib_enc/ivas_decision_matrix_enc_fx.c index 3d1084b1d4cd3909ce7dee575609d4768e9b3e98..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() @@ -74,7 +70,7 @@ void ivas_decision_matrix_enc_fx( Encoder_State *st, /* i : encoder state structure */ const Word32 element_brate, /* i : element bitrate Q0*/ const Word16 fft_buff[], /* i : FFT buffer Qx*/ - const Word32 enerBuffer[], /* i : energy buffer enerBuffer_exp*/ + const Word32 enerBuffer[], /* i : energy buffer enerBuffer_exp*/ Word16 enerBuffer_exp, const Word16 last_element_mode /* i : last element mode Q0*/ ) @@ -573,11 +569,11 @@ void ivas_decision_matrix_enc_fx( *---------------------------------------------------------------------*/ void ivas_signaling_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel Q0*/ - const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel Q0*/ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo Q0*/ ) { Word16 ind; diff --git a/lib_enc/ivas_dirac_enc_fx.c b/lib_enc/ivas_dirac_enc_fx.c index 9886b1cb76c99b094f6b57256954cde6fbcc4700..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; @@ -316,15 +314,15 @@ ivas_error ivas_dirac_enc_fx( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - Word32 *data_f_fx[], /* i/o: SBA channels Qx*/ - Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q*/ - Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q*/ + Word32 *data_f_fx[], /* i/o: SBA channels Qx*/ + Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q*/ + Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q*/ Word16 pp_fr_q, - const Word16 input_frame, /* i : input frame length Q0*/ - const Word16 dtx_vad, /* i : DTX vad flag Q0*/ - const IVAS_FORMAT ivas_format, /* i : ivas format */ + const Word16 input_frame, /* i : input frame length Q0*/ + const Word16 dtx_vad, /* i : DTX vad flag Q0*/ + const IVAS_FORMAT ivas_format, /* i : ivas format */ const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 hodirac_flag, /* i : hodirac flag Q0*/ + const Word16 hodirac_flag, /* i : hodirac flag Q0*/ const Word16 shift ) { Word16 orig_dirac_bands; @@ -535,12 +533,12 @@ ivas_error ivas_dirac_enc_fx( *-------------------------------------------------------------------------*/ static Word16 ivas_dirac_get_mono_flag_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation Q0*/ - Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/ - Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/ - Word16 e_Cldfb, /* i : Exponent of cldfb buffer */ - const Word16 nchan_ana, /* i : number of analysis channels Q0*/ - Word16 *mono_frame_count ) /* i/o: current number of mono frames count Q0*/ + const Word16 *band_grouping, /* i : Band grouping for estimation Q0*/ + Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/ + Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/ + Word16 e_Cldfb, /* i : Exponent of cldfb buffer */ + const Word16 nchan_ana, /* i : number of analysis channels Q0*/ + Word16 *mono_frame_count ) /* i/o: current number of mono frames count Q0*/ { Word16 brange[2]; Word16 i, j, ch_idx; @@ -733,9 +731,9 @@ void computeReferencePower_enc_fx_dirac( const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/ Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/ - Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ + Word16 e_Cldfb, /* i : exponent of Cldfb buffer */ Word32 *reference_power, /* o : Estimated power e_reference*/ - Word16 *e_reference, /* o : exponent of reference_power */ + Word16 *e_reference, /* o : exponent of reference_power */ const Word16 enc_param_start_band, /* i : first band to process Q0*/ const Word16 num_freq_bands, /* i : Number of frequency bands Q0*/ const IVAS_FORMAT ivas_format, /* i : ivas_format */ @@ -1151,7 +1149,7 @@ void ivas_dirac_param_est_enc_fx( } /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 Q0*/ + hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 Q0*/ move16(); index = hDirAC->index_buffer_intensity; /* Q0 */ move16(); @@ -1464,7 +1462,7 @@ static void computeIntensityVector_enc_fx( const DIRAC_ENC_HANDLE hDirAC, Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* q_cldfb */ Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* q_cldfb */ - const Word16 enc_param_start_band, /* i : first band to process Q0*/ + const Word16 enc_param_start_band, /* i : first band to process Q0*/ const Word16 num_frequency_bands, /* Q0 */ Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS], /* q_intensity_real */ Word16 q_cldfb, @@ -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 ae7d26e2e4935e7aa57ed5dba44a6ba709f93107..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 @@ -60,12 +60,12 @@ static void ivas_band_cov_fx( Word32 **ppIn_FR_real, Word32 **ppIn_FR_imag, Word *------------------------------------------------------------------------*/ ivas_error ivas_spar_covar_enc_open_fx( - ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word32 input_Fs, /* i : input sampling rate Q0*/ - const Word16 nchan_inp, /* i : number of input channels Q0*/ - const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ - const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + const Word16 nchan_inp, /* i : number of input channels Q0*/ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { ivas_enc_cov_handler_state_t *hCovState; diff --git a/lib_enc/ivas_enc_fx.c b/lib_enc/ivas_enc_fx.c index 4d8f99650b8292e5de06f50139200af66827b22c..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,15 +41,16 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * ivas_enc() * * Principal IVAS encoder routine *-------------------------------------------------------------------*/ 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 Q0*/ + 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 Q0*/ ) { Word16 i, n, input_frame, n_samples_chan, nchan_inp /*, scale*/; @@ -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; } @@ -158,19 +156,11 @@ ivas_error ivas_enc_fx( test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) { -#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC hp20_fx_32_opt( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#else - hp20_fx_32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) { -#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC hp20_fx_32_opt( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#else - hp20_fx_32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } } 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 99da0175f5811480995bcaa76c6323584143300c..5980d77f04edd60a79c74223a0531c88133cc5a7 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" @@ -50,25 +45,25 @@ * Standalone front-VAD module *-----------------------------------------------------------------------------------------*/ ivas_error front_vad_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ - Encoder_State *st, /* i/o: encoder state structure */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ - const Word16 input_frame, /* i : frame length Q0*/ - Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO Q0*/ - Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands q_fr_bands_fx*/ - Word16 q_fr_bands[], /* o : Q of fr_bands_fx */ - Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8*/ - Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels q_lf_E*/ - Word16 q_lf_E[], /* o : Q of lf_E_fx */ - Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels Q0*/ - Word16 vad_hover_flag[], /* o : VAD hangover flag Q0*/ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ + Encoder_State *st, /* i/o: encoder state structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 input_frame, /* i : frame length Q0*/ + Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO Q0*/ + Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands q_fr_bands_fx*/ + Word16 q_fr_bands[], /* o : Q of fr_bands_fx */ + Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8*/ + Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels q_lf_E*/ + Word16 q_lf_E[], /* o : Q of lf_E_fx */ + Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels Q0*/ + Word16 vad_hover_flag[], /* o : VAD hangover flag Q0*/ Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN q_band_energies_LR */ - Word16 *q_band_energies_LR, /* o : Q of band_energies_LR_fx */ - Word32 *PS_out_fx, /* o : energy spectrum q_PS_out*/ - Word16 *q_PS_out, /* o : Q of PS_out_fx Q0*/ - Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7*/ + Word16 *q_band_energies_LR, /* o : Q of band_energies_LR_fx */ + Word32 *PS_out_fx, /* o : energy spectrum q_PS_out*/ + Word16 *q_PS_out, /* o : Q of PS_out_fx Q0*/ + Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7*/ Word16 Q_inp, Word16 *Q_buffer, Word16 Q_add, @@ -226,10 +221,14 @@ 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 */ +#ifndef FIX_2410_HARM_MODIF_FS 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 ); +#else + modify_Fs_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 ); +#endif /* Preemphasis */ hFrontVad->mem_preemph_fx = shl( hFrontVad->mem_preemph_fx, sub( add( Q_inp, Qband ), hFrontVad->q_mem_preemph_fx ) ); /* Q_inp + Qband */ @@ -237,7 +236,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 +290,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 +344,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(); @@ -452,10 +451,10 @@ void front_vad_destroy_fx( * Standalone front-VAD module for SPAR *-----------------------------------------------------------------------------------------*/ ivas_error front_vad_spar_fx( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ - const Word32 *omni_in, /* i : omnidirectional input signal Q11*/ - ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ - const Word16 input_frame /* i : input frame length Q0*/ + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ + const Word32 *omni_in, /* i : omnidirectional input signal Q11*/ + ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : encoder configuration handle */ + const Word16 input_frame /* i : input frame length Q0*/ ) { FRONT_VAD_ENC_HANDLE hFrontVad; @@ -533,7 +532,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 +604,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 +635,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 +687,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 +703,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 +734,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 6b1185b1e40dba82ffc0307eb949293da2c3f9e5..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 @@ -144,6 +143,7 @@ void ivas_write_format_fx( return; } + /*-------------------------------------------------------------------* * ivas_write_format_sid() * @@ -230,6 +230,7 @@ void ivas_write_format_sid_fx( return; } + /*-------------------------------------------------------------------* * getNumChanAnalysis() * @@ -288,9 +289,9 @@ Word16 getNumChanAnalysis_fx( *-------------------------------------------------------------------*/ void copy_encoder_config_fx( - Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ - Encoder_State *st_fx, /* o : encoder state structure */ - const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ + Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ + Encoder_State *st_fx, /* o : encoder state structure */ + const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ) { IF( flag_all ) @@ -333,13 +334,13 @@ void copy_encoder_config_fx( st_fx->force_dir = st_ivas->hEncoderConfig->force_dir; #endif #endif - st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; /* Q0 */ move16(); return; } + /*------------------------------------------------------------------------- * ivas_initialize_handles_enc_fx() * @@ -484,7 +485,7 @@ ivas_error ivas_init_encoder_fx( nchan_inp_buff = add( nchan_inp_buff, 1 ); /* Q0 */ } - nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object Q0*/ + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object Q0*/ } FOR( n = 0; n < nchan_inp_buff; n++ ) @@ -569,11 +570,13 @@ ivas_error ivas_init_encoder_fx( move16(); sce_id = 0; move16(); + test(); - IF( NE_32( ( error = create_evs_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } + /* prepare stereo downmix for EVS */ IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { @@ -672,6 +675,7 @@ ivas_error ivas_init_encoder_fx( { return error; } + test(); IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) { @@ -745,6 +749,7 @@ ivas_error ivas_init_encoder_fx( { return error; } + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -851,6 +856,7 @@ ivas_error ivas_init_encoder_fx( return error; } } + IF( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1041,8 +1047,6 @@ void destroy_core_enc_fx( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ) { - Word16 i; - destroy_cldfb_encoder_fx( hCoreCoder ); IF( hCoreCoder->hSignalBuf != NULL ) @@ -1053,165 +1057,6 @@ void destroy_core_enc_fx( IF( hCoreCoder->hBstr != NULL ) { - /* reset buffer of indices */ - FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) - { - hCoreCoder->hBstr->ind_list[i].nb_bits = -1; - move16(); - } - free( hCoreCoder->hBstr ); - hCoreCoder->hBstr = NULL; - } - - IF( hCoreCoder->hLPDmem != NULL ) - { - free( hCoreCoder->hLPDmem ); - hCoreCoder->hLPDmem = NULL; - } - - IF( hCoreCoder->hTranDet != NULL ) - { - free( hCoreCoder->hTranDet ); - hCoreCoder->hTranDet = NULL; - } - - IF( hCoreCoder->hNoiseEst != NULL ) - { - free( hCoreCoder->hNoiseEst ); - hCoreCoder->hNoiseEst = NULL; - } - - IF( hCoreCoder->hVAD != NULL ) - { - free( hCoreCoder->hVAD ); - hCoreCoder->hVAD = NULL; - } - - IF( hCoreCoder->hVAD_CLDFB != NULL ) - { - /* This is not required as this is only allocated in EVS mode */ - // free( hCoreCoder->hVAD_CLDFB ); - hCoreCoder->hVAD_CLDFB = NULL; - } - - IF( hCoreCoder->hTdCngEnc != NULL ) - { - free( hCoreCoder->hTdCngEnc ); - hCoreCoder->hTdCngEnc = NULL; - } - - IF( hCoreCoder->hDtxEnc != NULL ) - { - free( hCoreCoder->hDtxEnc ); - hCoreCoder->hDtxEnc = NULL; - } - - IF( hCoreCoder->hSpMusClas != NULL ) - { - free( hCoreCoder->hSpMusClas ); - hCoreCoder->hSpMusClas = NULL; - } - - IF( hCoreCoder->hGSCEnc != NULL ) - { - free( hCoreCoder->hGSCEnc ); - hCoreCoder->hGSCEnc = NULL; - } - - IF( hCoreCoder->hSC_VBR != NULL ) - { - free( hCoreCoder->hSC_VBR ); - hCoreCoder->hSC_VBR = NULL; - } - - IF( hCoreCoder->hAmrwb_IO != NULL ) - { - free( hCoreCoder->hAmrwb_IO ); - hCoreCoder->hAmrwb_IO = NULL; - } - - IF( hCoreCoder->hBWE_TD != NULL ) - { - free( hCoreCoder->hBWE_TD ); - hCoreCoder->hBWE_TD = NULL; - } - - IF( hCoreCoder->hBWE_FD != NULL ) - { - free( hCoreCoder->hBWE_FD ); - hCoreCoder->hBWE_FD = NULL; - } - - IF( hCoreCoder->hRF != NULL ) - { - free( hCoreCoder->hRF ); - hCoreCoder->hRF = NULL; - } - - IF( hCoreCoder->hTECEnc != NULL ) - { - free( hCoreCoder->hTECEnc ); - hCoreCoder->hTECEnc = NULL; - } - - IF( hCoreCoder->hTcxEnc != NULL ) - { - free( hCoreCoder->hTcxEnc ); - hCoreCoder->hTcxEnc = NULL; - } - - IF( hCoreCoder->hTcxCfg != NULL ) - { - free( hCoreCoder->hTcxCfg ); - hCoreCoder->hTcxCfg = NULL; - } - - IF( hCoreCoder->hIGFEnc != NULL ) - { - free( hCoreCoder->hIGFEnc ); - hCoreCoder->hIGFEnc = NULL; - } - - IF( hCoreCoder->hPlcExt != NULL ) - { - free( hCoreCoder->hPlcExt ); - hCoreCoder->hPlcExt = NULL; - } - - IF( hCoreCoder->hHQ_core != NULL ) - { - free( hCoreCoder->hHQ_core ); - hCoreCoder->hHQ_core = NULL; - } - - free( hCoreCoder ); - - return; -} - - -void destroy_evs_core_enc_fx( - ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ -) -{ - Word16 i; - - destroy_encoder_fx( hCoreCoder ); - - IF( hCoreCoder->hSignalBuf != NULL ) - { - free( hCoreCoder->hSignalBuf ); - hCoreCoder->hSignalBuf = NULL; - } - - IF( hCoreCoder->hBstr != NULL ) - { - /* reset buffer of indices */ - FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) - { - hCoreCoder->hBstr->ind_list[i].nb_bits = -1; - move16(); - } free( hCoreCoder->hBstr ); hCoreCoder->hBstr = NULL; } @@ -1358,19 +1203,19 @@ void ivas_destroy_enc_fx( move16(); /* SCE handles */ - for ( i = 0; i < MAX_SCE; i++ ) + FOR( i = 0; i < MAX_SCE; i++ ) { - if ( st_ivas->hSCE[i] != NULL ) + IF( st_ivas->hSCE[i] != NULL ) { - destroy_sce_enc_fx( st_ivas->hSCE[i], EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ); + destroy_sce_enc_fx( st_ivas->hSCE[i] ); st_ivas->hSCE[i] = NULL; } } /* CPE handles */ - for ( i = 0; i < MAX_CPE; i++ ) + FOR( i = 0; i < MAX_CPE; i++ ) { - if ( st_ivas->hCPE[i] != NULL ) + IF( st_ivas->hCPE[i] != NULL ) { destroy_cpe_enc( st_ivas->hCPE[i] ); st_ivas->hCPE[i] = NULL; @@ -1378,11 +1223,11 @@ void ivas_destroy_enc_fx( } /* HP20 filter handles */ - if ( st_ivas->mem_hp20_in_fx != NULL ) + IF( st_ivas->mem_hp20_in_fx != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); /* Q0 */ - for ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { free( st_ivas->mem_hp20_in_fx[i] ); st_ivas->mem_hp20_in_fx[i] = NULL; @@ -1395,7 +1240,7 @@ void ivas_destroy_enc_fx( ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); /* ISM DTX Handle */ - if ( st_ivas->hISMDTX != NULL ) + IF( st_ivas->hISMDTX != NULL ) { free( st_ivas->hISMDTX ); st_ivas->hISMDTX = NULL; diff --git a/lib_enc/ivas_ism_dtx_enc_fx.c b/lib_enc/ivas_ism_dtx_enc_fx.c index bc2c83de194dbd617a94602b48940049b4ea1824..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" @@ -219,8 +218,8 @@ Word16 ivas_ism_dtx_enc_fx( } /* estimate SID metadata bit-budget */ - nBits = add( nBits, 1 ); /* number of objects Q0*/ - nBits = add( nBits, 1 ); /* SID metadata flag Q0*/ + nBits = add( nBits, 1 ); /* number of objects Q0*/ + nBits = add( nBits, 1 ); /* SID metadata flag Q0*/ IF( EQ_16( md_diff_flag[ch], 1 ) ) { nBits = add( nBits, nBits_azimuth ); /* Q0 */ @@ -240,12 +239,12 @@ Word16 ivas_ism_dtx_enc_fx( FOR( ch = 0; ch < nchan_transport - 1; ch++ ) { - nBits_MD_max = sub( nBits_MD_max, nBits_coh ); /* coherence Q0*/ + nBits_MD_max = sub( nBits_MD_max, nBits_coh ); /* coherence Q0*/ } if ( GT_16( nchan_ism, 3 ) ) { - nBits_MD_max = sub( nBits_MD_max, 1 ); /* ism_mode flag Q0*/ + nBits_MD_max = sub( nBits_MD_max, 1 ); /* ism_mode flag Q0*/ } /* too many metadata bits -> switch to active coding */ @@ -430,10 +429,10 @@ void ivas_ism_get_sce_id_dtx_fx( * *-------------------------------------------------------------------*/ void ivas_ism_coh_estim_dtx_enc_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels Q0*/ - const Word16 input_frame /* i : input frame length Q0*/ + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 input_frame /* i : input frame length Q0*/ ) { Encoder_State *st, *st_id0; diff --git a/lib_enc/ivas_ism_enc_fx.c b/lib_enc/ivas_ism_enc_fx.c index d3aaa46caa6fa269dbf1f00a99bbf860cc59ae0e..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 @@ -49,12 +49,12 @@ * ISM CoreCoders encoding routine *-------------------------------------------------------------------*/ ivas_error ivas_ism_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - Word32 *data[], /* i : input signal [channels][samples] Q(q_data)*/ - Word16 q_data, /* i : Q-factor of input signal */ - const Word16 input_frame, /* i : input frame length per channel Q0*/ - Word16 *nb_bits_metadata, /* i : number of metadata bits Q0*/ - const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag Q0*/ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Word32 *data[], /* i : input signal [channels][samples] Q(q_data)*/ + Word16 q_data, /* i : Q-factor of input signal */ + const Word16 input_frame, /* i : input frame length per channel Q0*/ + Word16 *nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag Q0*/ ) { SCE_ENC_HANDLE hSCE; @@ -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 32582f2db10e8e7dedae16d3796559b0727d65ce..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" /*-----------------------------------------------------------------------* @@ -505,7 +503,6 @@ ivas_error ivas_ism_metadata_enc_fx( { idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); - // valQ = fixedToFloat( valQ_fx, Q22 ); } ELSE /* ISM_MODE_PARAM */ { @@ -527,7 +524,6 @@ ivas_error ivas_ism_metadata_enc_fx( Word16 valQ_fx_tmp = extract_h( valQ_fx ); // 22 - 16 = 6 idx_radius_abs = usquant_fx( hIsmMetaData->radius_fx, &valQ_fx_tmp, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8, 1 << ISM_RADIUS_NBITS ); valQ_fx = L_shr( L_deposit_h( valQ_fx_tmp ), 3 ); // Q22 - // valQ = fixedToFloat( valQ_fx, Q22 ); encode_angle_indices_fx( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); encode_radius_fx( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); } @@ -1078,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 7d8a0f8354eaed50eefa768990027c5a38fe4e49..3b30558bee542d00124505f039fe451155a767d3 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" @@ -274,7 +273,7 @@ void ivas_masa_enc_close_fx( FOR( i = 0; i < ( *hMasa )->data.num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); } IF( ( *hMasa )->data.hOmasaData != NULL ) @@ -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++ ) { @@ -2897,7 +2900,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( IF( VQLevels > 0 ) { - lfeToTotalEnergyRatioIndices[2] = vquant_ivas_fx( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors_fx, 4, VQLevels ); + lfeToTotalEnergyRatioIndices[2] = vquant_fx_32( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors_fx, 4, VQLevels ); move16(); } } 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..0a6c3550dd554e10ec60645e122825efa5bd902b 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, @@ -208,9 +206,6 @@ ivas_error ivas_mcmasa_enc_open_fx( /* initialize delay compensation */ hMcMasa->num_samples_delay_comp = NS2SA_FX2( input_Fs, DELAY_DIRAC_ENC_CMP_NS ); move16(); -#ifdef DISABLE_DIRAC_DELAY_COMP - hMcMasa->num_samples_delay_comp = 0; /* disable delay compensation by setting to 0 */ -#endif tmp_f = idiv1616( hMcMasa->num_samples_delay_comp, ( NS2SA_FX2( input_Fs, DIRAC_SLOT_ENC_NS ) ) ); hMcMasa->num_slots_delay_comp = tmp_f; move16(); @@ -919,7 +914,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 +1018,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 +1066,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 +2090,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 166bd67318dff995663cc884565ce74a3dc2bf0f..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" @@ -242,7 +241,7 @@ void ivas_omasa_enc_close_fx( FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -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..48d0aebc23cfb719447be93ab7ef2e7314c58309 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" @@ -2097,6 +2096,12 @@ static Word16 GR_bits_azimuth_context_fx( Word16 no_symb_local[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 no_data = 0; move16(); +#ifdef FIX_FLOAT_1522_LTV_MSAN_QMETADATA_ENC_EC3 + + *real_GR_ord = GR_order; /* Init to avoid sanitizer warnings */ + move16(); + +#endif FOR( i = 0; i < no_data_in; i++ ) { IF( LT_32( data_in[i], MASA_NO_INDEX ) ) 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 793546c7a30a0bfea4080665af662fbd0584fc1a..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" @@ -52,7 +51,7 @@ const Word16 unclr_isel_td[SIZE_UNCLR_ISEL_TD] = /* UNCLR classifier in TD stereo:: mean & scale for feature normalization */ const Word32 unclr_mean_td[SIZE_UNCLR_ISEL_TD] = /*Q15*/ { - 166277, 163748, 209465, 50557, 34744, 239251, 21, 1277892, 44, 19270 + 166277, 163748, 209465, 50557, 34744, 239251, 21, 1277892, 44, 19270 }; const Word32 unclr_scale_td[SIZE_UNCLR_ISEL_TD] = /*Q15*/ 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 8ad20a539678a179572b2d572f72e6da7ad6a578..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 *----------------------------------------------------------------*/ @@ -385,17 +390,18 @@ ivas_error ivas_sce_enc_fx( } #endif - pop_wmops(); return error; } + /*------------------------------------------------------------------------- * create_sce_enc() * * Create, allocate and initialize IVAS encoder SCE handle *-------------------------------------------------------------------------*/ + ivas_error create_sce_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 sce_id, /* i : SCE # identifier */ @@ -404,7 +410,6 @@ ivas_error create_sce_enc_fx( { SCE_ENC_HANDLE hSCE; Encoder_State *st; - ivas_error error; error = IVAS_ERR_OK; @@ -433,6 +438,7 @@ ivas_error create_sce_enc_fx( /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ + test(); IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { @@ -467,17 +473,19 @@ 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(); st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; st->input_Fs = st_ivas->hEncoderConfig->input_Fs; - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( st, st_ivas, 0, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } + hSCE->hCoreCoder[0] = st; st_ivas->hSCE[sce_id] = hSCE; @@ -485,115 +493,15 @@ ivas_error create_sce_enc_fx( return error; } -/*------------------------------------------------------------------------- - * create_evs_sce_enc_fx() - * - * Create, allocate and initialize EVS encoder SCE handle - *-------------------------------------------------------------------------*/ -ivas_error create_evs_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ -) -{ - SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id]; - Encoder_State *st_fx; - - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - - /*-----------------------------------------------------------------* - * Allocate SCE handle - *-----------------------------------------------------------------*/ - - IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); - } - - /*-----------------------------------------------------------------* - * Initialization - general parameters - *-----------------------------------------------------------------*/ - - hSCE->sce_id = sce_id; - move16(); - hSCE->element_brate = element_brate; - move32(); - hSCE->last_element_brate = hSCE->element_brate; - move32(); - /*-----------------------------------------------------------------* - * Metadata: allocate and initialize - *-----------------------------------------------------------------*/ - test(); - IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) - { - IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - hSCE->hMetaData = NULL; - } - - /*-----------------------------------------------------------------* - * Core Coder, 1 instance: allocate and initialize - *-----------------------------------------------------------------*/ - IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); - } - memset( st_fx, 0, sizeof( Encoder_State ) ); - - copy_encoder_config_fx( st_ivas, st_fx, 1 ); - - st_fx->bitstreamformat = G192; - move16(); - - st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; - move32(); - - st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - move16(); - - IF( NE_32( ( error = init_encoder_fx( st_fx, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - /* set pointer to the buffer of indices */ - st_fx->hBstr->ind_list = st_ivas->ind_list; - st_fx->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; - st_fx->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; - st_fx->hBstr->nb_ind_tot = 0; - move16(); - st_fx->hBstr->nb_bits_tot = 0; - move16(); - st_fx->hBstr->st_ivas = st_ivas; - - hSCE->hCoreCoder[0] = st_fx; - - st_ivas->hSCE[sce_id] = hSCE; - - return error; -} /*------------------------------------------------------------------------- - * destroy_sce_enc_fx() + * destroy_sce_enc() * * Destroy and deallocate IVAS encoder SCE handle *-------------------------------------------------------------------------*/ void destroy_sce_enc_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - Flag is_evs /* i : Flag to indicate EVS encoder*/ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ) { Encoder_State *st; @@ -602,17 +510,8 @@ void destroy_sce_enc_fx( IF( st != NULL ) { - test(); - IF( ( st->element_mode == EVS_MONO ) && is_evs ) - { - destroy_evs_core_enc_fx( st ); - st = NULL; - } - ELSE - { - destroy_core_enc_fx( st ); - st = NULL; - } + destroy_core_enc_fx( st ); + st = NULL; } ivas_destroy_MD_bstr_enc_fx( &( hSCE->hMetaData ) ); 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 0b1f77245a19521319ec8798eb0f65bde6e2162b..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 @@ -228,7 +227,7 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move32(); move32(); - IF( NE_32( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( hSpar->hCoreCoderVAD, st_ivas, 0, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -929,7 +928,8 @@ static ivas_error ivas_spar_enc_process_fx( IF( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { /*cross fade between new active W channels and old passive W channel*/ - IF( EQ_16( dyn_active_w_flag, 1 ) ) + test(); + IF( EQ_16( dyn_active_w_flag, 1 ) || EQ_16( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag, 1 ) ) { IF( NE_16( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag, dyn_active_w_flag ) ) { 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 6cad0ac687c366068b9160a9c550abc3fc9e62c4..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 @@ -1186,12 +1186,10 @@ typedef struct stereo_dmx_evs_correlation_filter_structure Word32 isd_rate_s_fx; // Q31 Word32 iccr_s_fx; // Q31 -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING - Word32 phitd_fx; // Q15 - Word32 iccres_s_fx; // Q31 + Word32 phitd_fx; // Q15 + Word32 iccres_s_fx; // Q31 Word32 lvlin_fx[CPE_CHANNELS]; Word16 lvlin_fx_e[CPE_CHANNELS]; -#endif Word32 ipd_ff_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 Word32 Pr_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 Word32 Pi_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 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..452043160530a1b45efaac8fd5c0e88c3481266c 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" @@ -306,7 +303,7 @@ static void stereo_td_channel_extrapolate_fx( } r_l[0] = s_max( r_l[0], 1 ); move16(); - flag = E_LPC_lev_dur( r_h, r_l, A, NULL, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER, NULL ); + flag = E_LPC_lev_dur_fx( r_h, r_l, A, NULL, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER, NULL ); Copy_Scale_sig( A, A, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER + 1, sub( norm_s( A[0] ), 2 ) ); IF( EQ_16( flag, 1 ) ) { diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index 73f7e246c0a698beec46c1b3efac010e5d99eca2..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" /*-----------------------------------------------------------------------* @@ -77,7 +73,6 @@ #define STEREO_DMX_EVS_ICCR_HYST_L_Q31 1610612736 #define STEREO_DMX_EVS_ICCR_HYST_H_Q31 1825361101 -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING #define STEREO_DMX_EVS_ICCRES_FORGETTING_Q31 1975684956 #define STEREO_DMX_EVS_LVLU_FORGETTING_Q31 1073741824 #define STEREO_DMX_EVS_LVLD_FORGETTING_Q31 1975684956 @@ -85,7 +80,6 @@ #define STEREO_DMX_EVS_ICLD_THRESH_FX_E 2 #define STEREO_DMX_EVS_ICCRES_THRESH_Q31 858993459 #define STEREO_DMX_EVS_DICLD_THRESH_Q30 1606570807 -#endif #define STEREO_DMX_EVS_SWTCH_HYS_THRES 1 #define STEREO_DMX_EVS_LR_EGY_Q27 2013265920 @@ -204,7 +198,6 @@ static void weighted_ave_fx( const Word16 input_frame, /* i : input frame length per channel */ const Word32 wnd_fx[] /* i : window coef Q31 */ ); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING static void calc_energy_fx( const Word32 src1_fx[], /* i : Lch input signal */ const Word32 src2_fx[], /* i : Rch input signal */ @@ -228,28 +221,6 @@ static void create_M_signal_fx( Word16 *src_energy_fx_e, /* i/o: input signal energy */ STEREO_DMX_EVS_PHA_HANDLE hPHA /* i/o: correlation filter structure */ ); -#else -static void calc_energy_fx( - const Word32 src1_fx[], /* i : Lch input signal */ - const Word32 src2_fx[], /* i : Rch input signal */ - Word32 energy_fx[], /* o : calculated energy */ - Word16 *energy_fx_e, /* o : calculated energy */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word32 ratio_float_fx ); -static void create_M_signal_fx( - const Word32 srcL_fx[], /* i : Lch input signal Q16 */ - const Word32 srcR_fx[], /* i : Rch input signal Q16 */ - Word32 dmx_fx[], /* o : output signal Q31 */ - const Word32 w_curr_fx, /* i : adapting weight Q31 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word32 wnd_fx[], /* i : window coef Q31 */ - Word32 *w_prev_fx, /* i/o: adapting prev weight Q31 */ - Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ - Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ - Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ - Word16 *src_energy_fx_e /* i/o: input signal energy */ -); -#endif static Word32 find_poc_peak_fx( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ Word16 itd_fx[], /* o : estimated itd */ @@ -763,13 +734,15 @@ static void calc_poc_fx( move32(); eneR_e = 0; move16(); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING - step = sub( n0 >> 3, 1 ); + step = sub( shr( n0, 3 ), 1 ); tmp1 = 0; + move32(); tmp2 = 0; + move32(); n1 = 0; + move16(); n2 = 0; -#endif + move16(); FOR( ( n = 1, i = 1 ); n < nsbd; n++ ) { @@ -867,15 +840,17 @@ static void calc_poc_fx( } eneR = BASOP_Util_Add_Mant32Exp( eneR, eneR_e, W_round64_L( W_tmp ), sub( 1, L_tmp_e ), &eneR_e ); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING IF( EQ_16( i, step ) ) { tmp1 = eneL; + move32(); n1 = eneL_e; + move16(); tmp2 = eneR; + move32(); n2 = eneR_e; + move16(); } -#endif } // Pn = (float) inv_sqrt( ( tPr * tPr + tPi * tPi ) + EPSILON ); @@ -906,12 +881,7 @@ static void calc_poc_fx( } /* Computes Spectral flatness on one channel */ -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING IF( LT_32( spectral_flatness_fx( &tEl[1], &tEl_e[1], sub( nsbd, 1 ) ), STEREO_DMX_EVS_IPD_SF_THRES_Q31 ) ) -#else - tmp1 = spectral_flatness_fx( &tEl[1], &tEl_e[1], nsbd - 1 ); - IF( LT_32( tmp1, STEREO_DMX_EVS_IPD_SF_THRES_Q31 ) ) -#endif { hPHA->pha_ipd_chanswitch_allowed = 0; move16(); @@ -935,7 +905,6 @@ static void calc_poc_fx( hPHA->iccr_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ICCR_FORGETTING_Q31, hPHA->iccr_s_fx ), Mpy_32_32_r( MAX_32 - STEREO_DMX_EVS_ICCR_FORGETTING_Q31, ICCr ) ); // Q31 move32(); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING step = add( step, 1 ); eneL = BASOP_Util_Add_Mant32Exp( eneL, eneL_e, -tmp1, n1, &eneL_e ); @@ -1010,7 +979,6 @@ static void calc_poc_fx( L_tmp = L_shl_sat( L_tmp, L_tmp_e ); // Q31 hPHA->iccres_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ICCRES_FORGETTING_Q31, hPHA->iccres_s_fx ), Mpy_32_32_r( L_sub( MAX_32, STEREO_DMX_EVS_ICCRES_FORGETTING_Q31 ), L_add_sat( ICCr >> 1, L_tmp >> 1 ) ) ); // Q31 -#endif IF( EQ_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD ) ) { @@ -1569,11 +1537,7 @@ static Word32 find_poc_peak_fx( move16(); move16(); move16(); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING - IF( Q_fx[n] == 0 ) -#else if ( Q_fx[n] == 0 ) -#endif { Q_e[n] = 0; move16(); @@ -1959,7 +1923,7 @@ static void renorm_poc_fx( * * calculate energy *-------------------------------------------------------------------*/ -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING + void calc_energy_fx( const Word32 src1_fx[], /* i : Lch input signal */ const Word32 src2_fx[], /* i : Rch input signal */ @@ -1969,23 +1933,9 @@ void calc_energy_fx( Word16 *lvl_fx_e, /* i/o: signal level */ const Word16 input_frame, /* i : input frame length per channel */ const Word32 ratio_float_fx ) -#else -void calc_energy_fx( - const Word32 src1_fx[], /* i : Lch input signal */ - const Word32 src2_fx[], /* i : Rch input signal */ - Word32 energy_fx[], /* o : calculated energy */ - Word16 *energy_fx_e, /* o : calculated energy */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word32 ratio_float_fx ) -#endif { -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING Word32 E_32_fx, wnd_fx, wnd_diff_fx, lvli_fx, lvlff_fx; Word16 i, adaptlen, lvli_fx_e; -#else - Word32 E_32_fx, wnd_fx, wnd_diff_fx; - Word16 i, adaptlen; -#endif Word64 E_fx; /* Initialization */ @@ -2050,23 +2000,25 @@ void calc_energy_fx( *energy_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( *energy_fx, ratio_float_fx ), *energy_fx_e, Mpy_32_32( temp32, L_sub( MAX_32, ratio_float_fx ) ), sub( 31, q_temp32 ), energy_fx_e ); move32(); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING + test(); IF( ( lvl_fx != NULL ) && ( lvl_fx_e != NULL ) ) { E_32_fx = BASOP_Util_Add_Mant32Exp( E_32_fx, sub( 31, q_E ), EPSILON_FX_M, EPSILON_FX_E, &temp_e ); lvli_fx = BASOP_Util_Log10( E_32_fx, temp_e ); lvli_fx_e = 6; // +6 : compensate result of log in Q25 + move16(); IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( lvli_fx, lvli_fx_e, *lvl_fx, *lvl_fx_e ), 1 ) ) { lvlff_fx = STEREO_DMX_EVS_LVLU_FORGETTING_Q31; + move32(); } ELSE { lvlff_fx = STEREO_DMX_EVS_LVLD_FORGETTING_Q31; + move32(); } *lvl_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( *lvl_fx, lvlff_fx ), *lvl_fx_e, Mpy_32_32( lvli_fx, L_sub( MAX_32, lvlff_fx ) ), lvli_fx_e, lvl_fx_e ); // Q(31 - *lvli_fx_e) } -#endif return; } @@ -2157,7 +2109,6 @@ static void adapt_gain_fx( * * create downmix signal *-------------------------------------------------------------------*/ -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING void create_M_signal_fx( const Word32 srcL_fx[], /* i : Lch input signal Q16 */ const Word32 srcR_fx[], /* i : Rch input signal Q16 */ @@ -2172,21 +2123,6 @@ void create_M_signal_fx( Word16 *src_energy_fx_e, /* i/o: input signal energy */ STEREO_DMX_EVS_PHA_HANDLE hPHA /* i/o: correlation filter structure */ ) -#else -void create_M_signal_fx( - const Word32 srcL_fx[], /* i : Lch input signal Q16 */ - const Word32 srcR_fx[], /* i : Rch input signal Q16 */ - Word32 dmx_fx[], /* o : output signal Q31 */ - const Word32 w_curr_fx, /* i : adapting weight Q31 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word32 wnd_fx[], /* i : window coef Q31 */ - Word32 *w_prev_fx, /* i/o: adapting prev weight Q31 */ - Word32 *dmx_energy_fx, /* i/o: downmix signal energy dmx_energy_fx_e */ - Word16 *dmx_energy_fx_e, /* i/o: downmix signal energy */ - Word32 *src_energy_fx, /* i/o: input signal energy src_energy_fx_e */ - Word16 *src_energy_fx_e /* i/o: input signal energy */ -) -#endif { Word32 amp_mod_fx[CPE_CHANNELS]; Word32 weighted_fx[L_FRAME48k], Lbias_fx; @@ -2209,15 +2145,9 @@ void create_M_signal_fx( move32(); } weighted_ave_fx( srcL_fx, srcR_fx, dmx_fx, w_curr_fx, w_prev_fx[0], input_frame, wnd_fx ); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING calc_energy_fx( srcL_fx, srcL_fx, src_energy_fx, src_energy_fx_e, hPHA->lvlin_fx, hPHA->lvlin_fx_e, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); calc_energy_fx( srcR_fx, srcR_fx, src_energy_fx + 1, src_energy_fx_e + 1, hPHA->lvlin_fx + 1, hPHA->lvlin_fx_e + 1, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); calc_energy_fx( dmx_fx, dmx_fx, dmx_energy_fx, dmx_energy_fx_e, NULL, NULL, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); -#else - calc_energy_fx( srcL_fx, srcL_fx, src_energy_fx, src_energy_fx_e, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); - calc_energy_fx( srcR_fx, srcR_fx, src_energy_fx + 1, src_energy_fx_e + 1, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); - calc_energy_fx( dmx_fx, dmx_fx, dmx_energy_fx, dmx_energy_fx_e, input_frame, STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX ); -#endif temp32_1 = Mpy_32_32( src_energy_fx[0], Lbias_fx ); // 31 - src_energy_fx_e + Q28-31 temp_e_1 = add( src_energy_fx_e[0], 3 ); @@ -2340,15 +2270,9 @@ void stereo_dmx_evs_enc_fx( Word32 dmx_poc_data[L_FRAME48k] /*Q11*/, dmx_pha_data[L_FRAME48k] /*Q11*/, *p_dmx_data, fx_tmp, *p_dmx_data_fo; Word16 n_fad_r, n_fad_g, m_fad_g, n_fad_cnt; -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING STEREO_DMX_EVS_PRC prev_prc, req_prc; Word32 L_tmp1, L_tmp2, L_dmx_weight, icld_fx; Word16 L_tmp1_e, L_tmp2_e, icld_fx_e; -#else - STEREO_DMX_EVS_PRC prev_prc; - Word32 L_tmp1, L_tmp2; - Word16 L_tmp1_e, L_tmp2_e; -#endif STEREO_DMX_EVS_PHA_HANDLE hPHA; @@ -2430,10 +2354,6 @@ void stereo_dmx_evs_enc_fx( move16(); FOR( k = 0; k < CPE_CHANNELS; k++ ) { -#ifndef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING - fx_tmp = 0; -#endif - move32(); FOR( m = 0; m < STEREO_DMX_EVS_NB_SBFRM; m++ ) { p_sub_frame = &( data_fx[k][m * input_subframe] ); @@ -2474,11 +2394,7 @@ void stereo_dmx_evs_enc_fx( L_tmp2 = BASOP_Util_Divide3232_Scale_newton( subframe_energy[m], L_tmp1, &L_tmp2_e ); L_tmp2_e = add( L_tmp2_e, sub( subframe_energy_e[m], L_tmp1_e ) ); // if ( subframe_energy[m] / ( subframe_energy[m - 1] + EPSILON ) > STEREO_DMX_EVS_TRNS_DTC_INST ) -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING - IF( BASOP_Util_Cmp_Mant32Exp( L_tmp2, L_tmp2_e, STEREO_DMX_EVS_TRNS_DTC_INST_Q0, 31 ) > 0 ) -#else if ( BASOP_Util_Cmp_Mant32Exp( L_tmp2, L_tmp2_e, STEREO_DMX_EVS_TRNS_DTC_INST_Q0, 31 ) > 0 ) -#endif { is_transient = 1; move16(); @@ -2508,16 +2424,12 @@ void stereo_dmx_evs_enc_fx( move16(); } -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING L_dmx_weight = L_deposit_h( dmx_weight ); L_tmp1 = L_deposit_l( BASOP_Util_Divide1616_Scale( hStereoDmxEVS->itd_fx, input_frame, &L_tmp1_e ) ); hPHA->phitd_fx = L_shl( L_tmp1, L_tmp1_e ); // Q15 + create_M_signal_fx( data_fx[0], data_fx[1], dmx_poc_data, L_dmx_weight, input_frame, hStereoDmxEVS->s_wnd_fx, hStereoDmxEVS->dmx_weight_fx, hStereoDmxEVS->pre_dmx_energy_fx, hStereoDmxEVS->pre_dmx_energy_fx_e, hStereoDmxEVS->aux_dmx_energy_fx, hStereoDmxEVS->aux_dmx_energy_fx_e, hPHA ); -#else - create_M_signal_fx( data_fx[0], data_fx[1], dmx_poc_data, L_deposit_h( dmx_weight ), input_frame, hStereoDmxEVS->s_wnd_fx, - hStereoDmxEVS->dmx_weight_fx, hStereoDmxEVS->pre_dmx_energy_fx, hStereoDmxEVS->pre_dmx_energy_fx_e, hStereoDmxEVS->aux_dmx_energy_fx, hStereoDmxEVS->aux_dmx_energy_fx_e ); -#endif // Downscaling signals to avoid accumulation overflows scale_sig32( data_fx[0], input_frame, -5 ); // Q31->Q26 @@ -2609,7 +2521,6 @@ void stereo_dmx_evs_enc_fx( move32(); // if ( abs( (int16_t) hStereoDmxEVS->itd ) > hPHA->prc_thres ) IF( GT_16( abs_s( hStereoDmxEVS->itd_fx ), hPHA->prc_thres ) ) -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING { req_prc = STEREO_DMX_EVS_PRC_POC; move32(); @@ -2652,55 +2563,6 @@ void stereo_dmx_evs_enc_fx( } hPHA->prev_prc = req_prc; move32(); -#else - { - IF( NE_32( hPHA->curr_prc, STEREO_DMX_EVS_PRC_POC ) ) - { - IF( EQ_32( hPHA->prev_prc, STEREO_DMX_EVS_PRC_POC ) ) - { - hPHA->prc_hys_cnt = add( hPHA->prc_hys_cnt, 1 ); - move16(); - } - ELSE - { - hPHA->prc_hys_cnt = 0; - move16(); - } - - IF( GE_16( hPHA->prc_hys_cnt, STEREO_DMX_EVS_SWTCH_PRC_HYS_THRES ) ) - { - hPHA->curr_prc = STEREO_DMX_EVS_PRC_POC; - move32(); - } - } - hPHA->prev_prc = STEREO_DMX_EVS_PRC_POC; - move32(); - } - ELSE - { - IF( NE_32( hPHA->curr_prc, STEREO_DMX_EVS_PRC_PHA ) ) - { - IF( EQ_32( hPHA->prev_prc, STEREO_DMX_EVS_PRC_PHA ) ) - { - hPHA->prc_hys_cnt = add( hPHA->prc_hys_cnt, 1 ); - move16(); - } - ELSE - { - hPHA->prc_hys_cnt = 0; - move16(); - } - - IF( GE_16( hPHA->prc_hys_cnt, STEREO_DMX_EVS_SWTCH_PRC_HYS_THRES ) ) - { - hPHA->curr_prc = STEREO_DMX_EVS_PRC_PHA; - move32(); - } - } - hPHA->prev_prc = STEREO_DMX_EVS_PRC_PHA; - move32(); - } -#endif // if ( ( is_transient == 1 ) || ( hStereoDmxEVS->aux_dmx_energy[0] > STEREO_DMX_EVS_ILDS_EGY * hStereoDmxEVS->aux_dmx_energy[1] ) || ( hStereoDmxEVS->aux_dmx_energy[1] > STEREO_DMX_EVS_ILDS_EGY * hStereoDmxEVS->aux_dmx_energy[0] ) || ( ( hPHA->p_curr_taps[0] == NULL ) && ( hPHA->p_curr_taps[1] == NULL ) ) ) test(); @@ -3151,8 +3013,8 @@ ivas_error stereo_dmx_evs_init_encoder_fx( hStereoDmxEVS->hPHA->iccr_s_fx = 0; move32(); -#ifdef FIX_2184_EVS_STEREO_DMX_CHANNEL_DISAPPEARING hStereoDmxEVS->hPHA->phitd_fx = 0; + move32(); hStereoDmxEVS->hPHA->iccres_s_fx = 0; move32(); FOR( n = 0; n < CPE_CHANNELS; n++ ) @@ -3162,7 +3024,6 @@ ivas_error stereo_dmx_evs_init_encoder_fx( hStereoDmxEVS->hPHA->lvlin_fx_e[n] = 0; move16(); } -#endif pha_len = hStereoDmxEVS->hPHA->pha_len; move16(); 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..aa80d7330202a1e9806025f12a09c1708c04748e 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*/ @@ -1399,8 +1410,11 @@ void stereo_icBWE_preproc_fx( Scale_sig( temp_inp_fx, L_FRAME48k, sub( 0, hStereoICBWE->q_dataChan_fx ) ); /* q_dataChan_fx */ /* IVAS-219: Re-wire the shb nonref estimation through a lite CLDFB */ +#ifndef FIX_2410_HARM_MODIF_FS modify_Fs_ivas_fx( temp_inp_fx, L_FRAME32k, 32000, tempSHB_fx, 16000, hStereoICBWE->mem_decim_shb_ch0_fx, 0, &Q_new_inp, &mem_decim_size ); - +#else + modify_Fs_fx( temp_inp_fx, L_FRAME32k, 32000, tempSHB_fx, 16000, hStereoICBWE->mem_decim_shb_ch0_fx, 0, &Q_new_inp, &mem_decim_size ); +#endif Copy_Scale_sig( tempSHB_fx, shb_speech_nonref_fx, L_FRAME16k, sub( q_shb_speech_nonref_fx, Q_new_inp ) ); /* q_shb_speech_nonref_fx */ return; 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 4375046237747b0b603012af082f673e133b9bf4..573edd197dee70778997c035f9de0d4f00bc25fe 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" @@ -58,7 +57,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } IF( st->hGSCEnc == NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -94,7 +93,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } - speech_music_clas_init_ivas_fx( st->hSpMusClas ); + speech_music_clas_init_fx( st->element_mode, st->hSpMusClas ); } return IVAS_ERR_OK; @@ -183,7 +182,7 @@ static void deallocate_CoreCoder_enc_fx( IF( st->cldfbAnaEnc != NULL ) { - deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); + deleteCldfb_fx( &st->cldfbAnaEnc ); } IF( st->hBWE_TD != NULL ) @@ -194,7 +193,7 @@ static void deallocate_CoreCoder_enc_fx( IF( st->cldfbSynTd != NULL ) { - deleteCldfb_ivas_fx( &st->cldfbSynTd ); + deleteCldfb_fx( &st->cldfbSynTd ); } IF( st->hBWE_FD != NULL ) @@ -362,8 +361,8 @@ ivas_error stereo_memory_enc_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) ) { /* Deallocate MDCT CNG structures */ - deleteCldfb_ivas_fx( &hCPE->hCoreCoder[0]->cldfbAnaEnc ); - deleteCldfb_ivas_fx( &hCPE->hCoreCoder[1]->cldfbAnaEnc ); + deleteCldfb_fx( &hCPE->hCoreCoder[0]->cldfbAnaEnc ); + deleteCldfb_fx( &hCPE->hCoreCoder[1]->cldfbAnaEnc ); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { @@ -386,7 +385,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,8 +434,8 @@ ivas_error stereo_memory_enc_fx( } } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { @@ -603,7 +602,10 @@ ivas_error stereo_memory_enc_fx( IF( st->hFdCngEnc == NULL ) { - createFdCngEnc_fx( &st->hFdCngEnc ); + IF( ( error = createFdCngEnc_fx( &st->hFdCngEnc ) ) != IVAS_ERR_OK ) + { + return error; + } initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); configureFdCngEnc_ivas_fx( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); @@ -679,7 +681,7 @@ void stereo_switching_enc_fx( /* window DFT synthesis overlap memory @input_Fs, primary channel */ FOR( i = 0; i < dft_ovl; i++ ) { - hCPE->hStereoDft->output_mem_dmx_fx[i] = L_shl( Mpy_32_32_r( hCPE->hStereoDft->win_fx[dft_ovl - 1 - i], old_input_signal_pri[input_frame - dft_ovl + i] ), sub( 15, q_inp ) ); // Q15 + hCPE->hStereoDft->output_mem_dmx_fx[i] = L_shl_sat( Mpy_32_32_r( hCPE->hStereoDft->win_fx[dft_ovl - 1 - i], old_input_signal_pri[input_frame - dft_ovl + i] ), sub( 15, q_inp ) ); // Q15 move32(); } /* reset 48kHz BWE overlap memory */ 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 e617e1a9ab707d744a1a3d6a97498694ba3d0812..0066efbe490041bc0d082064b3292d97c8c77051 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" @@ -263,7 +261,7 @@ ivas_error stereo_set_tdm_fx( /* deallocate CLDFB ana for secondary channel */ IF( st->cldfbAnaEnc != NULL ) { - deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); + deleteCldfb_fx( &st->cldfbAnaEnc ); } /* deallocate BWEs for secondary channel */ @@ -275,7 +273,7 @@ ivas_error stereo_set_tdm_fx( st->hBWE_TD = NULL; } - deleteCldfb_ivas_fx( &st->cldfbSynTd ); + deleteCldfb_fx( &st->cldfbSynTd ); IF( st->hBWE_FD != NULL ) { @@ -327,8 +325,8 @@ ivas_error stereo_set_tdm_fx( return error; } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { @@ -398,9 +396,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 +795,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 c10705e5db5192984f0279374dce3288edab1870..20f030c6d1ed0e0abe7e93ea3f6d4696b80cd043 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,7 @@ 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 */ { - InitTnsConfigs_ivas_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); + InitTnsConfigs_fx( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, total_brate, st->element_mode, 0 ); SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, 0 ); } @@ -370,7 +369,6 @@ void stereo_tcx_core_enc( * Core Signal Analysis: MDCT, TNS, LPC analysis *---------------------------------------------------------------*/ - /* TODO: integrate this. */ st->prev_Q_new = 0; st->Q_old = 0; @@ -422,8 +420,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 @@ -436,10 +434,8 @@ void stereo_tcx_core_enc( } } -#ifdef FIX_1384_MSAN_stereo_tcx_core_enc st->acelp_cfg.midLpc = 0; move16(); -#endif last_core_orig = st->last_core; move16(); @@ -633,17 +629,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..8ca5a4a5029a9986997db3831e7a3f96777e4464 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,8 @@ void tdm_low_rate_enc( Word16 Q_exc = Q_new; move16(); - 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 ); + + 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 ); /*--------------------------------------------------------------------------------------* * iDCT transform @@ -128,7 +127,7 @@ void tdm_low_rate_enc( * Remove potential pre-echo in case an onset has been detected *--------------------------------------------------------------------------------------*/ - pre_echo_att_ivas_fx( &st->hGSCEnc->Last_frame_ener_fx, exc_fx, attack_flag, Q_exc, st->last_coder_type, st->L_frame ); + 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 ); /*--------------------------------------------------------------------------------------* * Update BWE excitation @@ -176,8 +175,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 +187,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 +281,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 +304,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 +335,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/lead_indexing_fx.c b/lib_enc/lead_indexing_fx.c index c26c817f406acd1157f25b49a12974e4ac798703..361b2493592b843f2612fa7cfe5d2ea3da2648aa 100644 --- a/lib_enc/lead_indexing_fx.c +++ b/lib_enc/lead_indexing_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include 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 a242ad6792288918e0eafa5c736b8a3a863b1f55..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 *---------------------------------------------------------------------*/ @@ -540,17 +540,8 @@ ivas_error IVAS_ENC_FeedObjectMetadata( { return IVAS_ERR_INVALID_INDEX; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth_fx, metadata.elevation_fx, metadata.radius_fx, metadata.yaw_fx, metadata.pitch_fx, metadata.non_diegetic_flag ); -#else - Word32 azimuth_fx = float_to_fix( metadata.azimuth, Q22 ); /* Q22 */ - Word32 elevation_fx = float_to_fix( metadata.elevation, Q22 ); /* Q22 */ - Word16 radius_fx = float_to_fix16( metadata.radius, Q9 ); /* Q9 */ - Word32 yaw_fx = float_to_fix( metadata.yaw, Q22 ); /* Q22 */ - Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */ - error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag ); -#endif + error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth_fx, metadata.elevation_fx, metadata.radius_fx, metadata.yaw_fx, metadata.pitch_fx, metadata.non_diegetic_flag ); IF( error != IVAS_ERR_OK ) { return error; @@ -1493,16 +1484,14 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( hEncoderConfig->Opt_AMR_WB ) { - amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); + amr_wb_enc_fx( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in_fx[0], inputBufferSize ); } ELSE { #ifdef DEBUG_MODE_INFO dbgwrite( inputBuffer, sizeof( int16_t ), inputBufferSize, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, 1, ENC ), ".pcm" ) ); #endif - hCoreCoder->input_frame_fx = inputBufferSize; - move32(); - IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in_fx[0], inputBufferSize ) ), IVAS_ERR_OK ) ) { return error; } @@ -1527,6 +1516,34 @@ return error; } +/*---------------------------------------------------------------------* + * IVAS_ENC_EncodeFrameToCompact() + * + * Main function to encode one frame to a compact bitstream (bytestream) + *---------------------------------------------------------------------*/ + +ivas_error IVAS_ENC_EncodeFrameToCompact( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input */ + const Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord8 *outputBitStream, /* o : pointer to compact output bitstream. The array must already be allocated. */ + UWord16 *numOutBits /* o : number of bits written to output bitstream */ +) +{ + ivas_error error; + UWord16 bitstream[IVAS_MAX_BITS_PER_FRAME]; + + IF( NE_32( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, inputBuffer, inputBufferSize, bitstream, numOutBits ), IVAS_ERR_OK ) ) + { + return error; + } + + convertSerialToBytestream_fx( bitstream, *numOutBits, outputBitStream ); + + return IVAS_ERR_OK; +} + + /*---------------------------------------------------------------------* * IVAS_ENC_SetBandwidth() * diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index 93918b81e425b9c67cfdcb695fc78b273df403a4..46e455617ff6f55a18575767f80f4300671c1f13 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -16,7 +16,7 @@ * Compute relative energy, long-term average total noise energy and total active speech energy *-------------------------------------------------------------------*/ void ivas_long_enr_fx( - Encoder_State *st_fx, /* i/o: state structure */ + Encoder_State *st_fx, /* i/o: state structure */ const Word32 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q24 */ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover Q0*/ Word16 high_lpn_flag, /* i : sp/mus LPN flag Q0*/ @@ -145,15 +145,12 @@ void ivas_long_enr_fx( move32(); } - /*-----------------------------------------------------------------* - * Initialize parameters for energy tracking and signal dynamics - *-----------------------------------------------------------------*/ return; } void long_enr_fx( - Encoder_State *st_fx, /* i/o: state structure */ + Encoder_State *st_fx, /* i/o: state structure */ const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) Q8*/ const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover Q0*/ Word16 high_lpn_flag /* i : sp/mus LPN flag Q0*/ @@ -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 4d6084c879694fe13d70d85916e1378c8c5584c3..81c9b43a6e2efb1dc91b2515e33e829771e51f42 100644 --- a/lib_enc/lp_exc_e_fx.c +++ b/lib_enc/lp_exc_e_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -187,22 +187,20 @@ static Word16 adpt_enr_fx( const Word16 *exc, /* i : excitation vector Q_new */ const Word16 *h1, /* i : impuls response Q15 */ Word16 *y1, /* o : zero-memory filtered adpt. excitation 12 bits */ - const Word16 L_subfr, /* i : vector length */ - Word16 *gain, /* o : subframe adaptive gain Q14 */ - Word16 *g_corr, /* o : correlations for adptive gain mant/exp*/ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - const Word16 *xn, /* i : adaptive codebook target 12 bits Q_new-1+shift*/ - Word16 *xn2, /* o : algebraic codebook target 12 bits Q_new-1+shift*/ + const Word16 L_subfr, /* i : vector length */ + Word16 *gain, /* o : subframe adaptive gain Q14 */ + Word16 *g_corr, /* o : correlations for adptive gain mant/exp */ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ + const Word16 *xn, /* i : adaptive codebook target 12 bits Q_new-1+shift*/ + Word16 *xn2, /* o : algebraic codebook target 12 bits Q_new-1+shift*/ Word16 *exp_ener, /* o : adaptive excitation energy exp */ - Word16 use_prev_sf_pit_gain /* i : flag to use prev sf pitch gain or not */ + Word16 use_prev_sf_pit_gain /* i : flag to use prev sf pitch gain or not */ ) { Word16 ener, i; Word16 exc_tmp[L_FRAME16k], xn_tmp[L_FRAME16k]; Word32 Ltmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL /* Critical Overflow */ Flag Overflow = 0; -#endif Overflow = 0; move16(); @@ -289,9 +287,7 @@ Word16 corr_xy1_fx( Word16 tmp, xx, xy, yy, exp_xy, exp_xx, exp_yy, exp_div, gain, gain_p_snr; Word32 Ltmp1, Ltmp2; Word16 xn[L_FRAME16k], y1[L_FRAME16k]; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif /*----------------------------------------------------------------* * Find the ACELP correlations and the pitch gain @@ -393,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 0c5656ac447fdddddd91746589b0cce60dc03081..bc1f4cb3a979d6ec7b864bbe8a8505f500d48877 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 c0e02d6c245bafbdd51e2a5ffc2c02bb85a2e4c1..2f9f2b7c7a87fe1557a842fd5001e1c9eda70836 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 ); } @@ -1562,11 +1520,11 @@ Word16 lsf_msvq_ma_encprm_ivas_fx( *--------------------------------------------------------------------------*/ void midlsf_enc_fx( - const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 lsf[], /* i: lsf coefficients (3Q12) */ - Word16 *idx, /* o: codebook index */ - const Word16 lpcorder, /* i: order of the lpc */ + const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ + const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ + const Word16 lsf[], /* i: lsf coefficients (3Q12) */ + Word16 *idx, /* o: codebook index */ + const Word16 lpcorder, /* i: order of the lpc */ const Word32 *Bin_Ener_128_fx, // Q_ener const Word16 Q_ener, const Word8 narrowBand, @@ -1631,9 +1589,9 @@ void midlsf_enc_fx( } err = L_shl_sat( err, 2 ); - /* err = L_shl(err,Wscale); */ + /* err = L_shl(err,Wscale); */ err = Mult_32_16( err, LSF_1_OVER_256SQ ); - /* err = Mult_32_16(err,Wmult); */ + /* err = Mult_32_16(err,Wmult); */ IF( LT_32( err, err_min ) ) { @@ -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/ltd_stable_fx.c b/lib_enc/ltd_stable_fx.c index 036fe2a7e82b382fd7e8a48723a567799aa62e39..190c1ec2877994967654098be7b03946ce4830da 100644 --- a/lib_enc/ltd_stable_fx.c +++ b/lib_enc/ltd_stable_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -72,7 +72,7 @@ void ltd_stable_fx( frame_energy_Sqr32 = L_shl( frame_energy_Sqr32, 16 ); Q_frames_power32 = add( Q_frames_power32, 16 ); - /* +0.1 */ + /* +0.1 */ IF( GE_16( Q_frames_power32, 40 ) ) { zerop001 = L_shr( CNT0P001, 1 ); @@ -317,7 +317,7 @@ void ltd_stable_fx( Qsum_dif32 = add( Qsum_apow32, leadingzero_tmp32 ); Qsum_dif32 = add( Qsum_dif32, leadingzero_tmp32 ); - /* +0.1 */ + /* +0.1 */ IF( GE_16( Qsum_apow32, 44 ) ) { zerop001 = L_shr( CNT0P0001, 1 ); @@ -444,7 +444,7 @@ void ltd_stable_fx( Qsum_dif32 = add( Qsum_apow32, leadingzero_tmp32 ); Qsum_dif32 = add( Qsum_dif32, leadingzero_tmp32 ); - /* +0.1 */ + /* +0.1 */ IF( GE_16( Qsum_apow32, 44 ) ) { zerop001 = L_shr( CNT0P0001, 1 ); diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index 2b55889f57d542899ea5ec7f52c9ec2010a83a5b..e5b45a6b06be0dcc1da8e76b10dae786c8fc3b60 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index 8799806e4c021daccb656d6ca4935a28c934327a..bc502d49fe69a6ca5f7d5ec25f64af4c7795a54e 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/mslvq_enc_fx.c b/lib_enc/mslvq_enc_fx.c index 05c379f3199b38da686b7ee4cd4040024e4c9e67..0b2f9703d221bbf631f285d7c1d7b1ced2c959fd 100644 --- a/lib_enc/mslvq_enc_fx.c +++ b/lib_enc/mslvq_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 10d89ea75405eefb6f0b9bda29c6626357e08eee..6c0ef3f094856d397141a4ec99d2093c200bb43b 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -9,32 +9,38 @@ #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() * * Perform multi-harmonic analysis, information used for UV and VAD decision *---------------------------------------------------------------------*/ -/* o : frame multi-harmonicity (1-harmonic, 0-not) */ +/* 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 */ - { - /* *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] ) ) + IF( element_mode != EVS_MONO ) { - *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 181b1f10efdaa1b64a506e835250cf7b7f2480ab..ff6784c4e17bd0de3ca5515a6fe7d561510f36e1 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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(); @@ -1011,7 +1025,6 @@ void noise_est_fx( { hSpMusClas->ener_RAT_fx = 0; move16(); - // PMT("hSpMusClas->ener_RAT_fx = 0, that should be validated") } ELSE { @@ -1106,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(); } @@ -1158,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; @@ -1220,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 ) @@ -1259,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 @@ -1370,6 +1383,7 @@ void noise_est_fx( move16(); } } + test(); IF( GE_16( i, 2 ) && LE_16( i, 16 ) ) { @@ -1438,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(); @@ -1453,6 +1471,7 @@ void noise_est_fx( { *st_harm_cor_cnt = 1; } + test(); test(); if ( GT_16( *st_harm_cor_cnt, 1 ) && @@ -1466,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*/ ) ) { @@ -1487,6 +1506,7 @@ void noise_est_fx( move16(); } } + if ( *bg_cnt >= 0 ) { *bg_cnt = add( *bg_cnt, 1 ); @@ -1507,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 */ @@ -1532,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 *-----------------------------------------------------------------*/ @@ -1547,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 { @@ -1569,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 { @@ -1640,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; @@ -1658,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 ); @@ -1725,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 */ @@ -1789,7 +1801,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); @@ -1799,7 +1810,6 @@ void noise_est_fx( move16(); /* Q0 */ } - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); @@ -1818,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(); @@ -1918,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 ); @@ -1932,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 @@ -2183,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] */ @@ -2280,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(); @@ -2337,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 @@ -2390,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(); @@ -2420,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 ); @@ -2432,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(); @@ -2597,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 @@ -2771,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 */ ) ) @@ -2805,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 *-----------------------------------------------------------------*/ @@ -2814,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 */ ) ) ) ) @@ -2832,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 ) ) @@ -2841,7 +2857,6 @@ void noise_est_ivas_fx( move16(); } - /*-----------------------------------------------------------------* * Energy based pause length counter *-----------------------------------------------------------------*/ @@ -2994,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 { @@ -3048,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 ) || @@ -3079,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(); @@ -3119,9 +3133,11 @@ void noise_est_ivas_fx( move16(); move16(); } + /*-----------------------------------------------------------------* * Stereo classifier - save raw aEn *-----------------------------------------------------------------*/ + IF( hStereoClassif != NULL ) { /* @@ -3152,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 */ @@ -3213,7 +3226,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* ns_mask = non_sta < 1e5f; */ ns_mask = 0; move16(); @@ -3223,7 +3235,6 @@ void noise_est_ivas_fx( move16(); /* Q0 */ } - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ lt_haco_mask = 0; move16(); @@ -3242,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(); @@ -3579,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/noise_adjust_fx.c b/lib_enc/noise_adjust_fx.c index 2a6ffd22e4b5d6edf7d35d75d4f6f2b865e523cf..ffbcd8b0982e5515735e48cc45a6a87e4ff77ca4 100644 --- a/lib_enc/noise_adjust_fx.c +++ b/lib_enc/noise_adjust_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/normalizecoefs_fx.c b/lib_enc/normalizecoefs_fx.c index 696bf272fdf4e7be2f18900e29613a0914550fbc..89bfadac57e2a19a230c9ce195b1d5134cff34c5 100644 --- a/lib_enc/normalizecoefs_fx.c +++ b/lib_enc/normalizecoefs_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index bd87efb23cec3986c22e08e44636e0a08029e160..56b591ea56f522acc54e43440906d4a87ed454e4 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -517,7 +517,7 @@ Word16 peak_vq_enc_fx( assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); - // PMT("max_peaks equation needs to be converted") + /* max_peaks equation needs to be converted */ max_peaks = (Word16) ( ( core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS ) / HVQ_PEAKS_BPS_DELTA ); diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index c20ec2479ba48060bd8f32dcf2d2a85d0eb69ce0..1fff579055698c31cf92d70aabf0511db6b6e993 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -19,39 +19,39 @@ static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr ); /*==============================================================================*/ -/* FUNCTION : pit_encode_fx() */ +/* FUNCTION : pit_encode_fx() */ /*------------------------------------------------------------------------------*/ -/* PURPOSE : Close-loop pitch lag search and pitch lag quantization */ -/* Adaptive excitation construction */ +/* PURPOSE : Close-loop pitch lag search and pitch lag quantization */ +/* Adaptive excitation construction */ /*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) core_brate: core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ -/* _ (Word16[]) T_op : open loop pitch estimates in current frame Q0 */ -/* _ (Word16) T0_min : lower limit for close-loop search Q0 */ -/* _ (Word16) T0_max : higher limit for close-loop search Q0 */ -/* _ (Word16) T0 : close loop integer pitch Q0 */ -/* _ (Word16) T0_frac : close loop fractional part of the pitch Q0 */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) h1 : weighted filter input response Q15 */ -/* _ (Word16[]) xn : target vector Q_new */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) i_subfr : current sub frame indicator Q0 */ -/* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */ -/* _ (Word16[]) L_subfr : subframe length Q0 */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) core_brate: core bitrate Q0 */ +/* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */ +/* _ (Word16) bwidth : input signal bandwidth Q0 */ +/* _ (Word16[]) T_op : open loop pitch estimates in current frame Q0 */ +/* _ (Word16) T0_min : lower limit for close-loop search Q0 */ +/* _ (Word16) T0_max : higher limit for close-loop search Q0 */ +/* _ (Word16) T0 : close loop integer pitch Q0 */ +/* _ (Word16) T0_frac : close loop fractional part of the pitch Q0 */ +/* _ (Word16) L_frame_fx: length of the frame Q0 */ +/* _ (Word16[]) h1 : weighted filter input response Q15 */ +/* _ (Word16[]) xn : target vector Q_new */ +/* _ (Word16) coder_type: coding type Q0 */ +/* _ (Word16) i_subfr : current sub frame indicator Q0 */ +/* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */ +/* _ (Word16[]) L_subfr : subframe length Q0 */ /*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16) T0_min : lower limit for close-loop search Q0 */ -/* _ (Word16) T0_max : higher limit for close-loop search Q0 */ -/* _ (Word16) T0 : close loop integer pitch Q0 */ -/* _ (Word16) T0_frac : close loop fractional part of the pitch Q0 */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ +/* _ (Word16) T0_min : lower limit for close-loop search Q0 */ +/* _ (Word16) T0_max : higher limit for close-loop search Q0 */ +/* _ (Word16) T0 : close loop integer pitch Q0 */ +/* _ (Word16) T0_frac : close loop fractional part of the pitch Q0 */ /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*==============================================================================*/ /* o : Fractional pitch for each subframe */ @@ -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 ab97b615007e4aa8422ebec85113eea3ee455434..ff9a2ab647e30dc356085c49b1001c88d7bcf716 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -26,6 +26,7 @@ * The pitch is searched in the interval @@ -15,6 +15,7 @@ /*-----------------------------------------------------------------* * Local Constants *-----------------------------------------------------------------*/ + #define PIT_MIN2 20 /* pit_min for pitch tracking */ #define PIT_MIN_1 44 /* for second pitch track */ #define PIT_MIN2_1 24 @@ -58,11 +59,15 @@ static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[] static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); +static void pitch_ol_resolve_fx( Word16 pitch[3], Word16 voicing[3], Word16 *old_pitch, Word16 *old_corr, Word16 *old_thres, Word16 *delta_pit, const Word16 element_mode, const Word16 corr_shift, const Word16 relE, const Word16 Opt_SC_VBR, Word16 pitchX[NHFR][2 * NSECT], Word16 corX[NHFR][2 * NSECT], Word16 scaledX[NHFR][2 * NSECT], const Word16 sect0, const Word16 *pit_max, const Word16 pit_min_coding ); + + /*-----------------------------------------------------------------* * pitch_ol_init() * * Open loop pitch variable initialization *-----------------------------------------------------------------*/ + void pitch_ol_init_fx( Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ @@ -78,349 +83,660 @@ void pitch_ol_init_fx( move16(); *old_corr = 0; move16(); -} + return; +} -/*==================================================================================*/ -/* FUNCTION : pitch_ol_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : - * Compute the open loop pitch lag. - * - * The pitch lag search is divided into two sets. - * Each set is divided into three sections. - * Each section cannot have a pitch multiple. - * We find a maximum for each section. - * We compare the maxima of each section. - * - * 1st set 2nd set - * 1st section: lag delay = 115 down to 62 and 115 down to 78 - * 2nd section: lag delay = 61 down to 32 and 77 down to 41 - * 3rd section: lag delay = 31 down to 17 and 40 down to 22 - * 4th section: lag delay = 16 down to 10 and 21 down to 12 +/*-----------------------------------------------------------------* + * pitch_ol_resolve_fx() * - * As there is a margin between section overlaps, especially for - * longer delays, this section selection is more robust for not - * to find multiples in the same section when pitch evolves rapidly. * - * For each section, the length of the vectors to correlate is - * greater/equal to the longest pitch delay. */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ -/* _ (Word16[]) old_corr_fx : correlation Q15 */ -/* _ (Word16[]) corr_shift_fx : normalized correlation correction Q15 */ -/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ -/* to past frame pitch Q15 */ -/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ -/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ -/* _ (Word16[]) wsp_fx : weighted speech for current frame & look-ahead qwsp */ -/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ -/* _ (Word16[]) relE_fx : relative frame energy Q8 */ -/* _ (Word16[]) L_look : look-ahead Q0 */ -/* _ (Word16[]) Opt_SC_VBR : SC-VBR flag Q0 */ -/* _ (Word16*) qwsp : wsp & filter memory Qformat */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch : open loop pitch lag for each half-frame Q0 */ -/* _ (Word16[]) T_op : open loop pitch lag for each half-frm for quant Q0 */ -/* _ (Word16[]) voicing_fx : max normalized correlation for each half-frame QIn */ -/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ -/* _ (Word16[]) old_corr_fx : correlation Q15 */ -/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ -/* to past frame pitch Q15 */ -/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ -/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ -/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ -/*----------------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ + *-----------------------------------------------------------------*/ -void pitch_ol_fx( - Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ - Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ - Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ - Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ - Word16 corr_shift, /* i : normalized correlation correction Q15 */ - Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ - Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ - Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ - const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ - Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 last_class, /* i : frame classification of last frame */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 Opt_SC_VBR /* i : SC-VBR flag */ +static void pitch_ol_resolve_fx( + Word16 pitch[3], /* o : open loop pitch lag for each half-frame Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past Q15 or Q14) */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction Q0 */ + const Word16 element_mode, /* i : if element_mode != EVS old_thres is in Q14 */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 Opt_SC_VBR, /* i : SC-VBR flag */ + Word16 pitchX[NHFR][2 * NSECT], /* i : pitch candidates Q0 */ + Word16 corX[NHFR][2 * NSECT], /* i : correlation candidates Q15 */ + Word16 scaledX[NHFR][2 * NSECT], /* i/o: scaled correlation candidates Q12 */ + const Word16 sect0, /* i : section offset */ + const Word16 *pit_max, /* i : maximum pitch delays (array) */ + const Word16 pit_min_coding /* i : minimum pitch delay for coding */ ) { - Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; - Word16 tmp_mem[3]; - - Word16 scale1[2 * DELTA_COH - 1]; - Word16 scaled_buf[2 * LEN_X + 3 * ( DELTA_COH - 1 )]; - Word16 scaled_buf_exp[2 * LEN_X + 3 * ( DELTA_COH - 1 )], exp_sect[8], exp_sect1[8], exp_sect0; - Word16 cor_buf[2 * LEN_X]; - Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; - Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; - Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; - Word16 thres1[6]; - Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; - Word16 ind_corX, ind1_corX; - - Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; - Word16 len_temp; - Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; + Word16 i, ind, ind1, ind_corX, ind1_corX; + Word16 fac, ftmp, k, tmp16, diff, cnt; + Word16 add_sect0, sub_sect0; + Word16 coh_flag, coh_flag1; + Word16 cor_mean; + Word32 Ltmp; - Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; - Word32 enr, enr2, Ltmp; - Word16 fac, tmp16, tmp16_2; - Word16 qCorX, qScaledX; - Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; - const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; + Word16 pitch_tmp[2 * NHFR]; + Word16 ind_tmp[2 * NHFR]; + Word16 cor_tmp[2 * NHFR]; + Word16 thres1[2 * NHFR]; + Word16 tmp_buf[NHFR + 1]; - Word16 pit_min_coding; + /*-----------------------------------------------------------------* + * Favor a smaller delay if it happens that it has its multiple + * in the longer-delay sections (harmonics check) + *-----------------------------------------------------------------*/ - /*--------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------*/ - len = len_12k8; - len1 = len1_12k8; - sublen = sublen_12k8; - sublen1 = sublen1_12k8; - pit_max = pit_max_12k8; - sec_length = sec_length_12k8; - sec_length1 = sec_length1_12k8; + FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ + { + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + } + fac = THRES0; + move16(); /* the look-ahead */ + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ test(); - if ( ( LT_16( last_class, VOICED_TRANSITION ) ) && ( NE_16( bwidth, NB ) ) ) + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) { - /*reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings*/ - *old_thres = 0; - move16(); + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } - pit_min_coding = PIT_MIN_EXTEND; + fac = THRES0; move16(); + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ test(); - test(); - test(); - test(); - IF( ( ( NE_16( bwidth, NB ) ) && ( GT_16( *old_pitch, PIT_MIN ) ) ) || - ( ( EQ_16( bwidth, NB ) ) && ( ( GT_16( *old_pitch, PIT_MIN2_1 ) ) || ( LT_16( *old_thres, 3277 ) ) ) ) ) /* 0.1 inQ15*/ + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) { - pit_min = PIT_MIN / OPL_DECIM; + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ + } + + /*-----------------------------------------------------------------* + * Do 1st estimate for pitch values + * Adjust the normalized correlation using estimated noise level + * Compute the maximum scaling for the neighbour correlation + * reinforcement + *-----------------------------------------------------------------*/ + + add_sect0 = add( NSECT, sect0 ); + sub_sect0 = sub( NSECT, sect0 ); + FOR( i = 0; i < NHFR; i++ ) + { + /* 1st set of pitch candidates */ + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_tmp[i] = ind; move16(); - pit_min1 = PIT_MIN_1 / OPL_DECIM; + pitch_tmp[i] = pitchX[i][ind]; move16(); - subsect0 = 2; + cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); move16(); - sect0 = 1; + + /* Higher is the neighbour's correlation, higher is the weighting */ + /* operands are Q15, result is Q15 */ + thres1[i] = mult( THRES1, cor_tmp[i] ); move16(); - } - ELSE - { - pit_min = PIT_MIN2 / OPL_DECIM; + + /* 2nd set of pitch candidates */ + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind_tmp[i + NHFR] = ind1; move16(); - pit_min1 = PIT_MIN2_1 / OPL_DECIM; + pitch_tmp[i + NHFR] = pitchX[i][ind1]; move16(); - subsect0 = 0; + cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); move16(); - sect0 = 0; + + /* Higher is the neighbour's correlation, higher is the weighting */ + /* operands are Q15, result is Q15 */ + thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); move16(); } - - len_x = ( PIT_MAX / OPL_DECIM - pit_min + 1 ); - move16(); - len_x1 = ( PIT_MAX / OPL_DECIM - pit_min1 + 1 ); - move16(); - - /*--------------------------------------------------------------* - * Find decimated weighted speech - * Update wsp buffer with the memory - * decimation of wsp[] to search pitch in LF and to reduce complexity - * Extend the decimation of wsp to the end of the speech buffer - * Update wsp memory - *--------------------------------------------------------------*/ - Copy( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - - LP_Decim2_Copy( wsp, wsp2, L_FRAME, mem_decim2 ); - - /* Avoid uninitialized memory access */ - set16_fx( wsp2 + L_FRAME / 2, 0, sizeof( old_wsp2 ) / sizeof( Word16 ) - ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ) - L_FRAME / 2 ); - tmp_mem[0] = mem_decim2[0]; - move16(); - tmp_mem[1] = mem_decim2[1]; - move16(); - tmp_mem[2] = mem_decim2[2]; - move16(); - - LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[( L_FRAME / 2 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ - - Copy( &old_wsp2[L_FRAME / 2], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - - /*-----------------------------------------------------------------* - * Attenuate the correlation correction factor due to noise. - * Reset correlation buffer outside the useful range. - * Find the scaling functions for immediate neigbours and - * further ones. + /*---- + -------------------------------------------------------------* + * Take into account previous and next pitch values of the present + * frame and look-ahead. Choose the pitch lags and normalize + * correlations for each half-frame & look-ahead *-----------------------------------------------------------------*/ - corr_shift = shr( corr_shift, 1 ); - - set16_fx( scaled_buf, 0, DELTA_COH - 1 ); - set16_fx( scaled_buf + ( DELTA_COH - 1 ) + len_x, 0, DELTA_COH - 1 ); - set16_fx( scaled_buf + 2 * ( DELTA_COH - 1 ) + len_x + len_x1, 0, DELTA_COH - 1 ); - set16_fx( scaled_buf_exp, 0, len_x + len_x1 + 3 * ( DELTA_COH - 1 ) ); + pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); - pt1 = scale1 + DELTA_COH - 1; - pt2 = pt1; - tmp16 = mult( negate( *old_thres ), MAX_16 / DELTA_COH ); - k = *old_thres; - move16(); - FOR( i = 0; i < DELTA_COH; i++ ) + FOR( i = 0; i < NHFR; i++ ) { - /* - * *pt1 = ( -(*old_thres)/DELTA_COH * i + *old_thres+1.0f ); - * To keep Q15 values, the following code does not add 1 to the result. - * A scaling factor must be applied accordingly (see next use of scale1) - */ - *pt1 = k; - move16(); - k = add( k, tmp16 ); - *pt2-- = *pt1++; - move16(); - } + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - /*-----------------------------------------------------------------------------* - * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames - *-----------------------------------------------------------------------------*/ - old_tmp = add( *old_pitch, *delta_pit ); - old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); - old_tmp = s_max( old_tmp, pit_min ); - old_tmp1 = add( old_tmp, *delta_pit ); - old_tmp1 = s_min( old_tmp1, PIT_MAX / OPL_DECIM ); - old_tmp1 = s_max( old_tmp1, pit_min ); + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + + if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) + { + ind = ind1; + move16(); + } + test(); + if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) + { + ind_corX = ind1_corX; + move16(); + } + test(); + test(); + test(); + IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) + { + pitch[i] = pitchX[i][ind_corX]; + move16(); + voicing[i] = corX[i][ind_corX]; + move16(); + } + ELSE + { + pitch[i] = pitchX[i][ind]; + move16(); + voicing[i] = corX[i][ind]; + move16(); + } + } /*-----------------------------------------------------------------* - * Loop for all three half-frames (current frame + look-ahead) + * Increase the threshold for correlation reinforcement with + * the past if correlation high and pitch stable *-----------------------------------------------------------------*/ - pt_cor0 = scaled_buf + DELTA_COH - 1; - - pt_cor2 = pt_cor0 - pit_min + old_tmp; - pt_cor4 = pt_cor0 - pit_min1 + old_tmp + ( DELTA_COH - 1 ) + len_x; - - FOR( i = 0; i < NHFR; i++ ) /* i = 0, 1, 2 */ - { - pt1 = wsp2 + i * 2 * ( L_SUBFR / OPL_DECIM ); /* *pt1 -> Q12 */ - pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ - pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ - - enr = L_deposit_l( 1 ); - pt_cor1 = pt_cor0; - pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; + /* all Q15 here */ + /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ + Ltmp = L_mult( voicing[0], 16384 /*.5 Q15*/ ); + Ltmp = L_mac( Ltmp, voicing[1], 16384 /*.5 Q15*/ ); + cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); - pt_exp1 = scaled_buf_exp + DELTA_COH - 1; - pt_exp2 = pt_exp1; - pt_exp3 = scaled_buf_exp + 2 * ( DELTA_COH - 1 ) + len_x; - pt_exp4 = pt_exp3; + /* pitch unstable in present frame or from previous frame or normalized correlation too low */ + coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); + move16(); + coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); + move16(); - IF( LT_16( i, NHFR - 1 ) ) /* First two half-frames (current frame) */ + test(); + test(); + test(); + IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) + { + /* Reset the threshold */ + *old_thres = 0; + move16(); + } + ELSE + { + /* The threshold increase is directly dependent on normalized correlation */ + /* *old_thres += (0.16f * cor_mean); */ + IF( element_mode != EVS_MONO ) { - pt3 = pt1; - pt5 = pt1; - - FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ - { - /*-----------------------------------------------------------------* - * Find fixed vector energy - *-----------------------------------------------------------------*/ + *old_thres = round_fx( L_mac0( L_deposit_h( *old_thres ), 5243 /* 0.16f in Q15 */, cor_mean ) ); // Q14 + } + ELSE + { + *old_thres = round_fx( L_mac( L_deposit_h( *old_thres ), 5243 /* 0.16f in Q15 */, cor_mean ) ); // Q15 + } + move16(); + } + IF( element_mode != EVS_MONO ) + { + *old_thres = s_min( *old_thres, 11469 /* 0.7f in Q14 */ ); // Q14 + } + ELSE + { + *old_thres = s_min( *old_thres, THRES3 /* 0.7f in Q14 */ ); // Q15 + } + move16(); - /* 1st set */ - k = (Word16) ( pt1 - pt3 ); - move16(); + IF( GT_16( voicing[1], voicing[0] ) ) + { + *old_corr = voicing[1]; + move16(); + } + ELSE + { + *old_corr = cor_mean; + move16(); + } - FOR( k = add( k, len[j] ); k > 0; k-- ) - { - enr = L_mac0( enr, *pt3, *pt3 ); - pt3++; - } - /* keep Q15 normalized result */ - cnt = norm_l( enr ); - enr0[j] = extract_h( L_shl( enr, cnt ) ); - enr0_exp[j] = sub( 30, cnt ); - move16(); + /*-----------------------------------------------------------------* + * Extrapolate the pitch value for the next frame by estimating + * the pitch evolution. This value is added to the old_pitch + * in the next frame and is then used when the normalized + * correlation is reinforced by the past estimate + *-----------------------------------------------------------------*/ - /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ - pt5 = pt3; - enr2 = enr; /* sets to 'enr' in 1 clock */ - move32(); + tmp_buf[0] = *old_pitch; + move16(); + FOR( i = 0; i < NHFR; i++ ) + { + tmp_buf[i + 1] = pitch[i]; + move16(); + } - /* 2nd set */ - k = (Word16) ( pt1 - pt5 ); - move16(); + *delta_pit = 0; + move16(); + cnt = 0; + move16(); - FOR( k = add( k, len1[j] ); k > 0; k-- ) - { - enr2 = L_mac0( enr2, *pt5, *pt5 ); - pt5++; - } - cnt = norm_l( enr2 ); - enr0_1[j] = extract_h( L_shl( enr2, cnt ) ); - enr0_1_exp[j] = sub( 30, cnt ); - move16(); - } + FOR( i = 0; i < NHFR; i++ ) + { + diff = sub( tmp_buf[i + 1], tmp_buf[i] ); + move16(); + coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); - /*----------------------------------------------------------* - * Find correlation for the non-overlapping pitch lag values - *----------------------------------------------------------*/ - exp_sect[subsect0] = 0; + if ( coh_flag != 0 ) + { + *delta_pit = add( *delta_pit, diff ); move16(); - pt_cor5 = pt_cor1; - pt_cor6 = pt_cor3; - - tmp16 = exp_sect[subsect0]; + } + cnt = add( cnt, coh_flag ); + } + if ( EQ_16( cnt, 2 ) ) + { + /* *delta_pit /= 2; */ + *delta_pit = shr( *delta_pit, 1 ); + move16(); + } + IF( EQ_16( cnt, 3 ) ) + { + k = *delta_pit; + move16(); + /* *delta_pit /= 3; */ + if ( k < 0 ) + { + *delta_pit = mult( *delta_pit, -32768 /*-1 Q15*/ ); move16(); + } + tmp16 = mult( *delta_pit, 10923 /*1/3 Q15*/ ); + if ( k < 0 ) + { + tmp16 = mult( tmp16, -32768 /*-1 Q15*/ ); + } + *delta_pit = tmp16; + move16(); + } - k = (Word16) ( pt2 - pt1 + pit_max[subsect0] ); - - IF( k >= 0 ) - { - len_temp = sublen[0]; - move16(); + /*--------------------------------------------------------------* + * Update old pitch, upsample pitch, + *--------------------------------------------------------------*/ - FOR( ; k >= 0; k-- ) - { - /* Keep Q15 normalized result */ - /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ - /* Update exponent to reflect shr by 1 */ - *pt_cor1 = extract_h( L_shr( Dot_product12( pt1, pt2--, len_temp, pt_exp1 ), 1 ) ); + *old_pitch = pitch[1]; + move16(); - /* save the biggest exponent */ - tmp16 = s_max( tmp16, *pt_exp1 ); + FOR( i = 0; i < NHFR; i++ ) + { + /* compensate decimation */ + pitch[i] = i_mult2( pitch[i], OPL_DECIM ); + move16(); + } - pt_cor1++; - pt_exp1++; - } - } - exp_sect[subsect0] = tmp16; - move16(); + return; +} - /*----------------------------------------------------------* - * For each subsection, find the correlation - *----------------------------------------------------------*/ - FOR( j = subsect0; j < NSUBSECT; j++ ) - { - len_temp = sublen[j]; - move16(); - k = (Word16) ( pt2 - pt1 ); - move16(); - k = add( k, pit_max[j + 1] ); +/*==================================================================================*/ +/* FUNCTION : pitch_ol_fx() */ +/*----------------------------------------------------------------------------------*/ +/* PURPOSE : + * Compute the open loop pitch lag. + * + * The pitch lag search is divided into two sets. + * Each set is divided into three sections. + * Each section cannot have a pitch multiple. + * We find a maximum for each section. + * We compare the maxima of each section. + * + * 1st set 2nd set + * 1st section: lag delay = 115 down to 62 and 115 down to 78 + * 2nd section: lag delay = 61 down to 32 and 77 down to 41 + * 3rd section: lag delay = 31 down to 17 and 40 down to 22 + * 4th section: lag delay = 16 down to 10 and 21 down to 12 + * + * As there is a margin between section overlaps, especially for + * longer delays, this section selection is more robust for not + * to find multiples in the same section when pitch evolves rapidly. + * + * For each section, the length of the vectors to correlate is + * greater/equal to the longest pitch delay. */ +/*----------------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ +/* _ (Word16[]) old_corr_fx : correlation Q15 */ +/* _ (Word16[]) corr_shift_fx : normalized correlation correction Q15 */ +/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ +/* to past frame pitch Q15 */ +/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ +/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ +/* _ (Word16[]) wsp_fx : weighted speech for current frame & look-ahead qwsp */ +/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ +/* _ (Word16[]) relE_fx : relative frame energy Q8 */ +/* _ (Word16[]) L_look : look-ahead Q0 */ +/* _ (Word16[]) Opt_SC_VBR : SC-VBR flag Q0 */ +/* _ (Word16*) qwsp : wsp & filter memory Qformat */ +/*----------------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16[]) pitch : open loop pitch lag for each half-frame Q0 */ +/* _ (Word16[]) T_op : open loop pitch lag for each half-frm for quant Q0 */ +/* _ (Word16[]) voicing_fx : max normalized correlation for each half-frame QIn */ +/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ +/* _ (Word16[]) old_corr_fx : correlation Q15 */ +/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ +/* to past frame pitch Q15 */ +/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ +/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ +/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ +/*----------------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*==================================================================================*/ + +void pitch_ol_fx( + Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ + Word16 corr_shift, /* i : normalized correlation correction Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ + Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ + const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ + Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 last_class, /* i : frame classification of last frame */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 Opt_SC_VBR /* i : SC-VBR flag */ +) +{ + Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; + Word16 tmp_mem[3]; + + Word16 scale1[2 * DELTA_COH - 1]; + Word16 scaled_buf[2 * LEN_X + 3 * ( DELTA_COH - 1 )]; + Word16 scaled_buf_exp[2 * LEN_X + 3 * ( DELTA_COH - 1 )], exp_sect[8], exp_sect1[8], exp_sect0; + Word16 cor_buf[2 * LEN_X]; + Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; + Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; + Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; + Word16 cnt, ind, ind1, offset, offset1, offset_la, offset_la1; + Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1; + Word16 len_temp; + Word16 pitchX[NHFR][2 * NSECT]; + Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; + Word32 enr, enr2, Ltmp; + Word16 tmp16, tmp16_2; + Word16 qCorX, qScaledX; + Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT]; + const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; + + Word16 pit_min_coding; + + /*--------------------------------------------------------------* + * Initialization + *--------------------------------------------------------------*/ + len = len_12k8; + len1 = len1_12k8; + sublen = sublen_12k8; + sublen1 = sublen1_12k8; + pit_max = pit_max_12k8; + sec_length = sec_length_12k8; + sec_length1 = sec_length1_12k8; + + test(); + if ( ( LT_16( last_class, VOICED_TRANSITION ) ) && ( NE_16( bwidth, NB ) ) ) + { + /*reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings*/ + *old_thres = 0; + move16(); + } + + pit_min_coding = PIT_MIN_EXTEND; + move16(); + test(); + test(); + test(); + test(); + IF( ( ( NE_16( bwidth, NB ) ) && ( GT_16( *old_pitch, PIT_MIN ) ) ) || + ( ( EQ_16( bwidth, NB ) ) && ( ( GT_16( *old_pitch, PIT_MIN2_1 ) ) || ( LT_16( *old_thres, 3277 ) ) ) ) ) /* 0.1 inQ15*/ + { + pit_min = PIT_MIN / OPL_DECIM; + move16(); + pit_min1 = PIT_MIN_1 / OPL_DECIM; + move16(); + subsect0 = 2; + move16(); + sect0 = 1; + move16(); + } + ELSE + { + pit_min = PIT_MIN2 / OPL_DECIM; + move16(); + pit_min1 = PIT_MIN2_1 / OPL_DECIM; + move16(); + subsect0 = 0; + move16(); + sect0 = 0; + move16(); + } + + len_x = ( PIT_MAX / OPL_DECIM - pit_min + 1 ); + move16(); + len_x1 = ( PIT_MAX / OPL_DECIM - pit_min1 + 1 ); + move16(); + + /*--------------------------------------------------------------* + * Find decimated weighted speech + * Update wsp buffer with the memory + * decimation of wsp[] to search pitch in LF and to reduce complexity + * Extend the decimation of wsp to the end of the speech buffer + * Update wsp memory + *--------------------------------------------------------------*/ + Copy( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + + LP_Decim2_Copy( wsp, wsp2, L_FRAME, mem_decim2 ); + + /* Avoid uninitialized memory access */ + set16_fx( wsp2 + L_FRAME / 2, 0, sizeof( old_wsp2 ) / sizeof( Word16 ) - ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ) - L_FRAME / 2 ); + tmp_mem[0] = mem_decim2[0]; + move16(); + tmp_mem[1] = mem_decim2[1]; + move16(); + tmp_mem[2] = mem_decim2[2]; + move16(); + + LP_Decim2_Copy( &wsp[L_FRAME], &wsp2[( L_FRAME / 2 )], L_LOOK_12k8, tmp_mem ); /* shr() used instead of division by OPL_DECIM*/ + + Copy( &old_wsp2[L_FRAME / 2], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + + /*-----------------------------------------------------------------* + * Attenuate the correlation correction factor due to noise. + * Reset correlation buffer outside the useful range. + * Find the scaling functions for immediate neigbours and + * further ones. + *-----------------------------------------------------------------*/ + + corr_shift = shr( corr_shift, 1 ); + + set16_fx( scaled_buf, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf + ( DELTA_COH - 1 ) + len_x, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf + 2 * ( DELTA_COH - 1 ) + len_x + len_x1, 0, DELTA_COH - 1 ); + set16_fx( scaled_buf_exp, 0, len_x + len_x1 + 3 * ( DELTA_COH - 1 ) ); + + pt1 = scale1 + DELTA_COH - 1; + pt2 = pt1; + tmp16 = mult( negate( *old_thres ), MAX_16 / DELTA_COH ); + k = *old_thres; + move16(); + FOR( i = 0; i < DELTA_COH; i++ ) + { + /* + * *pt1 = ( -(*old_thres)/DELTA_COH * i + *old_thres+1.0f ); + * To keep Q15 values, the following code does not add 1 to the result. + * A scaling factor must be applied accordingly (see next use of scale1) + */ + *pt1 = k; + move16(); + k = add( k, tmp16 ); + *pt2-- = *pt1++; + move16(); + } + + /*-----------------------------------------------------------------------------* + * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames + *-----------------------------------------------------------------------------*/ + + old_tmp = add( *old_pitch, *delta_pit ); + old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); + old_tmp = s_max( old_tmp, pit_min ); + old_tmp1 = add( old_tmp, *delta_pit ); + old_tmp1 = s_min( old_tmp1, PIT_MAX / OPL_DECIM ); + old_tmp1 = s_max( old_tmp1, pit_min ); + + /*-----------------------------------------------------------------* + * Loop for all three half-frames (current frame + look-ahead) + *-----------------------------------------------------------------*/ + + pt_cor0 = scaled_buf + DELTA_COH - 1; + + pt_cor2 = pt_cor0 - pit_min + old_tmp; + pt_cor4 = pt_cor0 - pit_min1 + old_tmp + ( DELTA_COH - 1 ) + len_x; + + FOR( i = 0; i < NHFR; i++ ) /* i = 0, 1, 2 */ + { + pt1 = wsp2 + i * 2 * ( L_SUBFR / OPL_DECIM ); /* *pt1 -> Q12 */ + pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ + pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ + + enr = L_deposit_l( 1 ); + + pt_cor1 = pt_cor0; + pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; + + pt_exp1 = scaled_buf_exp + DELTA_COH - 1; + pt_exp2 = pt_exp1; + pt_exp3 = scaled_buf_exp + 2 * ( DELTA_COH - 1 ) + len_x; + pt_exp4 = pt_exp3; + + IF( LT_16( i, NHFR - 1 ) ) /* First two half-frames (current frame) */ + { + pt3 = pt1; + pt5 = pt1; + + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + { + /*-----------------------------------------------------------------* + * Find fixed vector energy + *-----------------------------------------------------------------*/ + + /* 1st set */ + k = (Word16) ( pt1 - pt3 ); + move16(); + + FOR( k = add( k, len[j] ); k > 0; k-- ) + { + enr = L_mac0( enr, *pt3, *pt3 ); + pt3++; + } + /* keep Q15 normalized result */ + cnt = norm_l( enr ); + enr0[j] = extract_h( L_shl( enr, cnt ) ); + enr0_exp[j] = sub( 30, cnt ); + move16(); + + /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ + pt5 = pt3; + enr2 = enr; /* sets to 'enr' in 1 clock */ + move32(); + + /* 2nd set */ + k = (Word16) ( pt1 - pt5 ); + move16(); + + FOR( k = add( k, len1[j] ); k > 0; k-- ) + { + enr2 = L_mac0( enr2, *pt5, *pt5 ); + pt5++; + } + cnt = norm_l( enr2 ); + enr0_1[j] = extract_h( L_shl( enr2, cnt ) ); + enr0_1_exp[j] = sub( 30, cnt ); + move16(); + } + + /*----------------------------------------------------------* + * Find correlation for the non-overlapping pitch lag values + *----------------------------------------------------------*/ + + exp_sect[subsect0] = 0; + move16(); + pt_cor5 = pt_cor1; + pt_cor6 = pt_cor3; + + tmp16 = exp_sect[subsect0]; + move16(); + + k = (Word16) ( pt2 - pt1 + pit_max[subsect0] ); + + IF( k >= 0 ) + { + len_temp = sublen[0]; + move16(); + + FOR( ; k >= 0; k-- ) + { + /* Keep Q15 normalized result */ + /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ + /* Update exponent to reflect shr by 1 */ + *pt_cor1 = extract_h( L_shr( Dot_product12( pt1, pt2--, len_temp, pt_exp1 ), 1 ) ); + + /* save the biggest exponent */ + tmp16 = s_max( tmp16, *pt_exp1 ); + + pt_cor1++; + pt_exp1++; + } + } + exp_sect[subsect0] = tmp16; + move16(); + + /*----------------------------------------------------------* + * For each subsection, find the correlation + *----------------------------------------------------------*/ + + FOR( j = subsect0; j < NSUBSECT; j++ ) + { + len_temp = sublen[j]; + move16(); + + k = (Word16) ( pt2 - pt1 ); + move16(); + k = add( k, pit_max[j + 1] ); exp_sect[j + 1] = 0; move16(); exp_sect1[j] = 0; @@ -525,6 +841,7 @@ void pitch_ol_fx( /*-----------------------------------------------------------------* * Find correlation for the non-overlapping pitch lag values *-----------------------------------------------------------------*/ + exp_sect[subsect0] = 0; move16(); pt_cor5 = pt_cor1; @@ -673,6 +990,7 @@ void pitch_ol_fx( * Scale correlation function in the neighbourhood of * the extrapolated pitch *-----------------------------------------------------------------*/ + pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); pt2 = scale1; @@ -791,269 +1109,23 @@ void pitch_ol_fx( Ltmp = L_mult0( pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x], enr1 ); qScaledX = add( sub( 15, enr1_exp ), sub( 14, pt_exp3[ind1] ) ); scaledX[i][j + NSECT] = round_fx( L_shl( Ltmp, sub( 16 + 12, qScaledX ) ) ); - /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ - qScaledX = 12; - move16(); - - pt_cor3 += sec_length1[j]; - move16(); - offset1 = add( offset1, sec_length1[j] ); - - } /* FOR j < NSECT */ - } /* FOR i < NHFR */ - - /*-----------------------------------------------------------------* - * Favor a smaller delay if it happens that it has its multiple - * in the longer-delay sections (harmonics check) - *-----------------------------------------------------------------*/ - - FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ - { - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - } - - fac = THRES0; - move16(); /* the look-ahead */ - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ - } - - /*-----------------------------------------------------------------* - * Do 1st estimate for pitch values - * Adjust the normalized correlation using estimated noise level - * Compute the maximum scaling for the neighbour correlation - * reinforcement - *-----------------------------------------------------------------*/ - add_sect0 = add( NSECT, sect0 ); - sub_sect0 = sub( NSECT, sect0 ); - FOR( i = 0; i < NHFR; i++ ) - { - /* 1st set of pitch candidates */ - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_tmp[i] = ind; - move16(); - pitch_tmp[i] = pitchX[i][ind]; - move16(); - cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); - move16(); - - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i] = mult( THRES1, cor_tmp[i] ); - move16(); - - /* 2nd set of pitch candidates */ - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind_tmp[i + NHFR] = ind1; - move16(); - pitch_tmp[i + NHFR] = pitchX[i][ind1]; - move16(); - cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); - move16(); - - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); - move16(); - } - /*-----------------------------------------------------------------* - * Take into account previous and next pitch values of the present - * frame and look-ahead. Choose the pitch lags and normalize - * correlations for each half-frame & look-ahead - *-----------------------------------------------------------------*/ - - pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); - FOR( i = 0; i < NHFR; i++ ) - { - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - - if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) - { - ind = ind1; - move16(); - } - test(); - if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) - { - ind_corX = ind1_corX; - move16(); - } - test(); - test(); - test(); - IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) - { - pitch[i] = pitchX[i][ind_corX]; - move16(); - voicing[i] = corX[i][ind_corX]; - move16(); - } - ELSE - { - pitch[i] = pitchX[i][ind]; - move16(); - voicing[i] = corX[i][ind]; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Increase the threshold for correlation reinforcement with - * the past if correlation high and pitch stable - *-----------------------------------------------------------------*/ - - /* all Q15 here */ - /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult( voicing[0], 16384 ); - Ltmp = L_mac( Ltmp, voicing[1], 16384 ); - cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); - - /* pitch unstable in present frame or from previous frame or normalized correlation too low */ - coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); - move16(); - coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); - move16(); - - test(); - test(); - test(); - IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) - { - /* Reset the threshold */ - *old_thres = 0; - move16(); - } - ELSE - { - /* The threshold increase is directly dependent on normalized correlation */ - /* *old_thres += (0.16f * cor_mean); */ - *old_thres = round_fx( L_mac( L_deposit_h( *old_thres ), 5243, cor_mean ) ); - } - - *old_thres = s_min( *old_thres, THRES3 ); - move16(); - - IF( GT_16( voicing[1], voicing[0] ) ) - { - *old_corr = voicing[1]; - move16(); - } - ELSE - { - *old_corr = cor_mean; - move16(); - } - - /*-----------------------------------------------------------------* - * Extrapolate the pitch value for the next frame by estimating - * the pitch evolution. This value is added to the old_pitch - * in the next frame and is then used when the normalized - * correlation is reinforced by the past estimate - *-----------------------------------------------------------------*/ - tmp_buf[0] = *old_pitch; - move16(); - FOR( i = 0; i < NHFR; i++ ) - { - tmp_buf[i + 1] = pitch[i]; - move16(); - } - - *delta_pit = 0; - move16(); - cnt = 0; - move16(); - - FOR( i = 0; i < NHFR; i++ ) - { - diff = sub( tmp_buf[i + 1], tmp_buf[i] ); - move16(); - coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); - - if ( coh_flag != 0 ) - { - *delta_pit = add( *delta_pit, diff ); - move16(); - } - cnt = add( cnt, coh_flag ); - } - if ( EQ_16( cnt, 2 ) ) - { - /* *delta_pit /= 2; */ - *delta_pit = shr( *delta_pit, 1 ); - move16(); - } - IF( EQ_16( cnt, 3 ) ) - { - k = *delta_pit; - move16(); - /* *delta_pit /= 3; */ - if ( k < 0 ) - { - *delta_pit = mult( *delta_pit, -32768 ); - move16(); - } - tmp16 = mult( *delta_pit, 10923 ); - if ( k < 0 ) - { - tmp16 = mult( tmp16, -32768 ); - } - *delta_pit = tmp16; - move16(); - } + /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ + qScaledX = 12; + move16(); - /*--------------------------------------------------------------* - * Update old pitch, upsample pitch, - *--------------------------------------------------------------*/ + pt_cor3 += sec_length1[j]; + move16(); + offset1 = add( offset1, sec_length1[j] ); - *old_pitch = pitch[1]; - move16(); + } /* FOR j < NSECT */ + } /* FOR i < NHFR */ - FOR( i = 0; i < NHFR; i++ ) - { - /* compensate decimation */ - pitch[i] = i_mult2( pitch[i], OPL_DECIM ); - move16(); - } + pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); return; } + void pitch_ol_ivas_fx( Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ @@ -1072,7 +1144,7 @@ void pitch_ol_ivas_fx( Word16 qwsp /* i : Q factor for wsp Q0 */ ) { - Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; + Word16 old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; Word16 tmp_mem[3]; Word16 scale1[2 * DELTA_COH - 1]; @@ -1082,20 +1154,18 @@ void pitch_ol_ivas_fx( Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4; Word16 *pt_cor0_exp, *pt_cor1_exp, *pt_cor2_exp, *pt_cor3_exp, *pt_cor4_exp; - Word16 thres1[6]; - Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; - Word16 ind_corX, ind1_corX; - - Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; + Word16 cnt, ind, ind1, offset, offset1, offset_la, offset_la1; + Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1; Word16 len_temp; - Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; + Word16 pitchX[NHFR][2 * NSECT]; Word16 enr0_exp[NSECT], enr0_1_exp[NSECT], enr1_exp; Word32 enr0[NSECT], enr0_1[NSECT], enr1; Word64 temp, temp1; Word32 Ltmp; - Word16 fac, tmp16, tmp16_2; - Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; + Word16 tmp16, tmp16_2; + Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT]; + const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; @@ -1163,6 +1233,7 @@ void pitch_ol_ivas_fx( * Extend the decimation of wsp to the end of the speech buffer * Update wsp memory *--------------------------------------------------------------*/ + Copy( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); @@ -1212,6 +1283,7 @@ void pitch_ol_ivas_fx( /*-----------------------------------------------------------------------------* * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames *-----------------------------------------------------------------------------*/ + old_tmp = add( *old_pitch, *delta_pit ); old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); old_tmp = s_max( old_tmp, pit_min ); @@ -1222,6 +1294,7 @@ void pitch_ol_ivas_fx( /*-----------------------------------------------------------------* * Loop for all three half-frames (current frame + look-ahead) *-----------------------------------------------------------------*/ + pt_cor0 = scaled_buf + DELTA_COH - 1; pt_cor0_exp = scaled_buf_exp + DELTA_COH - 1; @@ -1341,6 +1414,7 @@ void pitch_ol_ivas_fx( /*----------------------------------------------------------* * For each subsection, find the correlation *----------------------------------------------------------*/ + FOR( j = subsect0; j < NSUBSECT; j++ ) { len_temp = sublen[j]; @@ -1426,6 +1500,7 @@ void pitch_ol_ivas_fx( /*-----------------------------------------------------------------* * For each section in both sets, find fixed vector energy *-----------------------------------------------------------------*/ + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ { /* 1st set */ @@ -1482,532 +1557,284 @@ void pitch_ol_ivas_fx( move32(); move16(); } - } - - /* Set pointers: same as IF/ELSE block */ - pt2 = pt6 - pit_min; - k = 2; - move16(); - IF( sect0 != 0 ) - { - pt2 = pt6 - add( pit_max[1], 1 ); - k = sub( pit_max[2], pit_max[1] ); - move16(); - } - - /*-----------------------------------------------------------------* - * Find correlation for the non-overlapping pitch lag values - *-----------------------------------------------------------------*/ - - len_temp = sublen[0]; - move16(); - - FOR( ; k > 0; k-- ) - { - temp = 0; - move64(); - FOR( m = 0; m < len_temp; m++ ) - { - temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp - } - tmp16_2 = W_norm( temp ); - *pt_cor1 = extract_h( W_extract_h( W_shl( temp, tmp16_2 ) ) ); // 2*qwsp+tmp16_2 - *pt_cor1_exp = sub( new_q, tmp16_2 ); // 2*qwsp+tmp16_2-32-16 - move16(); - move16(); - - pt_cor1++; - pt_cor1_exp++; - pt2--; - } - - /*-----------------------------------------------------------------* - * For each subsection, find the correlation (overlapping pitch lag values) - *-----------------------------------------------------------------*/ - - FOR( j = subsect0; j < NSUBSECT; j++ ) - { - k = sub( pit_max[j + 1], pit_max[j] ); - - IF( LT_16( sublen[j], sublen1[j] ) ) - { - FOR( ; k > 0; k-- ) - { - temp = W_mult0_16_16( pt6[0], pt2[0] ); // 2*qwsp - FOR( m = 1; m < sublen[j]; m++ ) - { - temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp - } - cnt = W_norm( temp ); - *pt_cor1 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 - *pt_cor1_exp = sub( new_q, cnt ); - move16(); - move16(); - - FOR( ; m < sublen1[j]; m++ ) - { - temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp - } - cnt = W_norm( temp ); - *pt_cor3 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 - *pt_cor3_exp = sub( new_q, cnt ); - move16(); - move16(); - - pt_cor1++; - pt_cor1_exp++; - pt_cor3++; - pt_cor3_exp++; - pt2--; - } - } - ELSE - { - FOR( ; k > 0; k-- ) - { - temp = W_mult0_16_16( pt6[0], pt2[0] ); // 2*qwsp - FOR( m = 1; m < sublen1[j]; m++ ) - { - temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp - } - cnt = W_norm( temp ); - *pt_cor3 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 - *pt_cor3_exp = sub( new_q, cnt ); - move16(); - move16(); - - FOR( ; m < sublen[j]; m++ ) - { - temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp - } - cnt = W_norm( temp ); - *pt_cor1 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 - *pt_cor1_exp = sub( new_q, cnt ); - move16(); - move16(); - - pt_cor1++; - pt_cor1_exp++; - pt_cor3++; - pt_cor3_exp++; - pt2--; - } - } - } - } /* 3rd half-frame (look-ahead) */ - - /* Scale all values in each section to the same exponent for upcoming Find_max() */ - Copy( pt_cor0, cor_buf, len_x ); /* Save unscaled correlation vector */ - Copy( pt_cor0_exp, cor_buf_exp, len_x ); /* Save unscaled correlation vector */ - Copy( pt_cor0 + ( DELTA_COH - 1 ) + len_x, cor_buf + len_x, len_x1 ); - Copy( pt_cor0_exp + ( DELTA_COH - 1 ) + len_x, cor_buf_exp + len_x, len_x1 ); - - /*-----------------------------------------------------------------* - * Scale correlation function in the neighbourhood of - * the extrapolated pitch - *-----------------------------------------------------------------*/ - pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); - pt_cor1_exp = pt_cor2_exp - ( DELTA_COH - 1 ); - pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); - pt_cor3_exp = pt_cor4_exp - ( DELTA_COH - 1 ); - pt2 = scale1; - - FOR( k = 0; k < 2 * DELTA_COH - 1; k++ ) - { - *pt_cor1 = mult( *pt_cor1, *pt2 ); // *pt_cor1_exp+1 - *pt_cor1_exp = add( *pt_cor1_exp, 1 ); // *pt_cor1_exp+1 - move16(); - move16(); - - *pt_cor3 = mult( *pt_cor3, *pt2++ ); // *pt_cor3_exp+1 - *pt_cor3_exp = add( *pt_cor3_exp, 1 ); // *pt_cor1_exp+1 - move16(); - move16(); - - pt_cor1++; - pt_cor1_exp++; - pt_cor3++; - pt_cor3_exp++; - } - - /* Update for next half-frame & look-ahead */ - pt_cor2 = pt_cor0 - pit_min + old_tmp1; - pt_cor2_exp = pt_cor0_exp - pit_min + old_tmp1; - - pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x; - pt_cor4_exp = pt_cor0_exp - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x; - - /*-----------------------------------------------------------------* - * For each section, find maximum correlation and compute - * normalized correlation - *-----------------------------------------------------------------*/ - - pt_cor1 = pt_cor0; - pt_cor1_exp = pt_cor0_exp; - offset = 0; - move16(); - pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; - pt_cor3_exp = pt_cor0_exp + ( DELTA_COH - 1 ) + len_x; - offset1 = 0; - move16(); - - FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ - { - /* 1st set */ - offset_la = 0; - move16(); - if ( EQ_16( i, 2 ) ) - { - offset_la = sub( L_LOOK_12k8 / OPL_DECIM, len[j] ); - } - - /* 2nd set */ - offset_la1 = 0; - move16(); - if ( EQ_16( i, 2 ) ) - { - offset_la1 = sub( L_LOOK_12k8 / OPL_DECIM, len1[j] ); - } - - /* 1st set of candidates */ - ind = add( maximum_exp_fx( pt_cor1, pt_cor1_exp, sec_length[j] ), offset ); - pitchX[i][j] = add( ind, pit_min ); - move16(); - pt2 = pt1 - pitchX[i][j] + /*-*/ offset_la; /* selected moving vector */ - - enr1_exp = 0; - move16(); - - /* enr1 = dotp( pt2, pt2, len[j] ) + 0.01f; */ - temp = 0; - move64(); - FOR( m = 0; m < len[j]; m++ ) - { - temp = W_mac0_16_16( temp, pt2[m], pt2[m] ); // 2*qwsp - } - - temp = W_shl( temp, sub( Q24, shl( qwsp, 1 ) ) ); // Q24 - - temp = W_add( temp, 167772 ); /*0.01f in Q24*/ - - enr1_exp = W_norm( temp ); - enr1 = W_extract_h( W_shl( temp, enr1_exp ) ); // enr1_exp+24-32 - enr1_exp = sub( 39, enr1_exp ); // 31-(enr1_exp+24-32) - - enr1 = Mpy_32_32( enr0[j], enr1 ); - enr1_exp = add( enr0_exp[j], enr1_exp ); - - enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ - - Ltmp = Mpy_32_16_1( enr1, cor_buf[ind] ); - corX[i][j] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind] ) ) ); // Q15 - move16(); - - Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind] ); - scaledX[i][j] = round_fx( L_shl( Ltmp, sub( add( enr1_exp, pt_cor0_exp[ind] ), 3 ) ) ); // Q12 - move16(); - - pt_cor1 += sec_length[j]; - pt_cor1_exp += sec_length[j]; - offset = add( offset, sec_length[j] ); + } - /* 2nd set of candidates */ - ind1 = add( maximum_exp_fx( pt_cor3, pt_cor3_exp, sec_length1[j] ), offset1 ); - pitchX[i][j + NSECT] = add( ind1, pit_min1 ); - move16(); - pt4 = pt1 - pitchX[i][j + NSECT] + /*-*/ offset_la1; - move16(); /* selected moving vector */ - enr1_exp = 0; + /* Set pointers: same as IF/ELSE block */ + pt2 = pt6 - pit_min; + k = 2; move16(); - - /* enr1 = dotp(pt4, pt4, len1[j]) + 0.01f; */ - temp = 0; - move64(); - move64(); - FOR( m = 0; m < len1[j]; m++ ) + IF( sect0 != 0 ) { - temp = W_mac0_16_16( temp, pt4[m], pt4[m] ); // 2*qwsp + pt2 = pt6 - add( pit_max[1], 1 ); + k = sub( pit_max[2], pit_max[1] ); + move16(); } - temp = W_shl( temp, sub( Q24, shl( qwsp, 1 ) ) ); // Q24 - - temp = W_add( temp, 167772 ); /*0.01f in Q24*/ - - enr1_exp = W_norm( temp ); - enr1 = W_extract_h( W_shl( temp, enr1_exp ) ); // enr1_exp+24-32 - enr1_exp = sub( 39, enr1_exp ); // 31-(enr1_exp+24-32) - - enr1 = Mpy_32_32( enr0_1[j], enr1 ); - enr1_exp = add( enr0_1_exp[j], enr1_exp ); - - enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr1_exp*/ + /*-----------------------------------------------------------------* + * Find correlation for the non-overlapping pitch lag values + *-----------------------------------------------------------------*/ - Ltmp = Mpy_32_16_1( enr1, cor_buf[ind1 + len_x] ); - corX[i][j + NSECT] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind1 + len_x] ) ) ); // Q15 + len_temp = sublen[0]; move16(); - Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x] ); - scaledX[i][j + NSECT] = round_fx( L_shl( Ltmp, sub( add( enr1_exp, pt_cor0_exp[ind1 + ( DELTA_COH - 1 ) + len_x] ), 3 ) ) ); // Q12 - move16(); - /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ + FOR( ; k > 0; k-- ) + { + temp = 0; + move64(); + FOR( m = 0; m < len_temp; m++ ) + { + temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp + } + tmp16_2 = W_norm( temp ); + *pt_cor1 = extract_h( W_extract_h( W_shl( temp, tmp16_2 ) ) ); // 2*qwsp+tmp16_2 + *pt_cor1_exp = sub( new_q, tmp16_2 ); // 2*qwsp+tmp16_2-32-16 + move16(); + move16(); - pt_cor3 += sec_length1[j]; - pt_cor3_exp += sec_length1[j]; - offset1 = add( offset1, sec_length1[j] ); + pt_cor1++; + pt_cor1_exp++; + pt2--; + } - } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + /*-----------------------------------------------------------------* + * For each subsection, find the correlation (overlapping pitch lag values) + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * Favor a smaller delay if it happens that it has its multiple - * in the longer-delay sections (harmonics check) - *-----------------------------------------------------------------*/ + FOR( j = subsect0; j < NSUBSECT; j++ ) + { + k = sub( pit_max[j + 1], pit_max[j] ); - FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ - { - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - } + IF( LT_16( sublen[j], sublen1[j] ) ) + { + FOR( ; k > 0; k-- ) + { + temp = W_mult0_16_16( pt6[0], pt2[0] ); // 2*qwsp + FOR( m = 1; m < sublen[j]; m++ ) + { + temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp + } + cnt = W_norm( temp ); + *pt_cor1 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 + *pt_cor1_exp = sub( new_q, cnt ); + move16(); + move16(); - fac = THRES0; - move16(); /* the look-ahead */ - find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - } - fac = THRES0; - move16(); - find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ - find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ - test(); - IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) - { - find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ - } + FOR( ; m < sublen1[j]; m++ ) + { + temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp + } + cnt = W_norm( temp ); + *pt_cor3 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 + *pt_cor3_exp = sub( new_q, cnt ); + move16(); + move16(); - /*-----------------------------------------------------------------* - * Do 1st estimate for pitch values - * Adjust the normalized correlation using estimated noise level - * Compute the maximum scaling for the neighbour correlation - * reinforcement - *-----------------------------------------------------------------*/ - add_sect0 = add( NSECT, sect0 ); - sub_sect0 = sub( NSECT, sect0 ); - FOR( i = 0; i < NHFR; i++ ) - { - /* 1st set of pitch candidates */ - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_tmp[i] = ind; - move16(); - pitch_tmp[i] = pitchX[i][ind]; - move16(); - cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); - move16(); + pt_cor1++; + pt_cor1_exp++; + pt_cor3++; + pt_cor3_exp++; + pt2--; + } + } + ELSE + { + FOR( ; k > 0; k-- ) + { + temp = W_mult0_16_16( pt6[0], pt2[0] ); // 2*qwsp + FOR( m = 1; m < sublen1[j]; m++ ) + { + temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp + } + cnt = W_norm( temp ); + *pt_cor3 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 + *pt_cor3_exp = sub( new_q, cnt ); + move16(); + move16(); - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i] = mult( THRES1, cor_tmp[i] ); - move16(); + FOR( ; m < sublen[j]; m++ ) + { + temp = W_mac0_16_16( temp, pt6[-m], pt2[-m] ); // 2*qwsp + } + cnt = W_norm( temp ); + *pt_cor1 = extract_h( W_extract_h( W_shl( temp, cnt ) ) ); // 2*qwsp+cnt-32-16 + *pt_cor1_exp = sub( new_q, cnt ); + move16(); + move16(); - /* 2nd set of pitch candidates */ - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind_tmp[i + NHFR] = ind1; - move16(); - pitch_tmp[i + NHFR] = pitchX[i][ind1]; - move16(); - cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); - move16(); + pt_cor1++; + pt_cor1_exp++; + pt_cor3++; + pt_cor3_exp++; + pt2--; + } + } + } + } /* 3rd half-frame (look-ahead) */ - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); - move16(); - } - /*-----------------------------------------------------------------* - * Take into account previous and next pitch values of the present - * frame and look-ahead. Choose the pitch lags and normalize - * correlations for each half-frame & look-ahead - *-----------------------------------------------------------------*/ + /* Scale all values in each section to the same exponent for upcoming Find_max() */ + Copy( pt_cor0, cor_buf, len_x ); /* Save unscaled correlation vector */ + Copy( pt_cor0_exp, cor_buf_exp, len_x ); /* Save unscaled correlation vector */ + Copy( pt_cor0 + ( DELTA_COH - 1 ) + len_x, cor_buf + len_x, len_x1 ); + Copy( pt_cor0_exp + ( DELTA_COH - 1 ) + len_x, cor_buf_exp + len_x, len_x1 ); - pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); - FOR( i = 0; i < NHFR; i++ ) - { - ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); - ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + /*-----------------------------------------------------------------* + * Scale correlation function in the neighbourhood of + * the extrapolated pitch + *-----------------------------------------------------------------*/ - ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); - ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); + pt_cor1_exp = pt_cor2_exp - ( DELTA_COH - 1 ); + pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); + pt_cor3_exp = pt_cor4_exp - ( DELTA_COH - 1 ); + pt2 = scale1; - if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) - { - ind = ind1; - move16(); - } - test(); - if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) - { - ind_corX = ind1_corX; - move16(); - } - test(); - test(); - test(); - IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && - ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) + FOR( k = 0; k < 2 * DELTA_COH - 1; k++ ) { - pitch[i] = pitchX[i][ind_corX]; + *pt_cor1 = mult( *pt_cor1, *pt2 ); // *pt_cor1_exp+1 + *pt_cor1_exp = add( *pt_cor1_exp, 1 ); // *pt_cor1_exp+1 move16(); - voicing[i] = corX[i][ind_corX]; move16(); - } - ELSE - { - pitch[i] = pitchX[i][ind]; + + *pt_cor3 = mult( *pt_cor3, *pt2++ ); // *pt_cor3_exp+1 + *pt_cor3_exp = add( *pt_cor3_exp, 1 ); // *pt_cor1_exp+1 move16(); - voicing[i] = corX[i][ind]; move16(); + + pt_cor1++; + pt_cor1_exp++; + pt_cor3++; + pt_cor3_exp++; } - } - /*-----------------------------------------------------------------* - * Increase the threshold for correlation reinforcement with - * the past if correlation high and pitch stable - *-----------------------------------------------------------------*/ + /* Update for next half-frame & look-ahead */ + pt_cor2 = pt_cor0 - pit_min + old_tmp1; + pt_cor2_exp = pt_cor0_exp - pit_min + old_tmp1; - /* all Q15 here */ - /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult( voicing[0], 16384 /*.5 Q15*/ ); - Ltmp = L_mac( Ltmp, voicing[1], 16384 /*.5 Q15*/ ); - cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); + pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x; + pt_cor4_exp = pt_cor0_exp - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x; - /* pitch unstable in present frame or from previous frame or normalized correlation too low */ - coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); - move16(); - coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); - move16(); + /*-----------------------------------------------------------------* + * For each section, find maximum correlation and compute + * normalized correlation + *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) - { - /* Reset the threshold */ - *old_thres = 0; + pt_cor1 = pt_cor0; + pt_cor1_exp = pt_cor0_exp; + offset = 0; move16(); - } - ELSE - { - /* The threshold increase is directly dependent on normalized correlation */ - /* *old_thres += (0.16f * cor_mean); */ - *old_thres = round_fx( L_mac0( L_deposit_h( *old_thres ), 5243 /* 0.16f in Q15 */, cor_mean ) ); // Q14 + pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x; + pt_cor3_exp = pt_cor0_exp + ( DELTA_COH - 1 ) + len_x; + offset1 = 0; move16(); - } - *old_thres = s_min( *old_thres, 11469 /* 0.7f in Q14 */ ); // Q14 - move16(); + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + { + /* 1st set */ + offset_la = 0; + move16(); + if ( EQ_16( i, 2 ) ) + { + offset_la = sub( L_LOOK_12k8 / OPL_DECIM, len[j] ); + } - IF( GT_16( voicing[1], voicing[0] ) ) - { - *old_corr = voicing[1]; - move16(); - } - ELSE - { - *old_corr = cor_mean; - move16(); - } + /* 2nd set */ + offset_la1 = 0; + move16(); + if ( EQ_16( i, 2 ) ) + { + offset_la1 = sub( L_LOOK_12k8 / OPL_DECIM, len1[j] ); + } - /*-----------------------------------------------------------------* - * Extrapolate the pitch value for the next frame by estimating - * the pitch evolution. This value is added to the old_pitch - * in the next frame and is then used when the normalized - * correlation is reinforced by the past estimate - *-----------------------------------------------------------------*/ - tmp_buf[0] = *old_pitch; - move16(); - FOR( i = 0; i < NHFR; i++ ) - { - tmp_buf[i + 1] = pitch[i]; - move16(); - } + /* 1st set of candidates */ + ind = add( maximum_exp_fx( pt_cor1, pt_cor1_exp, sec_length[j] ), offset ); + pitchX[i][j] = add( ind, pit_min ); + move16(); + pt2 = pt1 - pitchX[i][j] + /*-*/ offset_la; /* selected moving vector */ - *delta_pit = 0; - move16(); - cnt = 0; - move16(); + enr1_exp = 0; + move16(); - FOR( i = 0; i < NHFR; i++ ) - { - diff = sub( tmp_buf[i + 1], tmp_buf[i] ); - move16(); - coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); + /* enr1 = dotp( pt2, pt2, len[j] ) + 0.01f; */ + temp = 0; + move64(); + FOR( m = 0; m < len[j]; m++ ) + { + temp = W_mac0_16_16( temp, pt2[m], pt2[m] ); // 2*qwsp + } - if ( coh_flag != 0 ) - { - *delta_pit = add( *delta_pit, diff ); + temp = W_shl( temp, sub( Q24, shl( qwsp, 1 ) ) ); // Q24 + + temp = W_add( temp, 167772 ); /*0.01f in Q24*/ + + enr1_exp = W_norm( temp ); + enr1 = W_extract_h( W_shl( temp, enr1_exp ) ); // enr1_exp+24-32 + enr1_exp = sub( 39, enr1_exp ); // 31-(enr1_exp+24-32) + + enr1 = Mpy_32_32( enr0[j], enr1 ); + enr1_exp = add( enr0_exp[j], enr1_exp ); + + enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ + + Ltmp = Mpy_32_16_1( enr1, cor_buf[ind] ); + corX[i][j] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind] ) ) ); // Q15 move16(); - } - cnt = add( cnt, coh_flag ); - } - if ( EQ_16( cnt, 2 ) ) - { - /* *delta_pit /= 2; */ - *delta_pit = shr( *delta_pit, 1 ); - move16(); - } - IF( EQ_16( cnt, 3 ) ) - { - k = *delta_pit; - move16(); - /* *delta_pit /= 3; */ - if ( k < 0 ) - { - *delta_pit = mult( *delta_pit, -32768 /*-1 Q15*/ ); + + Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind] ); + scaledX[i][j] = round_fx( L_shl( Ltmp, sub( add( enr1_exp, pt_cor0_exp[ind] ), 3 ) ) ); // Q12 move16(); - } - tmp16 = mult( *delta_pit, 10923 /*1/3 Q15*/ ); - if ( k < 0 ) - { - tmp16 = mult( tmp16, -32768 /*-1 Q15*/ ); - } - *delta_pit = tmp16; - move16(); - } - /*--------------------------------------------------------------* - * Update old pitch, upsample pitch, - *--------------------------------------------------------------*/ + pt_cor1 += sec_length[j]; + pt_cor1_exp += sec_length[j]; + offset = add( offset, sec_length[j] ); - *old_pitch = pitch[1]; - move16(); + /* 2nd set of candidates */ + ind1 = add( maximum_exp_fx( pt_cor3, pt_cor3_exp, sec_length1[j] ), offset1 ); + pitchX[i][j + NSECT] = add( ind1, pit_min1 ); + move16(); + pt4 = pt1 - pitchX[i][j + NSECT] + /*-*/ offset_la1; + move16(); /* selected moving vector */ + enr1_exp = 0; + move16(); - FOR( i = 0; i < NHFR; i++ ) - { - /* compensate decimation */ - pitch[i] = i_mult2( pitch[i], OPL_DECIM ); - move16(); - } + /* enr1 = dotp(pt4, pt4, len1[j]) + 0.01f; */ + temp = 0; + move64(); + move64(); + FOR( m = 0; m < len1[j]; m++ ) + { + temp = W_mac0_16_16( temp, pt4[m], pt4[m] ); // 2*qwsp + } + + temp = W_shl( temp, sub( Q24, shl( qwsp, 1 ) ) ); // Q24 + + temp = W_add( temp, 167772 ); /*0.01f in Q24*/ + + enr1_exp = W_norm( temp ); + enr1 = W_extract_h( W_shl( temp, enr1_exp ) ); // enr1_exp+24-32 + enr1_exp = sub( 39, enr1_exp ); // 31-(enr1_exp+24-32) + + enr1 = Mpy_32_32( enr0_1[j], enr1 ); + enr1_exp = add( enr0_1_exp[j], enr1_exp ); + + enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr1_exp*/ + + Ltmp = Mpy_32_16_1( enr1, cor_buf[ind1 + len_x] ); + corX[i][j + NSECT] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind1 + len_x] ) ) ); // Q15 + move16(); + + Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x] ); + scaledX[i][j + NSECT] = round_fx( L_shl( Ltmp, sub( add( enr1_exp, pt_cor0_exp[ind1 + ( DELTA_COH - 1 ) + len_x] ), 3 ) ) ); // Q12 + move16(); + /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ + + pt_cor3 += sec_length1[j]; + pt_cor3_exp += sec_length1[j]; + offset1 = add( offset1, sec_length1[j] ); + + } /* FOR j < NSECT */ + } /* FOR i < NHFR */ + pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ return; } @@ -2018,6 +1845,7 @@ void pitch_ol_ivas_fx( * Verifies whether max pitch delays in higher sections have multiples * in lower sections *-----------------------------------------------------------------*/ + static void find_mult_fx( Word16 *fac, /* i/o: correlation scaling factor Q12 */ Word16 pitch0, /* i : pitch of max correlation in the c section */ @@ -2054,6 +1882,8 @@ static void find_mult_fx( pit_min = add( pit_min, pitch0 ); /* next multiple */ delta = add( delta, step ); /* the incertitude to the allowed range */ } + + return; } /*---------------------------------------------------------------------------* @@ -2062,6 +1892,7 @@ static void find_mult_fx( * Verifies if the maximum correlation pitch lag is coherent with neighbour * values *---------------------------------------------------------------------------*/ + static void pitch_neighbour_fx( Word16 sect0, /* i : indicates whether section 0 (below PIT_MIN) is used */ Word16 pitch_tmp[], /* i : estimated pitch values for each half-frame & look-ahead */ @@ -2175,13 +2006,17 @@ static void pitch_neighbour_fx( } } } + + return; } + /*-----------------------------------------------------------------* * pitch_coherence_fx * * Verify if pitch evolution is smooth *-----------------------------------------------------------------*/ + static Word16 pitch_coherence_fx( Word16 pitch0, /* i : first pitch to compare */ Word16 pitch1, /* i : 2nd pitch to compare */ @@ -2208,11 +2043,13 @@ static Word16 pitch_coherence_fx( return pc; } + /*-----------------------------------------------------------------* * LP_Decim2_Copy: * * Decimate a vector by 2 with 2nd order fir filter. *-----------------------------------------------------------------*/ + static void LP_Decim2_Copy( const Word16 x[], /* i: signal to process */ Word16 y[], /* o: signal to process */ @@ -2262,20 +2099,26 @@ static void LP_Decim2_Copy( y[j++] = round_fx( L_tmp ); move16(); } + + return; } + + /*---------------------------------------------------------------------* * Dot_product12_OL * * two different length dot products of x and y *---------------------------------------------------------------------*/ -static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ + +/* o : Q31: normalized result (1 < val <= -1) */ +static Word32 Dot_product12_OL( + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; @@ -2327,19 +2170,22 @@ static Word32 Dot_product12_OL( /* o : Q31: normalized result return L_sum; } + /*---------------------------------------------------------------------* * Dot_product12_OL_back() * * two different length dot products of x and y, computed backward *---------------------------------------------------------------------*/ -static Word32 Dot_product12_OL_back( /* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ + +/* o : Q31: normalized result (1 < val <= -1) */ +static Word32 Dot_product12_OL_back( + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; @@ -2391,6 +2237,13 @@ static Word32 Dot_product12_OL_back( /* o : Q31: normalized r return L_sum; } + +/*---------------------------------------------------------------------* + * pitchDoubling_det_fx() + * + * + *---------------------------------------------------------------------*/ + void pitchDoubling_det_fx( Word16 *wspeech, Word16 *pitch_ol, @@ -2402,7 +2255,6 @@ void pitchDoubling_det_fx( Word16 new_Top[2]; Word16 m, T; - /*save initial values*/ new_Top[0] = pitch_ol[0]; @@ -2412,7 +2264,6 @@ void pitchDoubling_det_fx( FOR( m = 2; m < 5; m++ ) { - /* T= pitch_ol[0]/m; */ T = mult( pitch_ol[0], One_div_fx[m - 1] ); @@ -2465,4 +2316,5 @@ void pitchDoubling_det_fx( pitch_ol[1] = new_Top[1]; move16(); -} /*end of pitch doubling detection*/ + return; +} diff --git a/lib_enc/plc_enc_ext_fx.c b/lib_enc/plc_enc_ext_fx.c index 97e3fd4bc44ca91ab63acb69b5f914d01f747e93..6e9571442c42a0ad30931c3511d36f1c17164ac0 100644 --- a/lib_enc/plc_enc_ext_fx.c +++ b/lib_enc/plc_enc_ext_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index 5e977c8f7b96f8b151deae0e406657ba2c6fbc11..15b013a4b9c309c5085e1a5e4002f81f46b35c2c 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -36,40 +36,40 @@ static void erb_diff_fx( const Word16 *prev_erb, Word16 pl, const Word16 *curr_e /* INPUT ARGUMENTS : */ /* _ (Word16 []) curr_lpc_fx: LPC coefficients, Q12 */ /* _ (struct DTFS_STRUCTURE_FX) CURRCW_NQ_FX : prototype in Cartesian domain */ -/* (Word16) lag_fx: length of prototype */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ +/* (Word16) lag_fx: length of prototype */ +/* (Word16 []) a/b: harmonics, normalized */ +/* (Word16) Q: norm factor of a */ /* _ (struct DTFS_STRUCTURE_FX) PREV_CW_E_FX : past dtfs in Cartesian domain */ -/* (Word16) lag: length of prototype */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (Word16) prevCW_lag_fx: Previous lag, Q0 */ -/* _ (Word16 *) exc : Global input (Q0) */ +/* (Word16) lag: length of prototype */ +/* (Word16 []) a/b: harmonics, normalized */ +/* (Word16) Q: norm factor of a */ +/* _ (Word16) prevCW_lag_fx: Previous lag, Q0 */ +/* _ (Word16 *) exc : Global input (Q0) */ /* _ (Word16 []) sinTab, Q15 : sin(2pi/4L*n), n=0,1,...,4L-1 */ /* _ (Word16 []) cosTab, Q15 : cos(2pi/4L*n), n=0,1,...,4L-1 */ /*---------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) pidx: Power index */ -/* _ (Word16[]) aidx: Amplitude indices, 2 words */ -/* _ (struct DTFS_fx *) CURRCW_Q_FX : quantized prototype in Cartesian domain */ -/* (Word16) lag_fx: length of prototype in time domain */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (struct DTFS_fx *) TARGETCW_FX : Target prototype in Cartesian domain */ -/* (Word16) lag_fx: length of prototype in time domain */ -/* (Word16 []) a/b: harmonics, normalized */ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) pidx: Power index */ +/* _ (Word16[]) aidx: Amplitude indices, 2 words */ +/* _ (struct DTFS_fx *) CURRCW_Q_FX : quantized prototype in Cartesian domain */ +/* (Word16) lag_fx: length of prototype in time domain */ +/* (Word16 []) a/b: harmonics, normalized */ +/* (Word16) Q: norm factor of a */ +/* _ (struct DTFS_fx *) TARGETCW_FX : Target prototype in Cartesian domain */ +/* (Word16) lag_fx: length of prototype in time domain */ +/* (Word16 []) a/b: harmonics, normalized */ /* (Word16) Q: norm factor of a */ /*---------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ +/* INPUT/OUTPUT ARGUMENTS : */ /* _ (Word16[]) lasterbE_fx: ERB history for differential */ /* quantization, Q13 */ -/* _ (Word16) lastLgainE_fx: low band power history, log domain, */ +/* _ (Word16) lastLgainE_fx: low band power history, log domain, */ /* Q11 */ -/* _ (Word16) lastHgainE_fx: high band power history, log domain, */ +/* _ (Word16) lastHgainE_fx: high band power history, log domain, */ /* Q11 */ /*---------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ -/* _ (Word16) returnFlag: flag indicating success/failure */ +/* _ (Word16) returnFlag: flag indicating success/failure */ /* (TRUE/FALSE) */ /*---------------------------------------------------------------------------------------*/ /* CALLED FROM : TX */ @@ -77,15 +77,15 @@ static void erb_diff_fx( const Word16 *prev_erb, Word16 pl, const Word16 *curr_e ivas_error ppp_quarter_encoder_fx( Word16 *returnFlag, /* o : return value */ - DTFS_STRUCTURE *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ - Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE vCURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16 *curr_lpc_fx, /* i : LPCS */ - Word16 *lastLgainE_fx, /* i/o: last low band gain */ - Word16 *lastHgainE_fx, /* i/o: last high band gain */ - Word16 *lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE PREV_CW_E_FX, /* i : past DTFS */ + DTFS_STRUCTURE *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ + Word16 prevCW_lag, /* i : previous lag */ + DTFS_STRUCTURE vCURRCW_NQ_FX, /* i : Unquantized DTFS */ + const Word16 *curr_lpc_fx, /* i : LPCS */ + Word16 *lastLgainE_fx, /* i/o: last low band gain */ + Word16 *lastHgainE_fx, /* i/o: last high band gain */ + Word16 *lasterbE_fx, /* i/o: last ERB vector */ + DTFS_STRUCTURE PREV_CW_E_FX, /* i : past DTFS */ Word16 *S_fx, /* i : sin table, Q15 */ Word16 *C_fx, /* i : cos table, Q15 */ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 29a0aa229357128eb352843d193f2dfc1e8d0c8e..f29d734ffd431a5f9a06cd9fe671a236ac332542 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -32,16 +32,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 */ Word16 *vad_hover_flag, - Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - + Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb imag buffer */ CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale */ @@ -53,7 +50,6 @@ void pre_proc_fx( { Word16 delay; const Word16 *signal_in; - Word16 i; Word16 *inp_12k8, *new_inp_12k8, *inp_16k, *new_inp_16k; /* pointers to current frame and new data */ Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ @@ -69,13 +65,12 @@ void pre_proc_fx( Word16 cor_map_sum, sp_div; /* speech/music clasif. parameters */ Word32 PS[128]; Word16 L_look; /* length of look-ahead */ + Word16 epsP_h[M + 1], epsP_l[M + 1]; Word16 Q_sp_div, Q_esp; Word16 localVAD_HE_SAD; /* HE SAD parameters */ Word16 snr_sum_he; /* HE SAD parameters */ - Word16 vad_flag_cldfb; - Word16 vad_flag_dtx; Word16 old_cor; Word32 hp_E[2]; /* Energy in HF */ @@ -126,10 +121,10 @@ void pre_proc_fx( LPD_state_HANDLE hLPDmem = st->hLPDmem; FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD; - /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ + signal_in = st->input_fx; vad_flag_dtx = 0; @@ -209,16 +204,22 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ + +#ifndef FIX_2410_HARM_MODIF_FS 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 ) ) ); +#else + 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 ) ), NULL, NULL ); +#endif + 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 +283,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 +326,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 +352,7 @@ void pre_proc_fx( } configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, L_tmp ); } + test(); IF( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) { @@ -447,7 +451,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 +484,6 @@ void pre_proc_fx( move16(); } - /*------------------------------------------------------------------* * Update estimated noise energy and voicing cut-off frequency *-----------------------------------------------------------------*/ @@ -493,6 +496,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 +507,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 +567,7 @@ void pre_proc_fx( hSC_VBR->Local_VAD = st->localVAD; move16(); } + /*----------------------------------------------------------------* * Speech/music classification * AC frame selection @@ -769,6 +775,7 @@ void pre_proc_fx( /*---------------------------------------------------------------------* * Decision matrix (selection of technologies) *---------------------------------------------------------------------*/ + IF( EQ_16( st->codec_mode, MODE1 ) ) { @@ -1012,7 +1019,11 @@ void pre_proc_fx( } ELSE IF( EQ_32( st->input_Fs, 32000 ) || EQ_32( st->input_Fs, 48000 ) ) { +#ifndef FIX_2410_HARM_MODIF_FS modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0 ); +#else + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0, NULL, NULL ); +#endif } ELSE /* keep memories up-to-date in case of bitrate switching */ { @@ -1329,5 +1340,10 @@ void pre_proc_fx( } } + epsP[0] = L_Comp( epsP_h[2], epsP_l[2] ); + move32(); + epsP[1] = L_Comp( epsP_h[M], epsP_l[M] ); + move32(); + return; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 448a93b9ff07d372b829a09e6da8983bc9c7c4d7..d6b13aa6e409259de1d94a96f0661d0b3274297e 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,27 +41,6 @@ #include "ivas_stat_enc.h" -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*/ - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/ - Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ - const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors Qx*/ - const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors Qx*/ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame Q15*/ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame 15*/ - Word16 vad_hover_flag_fx, /* 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*/ - 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_old_syn*/ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits_fx, /* o : number of unused bits Q0*/ - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const Word16 Q_new, - const Word16 shift ); - 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 +57,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 +97,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 +119,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 +138,11 @@ Word16 ivas_dtx_hangover_addition_fx( Word16 *rem_dtx_ho ); void fb_tbe_enc_fx( - 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 ); - -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 ); + 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 +190,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 +206,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 +264,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 */ ); @@ -540,16 +482,6 @@ Word16 signal_clas_fx( Word16 *uc_clas /* o : temporary classification used in music/speech class*/ ); -/* o : classification for current frames */ -Word16 signal_clas_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look, /* i : look-ahead */ - Word16 *uc_clas /* o : temporary classification used in music/speech class*/ -); - void speech_music_classif_fx( Encoder_State *st, /* i/o: state structure */ const Word16 *new_inp, /* i : new input signal */ @@ -571,10 +503,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,23 +518,8 @@ 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( +#ifndef HARM_FD_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *old_input_12k8_fx, /* i : i signal @12.8kHz for SWB BWE */ Word16 *old_input_16k_fx, /* i : i signal @16kHz for SWB BWE */ @@ -613,6 +531,7 @@ void swb_bwe_enc_fx( Word16 Q_slb_speech ); void swb_bwe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 last_element_mode, /* i : last element mode */ Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ @@ -620,23 +539,31 @@ 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 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ +#ifdef HARM_FD_BWE Word16 Q_shb_speech, Word16 Q_slb_speech ); +#else + const Word16 Q_slb_speech ); +#endif 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( +#ifdef HARMONIZE_TBE2 + 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*/ + const CLDFB_SCALE_FACTOR *cldfbScale, /* i : scale data of real and imag CLDFB buffers */ + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +#else Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *input_fx, /* i : original i signal */ Word16 *new_swb_speech_fx, /* o : original i signal at 32kHz */ @@ -645,6 +572,7 @@ void swb_pre_proc_fx( Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag buffer */ const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers*/ +#endif ); void InitSWBencBufferStates_fx( @@ -669,7 +597,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 */ @@ -720,23 +648,27 @@ void vad_param_updt_fx( ); void wb_bwe_enc_fx( +#ifndef HARM_FD_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_wb_speech_fx, /* i : original i signal at 16kHz */ Word16 coder_type /* i : coding type */ ); void wb_bwe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_wb_speech_fx /* i : original i signal at 16kHz */ ); void wb_pre_proc_fx( +#ifndef HARMONIZE_TBE2 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_inp_resamp16k, /* i : original i signal */ Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ ); void wb_pre_proc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 last_element_mode, /* i : last element mode */ const Word16 *new_inp_resamp16k, /* i : original input signal in Q-1 */ @@ -744,17 +676,6 @@ void wb_pre_proc_ivas_fx( ); void wb_tbe_enc_fx( - 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 */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : i HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing[] /* i : OL maximum normalized correlation */ -); - -void wb_tbe_enc_ivas_fx( 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 +733,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,57 +779,27 @@ 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 */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise, /* o : noise energy */ - Word16 Q_exc ); - -void gsc_enc_ivas_fx( - Encoder_State *st, /* i/o: State structure */ - Word16 res_dct_in_fx[], /* i : dct of residual signal */ - Word16 exc_dct_in_fx[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 *lsf_new_fx, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf_fx, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + Word16 *tmp_noise, /* o : noise energy */ Word16 *Q_exc ); void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -); - void lsf_end_enc_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 */ - 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 */ ); @@ -1039,23 +929,6 @@ void set_bw_stereo_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures */ ); -/* o : classification of wb signal */ -Word16 WB_BWE_encoding_fx( - const Word16 coder_type, /* i : coder type */ - const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ - Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ - Encoder_State *st_fx, /* i/o: Encoder structure */ - Word16 Q_synth, - Word16 Q_synth_lf ); - -/* o : classification of wb signal */ -Word16 WB_BWE_encoding_ivas_fx( - Encoder_State *st_fx, /* i/o: Encoder structure */ - const Word32 *yos_fx, /* i : MDCT coefficients of weighted original */ - Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ - Word16 Q_synth, - Word16 Q_synth_lf ); - void calculate_hangover_attenuation_gain_fx( Encoder_State *st, /* i : encoder state structure */ Word16 *att, /* o : attenuation factor */ @@ -1078,7 +951,7 @@ void InitTransientDetection_fx( void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, + TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ); /** Runs transient detection. @@ -1108,7 +981,7 @@ void RunTransientDetection_ivas_fx( * @return average temporal flatness measure with exponent AVG_FLAT_E */ Word16 GetTCXAvgTemporalFlatnessMeasure_fx( - TRAN_DET_HANDLE hTranDetn, + TRAN_DET_HANDLE hTranDet, const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks ); @@ -1165,12 +1038,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*/ @@ -1188,18 +1055,11 @@ 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( + const Word16 element_mode, /* i : element mode */ SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); -void speech_music_clas_init_ivas_fx( - SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ -); void pitchDoubling_det_fx( Word16 *wspeech, @@ -1524,21 +1384,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 */ @@ -1618,14 +1463,20 @@ void CalculateTnsFilt_fx( const Word16 pSpectrum_e, STnsData *pTnsData /* o : TNS data struct */ ); +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, Word32 const pSpectrum[], STnsData *pTnsData, Word16 *predictionGain ); +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT +#ifdef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT +Word16 DetectTnsFilt_fx( +#else Word16 DetectTnsFilt_ivas_fx( +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */ Word32 const pSpectrum[], /* i : MDCT spectrum Q=Qx */ STnsData *pTnsData, /* o : TNS data struct */ @@ -1635,6 +1486,7 @@ Word16 DetectTnsFilt_ivas_fx( Word16 *predictionGain /* o : TNS prediction gain Q=7 */ ); + Word16 EncodeTnsData_fx( STnsConfig const *pTnsConfig, STnsData const *pTnsData, @@ -1752,23 +1604,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) */ @@ -1809,25 +1647,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( @@ -1857,22 +1684,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*/ @@ -1893,30 +1704,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 */ -); - -/* Delete the instance of type FD_CNG */ -void deleteFdCngEnc_fx( - HANDLE_FD_CNG_ENC *hFdCngEnc ); - 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*/ @@ -1934,19 +1721,21 @@ void coder_acelp_rf_fx( Word16 Q_new, Word16 shift ); -/* Create an instance of type FD_CNG */ -void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ); +ivas_error createFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ); + +void deleteFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ); void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, - Word32 input_Fs, /* Q0 */ - Word16 scale ); + const Word32 input_Fs, /* Q0 */ + const Word16 scale ); -/* Configure CLDFB-CNG */ void configureFdCngEnc_fx( - HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, /* i: bandwidth Q0*/ - Word32 bitrate /* Q0 */ + HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ + const Word16 bandwidth, /* i: bandwidth Q0*/ + const Word32 bitrate /* Q0 */ ); /* Perform noise estimation */ @@ -2003,26 +1792,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*/ @@ -2043,50 +1816,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*/ @@ -2100,31 +1840,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 */ @@ -2134,14 +1856,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 */ @@ -2554,8 +2277,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, @@ -2568,14 +2291,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 */ @@ -2761,11 +2484,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*/, @@ -2872,14 +2590,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( @@ -2890,36 +2602,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, @@ -2962,14 +2651,11 @@ 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 */ ); +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT void TNSAnalysis_fx( TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 L_frame, /* i : frame length */ @@ -2981,7 +2667,13 @@ void TNSAnalysis_fx( Word8 *pfUseTns, /* o : Flag indicating if TNS is used */ Word16 *predictionGain ); +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT void TNSAnalysis_ivas_fx( +#else +void TNSAnalysis_fx( +#endif // !FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */ Word16 L_frame, /* i : frame length */ Word16 L_spec, /* i : length of the spectrum */ @@ -3509,31 +3201,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 */ @@ -3556,7 +3223,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( @@ -3604,7 +3271,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( @@ -3619,8 +3286,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*/ @@ -3630,8 +3297,9 @@ void re8_cod_fx( ); void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word16 last_core, /* i : last core */ + Word16 bandwidth /* i : bandwidth mode */ ); void acelp_core_switch_enc_fx( @@ -3639,16 +3307,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 */ @@ -3709,31 +3369,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*/ @@ -3843,32 +3478,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*/ @@ -3884,21 +3493,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*/ @@ -3919,26 +3513,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 */ @@ -3953,8 +3527,6 @@ 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 */ @@ -4005,28 +3577,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 ); - -void enc_pit_exc_ivas_fx( - Encoder_State *st_fx, /* i/o: State structure */ - const Word16 *speech, /* i : Input speech Q_new-1*/ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/ - const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *synth, /* i/o: core synthesis Q_new*/ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *gpit, /* o : pitch mean gpit Q15*/ - 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 ); /* o : bin where pitch contribution is significant */ Word16 Pit_exc_contribution_len_fx( @@ -4038,16 +3590,6 @@ Word16 Pit_exc_contribution_len_fx( Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ); -/* 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*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ - Word16 Qnew ); - Word16 pvq_core_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ @@ -4096,14 +3638,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 */ @@ -4279,26 +3813,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 */ @@ -4360,17 +3874,16 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ -); - -void InitSWBencBuffer_ivas_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + const Word16 element_mode, /* i : element mode */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); void ResetSHBbuffer_Enc_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); +Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, Word16 L_subfr /*Q0*/, Word16 bits /*Q0*/ ); + Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, @@ -4490,35 +4003,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 */ @@ -4607,12 +4106,13 @@ void rc_enc_finish_fx( PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ); +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_enc_finish_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ); - +#endif void rc_encode_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -4621,6 +4121,7 @@ void rc_encode_fx( UWord32 tot /* i : Total cumulative frequency Q0*/ ); +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -4635,7 +4136,7 @@ void rc_enc_uniform_ivas_fx( UWord32 value, /* i : Value to encode Q0*/ UWord32 tot /* i : Maximum value Q0*/ ); - +#endif void rc_enc_uniform_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -4650,13 +4151,14 @@ void rc_enc_bits_fx( Word16 bits /* i : Number of bits used Q0*/ ); +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_enc_bits_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ UWord32 value, /* i : Value to encode Q0*/ Word16 bits /* i : Number of bits used Q0*/ ); - +#endif void re8_compute_base_index_fx( const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ const Word16 ka, /* i : Identifier of the absolute leader related to x */ @@ -4728,26 +4230,17 @@ void index_lvq_ivas_fx( Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ const Word16 prediction_flag ); -ivas_error init_encoder_fx( - Encoder_State *st_fx, /* i/o: Encoder static variables structure */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID /* i : interval for SID update */ -); - void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ); -void destroy_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ -); - void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : i signal Q0*/ - const Word16 n_samples /* i : number of i samples Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_sp[], /* i : i signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ + const Word16 n_samples /* i : number of i samples Q0*/ ); void writeLPCparam_fx( diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 854c269386eadd3a39565e72993e5437d938e3aa..67e9adb29d055c27174475b4156390b22d0dd0e8 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -351,7 +351,11 @@ void pvq_encode_frame_ivas_fx( } } +#ifdef FIX_2425_REMOVE_RC_DUPLICATES + rc_enc_finish_fx( hBstr, hPVQ ); +#else rc_enc_finish_ivas_fx( hBstr, hPVQ ); +#endif return; } @@ -977,7 +981,11 @@ static void densityIndexSymbolEncode_ivas_fx( } } +#ifdef FIX_2425_REMOVE_RC_DUPLICATES + rc_encode_fx( hBstr, hPVQ, cum_freq, sym_freq, tot ); +#else rc_encode_ivas_fx( hBstr, hPVQ, cum_freq, sym_freq, tot ); +#endif } return; @@ -1146,7 +1154,11 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of tmp = 1; move16(); } +#ifdef FIX_2425_REMOVE_RC_DUPLICATES + rc_enc_bits_fx( hBstr, hPVQ, tmp, 1 ); +#else rc_enc_bits_ivas_fx( hBstr, hPVQ, tmp, 1 ); +#endif Np = add( Np, tmp ); } } diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index 85704ccf3ba1417296f037dc7caccd8d63ddda6a..d96f4943970cf185409c09d51772edfa7b8d79dd 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -365,10 +365,19 @@ void pvq_encode_ivas_fx( entry = mpvq_encode_vec_fx( y, dim, pulses ); /* send the short codeword(s) to the range encoder */ +#ifdef FIX_2425_REMOVE_RC_DUPLICATES + rc_enc_bits_fx( hBstr, hPVQ, UL_deposit_l( entry.lead_sign_ind ), 1 ); /* 0 or 1 */ +#else rc_enc_bits_ivas_fx( hBstr, hPVQ, UL_deposit_l( entry.lead_sign_ind ), 1 ); /* 0 or 1 */ +#endif + IF( NE_16( dim, 1 ) ) { +#ifdef FIX_2425_REMOVE_RC_DUPLICATES + rc_enc_uniform_fx( hBstr, hPVQ, entry.index, entry.size ); +#else rc_enc_uniform_ivas_fx( hBstr, hPVQ, entry.index, entry.size ); +#endif } return; diff --git a/lib_enc/q_gain2p_fx.c b/lib_enc/q_gain2p_fx.c index c576c25f6120a5092e5f5c3f6d80dd76cb1ed63a..b0f681120e6be2b31b7fbd9b1b02d6497a9e64b4 100644 --- a/lib_enc/q_gain2p_fx.c +++ b/lib_enc/q_gain2p_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/qlpc_avq_fx.c b/lib_enc/qlpc_avq_fx.c index 288612e43c16582526989a2cc89db455fa19aed6..5d4d93fdfaf6d1aa6859cb40eb5f9a3835058d7c 100644 --- a/lib_enc/qlpc_avq_fx.c +++ b/lib_enc/qlpc_avq_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -27,7 +27,7 @@ void qlpc_avq_fx( Word16 *nb_indices, /* o : Number of quantization indices Q0 */ Word16 *nbbits, /* o : Number of quantization bits Q0 */ const Word16 core, /* i : TCX10 or TCX20 Q0 */ - const Word32 sr_core /* i : internal sampling rate Q0 */ + const Word32 sr_core /* i : internal sampling rate Q0 */ ) { Word16 i; @@ -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 70a41378f66e8295ea6a4aa3162d177e06538846..0d02d4742be1a1f2e475fe14e829aec7fb01ae32 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -25,6 +25,7 @@ * * *--------------------------------------------------------------------*/ + void lpc_quantization_fx( Encoder_State *st, const Word16 lsp[], /* Q15 */ @@ -56,11 +57,8 @@ void lpc_quantization_fx( IF( st->lpcQuantization == 0 ) { - if ( st->sr_core != 12800 ) - { - // PMT("from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz, current sampling rate is NOT 12800, is it ok?") - /*_DIFF_FLOAT_FIX_ E_LPC_lsp_lsf_conversion, does it work for 16kHz as well ?*/ - } + /* from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz only, if current sampling rate is NOT 12800, is it ok? , float takes into account Fs */ + /* _DIFF_FLOAT_FIX_EVS_IVAS */ E_LPC_lsp_lsf_conversion( lsp, lsf, M ); /* check resonance for pitch clipping algorithm */ @@ -120,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(); @@ -128,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(); @@ -175,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 ) ); @@ -199,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; } @@ -373,14 +204,14 @@ void lpc_quantization_ivas_fx( *-------------------------------------------------------------------*/ void Unified_weighting_fx( - const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ + const Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband Q0*/ - const Word16 unvoiced, /* i : flag for Unvoiced frame Q0*/ - const Word32 sr_core, /* i : sampling rate of core-coder Q0*/ - const Word16 order /* i : LP order Q0*/ + const Word16 lsf_fx[], /* i : LSF vector x2.56 */ + Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ + const Word16 narrowBand, /* i : flag for Narrowband Q0*/ + const Word16 unvoiced, /* i : flag for Unvoiced frame Q0*/ + const Word32 sr_core, /* i : sampling rate of core-coder Q0*/ + const Word16 order /* i : LP order Q0*/ ) { Word16 i; diff --git a/lib_enc/range_enc_fx.c b/lib_enc/range_enc_fx.c index 3f157b0939d5123d4a93fbf51a4538b825645e61..52886cd55f725c5eba50e8dc0b9ddab98d4c5628 100644 --- a/lib_enc/range_enc_fx.c +++ b/lib_enc/range_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -11,10 +11,16 @@ #include "prot_fx_enc.h" /* Function prototypes */ +/*-------------------------------------------------------------------* + * Local funtions declarations + *-------------------------------------------------------------------*/ + static void rc_enc_shift_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ ); static void rc_enc_write_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits ); +#ifndef FIX_2425_REMOVE_RC_DUPLICATES static void rc_enc_shift_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ ); static void rc_enc_write_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits ); +#endif /*-------------------------------------------------------------------* * rc_enc_init() @@ -24,7 +30,7 @@ static void rc_enc_write_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bit void rc_enc_init_fx( PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - Word16 tot_bits /* i : Total bit budget Q0*/ + Word16 tot_bits /* i : Total bit budget Q0*/ ) { hPVQ->rc_low = L_deposit_l( 0 ); @@ -51,12 +57,13 @@ void rc_enc_init_fx( * * Encode symbol with range coder *-------------------------------------------------------------------*/ +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ - UWord32 sym_freq, /* i : Symbol probability Q0*/ - UWord32 tot /* i : Total cumulative frequency Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ + UWord32 sym_freq, /* i : Symbol probability Q0*/ + UWord32 tot /* i : Total cumulative frequency Q0*/ ) { UWord32 r, tmp, inv_tot, lsb; @@ -89,12 +96,14 @@ void rc_encode_ivas_fx( return; } +#endif + void rc_encode_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ - UWord32 sym_freq, /* i : Symbol probability Q0*/ - UWord32 tot /* i : Total cumulative frequency Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 cum_freq, /* i : Cumulative frequency up to symbol Q0*/ + UWord32 sym_freq, /* i : Symbol probability Q0*/ + UWord32 tot /* i : Total cumulative frequency Q0*/ ) { UWord32 r, tmp, inv_tot, lsb; @@ -131,10 +140,11 @@ void rc_encode_fx( * * Finalize range coder *-------------------------------------------------------------------*/ + +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_enc_finish_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ - ) { UWord32 val, mask, high; @@ -215,6 +225,8 @@ void rc_enc_finish_ivas_fx( return; } +#endif + void rc_enc_finish_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ @@ -304,9 +316,10 @@ void rc_enc_finish_fx( * * Shift a byte out to bitstream *-------------------------------------------------------------------*/ +#ifndef FIX_2425_REMOVE_RC_DUPLICATES static void rc_enc_shift_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ ) { test(); @@ -338,6 +351,8 @@ static void rc_enc_shift_ivas_fx( move32(); return; } +#endif + static void rc_enc_shift_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle */ @@ -376,11 +391,12 @@ static void rc_enc_shift_fx( * * *-------------------------------------------------------------------*/ +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_enc_bits_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode Q0*/ - Word16 bits /* i : Number of bits used Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + Word16 bits /* i : Number of bits used Q0*/ ) { IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) ) @@ -409,11 +425,13 @@ void rc_enc_bits_ivas_fx( return; } +#endif + void rc_enc_bits_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode Q0*/ - Word16 bits /* i : Number of bits used Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + Word16 bits /* i : Number of bits used Q0*/ ) { IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) ) @@ -445,11 +463,12 @@ void rc_enc_bits_fx( * * Encode with uniform distribution *-------------------------------------------------------------------*/ +#ifndef FIX_2425_REMOVE_RC_DUPLICATES void rc_enc_uniform_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode Q0*/ - UWord32 tot /* i : Maximum value Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + UWord32 tot /* i : Maximum value Q0*/ ) { Word16 n; @@ -469,11 +488,13 @@ void rc_enc_uniform_ivas_fx( return; } +#endif + void rc_enc_uniform_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - UWord32 value, /* i : Value to encode Q0*/ - UWord32 tot /* i : Maximum value Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + UWord32 value, /* i : Value to encode Q0*/ + UWord32 tot /* i : Maximum value Q0*/ ) { Word16 n; @@ -499,20 +520,23 @@ void rc_enc_uniform_fx( * * Write a byte to bitstream *-------------------------------------------------------------------*/ +#ifndef FIX_2425_REMOVE_RC_DUPLICATES static void rc_enc_write_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 byte, /* i : Byte to write Q0*/ - Word16 bits /* i : Number of bits Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 byte, /* i : Byte to write Q0*/ + Word16 bits /* i : Number of bits Q0*/ ) { push_indice( hBstr, IND_RC_START, byte, bits ); return; } +#endif + static void rc_enc_write_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 byte, /* i : Byte to write Q0*/ - Word16 bits /* i : Number of bits Q0*/ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 byte, /* i : Byte to write Q0*/ + Word16 bits /* i : Number of bits Q0*/ ) { push_indice( hBstr, IND_RC_START, byte, bits ); diff --git a/lib_enc/re8_cod_fx.c b/lib_enc/re8_cod_fx.c index d43dbbf57aa184d18022f519071e0e3df1c0a9b8..ea1990b63bfeaf9e54b4d2ededa320ddd4cc6ef2 100644 --- a/lib_enc/re8_cod_fx.c +++ b/lib_enc/re8_cod_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ diff --git a/lib_enc/reordernorm_fx.c b/lib_enc/reordernorm_fx.c index 31d7ad869151343b235efb54618ba6a06abb1446..149c499d18fb85dcec99848355a6c971d226a9af 100644 --- a/lib_enc/reordernorm_fx.c +++ b/lib_enc/reordernorm_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index d0ffa9b2de4fe7989833df20759cb43550a2e9ce..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef ROM_ENC_H @@ -45,14 +45,14 @@ /*----------------------------------------------------------------------------------* * General tables *----------------------------------------------------------------------------------*/ -extern const Word16 sqrt_han_window_fx[]; /* Half of the square root hanning window Q15*/ -extern const Word16 tipos[]; /* Starting points for pulse position search in Algebraic innovation codebook Q0*/ -extern const Word16 W_HIST_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy Q16*/ -extern const Word16 W_HIST_S_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy Q12*/ +extern const Word16 sqrt_han_window_fx[]; /* Half of the square root hanning window Q15*/ +extern const Word16 tipos[]; /* Starting points for pulse position search in Algebraic innovation codebook Q0*/ +extern const Word16 W_HIST_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy Q16*/ +extern const Word16 W_HIST_S_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy Q12*/ extern const Word16 bwd_start_bin[]; // Q0 extern const Word16 bwd_end_bin[]; // Q0 -extern const Word16 h_fir_fx[]; /* 2nd order fir filter for wsp, decimation by 2 Q15*/ +extern const Word16 h_fir_fx[]; /* 2nd order fir filter for wsp, decimation by 2 Q15*/ extern const Word16 preemphCompensation_fx[]; // Q11 /*----------------------------------------------------------------------------------* @@ -174,7 +174,7 @@ extern const Word32 LS_MIN_SILENCE_SNR[4]; // Q25 extern const Word16 SNR_SUB_BAND_NUM[4]; // Q0 extern const Word16 BAND_MUL[4]; // Q15 -extern const UWord8 E_ROM_tipos[]; /* ACELP indexing Q0*/ +extern const UWord8 E_ROM_tipos[]; /* ACELP indexing Q0*/ extern const Word16 Weight[86]; extern const Word16 BAND_SCALE_AJ[5]; // Q0 diff --git a/lib_enc/rom_enc_fx.c b/lib_enc/rom_enc_fx.c index c0208b4818a781a64caee671fbb1be6fe5be4cff..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -46,12 +46,12 @@ * VAD ROM tables *----------------------------------------------------------------------------------*/ -const Word16 hangover_hd_tbl[3] = {1, 1, 3}; // Q0 -const Word16 hangover_sf_tbl[6] = {1, 3, 4, 1, 1, 2}; // Q0 -const Word16 bwd_start_bin[BWD_N_BINS_MAX] = {1, 3, 6, 11}; // Q0 -const Word16 bwd_end_bin[BWD_N_BINS_MAX] = {1, 4, 9, 12}; // Q0 +const Word16 hangover_hd_tbl[3] = {1, 1, 3}; // Q0 +const Word16 hangover_sf_tbl[6] = {1, 3, 4, 1, 1, 2}; // Q0 +const Word16 bwd_start_bin[BWD_N_BINS_MAX] = {1, 3, 6, 11}; // Q0 +const Word16 bwd_end_bin[BWD_N_BINS_MAX] = {1, 4, 9, 12}; // Q0 -const Word16 BAND_NUM_TAB[5] = {10,10,20,40,60}; /* {OFFSET, NB, WB, SWB, FB} Q0*/ +const Word16 BAND_NUM_TAB[5] = {10,10,20,40,60}; /* {OFFSET, NB, WB, SWB, FB} Q0*/ typedef struct { Word16 r; @@ -76,16 +76,16 @@ const Word16 M_Wi_fix16[16] = 32609/* 9.9518473e-001f Q15 */,31356/* 9.5694034e-001f Q15 */,28898/* 8.8192126e-001f Q15 */,25329/* 7.7301045e-001f Q15 */,20787/* 6.3439328e-001f Q15 */,15446/* 4.7139674e-001f Q15 */, 9512/* 2.9028468e-001f Q15 */, 3212/* 9.8017140e-002f Q15 */ }; -const Word16 SP_CENTER_BAND_NUM_TAB[5] = {10, 10, 20, 24, 24}; // Q0 +const Word16 SP_CENTER_BAND_NUM_TAB[5] = {10, 10, 20, 24, 24}; // Q0 /* 107374184.f = 32768.f * 32768.f * 0.1 */ -const Word16 NREGION_INDEX_NB[9] = {0,1,2,3,4,5,6,7, 9}; // Q0 -const Word16 NREGION_INDEX_WB[13] = {0,1,2,3,4,5,6,8,10,12,16}; // Q0 -const Word16 NREGION_INDEX_SWB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; // Q0 -const Word16 NREGION_INDEX_FB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; // Q0 +const Word16 NREGION_INDEX_NB[9] = {0,1,2,3,4,5,6,7, 9}; // Q0 +const Word16 NREGION_INDEX_WB[13] = {0,1,2,3,4,5,6,8,10,12,16}; // Q0 +const Word16 NREGION_INDEX_SWB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; // Q0 +const Word16 NREGION_INDEX_FB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; // Q0 const Word16 NREGION_PREOFF[12] = { 0,0,0,0,0,0,1,1,1,2,3,4 }; -const Word16 ENERGY_BAND_NUM[4] = {8,10,12,MAX_SUBBAND_NUM}; // Q0 -const Word16 * const REGION_INDEX[4] = {NREGION_INDEX_NB, NREGION_INDEX_WB,NREGION_INDEX_SWB,NREGION_INDEX_FB}; // Q0 +const Word16 ENERGY_BAND_NUM[4] = {8,10,12,MAX_SUBBAND_NUM}; // Q0 +const Word16 * const REGION_INDEX[4] = {NREGION_INDEX_NB, NREGION_INDEX_WB,NREGION_INDEX_SWB,NREGION_INDEX_FB}; // Q0 const Word32 MAX_LF_SNR_TAB_FX[5] = { 26843545/* 0.8 Q25 */,26843545/* 0.8 Q25 */,53687090/* 1.6 Q25 */,26843545/* 0.8 Q25 */,26843545/* 0.8 Q25 */ }; const Word32 COMVAD_INIT_SNR_DELTA_FX[5] = { 33554431/* 1.0 Q25 */, 20132659/* 0.6 Q25 */, 28856811/* 0.86 Q25 */, 38923139/* 1.16 Q25 */, 33554431/* 1.0 Q25 */ }; const Word32 LT_MIN_SILENCE_SNR_FX[4] = { 150994940/* 4.5 Q25 */, 150994940/* 4.5 Q25 */, 150994940/* 4.5 Q25 */,150994940/* 4.5 Q25 */ }; @@ -106,7 +106,7 @@ const Word16 sqrt_han_window_fx[L_FFT / 2 + 1] = 31785, 31880, 31971, 32057, 32137, 32213, 32285, 32351, 32412, 32469, 32521, 32567, 32609, 32646, 32678, 32705, 32728, 32745, 32757, 32765, 32767 -}; // Q15 +}; // Q15 /*----------------------------------------------------------------------------------* * Starting points for pulse position search in Algebraic innovation codebook @@ -123,22 +123,22 @@ const Word16 tipos[40] = 3, 0, 1, 2, 0, 1, 2, 3, 1, 2, 3, 0 /* end point for 28 pulses &ipos[39], 4th iter */ -}; // Q0 +}; // Q0 /*----------------------------------------------------------------------------------* * Open-loop pitch tables *----------------------------------------------------------------------------------*/ -const Word16 nb_sect_12k8[3] = { 4, 4, 4 }; // Q0 -const Word16 nb_subsect_12k8[3] = { 7, 7, 7 }; // Q0 -const Word16 pit_max_12k8[8] = { 11, 16, 21, 31, 40, 61, 77, 115}; // Q0 +const Word16 nb_sect_12k8[3] = { 4, 4, 4 }; // Q0 +const Word16 nb_subsect_12k8[3] = { 7, 7, 7 }; // Q0 +const Word16 pit_max_12k8[8] = { 11, 16, 21, 31, 40, 61, 77, 115}; // Q0 -const Word16 len_12k8[4] = { 40, 40, 62, 115 }; // Q0 -const Word16 len1_12k8[4] = { 40, 50, 80, 115 }; // Q0 -const Word16 sublen_12k8[7] = { 40, 40, 40, 62, 62, 115, 115 }; // Q0 -const Word16 sublen1_12k8[7] = { 40, 40, 50, 50, 80, 80, 115 }; // Q0 -const Word16 sec_length_12k8[4] = { 7, 15, 30, 54 }; // Q0 -const Word16 sec_length1_12k8[4] = { 10, 19, 37, 38 }; // Q0 -const Word16 h_fir_fx[] = { 4260, 7536, 9175, 7536, 4260 }; // Q15 +const Word16 len_12k8[4] = { 40, 40, 62, 115 }; // Q0 +const Word16 len1_12k8[4] = { 40, 50, 80, 115 }; // Q0 +const Word16 sublen_12k8[7] = { 40, 40, 40, 62, 62, 115, 115 }; // Q0 +const Word16 sublen1_12k8[7] = { 40, 40, 50, 50, 80, 80, 115 }; // Q0 +const Word16 sec_length_12k8[4] = { 7, 15, 30, 54 }; // Q0 +const Word16 sec_length1_12k8[4] = { 10, 19, 37, 38 }; // Q0 +const Word16 h_fir_fx[] = { 4260, 7536, 9175, 7536, 4260 }; // Q15 const Word16 W_HIST_FX[DTX_HIST_SIZE] = { 13107, 10486, 8389, 6711, 5369, 4295, 3436, 687 }; /* Q16 */ const Word16 W_HIST_S_FX[DTX_HIST_SIZE] = { 20480, 11378, 8393, 6938, 6092, 5551, 5183, 5115 }; /* Q12 */ @@ -148,8 +148,8 @@ const Word16 preemphCompensation_fx[NB_BANDS] = { 19960/*9.7461f Q11*/, 19493/* * LSF quantizer *----------------------------------------------------------------------------------*/ -const Word16 lsf_numlevels[TCXLPC_NUMSTAGES] = { 32, 16, 16 }; // Q0 -const Word16 lsf_ind_numlevels[TCXLPC_IND_NUMSTAGES] = { 4 }; // Q0 +const Word16 lsf_numlevels[TCXLPC_NUMSTAGES] = { 32, 16, 16 }; // Q0 +const Word16 lsf_ind_numlevels[TCXLPC_IND_NUMSTAGES] = { 4 }; // Q0 const Word16 lsf_unified_fit_model_nb[4][16] = { @@ -157,7 +157,7 @@ const Word16 lsf_unified_fit_model_nb[4][16] = {20383 , 18855 , 8494 , 8062 , 8105 , 6211 , 5068 , 4408 , 3741 , 3458 , 2732 , 3174 , 2412 , 17421 , -21717 , 0}, {-717 , -617 , -144 , -117 , -229 , -144 , -141 , -98 , -92 , -69 , -51 , -87 , -37 , -3019 , 19864 , 8034}, {-2424 , 8999 , 5723 , 5629 , 4239 , 3423 , 2507 , 2019 , 1245 , 736 , -907 , -2237 , -2558 , -1979 , -652 , 1657} -}; // Q0 +}; // Q0 const Word16 lsf_unified_fit_model_wb[4][16] = { @@ -165,7 +165,7 @@ const Word16 lsf_unified_fit_model_wb[4][16] = {24635 , 19605 , 9294 , 7407 , 6419 , 5459 , 4966 , 4189 , 3394 , 2964 , 2425 , 2110 , 2140 , 1972 , 1540 , 2252}, {-867 , -666 , -168 , -114 , -90 , -122 , -129 , -101 , -65 , -56 , -39 , -35 , -40 , -42 , -35 , -56}, {-2313 , 3035 , 1677 , 2854 , 2334 , 1232 , 1347 , 1034 , 863 , 707 , 886 , 891 , 432 , 357 , 206 , -310} -}; // Q0 +}; // Q0 const Word16 lsf_unified_fit_model_wbhb[4][16] = { @@ -173,52 +173,52 @@ const Word16 lsf_unified_fit_model_wbhb[4][16] = {28135 , 16053 , 10129 , 7366 , 5898 , 5341 , 3290 , 2780 , 3146 , 2423 , 1613 , 1370 , 1294 , 1635 , 1105 , 1431}, {-615 , -308 , -147 , -119 , -104 , -105 , -30 , -28 , -50 , -39 , -15 , -14 , -14 , -21 , -19 , -29}, {1534 , 3569 , 3138 , 4023 , 2105 , 2023 , 2046 , 1264 , 1340 , 1067 , 780 , 547 , 188 , -540 , -722 , -479} -}; // Q0 +}; // Q0 const Word32 Freq_Weight_Com_fx[160] = /*Q31 */ { - 1073741824, 1351646720, 1610612736, 1832992000, 2003629568, 2110896768, 2147483647, 2147483647, - 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, - 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2088915968, 2033457920, 1980868480, - 1930930688, 1883448832, 1838246016, 1795162112, 1754051584, 1714781696, 1677231744, 1641291136, - 1606858368, 1573840768, 1542152704, 1511715456, 1482456448, 1454308608, 1427209600, 1401102080, - 1375932672, 1351651456, 1328212480, 1305572480, 1283691392, 1262531584, 1242058112, 1222238080, - 1203040640, 1184436864, 1166399744, 1148903808, 1131924864, 1115440512, 1099429376, 1083871488, - 1068747648, 1054040128, 1039731904, 1025806912, 1012249984, 999046720, 986183488, 973647232, - 961425728, 949507264, 937880640, 926535296, 915461184, 904648640, 894088512, 883772096, - 873691072, 863837376, 854203520, 844782144, 835566336, 826549440, 817725120, 809087168, - 800629824, 792347392, 784234624, 776286336, 768497472, 760863424, 753379520, 746041408, - 738844864, 731785856, 724860416, 718064832, 711395520, 704848896, 698421760, 692110720, - 685912704, 679824704, 673843840, 667967296, 662192384, 656516416, 650936960, 645451520, - 640057792, 634753472, 629536320, 624404224, 619355136, 614387008, 609497984, 604686208, - 599949760, 595286912, 590696000, 586175360, 581723392, 577338560, 573019328, 568764224, - 564571840, 560440832, 556369856, 552357568, 548402752, 544504128, 540660608, 536870912, - 533133984, 529448736, 525814080, 522228992, 518692448, 515203488, 511761152, 508364480, - 505012640, 501704704, 498439808, 495217120, 492035872, 488895200, 485794400, 482732672, - 479709280, 476723552, 473774752, 470862208, 467985248, 465143232, 462335520, 459561504, - 456820576, 454112160, 451435648, 448790528, 446176224, 443592192, 441037920, 438512896 + 1073741824, 1351646720, 1610612736, 1832992000, 2003629568, 2110896768, 2147483647, 2147483647, + 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, + 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2088915968, 2033457920, 1980868480, + 1930930688, 1883448832, 1838246016, 1795162112, 1754051584, 1714781696, 1677231744, 1641291136, + 1606858368, 1573840768, 1542152704, 1511715456, 1482456448, 1454308608, 1427209600, 1401102080, + 1375932672, 1351651456, 1328212480, 1305572480, 1283691392, 1262531584, 1242058112, 1222238080, + 1203040640, 1184436864, 1166399744, 1148903808, 1131924864, 1115440512, 1099429376, 1083871488, + 1068747648, 1054040128, 1039731904, 1025806912, 1012249984, 999046720, 986183488, 973647232, + 961425728, 949507264, 937880640, 926535296, 915461184, 904648640, 894088512, 883772096, + 873691072, 863837376, 854203520, 844782144, 835566336, 826549440, 817725120, 809087168, + 800629824, 792347392, 784234624, 776286336, 768497472, 760863424, 753379520, 746041408, + 738844864, 731785856, 724860416, 718064832, 711395520, 704848896, 698421760, 692110720, + 685912704, 679824704, 673843840, 667967296, 662192384, 656516416, 650936960, 645451520, + 640057792, 634753472, 629536320, 624404224, 619355136, 614387008, 609497984, 604686208, + 599949760, 595286912, 590696000, 586175360, 581723392, 577338560, 573019328, 568764224, + 564571840, 560440832, 556369856, 552357568, 548402752, 544504128, 540660608, 536870912, + 533133984, 529448736, 525814080, 522228992, 518692448, 515203488, 511761152, 508364480, + 505012640, 501704704, 498439808, 495217120, 492035872, 488895200, 485794400, 482732672, + 479709280, 476723552, 473774752, 470862208, 467985248, 465143232, 462335520, 459561504, + 456820576, 454112160, 451435648, 448790528, 446176224, 443592192, 441037920, 438512896 }; const Word32 Freq_Weight_UV_fx[160] = /*Q31 */ { - 1073741824, 1351646720, 1610612736, 1832992000, 2003629568, 2110896768, 2147483647, 2129881344, - 2112565248, 2095528448, 2078764160, 2062265984, 2046027776, 2030043136, 2014306304, 1998811648, - 1983553536, 1968526720, 1953725696, 1939145728, 1924781696, 1910628864, 1896682624, 1882938624, - 1869392256, 1856039424, 1842876032, 1829897984, 1817101568, 1804482816, 1792038016, 1779763840, - 1767656576, 1755713024, 1743929728, 1732303488, 1720831232, 1709510016, 1698336768, 1687308544, - 1676422656, 1665676416, 1655067008, 1644591872, 1634248576, 1624034560, 1613947392, 1603984640, - 1594144256, 1584423936, 1574821376, 1565334528, 1555961216, 1546699520, 1537547520, 1528503040, - 1519564416, 1510729728, 1501997184, 1493365120, 1484831488, 1476395008, 1468053760, 1459806336, - 1451650944, 1443586176, 1435610624, 1427722624, 1419920896, 1412203904, 1404570368, 1397018880, - 1389548288, 1382157056, 1374844032, 1367608064, 1360447744, 1353362048, 1346349824, 1339409920, - 1332541184, 1325742464, 1319012736, 1312351104, 1305756416, 1299227648, 1292763776, 1286363904, - 1280027136, 1273752576, 1267539072, 1261385984, 1255292416, 1249257344, 1243280000, 1237359616, - 1231495424, 1225686400, 1219932032, 1214231424, 1208583808, 1202988544, 1197444736, 1191951872, - 1186509184, 1181116032, 1175771648, 1170475264, 1165226496, 1160024704, 1154868992, 1149758976, - 1144693888, 1139673344, 1134696576, 1129763200, 1124872448, 1120023808, 1115216768, 1110450944, - 1105725568, 1101040384, 1096394624, 1091787904, 1087219712, 1082689664, 1078197248, 1073741824, - 1069323136, 1064940672, 1060593984, 1056282624, 1052006144, 1047764224, 1043556288, 1039382080, - 1035241152, 1031132992, 1027057408, 1023013888, 1019002048, 1015021568, 1011072064, 1007153152, - 1003264576, 999405824, 995576704, 991776768, 988005760, 984263360, 980549120, 976862848, - 973204224, 969572864, 965968512, 962390848, 958839552, 955314432, 951815104, 948341312, + 1073741824, 1351646720, 1610612736, 1832992000, 2003629568, 2110896768, 2147483647, 2129881344, + 2112565248, 2095528448, 2078764160, 2062265984, 2046027776, 2030043136, 2014306304, 1998811648, + 1983553536, 1968526720, 1953725696, 1939145728, 1924781696, 1910628864, 1896682624, 1882938624, + 1869392256, 1856039424, 1842876032, 1829897984, 1817101568, 1804482816, 1792038016, 1779763840, + 1767656576, 1755713024, 1743929728, 1732303488, 1720831232, 1709510016, 1698336768, 1687308544, + 1676422656, 1665676416, 1655067008, 1644591872, 1634248576, 1624034560, 1613947392, 1603984640, + 1594144256, 1584423936, 1574821376, 1565334528, 1555961216, 1546699520, 1537547520, 1528503040, + 1519564416, 1510729728, 1501997184, 1493365120, 1484831488, 1476395008, 1468053760, 1459806336, + 1451650944, 1443586176, 1435610624, 1427722624, 1419920896, 1412203904, 1404570368, 1397018880, + 1389548288, 1382157056, 1374844032, 1367608064, 1360447744, 1353362048, 1346349824, 1339409920, + 1332541184, 1325742464, 1319012736, 1312351104, 1305756416, 1299227648, 1292763776, 1286363904, + 1280027136, 1273752576, 1267539072, 1261385984, 1255292416, 1249257344, 1243280000, 1237359616, + 1231495424, 1225686400, 1219932032, 1214231424, 1208583808, 1202988544, 1197444736, 1191951872, + 1186509184, 1181116032, 1175771648, 1170475264, 1165226496, 1160024704, 1154868992, 1149758976, + 1144693888, 1139673344, 1134696576, 1129763200, 1124872448, 1120023808, 1115216768, 1110450944, + 1105725568, 1101040384, 1096394624, 1091787904, 1087219712, 1082689664, 1078197248, 1073741824, + 1069323136, 1064940672, 1060593984, 1056282624, 1052006144, 1047764224, 1043556288, 1039382080, + 1035241152, 1031132992, 1027057408, 1023013888, 1019002048, 1015021568, 1011072064, 1007153152, + 1003264576, 999405824, 995576704, 991776768, 988005760, 984263360, 980549120, 976862848, + 973204224, 969572864, 965968512, 962390848, 958839552, 955314432, 951815104, 948341312, }; /*----------------------------------------------------------------------------------* @@ -227,20 +227,20 @@ const Word32 Freq_Weight_UV_fx[160] = /*Q31 */ const Word16 w_spmus_fx[HANG_LEN][HANG_LEN] = { /*Q15*/ - {32767, 0, 0, 0, 0, 0, 0, 0,}, - {19661, 13107, 0, 0, 0, 0, 0, 0,}, - {15401, 10813, 6554, 0, 0, 0, 0, 0,}, - {13107, 9830, 6554, 3277, 0, 0, 0, 0,}, - { 9830, 8192, 6554, 4915, 3277, 0, 0, 0,}, - { 7635, 6783, 5898, 5014, 4162, 3277, 0, 0,}, - { 7700, 6717, 5702, 4686, 3670, 2654, 1638, 0,}, - { 6554, 5865, 5145, 4456, 3736, 3047, 2327, 1638} + {32767, 0, 0, 0, 0, 0, 0, 0,}, + {19661, 13107, 0, 0, 0, 0, 0, 0,}, + {15401, 10813, 6554, 0, 0, 0, 0, 0,}, + {13107, 9830, 6554, 3277, 0, 0, 0, 0,}, + { 9830, 8192, 6554, 4915, 3277, 0, 0, 0,}, + { 7635, 6783, 5898, 5014, 4162, 3277, 0, 0,}, + { 7700, 6717, 5702, 4686, 3670, 2654, 1638, 0,}, + { 6554, 5865, 5145, 4456, 3736, 3047, 2327, 1638} }; const Word32 sm_means_fx[N_SMC_FEATURES] = { 114371648, 762918, 258533, 305622, 877131, 1071555, 1272603, 67350312, 1296274, -2461829, 1882791, -41135, -306269, 641721, 5859343, -}; // Q20 +}; // Q20 const Word32 sm_scale_fx[N_SMC_FEATURES] = {//Q20 46789116, 166914, 66905, 70898, 117576, 108472, 96226, 17324576, @@ -257,12 +257,12 @@ const Word32 bcox_add_cnst_fx[N_SMC_FEATURES] = { 0, 0, -1886955264, -1559167616, 0, 0, 0, 0, -1672874752, 0, 0, 0, 0, 0, 0, -}; // Q31 +}; // Q31 const Word32 bcox_lmbd_fx[N_SMC_FEATURES] = { 0, 0, -1426534784, -907320448, 0, 0, 0, 0, -1362524672, 0, 0, 0, 0, 0, 0, -}; // Q31 +}; // Q31 const Word32 pca_mean_fx[N_SMC_FEATURES] = { 0, 0, 0, 0, 0, 0, 0, 0, @@ -541,287 +541,287 @@ const Word32 prec_chol_noise_fx[N_SMC_MIXTURES*(N_PCA_COEF*N_PCA_COEF + N_PCA_CO const Word16 m_speech_fx[N_MIXTURES*N_FEATURES] = { /*Q15*/ - 9436, 29987, 4795, 7076, 11050, 13645, 15206, 15194, 1936, 27952, 25172, 10301, - 10057, 30685, 8381, 9965, 10762, 8680, 11589, 15788, 1641, 26751, 27163, 10992, - 7927, 31230, 7191, 8505, 14304, 16336, 14972, 16077, 2052, 27271, 27694, 10859, - 13914, 17323, 10682, 16458, 17807, 18403, 19368, 12665, 2205, 29598, 29213, 11285, - 12468, 23848, 6880, 10301, 13824, 13066, 14647, 13189, 3451, 28442, 28766, 10410, - 11304, 21566, 7894, 11411, 14194, 15739, 16351, 13744, 6130, 28445, 28034, 11380 + 9436, 29987, 4795, 7076, 11050, 13645, 15206, 15194, 1936, 27952, 25172, 10301, + 10057, 30685, 8381, 9965, 10762, 8680, 11589, 15788, 1641, 26751, 27163, 10992, + 7927, 31230, 7191, 8505, 14304, 16336, 14972, 16077, 2052, 27271, 27694, 10859, + 13914, 17323, 10682, 16458, 17807, 18403, 19368, 12665, 2205, 29598, 29213, 11285, + 12468, 23848, 6880, 10301, 13824, 13066, 14647, 13189, 3451, 28442, 28766, 10410, + 11304, 21566, 7894, 11411, 14194, 15739, 16351, 13744, 6130, 28445, 28034, 11380 }; const Word32 invV_speech_fx[N_MIXTURES*N_FEATURES*N_FEATURES] = { /*Q10*/ - -40443, -14756, -39560, -18113, 8983, -11676, 450, -10588, -49908, 358, 17222, 32914, - -14756, -200610, -27679, -28092, -16846, -6393, 5954, 13058, -67051, -47861, -8575, 18740, - -39560, -27679, -772035, 118158, -48299, 27758, -37782, 74336, -305470, -23323, 181510, 91957, - -18113, -28092, 118158, -228070, 41104, -46248, 21977, 8161, -27789, 78357, 26088, 39736, - 8983, -16846, -48299, 41104, -96670, 41164, -18208, 3995, -14774, 23704, 13802, 17925, - -11676, -6393, 27758, -46248, 41164, -95654, 58562, 3668, 103, 5952, 9479, 11083, - 450, 5954, -37782, 21977, -18208, 58562, -91964, -5597, -47161, -15941, 14870, 11028, - -10588, 13058, 74336, 8161, 3995, 3668, -5597, -102767, 25363, -21490, -48411, 13509, - -49908, -67051, -305470, -27789, -14774, 103, -47161, 25363, -1410848, -57997, 238792, -117641, - 358, -47861, -23323, 78357, 23704, 5952, -15941, -21490, -57997, -221932, -936, 40579, - 17222, -8575, 181510, 26088, 13802, 9479, 14870, -48411, 238792, -936, -157118, -49202, - 32914, 18740, 91957, 39736, 17925, 11083, 11028, 13509, -117641, 40579, -49202, -321159, - -54755, -48603, -918, -25735, 31634, -27972, 23305, -18449, -68162, -3670, -7982, 35965, - -48603, -449238, -11496, -14811, 12790, -11453, 2686, -3752, -86924, -30083, -54695, 17457, - -918, -11496, -258042, 157642, 4617, 27546, -22677, 7281, -221085, -48457, 80126, 16406, - -25735, -14811, 157642, -334462, 64217, 7724, 24309, 20322, -99420, 2896, 76924, 35785, - 31634, 12790, 4617, 64217, -296101, 182629, -27282, 11581, -10495, 16901, 50011, 20823, - -27972, -11453, 27546, 7724, 182629, -274190, 15505, 4345, -7824, 79496, -2218, 12832, - 23305, 2686, -22677, 24309, -27282, 15505, -73195, 2055, -4690, 31413, 15447, 8774, - -18449, -3752, 7281, 20322, 11581, 4345, 2055, -77913, 57514, -8586, -106171, 6233, - -68162, -86924, -221085, -99420, -10495, -7824, -4690, 57514, -1966183, -9074, 512909, -17375, - -3670, -30083, -48457, 2896, 16901, 79496, 31413, -8586, -9074, -185355, -15990, 8445, - -7982, -54695, 80126, 76924, 50011, -2218, 15447, -106171, 512909, -15990, -444405, -71821, - 35965, 17457, 16406, 35785, 20823, 12832, 8774, 6233, -17375, 8445, -71821, -222292, - -96397, -65745, 316, -47258, 43061, -42973, 10442, -19582, -43973, -19682, -21732, 48029, - -65745, -838575, 30816, -43250, 6642, -4487, 11239, 338, -17329, -59741, -114530, -1706, - 316, 30816, -351192, 207585, -68100, 60838, -83672, 14796, -158998, 13313, 122647, 38113, - -47258, -43250, 207585, -322741, 76525, -99711, 59838, 20166, -63534, 7136, 76247, 22923, - 43061, 6642, -68100, 76525, -96244, 54110, -21689, 2401, -36455, -19725, 38782, 6802, - -42973, -4487, 60838, -99711, 54110, -284964, 220150, -642, -44874, -21815, 16040, 3963, - 10442, 11239, -83672, 59838, -21689, 220150, -239817, 2018, -17214, -1904, 16387, 4095, - -19582, 338, 14796, 20166, 2401, -642, 2018, -58537, 20742, -9245, -85094, 8867, - -43973, -17329, -158998, -63534, -36455, -44874, -17214, 20742, -1009892, 28181, 407531, -10963, - -19682, -59741, 13313, 7136, -19725, -21815, -1904, -9245, 28181, -186118, -32487, 5665, - -21732, -114530, 122647, 76248, 38782, 16040, 16387, -85094, 407531, -32487, -511009, -66277, - 48029, -1706, 38113, 22923, 6802, 3963, 4095, 8867, -10963, 5665, -66277, -251113, - -21146, 1393, -2365, 3756, -4538, -1528, 2298, -6668, -7599, -2720, -5226, 3049, - 1393, -46612, -28502, 11801, -5967, 8395, -4182, 13773, 18586, -9799, -6696, -3522, - -2365, -28502, -77446, 55688, -10615, 10476, -6282, 5520, -19365, 8818, -4576, 2603, - 3756, 11801, 55688, -152293, 104577, -8742, 15278, -2773, 16622, -12382, -2828, 5452, - -4538, -5967, -10615, 104577, -245151, 117173, -5020, 3412, -2855, -19929, 9729, 1888, - -1528, 8395, 10476, -8742, 117173, -258943, 136249, -2960, -8257, -20123, -6735, -6316, - 2298, -4182, -6282, 15278, -5020, 136249, -192889, 889, -6047, -74906, 15861, 4026, - -6668, 13773, 5520, -2773, 3412, -2960, 889, -298321, 8558, 5827, -66886, -3080, - -7599, 18586, -19365, 16622, -2855, -8257, -6047, 8558, -837495, -36576, 477123, -58582, - -2720, -9799, 8818, -12382, -19929, -20123, -74906, 5827, -36576, -279826, 29479, 36566, - -5226, -6696, -4576, -2828, 9729, -6735, 15861, -66886, 477123, 29479, -1017755, -75828, - 3049, -3522, 2603, 5452, 1888, -6316, 4026, -3080, -58582, 36566, -75828, -193453, - -30403, -6761, -6085, -8388, 12841, -17600, 8289, -11817, -4054, -3000, -13322, 14944, - -6761, -28452, -12326, -8945, 10515, -8369, -520, 2242, -3287, -20124, 179, 12354, - -6085, -12326, -180408, 89468, -19908, 3017, -41552, 4204, -31158, -23783, 87004, 44784, - -8388, -8945, 89468, -146434, 53166, -28645, 29987, -2506, -12242, 28411, 11874, 403, - 12841, 10515, -19908, 53166, -182342, 131104, -3630, 7016, -11031, -43497, 35570, 41136, - -17600, -8369, 3017, -28645, 131104, -169537, 52490, -4955, 3848, 41489, -7925, -19614, - 8289, -520, -41552, 29987, -3630, 52490, -111006, -916, 3418, 2295, 3395, 1491, - -11817, 2242, 4204, -2506, 7016, -4955, -916, -219477, -4965, -3871, -77054, -1199, - -4054, -3287, -31158, -12242, -11031, 3848, 3418, -4965, -272588, 2948, 184352, -45153, - -3000, -20124, -23783, 28411, -43497, 41489, 2295, -3871, 2948, -160538, -11875, 4491, - -13322, 179, 87004, 11874, 35570, -7925, 3395, -77054, 184352, -11875, -501251, -59166, - 14944, 12354, 44784, 403, 41136, -19614, 1491, -1199, -45153, 4491, -59166, -256669, - -24496, -5820, -2150, 131, 5291, -10279, 6605, -749, -2301, -4257, 6742, 4179, - -5820, -30866, -8866, -12879, -1341, 2042, -4488, 6991, -847, -21654, 3707, 11359, - -2150, -8866, -123923, 90609, -28405, 24864, -28222, 3814, 6439, -12821, 2736, 12974, - 131, -12879, 90609, -147490, 86712, -38319, 26159, 1048, -7654, 17099, 8973, 1271, - 5291, -1341, -28405, 86712, -147877, 74296, -14561, 2055, 18062, 1238, -4181, 14726, - -10279, 2042, 24864, -38319, 74296, -168459, 117891, -874, -17255, 675, 13174, -13101, - 6605, -4488, -28222, 26159, -14561, 117891, -147764, -13296, 2771, -4243, -4809, 1608, - -749, 6991, 3814, 1048, 2055, -874, -13296, -77582, -32335, -4868, 9778, -6784, - -2301, -847, 6439, -7654, 18062, -17255, 2771, -32335, -69840, 11490, 21385, -23633, - -4257, -21654, -12821, 17099, 1238, 675, -4243, -4868, 11490, -151841, -2520, 12898, - 6742, 3707, 2736, 8973, -4181, 13174, -4809, 9778, 21385, -2520, -60529, -3814, - 4179, 11359, 12974, 1271, 14726, -13101, 1608, -6784, -23633, 12898, -3814, -63927 + -40443, -14756, -39560, -18113, 8983, -11676, 450, -10588, -49908, 358, 17222, 32914, + -14756, -200610, -27679, -28092, -16846, -6393, 5954, 13058, -67051, -47861, -8575, 18740, + -39560, -27679, -772035, 118158, -48299, 27758, -37782, 74336, -305470, -23323, 181510, 91957, + -18113, -28092, 118158, -228070, 41104, -46248, 21977, 8161, -27789, 78357, 26088, 39736, + 8983, -16846, -48299, 41104, -96670, 41164, -18208, 3995, -14774, 23704, 13802, 17925, + -11676, -6393, 27758, -46248, 41164, -95654, 58562, 3668, 103, 5952, 9479, 11083, + 450, 5954, -37782, 21977, -18208, 58562, -91964, -5597, -47161, -15941, 14870, 11028, + -10588, 13058, 74336, 8161, 3995, 3668, -5597, -102767, 25363, -21490, -48411, 13509, + -49908, -67051, -305470, -27789, -14774, 103, -47161, 25363, -1410848, -57997, 238792, -117641, + 358, -47861, -23323, 78357, 23704, 5952, -15941, -21490, -57997, -221932, -936, 40579, + 17222, -8575, 181510, 26088, 13802, 9479, 14870, -48411, 238792, -936, -157118, -49202, + 32914, 18740, 91957, 39736, 17925, 11083, 11028, 13509, -117641, 40579, -49202, -321159, + -54755, -48603, -918, -25735, 31634, -27972, 23305, -18449, -68162, -3670, -7982, 35965, + -48603, -449238, -11496, -14811, 12790, -11453, 2686, -3752, -86924, -30083, -54695, 17457, + -918, -11496, -258042, 157642, 4617, 27546, -22677, 7281, -221085, -48457, 80126, 16406, + -25735, -14811, 157642, -334462, 64217, 7724, 24309, 20322, -99420, 2896, 76924, 35785, + 31634, 12790, 4617, 64217, -296101, 182629, -27282, 11581, -10495, 16901, 50011, 20823, + -27972, -11453, 27546, 7724, 182629, -274190, 15505, 4345, -7824, 79496, -2218, 12832, + 23305, 2686, -22677, 24309, -27282, 15505, -73195, 2055, -4690, 31413, 15447, 8774, + -18449, -3752, 7281, 20322, 11581, 4345, 2055, -77913, 57514, -8586, -106171, 6233, + -68162, -86924, -221085, -99420, -10495, -7824, -4690, 57514, -1966183, -9074, 512909, -17375, + -3670, -30083, -48457, 2896, 16901, 79496, 31413, -8586, -9074, -185355, -15990, 8445, + -7982, -54695, 80126, 76924, 50011, -2218, 15447, -106171, 512909, -15990, -444405, -71821, + 35965, 17457, 16406, 35785, 20823, 12832, 8774, 6233, -17375, 8445, -71821, -222292, + -96397, -65745, 316, -47258, 43061, -42973, 10442, -19582, -43973, -19682, -21732, 48029, + -65745, -838575, 30816, -43250, 6642, -4487, 11239, 338, -17329, -59741, -114530, -1706, + 316, 30816, -351192, 207585, -68100, 60838, -83672, 14796, -158998, 13313, 122647, 38113, + -47258, -43250, 207585, -322741, 76525, -99711, 59838, 20166, -63534, 7136, 76247, 22923, + 43061, 6642, -68100, 76525, -96244, 54110, -21689, 2401, -36455, -19725, 38782, 6802, + -42973, -4487, 60838, -99711, 54110, -284964, 220150, -642, -44874, -21815, 16040, 3963, + 10442, 11239, -83672, 59838, -21689, 220150, -239817, 2018, -17214, -1904, 16387, 4095, + -19582, 338, 14796, 20166, 2401, -642, 2018, -58537, 20742, -9245, -85094, 8867, + -43973, -17329, -158998, -63534, -36455, -44874, -17214, 20742, -1009892, 28181, 407531, -10963, + -19682, -59741, 13313, 7136, -19725, -21815, -1904, -9245, 28181, -186118, -32487, 5665, + -21732, -114530, 122647, 76248, 38782, 16040, 16387, -85094, 407531, -32487, -511009, -66277, + 48029, -1706, 38113, 22923, 6802, 3963, 4095, 8867, -10963, 5665, -66277, -251113, + -21146, 1393, -2365, 3756, -4538, -1528, 2298, -6668, -7599, -2720, -5226, 3049, + 1393, -46612, -28502, 11801, -5967, 8395, -4182, 13773, 18586, -9799, -6696, -3522, + -2365, -28502, -77446, 55688, -10615, 10476, -6282, 5520, -19365, 8818, -4576, 2603, + 3756, 11801, 55688, -152293, 104577, -8742, 15278, -2773, 16622, -12382, -2828, 5452, + -4538, -5967, -10615, 104577, -245151, 117173, -5020, 3412, -2855, -19929, 9729, 1888, + -1528, 8395, 10476, -8742, 117173, -258943, 136249, -2960, -8257, -20123, -6735, -6316, + 2298, -4182, -6282, 15278, -5020, 136249, -192889, 889, -6047, -74906, 15861, 4026, + -6668, 13773, 5520, -2773, 3412, -2960, 889, -298321, 8558, 5827, -66886, -3080, + -7599, 18586, -19365, 16622, -2855, -8257, -6047, 8558, -837495, -36576, 477123, -58582, + -2720, -9799, 8818, -12382, -19929, -20123, -74906, 5827, -36576, -279826, 29479, 36566, + -5226, -6696, -4576, -2828, 9729, -6735, 15861, -66886, 477123, 29479, -1017755, -75828, + 3049, -3522, 2603, 5452, 1888, -6316, 4026, -3080, -58582, 36566, -75828, -193453, + -30403, -6761, -6085, -8388, 12841, -17600, 8289, -11817, -4054, -3000, -13322, 14944, + -6761, -28452, -12326, -8945, 10515, -8369, -520, 2242, -3287, -20124, 179, 12354, + -6085, -12326, -180408, 89468, -19908, 3017, -41552, 4204, -31158, -23783, 87004, 44784, + -8388, -8945, 89468, -146434, 53166, -28645, 29987, -2506, -12242, 28411, 11874, 403, + 12841, 10515, -19908, 53166, -182342, 131104, -3630, 7016, -11031, -43497, 35570, 41136, + -17600, -8369, 3017, -28645, 131104, -169537, 52490, -4955, 3848, 41489, -7925, -19614, + 8289, -520, -41552, 29987, -3630, 52490, -111006, -916, 3418, 2295, 3395, 1491, + -11817, 2242, 4204, -2506, 7016, -4955, -916, -219477, -4965, -3871, -77054, -1199, + -4054, -3287, -31158, -12242, -11031, 3848, 3418, -4965, -272588, 2948, 184352, -45153, + -3000, -20124, -23783, 28411, -43497, 41489, 2295, -3871, 2948, -160538, -11875, 4491, + -13322, 179, 87004, 11874, 35570, -7925, 3395, -77054, 184352, -11875, -501251, -59166, + 14944, 12354, 44784, 403, 41136, -19614, 1491, -1199, -45153, 4491, -59166, -256669, + -24496, -5820, -2150, 131, 5291, -10279, 6605, -749, -2301, -4257, 6742, 4179, + -5820, -30866, -8866, -12879, -1341, 2042, -4488, 6991, -847, -21654, 3707, 11359, + -2150, -8866, -123923, 90609, -28405, 24864, -28222, 3814, 6439, -12821, 2736, 12974, + 131, -12879, 90609, -147490, 86712, -38319, 26159, 1048, -7654, 17099, 8973, 1271, + 5291, -1341, -28405, 86712, -147877, 74296, -14561, 2055, 18062, 1238, -4181, 14726, + -10279, 2042, 24864, -38319, 74296, -168459, 117891, -874, -17255, 675, 13174, -13101, + 6605, -4488, -28222, 26159, -14561, 117891, -147764, -13296, 2771, -4243, -4809, 1608, + -749, 6991, 3814, 1048, 2055, -874, -13296, -77582, -32335, -4868, 9778, -6784, + -2301, -847, 6439, -7654, 18062, -17255, 2771, -32335, -69840, 11490, 21385, -23633, + -4257, -21654, -12821, 17099, 1238, 675, -4243, -4868, 11490, -151841, -2520, 12898, + 6742, 3707, 2736, 8973, -4181, 13174, -4809, 9778, 21385, -2520, -60529, -3814, + 4179, 11359, 12974, 1271, 14726, -13101, 1608, -6784, -23633, 12898, -3814, -63927 }; const Word32 lvm_speech_fx[N_MIXTURES] = { /*Q10*/ - 32765, 33549, 33755, 32747, 31627, 26814 + 32765, 33549, 33755, 32747, 31627, 26814 }; const Word16 m_music_fx[N_MIXTURES*N_FEATURES] = { /*Q15*/ - 14804, 25446, 8882, 11624, 12963, 13563, 14794, 20567, 1033, 27373, 23772, 11713, - 15975, 20612, 7737, 12728, 14424, 15237, 16190, 15239, 2277, 30096, 28120, 11522, - 17631, 19827, 9280, 14111, 15555, 16289, 17009, 17271, 1132, 31186, 27733, 12469, - 15863, 24390, 7804, 11176, 11734, 11986, 12857, 23015, 713, 28823, 23782, 13779, - 10022, 22691, 12397, 15249, 15957, 16382, 17058, 15509, 4107, 23807, 22701, 12269, - 16842, 22819, 8062, 11248, 12283, 12978, 13722, 21178, 867, 30480, 25501, 12111 + 14804, 25446, 8882, 11624, 12963, 13563, 14794, 20567, 1033, 27373, 23772, 11713, + 15975, 20612, 7737, 12728, 14424, 15237, 16190, 15239, 2277, 30096, 28120, 11522, + 17631, 19827, 9280, 14111, 15555, 16289, 17009, 17271, 1132, 31186, 27733, 12469, + 15863, 24390, 7804, 11176, 11734, 11986, 12857, 23015, 713, 28823, 23782, 13779, + 10022, 22691, 12397, 15249, 15957, 16382, 17058, 15509, 4107, 23807, 22701, 12269, + 16842, 22819, 8062, 11248, 12283, 12978, 13722, 21178, 867, 30480, 25501, 12111 }; const Word32 invV_music_fx[N_MIXTURES*N_FEATURES*N_FEATURES] = { /*Q10*/ - -7878, -673, -2037, -885, -236, -667, 749, -1726, -20424, -859, 2463, 4011, - -673, -31356, -1591, -3048, -1872, 1277, -3806, 8836, 5555, -2031, -11076, -7329, - -2037, -1591, -65556, 42935, -11408, 12166, 751, 8792, 24077, -15804, -2546, -2517, - -885, -3048, 42935, -88483, 42957, -13081, 4776, 14411, 23734, -5735, 15306, 15210, - -236, -1872, -11408, 42957, -90738, 37950, -1795, 4021, -35266, 12445, 13655, 17403, - -667, 1277, 12166, -13081, 37950, -86289, 37943, 3429, -5655, 5664, 8658, -11, - 749, -3806, 751, 4776, -1795, 37943, -77863, -8515, -74265, 22313, 3842, 645, - -1726, 8836, 8792, 14411, 4021, 3429, -8515, -59311, -121235, 1622, -8500, 4967, - -20424, 5555, 24077, 23734, -35266, -5655, -74265, -121235, -5534279, 175865, 247781, -296138, - -859, -2031, -15804, -5735, 12445, 5664, 22313, 1622, 175865, -104343, -1168, 32220, - 2463, -11076, -2546, 15306, 13655, 8658, 3842, -8500, 247781, -1168, -79522, -45571, - 4011, -7329, -2517, 15210, 17403, -11, 645, 4967, -296138, 32220, -45571, -249005, - -10115, 613, -4406, -403, 731, 898, 350, -1995, -8975, -169, -1296, 1233, - 613, -30663, -12425, -1115, -1862, 2906, -2485, 12887, -8842, -12067, 4833, 3070, - -4406, -12425, -86550, 49625, -11519, 15386, -20054, 20873, -13684, 28341, 23152, -807, - -403, -1115, 49625, -131210, 81002, 1045, 3085, 8149, -11887, -3094, 43855, 14533, - 731, -1862, -11519, 81002, -226160, 115669, 9052, -6427, -19605, -20406, 7481, 6064, - 898, 2906, 15386, 1045, 115669, -281745, 150559, -5530, 271, -5717, 1673, 7674, - 350, -2485, -20054, 3085, 9052, 150559, -200735, -21872, -9366, 10471, -2190, 3083, - -1995, 12887, 20873, 8149, -6427, -5530, -21872, -111299, -29613, -27611, -54741, -9432, - -8975, -8842, -13684, -11887, -19605, 271, -9366, -29613, -616730, 74872, 189453, -79618, - -169, -12067, 28341, -3094, -20406, -5717, 10471, -27611, 74872, -359342, -12919, 29609, - -1296, 4833, 23152, 43855, 7481, 1673, -2190, -54741, 189453, -12919, -407670, -16961, - 1233, 3070, -807, 14533, 6064, 7674, 3083, -9432, -79618, 29609, -16961, -180700, - -12411, 5539, -1902, 92, 2813, 339, -114, -1078, -24097, -2938, -1812, 399, - 5539, -36224, -7229, -766, -2442, 2066, -2896, 8507, 16429, -11423, -12067, -191, - -1902, -7230, -115426, 44336, 11635, 13946, -3573, 22728, -73099, 119214, 70165, 4686, - 92, -766, 44336, -187908, 81624, 24838, 12765, 1471, -43322, -24066, 44669, 3543, - 2813, -2442, 11635, 81624, -295220, 104190, 52986, -3246, -146322, -78690, 34365, -2814, - 339, 2066, 13946, 24838, 104190, -347659, 169287, -4458, -127093, -94499, 42989, 5700, - -114, -2896, -3573, 12765, 52986, 169287, -310084, -18605, -27182, -19113, -2714, 11, - -1078, 8507, 22728, 1471, -3246, -4458, -18605, -69283, 40578, -47905, -135760, -6645, - -24097, 16429, -73099, -43322, -146322, -127093, -27182, 40578, -8241631, -71531, 1853193, -175523, - -2938, -11423, 119214, -24066, -78690, -94499, -19113, -47905, -71531, -1361618, -36609, 26675, - -1812, -12067, 70165, 44669, 34365, 42989, -2714, -135760, 1853193, -36609, -1337597, -83909, - 399, -191, 4686, 3543, -2814, 5700, 11, -6645, -175523, 26675, -83909, -223653, - -8809, 3326, -1275, -1509, 1423, 1222, -767, -3923, -65513, -5992, 9965, 3853, - 3326, -31906, -1905, 4114, -4704, 1138, -584, 10709, 104184, 6118, -30358, -5240, - -1275, -1905, -184413, 67973, -17415, 32246, -7121, 16051, -2994, -52989, 23547, 27770, - -1509, 4114, 67973, -160389, 86351, -8947, 13772, 8224, 3480, 2626, 24337, 1870, - 1423, -4704, -17415, 86351, -198772, 68001, 7361, 14025, 11152, 23137, 12598, 9972, - 1222, 1138, 32246, -8947, 68001, -166130, 57911, 17629, 118765, 39472, 1806, 7267, - -767, -584, -7121, 13772, 7361, 57911, -123203, 2059, 47920, 59494, 10484, -5066, - -3923, 10709, 16051, 8224, 14025, 17629, 2059, -90332, -367027, -30259, -20438, -3054, - -65513, 104184, -2994, 3480, 11152, 118765, 47920, -367027, -16854832, -181537, 903929, -95027, - -5992, 6118, -52989, 2626, 23137, 39472, 59494, -30259, -181537, -320917, -11497, 56536, - 9965, -30358, 23547, 24337, 12598, 1806, 10484, -20438, 903929, -11497, -197437, -16106, - 3853, -5240, 27770, 1870, 9972, 7267, -5066, -3054, -95027, 56536, -16106, -107942, - -14599, -2426, -4488, 2252, 20, -696, -2636, 5531, 1097, 109, 1359, 2742, - -2426, -22977, 1326, -4413, -6555, 199, -2249, 16239, 6914, -6267, 1335, -319, - -4488, 1326, -38846, 40605, -16372, -138, 6341, 2358, -5859, 1498, -1344, -3917, - 2252, -4413, 40605, -94592, 69176, -3799, -16812, -5416, -11189, -3107, 2060, -3508, - 20, -6555, -16372, 69176, -121278, 55283, 86, 3716, 11782, -9657, 3416, 549, - -696, 199, -138, -3799, 55283, -105539, 62225, 5299, 3619, 1933, -2511, 609, - -2636, -2249, 6341, -16812, 86, 62225, -79693, -7236, -9729, -2907, 2795, 57, - 5531, 16239, 2358, -5416, 3716, 5299, -7236, -52597, -40766, -5195, 2995, 11158, - 1097, 6914, -5859, -11189, 11782, 3619, -9729, -40766, -95884, 18462, 2795, -18509, - 109, -6267, 1498, -3107, -9657, 1933, -2907, -5195, 18462, -29138, 3027, 17268, - 1359, 1335, -1344, 2060, 3416, -2511, 2795, 2995, 2795, 3027, -10878, -6828, - 2742, -319, -3917, -3508, 549, 609, 57, 11158, -18509, 17268, -6828, -48324, - -9462, 2969, -1087, -1924, 1418, -350, 396, -3124, -35326, 682, 3248, 5848, - 2969, -29148, -2662, 2400, -3059, 2772, 847, 8375, 60040, -6778, -23223, -7694, - -1087, -2662, -172602, 83798, 2597, 33012, 3851, 12397, 81998, -81017, 15831, 35467, - -1924, 2400, 83798, -204141, 66003, 2928, 18028, 14706, 8557, 16030, 44283, 36177, - 1418, -3059, 2597, 66003, -202589, 47215, 19493, 10544, -4664, 46480, 10895, 18165, - -350, 2772, 33012, 2928, 47215, -198011, 76335, 14223, 123301, 70945, 1870, 8265, - 396, 847, 3851, 18028, 19493, 76335, -177594, -5345, 78880, 114804, -171, 3539, - -3124, 8375, 12397, 14706, 10544, 14223, -5345, -67596, -251454, -55035, -21890, 7263, - -35326, 60040, 81998, 8557, -4664, 123301, 78880, -251454, -12784658, -217014, 810245, -725111, - 682, -6778, -81017, 16030, 46480, 70945, 114804, -55035, -217014, -793758, -8106, 74886, - 3248, -23223, 15831, 44283, 10895, 1870, -171, -21890, 810245, -8106, -319630, -77833, - 5848, -7694, 35467, 36177, 18165, 8265, 3539, 7263, -725111, 74886, -77832, -481222 + -7878, -673, -2037, -885, -236, -667, 749, -1726, -20424, -859, 2463, 4011, + -673, -31356, -1591, -3048, -1872, 1277, -3806, 8836, 5555, -2031, -11076, -7329, + -2037, -1591, -65556, 42935, -11408, 12166, 751, 8792, 24077, -15804, -2546, -2517, + -885, -3048, 42935, -88483, 42957, -13081, 4776, 14411, 23734, -5735, 15306, 15210, + -236, -1872, -11408, 42957, -90738, 37950, -1795, 4021, -35266, 12445, 13655, 17403, + -667, 1277, 12166, -13081, 37950, -86289, 37943, 3429, -5655, 5664, 8658, -11, + 749, -3806, 751, 4776, -1795, 37943, -77863, -8515, -74265, 22313, 3842, 645, + -1726, 8836, 8792, 14411, 4021, 3429, -8515, -59311, -121235, 1622, -8500, 4967, + -20424, 5555, 24077, 23734, -35266, -5655, -74265, -121235, -5534279, 175865, 247781, -296138, + -859, -2031, -15804, -5735, 12445, 5664, 22313, 1622, 175865, -104343, -1168, 32220, + 2463, -11076, -2546, 15306, 13655, 8658, 3842, -8500, 247781, -1168, -79522, -45571, + 4011, -7329, -2517, 15210, 17403, -11, 645, 4967, -296138, 32220, -45571, -249005, + -10115, 613, -4406, -403, 731, 898, 350, -1995, -8975, -169, -1296, 1233, + 613, -30663, -12425, -1115, -1862, 2906, -2485, 12887, -8842, -12067, 4833, 3070, + -4406, -12425, -86550, 49625, -11519, 15386, -20054, 20873, -13684, 28341, 23152, -807, + -403, -1115, 49625, -131210, 81002, 1045, 3085, 8149, -11887, -3094, 43855, 14533, + 731, -1862, -11519, 81002, -226160, 115669, 9052, -6427, -19605, -20406, 7481, 6064, + 898, 2906, 15386, 1045, 115669, -281745, 150559, -5530, 271, -5717, 1673, 7674, + 350, -2485, -20054, 3085, 9052, 150559, -200735, -21872, -9366, 10471, -2190, 3083, + -1995, 12887, 20873, 8149, -6427, -5530, -21872, -111299, -29613, -27611, -54741, -9432, + -8975, -8842, -13684, -11887, -19605, 271, -9366, -29613, -616730, 74872, 189453, -79618, + -169, -12067, 28341, -3094, -20406, -5717, 10471, -27611, 74872, -359342, -12919, 29609, + -1296, 4833, 23152, 43855, 7481, 1673, -2190, -54741, 189453, -12919, -407670, -16961, + 1233, 3070, -807, 14533, 6064, 7674, 3083, -9432, -79618, 29609, -16961, -180700, + -12411, 5539, -1902, 92, 2813, 339, -114, -1078, -24097, -2938, -1812, 399, + 5539, -36224, -7229, -766, -2442, 2066, -2896, 8507, 16429, -11423, -12067, -191, + -1902, -7230, -115426, 44336, 11635, 13946, -3573, 22728, -73099, 119214, 70165, 4686, + 92, -766, 44336, -187908, 81624, 24838, 12765, 1471, -43322, -24066, 44669, 3543, + 2813, -2442, 11635, 81624, -295220, 104190, 52986, -3246, -146322, -78690, 34365, -2814, + 339, 2066, 13946, 24838, 104190, -347659, 169287, -4458, -127093, -94499, 42989, 5700, + -114, -2896, -3573, 12765, 52986, 169287, -310084, -18605, -27182, -19113, -2714, 11, + -1078, 8507, 22728, 1471, -3246, -4458, -18605, -69283, 40578, -47905, -135760, -6645, + -24097, 16429, -73099, -43322, -146322, -127093, -27182, 40578, -8241631, -71531, 1853193, -175523, + -2938, -11423, 119214, -24066, -78690, -94499, -19113, -47905, -71531, -1361618, -36609, 26675, + -1812, -12067, 70165, 44669, 34365, 42989, -2714, -135760, 1853193, -36609, -1337597, -83909, + 399, -191, 4686, 3543, -2814, 5700, 11, -6645, -175523, 26675, -83909, -223653, + -8809, 3326, -1275, -1509, 1423, 1222, -767, -3923, -65513, -5992, 9965, 3853, + 3326, -31906, -1905, 4114, -4704, 1138, -584, 10709, 104184, 6118, -30358, -5240, + -1275, -1905, -184413, 67973, -17415, 32246, -7121, 16051, -2994, -52989, 23547, 27770, + -1509, 4114, 67973, -160389, 86351, -8947, 13772, 8224, 3480, 2626, 24337, 1870, + 1423, -4704, -17415, 86351, -198772, 68001, 7361, 14025, 11152, 23137, 12598, 9972, + 1222, 1138, 32246, -8947, 68001, -166130, 57911, 17629, 118765, 39472, 1806, 7267, + -767, -584, -7121, 13772, 7361, 57911, -123203, 2059, 47920, 59494, 10484, -5066, + -3923, 10709, 16051, 8224, 14025, 17629, 2059, -90332, -367027, -30259, -20438, -3054, + -65513, 104184, -2994, 3480, 11152, 118765, 47920, -367027, -16854832, -181537, 903929, -95027, + -5992, 6118, -52989, 2626, 23137, 39472, 59494, -30259, -181537, -320917, -11497, 56536, + 9965, -30358, 23547, 24337, 12598, 1806, 10484, -20438, 903929, -11497, -197437, -16106, + 3853, -5240, 27770, 1870, 9972, 7267, -5066, -3054, -95027, 56536, -16106, -107942, + -14599, -2426, -4488, 2252, 20, -696, -2636, 5531, 1097, 109, 1359, 2742, + -2426, -22977, 1326, -4413, -6555, 199, -2249, 16239, 6914, -6267, 1335, -319, + -4488, 1326, -38846, 40605, -16372, -138, 6341, 2358, -5859, 1498, -1344, -3917, + 2252, -4413, 40605, -94592, 69176, -3799, -16812, -5416, -11189, -3107, 2060, -3508, + 20, -6555, -16372, 69176, -121278, 55283, 86, 3716, 11782, -9657, 3416, 549, + -696, 199, -138, -3799, 55283, -105539, 62225, 5299, 3619, 1933, -2511, 609, + -2636, -2249, 6341, -16812, 86, 62225, -79693, -7236, -9729, -2907, 2795, 57, + 5531, 16239, 2358, -5416, 3716, 5299, -7236, -52597, -40766, -5195, 2995, 11158, + 1097, 6914, -5859, -11189, 11782, 3619, -9729, -40766, -95884, 18462, 2795, -18509, + 109, -6267, 1498, -3107, -9657, 1933, -2907, -5195, 18462, -29138, 3027, 17268, + 1359, 1335, -1344, 2060, 3416, -2511, 2795, 2995, 2795, 3027, -10878, -6828, + 2742, -319, -3917, -3508, 549, 609, 57, 11158, -18509, 17268, -6828, -48324, + -9462, 2969, -1087, -1924, 1418, -350, 396, -3124, -35326, 682, 3248, 5848, + 2969, -29148, -2662, 2400, -3059, 2772, 847, 8375, 60040, -6778, -23223, -7694, + -1087, -2662, -172602, 83798, 2597, 33012, 3851, 12397, 81998, -81017, 15831, 35467, + -1924, 2400, 83798, -204141, 66003, 2928, 18028, 14706, 8557, 16030, 44283, 36177, + 1418, -3059, 2597, 66003, -202589, 47215, 19493, 10544, -4664, 46480, 10895, 18165, + -350, 2772, 33012, 2928, 47215, -198011, 76335, 14223, 123301, 70945, 1870, 8265, + 396, 847, 3851, 18028, 19493, 76335, -177594, -5345, 78880, 114804, -171, 3539, + -3124, 8375, 12397, 14706, 10544, 14223, -5345, -67596, -251454, -55035, -21890, 7263, + -35326, 60040, 81998, 8557, -4664, 123301, 78880, -251454, -12784658, -217014, 810245, -725111, + 682, -6778, -81017, 16030, 46480, 70945, 114804, -55035, -217014, -793758, -8106, 74886, + 3248, -23223, 15831, 44283, 10895, 1870, -171, -21890, 810245, -8106, -319630, -77833, + 5848, -7694, 35467, 36177, 18165, 8265, 3539, 7263, -725111, 74886, -77832, -481222 }; const Word32 lvm_music_fx[N_MIXTURES] = { /*Q10*/ - 28603, 31076, 35357, 31989, 20938, 34395 + 28603, 31076, 35357, 31989, 20938, 34395 }; const Word16 m_noise_fx[N_MIXTURES*N_FEATURES] = { /*Q15*/ - 14825, 18681, 7930, 11230, 13228, 13602, 14556, 14377, 1133, 29263, 26842, 13270, - 14312, 14992, 9378, 12891, 14075, 14581, 15548, 12386, 1050, 32143, 28322, 12379, - 18179, 16617, 8015, 13153, 13932, 14462, 15329, 11848, 1033, 31841, 28406, 12222, - 15822, 17883, 3231, 8086, 9983, 9933, 11537, 11904, 1018, 29549, 27473, 11111, - 13821, 16109, 8734, 12035, 13351, 13603, 15024, 12957, 1163, 31179, 28243, 11865, - 13845, 15577, 10545, 14292, 15353, 15784, 16567, 12750, 1589, 31695, 28796, 13420 + 14825, 18681, 7930, 11230, 13228, 13602, 14556, 14377, 1133, 29263, 26842, 13270, + 14312, 14992, 9378, 12891, 14075, 14581, 15548, 12386, 1050, 32143, 28322, 12379, + 18179, 16617, 8015, 13153, 13932, 14462, 15329, 11848, 1033, 31841, 28406, 12222, + 15822, 17883, 3231, 8086, 9983, 9933, 11537, 11904, 1018, 29549, 27473, 11111, + 13821, 16109, 8734, 12035, 13351, 13603, 15024, 12957, 1163, 31179, 28243, 11865, + 13845, 15577, 10545, 14292, 15353, 15784, 16567, 12750, 1589, 31695, 28796, 13420 }; const Word32 invV_noise_fx[N_MIXTURES*N_FEATURES*N_FEATURES] = { /*Q10*/ - -11129, -775, -807, 4750, -4310, -1632, 1694, 530, -25134, -2399, 1632, 1938, - -775, -43700, -5296, -23144, -4086, -2008, 9445, 12956, 17119, 10623, -18169, -14373, - -807, -5296, -117924, 78859, -23526, 22681, -7637, 52382, 20661, -1131, 18004, -18669, - 4750, -23144, 78859, -165973, 70704, -954, 10160, 6713, 50481, 19307, -10190, 16924, - -4310, -4086, -23526, 70704, -186160, 114906, -28994, 9999, 17677, -18372, -20805, -12577, - -1632, -2008, 22681, -954, 114906, -235840, 123708, -3753, 21616, 9200, 15641, -10616, - 1694, 9445, -7637, 10160, -28994, 123708, -156081, -1564, -7627, 5159, 14184, -12573, - 530, 12956, 52382, 6713, 9999, -3753, -1564, -116541, -130257, -2892, -51260, -1433, - -25134, 17119, 20661, 50481, 17677, 21616, -7627, -130257, -6857531, -23164, 425725, -172307, - -2399, 10623, -1131, 19307, -18372, 9200, 5159, -2892, -23164, -157605, 9307, 20639, - 1632, -18169, 18004, -10190, -20805, 15641, 14184, -51260, 425725, 9307, -184817, -2232, - 1938, -14373, -18669, 16924, -12577, -10616, -12573, -1433, -172307, 20639, -2232, -94498, - -23585, -1283, 2220, 5814, -1063, -5524, 5040, -408, -7744, 65700, -4948, 1221, - -1283, -102238, 18435, -18156, -6216, 17104, -1870, 25097, 97427, 32242, -77595, -4567, - 2220, 18435, -305438, 139861, 24123, 32851, -45614, 45538, 124040, 301172, -22649, 3625, - 5814, -18156, 139861, -565373, 242575, 46852, 50718, -18774, -159188, 141029, 89911, 9768, - -1063, -6216, 24123, 242575, -798475, 256535, 104095, 9375, -84525, -408528, 98204, 4495, - -5524, 17104, 32851, 46852, 256535, -845586, 312678, -6990, 50242, -543393, -42629, 99, - 5040, -1870, -45614, 50718, 104095, 312678, -732093, 14409, 83177, -140864, -2169, -2321, - -408, 25097, 45538, -18774, 9375, -6990, 14409, -314037, 273543, -30059, -253352, -3462, - -7744, 97427, 124040, -159188, -84525, 50242, 83177, 273543, -19301626, -952154, 3668367, -93870, - 65700, 32242, 301172, 141029, -408528, -543393, -140864, -30059, -952154, -16033274, -164405, -24189, - -4948, -77595, -22649, 89911, 98204, -42629, -2169, -253352, 3668367, -164405, -2501887, -105127, - 1221, -4567, 3625, 9768, 4495, 99, -2321, -3462, -93870, -24189, -105127, -252171, - -11556, 5444, 1053, 1823, -1754, -6509, 3535, -483, 5751, 22898, -4369, 2503, - 5444, -61418, -46603, 523, -4221, 5377, -14703, 2336, 4414, 4601, 17795, 5358, - 1053, -46603, -197022, 61944, 30015, 11139, -14163, 4583, 14704, 174734, 105587, 3797, - 1823, 523, 61944, -579713, 310766, -24876, -8601, -1522, -38055, -308764, 10254, 11526, - -1754, -4221, 30015, 310766, -873205, 294102, 7806, 2338, -28081, -507955, -5526, -1671, - -6509, 5377, 11139, -24876, 294102, -740664, 309186, -19342, -50840, -143800, 27527, 4324, - 3535, -14703, -14163, -8601, 7806, 309186, -508227, 24986, 208442, -230010, -48336, -9651, - -483, 2336, 4583, -1522, 2338, -19342, 24986, -362502, 140055, -118693, -134546, 982, - 5751, 4414, 14704, -38055, -28081, -50840, 208442, 140055, -20820834, -328791, 3081671, -99923, - 22898, 4601, 174734, -308764, -507955, -143800, -230010, -118693, -328791, -7236926, -225976, -47887, - -4369, 17795, 105587, 10254, -5526, 27527, -48336, -134546, 3081671, -225976, -2500626, -124929, - 2503, 5358, 3797, 11526, -1671, 4324, -9651, 982, -99923, -47887, -124929, -277469, - -14533, 3263, -8141, 13301, 5586, 1808, -5289, 472, 7371, -21379, -2460, 596, - 3263, -46002, -56596, 9198, -765, 13994, 5247, 2629, -14758, -21574, 5644, 3817, - -8141, -56596, -895669, 406276, -247505, 72418, -246462, 32532, -190899, -74267, 59747, 10271, - 13301, 9198, 406276, -551172, 137309, 34772, -5367, 41269, 67372, 262339, 42457, 60892, - 5586, -765, -247505, 137309, -964866, 393695, 36960, 5148, 114354, 66434, -19640, 18501, - 1808, 13994, 72418, 34772, 393695, -906317, 366933, 14058, 76374, 284422, 16253, 32973, - -5289, 5247, -246462, -5367, 36960, 366933, -711303, 23465, 84856, 157990, 2319, 21580, - 472, 2629, 32532, 41269, 5148, 14058, 23465, -349612, -74011, -89655, -17686, 7616, - 7371, -14758, -190899, 67372, 114354, 76374, 84856, -74011, -17027780, -264311, 396822, -266476, - -21379, -21574, -74267, 262339, 66434, 284422, 157990, -89655, -264311, -871539, 3553, 2308, - -2460, 5644, 59747, 42457, -19640, 16253, 2319, -17686, 396822, 3553, -334956, -46272, - 596, 3817, 10271, 60892, 18501, 32973, 21580, 7616, -266476, 2308, -46272, -357254, - -21040, -1263, -6696, 8169, -1272, -4427, 4142, -8459, -63196, -17218, 710, 2270, - -1263, -83196, -34319, -27267, 2213, -240, -783, 22287, 136898, 9589, -27942, -6781, - -6696, -34319, -329281, 107754, 677, -33332, -46218, 43055, -204958, -43031, 204918, 20438, - 8169, -27267, 107754, -371373, 103141, 10674, 46337, -3299, -65216, -42038, -5280, 13005, - -1272, 2213, 677, 103141, -420124, 194457, 1575, 22157, -26994, 36729, 47504, 13852, - -4427, -240, -33332, 10674, 194457, -368592, 152851, 14172, 107043, 44274, -23917, -8922, - 4142, -783, -46218, 46337, 1575, 152851, -280668, -8210, 40158, 24389, 13385, 8410, - -8459, 22287, 43055, -3299, 22157, 14172, -8210, -256064, 79772, -1255, -101174, 759, - -63196, 136898, -204958, -65216, -26994, 107043, 40158, 79772, -13100212, 263557, 2000831, -242675, - -17218, 9589, -43031, -42038, 36729, 44274, 24389, -1255, 263557, -1223057, -216580, -23199, - 710, -27942, 204918, -5280, 47504, -23917, 13385, -101174, 2000831, -216580, -1303910, -90175, - 2270, -6781, 20438, 13005, 13852, -8922, 8410, 759, -242675, -23199, -90175, -372746, - -24335, -321, -1426, 1524, 1959, -4164, 7012, -3148, -7859, 9391, 3193, 2194, - -321, -90890, -9068, -27277, 5303, 10922, 2298, 22512, 17201, 4798, 13388, -2773, - -1426, -9068, -180137, 85478, 42242, 14714, -12908, 34197, 67246, 40663, 36965, -9792, - 1524, -27277, 85478, -392290, 221884, 12492, 33161, -14359, 7950, -103145, -29210, -5361, - 1959, 5303, 42242, 221884, -600963, 259592, 30301, 7895, -32577, -115360, 20766, -7273, - -4164, 10922, 14714, 12492, 259592, -611459, 304095, 6323, -42968, -37072, -21092, -15235, - 7012, 2298, -12908, 33161, 30301, 304095, -467758, 26953, -35709, 29107, 35819, -8754, - -3148, 22512, 34197, -14359, 7895, 6323, 26953, -271919, 2988, 852, -128460, -11407, - -7859, 17201, 67246, 7950, -32577, -42968, -35709, 2988, -1773460, -215853, 756954, -99883, - 9391, 4798, 40663, -103145, -115360, -37072, 29107, 852, -215853, -2382074, -108833, 1061, - 3193, 13388, 36965, -29210, 20766, -21092, 35819, -128460, 756954, -108833, -1923617, -116204, - 2194, -2773, -9792, -5361, -7273, -15235, -8754, -11407, -99883, 1061, -116204, -103840 + -11129, -775, -807, 4750, -4310, -1632, 1694, 530, -25134, -2399, 1632, 1938, + -775, -43700, -5296, -23144, -4086, -2008, 9445, 12956, 17119, 10623, -18169, -14373, + -807, -5296, -117924, 78859, -23526, 22681, -7637, 52382, 20661, -1131, 18004, -18669, + 4750, -23144, 78859, -165973, 70704, -954, 10160, 6713, 50481, 19307, -10190, 16924, + -4310, -4086, -23526, 70704, -186160, 114906, -28994, 9999, 17677, -18372, -20805, -12577, + -1632, -2008, 22681, -954, 114906, -235840, 123708, -3753, 21616, 9200, 15641, -10616, + 1694, 9445, -7637, 10160, -28994, 123708, -156081, -1564, -7627, 5159, 14184, -12573, + 530, 12956, 52382, 6713, 9999, -3753, -1564, -116541, -130257, -2892, -51260, -1433, + -25134, 17119, 20661, 50481, 17677, 21616, -7627, -130257, -6857531, -23164, 425725, -172307, + -2399, 10623, -1131, 19307, -18372, 9200, 5159, -2892, -23164, -157605, 9307, 20639, + 1632, -18169, 18004, -10190, -20805, 15641, 14184, -51260, 425725, 9307, -184817, -2232, + 1938, -14373, -18669, 16924, -12577, -10616, -12573, -1433, -172307, 20639, -2232, -94498, + -23585, -1283, 2220, 5814, -1063, -5524, 5040, -408, -7744, 65700, -4948, 1221, + -1283, -102238, 18435, -18156, -6216, 17104, -1870, 25097, 97427, 32242, -77595, -4567, + 2220, 18435, -305438, 139861, 24123, 32851, -45614, 45538, 124040, 301172, -22649, 3625, + 5814, -18156, 139861, -565373, 242575, 46852, 50718, -18774, -159188, 141029, 89911, 9768, + -1063, -6216, 24123, 242575, -798475, 256535, 104095, 9375, -84525, -408528, 98204, 4495, + -5524, 17104, 32851, 46852, 256535, -845586, 312678, -6990, 50242, -543393, -42629, 99, + 5040, -1870, -45614, 50718, 104095, 312678, -732093, 14409, 83177, -140864, -2169, -2321, + -408, 25097, 45538, -18774, 9375, -6990, 14409, -314037, 273543, -30059, -253352, -3462, + -7744, 97427, 124040, -159188, -84525, 50242, 83177, 273543, -19301626, -952154, 3668367, -93870, + 65700, 32242, 301172, 141029, -408528, -543393, -140864, -30059, -952154, -16033274, -164405, -24189, + -4948, -77595, -22649, 89911, 98204, -42629, -2169, -253352, 3668367, -164405, -2501887, -105127, + 1221, -4567, 3625, 9768, 4495, 99, -2321, -3462, -93870, -24189, -105127, -252171, + -11556, 5444, 1053, 1823, -1754, -6509, 3535, -483, 5751, 22898, -4369, 2503, + 5444, -61418, -46603, 523, -4221, 5377, -14703, 2336, 4414, 4601, 17795, 5358, + 1053, -46603, -197022, 61944, 30015, 11139, -14163, 4583, 14704, 174734, 105587, 3797, + 1823, 523, 61944, -579713, 310766, -24876, -8601, -1522, -38055, -308764, 10254, 11526, + -1754, -4221, 30015, 310766, -873205, 294102, 7806, 2338, -28081, -507955, -5526, -1671, + -6509, 5377, 11139, -24876, 294102, -740664, 309186, -19342, -50840, -143800, 27527, 4324, + 3535, -14703, -14163, -8601, 7806, 309186, -508227, 24986, 208442, -230010, -48336, -9651, + -483, 2336, 4583, -1522, 2338, -19342, 24986, -362502, 140055, -118693, -134546, 982, + 5751, 4414, 14704, -38055, -28081, -50840, 208442, 140055, -20820834, -328791, 3081671, -99923, + 22898, 4601, 174734, -308764, -507955, -143800, -230010, -118693, -328791, -7236926, -225976, -47887, + -4369, 17795, 105587, 10254, -5526, 27527, -48336, -134546, 3081671, -225976, -2500626, -124929, + 2503, 5358, 3797, 11526, -1671, 4324, -9651, 982, -99923, -47887, -124929, -277469, + -14533, 3263, -8141, 13301, 5586, 1808, -5289, 472, 7371, -21379, -2460, 596, + 3263, -46002, -56596, 9198, -765, 13994, 5247, 2629, -14758, -21574, 5644, 3817, + -8141, -56596, -895669, 406276, -247505, 72418, -246462, 32532, -190899, -74267, 59747, 10271, + 13301, 9198, 406276, -551172, 137309, 34772, -5367, 41269, 67372, 262339, 42457, 60892, + 5586, -765, -247505, 137309, -964866, 393695, 36960, 5148, 114354, 66434, -19640, 18501, + 1808, 13994, 72418, 34772, 393695, -906317, 366933, 14058, 76374, 284422, 16253, 32973, + -5289, 5247, -246462, -5367, 36960, 366933, -711303, 23465, 84856, 157990, 2319, 21580, + 472, 2629, 32532, 41269, 5148, 14058, 23465, -349612, -74011, -89655, -17686, 7616, + 7371, -14758, -190899, 67372, 114354, 76374, 84856, -74011, -17027780, -264311, 396822, -266476, + -21379, -21574, -74267, 262339, 66434, 284422, 157990, -89655, -264311, -871539, 3553, 2308, + -2460, 5644, 59747, 42457, -19640, 16253, 2319, -17686, 396822, 3553, -334956, -46272, + 596, 3817, 10271, 60892, 18501, 32973, 21580, 7616, -266476, 2308, -46272, -357254, + -21040, -1263, -6696, 8169, -1272, -4427, 4142, -8459, -63196, -17218, 710, 2270, + -1263, -83196, -34319, -27267, 2213, -240, -783, 22287, 136898, 9589, -27942, -6781, + -6696, -34319, -329281, 107754, 677, -33332, -46218, 43055, -204958, -43031, 204918, 20438, + 8169, -27267, 107754, -371373, 103141, 10674, 46337, -3299, -65216, -42038, -5280, 13005, + -1272, 2213, 677, 103141, -420124, 194457, 1575, 22157, -26994, 36729, 47504, 13852, + -4427, -240, -33332, 10674, 194457, -368592, 152851, 14172, 107043, 44274, -23917, -8922, + 4142, -783, -46218, 46337, 1575, 152851, -280668, -8210, 40158, 24389, 13385, 8410, + -8459, 22287, 43055, -3299, 22157, 14172, -8210, -256064, 79772, -1255, -101174, 759, + -63196, 136898, -204958, -65216, -26994, 107043, 40158, 79772, -13100212, 263557, 2000831, -242675, + -17218, 9589, -43031, -42038, 36729, 44274, 24389, -1255, 263557, -1223057, -216580, -23199, + 710, -27942, 204918, -5280, 47504, -23917, 13385, -101174, 2000831, -216580, -1303910, -90175, + 2270, -6781, 20438, 13005, 13852, -8922, 8410, 759, -242675, -23199, -90175, -372746, + -24335, -321, -1426, 1524, 1959, -4164, 7012, -3148, -7859, 9391, 3193, 2194, + -321, -90890, -9068, -27277, 5303, 10922, 2298, 22512, 17201, 4798, 13388, -2773, + -1426, -9068, -180137, 85478, 42242, 14714, -12908, 34197, 67246, 40663, 36965, -9792, + 1524, -27277, 85478, -392290, 221884, 12492, 33161, -14359, 7950, -103145, -29210, -5361, + 1959, 5303, 42242, 221884, -600963, 259592, 30301, 7895, -32577, -115360, 20766, -7273, + -4164, 10922, 14714, 12492, 259592, -611459, 304095, 6323, -42968, -37072, -21092, -15235, + 7012, 2298, -12908, 33161, 30301, 304095, -467758, 26953, -35709, 29107, 35819, -8754, + -3148, 22512, 34197, -14359, 7895, 6323, 26953, -271919, 2988, 852, -128460, -11407, + -7859, 17201, 67246, 7950, -32577, -42968, -35709, 2988, -1773460, -215853, 756954, -99883, + 9391, 4798, 40663, -103145, -115360, -37072, 29107, 852, -215853, -2382074, -108833, 1061, + 3193, 13388, 36965, -29210, 20766, -21092, 35819, -128460, 756954, -108833, -1923617, -116204, + 2194, -2773, -9792, -5361, -7273, -15235, -8754, -11407, -99883, 1061, -116204, -103840 }; const Word32 lvm_noise_fx[N_MIXTURES] = { /*Q10*/ - 29413, 42169, 40240, 39433, 37918, 36348 + 29413, 42169, 40240, 39433, 37918, 36348 }; /* Mel filterbank */ const Word16 mel_fb_start[NB_MEL_BANDS] = { 1, 1, 2, 3, 4, 5, 5, 7, 8, 9, 10, 11, 13, 14, 16, 17, 19, 21, 23, 25, 28, 30, 33, 35, 38, 41, 45, 48, 52, 56, 60, 65, 69, 74, 80, 86, 92, 98, 105, 112 -}; // Q0 +}; // Q0 const Word16 mel_fb_len[NB_MEL_BANDS] = { 1, 2, 2, 2, 1, 2, 3, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 11, 12, 12, 12, 13, 14, 15, 16 -}; // Q0 +}; // Q0 const Word32 mel_fb_fx[246] = { 1306887040, 840596608, 701826176, 1445657472, 297866656, 1849617024, 67613584, 2079870080, @@ -855,7 +855,7 @@ const Word32 mel_fb_fx[246] = 1556051584, 1278092800, 1002327744, 728722176, 457242624, 187856208, 28791110, 311244128, 591432000, 869390912, 1145155968, 1418761472, 1690241024, 1959627392, 2068014592, 1802719104, 1539422848, 1278095872, 1018709056, 761233728, 505641920, 251906256, -}; // Q30 +}; // Q30 const Word32 dct_mtx_fx[NB_MEL_BANDS * NB_MEL_COEF] = { //Q31 479821728, 476863456, 470965184, 462163232, 450511904, 436083040, 418965536, 399264992, @@ -977,56 +977,56 @@ const Word16 huffnorm_e[32] = 1062, 550, 314, 274, 273, 272, 156, 79, 69, 38, 18, 40, 5, 3, 0, 1, 3, 4, 11, 21, 41, 32, 35, 67, 133, 264, 530, 315, 551, 2126, 4254, 4255 -}; // Q0 +}; // Q0 const Word16 huffnorm_n[32] = { 14831, 14830, 7414, 3706, 593, 927, 462, 297, 230, 116, 50, 36, 13, 8, 5, 1, 0, 2, 6, 7, 15, 19, 24, 56, 59, 51, 114, 117, 75, 149, 592, 1852 -}; // Q0 +}; // Q0 const Word16 huffsizn_e[32] = { 13, 12, 11, 11, 11, 11, 10, 9, 9, 8, 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, 6, 8, 8, 9, 10, 11, 12, 11, 12, 14, 15, 15 -}; // Q0 +}; // Q0 const Word16 huffsizn_n[32] = { 14, 14, 13, 12, 10, 10, 9, 9, 8, 7, 7, 6, 5, 4, 3, 3, 3, 3, 3, 4, 4, 5, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11 -}; // Q0 +}; // Q0 const Word16 resize_huffnorm[32] = { 0, 0, 0, 0, 0, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, 2, 5, 11, 23, 47, 95, 191, 383, 767, 2047, 0, 0, 0, 0, 0, 0 -}; // Q0 +}; // Q0 const Word16 huffnorm[32] = { 26, 58, 90, 122, 27, 59, 91, 123, 12, 28, 44, 60, 2, 6, 4, 6, 0, 2, 10, 14, 14, 30, 46, 62, 30, 62, 94, 126, 31, 63, 95, 127 -}; // Q0 +}; // Q0 const Word16 pgain_huffnorm[32] = { 1, 1, 2, 3, 3, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 3, 2, 3, 3, 4, 5, 0, 1 -}; // Q0 +}; // Q0 const Word16 hessize[8]= { 7, 5, 3, 2, 1, 4, 6, 7 -}; // Q0 +}; // Q0 const Word16 hescode[8]= { 11, 3, 1, 1, 1, 0, 4, 10 -}; // Q0 +}; // Q0 /*----------------------------------------------------------------------------------* * BWD @@ -1053,15 +1053,15 @@ const Word16 hann_window_320_fx[BWD_TOTAL_WIDTH / 2] = 7761, 7796, 7830, 7863, 7894, 7923, 7951, 7978, 8003, 8026, 8048, 8068, 8087, 8105, 8121, 8135, 8147, 8158, 8168, 8176, 8182, 8187, 8190, 8192 -}; // Q13 +}; // Q13 /*----------------------------------------------------------------------------------* * Starting line for the noise measurement in TCX. *----------------------------------------------------------------------------------*/ -const Word16 startLineWB[N_TCX_STARTLINE_NOISE_WB] = { 8, 23, 36, 45, 66, 128 /* 13.2kbps */, 200, 320, 320, 320 /* 48kbps */, 320 }; // Q0 +const Word16 startLineWB[N_TCX_STARTLINE_NOISE_WB] = { 8, 23, 36, 45, 66, 128 /* 13.2kbps */, 200, 320, 320, 320 /* 48kbps */, 320 }; // Q0 -const Word16 startLineSWB[N_TCX_STARTLINE_NOISE_SWB] = { 8, 44, 96 /* 13.2kbps */, 160, 320, 320, 256 /* 48kbps */, 341, 640 }; // Q0 +const Word16 startLineSWB[N_TCX_STARTLINE_NOISE_SWB] = { 8, 44, 96 /* 13.2kbps */, 160, 320, 320, 256 /* 48kbps */, 341, 640 }; // Q0 const Word32 LS_MIN_SILENCE_SNR[4] = { 251658233/* 7.5 Q25 */, 251658233/* 7.5 Q25 */, 228170137/* 6.8 Q25 */,228170137/* 6.8 Q25 */ }; @@ -1081,7 +1081,7 @@ const UWord8 E_ROM_tipos[40] = 3, 0, 1, 2, 0, 1, 2, 3, /* end point for 24 pulses &ipos[35], 4th iter */ 1, 2, 3, 0 /* end point for 36 pulses &ipos[39], 2nd iter */ -}; // Q0 +}; // Q0 /* pow(3 * i + 1, 0.3) / pow(256 - 1, 0.3) */ const Word16 Weight[86] = @@ -1094,7 +1094,7 @@ const Word16 Weight[86] = 0x7D61, 0x7DDA, 0x7E51, 0x7EC8, 0x7F3E, 0x7FB3, 0x7FFF }; -const Word16 BAND_SCALE_AJ[5] = { 3,3,5,6,6 }; /* {OFFSET, NB, WB, SWB, FB} Q0*/ +const Word16 BAND_SCALE_AJ[5] = { 3,3,5,6,6 }; /* {OFFSET, NB, WB, SWB, FB} Q0*/ /* Inv possible delta used in gaus_enc (1.0/(1.0+delta*delta)) and delta = [1,7] */ const Word16 inv_delta_tab[7] = /*Q15*/ diff --git a/lib_enc/rst_enc_fx.c b/lib_enc/rst_enc_fx.c index bbe32afb3605d7333c807144bbbacfb9a60a7e22..38b8e5ff29966b43c61531758a39f470886ffce4 100644 --- a/lib_enc/rst_enc_fx.c +++ b/lib_enc/rst_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -42,7 +42,6 @@ void CNG_reset_enc_fx( set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); hLPDmem->dm_fx.prev_state = 0; - // PMTE() move16(); /* last good received frame for FEC in ACELP */ diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index 5fd11bd31bff4f5ac2e3749167a4cd28e0ee8446..c7420e8ba57a92c6de77e382d28b6e4059eedbe1 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" /* Compilation switches */ @@ -25,7 +25,7 @@ void Scale_wsp( Word16 *old_wsp, /* i/o: Old weighted speech buffer */ Word16 *mem_decim2, /* i/o: Decimation buffer */ Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ - const Word16 Len_p_look /* i : L_frame + look ahead Q0*/ + const Word16 Len_p_look /* i : L_frame + look ahead Q0*/ ) { Word16 max, i, tmp; @@ -72,17 +72,17 @@ void Scale_wsp( * Find scaled preemphasis vector and its scaling factor *-------------------------------------------------------------------*/ void Preemph_scaled( - Word16 new_speech[], /* i : Speech to scale already on 14 bits Q_new*/ - Word16 *Q_new, /* o : Scaling factor */ - Word16 *mem_preemph, /* i/o: Preemph memory Q(-1)*/ - Word16 *Q_max, /* i/o: Q_new limitation */ - const Word16 Preemph_factor, /* i : Preemphasis factor Q15*/ - const Word16 bits, /* i : Bit to remove from the output to (15-bits) */ - const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ - const Word16 L_Q_mem, /* i : Number of old scaling to take into account Q0*/ - const Word16 Lframe, /* i : Frame length Q0*/ - const Word16 last_coder_type, /* i : coder_type Q0*/ - const Word16 Search_scaling /* i : enable the search of a proper scaling factor Q0*/ + Word16 new_speech[], /* i : Speech to scale already on 14 bits Q_new*/ + Word16 *Q_new, /* o : Scaling factor */ + Word16 *mem_preemph, /* i/o: Preemph memory Q(-1)*/ + Word16 *Q_max, /* i/o: Q_new limitation */ + const Word16 Preemph_factor, /* i : Preemphasis factor Q15*/ + const Word16 bits, /* i : Bit to remove from the output to (15-bits) */ + const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ + const Word16 L_Q_mem, /* i : Number of old scaling to take into account Q0*/ + const Word16 Lframe, /* i : Frame length Q0*/ + const Word16 last_coder_type, /* i : coder_type Q0*/ + const Word16 Search_scaling /* i : enable the search of a proper scaling factor Q0*/ ) { Word16 i, tmp_fixed; diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index 68dc2038ea38dd93e3680312453c32b8858a48a0..3ee47938446f08090fed1158c832946d166eadb6 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -52,14 +52,14 @@ static void convolve_tc2_fx( const Word16 g[], const Word16 h[], Word16 y[], con * * *---------------------------------------------------------------------------------------*/ void set_impulse_fx( - const Word16 xn_fx[], /* i : target signal Q_new-1+shift*/ - const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter Q(14+shift)*/ - Word16 exc_fx[], /* o : adaptive codebook excitation Q_new*/ - Word16 yy1_fx[], /* o : filtered adaptive codebook excitation Q_new*/ - Word16 *imp_shape, /* o : adaptive codebook index Q0*/ - Word16 *imp_pos, /* o : position of the glottal impulse center index Q0*/ - Word32 *gain_trans_fx, /* o : transition gain Q7*/ - Word16 Q_new /* i : Current scaling */ + const Word16 xn_fx[], /* i : target signal Q_new-1+shift*/ + const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter Q(14+shift)*/ + Word16 exc_fx[], /* o : adaptive codebook excitation Q_new*/ + Word16 yy1_fx[], /* o : filtered adaptive codebook excitation Q_new*/ + Word16 *imp_shape, /* o : adaptive codebook index Q0*/ + Word16 *imp_pos, /* o : position of the glottal impulse center index Q0*/ + Word32 *gain_trans_fx, /* o : transition gain Q7*/ + Word16 Q_new /* i : Current scaling */ ) { Word16 i, j, m; @@ -333,12 +333,12 @@ static void convolve_tc2_fx( * correlation for different vectors' lengths *-------------------------------------------------------------------*/ static void correlate_tc_fx( - const Word16 *x, /* i: target signal Qx*/ - Word16 *y, /* o: correlation between x[] and h[] -Q3*/ - const Word16 *h, /* i: impulse response (of weighted synthesis filter) Q15*/ - const Word16 start, /* i: index of iterest Q0*/ - const Word16 L_1, /* i: vector size Q0*/ - const Word16 L_2 /* i: index of interest Q0*/ + const Word16 *x, /* i: target signal Qx*/ + Word16 *y, /* o: correlation between x[] and h[] -Q3*/ + const Word16 *h, /* i: impulse response (of weighted synthesis filter) Q15*/ + const Word16 start, /* i: index of iterest Q0*/ + const Word16 L_1, /* i: vector size Q0*/ + const Word16 L_2 /* i: index of interest Q0*/ ) { Word16 i, j; diff --git a/lib_enc/setmodeindex_fx.c b/lib_enc/setmodeindex_fx.c index c1d52bbc7bb25f03d59a095455d15d674b030d87..6c34efb0f914e00a1d8ba810db6c4ab1fba7a964 100644 --- a/lib_enc/setmodeindex_fx.c +++ b/lib_enc/setmodeindex_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 78caad798f008b29eaa213f9f11c55fe575f3713..86ba906eb89ef255eb7bf32f6c996e7782b1c1d4 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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,10 +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 BASOP_NOGLOB_DECLARE_LOCAL + Word64 tmp64; Flag Overflow = 0; move32(); -#endif /*----------------------------------------------------------------* * Calculate average voicing @@ -71,266 +71,59 @@ 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 ) - { - 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 */ - Ltmp = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME; i++ ) - { - tmp16 = add( 1, tmpS ); - pt1++; - tmpS = shr( *pt1, 15 ); /* pt1 >=0 ---> 0 OTHERWISE -1 */ - Ltmp = L_msu0( Ltmp, tmpS, tmp16 ); - } - zc = extract_l( Ltmp ); - - /* compute pitch stability */ - 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 - *-----------------------------------------------------------------*/ - - /* corn = K_COR * mean_voi2 + C_COR */ - Ltmp = L_mult( C_COR_FX, 32767 ); - corn = round_fx( L_shl( L_mac( Ltmp, mean_voi2, K_COR_FX ), -4 ) ); /*Q13+Q13*Q15 =>Q13->Q9*/ - /* Limit [0, 1] */ - corn = s_max( corn, 0 ); - corn = s_min( corn, 512 ); - - Ltmp = L_mult( C_ZC_FX, 4 ); /*Q13*Q2 -> Q16*/ - zcn = round_fx( L_shl( L_mac( Ltmp, zc, K_ZC_FX ), 16 - 7 ) ); /*Q0*Q15 + Q16*/ - /* Limit [0, 1] */ - zcn = s_max( zcn, 0 ); - zcn = s_min( zcn, 512 ); - - Ltmp = L_mult( C_RELE_FX, 256 ); /*Q15*Q8 ->Q24*/ - relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/ - /* Limit [0.5, 1] */ - relEn = s_max( relEn, 256 ); - relEn = s_min( relEn, 512 ); - - Ltmp = L_mult( C_PC_FX, 2 ); /*Q14*Q1 -> Q16*/ - pcn = round_fx( L_shl( L_mac( Ltmp, pc, K_PC_FX ), 16 - 7 ) ); /*Q16 + Q0*Q15*/ - /* Limit [0, 1] */ - pcn = s_max( pcn, 0 ); - pcn = s_min( pcn, 512 ); - - Ltmp = L_mult( een, 10923 ); - Ltmp = L_mac( Ltmp, corn, 21845 ); - Ltmp = L_mac( Ltmp, zcn, 10923 ); - Ltmp = L_mac( Ltmp, relEn, 10923 ); - Ltmp = L_mac( Ltmp, pcn, 10923 ); - - fmerit1 = round_fx_o( L_shl_o( Ltmp, 16 - 10 - 1, &Overflow ), &Overflow ); /* fmerit1 ->Q15 */ - - /*-----------------------------------------------------------------* - * FEC classification - *-----------------------------------------------------------------*/ - - st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); /*Q15*/ - move16(); - st->prev_fmerit = fmerit1; - move16(); - - /* FEC classification */ - test(); - test(); - IF( st->localVAD == 0 || EQ_16( st->coder_type, UNVOICED ) || LT_16( relE, -1536 ) ) - { - clas = UNVOICED_CLAS; - *clas_mod = clas; - move16(); - move16(); - } - ELSE + IF( st->element_mode != EVS_MONO ) { - SWITCH( st->last_clas ) + 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 ) ) { - case VOICED_CLAS: - case ONSET: - case VOICED_TRANSITION: - - IF( LT_16( fmerit1, 16056 ) ) /*0.49f*/ - { - clas = UNVOICED_CLAS; - move16(); - } - ELSE IF( LT_16( fmerit1, 21626 ) ) /*0.66*/ - { - clas = VOICED_TRANSITION; - move16(); - } - ELSE - { - clas = VOICED_CLAS; - move16(); - } - IF( LT_16( fmerit1, 14745 /* 0.45f*/ ) ) - { - *clas_mod = UNVOICED_CLAS; - move16(); - } - ELSE IF( LT_16( fmerit1, 21626 /* 0.66f*/ ) ) - { - *clas_mod = VOICED_TRANSITION; - move16(); - } - ELSE - { - *clas_mod = VOICED_CLAS; - move16(); - } - BREAK; - - case UNVOICED_CLAS: - case UNVOICED_TRANSITION: - IF( GT_16( fmerit1, 20643 ) ) /*0.63*/ - { - clas = ONSET; - move16(); - } - ELSE IF( GT_16( fmerit1, 19169 ) ) /*0.585*/ - { - clas = UNVOICED_TRANSITION; - move16(); - } - ELSE - { - clas = UNVOICED_CLAS; - move16(); - } - *clas_mod = clas; - move16(); - - BREAK; - - default: - clas = UNVOICED_CLAS; - *clas_mod = clas; - move16(); - move16(); - BREAK; + 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 ); } - } - /* 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 */ - /* tc_cnt == 2: frame after onset/transition frame, coded by TC coder type */ - - if ( clas == 0 ) - { - st->tc_cnt = 0; - move16(); - } - - test(); - IF( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 ) - { - st->tc_cnt = add( st->tc_cnt, 1 ); - move16(); - } - - if ( GT_16( st->tc_cnt, 2 ) ) - { - st->tc_cnt = -1; - move16(); - } - return 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 */ - 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; - Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1; - Word16 i, clas, pc, zc, exp_ee; - Word16 tmp16, tmpS; - const Word16 *pt1; - Word64 tmp64; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - /*----------------------------------------------------------------* - * Calculate average voicing - * Calculate average spectral tilt - * Calculate zero-crossing rate - * Calculate pitch stability - *----------------------------------------------------------------*/ - - /* average voicing on second half-frame and look-ahead */ - 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 */ - 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 + /* 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 */ - IF( GT_16( een, 512 ) ) + test(); + test(); + IF( LT_32( Ltmp, 2048 ) ) { - een = 512; + een = 0; move16(); } - ELSE IF( een < 0 ) + ELSE IF( GT_32( Ltmp, THRES_EEN ) || hi > 0 || hi2 > 0 ) { - een = 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 */ @@ -348,6 +141,7 @@ Word16 signal_clas_ivas_fx( /* o : classification for cur 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 @@ -475,8 +269,8 @@ Word16 signal_clas_ivas_fx( /* o : classification for cur 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 */ @@ -500,9 +294,11 @@ Word16 signal_clas_ivas_fx( /* o : classification for cur st->tc_cnt = -1; move16(); } + return clas; } + /*-------------------------------------------------------------------* * select_TC_fx() * @@ -523,6 +319,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 ) ) { @@ -544,6 +341,7 @@ void select_TC_fx( return; } + /*-------------------------------------------------------------------* * coder_type_modif_fx() * @@ -552,14 +350,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; @@ -587,8 +383,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(); @@ -614,8 +410,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 ) ) ) @@ -624,9 +419,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 ) ) @@ -640,147 +433,20 @@ void coder_type_modif_fx( hSC_VBR->vbr_generic_ho = 0; move16(); } - } //_DIFF_FLOAT_FIX_ see below - // PMT("Verify if EVS or IVAS is right about last_7k2_coder_type update") - 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(); - } - //} closing bracket here in IVAS float, but not in EVS float. currently affects BE for switching bitrate on Linux 20220929 _DIFF_FLOAT_FIX_ !! - - 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 ) ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - 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 ) - { - 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(); @@ -791,7 +457,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/spec_center_fx.c b/lib_enc/spec_center_fx.c index 1e908d0c388682b49e1d71d6807d6deb2e3be89e..78af3cda39a85549120dfe211d4fdcaf79a268de 100644 --- a/lib_enc/spec_center_fx.c +++ b/lib_enc/spec_center_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -18,9 +18,9 @@ *-------------------------------------------------------------------*/ void spec_center_fx( - Word32 *sb_power, /* i : energy of sub-band divided uniformly Q31 */ - Word16 *sp_center, /* o : spectral center Q10 */ - const Word32 bw_index, /* i : band width Q0 */ + Word32 *sb_power, /* i : energy of sub-band divided uniformly Q31 */ + Word16 *sp_center, /* o : spectral center Q10 */ + const Word32 bw_index, /* i : band width Q0 */ const Word16 Q_sb_p /* i : the Scaling of sb_power*/ ) { @@ -64,7 +64,7 @@ void spec_center_fx( frame_power_nb = frame_power; move32(); - /*+0.1 */ + /*+0.1 */ Q_t_sc = sub( Q_sb_p, 10 ); IF( GE_16( Q_t_sc, 34 ) ) { @@ -144,7 +144,7 @@ void spec_center_fx( t_sp_center = L_add( L_shr( sb_power_mlt, 8 ), t_sp_center ); frame_power = L_add( sb_power_shr[i], frame_power ); /*1-19 */ } - /*+0.1 */ + /*+0.1 */ Q_t_sc = sub( Q_sb_p, 13 ); IF( GE_16( Q_t_sc, 34 ) ) @@ -218,7 +218,7 @@ void spec_center_fx( frame_power = L_add( sb_power_shr[i], frame_power ); /*1-23 */ } - /*+0.1 */ + /*+0.1 */ Q_t_sc = sub( Q_sb_p, 14 ); IF( GE_16( Q_t_sc, 34 ) ) @@ -314,7 +314,7 @@ void spec_center_fx( { sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_1[i - 1] ); t_sp_center = L_add( L_shr( sb_power_mlt, 6 ), t_sp_center ); - frame_power = L_add( sb_power_shr[i], frame_power ); /*1-9 */ + frame_power = L_add( sb_power_shr[i], frame_power ); /*1-9 */ } IF( frame_power == 0 ) { diff --git a/lib_enc/spec_flatness_fx.c b/lib_enc/spec_flatness_fx.c index d7bd9a6e9f2da301d4b1ffbb3c19e4c3b1248e9a..ba8838e05795761df22c46872e17effe7353ed1f 100644 --- a/lib_enc/spec_flatness_fx.c +++ b/lib_enc/spec_flatness_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -100,7 +100,7 @@ void spec_flatness_fx( } sums = MUL_F( sums, 0x0888 ); - /*+0.1 */ + /*+0.1 */ IF( GE_16( prods_Q, 34 ) ) { prods = L_shr( prods, sub( prods_Q, 33 ) ); @@ -186,7 +186,7 @@ void spec_flatness_fx( } sums = MUL_F( sums, 0x0666 ); - /*+0.1 */ + /*+0.1 */ IF( GE_16( prods_Q, 34 ) ) { prods = L_shr( prods, sub( prods_Q, 33 ) ); @@ -272,7 +272,7 @@ void spec_flatness_fx( sums = MUL_F( sums, 0x051e ); - /*+0.1 */ + /*+0.1 */ IF( GE_16( prods_Q, 34 ) ) { prods = L_shr( prods, sub( prods_Q, 33 ) ); diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 38fd1726005ea31439079f1bdebb53e8d36bb85a..2f184957a0c911d1d692044d49cb3d63d2af4a2d 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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,16 +67,8 @@ 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() * @@ -73,22 +76,25 @@ Word32 log_weights_noise_compute[N_SMC_MIXTURES] = { *---------------------------------------------------------------------*/ void speech_music_clas_init_fx( - SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ + const Word16 element_mode, /* i : element mode */ + SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ + ) { Word16 i; - hSpMusClas->inact_cnt = 0; move16(); set16_fx( hSpMusClas->past_dec, 0, HANG_LEN - 1 ); set16_fx( hSpMusClas->past_dlp_fx, 0, HANG_LEN - 1 ); + set16_fx( hSpMusClas->past_log_enr_fx, -1448, NB_BANDS_SPMUS ); /* log(E_MIN) in Q8 */ hSpMusClas->sp_mus_state = -8; move16(); hSpMusClas->wdrop_fx = 0; move16(); + hSpMusClas->wdlp_0_95_sp_fx = 0; move16(); set16_fx( hSpMusClas->last_lsp_fx, 0, M_LSP_SPMUS ); @@ -99,10 +105,9 @@ void speech_music_clas_init_fx( set32_fx( hSpMusClas->past_PS_fx, 0, HIGHEST_FBIN - LOWEST_FBIN ); hSpMusClas->past_ps_diff_fx = 0; move16(); - hSpMusClas->past_epsP2_fx = 1024; + hSpMusClas->past_epsP2_fx = 1024; /* 1.0f in Q10 */ move16(); - hSpMusClas->gsc_thres_fx[0] = TH_0_MIN_FX; move16(); hSpMusClas->gsc_thres_fx[1] = TH_1_MIN_FX; @@ -120,17 +125,18 @@ void speech_music_clas_init_fx( move16(); hSpMusClas->gsc_nb_thr_3 = 0; move16(); - hSpMusClas->mold_corr_fx = 29491; + hSpMusClas->mold_corr_fx = 29491; /* 0.9f in Q15 */ move16(); - hSpMusClas->mean_avr_dyn_fx = 64; - move16(); /*Q7 */ - hSpMusClas->last_sw_dyn_fx = 2560; + hSpMusClas->mean_avr_dyn_fx = 64; /* 0.5f in Q7 */ + move16(); + hSpMusClas->last_sw_dyn_fx = 2560; /* 10.0f in Q7 */ move16(); + /* speech/music classifier improvement */ FOR( i = 0; i < BUF_LEN; i++ ) { - hSpMusClas->buf_flux_fx[i] = -12800; - move16(); /*-100.0 in Q7 */ + hSpMusClas->buf_flux_fx[i] = -12800; /*-100.0f in Q7 */ + move16(); hSpMusClas->buf_pkh_fx[i] = 0; move16(); hSpMusClas->buf_epsP_tilt_fx[i] = 0; @@ -155,14 +161,15 @@ void speech_music_clas_init_fx( move16(); hSpMusClas->gsc_cnt = 0; move16(); + set16_fx( hSpMusClas->old_Bin_E_fx, 0, 3 * N_OLD_BIN_E ); set16_fx( hSpMusClas->buf_etot_fx, 0, 4 ); set16_fx( hSpMusClas->buf_dlp_fx, 0, 10 ); hSpMusClas->UV_cnt1 = 300; move16(); - hSpMusClas->LT_UV_cnt1_fx = 16000; - move16(); /*250.0f in Q6 */ + hSpMusClas->LT_UV_cnt1_fx = 16000; /* 250.0f in Q6 */ + move16(); hSpMusClas->onset_cnt = 0; move16(); hSpMusClas->attack_hangover = 0; @@ -171,8 +178,8 @@ void speech_music_clas_init_fx( move16(); hSpMusClas->dec_mov1_fx = 0; move16(); - hSpMusClas->mov_log_max_spl_fx = 25600; - move16(); /*200.0 in Q7 */ + hSpMusClas->mov_log_max_spl_fx = 25600; /* 200.0 in Q7 */ + move16(); hSpMusClas->old_lt_diff_fx[0] = 0; move16(); hSpMusClas->old_lt_diff_fx[1] = 0; @@ -182,7 +189,6 @@ void speech_music_clas_init_fx( hSpMusClas->high_stable_cor = 0; move16(); set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); - hSpMusClas->lps_fx = 0; move16(); hSpMusClas->lpm_fx = 0; @@ -194,9 +200,9 @@ void speech_music_clas_init_fx( /* speech/music classification */ set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); - hSpMusClas->lt_voicing = 16384 /*0.5f Q15*/; + hSpMusClas->lt_voicing = 16384; /* 0.5f in Q15 */ move16(); - hSpMusClas->lt_corr = 16384 /*0.5f Q15*/; + hSpMusClas->lt_corr = 16384; /* 0.5f in Q15 */ move16(); hSpMusClas->lt_tonality = 0; move32(); @@ -206,7 +212,6 @@ void speech_music_clas_init_fx( hSpMusClas->lowrate_pitchGain = 0; move16(); - hSpMusClas->lt_music_hangover = 0; move16(); set16_fx( hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT ); @@ -219,235 +224,82 @@ void speech_music_clas_init_fx( hSpMusClas->lt_speech_hangover = 0; move16(); - - return; -} - -void speech_music_clas_init_ivas_fx( - 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++ ) + IF( element_mode > EVS_MONO ) { - hSpMusClas->prev_FV_fx[i] = L_add( L_shr( hout_intervals_fx[2 * i], 1 ), L_shr( hout_intervals_fx[2 * i + 1], 1 ) ); + 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(); - } - FOR( i = 0; i < NB_BANDS_SPMUS; i++ ) - { - hSpMusClas->past_log_enr_fx[i] = -1448; /* log(E_MIN) in Q8 */ + 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->sp_mus_state = -8; - move16(); - hSpMusClas->wdrop_32fx = 0; - move32(); - hSpMusClas->wrise_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(); - hSpMusClas->gsc_thres_fx[1] = TH_1_MIN_FX; - move16(); - hSpMusClas->gsc_thres_fx[2] = TH_2_MIN_FX; - move16(); - hSpMusClas->gsc_thres_fx[3] = TH_3_MIN_FX; - move16(); - set16_fx( hSpMusClas->gsc_lt_diff_etot_fx, 0, 40 ); - hSpMusClas->gsc_mem_etot_fx = 0; - move16(); - hSpMusClas->gsc_last_music_flag = 0; - move16(); - hSpMusClas->gsc_nb_thr_1 = 0; - move16(); - hSpMusClas->gsc_nb_thr_3 = 0; - move16(); - hSpMusClas->mold_corr_fx = 29491; /* 0.9f in Q15 */ - move16(); - hSpMusClas->mean_avr_dyn_fx = 64; /* 0.5f in Q7 */ - move16(); - 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++ ) - { - hSpMusClas->buf_flux_fx[i] = -12800; /*-100.0f in Q7 */ + hSpMusClas->wdlp_0_95_sp_32fx = 0; + move32(); + hSpMusClas->wdlp_xtalk_fx = 0; move16(); - hSpMusClas->buf_pkh_fx[i] = 0; + hSpMusClas->past_PS_Q = Q31; move16(); - hSpMusClas->buf_epsP_tilt_fx[i] = 0; + hSpMusClas->past_epsP_fx = 0; move16(); - hSpMusClas->buf_cor_map_sum_fx[i] = 0; + hSpMusClas->flag_spitch_cnt = 0; move16(); - hSpMusClas->buf_Ntonal_fx[i] = 0; + hSpMusClas->relE_attack_cnt = 0; move16(); - hSpMusClas->buf_Ntonal2_fx[i] = 0; + hSpMusClas->prev_relE_fx = 0; move16(); - hSpMusClas->buf_Ntonal_lf_fx[i] = 0; + 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(); - } - - set16_fx( hSpMusClas->lpe_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->voicing_buf_fx, 0, HANG_LEN_INIT ); - hSpMusClas->gsc_hangover = 0; - move16(); - set16_fx( hSpMusClas->sparse_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->hf_spar_buf_fx, 0, HANG_LEN_INIT ); - hSpMusClas->LT_sparse_fx = 0; - 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 ); - set16_fx( hSpMusClas->buf_dlp_fx, 0, 10 ); - - hSpMusClas->UV_cnt1 = 300; - move16(); - hSpMusClas->LT_UV_cnt1_fx = 16000; /* 250.0f in Q6 */ - move16(); - hSpMusClas->onset_cnt = 0; - move16(); - hSpMusClas->attack_hangover = 0; - move16(); - hSpMusClas->dec_mov_fx = 0; - move16(); - hSpMusClas->dec_mov1_fx = 0; - move16(); - hSpMusClas->mov_log_max_spl_fx = 25600; /* 200.0 in Q7 */ - move16(); - hSpMusClas->old_lt_diff_fx[0] = 0; - move16(); - 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; - 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(); - - /* speech/music classification */ - set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); - hSpMusClas->lt_voicing = 16384; /* 0.5f in Q15 */ - move16(); - hSpMusClas->lt_corr = 16384; /* 0.5f in Q15 */ - move16(); - hSpMusClas->lt_tonality = 0; - move32(); - set16_fx( hSpMusClas->lt_corr_pitch, 0, 3 ); - hSpMusClas->lt_hangover = 0; - move16(); - hSpMusClas->lowrate_pitchGain = 0; - move16(); - - hSpMusClas->lt_music_hangover = 0; - move16(); - set16_fx( hSpMusClas->tonality2_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->tonality3_buf_fx, 0, HANG_LEN_INIT ); - set16_fx( hSpMusClas->LPCErr_buf_fx, 0, HANG_LEN_INIT ); - hSpMusClas->lt_music_state = 0; - move16(); - hSpMusClas->lt_speech_state = 0; - move16(); - hSpMusClas->lt_speech_hangover = 0; - move16(); - - hSpMusClas->lt_dec_thres_fx = 5120; /* 10.0f in Q9 */ - move16(); - hSpMusClas->ener_RAT_fx = 0; - move16(); - - hSpMusClas->high_stable_cor = 0; - move16(); - set16_fx( hSpMusClas->var_cor_t_fx, 0, VAR_COR_LEN ); - 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(); + } return; } + /*---------------------------------------------------------------------* * speech_music_classif() * @@ -492,8 +344,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 +373,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 +445,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 +780,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis *LPCErr = FV[9]; move16(); - /*------------------------------------------------------------------* * Calculation of posterior probability * Log-probability @@ -940,7 +790,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 +806,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 +861,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis move16(); } - IF( !vad ) { /* increase log-probability of noise */ @@ -1154,7 +1001,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 +1102,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis } } - /*------------------------------------------------------------------* * Updates *------------------------------------------------------------------*/ @@ -1441,13 +1286,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 +1409,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 +1463,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 +1695,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 +1848,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 +1876,7 @@ Word16 ivas_smc_gmm_fx( /*------------------------------------------------------------------* * Outlier detection based on feature histograms *------------------------------------------------------------------*/ + flag_odv = 0; move16(); IF( localVAD_HE_SAD ) @@ -2071,6 +1916,7 @@ Word16 ivas_smc_gmm_fx( /*------------------------------------------------------------------* * Adaptive short-term mean filter on feature vector *------------------------------------------------------------------*/ + Qfact_FV = 20; move16(); pFV_fx = FV_fx; @@ -2109,10 +1955,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 +2083,7 @@ Word16 ivas_smc_gmm_fx( * Decision without hangover * Weighted decision *------------------------------------------------------------------*/ + test(); test(); test(); @@ -2314,7 +2163,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 +2345,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 +2359,7 @@ Word16 ivas_smc_gmm_fx( } move16(); move16(); + /*------------------------------------------------------------------* * Updates *------------------------------------------------------------------*/ @@ -2534,6 +2384,7 @@ Word16 ivas_smc_gmm_fx( return dec; } + /*---------------------------------------------------------------------* * var_cor_calc_ivas_fx() * @@ -2583,20 +2434,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 +2487,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 +2514,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 +2650,7 @@ static Word16 attack_det_ivas_fx( /* o : attack flag return attack; } + /*---------------------------------------------------------------------* * tonal_det() * @@ -2904,12 +2757,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 +2986,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 +3052,7 @@ void ivas_smc_mode_selection_fx( return; } + /*---------------------------------------------------------------------* * mode_decision_fx() * @@ -3235,7 +3089,6 @@ static Word16 mode_decision_fx( Word16 M_flux10; SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; - mode = *dec_mov > 16384; logic16(); move16(); @@ -3476,6 +3329,7 @@ static Word16 mode_decision_fx( return ( mode ); } + /*---------------------------------------------------------------------* * tonal_dist_fx() * @@ -3496,7 +3350,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 +3413,7 @@ static void tonal_dist_fx( return; } + /*---------------------------------------------------------------------* * flux_fx() * @@ -3645,6 +3499,7 @@ static void flux_fx( return; } + /*---------------------------------------------------------------------* * spec_analysis_fx() * @@ -3761,8 +3616,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 +3999,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; @@ -4146,10 +4010,8 @@ static void tonal_context_improv_fx( Word32 L_tmp, tonality, tonality1, tonality2, tonality3, sort_max, sort_avg, sort_val[80]; VAD_HANDLE hVAD = st_fx->hVAD; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); -#endif IF( EQ_16( st_fx->last_codec_mode, MODE2 ) ) { @@ -4502,11 +4364,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 */ @@ -4598,7 +4462,7 @@ static void detect_sparseness_fx( Msp = shl( Msp, 5 ); /* Q8 */ /* find long-term smoothed sparseness */ - IF( st_fx->last_vad_spa_fx == 0 ) + IF( hSpMusClas->last_vad_spa == 0 ) { set16_fx( &hSpMusClas->sparse_buf_fx[0], sparse, HANG_LEN_INIT - 1 ); hSpMusClas->LT_sparse_fx = sparse; @@ -4853,7 +4717,7 @@ static void detect_sparseness_fx( move16(); } - st_fx->last_vad_spa_fx = localVAD_HE_SAD; + hSpMusClas->last_vad_spa = localVAD_HE_SAD; move16(); return; @@ -4864,6 +4728,7 @@ static void detect_sparseness_fx( * * *---------------------------------------------------------------------*/ + static void order_spectrum_fx( Word16 *vec, Word16 len ) @@ -4926,4 +4791,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 44125a717ff581be9d35dd2ce4b17b263ef06afb..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef STAT_ENC_H @@ -397,13 +397,8 @@ typedef struct fd_cng_enc_structure Word16 msLogPeriodog_fx[NPART]; Word16 msLogNoiseEst_fx[NPART]; Word32 msLogNoiseEst_32fx[NPART]; /*IVAS: Q25*/ -#ifdef NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG Word32 mem_coherence_fx[MDCT_ST_DTX_NUM_COHERENCE_BANDS][4]; Word16 mem_coherence_exp[MDCT_ST_DTX_NUM_COHERENCE_BANDS][4]; -#else - Word32 mem_coherence_fx[4]; - Word16 mem_coherence_exp[4]; -#endif } FD_CNG_ENC, *HANDLE_FD_CNG_ENC; @@ -713,8 +708,6 @@ typedef struct sp_mus_clas_structure typedef struct lpd_state_structure { - - /* signal memory */ Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ Word16 q_lpd_syn; @@ -808,7 +801,6 @@ typedef struct hq_enc_structure Word16 last_env_fx[BANDS_MAX]; /* Q1 */ Word16 last_max_pos_pulse; - } HQ_ENC_DATA, *HQ_ENC_HANDLE; /* PVQ range coder state */ @@ -1012,6 +1004,13 @@ typedef struct td_bwe_enc_structure Word16 gain_prec_swb_fx; /* Q14 */ Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; + + Word16 prev_Q_bwe_exc; + Word16 prev_Q_bwe_syn; + } TD_BWE_ENC_DATA, *TD_BWE_ENC_HANDLE; @@ -1157,20 +1156,17 @@ typedef struct tcx_enc_structure Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ /* Core Signal Analysis Outputs */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling Q15 */ Word16 noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth Q15 */ STnsData tnsData[2]; - // Word16 fUseTns[2]; + Word8 fUseTns[2]; Word16 bTnsOnWhithenedSpectra[2]; - // Word16 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word8 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word16 *speech_TCX; Word16 *new_speech_TCX; - // Word16 q_speech_TCX; Word16 tcxltp; Word16 tcxltp_pitch_int; @@ -1224,6 +1220,7 @@ typedef struct tcx_enc_structure Word16 spectrum_long_e; /* MDCT output for a long block. Points to spectrum */ Word16 q_spectrum_long_fx; Word16 spectrum_length; /* corresponds to L_frameTCX, used for scaling of MDCT/MDST buffers */ + } TCX_ENC_DATA, *TCX_ENC_HANDLE; @@ -1239,13 +1236,12 @@ typedef struct enc_core_structure * Common parameters *----------------------------------------------------------------------------------*/ - Word16 idchan; /* channel ID (audio channel number) */ - Word16 id_element; /* element ID */ + Word16 idchan; /* channel ID (audio channel number) */ +#ifdef DEBUGGING + Word16 id_element; /* element ID */ +#endif Word16 element_mode; /* element mode */ - Word16 last_element_mode; /* element mode */ Word32 element_brate; /* element bitrate */ - Word16 extl_orig; /* extension layer */ - Word32 extl_brate_orig; /* extension layer bitrate */ Word16 codec_mode; /* Mode1 or Mode2 */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ Word16 last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ @@ -1254,9 +1250,7 @@ typedef struct enc_core_structure Word16 mdct_sw_enable; /* MDCT switching enable flag */ Word16 mdct_sw; /* MDCT switching indicator */ - BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ - Word16 last_enerBuffer_exp; - + BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ @@ -1295,34 +1289,8 @@ typedef struct enc_core_structure char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ #endif #endif - Word16 nTimeSlots; /* for CLDFB */ - Word16 ini_frame; /* initialization frames counter */ - // Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - // Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - // Word32 core_brate_fx; /* core bitrate */ - // Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ - // Word16 extl_fx; /* extension layer */ - // Word16 last_extl_fx; /* previous extension layer */ - // Word32 extl_brate_fx; /* extension layer bitrate */ - // Word16 input_bwidth_fx; /* input signal bandwidth */ - // Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - // Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - // Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - // Word16 L_frame_fx; /* ACELP core internal frame length */ - // Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - // Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - // Word16 cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - // Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - // Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ - /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ @@ -1333,27 +1301,25 @@ typedef struct enc_core_structure Word16 fmerit_dt; /* signal classification score difference Q15 */ Word16 Nb_ACELP_frames; - Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ - // Word16 pitch_fx[3]; + Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ Word16 voicing_fx[3]; /* open-loop normalized correlation values for three half-frames Q15 */ LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 pstreaklen; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer Q15 */ - Word16 stab_fac_fx; /* LSF stability factor Q15 */ - Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ - // Word16 pstreaklen_fx; /* LSF quantizer */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 pstreaklen; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer Q15 */ + Word16 stab_fac_fx; /* LSF stability factor Q15 */ + Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ @@ -1369,15 +1335,12 @@ typedef struct enc_core_structure Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ Word16 exp_old_wsp; Word16 Q_old_wsp2; - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ Word16 mem_wsp_q; - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ Word16 GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; @@ -1386,7 +1349,6 @@ typedef struct enc_core_structure Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame Qlog2(2.56) */ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC Qlog2(2.56) */ Word16 next_force_safety_net; /* FEC - flag to force safety net in next frame */ - // Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ Word16 act_count; /* Stationary noise UV modification - activation counter */ @@ -1416,7 +1378,6 @@ typedef struct enc_core_structure Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ Word16 old_Es_pred_fx; /* old Es_pred for core switching Q8 */ Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ - Word16 last_vad_spa_fx; Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz Q-1 */ @@ -1472,7 +1433,7 @@ typedef struct enc_core_structure Word16 *old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ Word16 *buf_speech_enc_pe; // exp_buf_speech_enc_pe - Word16 *buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + Word16 *buf_synth; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ Word16 *buf_speech_enc; // exp_buf_speech_enc Word16 *buf_wspeech_enc; // exp_buf_wspeech_enc @@ -1483,6 +1444,8 @@ typedef struct enc_core_structure Word16 exp_buf_wspeech_enc; Word16 exp_buf_synth; + Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ + /*----------------------------------------------------------------------------------* * Noise estimation *----------------------------------------------------------------------------------*/ @@ -1495,8 +1458,6 @@ typedef struct enc_core_structure SP_MUS_CLAS_HANDLE hSpMusClas; - Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ - Word16 sp_aud_decision0; /* 1st stage speech/music decision flag */ Word16 sp_aud_decision1; /* 1st stage speech/music classification flag */ Word16 sp_aud_decision2; /* 2nd stage speech/music classification flag */ @@ -1535,9 +1496,6 @@ typedef struct enc_core_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc; /* main analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSynTd; /* synthesis filterbank - used for HB signal generation */ - // HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - - // HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; /*----------------------------------------------------------------------------------* * FD CNG handle @@ -1568,7 +1526,6 @@ typedef struct enc_core_structure HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ - PVQ_ENC_HANDLE hPVQ; /*----------------------------------------------------------------------------------* * TD BWE parameters *----------------------------------------------------------------------------------*/ @@ -1667,7 +1624,7 @@ typedef struct enc_core_structure Word16 inv_gamma; /* Q14 */ TRAN_DET_HANDLE hTranDet; - Word16 transient_info[3]; + Word16 acelpFramesCount; Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E Q7 in EVS */ /* Q4 in IVAS */ Word32 prevTempFlatness_32fx; /* Q21 in IVAS */ @@ -1766,8 +1723,7 @@ typedef struct enc_core_structure * IVAS parameters *---------------------------------------------------------------*/ - Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ - Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ /* stereo switching memories */ Word16 mem_preemph_DFT_fx; /* Q(-1) */ @@ -1783,16 +1739,13 @@ typedef struct enc_core_structure Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ + Word16 sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ + /*----------------------------------------------------------------------------------* * Fixed point only variables *----------------------------------------------------------------------------------*/ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - Word16 Q_exc; - - Word16 prev_Q_bwe_exc; - Word16 prev_Q_bwe_syn; Word16 Q_stat_noise_ge; Word16 Q_stat_noise; Word16 Q_syn2; @@ -1806,13 +1759,8 @@ typedef struct enc_core_structure Word16 prev_Q_new; Word16 prev_Q_shb; Word16 Q_max_enc[2]; - Word16 EnergyLT_fx_exp; - Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; - - Word16 sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ + Word16 last_enerBuffer_exp; } Encoder_State, *ENC_CORE_HANDLE; diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index a62963ff002602651abcb3aebf952f69d621c347..126e5cf8e2a63c6b37f53f29b04bc9ffb2d358e2 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -107,13 +107,13 @@ void stat_noise_uv_enc_fx( void stat_noise_uv_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: state structure */ + Encoder_State *st_fx, /* i/o: state structure */ const Word32 *LepsP, /* i : LP prediction errors Q=Qx*/ const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr Q=15*/ const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr Q=15*/ Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ - const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ + const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ Word16 *Q_new ) { Word16 noisiness = 0; diff --git a/lib_enc/subband_fft_fx.c b/lib_enc/subband_fft_fx.c index 10de09fe95e85e1dbbbc7ef6f6686115770cbbc6..daf9048a4df248ddea1a4ef5fb511142632fcba0 100644 --- a/lib_enc/subband_fft_fx.c +++ b/lib_enc/subband_fft_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index af72e0f4926c25256e65079a8429764c0bf1d520..05802bf45c605f2fc23a5fd455e4b4fae6b6a304 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -11,9 +11,29 @@ #include "prot_fx_enc.h" /* Function prototypes */ /*---------------------------------------------------------------------* - * Local functions + * Local functions declarations *---------------------------------------------------------------------*/ +#ifdef HARM_FD_BWE +static Word16 WB_BWE_encoding_fx( Encoder_State *st_fx, const Word32 *yos_fx, Word16 *WB_fenv_fx, Word16 Q_synth, const Word16 Q_synth_lf ); + +static Word16 SWB_BWE_encoding_fx( Encoder_State *st_fx, Word16 *insig_fx, const Word16 *insig_lp_fx, const Word16 *insig_hp_fx, const Word16 *synth_fx, const Word16 *yos_fx_16, const Word32 *yos_fx, Word16 *SWB_fenv_fx, const Word16 tilt_nb_fx, const Word16 st_offset, const Word16 Q_insig_lp, const Word16 Q_shb, const Word16 Q_synth, const Word16 Q_synth_lf ); +#else +static Word16 WB_BWE_encoding_fx( + const Word16 coder_type, /* i : coder type */ + const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ + Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ + Encoder_State *st_fx, /* i/o: Encoder structure */ + const Word16 Q_synth, + const Word16 Q_synth_lf ); + +static Word16 WB_BWE_encoding_ivas_fx( + Encoder_State *st_fx, /* i/o: Encoder structure */ + const Word32 *yos_fx, /* i : MDCT coefficients of weighted original */ + Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ + Word16 Q_synth, + const Word16 Q_synth_lf ); + static Word16 SWB_BWE_encoding_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *insig_fx, /* i/o: delayed original input signal at 32kHz (might be rescaled)*/ @@ -25,10 +45,10 @@ static Word16 SWB_BWE_encoding_fx( const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ const Word16 coder_type, /* i : coding type */ - Word16 Q_insig_lp, - Word16 Q_shb, - Word16 Q_synth, - Word16 Q_synth_lf ); + const Word16 Q_insig_lp, + const Word16 Q_shb, + const Word16 Q_synth, + const Word16 Q_synth_lf ); static Word16 SWB_BWE_encoding_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -40,17 +60,25 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ - Word16 Q_insig_lp, - Word16 Q_shb, - Word16 Q_synth, - Word16 Q_synth_lf ); + const Word16 Q_insig_lp, + const Word16 Q_shb, + const Word16 Q_synth, + const Word16 Q_synth_lf ); +#endif + + +/*-------------------------------------------------------------------* + * delay_input_signal_fx() + * + * + *-------------------------------------------------------------------*/ static void delay_input_signal_fx( Word16 *old_sig, Word16 *cur_sig, Word16 *new_sig, - Word16 m1, - Word16 m2, + const Word16 m1, + const Word16 m2, Word16 *Q_old, Word16 *Q_new ) { @@ -115,6 +143,7 @@ static void delay_input_signal_fx( return; } + /*-------------------------------------------------------------------* * wb_bwe_enc() * @@ -122,6 +151,7 @@ static void delay_input_signal_fx( *-------------------------------------------------------------------*/ void wb_bwe_enc_fx( +#ifndef HARM_FD_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_wb_speech_fx, /* i : original input signal at 16kHz */ Word16 coder_type /* i : coding type */ @@ -201,6 +231,7 @@ void wb_bwe_enc_fx( *-------------------------------------------------------------------*/ void wb_bwe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_wb_speech_fx /* i : original input signal at 16kHz */ ) @@ -221,6 +252,7 @@ void wb_bwe_enc_ivas_fx( /*---------------------------------------------------------------------* * Delay the original input signal to be synchronized with ACELP core synthesis *---------------------------------------------------------------------*/ + set16_fx( old_input_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k ); Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); move16(); @@ -232,22 +264,32 @@ void wb_bwe_enc_ivas_fx( /*---------------------------------------------------------------------*/ /* WB BWE encoding */ - - - /* MDCT of the core synthesis signal */ + /* MDCT of the core synthesis signal */ /*---------------------------------------------------------------------*/ - new_input_fx_exp = -1; + + new_input_fx_exp = -Q1; move16(); +#ifdef HARM_FD_BWE + if ( st_fx->element_mode == EVS_MONO ) + { + new_input_fx_exp = 0; + move16(); + } +#endif wtda_fx( old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - L_FRAME16k ); + &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ L_FRAME16k ); /* DCT of the ACELP core synthesis */ direct_transform_fx( L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); +#ifdef HARM_FD_BWE + mode = WB_BWE_encoding_fx( st_fx, yorig_32, WB_fenv_fx, new_input_fx_exp, new_input_fx_exp ); +#else mode = WB_BWE_encoding_ivas_fx( st_fx, yorig_32, WB_fenv_fx, new_input_fx_exp, new_input_fx_exp ); +#endif move16(); + push_indice( st_fx->hBstr, IND_WB_CLASS, sub( mode, 2 ), 1 ); } @@ -257,22 +299,33 @@ void wb_bwe_enc_ivas_fx( return; } + /*-------------------------------------------------------------------* * swb_bwe_enc() * * SWB BWE encoder (only for 32kHz signals) *-------------------------------------------------------------------*/ + +#ifdef HARM_FD_BWE +void swb_bwe_enc_fx( +#else void swb_bwe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode */ - Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ - Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ + const Word16 last_element_mode, /* i : last element mode */ + Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ + Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ 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 *shb_speech_fx_Q0, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ +#ifdef HARM_FD_BWE Word16 Q_shb_speech, - Word16 Q_slb_speech ) + Word16 Q_slb_speech +#else + const Word16 Q_slb_speech +#endif +) { Word16 i; Word16 *new_input_fx; @@ -304,14 +357,32 @@ void swb_bwe_enc_ivas_fx( move16(); Word16 fb_band_begin; Word16 q_new_input_hp; + Word16 shb_speech_fx[L_FRAME16k]; +#ifdef HARM_FD_BWE + Word16 Qenc_synth_hf, Qenc_synth; +#else + Word16 Q_shb_speech; +#endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( shb_speech_fx_Q0, shb_speech_fx, L_FRAME16k ); + } + ELSE +#endif + { + 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; @@ -349,230 +420,301 @@ void swb_bwe_enc_ivas_fx( Copy( old_input_12k8_fx + L_INP_MEM - Sample_Delay_LP, hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); Copy( hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, new_input_hp_fx, Sample_Delay_HP ); } +#ifndef HARM_FD_BWE } +#endif Copy( hBWE_FD->old_input_lp_fx, old_input_lp_fx, Sample_Delay_LP ); Copy( old_input_12k8_fx + L_INP_MEM, &old_input_lp_fx[Sample_Delay_LP], L_FRAME - Sample_Delay_LP ); Copy( old_input_12k8_fx + L_INP_MEM + L_FRAME - Sample_Delay_LP, hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); +#ifdef HARM_FD_BWE } ELSE { - Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); - 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_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); - IF( st_fx->element_mode > EVS_MONO ) - { - Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( inner_Fs, DELAY_FIR_RESAMPL_NS ) ); - Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); - - IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) - { - Copy( old_input_16k_fx + L_INP_MEM - Sample_Delay_LP, hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); - Copy( hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, new_input_hp_fx, Sample_Delay_HP ); - } - } - Copy( hBWE_FD->old_input_lp_fx, old_input_lp_fx, Sample_Delay_LP ); - Copy( old_input_16k_fx + L_INP_MEM, &old_input_lp_fx[Sample_Delay_LP], L_FRAME16k - Sample_Delay_LP ); - Copy( old_input_16k_fx + L_INP_MEM + L_FRAME16k - Sample_Delay_LP, hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + delay_input_signal_fx( hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_12k8_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); } - - q_new_input_hp = s_min( Q_shb_speech, hBWE_FD->Q_new_input_hp ); - IF( LT_16( Q_shb_speech, hBWE_FD->Q_new_input_hp ) ) +#endif +} +ELSE +{ + Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - Copy_Scale_sig( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP, sub( Q_shb_speech, hBWE_FD->Q_new_input_hp ) ); // Q_shb_speech - Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP ); // Q_shb_speech + 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 ); } - ELSE + Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); + IF( st_fx->element_mode > EVS_MONO ) { - Copy( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP ); // hBWE_FD->Q_new_input_hp - Copy_Scale_sig( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP, sub( hBWE_FD->Q_new_input_hp, Q_shb_speech ) ); // hBWE_FD->Q_new_input_hp - } + Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( inner_Fs, DELAY_FIR_RESAMPL_NS ) ); + Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); - hBWE_FD->Q_new_input_hp = Q_shb_speech; - move16(); - Copy( shb_speech_fx + L_FRAME16k - Sample_Delay_HP, hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); - new_input_fx = old_input_fx + Sample_Delay_SWB_BWE; - Copy( hBWE_FD->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); - Copy( new_swb_speech_fx, new_input_fx, inner_frame ); - Copy( old_input_fx + inner_frame, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); - /*----------------------------------------------------------------------* - * Calculate tilt of the input signal and the ACELP core synthesis - *----------------------------------------------------------------------*/ - - /* tilt returned in Q24 goto to Q11 */ - tilt_nb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) ); - - /*---------------------------------------------------------------------* - * SWB BWE encoding - * FB BWE encoding - *---------------------------------------------------------------------*/ - new_input_fx_q = Q_new_swb_speech; - move16(); - test(); - IF( ( EQ_16( st_fx->idchan, 1 ) ) && ( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) - { - FOR( i = 0; i < inner_frame; i++ ) + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - hBWE_FD->L_old_wtda_swb_fx[i] = mult_r( hBWE_FD->L_old_wtda_swb_fx[i], div_s( i, inner_frame ) ); - move16(); + Copy( old_input_16k_fx + L_INP_MEM - Sample_Delay_LP, hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + Copy( hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, new_input_hp_fx, Sample_Delay_HP ); } +#ifndef HARM_FD_BWE } - /* MDCT of the core synthesis signal */ - wtda_fx( old_input_fx, &new_input_fx_q, L_old_input_fx, hBWE_FD->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - inner_frame ); +#endif - /* DCT of the ACELP core synthesis */ - direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_q, st_fx->element_mode ); + Copy( hBWE_FD->old_input_lp_fx, old_input_lp_fx, Sample_Delay_LP ); + Copy( old_input_16k_fx + L_INP_MEM, &old_input_lp_fx[Sample_Delay_LP], L_FRAME16k - Sample_Delay_LP ); + Copy( old_input_16k_fx + L_INP_MEM + L_FRAME16k - Sample_Delay_LP, hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); +#ifdef HARM_FD_BWE +} +ELSE +{ + delay_input_signal_fx( hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); +} +#endif +} - /* high-band gain control in case of BWS */ - IF( st_fx->bwidth_sw_cnt > 0 ) - { - v_multc_fx_16( &yorig_32[L_FRAME16k], div_s( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ), &yorig_32[L_FRAME16k], sub( inner_frame, L_FRAME16k ) ); - } +q_new_input_hp = s_min( Q_shb_speech, hBWE_FD->Q_new_input_hp ); +#ifdef HARM_FD_BWE +IF( st_fx->element_mode == EVS_MONO ) +{ + Copy( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP ); + Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP ); +} +ELSE IF( LT_16( Q_shb_speech, hBWE_FD->Q_new_input_hp ) ) +#else + IF( LT_16( Q_shb_speech, hBWE_FD->Q_new_input_hp ) ) +#endif +{ + Copy_Scale_sig( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP, sub( Q_shb_speech, hBWE_FD->Q_new_input_hp ) ); // Q_shb_speech + Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP ); // Q_shb_speech +} +ELSE +{ + Copy( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP ); // hBWE_FD->Q_new_input_hp + Copy_Scale_sig( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP, sub( hBWE_FD->Q_new_input_hp, Q_shb_speech ) ); // hBWE_FD->Q_new_input_hp +} - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub( 16 + 8, new_input_fx_q ); - /* Possible to Upscale? */ - IF( scl > 0 ) +hBWE_FD->Q_new_input_hp = Q_shb_speech; +move16(); +Copy( shb_speech_fx + L_FRAME16k - Sample_Delay_HP, hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); +new_input_fx = old_input_fx + Sample_Delay_SWB_BWE; +Copy( hBWE_FD->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); +Copy( new_swb_speech_fx, new_input_fx, inner_frame ); +Copy( old_input_fx + inner_frame, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); + +/*----------------------------------------------------------------------* + * Calculate tilt of the input signal and the ACELP core synthesis + *----------------------------------------------------------------------*/ + +/* tilt returned in Q24 goto to Q11 */ +tilt_nb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) ); + +/*---------------------------------------------------------------------* + * SWB BWE encoding + * FB BWE encoding + *---------------------------------------------------------------------*/ + +new_input_fx_q = Q_new_swb_speech; +move16(); + +test(); +IF( ( EQ_16( st_fx->idchan, 1 ) ) && ( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) +{ + FOR( i = 0; i < inner_frame; i++ ) { - /* Yes */ - /* Calc Room to Upscale */ - Q_synth = Find_Max_Norm32( yorig_32, inner_frame ); - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min( Q_synth, scl ); + hBWE_FD->L_old_wtda_swb_fx[i] = mult_r( hBWE_FD->L_old_wtda_swb_fx[i], div_s( i, inner_frame ) ); + move16(); } - Copy_Scale_sig32_16( yorig_32, yorig_fx, inner_frame, scl ); - Q_synth = add( sub( new_input_fx_q, 16 ), scl ); - max = 0; +} + +/* MDCT of the core synthesis signal */ +wtda_fx( old_input_fx, &new_input_fx_q, L_old_input_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ inner_frame ); + +/* DCT of the ACELP core synthesis */ +direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_q, st_fx->element_mode ); + +/* high-band gain control in case of BWS */ +#ifdef HARM_FD_BWE +test(); +IF( st_fx->bwidth_sw_cnt > 0 && st_fx->element_mode > EVS_MONO ) +#else + IF( st_fx->bwidth_sw_cnt > 0 ) +#endif +{ + v_multc_fx_16( &yorig_32[L_FRAME16k], div_s( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ), &yorig_32[L_FRAME16k], sub( inner_frame, L_FRAME16k ) ); +} + +/* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ +scl = sub( 16 + 8, new_input_fx_q ); +/* Possible to Upscale? */ +IF( scl > 0 ) +{ + /* Yes */ + /* Calc Room to Upscale */ + Q_synth = Find_Max_Norm32( yorig_32, inner_frame ); + /* Stay within MAX_Q_NEW_INPUT */ + scl = s_min( Q_synth, scl ); +} +Copy_Scale_sig32_16( yorig_32, yorig_fx, inner_frame, scl ); +Q_synth = add( sub( new_input_fx_q, 16 ), scl ); +max = 0; +move16(); +Q_synth_hf = 0; +move16(); +IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) +{ + scl = 300; move16(); - Q_synth_hf = 0; +} +ELSE +{ + scl = 240; move16(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - scl = 300; - move16(); - } - ELSE - { - scl = 240; - move16(); - } - FOR( i = scl; i < inner_frame; i++ ) - { - max = s_max( max, abs_s( yorig_fx[i] ) ); - } +} +FOR( i = scl; i < inner_frame; i++ ) +{ + max = s_max( max, abs_s( yorig_fx[i] ) ); +} - IF( max == 0 ) +IF( max == 0 ) +{ + exp = 15; + move16(); +} +ELSE +{ + exp = norm_s( max ); +} +Copy_Scale_sig( &yorig_fx[scl], &yorig_fx[scl], sub( inner_frame, scl ), exp ); +Q_synth_hf = add( exp, Q_synth ); + +test(); +IF( EQ_16( st_fx->last_extl, SWB_BWE ) || EQ_16( st_fx->last_extl, FB_BWE ) ) +{ + exp = norm_l( st_fx->EnergyLT_fx ); + IF( GT_16( add( st_fx->EnergyLT_fx_exp, exp ), shl( sub( Q_synth_hf, 4 ), 1 ) ) ) { - exp = 15; - move16(); + Q_shb = sub( Q_synth_hf, 4 ); + st_fx->EnergyLT_fx = L_shr( st_fx->EnergyLT_fx, sub( st_fx->EnergyLT_fx_exp, shl( Q_shb, 1 ) ) ); + move32(); } ELSE { - exp = norm_s( max ); - } - Copy_Scale_sig( &yorig_fx[scl], &yorig_fx[scl], sub( inner_frame, scl ), exp ); - Q_synth_hf = add( exp, Q_synth ); - - test(); - IF( EQ_16( st_fx->last_extl, SWB_BWE ) || EQ_16( st_fx->last_extl, FB_BWE ) ) - { - exp = norm_l( st_fx->EnergyLT_fx ); - IF( GT_16( add( st_fx->EnergyLT_fx_exp, exp ), shl( sub( Q_synth_hf, 4 ), 1 ) ) ) - { - Q_shb = sub( Q_synth_hf, 4 ); - st_fx->EnergyLT_fx = L_shr( st_fx->EnergyLT_fx, sub( st_fx->EnergyLT_fx_exp, shl( Q_shb, 1 ) ) ); - move32(); - } - ELSE + Q_shb = shr( add( st_fx->EnergyLT_fx_exp, exp ), 1 ); + if ( EQ_16( s_and( exp, 0x0001 ), 1 ) ) { - Q_shb = shr( add( st_fx->EnergyLT_fx_exp, exp ), 1 ); - if ( EQ_16( s_and( exp, 0x0001 ), 1 ) ) - { - exp = sub( exp, 1 ); - } - st_fx->EnergyLT_fx = L_shl( st_fx->EnergyLT_fx, exp ); - move32(); + exp = sub( exp, 1 ); } + st_fx->EnergyLT_fx = L_shl( st_fx->EnergyLT_fx, exp ); + move32(); } - ELSE - { - Q_shb = sub( Q_synth_hf, 4 ); - } +} +ELSE +{ + Q_shb = sub( Q_synth_hf, 4 ); +} + +#ifdef HARM_FD_BWE +IF( st_fx->element_mode == EVS_MONO ) +{ + Copy_Scale_sig( new_input_hp_fx, new_input_hp_fx, L_FRAME16k, sub( Q_shb, Q_shb_speech ) ); + + Qenc_synth_hf = Q_synth_hf; + Qenc_synth = Q_synth; + move16(); + move16(); +} +ELSE +{ Copy_Scale_sig( new_input_hp_fx, new_input_hp_fx, L_FRAME16k, sub( Q_shb, q_new_input_hp ) ); - /* FB BWE encoding */ - IF( EQ_16( st_fx->extl, FB_BWE ) ) - { - fb_band_begin = FB_BAND_BEGIN; - move16(); - if ( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - fb_band_begin = FB_BAND_BEGIN_12k8; - move16(); - } - energy_fbe_fb_fx = L_deposit_l( 0 ); - FOR( i = fb_band_begin; i < FB_BAND_END; i++ ) - { - tmp = shr( yorig_fx[i], 4 ); - energy_fbe_fb_fx = L_mac0( energy_fbe_fb_fx, tmp, tmp ); /*2*(Q_synth_hf-4) */ - } - ener_low_fx = 0; - move16(); - FOR( i = fb_band_begin - FB_BAND_WIDTH; i < fb_band_begin; i++ ) - { - tmp = shr( yorig_fx[i], 4 ); - ener_low_fx = L_mac0( ener_low_fx, tmp, tmp ); /*2*(Q_synth_hf-4) */ - } + Qenc_synth_hf = new_input_fx_q; + Qenc_synth = new_input_fx_q; + move16(); + move16(); +} - IF( energy_fbe_fb_fx != 0 ) - { - exp = norm_l( energy_fbe_fb_fx ); - frac = extract_h( L_shl( energy_fbe_fb_fx, exp ) ); - tmp = div_s( 16384, frac ); /*15+14-(exp+2*(Q_synth_hf-4)-16) -->45-(exp+2*(Q_synth_hf-4)) */ - L_tmp = Mult_32_16( ener_low_fx, tmp ); /*45-(exp+2*(Q_synth_hf-4)) + 2*(Q_synth_hf-4) - 15 = 30-exp */ - exp1 = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp1 ); - exp = sub( sub( 31, exp1 ), sub( 30, exp ) ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ - fb_ener_adjust_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ - } - ELSE - { - fb_ener_adjust_fx = 0; - move16(); - } +/* SWB BWE encoding */ +IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) +{ + SWB_BWE_encoding_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, Qenc_synth_hf, Qenc_synth ); +} +ELSE +{ + SWB_BWE_encoding_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, Qenc_synth_hf, Qenc_synth ); +} +#else + Copy_Scale_sig( new_input_hp_fx, new_input_hp_fx, L_FRAME16k, sub( Q_shb, q_new_input_hp ) ); +#endif - fb_ener_adjust_fx = s_min( fb_ener_adjust_fx, 16384 ); /*Q15 */ - idxGain = usquant_fx( fb_ener_adjust_fx, &ener_adjust_quan_fx, 0, 512, shl( 1, NUM_BITS_FB_FRAMEGAIN ) ); +/* FB BWE encoding */ +IF( EQ_16( st_fx->extl, FB_BWE ) ) +{ + fb_band_begin = FB_BAND_BEGIN; + move16(); + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) + { + fb_band_begin = FB_BAND_BEGIN_12k8; + move16(); + } + energy_fbe_fb_fx = L_deposit_l( 0 ); + FOR( i = fb_band_begin; i < FB_BAND_END; i++ ) + { + tmp = shr( yorig_fx[i], 4 ); + energy_fbe_fb_fx = L_mac0( energy_fbe_fb_fx, tmp, tmp ); /*2*(Q_synth_hf-4) */ + } + ener_low_fx = 0; + move16(); + FOR( i = fb_band_begin - FB_BAND_WIDTH; i < fb_band_begin; i++ ) + { + tmp = shr( yorig_fx[i], 4 ); + ener_low_fx = L_mac0( ener_low_fx, tmp, tmp ); /*2*(Q_synth_hf-4) */ } - /* SWB BWE encoding */ - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + IF( energy_fbe_fb_fx != 0 ) { - SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, - SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, new_input_fx_q, new_input_fx_q ); + exp = norm_l( energy_fbe_fb_fx ); + frac = extract_h( L_shl( energy_fbe_fb_fx, exp ) ); + tmp = div_s( 16384, frac ); /*15+14-(exp+2*(Q_synth_hf-4)-16) -->45-(exp+2*(Q_synth_hf-4)) */ + L_tmp = Mult_32_16( ener_low_fx, tmp ); /*45-(exp+2*(Q_synth_hf-4)) + 2*(Q_synth_hf-4) - 15 = 30-exp */ + exp1 = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp1 ); + exp = sub( sub( 31, exp1 ), sub( 30, exp ) ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ + fb_ener_adjust_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ } ELSE { - SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, - SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, new_input_fx_q, new_input_fx_q ); + fb_ener_adjust_fx = 0; + move16(); } + fb_ener_adjust_fx = s_min( fb_ener_adjust_fx, 16384 ); /*Q15 */ + idxGain = usquant_fx( fb_ener_adjust_fx, &ener_adjust_quan_fx, 0, 512, shl( 1, NUM_BITS_FB_FRAMEGAIN ) ); +} - /* write FB BWE frame gain to the bitstream */ - IF( EQ_16( st_fx->extl, FB_BWE ) ) - { - push_indice( st_fx->hBstr, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); - } +#ifndef HARM_FD_BWE +/* SWB BWE encoding */ +IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) +{ + SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, new_input_fx_q, new_input_fx_q ); +} +ELSE +{ + SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, new_input_fx_q, new_input_fx_q ); +} - return; +#endif +/* write FB BWE frame gain to the bitstream */ +IF( EQ_16( st_fx->extl, FB_BWE ) ) +{ + push_indice( st_fx->hBstr, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); +} + +return; } +#ifndef HARM_FD_BWE /*-------------------------------------------------------------------* * swb_bwe_enc() * @@ -818,33 +960,35 @@ void swb_bwe_enc_fx( return; } - +#endif /*==========================================================================*/ -/* FUNCTION : static Word16 WB_BWE_fenv_q_fx() */ +/* FUNCTION : static Word16 WB_BWE_fenv_q_fx() */ /*--------------------------------------------------------------------------*/ -/* PURPOSE : Scalar quantizer routine */ +/* PURPOSE : Scalar quantizer routine */ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 *cb i: quantizer codebook Q10 */ -/* Word16 cb_length i: length of codebook */ -/* Word16 cb_dim i: dimension of codebook */ +/* INPUT ARGUMENTS : */ +/* Word16 *cb i: quantizer codebook Q10 */ +/* Word16 cb_length i: length of codebook */ +/* Word16 cb_dim i: dimension of codebook */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word16 *x i/o: energy of WB envelop Q10 */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* Word16 *x i/o: energy of WB envelop Q10 */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ -/* */ +/* */ /*==========================================================================*/ -static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain index */ - Word16 *x, /* i/o: energy of WB envelop Q10*/ - const Word16 *cb, /* i: quantizer codebook Q10 */ - const Word16 cb_length, /* i: length of codebook */ - const Word16 cb_dim /* i: dimension of codebook */ + +/* o: quantized gain index */ +static Word16 WB_BWE_fenv_q_fx( + Word16 *x, /* i/o: energy of WB envelop Q10*/ + const Word16 *cb, /* i : quantizer codebook Q10*/ + const Word16 cb_length, /* i : length of codebook */ + const Word16 cb_dim /* i : dimension of codebook */ ) { Word16 i, j, indx = 0; @@ -885,6 +1029,13 @@ static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain i return ( indx ); } + +/*-------------------------------------------------------------------* + * get_normalize_spec_fx() + * + * + *-------------------------------------------------------------------*/ + static void get_normalize_spec_fx( const Word16 core, /* i : core selected */ const Word16 extl, /* i : extension layer selected */ @@ -978,13 +1129,14 @@ static void get_normalize_spec_fx( * classify signal of above 6.4kHz, can be used for WB/SWB switch *-------------------------------------------------------------------*/ -static Word16 FD_BWE_class_fx( /* o : FD BWE class */ - const Word16 *fSpectrum, /* i : input spectrum */ - const Word32 fGain, /* i : global gain */ - const Word16 tilt_nb, /* i : BWE tilt */ - Word16 Q_syn, - Word16 Q_shb, - Encoder_State *st_fx /* i/o: Encoder structure */ +/* o: FD BWE class */ +static Word16 FD_BWE_class_fx( + const Word16 *fSpectrum, /* i : input spectrum */ + const Word32 fGain, /* i : global gain */ + const Word16 tilt_nb, /* i : BWE tilt */ + const Word16 Q_syn, + const Word16 Q_shb, + Encoder_State *st_fx /* i/o: Encoder structure */ ) { Word16 i, j, k, noise, sharpMod = 0; @@ -1256,6 +1408,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class * freq_weights_fx() * *-------------------------------------------------------------------*/ + static void freq_weights_fx( const Word16 Band_Ener[], /* i : Band energy Q8 */ const Word16 f_weighting[], /* i : weigting coefs. Q15 */ @@ -1324,6 +1477,7 @@ static void freq_weights_fx( * vqWithCand_w_fx() * *-------------------------------------------------------------------*/ + static void vqWithCand_w_fx( const Word16 *x, /* i : input vector Q8 */ const Word16 *E_ROM_dico, /* i : codebook Q8 */ @@ -1519,7 +1673,6 @@ static Word16 vqSimple_w_fx( } } - /* Reading the selected vector */ Copy( &cb[index * dim], y, dim ); @@ -1531,11 +1684,11 @@ static Word16 vqSimple_w_fx( * MSVQ_Interpol_Tran_fx() * *-------------------------------------------------------------------*/ + static void MSVQ_Interpol_Tran_fx( - Word16 *SWB_env_energy, /* i/o : (original/quantized) energy Q8 */ - Word16 *indice /* o : quantized index */ + Word16 *SWB_env_energy, /* i/o: (original/quantized) energy Q8 */ + Word16 *indice /* o : quantized index */ ) - { Word16 k, n_band, candInd[N_CAND_TR], ind_tmp[2], tmp; Word16 env_temp11[SWB_FENV_TRANS / 2], env_temp12[SWB_FENV_TRANS / 2]; @@ -1617,6 +1770,7 @@ static void MSVQ_Interpol_Tran_fx( move16(); } } + return; } @@ -1752,6 +1906,7 @@ static void msvq_interpol_fx( * msvq_interpol_2_fx() * *-------------------------------------------------------------------*/ + static void msvq_interpol_2_fx( Word16 *hq_generic_fenv, /* i/o: (original/quantized) energy */ const Word16 *w_env, /* i : weighting coffecients */ @@ -1896,11 +2051,14 @@ static void msvq_interpol_2_fx( *-------------------------------------------------------------------*/ static void calculate_Tonality_fx( - const Word16 *org, /* i : MDCT coefficients of original Q_new*/ - const Word16 *gen, /* i : MDCT coefficients of generated signal Q15*/ - Word16 *SFM_org, /* o : Spectral Flatness results Q12*/ - Word16 *SFM_gen, /* o : Spectral Flatness results Q12*/ - const Word16 length /* i : length for calculating tonality */ +#ifdef HARM_FD_BWE + const Word16 element_mode, /* i : element mode */ +#endif + const Word16 *org, /* i : MDCT coefficients of original Q_new*/ + const Word16 *gen, /* i : MDCT coefficients of generated signal Q15*/ + Word16 *SFM_org, /* o : Spectral Flatness results Q12*/ + Word16 *SFM_gen, /* o : Spectral Flatness results Q12*/ + const Word16 length /* i : length for calculating tonality */ ) { Word16 n_coeff; @@ -1937,19 +2095,40 @@ static void calculate_Tonality_fx( } } +#ifdef HARM_FD_BWE max = 0; move16(); - FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + IF( element_mode == EVS_MONO ) { - gen_spec[n_coeff] = abs_s( gen[n_coeff] ); - move16(); /*Q15 */ - /*test(); - if( sub(max,gen_spec[n_coeff]) < 0) +#endif + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) { - max = gen_spec[n_coeff];move16(); - }*/ - max = s_max( max, org_spec[n_coeff] ); + gen_spec[n_coeff] = abs_s( gen[n_coeff] ); + move16(); /*Q15 */ + /*test(); + if( sub(max,gen_spec[n_coeff]) < 0) + { + max = gen_spec[n_coeff];move16(); + }*/ + max = s_max( max, org_spec[n_coeff] ); + } +#ifdef HARM_FD_BWE } + ELSE + { + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + gen_spec[n_coeff] = abs_s( gen[n_coeff] ); + move16(); /*Q15 */ + /*test(); + if( sub(max,gen_spec[n_coeff]) < 0) + { + max = gen_spec[n_coeff];move16(); + }*/ + max = s_max( max, gen_spec[n_coeff] ); + } + } +#endif l_shift = norm_s( max ); FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) { @@ -2043,6 +2222,7 @@ static void calculate_Tonality_fx( return; } +#ifndef HARM_FD_BWE /*-------------------------------------------------------------------* * calculate_Tonality_ivas_fx() * @@ -2196,6 +2376,7 @@ static void calculate_Tonality_ivas_fx( return; } +#endif /*-------------------------------------------------------------------* * energy_control_fx() @@ -2267,8 +2448,13 @@ static void energy_control_fx( FOR( n_band = 0; n_band < max_band; ) { - calculate_Tonality_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, +#ifdef HARM_FD_BWE + calculate_Tonality_fx( st_fx->element_mode, org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] ); +#else + calculate_Tonality_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, + &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] ); +#endif IF( LT_16( SFM_gen_fx[n_band], mult_r( 24576, SFM_org_fx[n_band] ) ) ) { @@ -2286,9 +2472,11 @@ static void energy_control_fx( } n_band = add( n_band, band_step ); } + return; } +#ifndef HARM_FD_BWE /*-------------------------------------------------------------------* * energy_control_ivas_fx() * @@ -2381,6 +2569,7 @@ static void energy_control_ivas_fx( } return; } +#endif /*-------------------------------------------------------------------* * WB_BWE_encoding() @@ -2388,13 +2577,15 @@ static void energy_control_ivas_fx( * WB BWE main encoder *-------------------------------------------------------------------*/ -Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ - const Word16 coder_type, /* i : coder type */ - const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ - Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ - Encoder_State *st_fx, /* i/o: Encoder structure */ - Word16 Q_synth, - Word16 Q_synth_lf ) +/* o : classification of wb signal */ +static Word16 WB_BWE_encoding_fx( +#ifndef HARM_FD_BWE + const Word16 coder_type, /* i : coder type */ + const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ + Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ + Encoder_State *st_fx, /* i/o: Encoder structure */ + const Word16 Q_synth, + const Word16 Q_synth_lf ) { Word16 mode; Word16 i, n_coeff, n_band; @@ -2454,17 +2645,19 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb } /*-------------------------------------------------------------------* - * WB_BWE_encoding_ivas() + * WB_BWE_encoding() * * WB BWE main encoder *-------------------------------------------------------------------*/ -Word16 WB_BWE_encoding_ivas_fx( /* o : classification of wb signal */ - Encoder_State *st_fx, /* i/o: Encoder structure */ - const Word32 *yos_fx, /* i : MDCT coefficients of weighted original */ - Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ - Word16 Q_synth, - Word16 Q_synth_lf ) +/* o : classification of wb signal */ +static Word16 WB_BWE_encoding_ivas_fx( +#endif + Encoder_State *st_fx, /* i/o: Encoder structure */ + const Word32 *yos_fx, /* i : MDCT coefficients of weighted original */ + Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ + Word16 Q_synth, + const Word16 Q_synth_lf ) { Word16 mode; Word16 i, n_coeff, n_band; @@ -2479,46 +2672,115 @@ Word16 WB_BWE_encoding_ivas_fx( /* o : classification of Word16 q_shift, scale; Word16 q_WB_fenv[2]; Word16 yos_fx_16[L_FRAME16k]; - n_band = 0; - move16(); - FOR( i = 0; i < 2; i++ ) +#ifdef HARM_FD_BWE + Word16 Q_class, Q_energy, Q_fenv[2]; + + IF( st_fx->element_mode == EVS_MONO ) { - energy_fx_64 = 0; - move64(); - FOR( n_coeff = swb_bwe_subband[n_band]; n_coeff < swb_bwe_subband[n_band + 2]; n_coeff++ ) + Word16 new_input_fx_exp = Q_synth; + + /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ + scale = sub( 16 + 8 /*MAX_Q_NEW_INPUT*/, new_input_fx_exp ); + + /* Possible to Upscale? */ + IF( scale > 0 ) { - energy_fx_64 = W_add( energy_fx_64, W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ) ); /*2*Q_synth*/ + /* Yes */ + /* Calc Room to Upscale */ + Q_synth = Find_Max_Norm32( yos_fx, L_FRAME16k ); + + /* Stay within MAX_Q_NEW_INPUT */ + scale = s_min( Q_synth, scale ); } - q_shift = W_norm( energy_fx_64 ); - energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ - q_shift = sub( q_shift, 32 ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, L_FRAME16k, scale ); + Q_synth = sub( add( sub( new_input_fx_exp, 16 ), scale ), 1 ); - L_WB_fenv_fx[i] = energy_fx; - move32(); - q_WB_fenv[i] = add( shl( Q_synth, 1 ), q_shift ); + n_band = 0; + move16(); + FOR( i = 0; i < 2; i++ ) + { + energy_fx = L_deposit_l( 0 ); + FOR( n_coeff = swb_bwe_subband[n_band]; n_coeff < swb_bwe_subband[n_band + 2]; n_coeff++ ) + { + energy_fx = L_add( energy_fx, L_shr( L_mult0( yos_fx_16[n_coeff], yos_fx_16[n_coeff] ), 6 ) ); /*2*Q_synth-6 */ + } + + L_WB_fenv_fx[i] = energy_fx; + move32(); /*2*Q_synth-6 */ + n_band = add( n_band, 2 ); + } + + Q_class = Q_synth; + Q_energy = Q_synth; + move16(); + move16(); + Q_fenv[0] = Q_fenv[1] = sub( shl( Q_synth, 1 ), 2 ); move16(); - n_band = add( n_band, 2 ); } + ELSE +#endif + { + n_band = 0; + move16(); + FOR( i = 0; i < 2; i++ ) + { + energy_fx_64 = 0; + move64(); + FOR( n_coeff = swb_bwe_subband[n_band]; n_coeff < swb_bwe_subband[n_band + 2]; n_coeff++ ) + { + energy_fx_64 = W_add( energy_fx_64, W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ) ); /*2*Q_synth*/ + } + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); + + L_WB_fenv_fx[i] = energy_fx; + move32(); + q_WB_fenv[i] = add( shl( Q_synth, 1 ), q_shift ); + move16(); + n_band = add( n_band, 2 ); + +#ifdef HARM_FD_BWE + Q_fenv[i] = add( q_WB_fenv[i], 4 ); +#endif + } - scale = s_min( L_norm_arr( yos_fx, L_FRAME16k ), sub( Q27, Q_synth ) /* To accomodate 10 in Q_synth*/ ); - Copy_Scale_sig32_16( yos_fx, yos_fx_16, L_FRAME16k, scale ); + scale = s_min( L_norm_arr( yos_fx, L_FRAME16k ), sub( Q27, Q_synth ) /* To accomodate 10 in Q_synth*/ ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, L_FRAME16k, scale ); +#ifdef HARM_FD_BWE + Q_class = sub( add( Q_synth, scale ), Q16 ); + Q_energy = sub( add( Q_synth_lf, scale ), Q16 ); +#endif + } - mode = FD_BWE_class_fx( yos_fx_16, 0, 0, sub( add( Q_synth, scale ), Q16 ), 0, st_fx ); +#ifdef HARM_FD_BWE + mode = FD_BWE_class_fx( yos_fx_16, 0, 0, Q_class, 0, st_fx ); +#else + mode = FD_BWE_class_fx( yos_fx_16, 0, 0, sub( add( Q_synth, scale ), Q16 ), 0, st_fx ); +#endif - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx_16, 0, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) ); +#ifdef HARM_FD_BWE + energy_control_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx_16, 0, energy_factor_fx, Q_energy ); +#else + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx_16, 0, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) ); +#endif FOR( i = 0; i < 2; i++ ) { - ener_40 = mult_r( shr( energy_factor_fx[shl( i, 1 )], 1 ), 26214 ); /*Q19 */ - L_tmp = Mpy_32_16_1( L_WB_fenv_fx[i], ener_40 ); /*q_WB_fenv[i]+4 */ + ener_40 = mult_r( shr( energy_factor_fx[shl( i, 1 )], 1 ), 26214 ); /* Q19 */ + L_tmp = Mpy_32_16_1( L_WB_fenv_fx[i], ener_40 ); /* 2*Q_synth-2 / q_WB_fenv[i]+4 */ IF( L_tmp ) { exp = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - /*exp = 30-exp-(q_WB_fenv[i]+4); */ - exp = sub( sub( 30, exp ), ( add( q_WB_fenv[i], 4 ) ) ); + /* exp = 30-exp-(2*Q_synth-2 / exp = 30-exp-(q_WB_fenv[i]+4) */ +#ifdef HARM_FD_BWE + exp = sub( sub( 30, exp ), Q_fenv[i] ); +#else + exp = sub( sub( 30, exp ), ( add( q_WB_fenv[i], 4 ) ) ); +#endif L_tmp = Mpy_32_16( exp, tmp, 32767 ); /* Q16 */ - WB_fenv_fx[i] = round_fx( L_shl( L_tmp, 10 ) ); /*Q10 */ + WB_fenv_fx[i] = round_fx( L_shl( L_tmp, 10 ) ); /* Q10 */ move16(); } ELSE @@ -2540,7 +2802,9 @@ Word16 WB_BWE_encoding_ivas_fx( /* o : classification of * * SWB BWE encoder *-------------------------------------------------------------------*/ + static Word16 SWB_BWE_encoding_fx( +#ifndef HARM_FD_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *insig_fx, /* i : delayed original input signal at 32kHz */ const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ @@ -2551,10 +2815,10 @@ static Word16 SWB_BWE_encoding_fx( const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ const Word16 coder_type, /* i : coding type */ - Word16 Q_insig_lp, - Word16 Q_shb, - Word16 Q_synth, - Word16 Q_synth_lf ) + const Word16 Q_insig_lp, + const Word16 Q_shb, + const Word16 Q_synth, + const Word16 Q_synth_lf ) { Word16 IsTransient, mode; Word16 index; @@ -2977,22 +3241,27 @@ static Word16 SWB_BWE_encoding_fx( /*-------------------------------------------------------------------* * SWB_BWE_encoding() * - * SWB BWE encoder + * SWB BWE encoder, 32-bit variant *-------------------------------------------------------------------*/ + static Word16 SWB_BWE_encoding_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *insig_fx, /* i : delayed original input signal at 32kHz */ const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word32 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ - Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ - const Word16 tilt_nb_fx, /* i : SWB tilt */ - const Word16 st_offset, /* i : start frequency offset for BWE envelope */ - Word16 Q_insig_lp, - Word16 Q_shb, - Word16 Q_synth, - Word16 Q_synth_lf ) +#ifdef HARM_FD_BWE + const Word16 *yos_fx_16_orig, /* i : 16-bit MDCT coefficients of the windowed original input signal at 32kHz */ +#endif + const Word32 *yos_fx, /* i : 32-bit MDCT coefficients of the windowed original input signal at 32kHz */ + Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ + const Word16 tilt_nb_fx, /* i : SWB tilt */ + const Word16 st_offset, /* i : start frequency offset for BWE envelope */ + const Word16 Q_insig_lp, + const Word16 Q_shb, + const Word16 Q_synth, + const Word16 Q_synth_lf ) { Word16 IsTransient, mode; Word16 index; @@ -3021,6 +3290,9 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 inner_frame; Word16 q_shift; Word16 yos_fx_16[L_FRAME_MAX]; +#ifdef HARM_FD_BWE + Word16 Q_class, Q_energy; +#endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -3047,6 +3319,13 @@ static Word16 SWB_BWE_encoding_ivas_fx( move16(); } +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( yos_fx_16_orig, yos_fx_16, inner_frame ); + } +#endif + /* HF transient detect */ IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx ); st_fx->EnergyLT_fx_exp = shl( Q_shb, 1 ); @@ -3061,19 +3340,37 @@ static Word16 SWB_BWE_encoding_ivas_fx( energy_fx = L_deposit_l( 0 ); FOR( i = 0; i < L; i++ ) { - energy_fx = L_add( energy_fx, L_shr( L_mult0( insig_lp_fx[i + tmp], insig_lp_fx[i + tmp] ), 7 ) ); /*Q = 2 * Q_insig_lp - 7 */ + energy_fx = L_add( energy_fx, L_shr( L_mult0( insig_lp_fx[i + tmp], insig_lp_fx[i + tmp] ), 7 ) ); /*Q = 2*Q_slb_speech - 7 / 2*Q_insig_lp - 7 */ } - if ( BASOP_Util_Cmp_Mant32Exp( Mpy_32_16_1( energy_fx, 5958 /* 1/5.5f in Q15 */ ), sub( 31 + 7, shl( Q_insig_lp, 1 ) ), hBWE_FD->EnergyLF_fx, hBWE_FD->EnergyLF_exp ) > 0 ) +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) { - IsTransient_LF = 1; + if ( GT_32( Mult_32_16( energy_fx, 5958 ), hBWE_FD->EnergyLF_fx ) ) + { + IsTransient_LF = 1; + move16(); + } + + hBWE_FD->EnergyLF_fx = energy_fx; + hBWE_FD->EnergyLF_exp = sub( 31 + 7, shl( Q_insig_lp, 1 ) ); + move32(); move16(); } + ELSE +#endif + { + if ( BASOP_Util_Cmp_Mant32Exp( Mpy_32_16_1( energy_fx, 5958 /* 1/5.5f in Q15 */ ), sub( 31 + 7, shl( Q_insig_lp, 1 ) ), hBWE_FD->EnergyLF_fx, hBWE_FD->EnergyLF_exp ) > 0 ) + { + IsTransient_LF = 1; + move16(); + } - hBWE_FD->EnergyLF_fx = energy_fx; - hBWE_FD->EnergyLF_exp = sub( 31 + 7, shl( Q_insig_lp, 1 ) ); - move32(); - move16(); + hBWE_FD->EnergyLF_fx = energy_fx; + hBWE_FD->EnergyLF_exp = sub( 31 + 7, shl( Q_insig_lp, 1 ) ); + move32(); + move16(); + } } /* tilt returned in Q24 go to Q11 */ @@ -3095,48 +3392,87 @@ static Word16 SWB_BWE_encoding_ivas_fx( push_indice( hBstr, IND_SWB_CLASS, mode, 2 ); /* Energy for the different bands and global energies */ - global_gain_fx = L_deposit_l( 0 ); - FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) { - energy_fx_64 = W_deposit32_l( 0 ); - FOR( n_coeff = swb_bwe_trans_subband[n_band] + st_offset; n_coeff < swb_bwe_trans_subband[n_band + 1] + st_offset; n_coeff++ ) + global_gain_fx = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ - energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ + energy_fx = L_deposit_l( 0 ); + FOR( n_coeff = swb_bwe_trans_subband[n_band] + st_offset; n_coeff < swb_bwe_trans_subband[n_band + 1] + st_offset; n_coeff++ ) + { + L_tmp = L_shr( L_mult0( yos_fx_16[n_coeff], yos_fx_16[n_coeff] ), 7 ); /*2*Q_synth-7 */ + energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-7 */ + } + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( sub( shl( Q_synth, 1 ), 7 ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + L_SWB_fenv_fx[n_band] = energy_fx; + move32(); } - q_shift = W_norm( energy_fx_64 ); - energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ - q_shift = sub( q_shift, 32 ); - global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ - L_SWB_fenv_fx[n_band] = energy_fx; - move32(); - IF( L_SWB_fenv_fx[n_band] == 0 ) + global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ + + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - q_SWB_fenv[n_band] = Q31; - move16(); + expd = norm_s( swb_bwe_trans_subband_width[n_band] ); + tmp = div_s( shl( 1, sub( 14, expd ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-expd) */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*2*Q_synth-7+29-expd - 15 */ + exp = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), sub( add( shl( Q_synth, 1 ), 7 ), expd ) ); + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ + + SWB_fenv_fx[n_band] = sub( tmp, Mean_env_tr_fx[n_band] ); + move16(); /*Q8 */ } - ELSE + } + ELSE +#endif + { + global_gain_fx = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); - move16(); + energy_fx_64 = W_deposit32_l( 0 ); + FOR( n_coeff = swb_bwe_trans_subband[n_band] + st_offset; n_coeff < swb_bwe_trans_subband[n_band + 1] + st_offset; n_coeff++ ) + { + W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ + energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ + } + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); + + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + L_SWB_fenv_fx[n_band] = energy_fx; + move32(); + IF( L_SWB_fenv_fx[n_band] == 0 ) + { + q_SWB_fenv[n_band] = Q31; + move16(); + } + ELSE + { + q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); + move16(); + } } - } - global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) - { - expd = norm_s( swb_bwe_trans_subband_width[n_band] ); - tmp = div_s( shl( 1, sub( 14, expd ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-expd) */ - L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*q_SWB_fenv[n_band]+29-expd - 15 */ - exp = norm_l( L_tmp ); - tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), sub( add( q_SWB_fenv[n_band], Q14 ), expd ) ); - L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ - tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ + global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - SWB_fenv_fx[n_band] = sub( tmp, Mean_env_tr_fx[n_band] ); - move16(); /*Q8 */ + FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) + { + expd = norm_s( swb_bwe_trans_subband_width[n_band] ); + tmp = div_s( shl( 1, sub( 14, expd ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-expd) */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*q_SWB_fenv[n_band]+29-expd - 15 */ + exp = norm_l( L_tmp ); + tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), sub( add( q_SWB_fenv[n_band], Q14 ), expd ) ); + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ + + SWB_fenv_fx[n_band] = sub( tmp, Mean_env_tr_fx[n_band] ); + move16(); /*Q8 */ + } } WB_tenv_orig_fx = L_deposit_l( 0 ); @@ -3183,7 +3519,17 @@ static Word16 SWB_BWE_encoding_ivas_fx( expd = norm_l( WB_tenv_syn_fx ); den = round_fx_sat( L_shl( WB_tenv_syn_fx, expd ) ); - expd = sub( sub( 30, expd ), sub( shl( Q_insig_lp, 1 ), 7 ) ); + +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + expd = sub( sub( 30, expd ), sub( shl( st_fx->Q_syn2, 1 ), 7 ) ); + } + ELSE +#endif + { + expd = sub( sub( 30, expd ), sub( shl( Q_insig_lp, 1 ), 7 ) ); + } scale = shr( sub( den, num ), 15 ); num = shl( num, scale ); @@ -3376,48 +3722,103 @@ static Word16 SWB_BWE_encoding_ivas_fx( ELSE { /* Energy for the different bands and global energies */ - global_gain_fx = L_deposit_l( 0 ); - FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) { - energy_fx_64 = W_deposit32_l( 0 ); - FOR( n_coeff = swb_bwe_subband[n_band] + st_offset; n_coeff < swb_bwe_subband[n_band + 1] + st_offset; n_coeff++ ) + global_gain_fx = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ - energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ + energy_fx = L_deposit_l( 0 ); + FOR( n_coeff = swb_bwe_subband[n_band] + st_offset; n_coeff < swb_bwe_subband[n_band + 1] + st_offset; n_coeff++ ) + { + L_tmp = L_shr( L_mult0( yos_fx_16[n_coeff], yos_fx_16[n_coeff] ), 5 ); /*2*Q_synth-5 */ + energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-5 */ + } + + IF( LT_16( n_band, sub( SWB_FENV, 2 ) ) ) + { + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( 2 * Q_synth - 5, 2 * Q_shb ) ) ); /*2*Q_shb */ + } + L_SWB_fenv_fx[n_band] = energy_fx; + move32(); } - q_shift = W_norm( energy_fx_64 ); - energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ - q_shift = sub( q_shift, 32 ); - IF( LT_16( n_band, SWB_FENV - 2 ) ) + Q_class = Q_synth; + Q_energy = Q_synth_lf; + move16(); + move16(); + } + ELSE +#endif + { + global_gain_fx = L_deposit_l( 0 ); + FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + energy_fx_64 = W_deposit32_l( 0 ); + FOR( n_coeff = swb_bwe_subband[n_band] + st_offset; n_coeff < swb_bwe_subband[n_band + 1] + st_offset; n_coeff++ ) + { + W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ + energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ + } + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); + + IF( LT_16( n_band, SWB_FENV - 2 ) ) + { + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + } + L_SWB_fenv_fx[n_band] = energy_fx; + move32(); + q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); + move16(); } - L_SWB_fenv_fx[n_band] = energy_fx; - move32(); - q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); - move16(); + +#ifdef HARM_FD_BWE + scale = s_min( L_norm_arr( yos_fx, inner_frame ), sub( Q27, Q_synth ) /* To accomodate 10 in Q_synth*/ ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, scale ); + + Q_class = sub( add( Q_synth, scale ), Q16 ); + Q_energy = sub( add( Q_synth_lf, scale ), Q16 ); +#endif } global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - scale = s_min( L_norm_arr( yos_fx, inner_frame ), sub( Q27, Q_synth ) /* To accomodate 10 in Q_synth*/ ); - Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, scale ); - mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, scale ), Q16 ), Q_shb, st_fx ); +#ifdef HARM_FD_BWE + mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, Q_class, Q_shb, st_fx ); +#else + scale = s_min( L_norm_arr( yos_fx, inner_frame ), sub( Q27, Q_synth ) /* To accomodate 10 in Q_synth*/ ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, scale ); + mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, scale ), Q16 ), Q_shb, st_fx ); +#endif push_indice( hBstr, IND_SWB_CLASS, mode, 2 ); - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) ); +#ifdef HARM_FD_BWE + energy_control_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, Q_energy ); +#else + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) ); +#endif FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /*q_SWB_fenv[n_band] */ - L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*q_SWB_fenv[n_band] */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /* 2*Q_synth-5 / q_SWB_fenv[n_band] */ + L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /* 2*Q_synth-5 / q_SWB_fenv[n_band] */ IF( L_tmp != 0 ) { expn = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, expn ) ); - expn = sub( 30, add( expn, q_SWB_fenv[n_band] ) ); +#ifdef HARM_FD_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + expn = sub( 30, add( expn, sub( shl( Q_synth, 1 ), 5 ) ) ); + } + ELSE +#endif + { + expn = sub( 30, add( expn, q_SWB_fenv[n_band] ) ); + } L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ move16(); @@ -3454,6 +3855,8 @@ static Word16 SWB_BWE_encoding_ivas_fx( return mode; } + + /*-------------------------------------------------------------------* * get_normalize_spec_fx_32() * @@ -3550,6 +3953,7 @@ static void get_normalize_spec_fx_32( * calculate_tonality_fx_32() * *-------------------------------------------------------------------*/ + static void calculate_tonality_fx_32( const Word32 *org_fx, /* i : MDCT coefficients of original : Q12 */ const Word32 *gen_fx, /* i : MDCT coefficients of generated signal : Q12 */ @@ -3682,6 +4086,7 @@ static void calculate_tonality_fx_32( * energy_control_fx_32() * *-------------------------------------------------------------------*/ + static void energy_control_fx_32( Encoder_State *st_fx, /* i/o: encoder structure */ const Word16 core, /* i : core : Q0 */ @@ -3783,6 +4188,7 @@ static void energy_control_fx_32( * decision_hq_generic_class_fx_32() * *-------------------------------------------------------------------*/ + static Word16 decision_hq_generic_class_fx_32( const Word32 *coefs_fx, /* i: original MDCT spectrum : Q12 */ const Word16 hq_generic_offset /* i: frequency offset of high frequency spectrum : Q0 */ @@ -3790,7 +4196,6 @@ static Word16 decision_hq_generic_class_fx_32( { Word16 i, k; Word16 nband; - Word16 inv_band_fx; Word32 L_tmp, L_tmp1, L_tmp2; Word16 exp, tmp, tmp2; @@ -3851,7 +4256,8 @@ static Word16 decision_hq_generic_class_fx_32( } } avgp2a_fx = Mult_32_16( avgp2a_fx, inv_band_fx ); /*16 + 15 - 15 */ - IF( GT_32( avgp2a_fx, 187227 ) ) /*8.6 / 10log10(2), Q16 */ + + IF( GT_32( avgp2a_fx, 187227 ) ) /*8.6 / 10log10(2), Q16 */ { return HQ_GENERIC_EXC1; } @@ -3865,6 +4271,7 @@ static Word16 decision_hq_generic_class_fx_32( * hq_generic_encoding_fx() * *-------------------------------------------------------------------*/ + void hq_generic_encoding_fx( const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q3 */ @@ -3898,7 +4305,6 @@ void hq_generic_encoding_fx( move16(); } - energy_control_fx_32( st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx ); IF( EQ_16( hHQ_core->hq_generic_speech_class, 1 ) ) @@ -4016,7 +4422,6 @@ void hq_generic_encoding_fx( } } - /* Energy VQ */ IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { @@ -4064,7 +4469,6 @@ void hq_generic_encoding_fx( move16(); } - IF( EQ_16( st_fx->bwidth, FB ) ) { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) @@ -4083,6 +4487,7 @@ void hq_generic_encoding_fx( return; } + /*-------------------------------------------------------------------* * fd_bwe_enc_init_fx() * @@ -4129,10 +4534,12 @@ void fd_bwe_enc_init_fx( return; } + /*-------------------------------------------------------------------* - * hq_generic_encoding_fx() + * hq_generic_hf_encoding_fx() * *-------------------------------------------------------------------*/ + void hq_generic_hf_encoding_fx( const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q1 */ @@ -4167,7 +4574,6 @@ void hq_generic_hf_encoding_fx( move16(); } - energy_control_fx_32( st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx ); IF( EQ_16( hHQ_core->hq_generic_speech_class, 1 ) ) @@ -4285,7 +4691,6 @@ void hq_generic_hf_encoding_fx( } } - /* Energy VQ */ IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { @@ -4340,7 +4745,6 @@ void hq_generic_hf_encoding_fx( move16(); } - IF( EQ_16( length, L_SPEC48k ) ) { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index 5fa034fbfa236c4e27737fd1a34a7d4302d800d5..094310cdfb97aaed16f1acfc09f11105c0741451 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index a8b6f0a6df0ed02e1f59f63d68d7e6902c727585..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 @@ -89,10 +89,8 @@ static Word16 GetSubbandCorrIndex2_har_fx( /* o : Word32 L_tmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); -#endif exp_safe_e = 4; move16(); @@ -1026,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() * @@ -1311,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 6a108ce6f24092fd1ad90d79101d5d3c37992e77..9e27f0d74da6cfdea1b68b05c425e92784df64d6 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -1,44 +1,41 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" #include "cnst.h" #include "rom_com.h" -#include "stl.h" #include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#include "basop_util.h" #include "ivas_rom_enc.h" -#include /*========================================================================*/ -/* FUNCTION : wb_pre_proc_fx() */ +/* FUNCTION : wb_pre_proc_fx() */ /*------------------------------------------------------------------------*/ /* PURPOSE : Resampling of input signal when input signal sample rate */ -/* is above 16kHz */ +/* is above 16kHz */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Encoder_State *st_fx : Encoder State Structure */ -/* _ (Word16*) input : original input signal */ +/* INPUT ARGUMENTS : */ +/* Encoder_State *st_fx : Encoder State Structure */ +/* _ (Word16*) input : original input signal */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _ (Word16*) new_wb_speech : original input signal at 16kHz Q-1 */ /*------------------------------------------------------------------------*/ - /* st_fx->old_wtda_wb_fx */ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void wb_pre_proc_fx( +#ifndef HARMONIZE_TBE2 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *new_inp_resamp16k, /* i : original input signal in Q-1 */ Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz in Q-1 */ @@ -170,31 +167,32 @@ void wb_pre_proc_fx( /*========================================================================*/ -/* FUNCTION : wb_pre_proc_ivas_fx() */ +/* FUNCTION : wb_pre_proc_ivas_fx() */ /*------------------------------------------------------------------------*/ /* PURPOSE : Resampling of input signal when input signal sample rate */ -/* is above 16kHz */ +/* is above 16kHz */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Encoder_State *st_fx : Encoder State Structure */ -/* _ (Word16*) input : original input signal */ +/* INPUT ARGUMENTS : */ +/* Encoder_State *st_fx : Encoder State Structure */ +/* _ (Word16*) input : original input signal */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _ (Word16*) new_wb_speech : original input signal at 16kHz Q-1 */ /*------------------------------------------------------------------------*/ /* st_fx->old_wtda_wb_fx */ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void wb_pre_proc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 last_element_mode, /* i : last element mode */ + const Word16 last_element_mode, /* i : last element mode */ const Word16 *new_inp_resamp16k, /* i : original input signal in Q-1 */ Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz in Q-1 */ ) @@ -217,7 +215,6 @@ void wb_pre_proc_ivas_fx( move64(); move64(); - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -265,20 +262,45 @@ void wb_pre_proc_ivas_fx( Q_wb_sp = norm_s( max_wb ); Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, -3 ); - temp1 = W_mac_32_32( temp1, temp_buf[0], temp_buf[0] ); - FOR( i = 1; i < L_FRAME16k; i++ ) + +#ifdef HARMONIZE_TBE2 + IF( st_fx->element_mode == EVS_MONO ) { - temp1 = W_mac_32_32( temp1, temp_buf[i], temp_buf[i] ); - temp2 = W_mac_32_32( temp2, temp_buf[i - 1], temp_buf[i] ); - } - norm = s_min( W_norm( temp1 ), W_norm( temp2 ) ); - tmp1 = W_extract_h( W_shl( temp1, norm ) ); - tmp2 = W_extract_h( W_shl( temp2, norm ) ); + tmp1 = 0; + tmp2 = 0; + move32(); + move32(); + tmp1 = L_mac0( tmp1, temp_buf[0], temp_buf[0] ); + FOR( i = 1; i < L_FRAME16k; i++ ) + { + tmp1 = L_mac0( tmp1, temp_buf[i], temp_buf[i] ); + tmp2 = L_mac0( tmp2, temp_buf[i - 1], temp_buf[i] ); + } - IF( LT_32( tmp2, Mpy_32_16_1( tmp1, 31129 /*0.95f*/ ) ) ) + IF( tmp2 < Mult_32_16( tmp1, 31129 /*0.95f*/ ) ) + { + Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */ + } + } + ELSE +#endif { - Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */ + temp1 = W_mac_32_32( temp1, temp_buf[0], temp_buf[0] ); + FOR( i = 1; i < L_FRAME16k; i++ ) + { + temp1 = W_mac_32_32( temp1, temp_buf[i], temp_buf[i] ); + temp2 = W_mac_32_32( temp2, temp_buf[i - 1], temp_buf[i] ); + } + norm = s_min( W_norm( temp1 ), W_norm( temp2 ) ); + tmp1 = W_extract_h( W_shl( temp1, norm ) ); + tmp2 = W_extract_h( W_shl( temp2, norm ) ); + + IF( LT_32( tmp2, Mpy_32_16_1( tmp1, 31129 /*0.95f*/ ) ) ) + { + Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */ + } } + Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp ); Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp ); Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp ); @@ -417,9 +439,9 @@ void wb_pre_proc_ivas_fx( } /* rescale the hb_speech and memories back to Q-1 to keep the downstream BWE coding unaffected */ - Scale_sig( hb_speech, L_FRAME16k / 4, -Q_wb_sp ); - Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp ); - Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp ); + Scale_sig( hb_speech, L_FRAME16k / 4, negate( Q_wb_sp ) ); + Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), negate( Q_wb_sp ) ); + Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), negate( Q_wb_sp ) ); IF( NE_16( st_fx->extl, WB_TBE ) ) { @@ -439,7 +461,12 @@ void wb_pre_proc_ivas_fx( set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); } +#ifdef HARMONIZE_TBE2 + test(); + if ( hBWE_FD != NULL && st_fx->element_mode != EVS_MONO ) +#else if ( hBWE_FD != NULL ) +#endif { hBWE_FD->mem_old_wtda_swb_fx = new_inp_resamp16k[L_FRAME16k - L_MEM_RECALC_16K - L_FILT16k - 1]; move16(); @@ -449,7 +476,7 @@ void wb_pre_proc_ivas_fx( test(); test(); test(); - IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->total_brate, 0 ) ) ) && !ppp_mode ) + IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->extl_brate, 0 ) ) ) && !ppp_mode ) { Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); @@ -460,41 +487,47 @@ void wb_pre_proc_ivas_fx( IF( NE_16( st_fx->extl, SWB_BWE ) && NE_16( st_fx->extl, FB_BWE ) ) { Copy( old_input, hBWE_FD->L_old_wtda_swb_fx, L_FRAME16k ); - st_fx->Q_old_wtda = -1; - move16(); +#ifdef HARMONIZE_TBE2 + if ( st_fx->element_mode != EVS_MONO ) +#endif + { + st_fx->Q_old_wtda = -Q1; + move16(); + } } } + return; } /*========================================================================*/ -/* FUNCTION : swb_pre_proc_fx() */ +/* FUNCTION : swb_pre_proc_fx() */ /*------------------------------------------------------------------------*/ -/* PURPOSE : Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) */ +/* PURPOSE : Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) */ /* SHB target signal for SWB TBE or SWB BWE coding */ -/* Common SWB TBE and SWB BWE pre-processing */ +/* Common SWB TBE and SWB BWE pre-processing */ /*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Encoder_State *st_fx : Encoder State Structure Q0 */ +/* INPUT ARGUMENTS : */ +/* Encoder_State *st_fx : Encoder State Structure Q0 */ /* _ (Word16*) input_fx : original input signal Q0 */ /*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ /*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ +/* OUTPUT ARGUMENTS : */ /* _ (Word16*) new_swb_speech_fx : original input signal at 16kHz Q0 */ -/* _ (Word16*) shb_speech_fx : original input signal at 16kHz Q0 */ +/* _ (Word16*) shb_speech_fx : original input signal at 16kHz Q0 */ /*------------------------------------------------------------------------*/ - -/* st_fx->old_input_fx */ +/* st_fx->old_input_fx */ /* st_fx->old_wtda_shb_fx */ /*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*========================================================================*/ void swb_pre_proc_fx( +#ifndef HARMONIZE_TBE2 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *input_fx, /* i : original input signal */ Word16 *new_swb_speech_fx, /* o : original input signal at 32kHz */ @@ -521,10 +554,8 @@ void swb_pre_proc_fx( Word16 ts, nB, uB; /* Highband energy computation using CLDFB */ Word32 CldfbHB_ener; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); -#endif Word16 realQ_neg1, imagQ_neg1, exp, Cldfbtemp1; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -581,11 +612,7 @@ void swb_pre_proc_fx( IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) { /* resample 48 kHz to 32kHz */ -#ifdef NONBE_1244_FIX_SWB_BWE_MEMORY IF( ( st_fx->last_bwidth == FB && st_fx->element_mode == EVS_MONO ) || ( EQ_16( st_fx->bwidth, FB ) && st_fx->element_mode > EVS_MONO ) ) // note: once EVS i CR fixed, the condition will simplify to "if ( st->bwidth == FB )" only -#else - IF( EQ_16( st_fx->last_bwidth, FB ) ) -#endif { inner_frame = L_FRAME48k; inner_Fs = 48000; @@ -777,17 +804,18 @@ 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 */ +#endif + 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 */ +#ifdef HARMONIZE_TBE2 + const CLDFB_SCALE_FACTOR *cldfbScale, /* i : scale data of real and imag CLDFB buffers */ +#endif + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ) { Word16 Sample_Delay_SWB_BWE, inner_frame, delay; @@ -811,7 +839,7 @@ void swb_pre_proc_ivas_fx( Word32 lbEner; Word16 exp_lbEner = 0; Word16 Sample_Delay_SWB_BWE32k, lMemRecalc32k, dft_ovl32k; - Word32 one_by_50_Q31 = 42949673; + const Word32 one_by_50_Q31 = 42949673; lMemRecalc32k = NS2SA( 32000, L_MEM_RECALC_NS ); move16(); // exp_lbEner @@ -846,11 +874,12 @@ void swb_pre_proc_ivas_fx( Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE ); Copy( st->input_fx - L_FRAME32k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k ); - test(); - test(); scale_sig( hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( st->q_inp, st->Q_old_wtda ) ); // st->Q_old_wtda -> st->q_inp - st->Q_old_wtda = st->q_inp; + st->Q_old_wtda = st->q_inp; // st->Q_old_wtda = st->q_inp; move16(); + + test(); + test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) ) { Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) ); @@ -885,8 +914,13 @@ void swb_pre_proc_ivas_fx( IF( NE_16( st->extl, WB_BWE ) ) { Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k ); - st->Q_old_wtda = st->q_inp; - move16(); +#ifdef HARMONIZE_TBE2 + if ( st->element_mode > EVS_MONO ) +#endif + { + st->Q_old_wtda = st->q_inp; + move16(); + } } } @@ -898,7 +932,6 @@ void swb_pre_proc_ivas_fx( } ELSE /* 48 kHz */ { - Sample_Delay_SWB_BWE32k = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS ); move16(); Sample_Delay_SWB_BWE = NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS ); @@ -913,7 +946,7 @@ void swb_pre_proc_ivas_fx( dft_ovl32k = 0; move16(); - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { dft_ovl32k = (Word16) ( STEREO_DFT_OVL_MAX * 32000 / 48000 ); move16(); @@ -923,7 +956,6 @@ void swb_pre_proc_ivas_fx( { IF( st->element_mode > EVS_MONO ) { - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { } @@ -988,11 +1020,7 @@ void swb_pre_proc_ivas_fx( IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) { /* resample 48 kHz to 32kHz */ -#ifdef NONBE_1244_FIX_SWB_BWE_MEMORY IF( ( st->last_bwidth == FB && st->element_mode == EVS_MONO ) || ( EQ_16( st->bwidth, FB ) && st->element_mode > EVS_MONO ) ) // note: once EVS i CR fixed, the condition will simplify to "if ( st->bwidth == FB )" only -#else - IF( EQ_16( st->last_bwidth, FB ) ) -#endif { inner_frame = L_FRAME48k; move16(); @@ -1046,6 +1074,13 @@ void swb_pre_proc_ivas_fx( Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, inner_frame ); st->Q_old_wtda = st->q_inp; move16(); +#ifdef HARMONIZE_TBE2 + if ( st->element_mode == EVS_MONO ) + { + st->Q_old_wtda = 0; + move16(); + } +#endif } /* resample 48 kHz to 32kHz */ @@ -1073,6 +1108,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 @@ -1108,10 +1147,8 @@ void swb_pre_proc_ivas_fx( move64(); Word32 CldfbHB_fx = 0; // fixed counterpart Word16 CldfbHB_fx_e = 0; // fixed counterpart -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); -#endif Word16 realQ_neg1, imagQ_neg1, exp = 0, Cldfbtemp1; move32(); move16(); @@ -1137,6 +1174,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 ) ); @@ -1159,8 +1197,130 @@ void swb_pre_proc_ivas_fx( thr = icbwe_thr_DFT_fx; regV = icbwe_regressionValuesDFT_fx; } +#ifdef HARMONIZE_TBE2 + ELSE IF( st->element_mode == EVS_MONO ) + { + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + startB = 34; + move16(); + endB = 14; + move16(); + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + uB = 0; + move16(); + FOR( nB = startB; nB > endB; nB-- ) + { + realBufferFlipped[ts][uB] = realBuffer[ts][nB]; + move32(); + if ( s_and( ts, 1 ) != 0 ) + { + realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] ); + move32(); + } + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + move32(); + if ( s_and( ts, 1 ) == 0 ) + { + imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] ); + move32(); + } + uB = add( uB, 1 ); /* uB ++ */ + } + } + } + ELSE + { + startB = 39; + move16(); + endB = 19; + move16(); + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + uB = 0; + move16(); + FOR( nB = startB; nB > endB; nB-- ) + { + realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] ); + move32(); + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + move32(); + uB = add( uB, 1 ); /* uB ++ */ + } + } + } + + /* Highband energy computation for gain shape control in case of bandwidth switching fix*/ + { + Word32 cldfbWorkBuffer[256]; + + lbEner = 0; + move32(); + FOR( nB = 0; nB < 10; nB++ ) + { + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + realQ_neg1 = extract_l( L_shr( realBufferFlipped[ts][nB], 31 - ( 15 + cldfbScale->hb_scale ) + 1 ) ); + imagQ_neg1 = extract_l( L_shr( imagBufferFlipped[ts][nB], 31 - ( 15 + cldfbScale->hb_scale ) + 1 ) ); /* Q(-1), headroom needed */ + + lbEner = L_mac0_o( lbEner, realQ_neg1, realQ_neg1, &Overflow ); + lbEner = L_mac0_o( lbEner, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */ + } + } + + exp = norm_l( lbEner ); + lbEner = L_shl( lbEner, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ + Cldfbtemp1 = ( Log2_norm_lc( lbEner ) ); + Cldfbtemp1 = add( shr( Cldfbtemp1, 6 ), shl( sub( 30, sub( exp, 2 ) ), 9 ) ); /* Log2_norm_lc(CldfbHB_ener) = 2^15*(log2(CldfbHB_ener/2^30)) = 2^15*(log2(CldfbHB_fl*(2^-2)*2^exp/2^30)) = 2^15*(log2(CldfbHB_fl) + exp-2-30) => 2^(-6)*l2nc + 2^9(20-(exp-2)) = 2^9*log2(CldfbHB_fl), Q9 */ + lbEner = L_mult( sub( Cldfbtemp1, 1741 /*3.401 Q9*/ ), 3495 ); /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */ + hBWE_TD->cldfbHBLT = mac_r( lbEner, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ + + cldfbSynthesis_fx( st->cldfbSynTd, realBufferFlipped, imagBufferFlipped, cldfbScale, shb_speech, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); + } + + test(); + test(); + IF( NE_16( st->extl, WB_TBE ) && NE_16( st->extl, SWB_TBE ) && NE_16( st->extl, FB_TBE ) ) + { + /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ + delay = L_LOOK_16k + L_SUBFR16k; + Copy( shb_speech + L_FRAME16k - delay, hBWE_TD->old_speech_shb_fx, delay ); + } + + thr = 0; // just to avoid warnings + move16(); + regV = 0; // just to avoid warnings + move16(); + } +#endif ELSE { +#ifdef HARMONIZE_TBE2 + /* Scaling cldfb_state_fx */ + Word16 q_shift, scf_cldfb; + scf_cldfb = L_norm_arr( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length ); + + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, scf_cldfb ); + st->cldfbSynTd->Q_cldfb_state = add( st->cldfbSynTd->Q_cldfb_state, scf_cldfb ); + + q_shift = sub( sub( q_reImBuffer, 1 ), st->cldfbSynTd->Q_cldfb_state ); // cldfb_state_fx will be used in cldfbSynthesis_ivas_fx and has to be aligned with (q_re_im_buf[n] - 1) + IF( GT_32( q_shift, 0 ) ) + { + FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + scale_sig32( realBuffer[ts], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); + scale_sig32( imagBuffer[ts], CLDFB_NO_CHANNELS_MAX, negate( q_shift ) ); + } + q_reImBuffer = add( st->cldfbSynTd->Q_cldfb_state, 1 ); + } + ELSE + { + scale_sig32( st->cldfbSynTd->cldfb_state_fx, st->cldfbSynTd->p_filter_length, q_shift ); // st->cldfbSynTd->Q_cldfb_state -> q_realImagBuffer + st->cldfbSynTd->Q_cldfb_state = sub( q_reImBuffer, 1 ); + } + +#endif IF( EQ_16( st->L_frame, L_FRAME ) ) { startB = 34; @@ -1283,9 +1443,10 @@ 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 +#ifdef HARMONIZE_TBE2 + st->cldfbSynTd->Q_cldfb_state = sub( q_reImBuffer, 1 ); +#endif } IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL ) @@ -1303,6 +1464,7 @@ void swb_pre_proc_ivas_fx( t_16 = Log2_norm_lc( t ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */ t_16 = sub( shr( t_16, 6 ), shl( add( sub( Q31 - Q30, exp_t ), exp ), 9 ) ); t = L_mult( t_16, 9864 ); /* Q9 + Q15 + Q1 = Q25 */ + /* Three Level Decision Tree to calculate a regression value first */ IF( LT_32( t, thr[0] ) ) /* level 1 */ { @@ -1448,7 +1610,16 @@ void swb_pre_proc_ivas_fx( } } +#ifdef HARMONIZE_TBE2 + IF( st->element_mode == EVS_MONO ) + { + /* Reset CLDFB synthesis buffer */ + set16_fx( st->cldfbSynTd->FilterStates, 0, st->cldfbSynTd->p_filter_length + st->cldfbSynTd->no_channels * st->cldfbSynTd->no_col ); + } + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) +#else IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) +#endif { /* Reset CLDFB synthesis buffer */ set32_fx( st->cldfbSynTd->cldfb_state_fx, 0, st->cldfbSynTd->p_filter_length ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0dc1ad698662af60efa13bf37c3ddf24066b0ef1..6f270929b46df5377b88b48d896bb3a73a298047 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 *-----------------------------------------------------------------*/ @@ -31,33 +31,27 @@ static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, cons static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); -static void QuantizeSHBsubgains_ivas_fx( Encoder_State *st_fx, Word16 subgains[], const Word16 extl ); - -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 ); +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); 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 ); -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 ); +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 ); 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,21 +59,13 @@ 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 ); -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 ); - -static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_fx_32, Word16 Q_shb ); - -static void Quant_shb_ener_sf_ivas_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, Word16 Q_ener ); - -static void Quant_shb_res_gshape_fx( Encoder_State *st_fx, Word16 *shb_res_gshape_fx ); +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_res_gshape_ivas_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); +static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, const Word16 Q_ener ); -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 Quant_shb_res_gshape_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); -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 */ ); +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 */ ); /*-------------------------------------------------------------------* @@ -204,9 +190,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 +232,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 +314,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 +367,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; } @@ -379,112 +377,13 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) * * Initialize SWB buffers *-------------------------------------------------------------------*/ -void InitSWBencBuffer_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ -) -{ - Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - hBWE_TD->bwe_seed[0] = 23; - move16(); - hBWE_TD->bwe_seed[1] = 59; - move16(); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - - set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - hBWE_TD->prev_fb_energy_fx = 0; - move16(); - - 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 ); - set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); - - // IVAS_CODE - // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); - // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); - // hBWE_TD->old_mean_EnvSHBres = 0.0f; - // hBWE_TD->prev_enr_EnvSHBres = 1.0f; - // hBWE_TD->prev_shb_env_tilt = 0.0f; - // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - // hBWE_TD->prev_mix_factor = 1.0f; - // hBWE_TD->prev_Env_error = 0.0f; - set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); - - hBWE_TD->cldfbHBLT = 8192 /*1.0f Q13*/; - move16(); - hBWE_TD->prev_gainFr_SHB_fx = 0; - move32(); - set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277, 3 ); - set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); - - hBWE_TD->prev_swb_GainShape_fx = 0; - move16(); - hBWE_TD->prev_frGainAtten = 0; - move16(); - hBWE_TD->prev_wb_GainShape = 0; - move16(); - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - hBWE_TD->tilt_mem_fx = 0; - move16(); - - hBWE_TD->prev_coder_type = GENERIC; - move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = 0; - move16(); - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); - - /* TD BWE post-processing */ - hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - move16(); - } - - 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 ); - - - hBWE_TD->prev_fb_energy_fx_Q = 0; - move16(); - - - // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD - st_fx->prev_Q_bwe_exc = 31; - move16(); - st_fx->prev_Q_bwe_syn = 31; - move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); - - return; -} -void InitSWBencBuffer_ivas_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ +void InitSWBencBuffer_fx( + const Word16 element_mode, /* i : element mode */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; @@ -561,33 +460,41 @@ void InitSWBencBuffer_ivas_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 ); - hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); + IF( element_mode == EVS_MONO ) + { + hBWE_TD->prev_Q_bwe_exc = 31; + move16(); + hBWE_TD->prev_Q_bwe_syn = 31; + move16(); + } + ELSE + { + hBWE_TD->prev_Q_bwe_exc = 15; + move16(); + hBWE_TD->prev_Q_bwe_syn = 15; + move16(); + } - // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD - st_fx->prev_Q_bwe_exc = 15; - move16(); - st_fx->prev_Q_bwe_syn = 15; - move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + 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 ); return; } + /*-------------------------------------------------------------------* * ResetSHBbuffer_Enc() * *-------------------------------------------------------------------*/ + void ResetSHBbuffer_Enc_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - /* states for the filters used in generating SHB excitation from WB excitation*/ set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); @@ -595,13 +502,10 @@ void ResetSHBbuffer_Enc_fx( /* states for the filters used in generating SHB signal from SHB excitation*/ set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); - // IF( EQ_16(st_fx->extl, FB_TBE)) _DIFF_FLOAT_FIX_ - { - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - } /* states for the filters used in generating WB signal from WB excitation*/ set16_fx( hBWE_TD->decim_state1_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set16_fx( hBWE_TD->decim_state2_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); @@ -618,7 +522,6 @@ void ResetSHBbuffer_Enc_fx( hBWE_TD->tbe_premph_fx = 0; move16(); - return; } @@ -654,21 +557,20 @@ void ResetSHBbuffer_Enc_fx( #define WBTBE_LPCWIN_LENGTH ( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16 - 1 void wb_tbe_enc_fx( - 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 */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing_fx[] /* i : OL maximum normalized correlation */ + 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) */ + const Word16 Q_new, /* i : input HB speech Q factor */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + const Word16 pitch_buf[] /* i : pitch for each subframe Q6 */ ) { - Word16 i, j; + Word16 i, j, k; Word16 hb_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16]; Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; + Word16 shaped_wb_exc_scale[L_SHB_LAHEAD / 4]; Word16 exc4kWhtnd[L_FRAME16k / 4]; /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ Word32 GainFrame; @@ -684,11 +586,8 @@ void wb_tbe_enc_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_hb_frame; */ + 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; Word16 Q_ns = -1; @@ -703,13 +602,11 @@ void wb_tbe_enc_fx( Word16 frac, exp1; Word16 uv_flag; Word16 dummy = 0; - move16(); Word16 avg_voice_fac; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; - - /*Word16 att = 32767;*/ + move16(); + 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; @@ -723,65 +620,89 @@ void wb_tbe_enc_fx( test(); test(); test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( voicing_fx[0], 16384 ) && LT_16( voicing_fx[1], 16384 ) && LT_16( voicing_fx[2], 16384 ) ) ) && st_fx->igf == 0 ) + IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( st_fx->voicing_fx[0], 16384 ) && LT_16( st_fx->voicing_fx[1], 16384 ) && LT_16( st_fx->voicing_fx[2], 16384 ) ) ) && !st_fx->igf ) { /* In case of unvoiced signals after switching cores, back-propagate the target signal */ Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); i = WBTBE_LOOK_LSUFBR_5_OVER_16; move16(); + k = 0; + move16(); - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + 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( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; + 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 + { + 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, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); - - if ( st_fx->element_mode > EVS_MONO ) + 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 { + 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(); } - E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); + E_LPC_lev_dur_fx( 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 ) ); + 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++ ) + IF( st_fx->element_mode == EVS_MONO ) { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); - 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_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->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 + { + /* 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++ ) { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; + hBWE_TD->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; 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 ); } @@ -797,7 +718,7 @@ void wb_tbe_enc_fx( test(); IF( EQ_16( st_fx->rf_mode, 1 ) || EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - E_LPC_lev_dur( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL ); Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_LBR_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); /* Expand bandwidth of the LP coeffs */ @@ -813,11 +734,11 @@ void wb_tbe_enc_fx( lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -837,12 +758,12 @@ void wb_tbe_enc_fx( Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } @@ -856,7 +777,7 @@ void wb_tbe_enc_fx( } ELSE /* 13.2kbps */ { - E_LPC_lev_dur( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL ); Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); /* Expand bandwidth of the LP coeffs */ @@ -873,12 +794,11 @@ void wb_tbe_enc_fx( move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -898,12 +818,11 @@ void wb_tbe_enc_fx( } 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, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -925,16 +844,18 @@ void wb_tbe_enc_fx( } Copy( voice_factors, vf_modified_fx, NB_SUBFR16k ); - IF( EQ_16( coder_type, VOICED ) ) + IF( EQ_16( st_fx->coder_type, VOICED ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { /*vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1];*/ vf_modified_fx[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6553, voice_factors[i - 1] ) ); + move16(); } IF( NE_16( st_fx->L_frame, L_FRAME ) ) { vf_modified_fx[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6553, voice_factors[3] ) ); + move16(); } } @@ -956,9 +877,9 @@ void wb_tbe_enc_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ), n_mem ) ) { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); + Q_bwe_exc = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); } IF( uv_flag ) @@ -972,93 +893,204 @@ void wb_tbe_enc_fx( prev_pow = 0; move32(); - IF( st_fx->element_mode > EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + 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 = 0; + move32(); } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE { - 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 = 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 + { + 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(); + } + + 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 */ + } } - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); + rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); + + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) { bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); move16(); } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - +#ifdef HARMONIZE_TBE2 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, - vf_modified_fx, uv_flag, st_fx->igf ); - - curr_pow = 0; - move16(); - IF( st_fx->element_mode > EVS_MONO ) + 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 + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ + 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 ); } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - 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 ) ) + ELSE { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + 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 ); } +#endif - 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 ); - - - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + curr_pow = 0; + move32(); + IF( st_fx->element_mode == EVS_MONO ) { - 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(); - } + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + 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) */ + } - 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(); - /* Update WB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + } - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL, 1 ); + 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 ); - /* Gain frame adjustment factor */ - test(); - IF( GainShape[0] && hBWE_TD->prev_wb_GainShape ) - { - exp = norm_s( hBWE_TD->prev_wb_GainShape ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_wb_GainShape ); - L_tmp = L_mult( GainShape[0], tmp ); /* Q(30 - 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(); + } - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); + 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 + { + 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 ) ) + { + 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(); + } + 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) */ + } + + 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 */ + 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 ); + + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, + shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL, 1 ); + + /* Gain frame adjustment factor */ + test(); + IF( GainShape[0] && hBWE_TD->prev_wb_GainShape ) + { + exp = norm_s( hBWE_TD->prev_wb_GainShape ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_wb_GainShape ); + L_tmp = L_mult( GainShape[0], tmp ); /* Q(30 - exp) */ + + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); } ELSE { 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++ ) { @@ -1072,7 +1104,6 @@ void wb_tbe_enc_fx( exp1 = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - move16(); exp1 = sub( exp, exp1 ); L_tmp = Mpy_32_16( exp1, frac, 22713 ); temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); @@ -1102,7 +1133,6 @@ void wb_tbe_enc_fx( move16(); /* Q15 */ } - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; move16(); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) @@ -1113,11 +1143,19 @@ void wb_tbe_enc_fx( move16(); } - hBWE_TD->prev_wb_GainShape = GainShape[sub( shr( NUM_SHB_SUBFR, 2 ), 1 )]; - move16(); - p2m_in = pow_off_pk_fx( GainShape, shr( NUM_SHB_SUBFR, 2 ), 1 ); + hBWE_TD->prev_wb_GainShape = GainShape[( NUM_SHB_SUBFR >> 2 ) - 1]; move16(); + /* Compute the power of gains away from the peak gain prior to quantization */ + IF( st_fx->element_mode > EVS_MONO ) + { + p2m_in = pow_off_pk_corrected_fx( GainShape, NUM_SHB_SUBFR / 4, 1 ); + } + ELSE + { + p2m_in = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 4, 1 ); + } + IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { FOR( i = 0; i < 8; i++ ) @@ -1135,20 +1173,33 @@ void wb_tbe_enc_fx( } /* Compute the power of gains away from the peak gain after quantization */ - p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); + IF( st_fx->element_mode > EVS_MONO ) + { + p2m_out = pow_off_pk_corrected_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); + } + ELSE + { + p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); + } /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + 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 ); - /* 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. */ 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( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } + ELSE + { + GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } } pitBufAvg_fx = 0; @@ -1162,7 +1213,7 @@ void wb_tbe_enc_fx( move16(); FOR( i = 0; i < 3; i++ ) { - voicingBufAvg_fx = add( voicingBufAvg_fx, mult_r( voicing_fx[i], 10912 ) ); /*Q15 */ + voicingBufAvg_fx = add( voicingBufAvg_fx, mult_r( st_fx->voicing_fx[i], 10912 ) ); /*Q15 */ } /* GainFrame *= max(min((float)(pitBufAvg/voicingBufAvg), 1.0f), 0.7f); */ tmp = 32767; @@ -1177,19 +1228,26 @@ void wb_tbe_enc_fx( } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ - - test(); - IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) + IF( st_fx->element_mode == EVS_MONO ) { - GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ + GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ } - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + ELSE { - /*wbbwe_em_factor = add( mult_r( 29491, st_fx->prev_wbbwe_em_factor_fx ), mult_r( 3277, wbbwe_em_factor ) ); */ /* Q15 */ + GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ } + IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) + { + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ + } + ELSE + { + GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ + } + } /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ L_tmp = L_mult( voice_factors[0], 8192 ); @@ -1201,700 +1259,1001 @@ void wb_tbe_enc_fx( test(); test(); - IF( st_fx->igf != 0 && EQ_16( coder_type, VOICED ) ) + IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ - - GainFrame = Mult_32_16( GainFrame, 16384 ); + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 16384 ); + } + ELSE + { + 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 = Mult_32_16( GainFrame, 24576 ); + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 24576 ); + } + ELSE + { + GainFrame = Mpy_32_16_1( GainFrame, 24576 ); + } } /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); + IF( st_fx->rf_mode ) + { + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); + } + ELSE + { + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); + } /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ + IF( st_fx->element_mode > EVS_MONO ) + { + 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 ); - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + IF( st_fx->element_mode > EVS_MONO ) + { + Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); + } + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); return; } -/*==========================================================================*/ -/* FUNCTION : void wb_tbe_enc_ivas_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : WB TBE encoder, 6 - 8 kHz band encoding module */ -/*--------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------* + * 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, + Word16 elliptic_bpf_2_48k_mem_fx_Q[], + Word16 *prev_fb_energy_fx_Q ) +{ + set32_fx( elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); + set32_fx( elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); + set32_fx( elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); + set32_fx( elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); + *prev_fb_energy_fx = 0; + move16(); + set16_fx( elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); + *prev_fb_energy_fx_Q = 0; + move16(); + + return; +} + + +/*======================================================================================*/ +/* FUNCTION : void swb_tbe_enc_fx () */ +/*--------------------------------------------------------------------------------------*/ +/* PURPOSE : SWB TBE encoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band encoding module */ +/*--------------------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* Word16 *new_speech i : original input signal Q(-1) */ -/* Word32 *bwe_exc_extended i : bandwidth extended exciatation Q(2*Q_new) */ -/* Word16 voice_factors[] i : voicing factors Q15 */ -/* Word16 pitch_buf[] i : pitch for each subframe Q6 */ -/*--------------------------------------------------------------------------*/ +/* _(Word16) coder_type : coding type */ +/* _(Word16*) shb_speech_fx : SHB target signal (6-14kHz) at 16kHz Q0 */ +/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ +/* _(Word16[]) voice_factors :voicing factors Q15 */ +/* _(Word16*) Q_white_exc :Q Format of White Exc */ +/*--------------------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ -/* Word16 *synth o : WB SHB final synthesis */ -/*--------------------------------------------------------------------------*/ +/* _(Word16[])White_exc16k_fx : shaped white excitation for the FB TBE Q_white_exc */ +/* _(Word16*)fb_slope_fx : slope +ve (high freq > low freq), -ve or neutral Q12 */ +/*--------------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State *st_fx i/o: encoder state structure */ -/*--------------------------------------------------------------------------*/ +/* _ Encoder_State *st_fx: : Encoder state structure */ +/*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ +/*--------------------------------------------------------------------------------------*/ +/* CALLED FROM : TX */ +/*======================================================================================*/ -void wb_tbe_enc_ivas_fx( - 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) */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors Q15 */ - const Word16 pitch_buf[] /* i : pitch for each subframe Q6 */ +void swb_tbe_enc_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 coder_type, /* i : coding type */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ + 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*/ + Word16 *Q_white_exc, + Word16 Q_new, + Word16 Q_shb, + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6*/ ) { - Word16 i, j, k; - Word16 hb_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16]; + Word16 i, j; + + Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; - Word16 shaped_wb_exc_scale[L_SHB_LAHEAD / 4]; - Word16 exc4kWhtnd[L_FRAME16k / 4]; - /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ - Word32 GainFrame; - Word16 GainShape[NUM_SHB_SUBFR]; - Word16 lpc_wb[LPC_SHB_ORDER_WB + 1]; - Word32 lpc_wb_32_fx[LPC_SHB_ORDER_WB + 1]; - Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = { 32767, 32767 }; - move16(); - move16(); - Word16 *hb_new_speech, *hb_frame /*, hb_speech[ L_FRAME16k ]*/; - Word16 R_h[LPC_SHB_ORDER_WB + 2], R_l[LPC_SHB_ORDER_WB + 2]; + Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; + Word32 GainFrame_fx; + Word16 GainShape_fx[NUM_SHB_SUBFR]; + Word16 lpc_shb_fx[LPC_SHB_ORDER + 1], lsp_shb_fx[LPC_SHB_ORDER], lsf_shb_fx[LPC_SHB_ORDER]; + Word16 weights_lsp[LPC_SHB_ORDER]; + Word16 Q_out; + Word16 *shb_frame_fx, *shb_new_speech_fx; + Word16 R_h[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech MSB */ + Word16 R_l[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech LSB */ Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER_WB + 1]; + Word32 LepsP[LPC_SHB_ORDER + 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; - Word16 Q_ns = -1; + Word16 ana_align_delay[2] = { -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ), -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) }; move16(); - - Word16 pitBufAvg_fx, voicingBufAvg_fx; - Word16 vf_modified_fx[NB_SUBFR16k]; - Word16 temp_wb_fac_fx, feedback_fx; - Word16 lsp_spacing_fx; - Word16 lsp_wb_temp_fx[LPC_SHB_ORDER_WB], lpc_wb_temp_fx[LPC_SHB_ORDER_WB + 1]; - Word32 L_feedback; - Word16 frac, exp1; - Word16 uv_flag; - Word16 dummy = 0; - Word16 avg_voice_fac; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; move16(); + Word32 prev_pow_fx, curr_pow_fx, Lscale; + Word32 p2m_in_fx, p2m_out_fx; - /*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; - - Copy( hBWE_TD->old_speech_wb_fx, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - Copy( hb_speech, hb_new_speech, LFRAME16K_OVER_4 ); - Copy( hb_old_speech + LFRAME16K_OVER_4, hBWE_TD->old_speech_wb_fx, WBTBE_LOOK_LSUFBR_5_OVER_16 ); + Word16 exp_out, exp, exp1, frac; + Word16 cnt, n_mem, n_mem2; + Word32 L_tmp, L_tmp1; + Word16 Q_bwe_exc; - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( st_fx->voicing_fx[0], 16384 ) && LT_16( st_fx->voicing_fx[1], 16384 ) && LT_16( st_fx->voicing_fx[2], 16384 ) ) ) && !st_fx->igf ) - { - /* In case of unvoiced signals after switching cores, back-propagate the target signal */ - Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); + Word16 frGainAttenuate, frGainSmoothEn; + Word16 MA_lsp_shb_spacing; + Word16 temp_swb_fac, feedback; + Word32 L_feedback; + Word16 tmp, tmp1, tmp2; + Word32 Lmax; + Word16 sc; + Word16 lsf_shb_orig_fx[LPC_SHB_ORDER]; + Word16 sd_uq_q_fx; + Word16 vf_modified_fx[NB_SUBFR16k]; + Word16 pitBufAvg_fx; + Word16 voicingBufAvg_fx; + Word16 sum1, sum2; + Word16 recip, Q_recip; + const Word16 *ptr_lsp_interp_coef_fx; - i = WBTBE_LOOK_LSUFBR_5_OVER_16; - move16(); - k = 0; - move16(); + Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; + Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )]; - 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++; - } - } + /*Word32 shb_ener_sf_fx_32[4];*/ + Word32 shb_ener_sf_Q31; + Word16 shb_res_fx[L_FRAME16k]; + Word16 shb_res_gshape_fx[NB_SUBFR16k]; + Word32 shb_res_gshape_fx_32[NB_SUBFR16k]; + Word16 vf_ind_fx; - 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 ); + Word16 formant_fac_fx; + Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; - /* Ensure R[0] isn't zero when entering Levinson-Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); + Word16 mean_vf; + Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; + Word16 refl[M]; + Word16 tilt_para; + Word16 Q_bwe_exc_fb; + Word16 n_subfr_saturation; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + RF_ENC_HANDLE hRF = st_fx->hRF; - 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 + /* init and buffers set up */ + exp1 = 0; /* to avoid compilation warnings */ + set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); - 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 + /* compensate for the delay in target generation and subframe LA */ + shb_frame_fx = shb_old_speech_fx + L_SUBFR16k + ana_align_delay[0]; + move16(); - /* 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(); - } + /* set up the speech buffers for TBE processing*/ + shb_new_speech_fx = shb_old_speech_fx + ( L_LOOK_16k + L_SUBFR16k ); + move16(); + Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( L_LOOK_16k + L_SUBFR16k ) ); + Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( L_LOOK_16k + L_SUBFR16k ) ); - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + /* autocorrelation of SHB speech for 10-th order LP analysis */ + autocorr_fx( shb_old_speech_fx, + LPC_SHB_ORDER + 1, + R_h, /* autocorr (msb) Q15 */ + R_l, /* autocorr (lsb) */ + &Q_R, + NS2SA( INT_FS_16k, ACELP_LOOK_NS ) + L_SUBFR16k + L_FRAME16k, + win_lpc_shb_fx, + 0, + 1 ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; - move16(); - } - /* lsp_spacing_fx = 16384; move16(); */ - lsp_spacing_fx = lsp_wb_temp_fx[0]; - move16(); - FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) + /* Spectral smoothing of autocorrelation coefficients */ + test(); + IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { - /*if ( i == 0 ) + FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - tmp = lsp_wb_temp_fx[0]; move16(); + L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_h[i - 1], wac_swb_l[i - 1] ); + L_Extract( L_tmp, &R_h[i], &R_l[i] ); } - else - {*/ - tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - /*} */ - - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); } - /* Spectral smoothing of autocorrelation coefficients */ - FOR( i = 1; i <= LPC_SHB_ORDER_WB; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } + /* Set the autocorr[0] element to a non-negative value */ R_l[0] = s_max( R_l[0], 1 ); move16(); - test(); - IF( EQ_16( st_fx->rf_mode, 1 ) || EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) + E_LPC_lev_dur_fx( R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL ); /* LPC in Q14 */ { - E_LPC_lev_dur( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL ); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_LBR_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); + Word16 enerG, lpc_shb1[M + 1]; - /* Expand bandwidth of the LP coeffs */ - FOR( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) - { - lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); - move16(); - } + /* extend the lpc_shb to a 16th order gain calc */ + set16_fx( lpc_shb1, 0, M + 1 ); + Copy( lpc_shb_fx, lpc_shb1, LPC_SHB_ORDER + 1 ); - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); - move32(); /*Q27 */ - } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); + /* estimate the LP gain */ + enerG = Enr_1_Az_fx( lpc_shb1, 2 * L_SUBFR ); /* Q3 */ - FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) + /* if the LP gain is greater than a threshold, avoid saturation */ + IF( GT_16( enerG, 256 /*32 Q3*/ ) ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; - move16(); + set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); + E_LPC_lev_dur_fx( R_h, R_l, lpc_shb_fx, LepsP, 2, NULL ); /* LPC in Q14 */ } + } - lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_LBR_WB, &Q_out ); + /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); - /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, lbr_wb_bwe_lsfvq_cbook_2bit_fx, 4, LPC_SHB_ORDER_LBR_WB ); - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + /* Expand bandwidth of the LP coeffs */ + test(); + IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + { + FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsf_WB = i; + lpc_shb_fx[i] = mult_r( lpc_shb_fx[i], lpc_weights_fx[i] ); move16(); } - ELSE - { - push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); - } - - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); + } - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + /* LPC to LSP conversion */ + /* LPC: Q12, LSP: Q15 */ + E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } + /* LSP to LSF conversion */ + /* LSP: Q15, LSF: Q15 */ + E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - ELSE /* 13.2kbps */ - { - E_LPC_lev_dur( R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL ); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb[0] ), 2 ) ); + /* Input signal filtering in case of tonal sounds in the high band + gain Frame smoothing and attenuation control */ + gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); - /* Expand bandwidth of the LP coeffs */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); - move16(); - } + Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); + Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); - /* 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[i] ), 1 ) ); - move32(); /*Q27 */ - } + test(); + IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + { + lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); + /* to compensate for the 1.1* weighting done inside the function lsp_weights */ + /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ + weights_lsp[3] = mult_r( weights_lsp[3], 29789 /*0.909091f Q15*/ ); + move16(); + weights_lsp[4] = mult_r( weights_lsp[4], 29789 /*0.909091f Q15*/ ); + move16(); + /* 8-bit VQ, 10 dimension */ + i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); + Copy( swb_tbe_lsfvq_cbook_8b + i * LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; - move16(); - } + set16_fx( hBWE_TD->lsf_idx, 0, NUM_Q_LSF ); + hBWE_TD->lsf_idx[0] = i; + move16(); + } + ELSE + { + /* LSF quantization (21 bits) */ + Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); + } - lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_WB, &Q_out ); + /* space the lsfs to assert a minimum distance */ + space_lsfs_fx( lsf_shb_fx, LPC_SHB_ORDER ); - /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ + /* voice factor adjustment and gainframe attenuation factor */ + tmp = sub( lsf_shb_fx[0], lsf_shb_orig_fx[0] ); + L_tmp = L_mult( tmp, tmp ); + FOR( i = 1; i < LPC_SHB_ORDER; i++ ) + { + /* Estimate the QD in lsfs between UQ and Q */ + tmp = sub( lsf_shb_fx[i], lsf_shb_orig_fx[i] ); + L_tmp = L_mac( L_tmp, tmp, tmp ); + } + sd_uq_q_fx = round_fx( L_tmp ); /* sd_uq_q_fx in Q15 */ + /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ + /* mean(voice_factors_fx[i], 4); */ - 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 ); + L_tmp = L_mult( voice_factors_fx[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); + mean_vf = mac_r( L_tmp, voice_factors_fx[3], 8192 ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); + Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) + test(); + IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) + { + FOR( i = 1; i < NB_SUBFR; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + L_tmp = L_mult( voice_factors_fx[i], 26214 ); + vf_modified_fx[i] = mac_r( L_tmp, voice_factors_fx[i - 1], 6554 ); move16(); } - FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { - lpc_wb[i] = negate( lpc_wb[i] ); + L_tmp = L_mult( voice_factors_fx[4], 26214 ); + vf_modified_fx[4] = mac_r( L_tmp, voice_factors_fx[3], 6554 ); move16(); } - lpc_wb[0] = 4096; - move16(); } - uv_flag = 0; - move16(); + /* convert quantized LSFs to LSPs for interpolation */ + E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); + test(); - if ( EQ_32( st_fx->extl_brate, WB_TBE_1k05 ) && EQ_16( st_fx->coder_type_raw, UNVOICED ) ) + IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) { - uv_flag = 1; - move16(); - } - - Copy( voice_factors, vf_modified_fx, NB_SUBFR16k ); - IF( EQ_16( st_fx->coder_type, VOICED ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - /*vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1];*/ - vf_modified_fx[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6553, voice_factors[i - 1] ) ); - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - vf_modified_fx[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6553, voice_factors[3] ) ); - move16(); - } + /* SHB LSP values from prev. frame for interpolation */ + Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - - /* From low band excitation, generate highband excitation */ - Lmax = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME32k; i++ ) + ELSE { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[i] ) ); + /* Use current frame's LSPs; in effect no interpolation */ + Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - Q_bwe_exc = 31; + lsf_diff[0] = lsf_diff[LPC_SHB_ORDER - 1] = 16384; /*Q15*/ move16(); - if ( Lmax != 0 ) + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - Q_bwe_exc = norm_l( Lmax ); + lsf_diff[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); + move16(); } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); - - find_max_mem_wb_enc( st_fx, &n_mem ); + a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); - IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) - { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); - } + /* LSP interpolation for 13.2 kbps and 16.4 kbps */ + /* tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) + - 3.8714f * (1.0f + refl[0]) + + 1.3041f; */ + tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ + tmp1 = mult( 27425 /*Q12*/, tmp ); /*Q11*/ + tmp1 = mult( tmp1, tmp ); + tmp2 = shr( mult( 31715, tmp ), 2 ); /* Q11 */ + tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - IF( uv_flag ) + IF( NE_16( st_fx->last_extl, SWB_TBE ) ) { - if ( GT_16( Q_bwe_exc, 20 ) ) + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - Q_bwe_exc = 20; - move16(); /* restrict this to 20 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ + hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff[i], 16384 ); /*Q15*/ + move16(); } } - 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 ) ) + IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + test(); + test(); + test(); + test(); + test(); + IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && + !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( hBWE_TD->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) { - shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); + FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) + { + IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) + { + tmp = mult( 26214, lsf_diff[i] ); + tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); + move16(); + } + ELSE + { + tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); + tmp = div_s( tmp, lsf_diff[i] ); + tmp = s_max( tmp, 16384 ); + w[i] = s_min( tmp, 32767 ); + move16(); + } + } + w[0] = w[1]; + move16(); + w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; move16(); + + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w[i] ) ); + tmp2 = mult( lsp_shb_2_fx[i], w[i] ); + lsp_temp_fx[i] = add( tmp1, tmp2 ); + move16(); + } } - Q_prev_pow = shl_r( sub( sub( st_fx->prev_Q_bwe_exc, 16 ), 3 ), 1 ); - move16(); - } - ELSE - { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE { - shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; - move16(); + Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); } - Q_prev_pow = shl_r( sub( st_fx->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++ ) + Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = tilt_para; + move16(); + + shb_ener_sf_Q31 = 0; + move16(); + test(); + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { - prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ - } + /* ---------- SHB LSP interpolation ---------- */ + ptr_lsp_interp_coef_fx = interpol_frac_shb; /* Q15 */ + FOR( j = 0; j < 4; j++ ) + { + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ + /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1)); */ + L_tmp = L_mult( lsp_shb_1_fx[i], ( *ptr_lsp_interp_coef_fx ) ); + lsp_temp_fx[i] = mac_r( L_tmp, lsp_shb_2_fx[i], ( *( ptr_lsp_interp_coef_fx + 1 ) ) ); + move16(); + } + ptr_lsp_interp_coef_fx += 2; - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); + tmp = i_mult2( j, ( LPC_SHB_ORDER + 1 ) ); + /* convert LSPs to LPC coefficients for SHB synthesis*/ + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); + /* Bring the LPCs to Q12 */ + Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); + } - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - FOR( i = 0; i < L_FRAME32k; i++ ) - { - bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); - move16(); - } + /* -------- Calculate the SHB Energy -------- */ + /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ + FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) + { + /* shbEner = shbEner + in[i] * in[i] */ + shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); + /* o: shb_ener_sf_Q31 in (2*Q_shb) */ + } + 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 ); + Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, ( 2 * Q_shb ) ); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); - Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); + /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ + set16_fx( shb_res_fx, 0, L_FRAME16k ); + Residu3_10_fx( lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); + /* i: shb_frame_fx in Q_shb */ + /* o: shb_res_fx in Q_shb */ + + set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); + FOR( i = 0; i < NB_SUBFR16k; i++ ) + { + shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i * 64, 64 ); + move32(); + } + /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ - 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 ); + maximum_32_fx( shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp ); - 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 ) ) - { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + /* root_a_over_b_fx(shb_res_gshape_fx_32[i], (2*Q_shb+1), L_tmp, (2*Q_shb+1), &exp);*/ + /* First, find 1/L_tmp, L_tmp in QA = (2*Q_shb+1) */ + + /* case when den = 0 */ + recip = 0; /*instead of 32767 to be compatible with previous root_a_over_b_fx() output */ + Q_recip = 0; + + IF( L_tmp ) { - shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + recip = div_s( 16384, tmp ); + // Q_recip = 31 - ( exp - 14 ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ move16(); } - Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); - move16(); - } - ELSE - { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + + FOR( i = 0; i < NB_SUBFR16k; i++ ) { - shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + L_tmp1 = Mult_32_16( shb_res_gshape_fx_32[i], recip ); /*Q = Q_recip+1-16*/ + L_tmp = root_a_fx( L_tmp1, add( Q_recip, 1 - 16 ), &exp ); + shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /* Q14 */ move16(); } - Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); - move16(); + + Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); } - IF( st_fx->element_mode > EVS_MONO ) + + /* for 13.2 and 16.4kbps */ + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ + + /* Save the SWB LSP values from current frame for interpolation */ + Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ + + /* -------- start of memory rescaling -------- */ + /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ + Lmax = L_deposit_l( 0 ); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { - tmp = sub( Q_cur_pow, 31 + 16 ); - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(Q_cur_pow)*/ + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_bwe_exc = norm_l( Lmax ); + if ( Lmax == 0 ) + { + Q_bwe_exc = 31; + move16(); + } + Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); + + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ + find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); + + tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); + if ( GT_16( Q_bwe_exc, tmp2 ) ) { - curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ + Q_bwe_exc = tmp2; + move16(); } - IF( GT_16( voice_factors[0], 24576 ) ) + /* rescale the memories if Q_bwe_exc is different from previous frame */ + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); + IF( sc != 0 ) { - curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ + rescale_genSHB_mem_enc( st_fx, sc ); } - Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); + /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { - 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 */ + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); move16(); } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + + /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - 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 */ + /* save the previous Q factor of the buffer */ + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); - /* Update WB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape, subwin_wb_fx, NULL, 1 ); + /* -------- end of rescaling memories -------- */ + Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; + move16(); + /* Determine formant PF strength */ + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); + /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - /* Gain frame adjustment factor */ - test(); - IF( GainShape[0] && hBWE_TD->prev_wb_GainShape ) - { - exp = norm_s( hBWE_TD->prev_wb_GainShape ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_wb_GainShape ); - L_tmp = L_mult( GainShape[0], tmp ); /* Q(30 - exp) */ + /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ + vf_ind_fx = 20; + move16(); - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); + 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, 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 ); + + *Q_white_exc = Q_bwe_exc_fb; + move16(); + IF( EQ_16( st_fx->extl, FB_TBE ) ) + { + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + move16(); } ELSE { - temp_wb_fac_fx = 0; + /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. + 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ + hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); } - L_feedback = L_mult0( temp_wb_fac_fx, temp_wb_fac_fx ); - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) + + test(); + IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) { - /* temp_swb_fac = (float)log( (GainShape[i]+0.00001f) / (GainShape[i-1]+0.0001f) ); */ - test(); - IF( GainShape[i] && GainShape[i - 1] ) + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { - exp = norm_s( GainShape[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape[i - 1] ); - L_tmp = L_mult( GainShape[i], tmp ); /*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); + hBWE_TD->idx_mixFac = vf_ind_fx; + move16(); } ELSE { - temp_wb_fac_fx = 0; - move16(); + push_indice( st_fx->hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF ); } - - L_feedback = L_mac( L_feedback, temp_wb_fac_fx, temp_wb_fac_fx ); } - L_tmp = L_add( L_shr( L_feedback, 1 ), 1 << 21 ); /* Q30 */ - IF( L_tmp != 0 ) + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /* Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /* Q31 */ - feedback_fx = round_fx( L_tmp ); /* Q15 */ + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); + move16(); } - ELSE + + FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { - feedback_fx = 8738; - move16(); /* Q15 */ + PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); } + Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; - move16(); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); + prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - GainShape[i] = add( mult_r( sub( 32767, feedback_fx ), GainShape[i] ), mult_r( feedback_fx, temp_wb_fac_fx ) ); - move16(); - temp_wb_fac_fx = GainShape[i]; - move16(); + prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ } - hBWE_TD->prev_wb_GainShape = GainShape[( NUM_SHB_SUBFR >> 2 ) - 1]; - move16(); + if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ + curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ + } - /* Compute the power of gains away from the peak gain prior to quantization */ - IF( st_fx->element_mode > EVS_MONO ) + Lscale = root_a_over_b_fx( curr_pow_fx, + shl( Q_bwe_exc, 1 ), + prev_pow_fx, + shl( Q_bwe_exc, 1 ), + &exp ); + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - p2m_in = pow_off_pk_corrected_fx( GainShape, NUM_SHB_SUBFR / 4, 1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); } - ELSE + IF( exp < 0 ) { - p2m_in = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 4, 1 ); + Lscale = L_shl( Lscale, exp ); + exp = 0; + move16(); } - - IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) + /* + code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues + thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations + */ + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - FOR( i = 0; i < 8; i++ ) + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { - GainShape[i] = RECIP_ROOT_EIGHT_FX; + tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ + tmp = sub( 32767 /*1.0f Q15*/, tmp ); + Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } } ELSE { - push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + { + tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ + tmp = sub( 32767 /*1.0f Q15*/, tmp ); + Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); + } + } - /* Quantization of the subframe gain parameter */ - QuantizeSHBsubgains_ivas_fx( st_fx, GainShape, st_fx->extl ); + /* Update SHB excitation */ + Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ + + /* Estimate the gain-shape parameter */ + n_subfr_saturation = 0; + move16(); + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, + Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 1 ); + + /* Gain shape BWS/high band low energy fix */ + IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ + { + /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ + /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ + GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); + move16(); + } } - /* Compute the power of gains away from the peak gain after quantization */ - IF( st_fx->element_mode > EVS_MONO ) + /* Gain frame adjustment factor */ + /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ + test(); + IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) { - p2m_out = pow_off_pk_corrected_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ + + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ + exp1 = sub( exp, exp1 ); /*move16(); */ + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); } ELSE { - p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); + temp_swb_fac = 0; + move16(); } + L_feedback = L_mult0( temp_swb_fac, temp_swb_fac ); - /* Estimate the gain parameter */ - 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 ); - - - /* 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. */ - IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) + FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) { - 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 */ - } + test(); + IF( GainShape_fx[i] && GainShape_fx[i - 1] ) + { + exp = norm_s( GainShape_fx[i - 1] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ - pitBufAvg_fx = 0; - move16(); + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + } + ELSE + { + temp_swb_fac = 0; + move16(); + } - FOR( i = 0; i < NB_SUBFR; i++ ) - { - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[i], 82 ) ); /*Q6 */ + L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); } - voicingBufAvg_fx = 0; - move16(); - FOR( i = 0; i < 3; i++ ) + + /* feedback = 0.4f / (1 + 0.5f * feedback) */ + L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl( 1, 21 ) ); /* Q21 */ + IF( L_tmp != 0 ) { - voicingBufAvg_fx = add( voicingBufAvg_fx, mult_r( st_fx->voicing_fx[i], 10912 ) ); /*Q15 */ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 21 ); + tmp = div_s( 16384, tmp ); /*Q(15+exp) */ + L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ + feedback = round_fx( L_tmp ); /*Q15 */ } - /* GainFrame *= max(min((float)(pitBufAvg/voicingBufAvg), 1.0f), 0.7f); */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) + ELSE { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ - L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ - L_tmp = L_shl_sat( L_tmp, add( exp, 10 ) ); - tmp = round_fx_sat( L_tmp ); /* Q15 */ + feedback = 8738; + move16(); /*Q15 */ } - tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - 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 */ - } + /* voicing in Q15 */ + L_tmp = L_mult( voicing[0], 8192 ); + L_tmp = L_mac( L_tmp, voicing[1], 8192 ); + L_tmp = L_mac( L_tmp, voicing[2], 8192 ); + tmp = sum1 = round_fx( L_tmp ); /* sum1 used again below - Q13 */ + tmp = add( tmp, 1 ); /* To ensure change is BE */ + + /* voice_factors_fx in Q15 */ + L_tmp = L_mult( voice_factors_fx[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); + tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ + + + test(); + test(); + IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 ) && GT_16( tmp1, 6554 ) ) ) - /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult( voice_factors[0], 8192 ); - FOR( i = 1; i < NB_SUBFR; i++ ) { - L_tmp = L_mac( L_tmp, voice_factors[i], 8192 ); + temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; + move16(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ + GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); + move16(); + temp_swb_fac = GainShape_fx[i]; + move16(); + } + } + hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; + move16(); + + /* Compute the power of gains away from the peak gain prior to quantization */ + p2m_in_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); + + /* Quantization of the gain shape parameter */ + + QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); + /* o: GainShape_fx in Q15 */ + /* Compute the power of gains away from the peak gain after quantization */ + p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); + + /* Estimate the gain parameter */ + 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 ); + + IF( EQ_16( st_fx->tec_tfa, 1 ) ) + { + tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); + } + + /* 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. */ + IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) ) + { + L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); + GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ + } + test(); + IF( EQ_16( frGainSmoothEn, 1 ) && LT_32( hBWE_TD->prev_gainFr_SHB_fx, GainFrame_fx ) ) + { + GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ } - avg_voice_fac = round_fx( L_tmp ); test(); test(); - IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) + IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) { - /*GainFrame *= 0.5f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 16384 ); + exp1 = norm_l( GainFrame_fx ); + frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); + exp = sub( 30, add( exp1, 21 ) ); + L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); + GainFrame_fx = Pow2( 30, frac ); + exp = sub( exp, 30 ); + GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ } - ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ + ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { - /*GainFrame *= 0.75f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 24576 ); + /*GainFrame *= (0.8f + 0.5f*feedback); */ + tmp = add( 26214, mult_r( feedback, 16384 ) ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ } + hBWE_TD->prev_frGainAtten = frGainAttenuate; + move16(); + hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; + move16(); /* Q18 */ - /* Quantization of the frame gain parameter */ - IF( st_fx->rf_mode ) + + /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ + tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); + tmp1 = mult_r( 6554 /*0.2f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } ELSE { - QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); + tmp1 = mult_r( 3277 /*0.1f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } + /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ + L_tmp = L_min( L_tmp, 8192l /*1.0f Q13*/ ); + L_tmp = L_max( L_tmp, 4096l /*0.5f Q13*/ ); /* Q13 */ + /* keep the L_tmp; dont overwrite */ - /* 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 ); - 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 ); + /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ + /* pitch_buf: Q6 */ + pitBufAvg_fx = mult_r( pitch_buf[0], 1311 ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[1], 1311 ) ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[2], 1311 ) ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[3], 1311 ) ); /* Q10 */ - Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ + tmp2 = 5462 /*0.1667f Q15*/; move16(); + if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) + { + tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ + move16(); + } + voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - return; -} + /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ + /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ -void fb_tbe_reset_enc_fx( - Word32 elliptic_bpf_2_48k_mem_fx[][4], - Word32 *prev_fb_energy_fx, - Word16 elliptic_bpf_2_48k_mem_fx_Q[], - Word16 *prev_fb_energy_fx_Q ) -{ - set32_fx( elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - *prev_fb_energy_fx = 0; + /* 1/voicingBufAvg_fx */ + tmp = 32767; move16(); - set16_fx( elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); - *prev_fb_energy_fx_Q = 0; + IF( voicingBufAvg_fx > 0 ) + { + exp = norm_s( voicingBufAvg_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ + + /* sd_uq_q*pitBufAvg */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ + tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ + } + + tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); + tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ + + test(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) + { + /* Compensate for energy increase mismatch due to memory-less synthesis*/ + GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ + } + + /* Quantization of the frame gain parameter */ + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); + + /* Adjust the subframe and frame gain of the synthesized SHB signal */ + /* Scale the shaped excitation */ + IF( EQ_32( st_fx->extl, FB_TBE ) ) + { + tmp = norm_l( GainFrame_fx ); + if ( GainFrame_fx == 0 ) + { + tmp = 31; + move16(); + } + L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ + + tmp1 = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ + /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ + /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + /*White_exc16k_fx[i] =32767;*/ + /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ + } + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ + tmp = norm_s( tmp1 ); + if ( tmp1 == 0 ) + { + tmp = 15; + move16(); + } + + FOR( i = 0; i < L_FRAME16k; i++ ) + { + White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); + move16(); + } + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); + move16(); + } + + /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); return; @@ -1902,7 +2261,7 @@ void fb_tbe_reset_enc_fx( /*======================================================================================*/ -/* FUNCTION : void swb_tbe_enc_fx () */ +/* FUNCTION : void swb_tbe_enc_ivas_fx () */ /*--------------------------------------------------------------------------------------*/ /* PURPOSE : SWB TBE encoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band encoding module */ /*--------------------------------------------------------------------------------------*/ @@ -1926,28 +2285,28 @@ void fb_tbe_reset_enc_fx( /* CALLED FROM : TX */ /*======================================================================================*/ -void swb_tbe_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ - 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*/ +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 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 */ Word16 *Q_white_exc, Word16 Q_new, Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6*/ + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6 */ ) { - Word16 i, j; + Word16 i, j, k, delay; Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; - Word32 GainFrame_fx; - Word16 GainShape_fx[NUM_SHB_SUBFR]; + Word32 GainFrame_fx; /* Q18 */ + Word16 GainShape_fx[NUM_SHB_SUBFR]; /* Q15 */ Word16 lpc_shb_fx[LPC_SHB_ORDER + 1], lsp_shb_fx[LPC_SHB_ORDER], lsf_shb_fx[LPC_SHB_ORDER]; Word16 weights_lsp[LPC_SHB_ORDER]; Word16 Q_out; @@ -1957,9 +2316,7 @@ void swb_tbe_enc_fx( Word16 Q_R; Word32 LepsP[LPC_SHB_ORDER + 1]; - Word16 ana_align_delay[2] = { -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ), -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) }; - move16(); - move16(); + Word16 ana_align_delay; Word32 prev_pow_fx, curr_pow_fx, Lscale; Word32 p2m_in_fx, p2m_out_fx; @@ -1995,31 +2352,111 @@ void swb_tbe_enc_fx( Word16 vf_ind_fx; Word16 formant_fac_fx; + // int16_t stab_check = 1; + Word16 MSFlag; + Word16 *nlExc16k_fx, *nlExc16k_e, *mixExc16k_fx, *mixExc16k_e; + Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; + Word16 acorr_v2a_fx; /* Q15 */ + + Word16 acorr_EnvSHBres[ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN], *p_acorr, shb_env_tilt_fx; + Word16 buf_EnvSHBres_fx[2 * L_FRAME4k], *p_buf, EnvSHBres_fx[L_FRAME16k], EnvSHBres_4k_fx[L_FRAME4k], EnvSHBres_4k_norm_fx[L_FRAME4k], env_mean_normf_fx[L_FRAME4k]; + Word32 tmp_buf[L_FRAME4k]; + Word16 Q_EnvSHBres_4k_norm = Q31; + move16(); + Word16 GainShape_Interp_fx[NUM_SHB_SUBGAINS], GainShape_tilt_fx; /* Q15 */ + Word16 seg_mean[4], den_seg_mean[4], *p_env, step; + Word16 temp, scale_fx, scale_e, pow_e, tmp_e, tmp1_e; + Word16 seg_len, seg_len_2; + Word16 den_seg_len, den_seg_len_2, fact_atten_fx; /* Q15 */ + Word32 sum_gain_fx, normFact_fx; + Word32 pow0_fx, alpha_fx; + Word16 Env_error_part_fx[NUM_SHB_SUBGAINS], Env_error_fx; /* Q0 */ + Word16 mean_vf; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; + Word16 lsf_diff_fx[LPC_SHB_ORDER], w_fx[LPC_SHB_ORDER]; + Word16 refl_fx[M]; + Word16 tilt_para_fx; Word16 Q_bwe_exc_fb; Word16 n_subfr_saturation; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; + + Env_error_fx = 0; + move16(); + pitBufAvg_fx = 0; + move16(); + voicingBufAvg_fx = 0; + move16(); + set16_fx( Env_error_part_fx, 0, NUM_SHB_SUBGAINS ); + shb_env_tilt_fx = 0; + move16(); + sum1 = 0; + move16(); + sum2 = 0; + move16(); + + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; /* init and buffers set up */ exp1 = 0; /* to avoid compilation warnings */ + move16(); + + test(); + IF( st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) + { + nlExc16k_fx = hStereoICBWE->nlExc16k_fx; + nlExc16k_e = &hStereoICBWE->nlExc16k_e; + mixExc16k_fx = hStereoICBWE->mixExc16k_fx; + mixExc16k_e = &hStereoICBWE->mixExc16k_e; + MSFlag = hStereoICBWE->MSFlag; + move16(); + } + ELSE + { + nlExc16k_fx = NULL; + nlExc16k_e = NULL; + mixExc16k_fx = NULL; + mixExc16k_e = NULL; + MSFlag = 0; + move16(); + } + set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); + test(); + test(); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) + { + ana_align_delay = -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) + 20; /* 20 corresponds to the 1.25 ms CLDFB delay */ + move16(); + } + ELSE + { + ana_align_delay = -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ); + move16(); + } + /* compensate for the delay in target generation and subframe LA */ - shb_frame_fx = shb_old_speech_fx + L_SUBFR16k + ana_align_delay[0]; - move16(); + shb_frame_fx = shb_old_speech_fx + L_SUBFR16k + ana_align_delay; + + set16_fx( shb_old_speech_fx, 0, L_LOOK_16k + L_SUBFR16k + L_FRAME16k ); /* set up the speech buffers for TBE processing*/ - shb_new_speech_fx = shb_old_speech_fx + ( L_LOOK_16k + L_SUBFR16k ); + delay = L_LOOK_16k + L_SUBFR16k; move16(); - Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( L_LOOK_16k + L_SUBFR16k ) ); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + shb_new_speech_fx = shb_old_speech_fx + delay - L_MEM_RECALC_TBE_16K; + } + ELSE + { + shb_new_speech_fx = shb_old_speech_fx + delay; + } + + Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, delay ); Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( L_LOOK_16k + L_SUBFR16k ) ); + Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, delay ); /* autocorrelation of SHB speech for 10-th order LP analysis */ autocorr_fx( shb_old_speech_fx, @@ -2035,11 +2472,12 @@ void swb_tbe_enc_fx( /* Spectral smoothing of autocorrelation coefficients */ test(); - IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + test(); + IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_h[i - 1], wac_swb_l[i - 1] ); + L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_ivas_h[i - 1], wac_swb_ivas_l[i - 1] ); L_Extract( L_tmp, &R_h[i], &R_l[i] ); } } @@ -2048,7 +2486,7 @@ void swb_tbe_enc_fx( R_l[0] = s_max( R_l[0], 1 ); move16(); - E_LPC_lev_dur( R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL ); /* LPC in Q14 */ + E_LPC_lev_dur_fx( R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL ); /* LPC in Q14 */ { Word16 enerG, lpc_shb1[M + 1]; @@ -2060,19 +2498,34 @@ void swb_tbe_enc_fx( enerG = Enr_1_Az_fx( lpc_shb1, 2 * L_SUBFR ); /* Q3 */ /* if the LP gain is greater than a threshold, avoid saturation */ - IF( GT_16( enerG, 256 /*32 Q3*/ ) ) + Word16 flag_sat = 0; + Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); + IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) + { + FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) + { + IF( LT_16( norm_s( lpc_shb_fx[i] ), lpc_shb_fx0_req_shift ) ) + { + flag_sat = 1; + break; + } + } + } + + IF( GT_16( enerG, 256 /* 32.0 in Q3 */ ) || flag_sat ) { set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); - E_LPC_lev_dur( R_h, R_l, lpc_shb_fx, LepsP, 2, NULL ); /* LPC in Q14 */ + E_LPC_lev_dur_fx( R_h, R_l, lpc_shb_fx, LepsP, 2, NULL ); /* LPC in Q14 */ } } /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); + scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Expand bandwidth of the LP coeffs */ test(); - IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + test(); + IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { @@ -2081,6 +2534,8 @@ void swb_tbe_enc_fx( } } + /* stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); */ + /* LPC to LSP conversion */ /* LPC: Q12, LSP: Q15 */ E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); @@ -2089,17 +2544,35 @@ void swb_tbe_enc_fx( /* LSP: Q15, LSF: Q15 */ E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); - /* Input signal filtering in case of tonal sounds in the high band - gain Frame smoothing and attenuation control */ - gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); + test(); + test(); + IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) + { + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + // hBWE_TD->prev_lsp_shb_fx[i] = i / 20.0f; // This value in float enc is lsf. + hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_swb_tbe_enc_fx[i]; // lsf converted to lsp as fixed enc stores lsp. + move16(); + } + } + + // if ( stab_check == 0 ) + //{ + // mvr2r( hBWE_TD->prev_lsp_shb, lsf_shb, LPC_SHB_ORDER ); + // } Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); + /* Input signal filtering in case of tonal sounds in the high band + gain Frame smoothing and attenuation control */ + gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); + test(); - IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) + test(); + IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { - lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); + lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); /* to compensate for the 1.1* weighting done inside the function lsp_weights */ /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ @@ -2113,13 +2586,21 @@ void swb_tbe_enc_fx( Copy( swb_tbe_lsfvq_cbook_8b + i * LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER ); set16_fx( hBWE_TD->lsf_idx, 0, NUM_Q_LSF ); - hBWE_TD->lsf_idx[0] = i; - move16(); + + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) + { + push_indice( hBstr, IND_SHB_LSF, i, 8 ); + } + ELSE + { + hBWE_TD->lsf_idx[0] = i; + move16(); + } } ELSE { /* LSF quantization (21 bits) */ - Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); + Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); } /* space the lsfs to assert a minimum distance */ @@ -2146,7 +2627,7 @@ void swb_tbe_enc_fx( Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); test(); - IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) + IF( EQ_16( st_fx->coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { @@ -2177,72 +2658,72 @@ void swb_tbe_enc_fx( Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - lsf_diff[0] = lsf_diff[LPC_SHB_ORDER - 1] = 16384; /*Q15*/ + lsf_diff_fx[0] = lsf_diff_fx[sub( LPC_SHB_ORDER, 1 )] = 16384; /*Q15*/ move16(); FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); + lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); move16(); } - a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); + a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl_fx, M ); /* LSP interpolation for 13.2 kbps and 16.4 kbps */ - /* tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) - - 3.8714f * (1.0f + refl[0]) + /* tilt_para_fx = 6.6956f * (1.0f + refl_fx[0]) * (1.0f + refl_fx[0]) + - 3.8714f * (1.0f + refl_fx[0]) + 1.3041f; */ - tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ - tmp1 = mult( 27425 /*Q12*/, tmp ); /*Q11*/ + tmp = add( 16384, shr( refl_fx[0], 1 ) ); /*Q14*/ + tmp1 = mult( 27425 /*Q12*/, tmp ); /*Q11*/ tmp1 = mult( tmp1, tmp ); - tmp2 = shr( mult( 31715, tmp ), 2 ); /* Q11 */ - tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ + tmp2 = shr( mult( 31715, tmp ), 2 ); /* Q11 */ + tilt_para_fx = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ IF( NE_16( st_fx->last_extl, SWB_TBE ) ) { FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff[i], 16384 ); /*Q15*/ + hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff_fx[i], 16384 ); /*Q15*/ move16(); } } - IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) + IF( LE_32( st_fx->extl_brate, FB_TBE_1k8 ) ) { test(); test(); test(); test(); test(); - IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && - !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( hBWE_TD->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) + IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 /* 5.0f in Q10 */ ) && ( EQ_16( st_fx->coder_type, TRANSITION ) || LT_16( tilt_para_fx, 1024 /* 1.0f in Q10 */ ) ) ) && + !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 /* 3.0f in Q10 */ ) && GE_16( hBWE_TD->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para_fx, 5120 /* 5.0f in Q10 */ ) ) ) { FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) + IF( LT_16( lsf_diff_fx[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) { - tmp = mult( 26214, lsf_diff[i] ); + tmp = mult( 26214, lsf_diff_fx[i] ); tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); + w_fx[i] = s_min( tmp, 32767 ); move16(); } ELSE { tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - tmp = div_s( tmp, lsf_diff[i] ); + tmp = div_s( tmp, lsf_diff_fx[i] ); tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); + w_fx[i] = s_min( tmp, 32767 ); move16(); } } - w[0] = w[1]; + w_fx[0] = w_fx[1]; move16(); - w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; + w_fx[LPC_SHB_ORDER - 1] = w_fx[LPC_SHB_ORDER - 2]; move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w[i] ) ); - tmp2 = mult( lsp_shb_2_fx[i], w[i] ); + tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w_fx[i] ) ); + tmp2 = mult( lsp_shb_2_fx[i], w_fx[i] ); lsp_temp_fx[i] = add( tmp1, tmp2 ); move16(); } @@ -2253,14 +2734,14 @@ void swb_tbe_enc_fx( } } - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = tilt_para; + Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = tilt_para_fx; move16(); shb_ener_sf_Q31 = 0; move16(); test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) + IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) { /* ---------- SHB LSP interpolation ---------- */ ptr_lsp_interp_coef_fx = interpol_frac_shb; /* Q15 */ @@ -2293,7 +2774,7 @@ void swb_tbe_enc_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 ); - Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, ( 2 * Q_shb ) ); + Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ set16_fx( shb_res_fx, 0, L_FRAME16k ); @@ -2307,7 +2788,7 @@ void swb_tbe_enc_fx( set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); FOR( i = 0; i < NB_SUBFR16k; i++ ) { - shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i * 64, 64 ); + shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i_mult( i, 64 ), 64 ); move32(); } /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ @@ -2319,3598 +2800,2088 @@ void swb_tbe_enc_fx( /* case when den = 0 */ recip = 0; /*instead of 32767 to be compatible with previous root_a_over_b_fx() output */ + move16(); Q_recip = 0; + move16(); IF( L_tmp ) { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); recip = div_s( 16384, tmp ); - // Q_recip = 31 - ( exp - 14 ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + // Q_recip = sub( 31, sub( exp, 14 ) ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ - move16(); } FOR( i = 0; i < NB_SUBFR16k; i++ ) { L_tmp1 = Mult_32_16( shb_res_gshape_fx_32[i], recip ); /*Q = Q_recip+1-16*/ - L_tmp = root_a_fx( L_tmp1, add( Q_recip, 1 - 16 ), &exp ); + L_tmp = root_a_fx( L_tmp1, sub( Q_recip, 15 ), &exp ); shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /* Q14 */ move16(); } Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); } + ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + FOR( j = 0; j < 4; j++ ) + { + tmp = i_mult2( j, ( LPC_SHB_ORDER + 1 ) ); + /* convert LSPs to LPC coefficients for SHB synthesis*/ + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); + /* Bring the LPCs to Q12 */ + Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); + } + + /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ + set16_fx( shb_res_fx, 0, L_FRAME16k ); + Residu3_10_fx( lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); + Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); + } + Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ /* for 13.2 and 16.4kbps */ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ - /* Save the SWB LSP values from current frame for interpolation */ - Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = L_deposit_l( 0 ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if ( Lmax == 0 ) - { - Q_bwe_exc = 31; - move16(); - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); + /* Determine formant PF strength */ + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); + /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); + /* calculate SHB auto-correlation function and convert to SHB voicing factor */ + // acorr_v2a = 0.0f; + L_tmp = 0; + move32(); + acorr_v2a_fx = 0; + move16(); - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); - if ( GT_16( Q_bwe_exc, tmp2 ) ) + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - Q_bwe_exc = tmp2; - move16(); - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_enc( st_fx, sc ); - } + /* calculate the TD envelope of the SHB residual signal */ + Scale_sig( hBWE_TD->mem_shb_res_fx, MAX_LEN_MA_FILTER, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ + find_td_envelope_fx( shb_res_fx, L_FRAME16k, 20, hBWE_TD->mem_shb_res_fx, EnvSHBres_fx ); /* Q_shb */ - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); + /* downsample the TD envelope by 4 */ + FOR( k = 0; k < L_FRAME4k; k++ ) + { + EnvSHBres_4k_fx[k] = EnvSHBres_fx[4 * k]; /* Q_shb */ + 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 ) ); + /* calculate long-term mean envelope over four consecutive segments using linear interpolation */ + seg_len = L_FRAME4k / 4; move16(); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - - /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; - move16(); - /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ - vf_ind_fx = 20; - move16(); - - 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, - &( 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, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0 ); - - *Q_white_exc = Q_bwe_exc_fb; - move16(); - IF( EQ_16( st_fx->extl, FB_TBE ) ) - { - hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + den_seg_len = 1638; /* Q15 */ move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - hBWE_TD->prev_Q_bwe_exc_fb = 51; + seg_len_2 = L_FRAME4k / 8; move16(); - } - - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + den_seg_len_2 = 3641; /* Q15 */ + move16(); + FOR( k = 0; k < 4; k++ ) { - hBWE_TD->idx_mixFac = vf_ind_fx; + // seg_mean[k] = max(1.0f, mean(&EnvSHBres_4k[k * seg_len], seg_len)); + seg_mean[k] = s_max( 1, mean_no_sat_fx( &EnvSHBres_4k_fx[k * seg_len], seg_len ) ); /* Q_shb */ + move16(); + // den_seg_mean[k] = 1.0f / seg_mean[k]; + tmp = BASOP_Util_Divide1616_Scale( MAX16B, seg_mean[k], &tmp_e ); + tmp_e = sub( tmp_e, sub( 15, Q_shb ) ); + den_seg_mean[k] = shl_sat( tmp, tmp_e ); /* Q15 */ move16(); } + + /* first half of the first segment */ + IF( hBWE_TD->old_mean_EnvSHBres_fx == 0 ) + { + set16_fx( env_mean_normf_fx, den_seg_mean[0], seg_len_2 ); + } ELSE { - push_indice( st_fx->hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF ); + env_mean_normf_fx[0] = hBWE_TD->old_mean_EnvSHBres_fx; /* Q15 */ + move16(); + // step = (den_seg_mean[0] - hBWE_TD->old_mean_EnvSHBres) * den_seg_len_2; + step = mult( sub( den_seg_mean[0], hBWE_TD->old_mean_EnvSHBres_fx ), den_seg_len_2 ); /* Q15 */ + FOR( i = 1; i < seg_len_2; i++ ) + { + env_mean_normf_fx[i] = add_sat( env_mean_normf_fx[i - 1], step ); /* Q15 */ + move16(); + } } - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ - } - Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - - tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); - prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ - } + /* segments 1-4 */ + p_env = &env_mean_normf_fx[seg_len_2]; + FOR( k = 1; k < 4; k++ ) + { + // step = ( den_seg_mean[k] - den_seg_mean[k - 1] ) * den_seg_len; + step = mult( sub( den_seg_mean[k], den_seg_mean[k - 1] ), den_seg_len ); + FOR( i = 0; i < seg_len; i++ ) + { + *p_env = add_sat( *( p_env - 1 ), step ); + move16(); + p_env++; + } + } - Lscale = root_a_over_b_fx( curr_pow_fx, - shl( Q_bwe_exc, 1 ), - prev_pow_fx, - shl( Q_bwe_exc, 1 ), - &exp ); - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - IF( exp < 0 ) - { - Lscale = L_shl( Lscale, exp ); - exp = 0; + /* last half of the last segment */ + // set_f( p_env, den_seg_mean[3], seg_len_2 ); + set16_fx( p_env, den_seg_mean[3], seg_len_2 ); + hBWE_TD->old_mean_EnvSHBres_fx = den_seg_mean[3]; move16(); - } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + + /* normalize residual SHB envelope with its long-term mean envelope */ + FOR( k = 0; k < L_FRAME4k; k++ ) { - tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ - tmp = sub( 32767 /*1.0f Q15*/, tmp ); - Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); + tmp_buf[k] = L_mult( EnvSHBres_4k_fx[k], env_mean_normf_fx[k] ); // Q_shb + Q15 + Q1 => Q_shb + Q16 + move32(); } - } - ELSE - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + Q_EnvSHBres_4k_norm = sub( getScaleFactor32( tmp_buf, L_FRAME4k ), 1 /* Guard bit */ ); + FOR( k = 0; k < L_FRAME4k; k++ ) { - tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ - tmp = sub( 32767 /*1.0f Q15*/, tmp ); - Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + EnvSHBres_4k_norm_fx[k] = extract_h( L_shl( tmp_buf[k], Q_EnvSHBres_4k_norm ) ); // Q_shb + Q16 + Q_EnvSHBres_4k_norm - Q16 => Q_EnvSHBres_4k_norm + Q_shb move16(); } - } - /* Update SHB excitation */ - Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ + /* calculate tilt of the long-term mean envelope */ + lls_interp_n_fx( seg_mean, 4, &shb_env_tilt_fx, &temp, 0 ); - /* Estimate the gain-shape parameter */ - n_subfr_saturation = 0; - move16(); - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 1 ); + /* copy previous residual envelope to the buffer */ + Copy_Scale_sig( hBWE_TD->old_EnvSHBres_fx, buf_EnvSHBres_fx, L_FRAME4k, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ - /* Gain shape BWS/high band low energy fix */ - IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ - { - /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + /* subtract mean value from the normalized SHB residual envelope */ + p_buf = &buf_EnvSHBres_fx[L_FRAME4k]; + temp = mean_no_sat_fx( EnvSHBres_4k_norm_fx, L_FRAME4k ); // Q_EnvSHBres_4k_norm + Q_shb + FOR( k = 0; k < L_FRAME4k; k++ ) { - /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ - /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ - GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); + *p_buf++ = shr( sub( EnvSHBres_4k_norm_fx[k], temp ), Q_EnvSHBres_4k_norm ); // Q_shb move16(); } - } - - /* Gain frame adjustment factor */ - /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ - test(); - IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) - { - exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); - L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ - exp1 = sub( exp, exp1 ); /*move16(); */ - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_swb_fac = 0; - move16(); - } - L_feedback = L_mult0( temp_swb_fac, temp_swb_fac ); + Q_EnvSHBres_4k_norm = add( Q_EnvSHBres_4k_norm, Q_shb ); + /* update memory */ + Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); // Q_shb - FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) - { - test(); - IF( GainShape_fx[i] && GainShape_fx[i - 1] ) + /* calculate energy normalization factor for the auto-correlation function */ + // pow0 = sum2_f( &buf_EnvSHBres[L_FRAME4k], L_FRAME4k ) + 1.0f; + pow_e = sub( 15, Q_shb ); + pow0_fx = sum2_16_exp_fx( &buf_EnvSHBres_fx[L_FRAME4k], L_FRAME4k, &pow_e, 0 /* Give guard bits */ ) + 1; + // if (hBWE_TD->prev_enr_EnvSHBres == 1.0f) + IF( BASOP_Util_Cmp_Mant32Exp( hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e, 1, 31 ) == 0 ) { - exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); - L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + // scale = 1.0f / pow0; + scale_fx = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, pow0_fx, &tmp_e ); + scale_e = sub( tmp_e, pow_e ); } ELSE { - temp_swb_fac = 0; - move16(); + // scale = 1.0f / max( pow0, hBWE_TD->prev_enr_EnvSHBres ); + L_tmp1 = pow0_fx; + move32(); + IF( BASOP_Util_Cmp_Mant32Exp( L_tmp1, pow_e, hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e ) < 0 ) + { + L_tmp1 = hBWE_TD->prev_enr_EnvSHBres_fx; + move32(); + pow_e = hBWE_TD->prev_enr_EnvSHBres_e; + move16(); + } + scale_fx = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_tmp1, &tmp_e ); // Qs to be handled + scale_e = sub( tmp_e, pow_e ); } + hBWE_TD->prev_enr_EnvSHBres_fx = pow0_fx; + move32(); + hBWE_TD->prev_enr_EnvSHBres_e = pow_e; + move16(); - L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); - } + /* calculate normalized auto-correlation function on the residual normalized SHB envelope */ + p_acorr = acorr_EnvSHBres; + p_buf = &buf_EnvSHBres_fx[L_FRAME4k - ENVSHBRES_ACORR_MIN]; - /* feedback = 0.4f / (1 + 0.5f * feedback) */ - L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl( 1, 21 ) ); /* Q21 */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /*Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ - feedback = round_fx( L_tmp ); /*Q15 */ - } - ELSE - { - feedback = 8738; - move16(); /*Q15 */ - } + FOR( k = 0; k < ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN; k++ ) + { + //*p_acorr++ = scale * dotp(&buf_EnvSHBres[L_FRAME4k], p_buf--, L_FRAME4k); + Word64 W_tmp = 0; + move64(); - /* voicing in Q15 */ - L_tmp = L_mult( voicing[0], 8192 ); - L_tmp = L_mac( L_tmp, voicing[1], 8192 ); - L_tmp = L_mac( L_tmp, voicing[2], 8192 ); - tmp = sum1 = round_fx( L_tmp ); /* sum1 used again below - Q13 */ - tmp = add( tmp, 1 ); /* To ensure change is BE */ + // tmp = *p_buf; + FOR( i = 0; i < L_FRAME4k; ++i ) + { + L_tmp = L_mult( buf_EnvSHBres_fx[L_FRAME4k + i], p_buf[i] ); // 2 * Q_shb + 1 + W_tmp = W_add( W_tmp, W_deposit32_l( L_tmp ) ); + } + p_buf--; + tmp_e = W_norm( W_tmp ); + L_tmp1 = W_extract_h( W_shl( W_tmp, tmp_e ) ); // 2 * Q_shb + tmp_e - 31 + L_tmp = Mpy_32_16_1( L_tmp1, scale_fx ); /* 2 * Q_shb + tmp_e - 31 - scale_e */ + //*p_acorr++ = extract_h( L_shl( L_tmp, add( 16, Q_shb ) - ( 2 * Q_shb + tmp_e - 31 - scale_e ) ) ); + *p_acorr++ = extract_h( L_shl( L_tmp, sub( add( 16, Q_shb ), sub( sub( add( shl( Q_shb, 1 ), tmp_e ), 31 ), scale_e ) ) ) ); + move16(); + } - /* voice_factors_fx in Q15 */ - L_tmp = L_mult( voice_factors_fx[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); - tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ + /* calculate variance of the SHB autocorrelation function */ + // acorr_v2a = sum2_f( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN ) / ( ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN ); + tmp_e = sub( 15, Q_shb ); + L_tmp = Mpy_32_32( sum2_16_exp_fx( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN, &tmp_e, 0 ), 53687091 /* 1 / ( ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN ) in Q31 */ ); + /* multiply with the maximum of the SHB autocorrelation function */ + maximum_fx( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN, &temp ); + // acorr_v2a *= temp; + L_tmp = Mpy_32_16_1( L_tmp, temp ); /* 31 - tmp_e + Q_shb - 15 */ - test(); - test(); - IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 ) && GT_16( tmp1, 6554 ) ) ) + // alpha = 25.0f; + alpha_fx = -1677721600; // Q26 + move32(); - { - temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; + // acorr_v2a = 2.0f / ( 1.0f + (float) expf( -alpha * acorr_v2a ) ) - 1.0f; + Word32 exp_tmp = 1459366444; + Word16 exp_e = 2; + Word16 res_e = 0; + move32(); move16(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + move16(); + + L_tmp = Mpy_32_32( alpha_fx, L_tmp ); // 31 - tmp_e + Q_shb - 15 - 5 + + tmp_e = sub( 31, sub( sub( add( sub( 31, tmp_e ), Q_shb ), 15 ), 5 ) ); + + // L_tmp = BASOP_Util_fPow(exp_tmp, exp_e, 2, 31, &res_e); + + L_tmp = BASOP_Util_fPow( exp_tmp, exp_e, L_tmp, tmp_e, &res_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q31, 0, L_tmp, res_e, &tmp_e ); + acorr_v2a_fx = BASOP_Util_Divide3232_Scale( 2, L_tmp, &res_e ); + + res_e = sub( add( res_e, 31 ), tmp_e ); + + res_e = BASOP_Util_Add_MantExp( acorr_v2a_fx, res_e, -1, 15, &acorr_v2a_fx ); + + /* limit in the range 0.0 - 1.0 */ + // acorr_v2a = min( 1.0f, max( 0.0f, acorr_v2a ) ); + acorr_v2a_fx = shl_sat( acorr_v2a_fx, res_e ); + + if ( acorr_v2a_fx < 0 ) { - /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ - GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); - move16(); - temp_swb_fac = GainShape_fx[i]; + acorr_v2a_fx = 0; move16(); } - } - hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; - move16(); - - /* Compute the power of gains away from the peak gain prior to quantization */ - p2m_in_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); - /* Quantization of the gain shape parameter */ + hBWE_TD->prev_shb_env_tilt_fx = shb_env_tilt_fx; + move16(); + hBWE_TD->prev_Q_shb = Q_shb; + move16(); + } - QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); - /* o: GainShape_fx in Q15 */ - /* Compute the power of gains away from the peak gain after quantization */ - p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); + /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ + vf_ind_fx = 20; + move16(); - /* Estimate the gain parameter */ - 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 ); + /* Save the SWB LSP values from current frame for interpolation */ - IF( EQ_16( st_fx->tec_tfa, 1 ) ) + /* -------- start of memory rescaling -------- */ + /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ + Lmax = L_deposit_l( 0 ); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { - tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - - /* 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. */ - IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) ) + Q_bwe_exc = norm_l( Lmax ); + if ( Lmax == 0 ) { - L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); - GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ + Q_bwe_exc = 31; + move16(); } - test(); - IF( EQ_16( frGainSmoothEn, 1 ) && LT_32( hBWE_TD->prev_gainFr_SHB_fx, GainFrame_fx ) ) + Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); + + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ + find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); + + tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); + if ( GT_16( Q_bwe_exc, tmp2 ) ) { - GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ + Q_bwe_exc = tmp2; + move16(); } - test(); - test(); - IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) + /* rescale the memories if Q_bwe_exc is different from previous frame */ + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); + IF( sc != 0 ) { - exp1 = norm_l( GainFrame_fx ); - frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); - exp = sub( 30, add( exp1, 21 ) ); - L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - GainFrame_fx = Pow2( 30, frac ); - exp = sub( exp, 30 ); - GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ + rescale_genSHB_mem_enc( st_fx, sc ); } - ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) + + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); + /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { - /*GainFrame *= (0.8f + 0.5f*feedback); */ - tmp = add( 26214, mult_r( feedback, 16384 ) ); - GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ + bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + move16(); } - hBWE_TD->prev_frGainAtten = frGainAttenuate; + + /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + + /* save the previous Q factor of the buffer */ + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); - hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; - move16(); /* Q18 */ + Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ - tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + /* -------- end of rescaling memories -------- */ + Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; + move16(); + +#ifdef HARMONIZE_TBE2 + GenShapedSHBExcitation_ivas_fx( ENC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, +#else + GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, +#endif + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, 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, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, + nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, + &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); + + *Q_white_exc = Q_bwe_exc_fb; + move16(); + IF( EQ_16( st_fx->extl, FB_TBE ) ) { - tmp1 = mult_r( 6554 /*0.2f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + move16(); } ELSE { - tmp1 = mult_r( 3277 /*0.1f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ + /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. + 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ + hBWE_TD->prev_Q_bwe_exc_fb = 51; + move16(); } - /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ - L_tmp = L_min( L_tmp, 8192l /*1.0f Q13*/ ); - L_tmp = L_max( L_tmp, 4096l /*0.5f Q13*/ ); /* Q13 */ - /* keep the L_tmp; dont overwrite */ - /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ - /* pitch_buf: Q6 */ - pitBufAvg_fx = mult_r( pitch_buf[0], 1311 ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[1], 1311 ) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[2], 1311 ) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[3], 1311 ) ); /* Q10 */ + /* fill-in missing SHB excitation */ + test(); + test(); + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) + { + Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + } - /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ - tmp2 = 5462 /*0.1667f Q15*/; - move16(); - if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) + test(); + IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) { - tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ + Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k ); + hStereoICBWE->shbSynthRef_e = sub( 15, Q_bwe_exc ); move16(); } - voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - - /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ - /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ - - /* 1/voicingBufAvg_fx */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) + test(); + test(); + IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ - - /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ - tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + hBWE_TD->idx_mixFac = vf_ind_fx; + move16(); + } + ELSE + { + push_indice( hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF ); + } } - tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); - tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); - GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); + move16(); + } test(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) + IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ - } - /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind ); + FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) + { + PostShortTerm_ivas_enc_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); + /* i: shaped_shb_excitation_fx in Q_bwe_exc */ + /* i: lpc_shb_fx in Q12 */ + } + Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation */ - IF( EQ_32( st_fx->extl, FB_TBE ) ) - { - tmp = norm_l( GainFrame_fx ); - if ( GainFrame_fx == 0 ) + Word16 max_val; + maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); + IF( max_val == 0 ) { - tmp = 31; + Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ + move32(); + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ + move32(); + } + exp = 0; move16(); } - L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ + ELSE + { + Word64 prev_pow_64fx, curr_pow_64fx; + Word16 w_shift; + tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); + prev_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) + { + prev_pow_64fx = W_mac0_16_16( prev_pow_64fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + } - tmp1 = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ + curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ + } + + w_shift = s_min( W_norm( prev_pow_64fx ), W_norm( curr_pow_64fx ) ); + prev_pow_fx = W_extract_h( W_shl( prev_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 + curr_pow_fx = W_extract_h( W_shl( curr_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 + w_shift = sub( add( shl( Q_bwe_exc, 1 ), w_shift ), 32 ); + + Lscale = root_a_over_b_fx( curr_pow_fx, + w_shift, + prev_pow_fx, + w_shift, + &exp ); + } + + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ - /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); - /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ - tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); - /*White_exc16k_fx[i] =32767;*/ - /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) + IF( exp < 0 ) { - tmp = 15; + Lscale = L_shl( Lscale, exp ); + exp = 0; move16(); } - - FOR( i = 0; i < L_FRAME16k; i++ ) + /* + code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues + thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations + */ + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); - move16(); + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + { + tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ + tmp = sub( 32767 /*1.0f Q15*/, tmp ); + L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); + } } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); + ELSE + { + FOR( ; i < L_SHB_LAHEAD + 10; i++ ) + { + tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ + tmp = sub( 32767 /*1.0f Q15*/, tmp ); + L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); + } + } + } + ELSE + { + /* reset the PF memories if the PF is not running */ + set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; move16(); + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); } - /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; - move16(); + /* Update SHB excitation */ + Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - return; -} + /* Estimate the gain-shape parameter */ + n_subfr_saturation = 0; + move16(); + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, + Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + /* Gain shape attenuation in case of big error in envelope modelling */ + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + IF( GT_16( Env_error_part_fx[i], 100 ) ) + { + /* set gain shape to the average of the remaining gains */ + // GainShape[i] = ( sum_f( GainShape, NUM_SHB_SUBGAINS ) - GainShape[i] ) / ( NUM_SHB_SUBGAINS - 1 ); + L_tmp = L_sub( sum16_32_fx( GainShape_fx, NUM_SHB_SUBGAINS ), GainShape_fx[i] ); + tmp = BASOP_Util_Divide3232_Scale( L_tmp, NUM_SHB_SUBGAINS - 1, &exp ); + GainShape_fx[i] = shl( tmp, sub( exp, 15 ) ); /* Q15 */ + move16(); + } + } + } -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_enc_ivas_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE encoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band encoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type : coding type */ -/* _(Word16*) shb_speech_fx : SHB target signal (6-14kHz) at 16kHz Q0 */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16[])White_exc16k_fx : shaped white excitation for the FB TBE Q_white_exc */ -/* _(Word16*)fb_slope_fx : slope +ve (high freq > low freq), -ve or neutral Q12 */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Encoder_State *st_fx: : Encoder state structure */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*======================================================================================*/ + test(); + IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + /* Gain shape BWS/high band low energy fix */ + IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ + { + /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ + /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ + GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); + move16(); + } + } + } -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 */ - 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 */ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6 */ -) -{ - Word16 i, j, k, delay; + /* high-band gain control in case of BWS */ + test(); + IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + IF( st_fx->bwidth_sw_cnt > 0 ) + { + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + // GainShape[i] *= ( (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD ); + tmp = i_mult( st_fx->bwidth_sw_cnt, ONE_BY_BWS_TRAN_PERIOD_Q15 ); + GainShape_fx[i] = mult( GainShape_fx[i], tmp ); + move16(); + } + } + } - Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; - Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - - Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; - Word32 GainFrame_fx; /* Q18 */ - Word16 GainShape_fx[NUM_SHB_SUBFR]; /* Q15 */ - Word16 lpc_shb_fx[LPC_SHB_ORDER + 1], lsp_shb_fx[LPC_SHB_ORDER], lsf_shb_fx[LPC_SHB_ORDER]; - Word16 weights_lsp[LPC_SHB_ORDER]; - Word16 Q_out; - Word16 *shb_frame_fx, *shb_new_speech_fx; - Word16 R_h[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech MSB */ - Word16 R_l[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech LSB */ - Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER + 1]; - - Word16 ana_align_delay; - Word32 prev_pow_fx, curr_pow_fx, Lscale; - Word32 p2m_in_fx, p2m_out_fx; - - Word16 exp_out, exp, exp1, frac; - Word16 cnt, n_mem, n_mem2; - Word32 L_tmp, L_tmp1; - Word16 Q_bwe_exc; - - Word16 frGainAttenuate, frGainSmoothEn; - Word16 MA_lsp_shb_spacing; - Word16 temp_swb_fac, feedback; - Word32 L_feedback; - Word16 tmp, tmp1, tmp2; - Word32 Lmax; - Word16 sc; - Word16 lsf_shb_orig_fx[LPC_SHB_ORDER]; - Word16 sd_uq_q_fx; - Word16 vf_modified_fx[NB_SUBFR16k]; - Word16 pitBufAvg_fx; - Word16 voicingBufAvg_fx; - Word16 sum1, sum2; - Word16 recip, Q_recip; - const Word16 *ptr_lsp_interp_coef_fx; - - Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; - Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )]; - - /*Word32 shb_ener_sf_fx_32[4];*/ - Word32 shb_ener_sf_Q31; - Word16 shb_res_fx[L_FRAME16k]; - Word16 shb_res_gshape_fx[NB_SUBFR16k]; - Word32 shb_res_gshape_fx_32[NB_SUBFR16k]; - Word16 vf_ind_fx; - - Word16 formant_fac_fx; - // int16_t stab_check = 1; - Word16 MSFlag; - Word16 *nlExc16k_fx, *nlExc16k_e, *mixExc16k_fx, *mixExc16k_e; + /* Gain frame adjustment factor */ + /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ + IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) + { + exp = 13 /* norm_s(3) */; + tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; + } + ELSE + { + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); + } - Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ - Word16 acorr_v2a_fx; /* Q15 */ + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ + exp1 = sub( exp, exp1 ); /*move16(); */ + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - Word16 acorr_EnvSHBres[ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN], *p_acorr, shb_env_tilt_fx; - Word16 buf_EnvSHBres_fx[2 * L_FRAME4k], *p_buf, EnvSHBres_fx[L_FRAME16k], EnvSHBres_4k_fx[L_FRAME4k], EnvSHBres_4k_norm_fx[L_FRAME4k], env_mean_normf_fx[L_FRAME4k]; - Word32 tmp_buf[L_FRAME4k]; - Word16 Q_EnvSHBres_4k_norm = Q31; - move16(); - Word16 GainShape_Interp_fx[NUM_SHB_SUBGAINS], GainShape_tilt_fx; /* Q15 */ - Word16 seg_mean[4], den_seg_mean[4], *p_env, step; - Word16 temp, scale_fx, scale_e, pow_e, tmp_e, tmp1_e; - Word16 seg_len, seg_len_2; - Word16 den_seg_len, den_seg_len_2, fact_atten_fx; /* Q15 */ - Word32 sum_gain_fx, normFact_fx; - Word32 pow0_fx, alpha_fx; - Word16 Env_error_part_fx[NUM_SHB_SUBGAINS], Env_error_fx; /* Q0 */ + L_feedback = L_mult( temp_swb_fac, temp_swb_fac ); - Word16 mean_vf; - Word16 lsf_diff_fx[LPC_SHB_ORDER], w_fx[LPC_SHB_ORDER]; - Word16 refl_fx[M]; - Word16 tilt_para_fx; - Word16 Q_bwe_exc_fb; - Word16 n_subfr_saturation; - Env_error_fx = 0; - move16(); - pitBufAvg_fx = 0; - move16(); - voicingBufAvg_fx = 0; - move16(); - set16_fx( Env_error_part_fx, 0, NUM_SHB_SUBGAINS ); - shb_env_tilt_fx = 0; - move16(); - sum1 = 0; - move16(); - sum2 = 0; - move16(); + FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + { + test(); + IF( GainShape_fx[i - 1] == 0 ) + { + exp = 13 /* norm_s(3) */; + tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; + } + ELSE + { + exp = norm_s( GainShape_fx[i - 1] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + } + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - /* init and buffers set up */ - exp1 = 0; /* to avoid compilation warnings */ - move16(); + L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + } - test(); - IF( st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) + /* feedback = 0.4f / (1 + 0.5f * feedback) */ + L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl( 1, 21 ) ); /* Q21 */ + IF( L_tmp != 0 ) { - nlExc16k_fx = hStereoICBWE->nlExc16k_fx; - nlExc16k_e = &hStereoICBWE->nlExc16k_e; - mixExc16k_fx = hStereoICBWE->mixExc16k_fx; - mixExc16k_e = &hStereoICBWE->mixExc16k_e; - MSFlag = hStereoICBWE->MSFlag; - move16(); + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( sub( 30, exp ), 21 ); + tmp = div_s( 16384, tmp ); /*Q(15+exp) */ + L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ + feedback = round_fx( L_tmp ); /*Q15 */ } ELSE { - nlExc16k_fx = NULL; - nlExc16k_e = NULL; - mixExc16k_fx = NULL; - mixExc16k_e = NULL; - MSFlag = 0; - move16(); + feedback = 8738; + move16(); /*Q15 */ } - set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); + /* calculate tilt in all sub-frame gains */ + Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); + lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); test(); - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) - { - ana_align_delay = -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) + 20; /* 20 corresponds to the 1.25 ms CLDFB delay */ - move16(); - } - ELSE + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - ana_align_delay = -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ); - move16(); - } - - /* compensate for the delay in target generation and subframe LA */ - shb_frame_fx = shb_old_speech_fx + L_SUBFR16k + ana_align_delay; - - set16_fx( shb_old_speech_fx, 0, L_LOOK_16k + L_SUBFR16k + L_FRAME16k ); + // if (acorr_v2a < 0.4f && vf_ind >= 5 && fabs(GainShape_tilt) < 0.2f && shb_env_tilt < 500.0f && hBWE_TD->prev_shb_env_tilt < 500.0f) + test(); + test(); + test(); + test(); + IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_Q_shb ) ) ) + { + /* stronger smoothing in case of unvoiced SHB residual signal with gaussian excitation */ + // feedback = lin_interp(acorr_v2a, 0.4f, 0.0f, 0.0f, 0.95f, 0); + feedback = lin_interp_ivas_fx( acorr_v2a_fx, 13107 /* 0.4f in Q15 */, 0, 0, 31130 /* 0.95f in Q15 */, 0 ); + // feedback = min( max( feedback, 0.0f ), 1.0f ); + feedback = s_min( s_max( feedback, 0 ), MAX16B ); - /* set up the speech buffers for TBE processing*/ - delay = L_LOOK_16k + L_SUBFR16k; - move16(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - shb_new_speech_fx = shb_old_speech_fx + delay - L_MEM_RECALC_TBE_16K; + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + // GainShape[i] = ( 1 - feedback ) * GainShape[i] + feedback * GainShape_Interp[i]; + GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i] ), feedback, GainShape_Interp_fx[i] ) ); + move16(); + } + } } ELSE { - shb_new_speech_fx = shb_old_speech_fx + delay; - } + /* voicing in Q15 */ + L_tmp = L_mult( voicing[0], 8192 ); + L_tmp = L_mac( L_tmp, voicing[1], 8192 ); + L_tmp = L_mac( L_tmp, voicing[2], 8192 ); + tmp = sum1 = round_fx( L_tmp ); /* sum1 used again below - Q13 */ + tmp = add( tmp, 1 ); /* To ensure change is BE */ - Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, delay ); - Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, delay ); + /* voice_factors_fx in Q15 */ + L_tmp = L_mult( voice_factors_fx[0], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); + L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); + tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ - /* autocorrelation of SHB speech for 10-th order LP analysis */ - autocorr_fx( shb_old_speech_fx, - LPC_SHB_ORDER + 1, - R_h, /* autocorr (msb) Q15 */ - R_l, /* autocorr (lsb) */ - &Q_R, - NS2SA( INT_FS_16k, ACELP_LOOK_NS ) + L_SUBFR16k + L_FRAME16k, - win_lpc_shb_fx, - 0, - 1 ); + test(); + test(); + IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 /* 2.4f in Q13 */ ) && GT_16( tmp1, 6554 /* 0.8f in Q13 */ ) ) ) - /* Spectral smoothing of autocorrelation coefficients */ - test(); - test(); - IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_ivas_h[i - 1], wac_swb_ivas_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); + temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; + move16(); + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ + GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); + move16(); + temp_swb_fac = GainShape_fx[i]; + move16(); + } } } - /* Set the autocorr[0] element to a non-negative value */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); - - E_LPC_lev_dur( R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL ); /* LPC in Q14 */ + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - Word16 enerG, lpc_shb1[M + 1]; - - /* extend the lpc_shb to a 16th order gain calc */ - set16_fx( lpc_shb1, 0, M + 1 ); - Copy( lpc_shb_fx, lpc_shb1, LPC_SHB_ORDER + 1 ); - - /* estimate the LP gain */ - enerG = Enr_1_Az_fx( lpc_shb1, 2 * L_SUBFR ); /* Q3 */ - - /* if the LP gain is greater than a threshold, avoid saturation */ - Word16 flag_sat = 0; - Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); - IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) - { - IF( LT_16( norm_s( lpc_shb_fx[i] ), lpc_shb_fx0_req_shift ) ) - { - flag_sat = 1; - break; - } - } - } - - IF( GT_16( enerG, 256 /* 32.0 in Q3 */ ) || flag_sat ) + /* Re-normalize gain shape before quantization */ + // sum_gain = sum2_f(GainShape, NUM_SHB_SUBGAINS); + tmp = 0; + move16(); + sum_gain_fx = sum2_16_exp_fx( GainShape_fx, NUM_SHB_SUBGAINS, &tmp, 2 ); + IF( sum_gain_fx == 0 ) { - set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); - E_LPC_lev_dur( R_h, R_l, lpc_shb_fx, LepsP, 2, NULL ); /* LPC in Q14 */ + normFact_fx = 0; + move16(); } - } - - /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); - - /* Expand bandwidth of the LP coeffs */ - test(); - test(); - IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) + ELSE { - lpc_shb_fx[i] = mult_r( lpc_shb_fx[i], lpc_weights_fx[i] ); - move16(); + // normFact = (float) sqrt( 1.0f / sum_gain ); + normFact_fx = ISqrt32( sum_gain_fx, &tmp ); } - } - - /* stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); */ - - /* LPC to LSP conversion */ - /* LPC: Q12, LSP: Q15 */ - E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); - /* LSP to LSF conversion */ - /* LSP: Q15, LSF: Q15 */ - E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); - - test(); - test(); - IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + // v_multc( GainShape, normFact, GainShape, NUM_SHB_SUBGAINS ); + FOR( i = 0; i < NUM_SHB_SUBGAINS; ++i ) { - // hBWE_TD->prev_lsp_shb_fx[i] = i / 20.0f; // This value in float enc is lsf. - hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_swb_tbe_enc_fx[i]; // lsf converted to lsp as fixed enc stores lsp. + GainShape_fx[i] = extract_h( L_shl( Mpy_32_16_1( normFact_fx, GainShape_fx[i] ), tmp ) ); /* Q15 */ move16(); } } - // if ( stab_check == 0 ) - //{ - // mvr2r( hBWE_TD->prev_lsp_shb, lsf_shb, LPC_SHB_ORDER ); - // } - - Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); - Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); - - /* Input signal filtering in case of tonal sounds in the high band - gain Frame smoothing and attenuation control */ - gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); + hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; + move16(); - test(); - test(); - IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) + /* Compute the power of gains away from the peak gain prior to quantization */ + IF( st_fx->element_mode > EVS_MONO ) { - lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); - - /* to compensate for the 1.1* weighting done inside the function lsp_weights */ - /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ - weights_lsp[3] = mult_r( weights_lsp[3], 29789 /*0.909091f Q15*/ ); - move16(); - weights_lsp[4] = mult_r( weights_lsp[4], 29789 /*0.909091f Q15*/ ); - move16(); - - /* 8-bit VQ, 10 dimension */ - i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); - Copy( swb_tbe_lsfvq_cbook_8b + i * LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER ); - - set16_fx( hBWE_TD->lsf_idx, 0, NUM_Q_LSF ); - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - push_indice( hBstr, IND_SHB_LSF, i, 8 ); - } - ELSE - { - hBWE_TD->lsf_idx[0] = i; - move16(); - } + p2m_in_fx = pow_off_pk_corrected_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); } ELSE { - /* LSF quantization (21 bits) */ - Quant_BWE_LSF_ivas_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); + p2m_in_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); } - /* space the lsfs to assert a minimum distance */ - space_lsfs_fx( lsf_shb_fx, LPC_SHB_ORDER ); + /* Quantization of the gain shape parameter */ + QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); - /* voice factor adjustment and gainframe attenuation factor */ - tmp = sub( lsf_shb_fx[0], lsf_shb_orig_fx[0] ); - L_tmp = L_mult( tmp, tmp ); - FOR( i = 1; i < LPC_SHB_ORDER; i++ ) + /* Compute the power of gains away from the peak gain after quantization */ + IF( st_fx->element_mode > EVS_MONO ) { - /* Estimate the QD in lsfs between UQ and Q */ - tmp = sub( lsf_shb_fx[i], lsf_shb_orig_fx[i] ); - L_tmp = L_mac( L_tmp, tmp, tmp ); + p2m_out_fx = pow_off_pk_corrected_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); + } + ELSE + { + p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); } - sd_uq_q_fx = round_fx( L_tmp ); /* sd_uq_q_fx in Q15 */ - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors_fx[i], 4); */ - - L_tmp = L_mult( voice_factors_fx[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); - mean_vf = mac_r( L_tmp, voice_factors_fx[3], 8192 ); - - Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); - test(); - IF( EQ_16( st_fx->coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) + /* Gain shape smoothing after quantization */ + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - FOR( i = 1; i < NB_SUBFR; i++ ) + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - L_tmp = L_mult( voice_factors_fx[i], 26214 ); - vf_modified_fx[i] = mac_r( L_tmp, voice_factors_fx[i - 1], 6554 ); + GainShape_Interp_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS]; move16(); } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) + + lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); + + // if ( vf_ind >= 6 && fabs( GainShape_tilt ) < 0.12f ) + test(); + IF( GE_16( vf_ind_fx, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 /* 0.12f in Q15 */ ) ) { - L_tmp = L_mult( voice_factors_fx[4], 26214 ); - vf_modified_fx[4] = mac_r( L_tmp, voice_factors_fx[3], 6554 ); + // feedback = 0.3f; + feedback = 9830; /* 0.3f in Q15 */ move16(); + 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_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), feedback, GainShape_Interp_fx[i] ) ); // Q15 + move16(); + } + + FOR( i = NUM_SHB_SUBFR - 1; i > 0; i-- ) + { + GainShape_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + move16(); + } } } - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); + /* Estimate the gain parameter */ + 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 ); - test(); - IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); - } - ELSE + IF( EQ_16( st_fx->tec_tfa, 1 ) ) { - /* Use current frame's LSPs; in effect no interpolation */ - Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); + tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); } - lsf_diff_fx[0] = lsf_diff_fx[sub( LPC_SHB_ORDER, 1 )] = 16384; /*Q15*/ - move16(); - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) + /* 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. */ + IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) ) { - lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); - move16(); + L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); + GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ } - a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl_fx, M ); - - /* LSP interpolation for 13.2 kbps and 16.4 kbps */ - /* tilt_para_fx = 6.6956f * (1.0f + refl_fx[0]) * (1.0f + refl_fx[0]) - - 3.8714f * (1.0f + refl_fx[0]) - + 1.3041f; */ - tmp = add( 16384, shr( refl_fx[0], 1 ) ); /*Q14*/ - tmp1 = mult( 27425 /*Q12*/, tmp ); /*Q11*/ - tmp1 = mult( tmp1, tmp ); - tmp2 = shr( mult( 31715, tmp ), 2 ); /* Q11 */ - tilt_para_fx = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - IF( NE_16( st_fx->last_extl, SWB_TBE ) ) + // if ( st_fx->element_mode > EVS_MONO && st_fx->L_frame != st_fx->last_L_frame && hBWE_TD->prev_gainFr_SHB != 0 && ( st_fx->last_extl == SWB_TBE || st_fx->last_extl == FB_TBE ) && st_fx->coder_type == TRANSITION && st_fx->coder_type_raw != VOICED && st_fx->clas == VOICED_CLAS && st_fx->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st_fx->L_frame >> 6 ) - 1] ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->L_frame, st_fx->last_L_frame ) && hBWE_TD->prev_gainFr_SHB_fx != 0 && ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->coder_type, TRANSITION ) && NE_16( st_fx->coder_type_raw, VOICED ) && EQ_16( st_fx->clas, VOICED_CLAS ) && EQ_16( st_fx->last_clas, VOICED_CLAS ) && LT_16( mult( 24576 /* 3.0f in Q13 */, voice_factors_fx[0] ), shr( voice_factors_fx[( st_fx->L_frame >> 6 ) - 1], 2 ) ) ) { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) + // float fac = GainFrame / hBWE_TD->prev_gainFr_SHB; + Word16 fac = BASOP_Util_Divide3232_Scale( GainFrame_fx, hBWE_TD->prev_gainFr_SHB_fx, &tmp_e ); + + // if ( fac > 4.0f ) + IF( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( fac ), tmp_e, 1073741824, 3 ) > 0 ) { - hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff_fx[i], 16384 ); /*Q15*/ - move16(); + // GainFrame = 4.0f * GainFrame / fac; + GainFrame_fx = BASOP_Util_Divide3216_Scale( GainFrame_fx, fac, &tmp1_e ); + GainFrame_fx = L_shl( GainFrame_fx, add( tmp1_e, 2 ) ); /* Q18 */ } } - IF( LE_32( st_fx->extl_brate, FB_TBE_1k8 ) ) + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { + // if ( acorr_v2a > 0.1f && Env_error > 5.0f ) test(); test(); - test(); - test(); - test(); - IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 /* 5.0f in Q10 */ ) && ( EQ_16( st_fx->coder_type, TRANSITION ) || LT_16( tilt_para_fx, 1024 /* 1.0f in Q10 */ ) ) ) && - !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 /* 3.0f in Q10 */ ) && GE_16( hBWE_TD->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para_fx, 5120 /* 5.0f in Q10 */ ) ) ) + IF( GT_16( acorr_v2a_fx, 3277 /* 0.1f in Q15 */ ) && GT_16( Env_error_fx, 5 ) ) { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) + /* attenuate frame gain in case of voiced SHB residual signal with gaussian excitation */ + // fact_atten = lin_interp( Env_error, 5.0f, 1.0f, 25.0f, 0.2f, 1 ); + fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 5, MAX16B, 25, 6554 /* 0.2f in Q15 */, 1 ); + // GainFrame *= fact_atten; + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); + } + /* Frame gain attenuation in case of big error in envelope modelling */ + // else if ( Env_error > 100.0f || hBWE_TD->prev_Env_error > 100.0f ) + ELSE IF( GT_16( Env_error_fx, 100 ) || GT_16( hBWE_TD->prev_Env_error_fx, 100 ) ) + { + // if ( Env_error > 100.0f ) + IF( GT_16( Env_error_fx, 100 ) ) { - IF( LT_16( lsf_diff_fx[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) - { - tmp = mult( 26214, lsf_diff_fx[i] ); - tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - tmp = s_max( tmp, 16384 ); - w_fx[i] = s_min( tmp, 32767 ); - move16(); - } - ELSE - { - tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - tmp = div_s( tmp, lsf_diff_fx[i] ); - tmp = s_max( tmp, 16384 ); - w_fx[i] = s_min( tmp, 32767 ); - move16(); - } - } - w_fx[0] = w_fx[1]; - move16(); - w_fx[LPC_SHB_ORDER - 1] = w_fx[LPC_SHB_ORDER - 2]; - move16(); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w_fx[i] ) ); - tmp2 = mult( lsp_shb_2_fx[i], w_fx[i] ); - lsp_temp_fx[i] = add( tmp1, tmp2 ); - move16(); + // fact_atten = lin_interp( Env_error, 100.0f, 1.0f, 300.0f, 0.1f, 1 ); + fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 100, MAX16B, 300, 3277 /* 0.1f in Q15 */, 1 ); } - } - ELSE - { - Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); - } - } - - Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = tilt_para_fx; - move16(); - - shb_ener_sf_Q31 = 0; - move16(); - test(); - IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef_fx = interpol_frac_shb; /* Q15 */ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + ELSE { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1)); */ - L_tmp = L_mult( lsp_shb_1_fx[i], ( *ptr_lsp_interp_coef_fx ) ); - lsp_temp_fx[i] = mac_r( L_tmp, lsp_shb_2_fx[i], ( *( ptr_lsp_interp_coef_fx + 1 ) ) ); - move16(); + // fact_atten = lin_interp( hBWE_TD->prev_Env_error, 100.0f, 1.0f, 300.0f, 0.5f, 1 ); + fact_atten_fx = lin_interp_ivas_fx( hBWE_TD->prev_Env_error_fx, 100, MAX16B, 300, ONE_IN_Q14 /* 0.5f in Q15 */, 1 ); } - ptr_lsp_interp_coef_fx += 2; - - tmp = i_mult2( j, ( LPC_SHB_ORDER + 1 ) ); - /* convert LSPs to LPC coefficients for SHB synthesis*/ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); - } - - /* -------- Calculate the SHB Energy -------- */ - /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ - FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) - { - /* shbEner = shbEner + in[i] * in[i] */ - shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); - /* o: shb_ener_sf_Q31 in (2*Q_shb) */ - } - 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 ); - Quant_shb_ener_sf_ivas_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); - - /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ - set16_fx( shb_res_fx, 0, L_FRAME16k ); - Residu3_10_fx( lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); - /* i: shb_frame_fx in Q_shb */ - /* o: shb_res_fx in Q_shb */ - - set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i_mult( i, 64 ), 64 ); - move32(); - } - /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ - - maximum_32_fx( shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp ); - - /* root_a_over_b_fx(shb_res_gshape_fx_32[i], (2*Q_shb+1), L_tmp, (2*Q_shb+1), &exp);*/ - /* First, find 1/L_tmp, L_tmp in QA = (2*Q_shb+1) */ - - /* case when den = 0 */ - recip = 0; /*instead of 32767 to be compatible with previous root_a_over_b_fx() output */ - move16(); - Q_recip = 0; - move16(); - - IF( L_tmp ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - recip = div_s( 16384, tmp ); - // Q_recip = sub( 31, sub( exp, 14 ) ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ - Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ - } - - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - L_tmp1 = Mult_32_16( shb_res_gshape_fx_32[i], recip ); /*Q = Q_recip+1-16*/ - L_tmp = root_a_fx( L_tmp1, sub( Q_recip, 15 ), &exp ); - shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /* Q14 */ - move16(); + // GainFrame *= fact_atten; + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); } - - Quant_shb_res_gshape_ivas_fx( st_fx, shb_res_gshape_fx ); } - ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + ELSE { - FOR( j = 0; j < 4; j++ ) + test(); + IF( EQ_16( frGainSmoothEn, 1 ) && LT_32( hBWE_TD->prev_gainFr_SHB_fx, GainFrame_fx ) ) { - tmp = i_mult2( j, ( LPC_SHB_ORDER + 1 ) ); - /* convert LSPs to LPC coefficients for SHB synthesis*/ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); + GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ } - - /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ - set16_fx( shb_res_fx, 0, L_FRAME16k ); - Residu3_10_fx( lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); } - Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ - - /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - - /* calculate SHB auto-correlation function and convert to SHB voicing factor */ - // acorr_v2a = 0.0f; - L_tmp = 0; - move32(); - acorr_v2a_fx = 0; - move16(); - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + test(); + IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) { - /* calculate the TD envelope of the SHB residual signal */ - Scale_sig( hBWE_TD->mem_shb_res_fx, MAX_LEN_MA_FILTER, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ - find_td_envelope_fx( shb_res_fx, L_FRAME16k, 20, hBWE_TD->mem_shb_res_fx, EnvSHBres_fx ); /* Q_shb */ - - /* downsample the TD envelope by 4 */ - FOR( k = 0; k < L_FRAME4k; k++ ) - { - EnvSHBres_4k_fx[k] = EnvSHBres_fx[4 * k]; /* Q_shb */ - move16(); - } - - /* calculate long-term mean envelope over four consecutive segments using linear interpolation */ - seg_len = L_FRAME4k / 4; - move16(); - den_seg_len = 1638; /* Q15 */ - move16(); - seg_len_2 = L_FRAME4k / 8; - move16(); - den_seg_len_2 = 3641; /* Q15 */ - move16(); - FOR( k = 0; k < 4; k++ ) - { - // seg_mean[k] = max(1.0f, mean(&EnvSHBres_4k[k * seg_len], seg_len)); - seg_mean[k] = s_max( 1, mean_no_sat_fx( &EnvSHBres_4k_fx[k * seg_len], seg_len ) ); /* Q_shb */ - move16(); - // den_seg_mean[k] = 1.0f / seg_mean[k]; - tmp = BASOP_Util_Divide1616_Scale( MAX16B, seg_mean[k], &tmp_e ); - tmp_e = sub( tmp_e, sub( 15, Q_shb ) ); - den_seg_mean[k] = shl_sat( tmp, tmp_e ); /* Q15 */ - move16(); - } - - /* first half of the first segment */ - IF( hBWE_TD->old_mean_EnvSHBres_fx == 0 ) - { - set16_fx( env_mean_normf_fx, den_seg_mean[0], seg_len_2 ); - } - ELSE - { - env_mean_normf_fx[0] = hBWE_TD->old_mean_EnvSHBres_fx; /* Q15 */ - move16(); - // step = (den_seg_mean[0] - hBWE_TD->old_mean_EnvSHBres) * den_seg_len_2; - step = mult( sub( den_seg_mean[0], hBWE_TD->old_mean_EnvSHBres_fx ), den_seg_len_2 ); /* Q15 */ - FOR( i = 1; i < seg_len_2; i++ ) - { - env_mean_normf_fx[i] = add_sat( env_mean_normf_fx[i - 1], step ); /* Q15 */ - move16(); - } - } - - /* segments 1-4 */ - p_env = &env_mean_normf_fx[seg_len_2]; - FOR( k = 1; k < 4; k++ ) - { - // step = ( den_seg_mean[k] - den_seg_mean[k - 1] ) * den_seg_len; - step = mult( sub( den_seg_mean[k], den_seg_mean[k - 1] ), den_seg_len ); - FOR( i = 0; i < seg_len; i++ ) - { - *p_env = add_sat( *( p_env - 1 ), step ); - move16(); - p_env++; - } - } - - /* last half of the last segment */ - // set_f( p_env, den_seg_mean[3], seg_len_2 ); - set16_fx( p_env, den_seg_mean[3], seg_len_2 ); - hBWE_TD->old_mean_EnvSHBres_fx = den_seg_mean[3]; - move16(); - - /* normalize residual SHB envelope with its long-term mean envelope */ - FOR( k = 0; k < L_FRAME4k; k++ ) - { - tmp_buf[k] = L_mult( EnvSHBres_4k_fx[k], env_mean_normf_fx[k] ); // Q_shb + Q15 + Q1 => Q_shb + Q16 - move32(); - } - Q_EnvSHBres_4k_norm = sub( getScaleFactor32( tmp_buf, L_FRAME4k ), 1 /* Guard bit */ ); - FOR( k = 0; k < L_FRAME4k; k++ ) - { - EnvSHBres_4k_norm_fx[k] = extract_h( L_shl( tmp_buf[k], Q_EnvSHBres_4k_norm ) ); // Q_shb + Q16 + Q_EnvSHBres_4k_norm - Q16 => Q_EnvSHBres_4k_norm + Q_shb - move16(); - } - - /* calculate tilt of the long-term mean envelope */ - lls_interp_n_fx( seg_mean, 4, &shb_env_tilt_fx, &temp, 0 ); - - /* copy previous residual envelope to the buffer */ - Copy_Scale_sig( hBWE_TD->old_EnvSHBres_fx, buf_EnvSHBres_fx, L_FRAME4k, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ - - /* subtract mean value from the normalized SHB residual envelope */ - p_buf = &buf_EnvSHBres_fx[L_FRAME4k]; - temp = mean_no_sat_fx( EnvSHBres_4k_norm_fx, L_FRAME4k ); // Q_EnvSHBres_4k_norm + Q_shb - FOR( k = 0; k < L_FRAME4k; k++ ) - { - *p_buf++ = shr( sub( EnvSHBres_4k_norm_fx[k], temp ), Q_EnvSHBres_4k_norm ); // Q_shb - move16(); - } - Q_EnvSHBres_4k_norm = add( Q_EnvSHBres_4k_norm, Q_shb ); - - /* update memory */ - Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); // Q_shb - - /* calculate energy normalization factor for the auto-correlation function */ - // pow0 = sum2_f( &buf_EnvSHBres[L_FRAME4k], L_FRAME4k ) + 1.0f; - pow_e = sub( 15, Q_shb ); - pow0_fx = sum2_16_exp_fx( &buf_EnvSHBres_fx[L_FRAME4k], L_FRAME4k, &pow_e, 0 /* Give guard bits */ ) + 1; - // if (hBWE_TD->prev_enr_EnvSHBres == 1.0f) - IF( BASOP_Util_Cmp_Mant32Exp( hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e, 1, 31 ) == 0 ) - { - // scale = 1.0f / pow0; - scale_fx = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, pow0_fx, &tmp_e ); - scale_e = sub( tmp_e, pow_e ); - } - ELSE - { - // scale = 1.0f / max( pow0, hBWE_TD->prev_enr_EnvSHBres ); - L_tmp1 = pow0_fx; - move32(); - IF( BASOP_Util_Cmp_Mant32Exp( L_tmp1, pow_e, hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e ) < 0 ) - { - L_tmp1 = hBWE_TD->prev_enr_EnvSHBres_fx; - move32(); - pow_e = hBWE_TD->prev_enr_EnvSHBres_e; - move16(); - } - scale_fx = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_tmp1, &tmp_e ); // Qs to be handled - scale_e = sub( tmp_e, pow_e ); - } - hBWE_TD->prev_enr_EnvSHBres_fx = pow0_fx; - move32(); - hBWE_TD->prev_enr_EnvSHBres_e = pow_e; - move16(); - - /* calculate normalized auto-correlation function on the residual normalized SHB envelope */ - p_acorr = acorr_EnvSHBres; - p_buf = &buf_EnvSHBres_fx[L_FRAME4k - ENVSHBRES_ACORR_MIN]; - - FOR( k = 0; k < ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN; k++ ) - { - //*p_acorr++ = scale * dotp(&buf_EnvSHBres[L_FRAME4k], p_buf--, L_FRAME4k); - Word64 W_tmp = 0; - move64(); - - // tmp = *p_buf; - FOR( i = 0; i < L_FRAME4k; ++i ) - { - L_tmp = L_mult( buf_EnvSHBres_fx[L_FRAME4k + i], p_buf[i] ); // 2 * Q_shb + 1 - W_tmp = W_add( W_tmp, W_deposit32_l( L_tmp ) ); - } - p_buf--; - tmp_e = W_norm( W_tmp ); - L_tmp1 = W_extract_h( W_shl( W_tmp, tmp_e ) ); // 2 * Q_shb + tmp_e - 31 - L_tmp = Mpy_32_16_1( L_tmp1, scale_fx ); /* 2 * Q_shb + tmp_e - 31 - scale_e */ - //*p_acorr++ = extract_h( L_shl( L_tmp, add( 16, Q_shb ) - ( 2 * Q_shb + tmp_e - 31 - scale_e ) ) ); - *p_acorr++ = extract_h( L_shl( L_tmp, sub( add( 16, Q_shb ), sub( sub( add( shl( Q_shb, 1 ), tmp_e ), 31 ), scale_e ) ) ) ); - move16(); - } - - /* calculate variance of the SHB autocorrelation function */ - // acorr_v2a = sum2_f( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN ) / ( ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN ); - tmp_e = sub( 15, Q_shb ); - L_tmp = Mpy_32_32( sum2_16_exp_fx( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN, &tmp_e, 0 ), 53687091 /* 1 / ( ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN ) in Q31 */ ); - - /* multiply with the maximum of the SHB autocorrelation function */ - maximum_fx( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN, &temp ); - // acorr_v2a *= temp; - L_tmp = Mpy_32_16_1( L_tmp, temp ); /* 31 - tmp_e + Q_shb - 15 */ - - // alpha = 25.0f; - alpha_fx = -1677721600; // Q26 - move32(); - - // acorr_v2a = 2.0f / ( 1.0f + (float) expf( -alpha * acorr_v2a ) ) - 1.0f; - Word32 exp_tmp = 1459366444; - Word16 exp_e = 2; - Word16 res_e = 0; - move32(); - move16(); - move16(); - - L_tmp = Mpy_32_32( alpha_fx, L_tmp ); // 31 - tmp_e + Q_shb - 15 - 5 - - tmp_e = sub( 31, sub( sub( add( sub( 31, tmp_e ), Q_shb ), 15 ), 5 ) ); - - // L_tmp = BASOP_Util_fPow(exp_tmp, exp_e, 2, 31, &res_e); - - L_tmp = BASOP_Util_fPow( exp_tmp, exp_e, L_tmp, tmp_e, &res_e ); - L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q31, 0, L_tmp, res_e, &tmp_e ); - acorr_v2a_fx = BASOP_Util_Divide3232_Scale( 2, L_tmp, &res_e ); - - res_e = sub( add( res_e, 31 ), tmp_e ); - - res_e = BASOP_Util_Add_MantExp( acorr_v2a_fx, res_e, -1, 15, &acorr_v2a_fx ); - - /* limit in the range 0.0 - 1.0 */ - // acorr_v2a = min( 1.0f, max( 0.0f, acorr_v2a ) ); - acorr_v2a_fx = shl_sat( acorr_v2a_fx, res_e ); - - if ( acorr_v2a_fx < 0 ) - { - acorr_v2a_fx = 0; - move16(); - } - - hBWE_TD->prev_shb_env_tilt_fx = shb_env_tilt_fx; - move16(); - hBWE_TD->prev_Q_shb = Q_shb; - move16(); - } - - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ - vf_ind_fx = 20; - move16(); - - /* Save the SWB LSP values from current frame for interpolation */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = L_deposit_l( 0 ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if ( Lmax == 0 ) - { - Q_bwe_exc = 31; - move16(); - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); - - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); - - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); - if ( GT_16( Q_bwe_exc, tmp2 ) ) - { - Q_bwe_exc = tmp2; - move16(); - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_enc( st_fx, sc ); - } - - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) - { - bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); - move16(); - } - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - - /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; - move16(); - - GenShapedSHBExcitation_ivas_enc_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, st_fx->coder_type, 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, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, - nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, - &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); - - *Q_white_exc = Q_bwe_exc_fb; - move16(); - IF( EQ_16( st_fx->extl, FB_TBE ) ) - { - hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - } - - /* fill-in missing SHB excitation */ - test(); - test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) - { - Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - } - - test(); - IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) - { - Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k ); - hStereoICBWE->shbSynthRef_e = sub( 15, Q_bwe_exc ); - move16(); - } - - test(); - test(); - IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - hBWE_TD->idx_mixFac = vf_ind_fx; - move16(); - } - ELSE - { - push_indice( hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF ); - } - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); - move16(); - } - - test(); - IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - PostShortTerm_ivas_enc_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ - } - Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - Word16 max_val; - maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); - IF( max_val == 0 ) - { - Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ - move32(); - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ - move32(); - } - exp = 0; - move16(); - } - ELSE - { - Word64 prev_pow_64fx, curr_pow_64fx; - Word16 w_shift; - tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); - prev_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow_64fx = W_mac0_16_16( prev_pow_64fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ - } - - w_shift = s_min( W_norm( prev_pow_64fx ), W_norm( curr_pow_64fx ) ); - prev_pow_fx = W_extract_h( W_shl( prev_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 - curr_pow_fx = W_extract_h( W_shl( curr_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 - w_shift = sub( add( shl( Q_bwe_exc, 1 ), w_shift ), 32 ); - - Lscale = root_a_over_b_fx( curr_pow_fx, - w_shift, - prev_pow_fx, - w_shift, - &exp ); - } - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - IF( exp < 0 ) - { - Lscale = L_shl( Lscale, exp ); - exp = 0; - move16(); - } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ - tmp = sub( 32767 /*1.0f Q15*/, tmp ); - L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - ELSE - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ - tmp = sub( 32767 /*1.0f Q15*/, tmp ); - L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - } - ELSE - { - /* reset the PF memories if the PF is not running */ - set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; - move16(); - set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - /* Estimate the gain-shape parameter */ - n_subfr_saturation = 0; - move16(); - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); - - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - /* Gain shape attenuation in case of big error in envelope modelling */ - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - IF( GT_16( Env_error_part_fx[i], 100 ) ) - { - /* set gain shape to the average of the remaining gains */ - // GainShape[i] = ( sum_f( GainShape, NUM_SHB_SUBGAINS ) - GainShape[i] ) / ( NUM_SHB_SUBGAINS - 1 ); - L_tmp = L_sub( sum16_32_fx( GainShape_fx, NUM_SHB_SUBGAINS ), GainShape_fx[i] ); - tmp = BASOP_Util_Divide3232_Scale( L_tmp, NUM_SHB_SUBGAINS - 1, &exp ); - GainShape_fx[i] = shl( tmp, sub( exp, 15 ) ); /* Q15 */ - move16(); - } - } - } - - test(); - IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - /* Gain shape BWS/high band low energy fix */ - IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ - { - /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ - /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ - GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); - move16(); - } - } - } - - /* high-band gain control in case of BWS */ - test(); - IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - IF( st_fx->bwidth_sw_cnt > 0 ) - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - // GainShape[i] *= ( (float) ( st->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD ); - tmp = i_mult( st_fx->bwidth_sw_cnt, ONE_BY_BWS_TRAN_PERIOD_Q15 ); - GainShape_fx[i] = mult( GainShape_fx[i], tmp ); - move16(); - } - } - } - - /* Gain frame adjustment factor */ - /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ - IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) - { - exp = 13 /* norm_s(3) */; - tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; - } - ELSE - { - exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); - } - - L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ - exp1 = sub( exp, exp1 ); /*move16(); */ - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - - L_feedback = L_mult( temp_swb_fac, temp_swb_fac ); - - - FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) - { - test(); - IF( GainShape_fx[i - 1] == 0 ) - { - exp = 13 /* norm_s(3) */; - tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; - } - ELSE - { - exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); - } - L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - - L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); - } - - /* feedback = 0.4f / (1 + 0.5f * feedback) */ - L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl( 1, 21 ) ); /* Q21 */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /*Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ - feedback = round_fx( L_tmp ); /*Q15 */ - } - ELSE - { - feedback = 8738; - move16(); /*Q15 */ - } - - /* calculate tilt in all sub-frame gains */ - Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); - lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); - - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - // if (acorr_v2a < 0.4f && vf_ind >= 5 && fabs(GainShape_tilt) < 0.2f && shb_env_tilt < 500.0f && hBWE_TD->prev_shb_env_tilt < 500.0f) - test(); - test(); - test(); - test(); - IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_Q_shb ) ) ) - { - /* stronger smoothing in case of unvoiced SHB residual signal with gaussian excitation */ - // feedback = lin_interp(acorr_v2a, 0.4f, 0.0f, 0.0f, 0.95f, 0); - feedback = lin_interp_ivas_fx( acorr_v2a_fx, 13107 /* 0.4f in Q15 */, 0, 0, 31130 /* 0.95f in Q15 */, 0 ); - // feedback = min( max( feedback, 0.0f ), 1.0f ); - feedback = s_min( s_max( feedback, 0 ), MAX16B ); - - 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] ) ) ); - move16(); - } - } - } - ELSE - { - /* voicing in Q15 */ - L_tmp = L_mult( voicing[0], 8192 ); - L_tmp = L_mac( L_tmp, voicing[1], 8192 ); - L_tmp = L_mac( L_tmp, voicing[2], 8192 ); - tmp = sum1 = round_fx( L_tmp ); /* sum1 used again below - Q13 */ - tmp = add( tmp, 1 ); /* To ensure change is BE */ - - /* voice_factors_fx in Q15 */ - L_tmp = L_mult( voice_factors_fx[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); - tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ - - - test(); - test(); - IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 /* 2.4f in Q13 */ ) && GT_16( tmp1, 6554 /* 0.8f in Q13 */ ) ) ) - - { - temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; - move16(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ - GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); - move16(); - temp_swb_fac = GainShape_fx[i]; - move16(); - } - } - } - - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - /* Re-normalize gain shape before quantization */ - // sum_gain = sum2_f(GainShape, NUM_SHB_SUBGAINS); - tmp = 0; - move16(); - sum_gain_fx = sum2_16_exp_fx( GainShape_fx, NUM_SHB_SUBGAINS, &tmp, 2 ); - IF( sum_gain_fx == 0 ) - { - normFact_fx = 0; - move16(); - } - ELSE - { - // normFact = (float) sqrt( 1.0f / sum_gain ); - normFact_fx = ISqrt32( sum_gain_fx, &tmp ); - } - - // v_multc( GainShape, normFact, GainShape, NUM_SHB_SUBGAINS ); - FOR( i = 0; i < NUM_SHB_SUBGAINS; ++i ) - { - GainShape_fx[i] = extract_h( L_shl( Mpy_32_16_1( normFact_fx, GainShape_fx[i] ), tmp ) ); /* Q15 */ - move16(); - } - } - - - hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; - move16(); - - /* Compute the power of gains away from the peak gain prior to quantization */ - IF( st_fx->element_mode > EVS_MONO ) - { - p2m_in_fx = pow_off_pk_corrected_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); - } - ELSE - { - p2m_in_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); - } - - /* Quantization of the gain shape parameter */ - QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); - /* o: GainShape_fx in Q15 */ - - /* Compute the power of gains away from the peak gain after quantization */ - IF( st_fx->element_mode > EVS_MONO ) - { - p2m_out_fx = pow_off_pk_corrected_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); - } - ELSE - { - p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); - } - - /* Gain shape smoothing after quantization */ - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - GainShape_Interp_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS]; - move16(); - } - - lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); - - // if ( vf_ind >= 6 && fabs( GainShape_tilt ) < 0.12f ) - test(); - IF( GE_16( vf_ind_fx, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 /* 0.12f in Q15 */ ) ) - { - // feedback = 0.3f; - feedback = 9830; /* 0.3f in Q15 */ - move16(); - 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 - move16(); - } - - FOR( i = NUM_SHB_SUBFR - 1; i > 0; i-- ) - { - GainShape_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; - move16(); - } - } - } - - /* Estimate the gain parameter */ - 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 ); - - IF( EQ_16( st_fx->tec_tfa, 1 ) ) - { - tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); - } - - /* 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. */ - IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) ) - { - L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); - GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ - } - - // if ( st_fx->element_mode > EVS_MONO && st_fx->L_frame != st_fx->last_L_frame && hBWE_TD->prev_gainFr_SHB != 0 && ( st_fx->last_extl == SWB_TBE || st_fx->last_extl == FB_TBE ) && st_fx->coder_type == TRANSITION && st_fx->coder_type_raw != VOICED && st_fx->clas == VOICED_CLAS && st_fx->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st_fx->L_frame >> 6 ) - 1] ) ) - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->L_frame, st_fx->last_L_frame ) && hBWE_TD->prev_gainFr_SHB_fx != 0 && ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->coder_type, TRANSITION ) && NE_16( st_fx->coder_type_raw, VOICED ) && EQ_16( st_fx->clas, VOICED_CLAS ) && EQ_16( st_fx->last_clas, VOICED_CLAS ) && LT_16( mult( 24576 /* 3.0f in Q13 */, voice_factors_fx[0] ), shr( voice_factors_fx[( st_fx->L_frame >> 6 ) - 1], 2 ) ) ) - { - // float fac = GainFrame / hBWE_TD->prev_gainFr_SHB; - Word16 fac = BASOP_Util_Divide3232_Scale( GainFrame_fx, hBWE_TD->prev_gainFr_SHB_fx, &tmp_e ); - - // if ( fac > 4.0f ) - IF( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( fac ), tmp_e, 1073741824, 3 ) > 0 ) - { - // GainFrame = 4.0f * GainFrame / fac; - GainFrame_fx = BASOP_Util_Divide3216_Scale( GainFrame_fx, fac, &tmp1_e ); - GainFrame_fx = L_shl( GainFrame_fx, add( tmp1_e, 2 ) ); /* Q18 */ - } - } - - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - // if ( acorr_v2a > 0.1f && Env_error > 5.0f ) - test(); - test(); - IF( GT_16( acorr_v2a_fx, 3277 /* 0.1f in Q15 */ ) && GT_16( Env_error_fx, 5 ) ) - { - /* attenuate frame gain in case of voiced SHB residual signal with gaussian excitation */ - // fact_atten = lin_interp( Env_error, 5.0f, 1.0f, 25.0f, 0.2f, 1 ); - fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 5, MAX16B, 25, 6554 /* 0.2f in Q15 */, 1 ); - // GainFrame *= fact_atten; - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); - } - /* Frame gain attenuation in case of big error in envelope modelling */ - // else if ( Env_error > 100.0f || hBWE_TD->prev_Env_error > 100.0f ) - ELSE IF( GT_16( Env_error_fx, 100 ) || GT_16( hBWE_TD->prev_Env_error_fx, 100 ) ) - { - // if ( Env_error > 100.0f ) - IF( GT_16( Env_error_fx, 100 ) ) - { - // fact_atten = lin_interp( Env_error, 100.0f, 1.0f, 300.0f, 0.1f, 1 ); - fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 100, MAX16B, 300, 3277 /* 0.1f in Q15 */, 1 ); - } - ELSE - { - // fact_atten = lin_interp( hBWE_TD->prev_Env_error, 100.0f, 1.0f, 300.0f, 0.5f, 1 ); - fact_atten_fx = lin_interp_ivas_fx( hBWE_TD->prev_Env_error_fx, 100, MAX16B, 300, ONE_IN_Q14 /* 0.5f in Q15 */, 1 ); - } - // GainFrame *= fact_atten; - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); - } - } - ELSE - { - test(); - IF( EQ_16( frGainSmoothEn, 1 ) && LT_32( hBWE_TD->prev_gainFr_SHB_fx, GainFrame_fx ) ) - { - GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ - } - } - - test(); - test(); - IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) - { - exp1 = norm_l( GainFrame_fx ); - frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); - exp = sub( 30, add( exp1, 21 ) ); - L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - GainFrame_fx = Pow2( 30, frac ); - exp = sub( exp, 30 ); - GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ - } - ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) - { - /*GainFrame *= (0.8f + 0.5f*feedback); */ - tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); - GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ - } - - hBWE_TD->prev_frGainAtten = frGainAttenuate; - move16(); - - hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; - move16(); /* Q18 */ - - // if ( GainFrame > 153.0f && st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) - test(); - test(); - if ( GT_32( GainFrame_fx, 40108032 /* 153.0f in Q18 */ ) && GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) - { - hStereoICBWE->MSFlag = 1; - move16(); - } - - /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ - tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ - - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - // sd_uq_q = 1 - 0.7f * ( sd_uq_q * sd_uq_q ); - tmp1 = mult_r( 22938 /*0.7f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ - } - ELSE - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - tmp1 = mult_r( 6554 /*0.2f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ - } - ELSE - { - tmp1 = mult_r( 3277 /*0.1f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ - } - } - /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ - L_tmp = L_min( L_tmp, 8192l /*1.0f Q13*/ ); - L_tmp = L_max( L_tmp, 4096l /*0.5f Q13*/ ); /* Q13 */ - /* keep the L_tmp; dont overwrite */ - - test(); - IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ - /* pitch_buf: Q6 */ - pitBufAvg_fx = mult_r( pitch_buf[0], 1311 ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[1], 1311 ) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[2], 1311 ) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[3], 1311 ) ); /* Q10 */ - - /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ - tmp2 = 5462 /*0.1667f Q15*/; - move16(); - if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) - { - tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ - move16(); - } - voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - - // if ( voicingBufAvg <= 0.0f && sd_uq_q * pitBufAvg != 0 ) - test(); - IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) - { - // voicingBufAvg = sd_uq_q * pitBufAvg / 1.001f; - tmp = BASOP_Util_Divide1616_Scale( pitBufAvg_fx, 16400, &tmp_e ); - tmp_e = sub( add( tmp_e, 5 ), 1 ); - L_tmp1 = Mpy_32_16_1( L_tmp, tmp ); - voicingBufAvg_fx = extract_h( L_tmp1 ); - } - // else if ( voicingBufAvg <= 0.0f ) - ELSE IF( voicingBufAvg_fx <= 0 ) - { - // voicingBufAvg = 1.0f; - voicingBufAvg_fx = MAX16B; - move16(); - } - } - - /* high-band gain control in case of BWS */ - test(); - IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - IF( st_fx->bwidth_sw_cnt > 0 ) - { - // GainFrame *= ( (float) ( st_fx->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD ); - tmp = i_mult( st_fx->bwidth_sw_cnt, ONE_BY_BWS_TRAN_PERIOD_Q15 ); - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, tmp ); - } - } - - /* Controlled gain evolution in SWB for stronger voiced segments */ - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - // GainFrame *= sd_uq_q; - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, extract_l( L_shl( L_tmp, 2 ) ) ); - } - ELSE - { - /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ - /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ - /* 1/voicingBufAvg_fx */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) - { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ - - /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ - tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ - } - tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); - tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); - GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ - } - - test(); - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) - { - if ( EQ_16( st_fx->rf_mode, 1 ) ) - { - /* Compensate for energy increase mismatch due to memory-less synthesis */ - // GainFrame *= 0.85f; - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 ); - } - } - ELSE - { - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) - { - /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ - } - } - - /* Quantization of the frame gain parameter */ - IF( st_fx->rf_mode ) - { - QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); - } - ELSE - { - 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 ); - } - - IF( hStereoICBWE != NULL ) - { - push_indice( hBstr, IND_STEREO_ICBWE_MSFLAG, hStereoICBWE->MSFlag, STEREO_ICBWE_MSFLAG_BITS ); - } - - /* Backup for the IC BWE parameters */ - test(); - IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) - { - // Check Qs - Copy_Scale_sig_16_32_DEPREC( lpc_shb_fx, hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 0 ); - hStereoICBWE->lpSHBRef_e = 31 - Q12; - move16(); - } - - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation */ - IF( EQ_32( st_fx->extl, FB_TBE ) ) - { - tmp = norm_l( GainFrame_fx ); - if ( GainFrame_fx == 0 ) - { - tmp = 31; - move16(); - } - L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ - - tmp1 = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ - /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ - move16(); - /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ - tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); - /*White_exc16k_fx[i] =32767;*/ - /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ - } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ - move16(); - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) - { - tmp = 15; - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); - move16(); - } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); - move16(); - } - - hBWE_TD->prev_Env_error_fx = Env_error_fx; - move16(); - - /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : static void EstimateSHBFrameGain_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Estimate the overall gain factor needed to scale */ -/* synthesized highband to original highband signal level. */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) length : SHB overlap length Q0 */ -/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ -/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ -/* _(Word16*) win_shb : SHB window Q15 */ -/* _(Word16*) subwin_shb_local : SHB subframe window Q15 */ -/* _(Word16) Q_oriSHB : Q format of oriSHB */ -/* _(Word16) Q_synSHB : Q format of synSHB */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word32*)GainFrame :estimat of gain frame Q18 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -static void EstimateSHBFrameGain_fx( - 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 */ - const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ - const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ - Word16 *subgain, /* i : estimate of gain shape Q15 */ - Word32 *GainFrame, /* o : estimat of gain frame Q18 */ - const Word16 *win_shb, /* i : SHB window Q15 */ - 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 */ -) -{ - const Word16 *skip; - Word16 i, j, k, l_shb_lahead, l_frame; - Word16 join_length, num_join, sig; - Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD]; - Word32 oriNrg, synNrg; - Word16 sum_gain; - Word32 frame_gain; - Word32 L_tmp; - Word16 exp_out; - Word16 tmp; - Word16 scaling = 0; - move16(); - - /* initilaization */ - l_frame = L_FRAME16k; - move16(); - l_shb_lahead = L_SHB_LAHEAD; - move16(); - skip = skip_bands_SWB_TBE; - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - skip = skip_bands_WB_TBE; - l_frame = L_FRAME16k / 4; - move16(); - l_shb_lahead = L_SHB_LAHEAD / 4; - move16(); - } - - /* apply gain for each subframe, and store noise output signal using overlap-add*/ - set32_fx( mod_syn, 0, l_frame + l_shb_lahead ); - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - sum_gain = 0; - 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_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) */ - } - } - ELSE - { - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - 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_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++ ) - { - 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 ) */ - j++; - } - } - /* adjust frame energy */ - oriNrg = L_deposit_l( 0 ); - synNrg = L_deposit_l( 0 ); - - FOR( i = 0; i < l_shb_lahead; i++ ) - { - 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 */ - } - - 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 */ - } - - tmp = add( l_frame, l_shb_lahead ); - FOR( ; i < tmp; i++ ) - { - 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 */ - } - IF( EQ_32( oriNrg, MAX_32 ) ) - { - scaling = negate( add( shr( n_subfr_saturation, 1 ), 1 ) ); - oriNrg = 0; - move32(); - FOR( i = 0; i < l_shb_lahead; i++ ) - { - sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - FOR( ; i < l_frame; i++ ) - { - sig = shl_sat( oriSHB[i], scaling ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - FOR( ; i < tmp; i++ ) - { - sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - } - L_tmp = root_a_over_b_fx( oriNrg, 2 * Q_oriSHB, synNrg, 2 * Q_synSHB, &exp_out ); - exp_out = sub( exp_out, scaling ); - frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ - *GainFrame = frame_gain; - move32(); - - return; -} - -static void EstimateSHBFrameGain_ivas_fx( - 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 */ - const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ - const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ - Word16 *subgain, /* i : estimate of gain shape Q15 */ - Word32 *GainFrame, /* o : estimat of gain frame Q18 */ - const Word16 *win_shb, /* i : SHB window Q15 */ - 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 */ -) -{ - const Word16 *skip; - Word16 i, j, k, l_shb_lahead, l_frame; - Word16 join_length, num_join, sig; - Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD]; - Word32 oriNrg, synNrg; - Word16 sum_gain; - Word32 frame_gain; - Word32 L_tmp; - Word16 exp_out; - Word16 tmp; - Word16 scaling = 0; - move16(); - - /* initilaization */ - l_frame = L_FRAME16k; - move16(); - l_shb_lahead = L_SHB_LAHEAD; - move16(); - skip = skip_bands_SWB_TBE; - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - skip = skip_bands_WB_TBE; - l_frame = L_FRAME16k / 4; - move16(); - l_shb_lahead = L_SHB_LAHEAD / 4; - move16(); - } - - /* apply gain for each subframe, and store noise output signal using overlap-add*/ - set32_fx( mod_syn, 0, l_frame + l_shb_lahead ); - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - sum_gain = 0; - 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++ ) - { - 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 - { - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - 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++ ) - { - 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 ); - - FOR( i = 0; i < l_shb_lahead; i++ ) - { - 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*/ - } - - 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*/ - } - - tmp = add( l_frame, l_shb_lahead ); - FOR( ; i < tmp; i++ ) - { - 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*/ - } - IF( EQ_32( oriNrg, MAX_32 ) ) - { - scaling = negate( add( shr( n_subfr_saturation, 1 ), 1 ) ); - oriNrg = 0; - move32(); - FOR( i = 0; i < l_shb_lahead; i++ ) - { - sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - FOR( ; i < l_frame; i++ ) - { - sig = shl_sat( oriSHB[i], scaling ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - FOR( ; i < tmp; i++ ) - { - sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); - 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 ); - exp_out = sub( exp_out, scaling ); - frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ - *GainFrame = frame_gain; - move32(); - - return; -} - - -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) -{ - Word16 i, j; - Word32 sum, L_tmp; - - sum = L_shr( L_mult0( a[0], a[0] ), 1 ); /* Q29 */ - - j = 0; - move16(); - FOR( i = 1; i < len; i += step ) - { - L_tmp = L_shr( L_mult0( a[i], a[i] ), 1 ); /* Q29 */ - sum = L_add( sum, L_tmp ); /* Q29 */ - if ( GT_16( a[i], a[j] ) ) - { - j = i; - move16(); - } - } - L_tmp = L_shr( L_mult0( a[j], a[j] ), 1 ); /* Q29 */ - sum = L_sub( sum, L_tmp ); /* Q29 */ - - return ( sum ); -} - - -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ) -{ - Word16 i, j; - Word32 sum, L_tmp; - - sum = L_shr( L_mult0( a[0], a[0] ), 1 ); /* Q29 */ - - j = 0; - move16(); - FOR( i = step; i < len; i += step ) - { - L_tmp = L_shr( L_mult0( a[i], a[i] ), 1 ); /* Q29 */ - sum = L_add( sum, L_tmp ); /* Q29 */ - if ( GT_16( a[i], a[j] ) ) - { - j = i; - move16(); - } - } - L_tmp = L_shr( L_mult0( a[j], a[j] ), 1 ); /* Q29 */ - sum = L_sub( sum, L_tmp ); /* Q29 */ - - return ( sum ); -} - - -/*==========================================================================*/ -/* FUNCTION : static void EstimateSHBGainShape_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Estimate temporal gain parameters */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) length : SHB overlap length Q0 */ -/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ -/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ -/* _(Word16*) subwin : SHB subframe window Q15 */ -/* _(Word16) Q_oriSHB : Q format of oriSHB */ -/* _(Word16) Q_synSHB : Q format of synSHB */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)subgain :estimate of gain shape Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ - -static void EstimateSHBGainShape_fx( - 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 target original SHB frame */ - const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ - const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ - Word16 *subgain, /* o : estimate of gain shape Q15 */ - const Word16 *subwin, /* i : SHB subframe window Q15 */ - Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ - const Flag limit_min_gain /* i : gain shape limiting flag */ -) -{ - const Word16 *skip; - Word16 i, j, k; - Word16 sig; - Word32 L_subgain[NUM_SHB_SUBFR]; - Word32 L_sum_gain = 0; - Word32 oriNrg, synNrg; - Word16 num_join, num_gains, join_length; - Word16 norm[NUM_SHB_SUBFR]; - Word16 n_max = -32768; - Word16 n; - Word16 length2 = shl( length, 1 ); - Word16 length_tmp; - Word32 L_tmp, normFact; - Word16 scaling = 0; - move32(); - move16(); - move16(); - - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - num_gains = NUM_SHB_SUBGAINS; - move16(); - skip = skip_bands_SWB_TBE; - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - num_gains = NUM_SHB_SUBFR / 4; - move16(); - skip = skip_bands_WB_TBE; - } - /* calculate and normalize the subgain */ - oriNrg = 0; - move32(); - synNrg = 0; - move32(); - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 2; i++ ) - { - logic16(); - IF( s_and( i, 0x1 ) == 0 ) - { - oriNrg = 0; - move32(); - synNrg = 0; - move32(); - } - j = skip[i]; - move16(); - IF( i == 0 ) - { - FOR( k = 0; k < length / 2; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[2 * k + 2] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + k], subwin[2 * k + 2] ); /* Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - FOR( k = length / 2; k < length; k++ ) - { - sig = oriSHB[j + k]; - move16(); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = synSHB[j + k]; - move16(); - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - ELSE - { - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - IF( EQ_16( i, NUM_SHB_SUBFR / 2 - 1 ) ) - { - length_tmp = sub( length2, shr( length, 1 ) ); - FOR( ; k < length_tmp; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - ELSE - { - FOR( ; k < length2; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[2 * length - k - 1] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + k], subwin[2 * length - k - 1] ); /* Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - - logic16(); - IF( EQ_16( s_and( i, 0x1 ), 1 ) ) - { - L_subgain[i / 2] = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &n ); - move16(); /* Q(31-n) */ - norm[i / 2] = n; - move16(); - if ( GT_16( norm[i / 2], n_max ) ) - { - n_max = norm[i / 2]; - move16(); - } - } - } - } - ELSE - { - join_length = i_mult2( num_join, length ); - FOR( i = 0; i < num_gains; i++ ) - { - oriNrg = 0; - move32(); - synNrg = 0; - move32(); - - j = i_mult2( join_length, i ); - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ - } - - FOR( k = 0; k < ( join_length - length ); k++ ) - { - sig = mult_r( oriSHB[length + j + k], 32767 ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[length + j + k], 32767 ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ - } - - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ - } - /* Only implemented in SWB because the length of samples in SWB frame is longer, more likely to saturate */ - scaling = 0; - move16(); - IF( EQ_32( oriNrg, MAX_32 ) ) - { - IF( n_subfr_saturation != NULL ) - { - *n_subfr_saturation = add( *n_subfr_saturation, 1 ); - move16(); - } - scaling = -1; - move16(); - oriNrg = 0; - move32(); - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ - } - FOR( k = 0; k < ( join_length - length ); k++ ) - { - sig = shr( oriSHB[length + j + k], 1 ); - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ - } - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( shr( oriSHB[j + join_length + k], 1 ), subwin[length - k - 1] ); /* Q_oriSHB - 1(scaling) */ - oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2 */ - } - } - L_subgain[i] = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &n ); - move32(); /* Q(31-n) */ - n = sub( n, scaling ); - norm[i] = n; - move16(); - if ( GT_16( norm[i], n_max ) ) - { - n_max = norm[i]; - move16(); - } - } + exp1 = norm_l( GainFrame_fx ); + frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); + exp = sub( 30, add( exp1, 21 ) ); + L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); + GainFrame_fx = Pow2( 30, frac ); + exp = sub( exp, 30 ); + GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ + } + ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) + { + /*GainFrame *= (0.8f + 0.5f*feedback); */ + tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); + GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ } - FOR( i = 0; i < num_gains; i++ ) + hBWE_TD->prev_frGainAtten = frGainAttenuate; + move16(); + + hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; + move16(); /* Q18 */ + + // if ( GainFrame > 153.0f && st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) + test(); + test(); + if ( GT_32( GainFrame_fx, 40108032 /* 153.0f in Q18 */ ) && GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) { - subgain[i] = round_fx_sat( L_shl_sat( L_subgain[i], sub( norm[i], n_max + 1 ) ) ); /* Q(14-n_max) */ - L_sum_gain = L_mac0_sat( L_sum_gain, subgain[i], subgain[i] ); /* Q(28-2*n_max) */ + hStereoICBWE->MSFlag = 1; move16(); } - /* normalize the subgain */ - n = norm_l( L_sum_gain ); - L_sum_gain = L_shl( L_sum_gain, n ); - n = sub( 31, add( n, ( sub( 28, shl( n_max, 1 ) ) ) ) ); - normFact = Isqrt_lc( L_sum_gain, &n ); + /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ + tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ - IF( limit_min_gain ) + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - FOR( i = 0; i < num_gains; i++ ) + // sd_uq_q = 1 - 0.7f * ( sd_uq_q * sd_uq_q ); + tmp1 = mult_r( 22938 /*0.7f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ + } + ELSE + { + IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ - subgain[i] = s_max( round_fx_sat( L_shl_sat( L_tmp, add( n, n_max + 1 ) ) ), 3277 /*0.1f Q15*/ ); /* Q15 */ - move16(); + tmp1 = mult_r( 6554 /*0.2f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ + } + ELSE + { + tmp1 = mult_r( 3277 /*0.1f Q15*/, tmp ); /* Q15, Q6 => Q6 */ + L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } } - ELSE + /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ + L_tmp = L_min( L_tmp, 8192l /*1.0f Q13*/ ); + L_tmp = L_max( L_tmp, 4096l /*0.5f Q13*/ ); /* Q13 */ + /* keep the L_tmp; dont overwrite */ + + test(); + IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - FOR( i = 0; i < num_gains; i++ ) + /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ + /* pitch_buf: Q6 */ + pitBufAvg_fx = mult_r( pitch_buf[0], 1311 ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[1], 1311 ) ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[2], 1311 ) ); + pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[3], 1311 ) ); /* Q10 */ + + /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ + tmp2 = 5462 /*0.1667f Q15*/; + move16(); + if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) { - L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ - subgain[i] = round_fx_sat( L_shl_sat( L_tmp, add( n, n_max + 1 ) ) ); /* Q15 */ + tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ move16(); } - } + voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - return; -} + // if ( voicingBufAvg <= 0.0f && sd_uq_q * pitBufAvg != 0 ) + test(); + IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) + { + // voicingBufAvg = sd_uq_q * pitBufAvg / 1.001f; + tmp = BASOP_Util_Divide1616_Scale( pitBufAvg_fx, 16400, &tmp_e ); + tmp_e = sub( add( tmp_e, 5 ), 1 ); + L_tmp1 = Mpy_32_16_1( L_tmp, tmp ); + voicingBufAvg_fx = extract_h( L_tmp1 ); + } + // else if ( voicingBufAvg <= 0.0f ) + ELSE IF( voicingBufAvg_fx <= 0 ) + { + // voicingBufAvg = 1.0f; + voicingBufAvg_fx = MAX16B; + move16(); + } + } + /* high-band gain control in case of BWS */ + test(); + IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + IF( st_fx->bwidth_sw_cnt > 0 ) + { + // GainFrame *= ( (float) ( st_fx->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD ); + tmp = i_mult( st_fx->bwidth_sw_cnt, ONE_BY_BWS_TRAN_PERIOD_Q15 ); + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, tmp ); + } + } -/*==========================================================================*/ -/* FUNCTION :static short closest_centroid_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Determine a set of closest VQ centroids for a given input*/ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16*) data : input data Q15 */ -/* _(Word16*) weights : weights Q0 */ -/* _(Word16*) quantizer : quantizer table Q15 */ -/* _(Word16) centroids : number of centroids Q0 */ -/* _(Word16) length : dimension of quantiser Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ Word16 : index Q0 */ -/*--------------------------------------------------------------------------*/ -static Word16 closest_centroid_fx( - const Word16 *data, /* i : input data Qx*/ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table Qx*/ - const Word16 centroids, /* i : number of centroids */ - const Word16 length ) /* i : dimension of quantiser */ -{ - Word16 i, j, index; - Word16 tmp, tmpL; - Word64 werr_64; - Word32 L_tmp, werr, best_werr; + /* Controlled gain evolution in SWB for stronger voiced segments */ + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + { + // GainFrame *= sd_uq_q; + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, extract_l( L_shl( L_tmp, 2 ) ) ); + } + ELSE + { + /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ + /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ + /* 1/voicingBufAvg_fx */ + tmp = 32767; + move16(); + IF( voicingBufAvg_fx > 0 ) + { + exp = norm_s( voicingBufAvg_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ - index = 0; - move16(); - best_werr = MAX_32; - move32(); + /* sd_uq_q*pitBufAvg */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ + tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ + } + tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); + tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ + } - FOR( i = 0; i < centroids; i++ ) + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - werr_64 = 0; - move64(); - tmpL = i_mult2( i, length ); - FOR( j = 0; j < length; j++ ) + if ( EQ_16( st_fx->rf_mode, 1 ) ) { - tmp = sub( data[j], quantizer[tmpL + j] ); - L_tmp = L_mult( tmp, tmp ); - werr_64 = W_mac_32_16( werr_64, L_tmp, weights[j] ); + /* Compensate for energy increase mismatch due to memory-less synthesis */ + // GainFrame *= 0.85f; + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 ); } - werr = W_sat_m( werr_64 ); - if ( LT_32( werr, best_werr ) ) + } + ELSE + { + test(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) { - index = i; - move16(); + /* Compensate for energy increase mismatch due to memory-less synthesis*/ + GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ } - best_werr = L_min( best_werr, werr ); } - return index; -} - -/*==========================================================================*/ -/* FUNCTION :static short closest_centroid_lc_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*/ - const Word16 centroids ) /* i : number of centroids */ -{ - Word16 i, index, tmp, tmpL; - Word32 werr, best_werr; - index = 0; - move16(); - best_werr = MAX_32; - move32(); + /* Quantization of the frame gain parameter */ + 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 ); - FOR( i = 0; i < centroids; i++ ) + IF( hStereoICBWE != NULL ) { - /* Gain shape dimension 4 */ - tmpL = shl( i, 2 ); - - /* index 0 */ - tmp = sub( data[0], quantizer[tmpL] ); - werr = L_mult( tmp, tmp ); + push_indice( hBstr, IND_STEREO_ICBWE_MSFLAG, hStereoICBWE->MSFlag, STEREO_ICBWE_MSFLAG_BITS ); + } - /* index 1 */ - tmp = sub( data[1], quantizer[tmpL + 1] ); - werr = L_mac( werr, tmp, tmp ); + /* Backup for the IC BWE parameters */ + test(); + IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) + { + // Check Qs + Copy_Scale_sig_16_32_DEPREC( lpc_shb_fx, hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 0 ); + hStereoICBWE->lpSHBRef_e = 31 - Q12; + move16(); + } - /* index 2 */ - tmp = sub( data[2], quantizer[tmpL + 2] ); - werr = L_mac( werr, tmp, tmp ); + /* Adjust the subframe and frame gain of the synthesized SHB signal */ + /* Scale the shaped excitation */ + IF( EQ_32( st_fx->extl, FB_TBE ) ) + { + tmp = norm_l( GainFrame_fx ); + if ( GainFrame_fx == 0 ) + { + tmp = 31; + move16(); + } + L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ - /* index 3 */ - tmp = sub( data[3], quantizer[tmpL + 3] ); - werr = L_mac( werr, tmp, tmp ); + tmp1 = 0; + move16(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ + /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ + /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + /*White_exc16k_fx[i] =32767;*/ + /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ + } + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ + move16(); + tmp = norm_s( tmp1 ); + if ( tmp1 == 0 ) + { + tmp = 15; + move16(); + } - if ( LT_32( werr, best_werr ) ) + FOR( i = 0; i < L_FRAME16k; i++ ) { - index = i; + White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); move16(); } - best_werr = L_min( best_werr, werr ); + *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); + move16(); } - return index; + hBWE_TD->prev_Env_error_fx = Env_error_fx; + move16(); + + /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; + move16(); + + return; } -/*============================================================*/ -/* FUNCTION : static void QuantizeSHBsubgains_fx() */ -/*------------------------------------------------------------*/ -/* PURPOSE : Quantize super highband temporal gains */ -/*------------------------------------------------------------*/ + +/*==========================================================================*/ +/* FUNCTION : static void EstimateSHBFrameGain_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Estimate the overall gain factor needed to scale */ +/* synthesized highband to original highband signal level. */ +/*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _(Word16) extl : extension layer Q0 */ -/*------------------------------------------------------------*/ +/* _(Word16) length : SHB overlap length Q0 */ +/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ +/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ +/* _(Word16*) win_shb : SHB window Q15 */ +/* _(Word16*) subwin_shb_local : SHB subframe window Q15 */ +/* _(Word16) Q_oriSHB : Q format of oriSHB */ +/* _(Word16) Q_synSHB : Q format of synSHB */ +/*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ +/* _(Word32*)GainFrame :estimat of gain frame Q18 */ +/*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16[])subgains :super highband temporal gains Q15 */ -/*------------------------------------------------------------*/ +/* _None */ +/*--------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ -/*------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ -static void QuantizeSHBsubgains_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 subgains[], /* i/o: super highband temporal gains Q15*/ - const Word16 extl /* i : extension layer */ +static void EstimateSHBFrameGain_fx( + const Word16 element_mode, /* i : element mode */ + 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 */ + const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ + const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ + Word16 *subgain, /* i : estimate of gain shape Q15 */ + Word32 *GainFrame, /* o : estimat of gain frame Q18 */ + const Word16 *win_shb, /* i : SHB window Q15 */ + 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 */ ) { - Word16 i, idxSubGain; - Word16 Unit_weights10[NUM_SHB_SUBFR]; - Word16 exp, frac; + const Word16 *skip; + Word16 i, j, k, l_shb_lahead, l_frame; + Word16 join_length, num_join, sig; + Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD]; + Word32 oriNrg, synNrg; + Word16 sum_gain; + Word32 frame_gain; Word32 L_tmp; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + Word16 exp_out; + Word16 tmp; + Word16 scaling = 0; + move16(); - IF( EQ_16( extl, WB_TBE ) ) + /* initilaization */ + l_frame = L_FRAME16k; + move16(); + l_shb_lahead = L_SHB_LAHEAD; + move16(); + skip = skip_bands_SWB_TBE; + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) { - set16_fx( Unit_weights10, 32767, (Word16) NUM_SHB_SUBFR / 4 ); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + skip = skip_bands_WB_TBE; + l_frame = L_FRAME16k / 4; + move16(); + l_shb_lahead = L_SHB_LAHEAD / 4; + move16(); + } + + /* apply gain for each subframe, and store noise output signal using overlap-add*/ + set32_fx( mod_syn, 0, l_frame + l_shb_lahead ); + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) + { + sum_gain = 0; + move16(); + j = skip[0]; + move16(); + + IF( element_mode == EVS_MONO ) { - IF( EQ_16( subgains[i], 0 ) ) + FOR( k = 0; k < length / 2; k++ ) { - subgains[i + NUM_SHB_SUBFR / 4] = -18432; - move16(); /* (-72) in Q8 */ + 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) */ } - ELSE + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /* move16(); */ - /*exp = -1 - exp; */ - exp = sub( -1, exp ); - L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q13 ; 20.0 * log10(2) in Q12*/ - subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ + 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) */ } } - idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, subgains, NUM_SHB_SUBFR / 4 ); + ELSE + { + 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 + { + num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; + move16(); + join_length = i_mult2( num_join, length ); + j = 0; + move16(); - push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); + IF( element_mode == EVS_MONO ) + { + FOR( k = 0; k < length; k++ ) + { + 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( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + 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++ ) + { + 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 ) */ + j++; + } + } + ELSE + { + 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 ); + + FOR( i = 0; i < l_shb_lahead; i++ ) + { + 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*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_synSHB / 2*Q_oriSHB - 2*/ + } + + tmp = add( l_frame, l_shb_lahead ); + FOR( ; i < tmp; i++ ) + { + 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_synSHB / 2*Q_oriSHB - 2*/ + } + IF( EQ_32( oriNrg, MAX_32 ) ) + { + scaling = negate( add( shr( n_subfr_saturation, 1 ), 1 ) ); + oriNrg = 0; + move32(); + FOR( i = 0; i < l_shb_lahead; i++ ) + { + sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ + } + FOR( ; i < l_frame; i++ ) { - L_tmp = L_mult( subgains[i], 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - move16(); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], add( exp, 1 ) ); - move16(); /*Q15 */ + sig = shl_sat( oriSHB[i], scaling ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ } - - FOR( i = NUM_SHB_SUBFR / 2 - 1; i >= 0; i-- ) + FOR( ; i < tmp; i++ ) { - subgains[i] = subgains[i / 2]; - move16(); + sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ } } + + 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 { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - IF( EQ_16( subgains[i], 0 ) ) - { - subgains[i] = -12288; - move16(); /* (-3) in Q12 */ - } - ELSE - { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); - /*exp = -1 - exp; */ - exp = sub( -1, exp ); + 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; + move32(); - L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ - subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ - move16(); - } - } + return; +} - idxSubGain = (Word16) vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = L_mult( subgains[i], 27213 ); /* *3.321928 in Q13 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - move16(); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], add( exp, 1 ) ); - move16(); /*Q15 */ - } +static Word32 pow_off_pk_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) +{ + Word16 i, j; + Word32 sum, L_tmp; - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) + sum = L_shr( L_mult0( a[0], a[0] ), 1 ); /* Q29 */ + + j = 0; + move16(); + FOR( i = 1; i < len; i += step ) + { + L_tmp = L_shr( L_mult0( a[i], a[i] ), 1 ); /* Q29 */ + sum = L_add( sum, L_tmp ); /* Q29 */ + if ( GT_16( a[i], a[j] ) ) { - subgains[i] = subgains[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + j = i; move16(); } + } + L_tmp = L_shr( L_mult0( a[j], a[j] ), 1 ); /* Q29 */ + sum = L_sub( sum, L_tmp ); /* Q29 */ - hBWE_TD->idxSubGains = idxSubGain; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) + return ( sum ); +} + + +static Word32 pow_off_pk_corrected_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) +{ + Word16 i, j; + Word32 sum, L_tmp; + + sum = L_shr( L_mult0( a[0], a[0] ), 1 ); /* Q29 */ + + j = 0; + move16(); + FOR( i = step; i < len; i += step ) + { + L_tmp = L_shr( L_mult0( a[i], a[i] ), 1 ); /* Q29 */ + sum = L_add( sum, L_tmp ); /* Q29 */ + if ( GT_16( a[i], a[j] ) ) { - push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); + j = i; + move16(); } } + L_tmp = L_shr( L_mult0( a[j], a[j] ), 1 ); /* Q29 */ + sum = L_sub( sum, L_tmp ); /* Q29 */ - return; + return ( sum ); } -/*============================================================*/ -/* FUNCTION : static void QuantizeSHBsubgains_ivas_fx() */ -/*------------------------------------------------------------*/ -/* PURPOSE : Quantize super highband temporal gains */ -/*------------------------------------------------------------*/ +/*==========================================================================*/ +/* FUNCTION : static void EstimateSHBGainShape_fx() */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Estimate temporal gain parameters */ +/*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _(Word16) extl : extension layer Q0 */ -/*------------------------------------------------------------*/ +/* _(Word16) length : SHB overlap length Q0 */ +/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ +/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ +/* _(Word16*) subwin : SHB subframe window Q15 */ +/* _(Word16) Q_oriSHB : Q format of oriSHB */ +/* _(Word16) Q_synSHB : Q format of synSHB */ +/*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ +/* _(Word16*)subgain :estimate of gain shape Q15 */ +/*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16[])subgains :super highband temporal gains Q15 */ -/*------------------------------------------------------------*/ +/* _None */ +/*--------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ -/*------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ -static void QuantizeSHBsubgains_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 subgains[], /* i/o: super highband temporal gains Q15 */ - const Word16 extl /* i : extension layer */ +static void EstimateSHBGainShape_fx( + 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 target original SHB frame */ + const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ + const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ + Word16 *subgain, /* o : estimate of gain shape Q15 */ + const Word16 *subwin, /* i : SHB subframe window Q15 */ + Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ + const Flag limit_min_gain /* i : gain shape limiting flag */ ) { - Word16 i, idxSubGain; - Word16 Unit_weights10[NUM_SHB_SUBFR]; - Word16 exp, frac; - Word32 L_tmp; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + const Word16 *skip; + Word16 i, j, k; + Word16 sig; + Word32 L_subgain[NUM_SHB_SUBFR]; + Word32 L_sum_gain = 0; + Word32 oriNrg, synNrg; + Word16 num_join, num_gains, join_length; + Word16 norm[NUM_SHB_SUBFR]; + Word16 n_max = -32768; + Word16 n; + Word16 length2 = shl( length, 1 ); + Word16 length_tmp; + Word32 L_tmp, normFact; + Word16 scaling = 0; + move32(); + move16(); + move16(); - IF( EQ_16( extl, WB_TBE ) ) + num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; + move16(); + num_gains = NUM_SHB_SUBGAINS; + move16(); + skip = skip_bands_SWB_TBE; + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) { - set16_fx( Unit_weights10, 32767, NUM_SHB_SUBFR / 4 ); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + num_gains = NUM_SHB_SUBFR / 4; + move16(); + skip = skip_bands_WB_TBE; + } + /* calculate and normalize the subgain */ + oriNrg = 0; + move32(); + synNrg = 0; + move32(); + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) + { + FOR( i = 0; i < NUM_SHB_SUBFR / 2; i++ ) { - IF( EQ_16( subgains[i], 0 ) ) + logic16(); + IF( s_and( i, 0x1 ) == 0 ) { - subgains[i + NUM_SHB_SUBFR / 4] = -18432; - move16(); /* (-72) in Q8 */ + oriNrg = 0; + move32(); + synNrg = 0; + move32(); + } + j = skip[i]; + move16(); + IF( i == 0 ) + { + FOR( k = 0; k < length / 2; k++ ) + { + sig = mult_r( oriSHB[j + k], subwin[2 * k + 2] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[2 * k + 2] ); /* Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ + } + FOR( k = length / 2; k < length; k++ ) + { + sig = oriSHB[j + k]; + move16(); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = synSHB[j + k]; + move16(); + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ + } } ELSE { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /* move16(); */ - /*exp = -1 - exp; */ - exp = sub( -1, exp ); - L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q13 ; 20.0 * log10(2) in Q12*/ - subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ + FOR( k = 0; k < length; k++ ) + { + sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ + } + } + IF( EQ_16( i, NUM_SHB_SUBFR / 2 - 1 ) ) + { + length_tmp = sub( length2, shr( length, 1 ) ); + FOR( ; k < length_tmp; k++ ) + { + sig = mult_r( oriSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + + sig = mult_r( synSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ + } + } + ELSE + { + FOR( ; k < length2; k++ ) + { + sig = mult_r( oriSHB[j + k], subwin[2 * length - k - 1] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[2 * length - k - 1] ); /* Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_synSHB */ + } + } + + logic16(); + IF( EQ_16( s_and( i, 0x1 ), 1 ) ) + { + L_subgain[i / 2] = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &n ); + move16(); /* Q(31-n) */ + norm[i / 2] = n; move16(); + if ( GT_16( norm[i / 2], n_max ) ) + { + n_max = norm[i / 2]; + move16(); + } } } - idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, subgains, NUM_SHB_SUBFR / 4 ); - - push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); - - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - L_tmp = L_mult( subgains[i], 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - move16(); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], add( exp, 1 ) ); - move16(); /*Q15 */ - } - - FOR( i = NUM_SHB_SUBFR / 2 - 1; i >= 0; i-- ) - { - subgains[i] = subgains[i / 2]; - move16(); - } } ELSE { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + join_length = i_mult2( num_join, length ); + FOR( i = 0; i < num_gains; i++ ) { - IF( EQ_16( subgains[i], 0 ) ) + oriNrg = 0; + move32(); + synNrg = 0; + move32(); + + j = i_mult2( join_length, i ); + FOR( k = 0; k < length; k++ ) { - subgains[i] = -12288; - move16(); /* (-3) in Q12 */ + sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ } - ELSE + + FOR( k = 0; k < ( join_length - length ); k++ ) { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); - /*exp = -1 - exp; */ - exp = sub( -1, exp ); + sig = mult_r( oriSHB[length + j + k], 32767 ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[length + j + k], 32767 ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ + } - L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ - subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ + FOR( k = 0; k < length; k++ ) + { + sig = mult_r( oriSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ + } + /* Only implemented in SWB because the length of samples in SWB frame is longer, more likely to saturate */ + scaling = 0; + move16(); + IF( EQ_32( oriNrg, MAX_32 ) ) + { + IF( n_subfr_saturation != NULL ) + { + *n_subfr_saturation = add( *n_subfr_saturation, 1 ); + move16(); + } + scaling = -1; + move16(); + oriNrg = 0; + move32(); + FOR( k = 0; k < length; k++ ) + { + sig = mult_r( oriSHB[j + k], subwin[k + 1] ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + } + FOR( k = 0; k < ( join_length - length ); k++ ) + { + sig = shr( oriSHB[length + j + k], 1 ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + } + FOR( k = 0; k < length; k++ ) + { + sig = mult_r( shr( oriSHB[j + join_length + k], 1 ), subwin[length - k - 1] ); /* Q_oriSHB - 1(scaling) */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2 */ + } + } + L_subgain[i] = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &n ); + move32(); /* Q(31-n) */ + n = sub( n, scaling ); + norm[i] = n; + move16(); + if ( GT_16( norm[i], n_max ) ) + { + n_max = norm[i]; move16(); } } + } - idxSubGain = vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); + FOR( i = 0; i < num_gains; i++ ) + { + subgain[i] = round_fx_sat( L_shl_sat( L_subgain[i], sub( norm[i], n_max + 1 ) ) ); /* Q(14-n_max) */ + L_sum_gain = L_mac0_sat( L_sum_gain, subgain[i], subgain[i] ); /* Q(28-2*n_max) */ + move16(); + } - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = L_mult( subgains[i], 27213 ); /* *3.321928 in Q13 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - move16(); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], add( exp, 1 ) ); - move16(); /*Q15 */ - } + /* normalize the subgain */ + n = norm_l( L_sum_gain ); + L_sum_gain = L_shl( L_sum_gain, n ); + n = sub( 31, add( n, ( sub( 28, shl( n_max, 1 ) ) ) ) ); + normFact = Isqrt_lc( L_sum_gain, &n ); - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) + IF( limit_min_gain ) + { + FOR( i = 0; i < num_gains; i++ ) { - subgains[i] = subgains[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ + subgain[i] = s_max( round_fx_sat( L_shl_sat( L_tmp, add( n, n_max + 1 ) ) ), 3277 /*0.1f Q15*/ ); /* Q15 */ move16(); } - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + } + ELSE + { + FOR( i = 0; i < num_gains; i++ ) { - hBWE_TD->idxSubGains = idxSubGain; + L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ + subgain[i] = round_fx_sat( L_shl_sat( L_tmp, add( n, n_max + 1 ) ) ); /* Q15 */ move16(); } - ELSE - { - push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); - } - } - - return; -} - - -/*-------------------------------------------------------------------* - * Quant_shb_ener_sf_fx_fx() - * - * Quantize SHB subframe energies - *-------------------------------------------------------------------*/ - -static void Quant_shb_ener_sf_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ - Word16 Q_ener ) -{ - Word16 idxSubEner_fx; - Word16 temp_shb_ener_sf_fx; - Word16 exp /*, exp2*/, frac; - Word32 L_tmp1, L_tmp; - Word32 sum; - Word16 tmp; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ - sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ - move32(); - - 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, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - - 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, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ - - /* 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 Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2( 14, frac ); - // *shb_ener_sf_Q31 = L_shl( L_tmp, exp - 14 + Q_ener ); /* In Q_ener */ - *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ - move32(); - - hBWE_TD->idx_shb_fr_gain = idxSubEner_fx; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF ); } return; } -/*-------------------------------------------------------------------* - * Quant_shb_ener_sf_ivas_fx() - * - * Quantize SHB subframe energies - *-------------------------------------------------------------------*/ +/*==========================================================================*/ +/* FUNCTION :static short closest_centroid_fx () */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Determine a set of closest VQ centroids for a given input*/ +/*--------------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _(Word16*) data : input data Q15 */ +/* _(Word16*) weights : weights Q0 */ +/* _(Word16*) quantizer : quantizer table Q15 */ +/* _(Word16) centroids : number of centroids Q0 */ +/* _(Word16) length : dimension of quantiser Q0 */ +/*--------------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _None */ +/*--------------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*--------------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ Word16 : index Q0 */ +/*--------------------------------------------------------------------------*/ -static void Quant_shb_ener_sf_ivas_fx( - 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 ) +static Word16 closest_centroid_fx( + const Word16 *data, /* i : input data Qx*/ + const Word16 *weights, /* i : weights */ + const Word16 *quantizer, /* i : quantizer table Qx*/ + const Word16 centroids, /* i : number of centroids */ + const Word16 length ) /* i : dimension of quantiser */ { - Word16 idxSubEner_fx; - Word16 temp_shb_ener_sf_fx; - Word16 exp /*, exp2*/, frac; - Word32 L_tmp1, L_tmp; - Word32 sum; - Word16 tmp; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ - sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ - move32(); - - 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 */ - - tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + Word16 i, j, index; + Word16 tmp, tmpL; + Word64 werr_64; + Word32 L_tmp, werr, best_werr; - temp_shb_ener_sf_fx = 0; + index = 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 */ - - /* 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 = Pow2( 14, frac ); - *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ + best_werr = MAX_32; move32(); - hBWE_TD->idx_shb_fr_gain = idxSubEner_fx; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) + FOR( i = 0; i < centroids; i++ ) { - push_indice( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF ); + werr_64 = 0; + move64(); + tmpL = i_mult2( i, length ); + FOR( j = 0; j < length; j++ ) + { + tmp = sub( data[j], quantizer[tmpL + j] ); + L_tmp = L_mult( tmp, tmp ); + werr_64 = W_mac_32_16( werr_64, L_tmp, weights[j] ); + } + werr = W_sat_m( werr_64 ); + if ( LT_32( werr, best_werr ) ) + { + index = i; + move16(); + } + best_werr = L_min( best_werr, werr ); } - - return; + return index; } +/*==========================================================================*/ +/* FUNCTION :static short closest_centroid_lc_fx () */ +/*--------------------------------------------------------------------------*/ +/* PURPOSE : Determine a set of closest VQ centroids for a given input */ +/* Gain shape is 4 dimensional */ +/*--------------------------------------------------------------------------*/ -/*-------------------------------------------------------------------* - * Quant_shb_res_gshape_fx() - * - * Quantize SHB gain shapes in residual domain - *-------------------------------------------------------------------*/ - -static void Quant_shb_res_gshape_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ -) +static Word16 closest_centroid_lc_fx( + const Word16 *data, /* i : input data Qx*/ + const Word16 *quantizer, /* i : quantizer table Qx*/ + const Word16 centroids ) /* i : number of centroids */ { - Word16 i, idxSubGain_fx[NB_SUBFR16k]; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - idxSubGain_fx[i] = usquant_fx( shb_res_gshape_fx[i], - &shb_res_gshape_fx[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/, /*1024 = 0.125 in Q13 */ - shl( 1, NUM_BITS_SHB_RES_GS ) ); - move16(); + Word16 i, index, tmp, tmpL; + Word32 werr, best_werr; - hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( st_fx->hBstr, IND_SHB_RES_GS + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); - } - } + index = 0; + move16(); + best_werr = MAX_32; + move32(); - return; -} + FOR( i = 0; i < centroids; i++ ) + { + /* Gain shape dimension 4 */ + tmpL = shl( i, 2 ); + /* index 0 */ + tmp = sub( data[0], quantizer[tmpL] ); + werr = L_mult( tmp, tmp ); -/*-------------------------------------------------------------------* - * Quant_shb_res_gshape_ivas_fx() - * - * Quantize SHB gain shapes in residual domain - *-------------------------------------------------------------------*/ + /* index 1 */ + tmp = sub( data[1], quantizer[tmpL + 1] ); + werr = L_mac( werr, tmp, tmp ); -static void Quant_shb_res_gshape_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ -) -{ - Word16 i, idxSubGain_fx[NB_SUBFR16k]; - TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + /* index 2 */ + tmp = sub( data[2], quantizer[tmpL + 2] ); + werr = L_mac( werr, tmp, tmp ); - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - idxSubGain_fx[i] = usquant_fx( shb_res_gshape_fx[i], - &shb_res_gshape_fx[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/, /*1024 = 0.125 in Q13 */ - shl( 1, NUM_BITS_SHB_RES_GS ) ); - move16(); + /* index 3 */ + tmp = sub( data[3], quantizer[tmpL + 3] ); + werr = L_mac( werr, tmp, tmp ); - IF( EQ_16( st->codec_mode, MODE2 ) ) + if ( LT_32( werr, best_werr ) ) { - hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; + index = i; move16(); } - ELSE - { - push_indice( st->hBstr, IND_SHB_RES_GS + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); - } + best_werr = L_min( best_werr, werr ); } - return; + return index; } - -/*==========================================================================*/ -/* FUNCTION : static void QuantizeSHBframegain_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : QQuantize super highband frame gain */ -/*--------------------------------------------------------------------------*/ +/*============================================================*/ +/* FUNCTION : static void QuantizeSHBsubgains_fx() */ +/*------------------------------------------------------------*/ +/* PURPOSE : Quantize super highband temporal gains */ +/*------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* Word16 extl i : extension layer */ -/* Word32 extl_brate i : extension layer bitrate */ -/*--------------------------------------------------------------------------*/ +/* _(Word16) extl : extension layer Q0 */ +/*------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ +/* _ None */ +/*------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Word32 *GainFrame i/o: Gain Q18 */ -/*--------------------------------------------------------------------------*/ +/* _(Word16[])subgains :super highband temporal gains Q15 */ +/*------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ +/*------------------------------------------------------------*/ -static void QuantizeSHBframegain_fx( +static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - Word32 *GainFrame, /* i/o: Gain Q18 */ - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extension layer bitrate */ - Word16 *rf_gainFrame_ind ) + Word16 subgains[], /* i/o: super highband temporal gains Q15*/ + const Word16 extl /* i : extension layer */ +) { - Word16 idxFrameGain; - Word32 Q_GainFrame; - Word16 Unit_weights1 = 1; - move16(); - Word16 exp, frac, tmp; + Word16 i, idxSubGain; + Word16 Unit_weights10[NUM_SHB_SUBFR]; + Word16 exp, frac; Word32 L_tmp; - Word32 GainFrameLog; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; + BSTR_ENC_HANDLE hBstr = st_fx->hBstr; IF( EQ_16( extl, WB_TBE ) ) { - determine_gain_weights_fx( GainFrame, &( Unit_weights1 ), 1 ); - IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) + set16_fx( Unit_weights10, 32767, (Word16) NUM_SHB_SUBFR / 4 ); + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, - &Q_GainFrame, SHBCB_FrameGain16_fx ); - test(); - IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + IF( EQ_16( subgains[i], 0 ) ) { - idxFrameGain--; - Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + subgains[i + NUM_SHB_SUBFR / 4] = -18432; + move16(); /* (-72) in Q8 */ + } + ELSE + { + L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ + exp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /* move16(); */ + /*exp = -1 - exp; */ + exp = sub( -1, exp ); + L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q13 ; 20.0 * log10(2) in Q12*/ + subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ + move16(); } - hBWE_TD->gFrame_WB = idxFrameGain; - move16(); - *rf_gainFrame_ind = idxFrameGain; } - ELSE - { - singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain, &idxFrameGain, &Q_GainFrame, - SHBCB_FrameGain64_fx ); + idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); + Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, subgains, NUM_SHB_SUBFR / 4 ); - push_indice( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FrameGain ); - *rf_gainFrame_ind = idxFrameGain; - move16(); /* Q18 */ - } - } - ELSE - { - IF( *GainFrame == 0 ) - { - GainFrameLog = -196608; - move32(); - } - ELSE + push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); + + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - exp = norm_l( *GainFrame ); - frac = Log2_norm_lc( L_shl( *GainFrame, exp ) ); - // exp = ( 30 - exp - 18 ); - exp = sub( 30 - 18, exp ); - GainFrameLog = Mpy_32_16( exp, frac, 9864 ); - /*GainFrameLog= round_fx(L_shl(L_tmp,12)); //Q12 */ + L_tmp = L_mult( subgains[i], 21771 ); /* *0.166096 in Q17 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); + subgains[i] = extract_l( Pow2( 14, frac ) ); + move16(); + /* Put 14 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + subgains[i] = shl( subgains[i], add( exp, 1 ) ); + move16(); /*Q15 */ } - exp = norm_s( SHB_GAIN_QDELTA_FX_15 ); - tmp = div_s( shl( 1, sub( 14, exp ) ), SHB_GAIN_QDELTA_FX_15 ); - L_tmp = Mult_32_16( L_sub( GainFrameLog, SHB_GAIN_QLOW_FX_16 ), tmp ); - idxFrameGain = extract_l( L_shr( L_add( L_tmp, shl( 1, sub( 14, exp ) ) ), sub( 15, exp ) ) ); /*Q0*/ - IF( GT_16( idxFrameGain, ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1 ) ) + FOR( i = NUM_SHB_SUBFR / 2 - 1; i >= 0; i-- ) { - idxFrameGain = ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1; + subgains[i] = subgains[i / 2]; move16(); } - ELSE + } + ELSE + { + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - if ( idxFrameGain < 0 ) + IF( EQ_16( subgains[i], 0 ) ) + { + subgains[i] = -12288; + move16(); /* (-3) in Q12 */ + } + ELSE { - idxFrameGain = 0; + L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ + exp = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); + /*exp = -1 - exp; */ + exp = sub( -1, exp ); + + L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ + subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ move16(); } } - L_tmp = SHB_GAIN_QLOW_FX_16; - Q_GainFrame = L_mac( L_tmp, idxFrameGain, SHB_GAIN_QDELTA_FX_15 ); - - test(); - WHILE( GT_32( Q_GainFrame, L_add( GainFrameLog, 4866 ) ) && - idxFrameGain != 0 ) + idxSubGain = (Word16) vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); + + FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + L_tmp = L_mult( subgains[i], 27213 ); /* *3.321928 in Q13 -> Q26 */ + L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ + frac = L_Extract_lc( L_tmp, &exp ); + subgains[i] = extract_l( Pow2( 14, frac ) ); + move16(); + /* Put 14 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + subgains[i] = shl( subgains[i], add( exp, 1 ) ); + move16(); /*Q15 */ + } + + FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) { - test(); - idxFrameGain = sub( idxFrameGain, 1 ); - Q_GainFrame = L_mac0( SHB_GAIN_QLOW_FX_16, idxFrameGain, SHB_GAIN_QDELTA_FX_16 ); + subgains[i] = subgains[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + move16(); } - /* Q_GainFrame = (float) pow(10.0, Q_GainFrame ); */ - /* i: Q_GainFrame in Q16 */ - L_tmp = Mult_32_16( Q_GainFrame, 27213 ); /* *3.321928 in Q13 -> Q25 */ - L_tmp = L_shr( L_tmp, -2 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - Q_GainFrame = Pow2( 30, frac ); - exp = sub( exp, 30 ); - Q_GainFrame = L_shl( Q_GainFrame, add( exp, 18 ) ); /* Q18 */ - - hBWE_TD->idxFrameGain = idxFrameGain; + hBWE_TD->idxSubGains = idxSubGain; move16(); IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - push_indice( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); + push_indice( hBstr, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); } - *rf_gainFrame_ind = idxFrameGain; - move16(); } - IF( EQ_16( st_fx->rf_mode, 1 ) ){ - /*Currently intended for SWB only. Modify for WB is needed later!*/ - IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ){ - *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ - move16(); + return; } -ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ + + +/*-------------------------------------------------------------------* + * Quant_shb_ener_sf_fx_fx() + * + * Quantize SHB subframe energies + *-------------------------------------------------------------------*/ + +static void Quant_shb_ener_sf_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies Q_ener */ + const Word16 Q_ener ) { - IF( *GainFrame <= 327680 /*1.25 in Q18*/ ) /* [0 to 1.25] range --> 0.5*/ - { - *rf_gainFrame_ind = 0; - } - ELSE IF( *GainFrame <= 786432 /*3 in Q18*/ ) /* (1.25 to 3] --> 2 */ + Word16 idxSubEner_fx; + Word16 temp_shb_ener_sf_fx; + Word16 exp /*, exp2*/, frac; + Word32 L_tmp1, L_tmp; + Word32 sum; + Word16 tmp; + Word16 Q_fac; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + + /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ + sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ + move32(); + + exp = norm_l( sum ); + frac = Log2_norm_lc( L_shl( sum, exp ) ); + exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ + IF( st_fx->element_mode == EVS_MONO ) { - *rf_gainFrame_ind = 1; + L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ + + 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, 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 IF( *GainFrame <= 1572864 /*6 in Q18*/ ) /* (3 to 6] --> 4 */ + ELSE { - *rf_gainFrame_ind = 2; + 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 */ + Q_fac = -Q9; + move16(); } - ELSE /* (6 to Inf) --> 8 */ + + /* 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 Q12/Q11+Q13+1 = Q26/Q25 */ + L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ + 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(); + + hBWE_TD->idx_shb_fr_gain = idxSubEner_fx; + move16(); + IF( NE_16( st_fx->codec_mode, MODE2 ) ) { - *rf_gainFrame_ind = 3; + push_indice( st_fx->hBstr, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF ); } - move16(); -} + + return; } -*GainFrame = Q_GainFrame; -move32(); /* Q18 */ -return; +/*-------------------------------------------------------------------* + * Quant_shb_res_gshape_fx() + * + * Quantize SHB gain shapes in residual domain + *-------------------------------------------------------------------*/ + +static void Quant_shb_res_gshape_fx( + Encoder_State *st, /* i/o: encoder state structure */ + Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ +) +{ + Word16 i, idxSubGain_fx[NB_SUBFR16k]; + TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; + + FOR( i = 0; i < NB_SUBFR16k; i++ ) + { + idxSubGain_fx[i] = usquant_fx( shb_res_gshape_fx[i], + &shb_res_gshape_fx[i], + 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ + 1024 /*0.125f Q13*/, /*1024 = 0.125 in Q13 */ + shl( 1, NUM_BITS_SHB_RES_GS ) ); + move16(); + + IF( EQ_16( st->codec_mode, MODE2 ) ) + { + hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; + move16(); + } + ELSE + { + push_indice( st->hBstr, IND_SHB_RES_GS + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); + } + } + + return; } /*==========================================================================*/ -/* FUNCTION : static void QuantizeSHBframegain_ivas_fx() */ +/* FUNCTION : static void QuantizeSHBframegain_fx() */ /*--------------------------------------------------------------------------*/ /* PURPOSE : QQuantize super highband frame gain */ /*--------------------------------------------------------------------------*/ @@ -5929,7 +4900,7 @@ return; /* */ /*==========================================================================*/ -static void QuantizeSHBframegain_ivas_fx( +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5958,11 +4929,23 @@ 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 */ + + IF( st_fx->element_mode == EVS_MONO ) + { + 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 { - idxFrameGain--; - Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + 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 ) ) @@ -6168,6 +5151,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*/ @@ -6232,6 +5216,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 */ @@ -6300,6 +5285,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*/ @@ -6476,195 +5462,75 @@ static Word16 Find_LSF_grid_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - tmp = mult_r( sub( lsf_map[i], offset ), scale ); - lsf_map[i] = add( tmp, offset ); - move16(); - } - } - - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; - move16(); - scale = sub( MAX_LSF_FX, last_q_lsf ); - - FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) - { - FOR( j = 0; j < NUM_MAP_LSF; j++ ) - { - grid[i][j] = add( mult_r( lsf_grid_fx[i][j], scale ), last_q_lsf ); - move16(); - } - } - - D_best = L_add( MAX_32, 0 ); - FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) - { - D = L_deposit_l( 0 ); - FOR( j = 0; j < NUM_MAP_LSF; j++ ) - { - /*lsf_t[j] = (1 - grid_smoothing[j])*lsf_map[j] + grid_smoothing[j]*grid[i][j]; */ - tmp = sub( 32767, grid_smoothing_fx[j] ); - tmp = mult_r( tmp, lsf_map[j] ); - tmp1 = mult_r( grid_smoothing_fx[j], grid[i][j] ); - lsf_t[j] = add( tmp, tmp1 ); - move16(); - - tmp = sub( lsf_t[j], lsf[NUM_Q_LSF + j] ); - D = L_mac0( D, tmp, tmp ); - - /* D += (lsf_t[j] - lsf[NUM_Q_LSF + j])*(lsf_t[j] - lsf[NUM_Q_LSF + j]); */ - } - IF( LT_32( D, D_best ) ) - { - Copy( lsf_t, lsf_smooth, NUM_MAP_LSF ); - D_best = L_add( D, 0 ); - I_best = i; - move16(); - } - } - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; - move16(); - } - - return I_best; -} - -/*-------------------------------------------------------------------* - * gainFrSmooth_En_fx() - * - * Gain frame smoothing and attenuation control - *-------------------------------------------------------------------*/ -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 ) -{ - Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; - Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; - Word16 lsp_spacing; - - Word32 tempQ31; - Word16 tempQ15_1, tempQ15_2; - Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - /* inits */ - *frGainAttenuate = 0; - move16(); - *frGainSmoothEn = 0; - move16(); - *MA_lsp_shb_spacing = 16384; - move16(); - lsp_spacing = lsp_shb_fx[0]; - move16(); - - /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_slow_interpl_fx[0] ); - tempQ15_2 = sub( lsp_shb_fx[0], hBWE_TD->lsp_shb_fast_interpl_fx[0] ); - lsp_slow_evol_rate = L_mult( tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mult( tempQ15_2, tempQ15_2 ); - - /* update the slow and fast lsp interp for next frame */ - tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[0], 22937 ); - hBWE_TD->lsp_shb_slow_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 9830 ); - move16(); - tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[0], 9830 ); - hBWE_TD->lsp_shb_fast_interpl_fx[0] = mac_r( tempQ31, lsp_shb_fx[0], 22937 ); - move16(); - - FOR( i = 1; i < LPC_SHB_ORDER; i++ ) - { - tempQ15_1 = sub( lsp_shb_fx[i], lsp_shb_fx[i - 1] ); - lsp_spacing = s_min( lsp_spacing, tempQ15_1 ); - - /* 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 = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); - - /* update the slow and fast interpolation lsps for next frame */ - tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 ); - hBWE_TD->lsp_shb_slow_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 9830 ); - move16(); - tempQ31 = L_mult( hBWE_TD->lsp_shb_fast_interpl_fx[i], 9830 ); - hBWE_TD->lsp_shb_fast_interpl_fx[i] = mac_r( tempQ31, lsp_shb_fx[i], 22937 ); - move16(); - } - - test(); - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && LT_16( lsp_spacing, 262 ) ) - { - hBWE_TD->lsp_shb_spacing_fx[0] = lsp_spacing; - move16(); - hBWE_TD->lsp_shb_spacing_fx[1] = lsp_spacing; - move16(); - hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; - move16(); - hBWE_TD->prev_frGainAtten = 1; - move16(); - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + tmp = mult_r( sub( lsf_map[i], offset ), scale ); + lsf_map[i] = add( tmp, offset ); + move16(); + } } - /* Estimate the moving average LSP spacing */ - tempQ31 = L_mult( hBWE_TD->lsp_shb_spacing_fx[0], 3277 ); /* 0.1f */ - tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f */ - tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f */ - *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f */ - move16(); - - hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; - move16(); - hBWE_TD->lsp_shb_spacing_fx[1] = hBWE_TD->lsp_shb_spacing_fx[2]; - move16(); - hBWE_TD->lsp_shb_spacing_fx[2] = lsp_spacing; + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; move16(); + scale = sub( MAX_LSF_FX, last_q_lsf ); - test(); - test(); - test(); - IF( ( LT_16( lsp_spacing, 262 ) && ( LT_16( *MA_lsp_shb_spacing, 164 ) || EQ_16( hBWE_TD->prev_frGainAtten, 1 ) ) ) || LE_16( lsp_spacing, 105 ) ) + FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) { - *frGainAttenuate = 1; - move16(); - - IF( NE_32( st_fx->total_brate, ACELP_24k40 ) ) + FOR( j = 0; j < NUM_MAP_LSF; j++ ) { - Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); - fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, hBWE_TD->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1, 3 ); + grid[i][j] = add( mult_r( lsf_grid_fx[i][j], scale ), last_q_lsf ); + move16(); } - ELSE + } + + D_best = L_add( MAX_32, 0 ); + FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) + { + D = L_deposit_l( 0 ); + FOR( j = 0; j < NUM_MAP_LSF; j++ ) { - set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - } + /*lsf_t[j] = (1 - grid_smoothing[j])*lsf_map[j] + grid_smoothing[j]*grid[i][j]; */ + tmp = sub( 32767, grid_smoothing_fx[j] ); + tmp = mult_r( tmp, lsf_map[j] ); + tmp1 = mult_r( grid_smoothing_fx[j], grid[i][j] ); + lsf_t[j] = add( tmp, tmp1 ); + move16(); - test(); - if ( LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) + tmp = sub( lsf_t[j], lsf[NUM_Q_LSF + j] ); + D = L_mac0( D, tmp, tmp ); + + /* D += (lsf_t[j] - lsf[NUM_Q_LSF + j])*(lsf_t[j] - lsf[NUM_Q_LSF + j]); */ + } + IF( LT_32( D, D_best ) ) { - *frGainSmoothEn = 1; + Copy( lsf_t, lsf_smooth, NUM_MAP_LSF ); + D_best = L_add( D, 0 ); + I_best = i; move16(); } } + + FOR( i = 0; i < NUM_MAP_LSF; i++ ) + { + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + move16(); + } + + return I_best; } /*-------------------------------------------------------------------* - * gainFrSmooth_En_ivas_fx() + * gainFrSmooth_En_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 */ ) + +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 */ ) { Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; @@ -6712,8 +5578,16 @@ 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 ); + 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 + { + 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 */ ); @@ -6772,12 +5646,23 @@ 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 ) ) + 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 ) + { + 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 @@ -7150,72 +6035,8 @@ static void LVQQuant_BWE_LSF_fx( * Quantize super highband spectral envolope *-------------------------------------------------------------------*/ -static void Quant_BWE_LSF_fx( - - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 lsf_shb[], /* i : unquanitzed LSFs */ - Word16 Q_lsfs[] /* o : quanitzed LSFs */ -) -{ - Word16 lsf[LPC_SHB_ORDER]; - Word16 lsf_q[LPC_SHB_ORDER]; - Word16 lsf_idx[NUM_Q_LSF]; - Word16 i; - Word16 m_idx; - Word16 m; - Word16 grid_idx; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - lsf[i] = sub( 16384, lsf_shb[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - - Quant_lower_LSF_fx( lsf, lsf_q, lsf_idx ); - /* i: lsf in Q15 */ - /* o: lsf_q in Q15 */ - - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - hBWE_TD->lsf_idx[i] = lsf_idx[i]; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( hBstr, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); - } - } - - m_idx = Quant_mirror_point_fx( lsf, lsf_q, &m ); - - hBWE_TD->m_idx = m_idx; - move16(); - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( hBstr, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); - } - - grid_idx = Find_LSF_grid_fx( lsf, lsf_q, m ); - - hBWE_TD->grid_idx = grid_idx; - IF( NE_16( st_fx->codec_mode, MODE2 ) ) - { - push_indice( hBstr, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - Q_lsfs[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - - return; -} - -static void Quant_BWE_LSF_ivas_fx( +static void Quant_BWE_LSF_fx( 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 */ @@ -7299,135 +6120,11 @@ static void Quant_BWE_LSF_ivas_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( - 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 ) -{ - Word16 ratio; - Word16 tmp_vec[L_FRAME48k]; - Word16 idxGain; - Word16 input_fhb_buffer[L_FRAME48k + 4]; - Word16 *input_fhb = &input_fhb_buffer[0] + 4; - Word16 Sample_Delay_HP; - Word32 fb_exc_energy, temp2; - Word32 L_tmp; - Word16 tmp, tmp1, tmp2, exp, exp2, exp_norm; - Word16 s_max_value, exp_temp, i; - TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; - - s_max_value = 0; - FOR( i = 0; i < L_FRAME48k; i++ ) - { - s_max_value = s_max( s_max_value, abs_s( new_input[i] ) ); - } - exp_temp = norm_s( s_max_value ); - if ( s_max_value == 0 ) - { - exp_temp = 15; - move16(); - } - exp_temp = sub( exp_temp, 1 ); - - 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 ); - 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 ) ) - { - set16_fx( hBWE_TD->old_input_fhb_fx, 0, Sample_Delay_HP ); - hBWE_TD->old_input_fhb_fx_Q = 0; - move16(); - set16_fx( tmp_vec, 0, L_FRAME16k ); - } - 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 ); - temp2 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ - temp2 = L_add_sat( temp2, 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_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ - - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - L_tmp = L_max( 1, temp2 ); /*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_energy ); - tmp2 = extract_h( L_shl( fb_exc_energy, 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 ); - exp_norm = norm_s( ratio ); - idxGain = sub( 14, exp_norm ); - 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 ); - } - - /* ratio = (float)(1 << idxGain);*/ - IF( st->codec_mode == MODE2 ) - { - hBWE_TD->idxGain = idxGain; - move16(); - } - ELSE - { - push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); - } - - return; -} - -void fb_tbe_enc_ivas_fx( 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]; @@ -7442,12 +6139,20 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; Word16 q_diff, q_input_fhb; Word64 temp1, temp2; + Word16 offset; + + offset = 0; + move16(); + if ( st->element_mode > EVS_MONO ) + { + offset = NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); + } s_max_value = 0; move16(); - FOR( i = 0; i < L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); i++ ) + FOR( i = 0; i < add( L_FRAME48k, offset ); i++ ) { - s_max_value = s_max( s_max_value, abs_s( new_input[i - NS2SA( 48000, DELAY_FIR_RESAMPL_NS )] ) ); + s_max_value = s_max( s_max_value, abs_s( new_input[i - offset] ) ); } exp_temp = norm_s( s_max_value ); if ( s_max_value == 0 ) @@ -7456,27 +6161,26 @@ void fb_tbe_enc_ivas_fx( move16(); } - Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); + if ( st->element_mode == EVS_MONO ) + { + exp_temp = sub( exp_temp, 1 ); + } + + Copy_Scale_sig( new_input - offset, input_fhb_new, add( L_FRAME48k, offset ), exp_temp ); 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 ); + 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 ); } 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; @@ -7499,71 +6203,142 @@ 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 ) + 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 { - 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);*/ @@ -7576,8 +6351,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 */ ) @@ -7604,7 +6388,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 ) ) { @@ -7656,22 +6439,29 @@ void tbe_write_bitstream_fx( { push_next_indice( hBstr, hBWE_TD->idxGain, 4 ); } + + return; } +/*---------------------------------------------------------------------* + * TBEreset_enc() + * + * + *---------------------------------------------------------------------*/ + void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word16 last_core, /* i : last core */ + Word16 bandwidth /* i : bandwidth mode */ ) { - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - IF( NE_16( st_fx->last_core, ACELP_CORE ) ) + IF( NE_16( last_core, ACELP_CORE ) ) { 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(); - st_fx->prev_Q_bwe_exc = 31; + hBWE_TD->prev_Q_bwe_exc = 31; move16(); } @@ -7701,6 +6491,8 @@ void TBEreset_enc_fx( 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 ); } } + + return; } /*-------------------------------------------------------------------* diff --git a/lib_enc/tcq_core_enc_fx.c b/lib_enc/tcq_core_enc_fx.c index d5841094fffca30c897bf4c791ad55ad703ffd56..517c1c0b49400fc77ded750bf8cb4924be12033e 100644 --- a/lib_enc/tcq_core_enc_fx.c +++ b/lib_enc/tcq_core_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include @@ -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 9f8b26cf8e751119ba541900953f8e53ae3dd3d1..7650516cb3898086ace272f3966f4e47db1a2d00 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -1,10 +1,10 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #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/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index bbeb26ee394d24ee76664d0f3c1293532f83b663..9765655ba4d880bab90ca7e255273a39d60d3b79 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index a6a1eaa8501e54e4fca18402b1ee6c759fbd53da..60427f792b0877bc47e79a7bf6087f6161ca2fb2 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 3f671f705930b82e4fdce2858c72e23b2c60052e..be7c067608e36ab3bfd92cfde03a2925d5580857 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" @@ -50,6 +50,7 @@ typedef Word32 ( *TLinearPredictionFilter )( Word16 order, Word16 const parCoeff /********************************/ #define MAX_SUBDIVISIONS 3 +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, Word32 const pSpectrum[], @@ -301,7 +302,7 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, return ( pTnsData->nFilters > 0 ); } - +#endif // FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT void CalculateTnsFilt_fx( STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */ const Word32 pSpectrum[], /* i : MDCT spectrum */ @@ -409,13 +410,19 @@ void CalculateTnsFilt_fx( return; } -Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */ - Word32 const pSpectrum[], /* i : MDCT spectrum Q=Qx */ - STnsData *pTnsData, /* o : TNS data struct */ - TRAN_DET_HANDLE hTranDet, /* i : transient detection handle */ - Word8 isTCX10, /* i : TCX10 or TCX20? */ - Word16 ltp_gain, /* i : LTP gain Q=15 */ - Word16 *predictionGain /* o : TNS prediction gain Q=7 */ +#ifdef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT +Word16 DetectTnsFilt_fx( +#else +Word16 DetectTnsFilt_ivas_fx( +#endif // FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT + + STnsConfig const *pTnsConfig, /* i : TNS Configuration struct */ + Word32 const pSpectrum[], /* i : MDCT spectrum Q=Qx */ + STnsData *pTnsData, /* o : TNS data struct */ + TRAN_DET_HANDLE hTranDet, /* i : transient detection handle */ + Word8 isTCX10, /* i : TCX10 or TCX20? */ + Word16 ltp_gain, /* i : LTP gain Q=15 */ + Word16 *predictionGain /* o : TNS prediction gain Q=7 */ ) { Word16 facs[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; @@ -630,7 +637,11 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur } /* We check the filter's decisions in the opposite direction */ +#ifndef FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT FOR( iFilter = ( pTnsConfig->nMaxFilters - 1 ); iFilter >= 0; iFilter-- ) +#else + FOR( iFilter = sub( pTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) +#endif // FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT { STnsFilter *pFilter; struct TnsParameters const *pTnsParameters; @@ -791,32 +802,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. */ /*********************************************************************************************/ @@ -837,7 +849,7 @@ static void GetFilterParameters_ivas( Word32 rxx[], Word16 maxOrder, STnsFilter #elif TNS_COEF_RES == 4 Word16 const *values = tnsCoeff4; #elif TNS_COEF_RES == 3 - Word16 const *values = tnsCoeff3; + Word16 const *values = tnsCoeff3; #endif Word16 *indexes = pTnsFilter->coefIndex; @@ -899,7 +911,7 @@ static void GetFilterParameters( Word32 rxx[], Word16 maxOrder, STnsFilter *pTns #elif TNS_COEF_RES == 4 Word16 const *values = tnsCoeff4; #elif TNS_COEF_RES == 3 - Word16 const *values = tnsCoeff3; + Word16 const *values = tnsCoeff3; #endif Word16 *indexes = pTnsFilter->coefIndex; @@ -959,7 +971,7 @@ static void Parcor2Index( const Word16 parCoeff[] /*Q15*/, Word16 index[], Word1 #elif TNS_COEF_RES == 4 values = tnsCoeff4; #elif TNS_COEF_RES == 3 - values = tnsCoeff3; + values = tnsCoeff3; #endif FOR( i = 0; i < order; i++ ) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index b0593456d05d7aeada3e57c854eb50b4a398e020..f671b8d9eef275a7c27505c68bbdf9f21f422b5a 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "options.h" @@ -296,7 +296,6 @@ void InitTransientDetection_fx( /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ hTranDet->transientDetector.pSubblockEnergies->nDelay = add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); - move16(); return; } @@ -305,29 +304,32 @@ void InitTransientDetection_fx( void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, + TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ) { /* Init the delay buffer. */ - InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); + InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); + /* Init the TCX Short/Long transient detector. */ - InitTransientDetector_ivas_fx( &pTransientDetection->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); + InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ IF( ext_mem_flag ) { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); move16(); } ELSE { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); move16(); } @@ -432,7 +434,6 @@ Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( return i; } - Word16 GetTCXMaxenergyChange_fx( TRAN_DET_HANDLE hTranDet, const Word8 isTCX10, diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 842b635515650a93aea44655363ad030ea3c5de6..00e047e16e6bfbc4f53e4b7b1fa9dc03710ef5e4 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -16,44 +16,43 @@ 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 ); /*==========================================================================*/ -/* FUNCTION : void transition_enc_fx () */ +/* FUNCTION : void transition_enc_fx () */ /*--------------------------------------------------------------------------*/ /* PURPOSE :Principal function for adaptive excitation construction in TC*/ /*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* (Word32) core_brate : core bitrate Q0 */ -/* (Word16) bwidth : input signal bandwidth Q0 */ -/* (Word16) i_subfr : subrame index Q0 */ -/* (Word16*) Jopt_flag : joint optimization flag Q0 */ -/* (Word16*) h1_fx : weighted filter input response Q14 */ -/* (Word16*) xn_fx : target signal Q_new*/ -/* (Word16) Q_new : input scaling */ +/* INPUT ARGUMENTS : */ +/* (Word32) core_brate : core bitrate Q0 */ +/* (Word16) bwidth : input signal bandwidth Q0 */ +/* (Word16) i_subfr : subrame index Q0 */ +/* (Word16*) Jopt_flag : joint optimization flag Q0 */ +/* (Word16*) h1_fx : weighted filter input response Q14 */ +/* (Word16*) xn_fx : target signal Q_new */ +/* (Word16) Q_new : input scaling */ /*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* (Word16*) y1_fx : zero-memory filtered adaptive excitation Q12*/ -/* (Word16*) xn2_fx : target vector for innovation search Qnew */ -/* (Word16*) gain_pit_fx : pitch gain (0..GAIN_PIT_MAX) Q14*/ -/* (Word16[])g_corr_fx : correlations and -2 */ -/* (Word16**)pt_pitch_fx : floating pitch values Q6 */ -/* (Word16*) bwe_exc_fx : excitation for SWB TBE Q0 */ +/* OUTPUT ARGUMENTS : */ +/* (Word16*) y1_fx : zero-memory filtered adaptive excitation Q12*/ +/* (Word16*) xn2_fx : target vector for innovation search Qnew */ +/* (Word16*) gain_pit_fx : pitch gain (0..GAIN_PIT_MAX) Q14*/ +/* (Word16[])g_corr_fx : correlations and -2 */ +/* (Word16**)pt_pitch_fx : floating pitch values Q6 */ +/* (Word16*) bwe_exc_fx : excitation for SWB TBE Q0 */ /*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* (Word16*) tc_subfr : TC subframe index Q0 */ -/* (Word16*) position : index of the residual signal maximum Q0 */ -/* (Word16*) T0_min : lower pitch limit Q0 */ -/* (Word16*) T0_max : higher pitch limit Q0 */ -/* (Word16*) T0 : close loop integer pitch Q0 */ -/* (Word16*) T0_frac : close loop fractional part of the pitch Q0*/ -/* (Word16*) exc_fx : pointer to excitation signal frame */ -/* (Word16*) gp_cl_fx : memory of gain of pitch clipping algorithm*/ -/* (Word16*) clip_gain : adaptive gain clipping flag Q0 */ +/* INPUT/OUTPUT ARGUMENTS : */ +/* (Word16*) tc_subfr : TC subframe index Q0 */ +/* (Word16*) position : index of the residual signal maximum Q0 */ +/* (Word16*) T0_min : lower pitch limit Q0 */ +/* (Word16*) T0_max : higher pitch limit Q0 */ +/* (Word16*) T0 : close loop integer pitch Q0 */ +/* (Word16*) T0_frac : close loop fractional part of the pitch Q0*/ +/* (Word16*) exc_fx : pointer to excitation signal frame */ +/* (Word16*) gp_cl_fx : memory of gain of pitch clipping algorithm*/ +/* (Word16*) clip_gain : adaptive gain clipping flag Q0 */ /*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ +/* RETURN ARGUMENTS : */ +/* _ None */ /*--------------------------------------------------------------------------*/ void transition_enc_fx( @@ -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,941 +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; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - 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 ); @@ -1962,230 +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; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - 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/update_decision_fx.c b/lib_enc/update_decision_fx.c index 315adcf819d9061691879a2b3c4c3f4752bdba94..67476f993d40d0b86101138e67942b60fcb152df 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index 9b6f80c3f26de28c7667369eb0e83af8569e3d5f..d0826c42953b0177216ddcdaf36b23e0abf1ab90 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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 ); @@ -266,7 +269,7 @@ void updt_IO_switch_enc_fx( hSC_VBR->nelp_mode = 0; move16(); } - st->hGSCEnc->seed_tcx = 15687; /* the re-init here was present only in float _DIFF_FLOAT_FIX_*/ + st->hGSCEnc->seed_tcx = 15687; move16(); } @@ -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/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index 9d6b5d2d6751c852216a6801f7aa9d4af97801d2..b379f24ef12bf213da0b25001f10d716d6a2c5f9 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include "options.h" /* Compilation switches */ @@ -23,10 +23,8 @@ void updt_tar_fx( { Word16 i; Word32 L_tmp; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif FOR( i = 0; i < L; i++ ) @@ -55,10 +53,8 @@ void updt_tar_HR_fx( { Word16 i; Word32 L_tmp, L_tmp1; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); -#endif FOR( i = 0; i < L; i++ ) { diff --git a/lib_enc/vad_basop.h b/lib_enc/vad_basop.h index 2437317849895d206e5b0fc7e6a42cec5f568a22..f6a0fed342357d0b1fe10f1d654305ddd85a607d 100644 --- a/lib_enc/vad_basop.h +++ b/lib_enc/vad_basop.h @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef __VAD_BASOP_H__ diff --git a/lib_enc/vad_basop_fx.c b/lib_enc/vad_basop_fx.c index d6d0783105621e70b314ab8a971be27bd4d60434..3436a1d681e79b4d9822da261aa0f76414c293e3 100644 --- a/lib_enc/vad_basop_fx.c +++ b/lib_enc/vad_basop_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index c4c6df6c3b4e55a8e1aa0beccac0951ecdbb63d7..7c541478058975c0b623e303c7d9a8833b7e8a7f 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -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() * @@ -632,15 +449,15 @@ Word16 ivas_dtx_hangover_addition_fx( *-----------------------------------------------------------------*/ /* new simplified and harmonized code */ Word16 wb_vad_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ Word16 *localVAD_HE_SAD, Word16 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ + const Word16 Q_new, /* i : scaling factor Q0 */ VAD_HANDLE hVAD, /* i/o: VAD data handle */ NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ @@ -745,16 +562,7 @@ Word16 wb_vad_fx( st_fx->max_band = 19; move16(); } - /*_DIFF_FLOAT_FIX_ -> see around Ln1570, inversion in if conditions compared to float*/ - // PMT("Error in EVS fixed point ?") - /*FIXED EVS */ - /* ELSE IF(((LE_16(st_fx->last_coder_type, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR != 0)) || - ((LE_16(last_7k2_coder_type, UNVOICED)) && (LT_32(L_snr_outlier, MAX_SNR_OUTLIER_2_FX)) && (st_fx->Opt_SC_VBR == 0)))*/ - - /*FLOAT both IVAS and EVS */ - /*if ((snr_outlier_index <= 4 && (st->last_coder_type > UNVOICED) && !st->Opt_SC_VBR) || - (snr_outlier_index <= 4 && (last_7k2_coder_type > UNVOICED) && st->Opt_SC_VBR))*/ - IF( 1 ) // st_fx->Opt_SC_VBR) + 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(); @@ -1327,7 +1135,7 @@ Word16 wb_vad_fx( test(); test(); test(); - test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float + test(); /*_DIFF_FLOAT_FIX_EVS -> the conditions around Opt_SC_VBR_fx are invertered compared to float ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ // test(); IF( LE_16( snr_outlier_index, 4 ) && ( ( GT_16( st_fx->last_coder_type, UNVOICED ) && ( st_fx->Opt_SC_VBR != 0 ) ) || @@ -1730,7 +1538,7 @@ Word16 wb_vad_fx( /* *flag_noisy_speech_snr is a Word8 parameter */ - *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_ -> this initialisation is not done here in float */ + *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */ move16(); IF( vad_bwidth_fx != NB ) { @@ -1860,8 +1668,8 @@ Word16 wb_vad_fx( } Word16 wb_vad_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ const Word16 q_fr_bands, /* i : Q of fr_bands */ Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ @@ -2593,8 +2401,7 @@ Word16 wb_vad_ivas_fx( test(); test(); test(); - test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float - ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ + test(); test(); IF( ( LE_16( snr_outlier_index, 4 ) && ( st_fx->last_coder_type > UNVOICED ) && !st_fx->Opt_SC_VBR ) || ( LE_16( snr_outlier_index, 4 ) && ( last_7k2_coder_type > UNVOICED ) && st_fx->Opt_SC_VBR ) ) @@ -3006,7 +2813,7 @@ Word16 wb_vad_ivas_fx( /* *flag_noisy_speech_snr is a Word8 parameter */ - *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_ -> this initialisation is not done here in float */ + *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */ move16(); IF( vad_bwidth_fx != NB ) { diff --git a/lib_enc/vad_param_updt_fx.c b/lib_enc/vad_param_updt_fx.c index 9738da4d653187e2e8c9c77ad19b984e32af1e3a..9677fd2ebb8518c874b3cf8b0287bdbb7988b201 100644 --- a/lib_enc/vad_param_updt_fx.c +++ b/lib_enc/vad_param_updt_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index 16247be44474036584edb5484e2e47a18279a037..62469f3a7f522f8dcb9db781f9fdc334c46e5225 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ diff --git a/lib_enc/vbr_average_rate_fx.c b/lib_enc/vbr_average_rate_fx.c index f1f75a30a40dff5cef50c030d359d1bfd2fcabb4..fd1092104eebfa09456f6f7bbc4b8f7c229d2703 100644 --- a/lib_enc/vbr_average_rate_fx.c +++ b/lib_enc/vbr_average_rate_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -15,27 +15,27 @@ #define RATEWIN 600 /* length of the rate control window. This is 600 active speech frames. This equals roughly 12s of active speech */ /*=================================================================================*/ -/* FUNCTION : update_average_rate_fx */ +/* FUNCTION : update_average_rate_fx */ /*---------------------------------------------------------------------------------*/ -/* PURPOSE : SC-VBR update average data rate */ +/* PURPOSE : SC-VBR update average data rate */ /*---------------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) */ +/* _ (struct DTFS_STRUCTURE_FX) */ /*---------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* hSC_VBR->global_avr_rate_fx Q13 */ -/* hSC_VBR->sum_of_rates_fx Q13 */ -/* hSC_VBR->SNR_THLD_fx Q8 */ -/* hSC_VBR->Q_to_F_fx Q0 */ -/* hSC_VBR->pattern_m_fx Q0 */ -/* hSC_VBR->rate_control_fx Q0 */ +/* hSC_VBR->global_avr_rate_fx Q13 */ +/* hSC_VBR->sum_of_rates_fx Q13 */ +/* hSC_VBR->SNR_THLD_fx Q8 */ +/* hSC_VBR->Q_to_F_fx Q0 */ +/* hSC_VBR->pattern_m_fx Q0 */ +/* hSC_VBR->rate_control_fx Q0 */ /*---------------------------------------------------------------------------------*/ -/*/* OUTPUT ARGUMENTS : */ +/*/* OUTPUT ARGUMENTS : */ /* _ None */ /*---------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : _ None. */ /*---------------------------------------------------------------------------------*/ -/* CALLED FROM : */ +/* CALLED FROM : */ /*=================================================================================*/ void update_average_rate_fx( SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */ diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index 9cbbd87964c44b8fa187ab7e5c197ce34d460fe2..f9b5ebbb321233c91cfc5fd889cc9c10f7276bf9 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/vlpc_2st_cod_fx.c b/lib_enc/vlpc_2st_cod_fx.c index 6db7cd3ef6e350ce3cced4767ed7bffb466cd9a6..32ab21877f844b8b1876a310dab6ee8ba590e645 100644 --- a/lib_enc/vlpc_2st_cod_fx.c +++ b/lib_enc/vlpc_2st_cod_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include @@ -17,7 +17,7 @@ * *------------------------------------------------------------------*/ -Word16 vlpc_2st_cod_fx( /* output: number of allocated bits */ +Word16 vlpc_2st_cod_fx( /* output: number of allocated bits */ const Word16 *lsf, /* i : normalized vector to quantize (14Q1*1.28) */ Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage (14Q1*1.28) */ Word16 *indx, /* o : index[] (4 bits per words) Q0 */ diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index a78ec7648031fa923d47c90b184a8b6aeab61ca6..fc3b81724aedeea77fa7fbfa06f01bf235fac865 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_enc/waveadjust_fec_cod_fx.c b/lib_enc/waveadjust_fec_cod_fx.c index 4efe9b9fef3c422bca866726e53010a98fe3758c..07fa26b5b7857b408733df7778c2a916c368b493 100644 --- a/lib_enc/waveadjust_fec_cod_fx.c +++ b/lib_enc/waveadjust_fec_cod_fx.c @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include 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_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 e1b173e02c4655a9e462eb3e0078ad76e5a67788..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( @@ -67,13 +67,8 @@ void isar_splitBinPreRendClose( void lc3plusTimeAlignCldfbPoseCorr( SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renderer handle */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, real part */ Word32 *Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, imag. part */ -#else - Word32 Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], -#endif Word16 *Q_in ); @@ -193,13 +188,8 @@ void isar_splitBinLCLDEncClose( void isar_splitBinLCLDEncProcess( ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE hSplitBinLCLDEnc, /* i/o: ISAR LCLD encoder handle */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_In_Real_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, real part */ Word32 *Cldfb_In_Imag_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, imag. part */ -#else - Word32 Cldfb_In_Real[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_In_Imag[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], -#endif const Word32 available_bits, /* i : available bit-budget */ ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: ISAR bits handle */ Word16 *q_final @@ -295,17 +285,9 @@ void isar_rend_CldfbSplitPreRendProcess( const ISAR_BIN_HR_SPLIT_PRE_REND_HANDLE hBinHrSplitPreRend, /* i : binaural pre-renderer handle */ const IVAS_QUATERNION headPosition, /* i : head rotation QUATERNION */ MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32* Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i : Binaural signals, real part */ -#else - Word32 Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], -#endif Word16 exp_cldfb_re, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32* Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], /* i : Binaural signals, imag. part */ -#else - Word32 Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], -#endif Word16 exp_cldfb_im, ISAR_SPLIT_REND_BITS_HANDLE pBits, const Word32 target_md_bits, @@ -388,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 e1ddadf354a1e514671bb303ea7e21cba8528643..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 @@ -225,27 +225,15 @@ void isar_splitBinLCLDDecProcess( #endif IF( AnyDecodingFailed( hSplitBinLCLDDec->psLCLDDecoder ) ) { - IF( NE_16( *Q_cldfb_final, 11 ) ) - { - FOR( n = 0; n < hSplitBinLCLDDec->iChannels; n++ ) - { - FOR( k = 0; k < hSplitBinLCLDDec->iNumBlocks; k++ ) - { - FOR( Word16 j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - hSplitBinLCLDDec->pppfDecLCLDReal_fx[n][k][j] = L_shl_r( hSplitBinLCLDDec->pppfDecLCLDReal_fx[n][k][j], sub( 11, *Q_cldfb_final ) ); // Q11 - hSplitBinLCLDDec->pppfDecLCLDImag_fx[n][k][j] = L_shl_r( hSplitBinLCLDDec->pppfDecLCLDImag_fx[n][k][j], sub( 11, *Q_cldfb_final ) ); // Q11 - } - } - } - *Q_cldfb_final = 11; - } + *Q_cldfb_final = hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx; + /* continue concealing */ isar_splitBinRendPLC( hSplitBinLCLDDec->hSplitRendPLC, Cldfb_Out_Real_fx, Cldfb_Out_Imag_fx, (Word16) hSplitBinLCLDDec->iChannels, hSplitBinLCLDDec->iNumBlocks, hSplitBinLCLDDec->iNumIterations, GetDecodingFailedStatus( hSplitBinLCLDDec->psLCLDDecoder ), *Q_cldfb_final ); } + IF( AnyDecodingFailedPrev( hSplitBinLCLDDec->psLCLDDecoder ) ) { - IF( NE_16( *Q_cldfb_final, 11 ) ) + IF( GT_16( *Q_cldfb_final, hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx ) ) { FOR( n = 0; n < hSplitBinLCLDDec->iChannels; n++ ) { @@ -253,13 +241,15 @@ void isar_splitBinLCLDDecProcess( { FOR( Word16 j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - hSplitBinLCLDDec->pppfDecLCLDReal_fx[n][k][j] = L_shl_r( hSplitBinLCLDDec->pppfDecLCLDReal_fx[n][k][j], sub( 11, *Q_cldfb_final ) ); // Q11 - hSplitBinLCLDDec->pppfDecLCLDImag_fx[n][k][j] = L_shl_r( hSplitBinLCLDDec->pppfDecLCLDImag_fx[n][k][j], sub( 11, *Q_cldfb_final ) ); // Q11 + hSplitBinLCLDDec->pppfDecLCLDReal_fx[n][k][j] = L_shl_r( hSplitBinLCLDDec->pppfDecLCLDReal_fx[n][k][j], sub( hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx, *Q_cldfb_final ) ); // hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx + hSplitBinLCLDDec->pppfDecLCLDImag_fx[n][k][j] = L_shl_r( hSplitBinLCLDDec->pppfDecLCLDImag_fx[n][k][j], sub( hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx, *Q_cldfb_final ) ); // hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx } } } - *Q_cldfb_final = 11; + + *Q_cldfb_final = hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx; } + /* cross-fade recovered frame into good frame */ isar_splitBinRendPLC_xf_fx( hSplitBinLCLDDec->hSplitRendPLC, Cldfb_Out_Real_fx, Cldfb_Out_Imag_fx, (Word16) hSplitBinLCLDDec->iChannels, hSplitBinLCLDDec->iNumBlocks, hSplitBinLCLDDec->iNumIterations, GetDecodingFailedStatus( hSplitBinLCLDDec->psLCLDDecoder ), GetDecodingFailedPrevStatus( hSplitBinLCLDDec->psLCLDDecoder ), *Q_cldfb_final ); } @@ -270,6 +260,8 @@ void isar_splitBinLCLDDecProcess( /* set states in decoder */ SetDecodingUnresolved( hSplitBinLCLDDec->psLCLDDecoder ); + *Q_cldfb_final = hSplitBinLCLDDec->hSplitRendPLC->CldfbPLC_state.Q_Prev_Bin_fx; + /* do PLC for lost split renderer frame */ isar_splitBinRendPLC( hSplitBinLCLDDec->hSplitRendPLC, Cldfb_Out_Real_fx, Cldfb_Out_Imag_fx, (Word16) hSplitBinLCLDDec->iChannels, hSplitBinLCLDDec->iNumBlocks, hSplitBinLCLDDec->iNumIterations, GetDecodingFailedStatus( hSplitBinLCLDDec->psLCLDDecoder ), *Q_cldfb_final ); } diff --git a/lib_isar/isar_splitRend_lcld_enc.c b/lib_isar/isar_splitRend_lcld_enc.c index b1249653f805e7ad97c993a46c8b5e7e3984ef24..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 @@ -39,11 +39,13 @@ #endif #include "wmc_auto.h" + /*------------------------------------------------------------------------- * Function isar_splitBinLCLDEncOpen() * * *------------------------------------------------------------------------*/ + ivas_error isar_splitBinLCLDEncOpen( ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE *hSplitBinLCLDEnc, const Word32 iSampleRate, @@ -145,22 +147,19 @@ void isar_splitBinLCLDEncClose( return; } + /*------------------------------------------------------------------------- * Function isar_splitBinLCLDEncProcess() * * *------------------------------------------------------------------------*/ + void isar_splitBinLCLDEncProcess( ISAR_BIN_HR_SPLIT_LCLD_ENC_HANDLE hSplitBinLCLDEnc, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_In_Real_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, real part */ Word32 *Cldfb_In_Imag_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, imag part */ -#else - Word32 Cldfb_In_Real_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_In_Imag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], -#endif - const Word32 available_bits, /* i : available bit-budget */ - ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: ISAR bits handle */ + const Word32 available_bits, /* i : available bit-budget */ + ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: ISAR bits handle */ Word16 *q_final ) { Word32 iBitsWritten, itr, available_bits_itr, rem_itr, available_bits_local; 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 f03afbeb8b79a4df9097257ed1f67b889301fd75..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 @@ -133,12 +131,12 @@ void isar_splitBinPostRendClose( { IF( ( *hBinHrSplitPostRend )->cldfbSyn[ch] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPostRend )->cldfbSyn[ch] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPostRend )->cldfbSyn[ch] ) ); ( *hBinHrSplitPostRend )->cldfbSyn[ch] = NULL; } IF( ( *hBinHrSplitPostRend )->cldfbAna[ch] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPostRend )->cldfbAna[ch] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPostRend )->cldfbAna[ch] ) ); ( *hBinHrSplitPostRend )->cldfbAna[ch] = NULL; } } @@ -149,7 +147,7 @@ void isar_splitBinPostRendClose( { if ( ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] ) ); ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] = NULL; } } @@ -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++ ) @@ -1818,13 +1816,14 @@ static void isar_rend_CldfbSplitPostRendProcessTdIn( { RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch_idx][slot_idx]; ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch_idx][slot_idx]; - scaleFactor = s_min( scaleFactor, s_min( getScaleFactor32( RealBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX ), getScaleFactor32( ImagBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX ) ) ); + scaleFactor = s_min( scaleFactor, s_min( L_norm_arr( RealBuffer_fx[slot_idx], num_cldfb_bands ), L_norm_arr( ImagBuffer_fx[slot_idx], num_cldfb_bands ) ) ); + scaleFactor = s_min( scaleFactor, L_norm_arr( hBinHrSplitPostRend->cldfbSyn[ch_idx]->cldfb_state_fx, hBinHrSplitPostRend->cldfbSyn[ch_idx]->cldfb_state_length ) ); } scaleFactor = s_min( sub( scaleFactor, 6 ), Q24 ); // guarded bits FOR( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) { - Scale_sig32( RealBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX, scaleFactor ); - Scale_sig32( ImagBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX, scaleFactor ); + Scale_sig32( RealBuffer_fx[slot_idx], num_cldfb_bands, scaleFactor ); + Scale_sig32( ImagBuffer_fx[slot_idx], num_cldfb_bands, scaleFactor ); } Q_cldfb = add( scaleFactor, Q_in ); Scale_sig32( hBinHrSplitPostRend->cldfbSyn[ch_idx]->cldfb_state_fx, hBinHrSplitPostRend->cldfbSyn[ch_idx]->p_filter_length, sub( sub( Q_cldfb, 1 ), Q11 ) ); @@ -1880,14 +1879,15 @@ void isar_rend_CldfbSplitPostRendProcess( { RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch_idx][slot_idx]; ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch_idx][slot_idx]; - scaleFactor = s_min( scaleFactor, s_min( getScaleFactor32( RealBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX ), getScaleFactor32( ImagBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX ) ) ); + scaleFactor = s_min( scaleFactor, s_min( L_norm_arr( RealBuffer_fx[slot_idx], num_cldfb_bands ), L_norm_arr( ImagBuffer_fx[slot_idx], num_cldfb_bands ) ) ); + scaleFactor = s_min( scaleFactor, L_norm_arr( hBinHrSplitPostRend->cldfbSyn[ch_idx]->cldfb_state_fx, hBinHrSplitPostRend->cldfbSyn[ch_idx]->cldfb_state_length ) ); } scaleFactor = s_min( sub( scaleFactor, 6 ), Q24 ); // guarded bits FOR( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) { - Scale_sig32( RealBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX, scaleFactor ); - Scale_sig32( ImagBuffer_fx[slot_idx], CLDFB_NO_CHANNELS_MAX, scaleFactor ); + Scale_sig32( RealBuffer_fx[slot_idx], num_cldfb_bands, scaleFactor ); + Scale_sig32( ImagBuffer_fx[slot_idx], num_cldfb_bands, scaleFactor ); } Q_cldfb = scaleFactor + Q_cldfb_in; Scale_sig32( hBinHrSplitPostRend->cldfbSyn[ch_idx]->cldfb_state_fx, hBinHrSplitPostRend->cldfbSyn[ch_idx]->p_filter_length, sub( sub( Q_cldfb, 1 ), Q11 ) ); diff --git a/lib_isar/isar_splitRendererPre.c b/lib_isar/isar_splitRendererPre.c index 8632b0aecf637cf4e513d38f02a98fd32d503299..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 @@ -48,6 +47,9 @@ #ifdef DBG_WAV_WRITER #include "string.h" #endif +#ifdef DEBUG_QUANT_CODE_OUT +#include "float_to_fix_ops.h" +#endif #include "basop_util.h" /*---------------------------------------------------------------------* @@ -56,17 +58,10 @@ static void isar_SplitRenderer_GetRotMd_fx( ISAR_BIN_HR_SPLIT_PRE_REND_HANDLE hBinHrSplitPreRend, MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_RealBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_re, Word32 *Cldfb_ImagBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_im, -#else - Word32 Cldfb_RealBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_re, - Word32 Cldfb_ImagBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_im, -#endif const Word16 low_res, const Word16 ro_md_flag ); @@ -354,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] ); } } @@ -524,29 +519,15 @@ static void ComputePostPredCov_fx( static void ComputeBandedCrossCov_fx( -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_RealBuffer1_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_re_1, Word32 *Cldfb_ImagBuffer1_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_im_1, -#else - Word32 Cldfb_RealBuffer1_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_re_1, - Word32 Cldfb_ImagBuffer1_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_im_1, -#endif const Word16 ch_start_idx1, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_RealBuffer2_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_re_2, Word32 *Cldfb_ImagBuffer2_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_im_2, -#else - Word32 Cldfb_RealBuffer2_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_re_2, - Word32 Cldfb_ImagBuffer2_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_im_2, -#endif const Word16 ch_start_idx2, Word32 out_cov_re_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word16 *exp_out_cov_re, @@ -656,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++ ) @@ -679,17 +660,10 @@ static void ComputeBandedCrossCov_fx( static void ComputeBandedCov_fx( -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *Cldfb_RealBuffer_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_re, Word32 *Cldfb_ImagBuffer_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_im, -#else - Word32 Cldfb_RealBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_re, - Word32 Cldfb_ImagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_im, -#endif const Word16 ch_start_idx, Word32 out_cov_re_fx[][BINAURAL_CHANNELS], Word16 *exp_cov_re, @@ -815,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] ); } } @@ -1127,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; @@ -2182,20 +2156,14 @@ static void isar_SplitRenderer_quant_code( * * *------------------------------------------------------------------------*/ + static void isar_SplitRenderer_GetRotMd_fx( - ISAR_BIN_HR_SPLIT_PRE_REND_HANDLE hBinHrSplitPreRend, /* i/o: binaural renderer handle */ - MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + ISAR_BIN_HR_SPLIT_PRE_REND_HANDLE hBinHrSplitPreRend, /* i/o: binaural renderer handle */ + MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ Word32 *Cldfb_RealBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX], /* o : Reference Binaural signals */ Word16 exp_cldfb_re, Word32 *Cldfb_ImagBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX], /* o : Reference Binaural signals */ Word16 exp_cldfb_im, -#else - Word32 Cldfb_RealBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* o : Reference Binaural signals */ - Word16 exp_cldfb_re, - Word32 Cldfb_ImagBuffer_Ref_Binaural_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* o : Reference Binaural signals */ - Word16 exp_cldfb_im, -#endif const Word16 low_res, const Word16 ro_md_flag ) { @@ -2294,17 +2262,10 @@ void isar_rend_CldfbSplitPreRendProcess( const ISAR_BIN_HR_SPLIT_PRE_REND_HANDLE hBinHrSplitPreRend, /* i : binaural pre-renderer handle */ const IVAS_QUATERNION headPosition, /* i : head rotation QUATERNION */ MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, /* i/o: pose correction data handle */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - Word32 *Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i : Binaural signals, real part */ + Word32 *Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i : Binaural signals, real part */ Word16 exp_cldfb_re, Word32 *Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], Word16 exp_cldfb_im, -#else - Word32 Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_re, - Word32 Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 exp_cldfb_im, -#endif ISAR_SPLIT_REND_BITS_HANDLE pBits, /* i/o: ISAR bits handle */ const Word32 target_md_bits, /* i : ISAR MD bitrate */ const Word16 low_res_pre_rend_rot, /* i : low time resolution pre-renderer flag */ @@ -2655,7 +2616,7 @@ void isar_splitBinPreRendClose( { IF( ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] ) ); ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] = NULL; } } @@ -2744,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; } @@ -2876,6 +2838,7 @@ ivas_error splitRendLc3plusEncodeAndWrite( pBits->pose_correction = hSplitBin->multiBinPoseData.poseCorrectionMode; pBits->codec_frame_size_ms = (Word16) ( hSplitBin->hLc3plusEnc->config.lc3plus_frame_duration_us / 1000 ); pBits->isar_frame_size_ms = (Word16) ( hSplitBin->hLc3plusEnc->config.isar_frame_duration_us / 1000 ); + pBits->lc3plus_highres = hSplitBin->hLc3plusEnc->config.high_res_mode_enabled; return IVAS_ERR_OK; } @@ -2914,11 +2877,9 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( UWord8 useLc3plus; Word32 *in_delayed_fx[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; Word16 i; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word16 j; Word32 *p_Cldfb_In_BinReal[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; Word32 *p_Cldfb_In_BinImag[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; -#endif Word32 num_slots; push_wmops( "isar_renderMultiTDBinToSplitBinaural" ); @@ -2928,7 +2889,6 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( useLc3plus = hSplitBin->hLc3plusEnc != NULL; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { FOR( j = 0; j < CLDFB_NO_COL_MAX; ++j ) @@ -2937,7 +2897,6 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( p_Cldfb_In_BinImag[i][j] = Cldfb_In_BinImag_fx[i][j]; } } -#endif IF( useLc3plus ) { @@ -3034,11 +2993,7 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( // target_md_bits = isar_get_split_rend_md_target_brate( SplitRendBitRate, pcm_out_flag ) * L_FRAME48k / 48000; target_md_bits = W_extract_l( W_mult0_32_32( isar_get_split_rend_md_target_brate( SplitRendBitRate, pcm_out_flag ), L_FRAME48k ) ); tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( target_md_bits, 48000, &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( target_md_bits, 48000, &tmp_e ); -#endif target_md_bits = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 /*scaling to max Q*/ @@ -3046,11 +3001,7 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( move32(); FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; i++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#else - FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#endif { scale_factor = s_min( scale_factor, s_min( getScaleFactor32( Cldfb_In_BinReal_fx[i][j], CLDFB_NO_CHANNELS_MAX ), getScaleFactor32( Cldfb_In_BinImag_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ) ); } @@ -3058,11 +3009,7 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( scale_factor = sub( scale_factor, 2 ); FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; i++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#else - FOR( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#endif { Scale_sig32( Cldfb_In_BinReal_fx[i][j], CLDFB_NO_CHANNELS_MAX, scale_factor ); Scale_sig32( Cldfb_In_BinImag_fx[i][j], CLDFB_NO_CHANNELS_MAX, scale_factor ); @@ -3071,21 +3018,15 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( q_final = add( q_final, scale_factor ); Word16 exp_cldfb_re = sub( 31, q_final ); Word16 exp_cldfb_im = sub( 31, q_final ); + isar_rend_CldfbSplitPreRendProcess( hSplitBin->hBinHrSplitPreRend, headPosition, &hSplitBin->multiBinPoseData, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP p_Cldfb_In_BinReal, exp_cldfb_re, p_Cldfb_In_BinImag, exp_cldfb_im, -#else - Cldfb_In_BinReal_fx, - exp_cldfb_re, - Cldfb_In_BinImag_fx, - exp_cldfb_im, -#endif pBits, target_md_bits, low_res_pre_rend_rot, @@ -3102,26 +3043,18 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( // available_bits = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); available_bits = W_extract_l( W_mult0_32_32( SplitRendBitRate, L_mult0( hSplitBin->hSplitBinLCLDEnc->iNumBlocks, hSplitBin->hSplitBinLCLDEnc->iNumIterations ) ) ); tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( available_bits, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( available_bits, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#endif available_bits = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 available_bits = L_sub( available_bits, pBits->bits_written ); pBits->codec_frame_size_ms = codec_frame_size_ms; move16(); pBits->isar_frame_size_ms = isar_frame_size_ms; move16(); + isar_splitBinLCLDEncProcess( hSplitBin->hSplitBinLCLDEnc, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP p_Cldfb_In_BinReal, p_Cldfb_In_BinImag, -#else - Cldfb_In_BinReal_fx, - Cldfb_In_BinImag_fx, -#endif available_bits, pBits, &q_final ); @@ -3162,14 +3095,9 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( IF( !useLc3plus ) { // bit_len = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); - bit_len = W_extract_l( W_mult0_32_32( SplitRendBitRate, L_mult0( hSplitBin->hSplitBinLCLDEnc->iNumBlocks, hSplitBin->hSplitBinLCLDEnc->iNumIterations ) ) ); tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( bit_len, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( bit_len, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#endif bit_len = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 } ELSE @@ -3180,11 +3108,7 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( // bit_len = hSplitBin->hLc3plusEnc->config.ivas_frame_duration_us / 1000; // bit_len = SplitRendBitRate * bit_len / 1000; tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( W_extract_l( W_mult0_32_32( SplitRendBitRate, bit_len ) ), 1000, &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( W_extract_l( W_mult0_32_32( SplitRendBitRate, bit_len ) ), 1000, &tmp_e ); -#endif bit_len = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 } } @@ -3208,14 +3132,9 @@ ivas_error isar_renderMultiTDBinToSplitBinaural( *------------------------------------------------------------------------*/ void lc3plusTimeAlignCldfbPoseCorr( - SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renderer handle */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + SPLIT_REND_WRAPPER *hSplitBin, /* i/o: Split renderer pre-renderer handle */ Word32 *Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, real part */ Word32 *Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX], /* i/o: Binaural signals, imag. part */ -#else - Word32 Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: Binaural signals, real part */ - Word32 Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: Binaural signals, imag. part */ -#endif Word16 *Q_in ) { Word32 Cldfb_In_BinReal_tmp_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][2][CLDFB_NO_CHANNELS_MAX]; @@ -3235,11 +3154,7 @@ void lc3plusTimeAlignCldfbPoseCorr( } ELSE { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( Word16 i = 0; i < i_mult( hSplitBin->multiBinPoseData.num_poses, BINAURAL_CHANNELS ); i++ ) -#else - FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ ) -#endif { for ( Word16 j = 0; j < CLDFB_NO_COL_MAX; j++ ) 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 4576e7c1ddac64c7f7ecb40510cc765f6b4c92ec..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 @@ -242,7 +242,6 @@ typedef struct } ISAR_SPLIT_POST_REND_WRAPPER; - typedef struct { MULTI_BIN_REND_POSE_DATA multiBinPoseData; @@ -256,7 +255,6 @@ typedef struct Word32 lc3plusDelaySamples; } SPLIT_REND_WRAPPER; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP typedef struct { Word32 *real; @@ -267,6 +265,5 @@ typedef struct Word16 is_full; } ISAR_CLDFB_RINGBUF, *ISAR_CLDFB_RINGBUF_HANDLE; -#endif #endif /* ISAR_STAT_H */ 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 ae32791dd8fba0c9b1fd5e492ef564bfd5e66a74..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 */ ) { @@ -203,7 +203,7 @@ void ISAR_PRE_REND_close( { IF( hSplitBinRend->hCldfbHandles->cldfbAna[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitBinRend->hCldfbHandles->cldfbAna[ch] ); + deleteCldfb_fx( &hSplitBinRend->hCldfbHandles->cldfbAna[ch] ); hSplitBinRend->hCldfbHandles->cldfbAna[ch] = NULL; } } @@ -212,7 +212,7 @@ void ISAR_PRE_REND_close( { IF( hSplitBinRend->hCldfbHandles->cldfbSyn[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitBinRend->hCldfbHandles->cldfbSyn[ch] ); + deleteCldfb_fx( &hSplitBinRend->hCldfbHandles->cldfbSyn[ch] ); hSplitBinRend->hCldfbHandles->cldfbSyn[ch] = NULL; } } @@ -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,26 +277,21 @@ 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, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + 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 */ -#else - Word32 Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], -#endif - const Word16 max_bands, /* i : CLDFB bands */ - Word32 *pOutput_fx[], /* i/o: PCM in/out buffer */ - 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 domain 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 */ + const Word16 max_bands, /* i : CLDFB bands */ + Word32 *pOutput_fx[], /* i/o: PCM in/out buffer */ + 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 domain 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 ) { @@ -304,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; @@ -380,18 +376,14 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( // available_bits = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); available_bits = W_extract_l( W_mult0_32_32( SplitRendBitRate, L_mult0( hSplitBin->hSplitBinLCLDEnc->iNumBlocks, hSplitBin->hSplitBinLCLDEnc->iNumIterations ) ) ); tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( available_bits, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( available_bits, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#endif available_bits = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 available_bits = L_sub( available_bits, pBits->bits_written ); pBits->codec_frame_size_ms = codec_frame_size_ms; q_final = sub( s_min( Q_buff_re, Q_buff_im ), 2 ); FOR( i = 0; i < hSplitBin->hSplitBinLCLDEnc->iChannels; i++ ) { - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) + FOR( j = 0; j < hSplitBin->hSplitBinLCLDEnc->iNumBlocks; j++ ) { Scale_sig32( Cldfb_In_BinReal_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( q_final, Q_buff_re ) ); Scale_sig32( Cldfb_In_BinImag_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( q_final, Q_buff_im ) ); @@ -423,11 +415,7 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( move16(); FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( j = 0; j < num_slots; j++ ) -#else - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#endif { q1 = s_min( getScaleFactor32( Cldfb_In_BinReal_fx[ch][j], CLDFB_NO_CHANNELS_MAX ), q1 ); q2 = s_min( getScaleFactor32( Cldfb_In_BinImag_fx[ch][j], CLDFB_NO_CHANNELS_MAX ), q2 ); @@ -441,11 +429,7 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( j = 0; j < num_slots; j++ ) -#else - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#endif { Scale_sig32( Cldfb_In_BinReal_fx[ch][j], CLDFB_NO_CHANNELS_MAX, sub( q_final, Q_buff_re ) ); Scale_sig32( Cldfb_In_BinImag_fx[ch][j], CLDFB_NO_CHANNELS_MAX, sub( q_final, Q_buff_im ) ); @@ -508,11 +492,7 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( move16(); q2 = 31; move16(); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( j = 0; j < num_slots; j++ ) -#else - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#endif { q1 = s_min( getScaleFactor32( Cldfb_In_BinReal_fx[ch][j], CLDFB_NO_CHANNELS_MAX ), q1 ); q2 = s_min( getScaleFactor32( Cldfb_In_BinImag_fx[ch][j], CLDFB_NO_CHANNELS_MAX ), q2 ); @@ -521,11 +501,7 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( q_final = s_min( add( Q_buff_re, q_final ), add( Q_buff_im, q_final ) ); q_final = sub( q_final, 6 ); // guard bits q_final = s_min( q_final, Q25 ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( j = 0; j < num_slots; j++ ) -#else - FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ ) -#endif { Scale_sig32( Cldfb_In_BinReal_fx[ch][j], CLDFB_NO_CHANNELS_MAX, sub( q_final, Q_buff_re ) ); Scale_sig32( Cldfb_In_BinImag_fx[ch][j], CLDFB_NO_CHANNELS_MAX, sub( q_final, Q_buff_im ) ); @@ -566,14 +542,9 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( IF( splitCodec == ISAR_SPLIT_REND_CODEC_LCLD ) { // bit_len = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); - bit_len = W_extract_l( W_mult0_32_32( SplitRendBitRate, L_mult0( hSplitBin->hSplitBinLCLDEnc->iNumBlocks, hSplitBin->hSplitBinLCLDEnc->iNumIterations ) ) ); tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( bit_len, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( bit_len, L_mult0( 16, FRAMES_PER_SEC ), &tmp_e ); -#endif bit_len = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 } ELSE @@ -584,11 +555,7 @@ ivas_error ISAR_PRE_REND_MultiBinToSplitBinaural( // bit_len = hSplitBin->hLc3plusEnc->config.ivas_frame_duration_us / 1000; // bit_len = SplitRendBitRate * bit_len / 1000; tmp_e = 0; -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - tmp_32 = BASOP_Util_Divide3232_Scale_cadence( W_extract_l( W_mult0_32_32( SplitRendBitRate, bit_len ) ), 1000, &tmp_e ); -#else tmp_32 = BASOP_Util_Divide3232_Scale_newton( W_extract_l( W_mult0_32_32( SplitRendBitRate, bit_len ) ), 1000, &tmp_e ); -#endif bit_len = L_shr( tmp_32, sub( 31, tmp_e ) ); // Q0 } } diff --git a/lib_isar/lib_isar_pre_rend.h b/lib_isar/lib_isar_pre_rend.h index 9ee1aae8696f2c27b3b2960c575d2c1f82b1a7d8..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,47 +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 */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - 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 */ -#else - Word32 Cldfb_In_BinReal_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: CLDFB real buffer */ - Word32 Cldfb_In_BinImag_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: CLDFB imag buffer */ -#endif - 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 70e288ba31ad46a3f8ab5fa3535d4d8da892973d..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 /*----------------------------------------------------------------------------------* @@ -543,7 +543,7 @@ return IVAS_ERR_OK; ivas_error ivas_allocate_binaural_hrtf_fx( HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ - const int16_t n_channels, /* i : number of input channels */ + const Word16 n_channels, /* i : number of input channels */ const Word16 allocate_init_flag /* i : Memory allocation flag */ ) { @@ -1235,6 +1235,7 @@ ivas_error ivas_binRenderer_open_fx( IF( hBinRenderer->hReverb != NULL && NE_16( hBinRenderer->nInChannels, HOA3_CHANNELS ) ) { + test(); test(); test(); IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) @@ -1245,7 +1246,7 @@ ivas_error ivas_binRenderer_open_fx( // Q29: hBinRenderer->hReverb->foa_enc_fx[k] } } - ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) ) { IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { diff --git a/lib_rend/ivas_cldfb_ring_buffer.c b/lib_rend/ivas_cldfb_ring_buffer.c index 49d88e8f31479242a234ffa95585e56425e45f16..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,16 +32,16 @@ #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" #endif #include "wmc_auto.h" -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + /*---------------------------------------------------------------------* * CLDFB ring-buffer functions needed in split-rendering outputs *---------------------------------------------------------------------*/ @@ -318,4 +318,3 @@ void ivas_CLDFB_RINGBUF_GetByIdx( return; } -#endif diff --git a/lib_rend/ivas_crend_fx.c b/lib_rend/ivas_crend_fx.c index 9c3379527d84ee278052b0ce8099af94674a623c..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; @@ -1862,7 +1864,7 @@ static ivas_error ivas_rend_crendConvolver_fx( } /* subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; */ - subframe_length = extract_l( Mpy_32_32_r( output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); + subframe_length = extract_l( Mpy_32_16_1( output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); lfe_idx_in = -1; move16(); @@ -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 37150a6da69944f8f5e14d50816bcb9ca0bf8ffc..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 @@ -196,7 +196,7 @@ void ivas_dirac_ana_close_fx( FOR( i = 0; i < ( *hDirAC )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hDirAC )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hDirAC )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -255,16 +255,15 @@ void ivas_dirac_ana_fx( Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + /* Estimate MASA parameters from the SBA signals */ ivas_dirac_param_est_ana_fx( hDirAC, data_fx, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, input_frame, data_q ); -#ifdef NONBE_1344_REND_MASA_LOW_FS /* Add zeros to higher bands in case of lower sampling rates */ IF( LT_16( hDirAC->nbands, MASA_FREQUENCY_BANDS ) ) { ivas_masa_zero_high_bands_fx( hDirAC->nbands, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx ); } -#endif /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta_fx( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 3211b0e46fcb0b5844447e2e1ec4d87fa18b6bcf..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 ); /*------------------------------------------------------------------------- @@ -371,7 +372,6 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( Word16 nchan_to_allocate; Word16 n_samples_granularity; -#ifdef FIX_NCHAN_BUFFERS nchan_to_allocate = BINAURAL_CHANNELS; move16(); IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) @@ -383,18 +383,14 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( { nchan_to_allocate = add( nchan_to_allocate, 1 ); } -#else - nchan_to_allocate = 2 * BINAURAL_CHANNELS; - move16(); -#endif if ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { 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; } @@ -517,21 +513,13 @@ void ivas_dirac_dec_binaural_render_fx( UWord16 nchan_out; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word32 *output_fx_local[MAX_OUTPUT_CHANNELS]; -#ifndef FIX_RENDERER_STACK - Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word16 output_length; -#endif hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_out = BINAURAL_CHANNELS; move16(); FOR( ch = 0; ch < nchan_out; ch++ ) { -#ifdef FIX_RENDERER_STACK output_fx_local[ch] = output_fx[ch]; -#else - output_fx_local[ch] = output_fx_local_buff[ch]; -#endif } slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); @@ -550,10 +538,6 @@ void ivas_dirac_dec_binaural_render_fx( last_sf = add( last_sf, 1 ); } -#ifndef FIX_RENDERER_STACK - output_length = 0; - move16(); -#endif FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { n_samples_sf = imult1616( slot_size, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); @@ -565,19 +549,10 @@ void ivas_dirac_dec_binaural_render_fx( output_fx_local[ch] += n_samples_sf; } -#ifndef FIX_RENDERER_STACK - output_length = add( output_length, n_samples_sf ); -#endif /* update combined orientation access index */ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } -#ifndef FIX_RENDERER_STACK - FOR( ch = 0; ch < nchan_out; ch++ ) - { - Copy32( output_fx_local_buff[ch], output_fx[ch], output_length ); - } -#endif IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) { hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; @@ -1091,12 +1066,7 @@ static void ivas_dirac_dec_binaural_internal_fx( { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe]; i++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[ch], tmp_Cldfb_out_re[ch][i], tmp_Cldfb_out_im[ch][i], CLDFB_NO_CHANNELS_MAX ); -#else - Copy32( tmp_Cldfb_out_re[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); - Copy32( tmp_Cldfb_out_im[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); -#endif } } } @@ -1155,21 +1125,9 @@ static void ivas_dirac_dec_binaural_internal_fx( Copy( st_ivas->hDiracDecBin[0]->ChCrossRe_e, hDiracDecBin->ChCrossRe_e, hSpatParamRendCom->num_freq_bands ); Copy( st_ivas->hDiracDecBin[0]->ChCrossIm_e, hDiracDecBin->ChCrossIm_e, hSpatParamRendCom->num_freq_bands ); - ivas_dirac_dec_binaural_formulate_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Rmat_local, subframe, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, -#else - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, -#endif - subFrameTotalEne_fx, subFrameTotalEne_e, IIReneLimiter_fx, st_ivas->hMasaIsmData ); + ivas_dirac_dec_binaural_formulate_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Rmat_local, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, subFrameTotalEne_fx, subFrameTotalEne_e, IIReneLimiter_fx, st_ivas->hMasaIsmData ); - ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_local, subframe, -#ifdef FIX_1119_SPLIT_RENDERING_VOIP - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, -#else - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, -#endif - nchanSeparateChannels, st_ivas->hMasaIsmData ); + ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_local, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); q_mat = hDiracDecBin->q_processMtx; move16(); @@ -1216,12 +1174,7 @@ static void ivas_dirac_dec_binaural_internal_fx( { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe]; i++ ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_CLDFB_RINGBUF_Push( st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch], tmp_Cldfb_out_re[ch][i], tmp_Cldfb_out_im[ch][i], CLDFB_NO_CHANNELS_MAX ); -#else - Copy32( tmp_Cldfb_out_re[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[pos_idx * BINAURAL_CHANNELS + ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); - Copy32( tmp_Cldfb_out_im[ch][i], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[pos_idx * BINAURAL_CHANNELS + ch][hSpatParamRendCom->slots_rendered + i], CLDFB_NO_CHANNELS_MAX ); -#endif } } @@ -1516,11 +1469,7 @@ static void ivas_dirac_dec_binaural_formulate_input_covariance_matrices_fx( move16(); den = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChEnePrev_fx[0][bin], hDiracDecBin->ChEnePrev_e[0][bin], hDiracDecBin->ChEnePrev_fx[1][bin], hDiracDecBin->ChEnePrev_e[1][bin], &den_e ); den = L_max( 1, den ); -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - IIReneLimiter_fx[bin] = BASOP_Util_Divide3232_Scale_cadence( num, den, &exp ); -#else IIReneLimiter_fx[bin] = BASOP_Util_Divide3232_Scale_newton( num, den, &exp ); -#endif exp = add( sub( num_e, den_e ), add( 5, exp ) ); IF( L_shr_sat( IIReneLimiter_fx[bin], sub( 31, exp ) ) > 0 ) { @@ -2022,11 +1971,7 @@ static void ivas_dirac_dec_binaural_formulate_target_covariance_matrices_fx( move32(); /* Formulate average diffuseness over frame */ -#ifndef REMOVE_BASOP_Util_Divide3232_Scale_cadence - frameMeanDiffuseness = BASOP_Util_Divide3232_Scale_cadence( frameMeanDiffuseness, L_max( EPSILLON_FX, frameMeanDiffusenessEneWeight_fx[bin] ), &exp ); // exp = exp + 31 - q_meanEnePerCh - exp1 -#else frameMeanDiffuseness = BASOP_Util_Divide3232_Scale_newton( frameMeanDiffuseness, L_max( EPSILLON_FX, frameMeanDiffusenessEneWeight_fx[bin] ), &exp ); // exp = exp + 31 - q_meanEnePerCh - exp1 -#endif exp = sub( exp, sub( sub( 31, q_meanEnePerCh ), exp1 ) ); hDiracDecBin->frameMeanDiffuseness_fx[bin] = L_shl( frameMeanDiffuseness, sub( exp, 2 ) ); // Q29 move32(); @@ -2284,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 @@ -2968,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 @@ -2986,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 @@ -2994,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(); } @@ -3518,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*/ @@ -3532,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 ); @@ -3569,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; } @@ -3913,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++ ) { @@ -3923,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*/ @@ -3950,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++ ) { @@ -3991,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(); @@ -4017,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 ) - 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 ) ) + 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(); - 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 ) - 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 ) ) + 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(); - 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(); @@ -4083,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++ ) @@ -4136,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; } @@ -4647,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 @@ -4704,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 ); @@ -4767,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 ) @@ -4901,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; } @@ -5859,7 +5745,6 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( move16(); move16(); -#ifdef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES totalTargetEneCh[0] = subframeEneCh[0]; // subQch[0] move32(); totalTargetEneCh[1] = subframeEneCh[1]; // subQch[1] @@ -5868,20 +5753,6 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( move32(); masaEneThisCh[1] = subframeEneCh[1]; // subQch[1] move32(); -#else - /* Zero check */ - IF( GT_32( subframeEne, 0 ) ) - { - totalTargetEneCh[0] = subframeEneCh[0]; // subQch[0] - move32(); - totalTargetEneCh[1] = subframeEneCh[1]; // subQch[1] - move32(); - masaEneThisCh[0] = subframeEneCh[0]; // subQch[0] - move32(); - masaEneThisCh[1] = subframeEneCh[1]; // subQch[1] - move32(); - } -#endif /* Gain editing */ /* For each object, estimate new target energy per channel based on the applied gain */ @@ -6016,14 +5887,11 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( } } - -#ifdef NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES /* Limit target energies to non-negative values */ FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { totalTargetEneCh[ch] = L_max( 0, totalTargetEneCh[ch] ); } -#endif /* due to rounding, the sum may exceed 1.0f ever so slightly, so clip it */ ratioAccOrig = L_min( ratioAccOrig, ONE_IN_Q30 ); @@ -6122,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 ) ) ); @@ -6155,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++ ) { @@ -6385,12 +6253,8 @@ void ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( { temp = BASOP_Util_Divide3232_Scale_newton( hMasaIsmData->preprocEneTarget_fx[band_idx], L_max( 1, hMasaIsmData->preprocEneRealized_fx[band_idx] ), &temp_q ); temp_q = sub( Q31, sub( sub( Q31, temp_q ), sub( hMasaIsmData->preprocEneTarget_e[band_idx], hMasaIsmData->preprocEneRealized_e[band_idx] ) ) ); - temp = Sqrt32( temp, &temp_q ); // Q: 31-temp_q -#ifdef FIX_2164_ASSERT_IN_OMASA_PREPROC_FOR_EDIT + temp = Sqrt32( temp, &temp_q ); // Q: 31-temp_q temp = L_shl_sat( temp, sub( temp_q, 3 ) ); // Q28 -#else - temp = L_shl( temp, sub( temp_q, 3 ) ); // Q28 -#endif temp_q = Q28; move16(); } @@ -6745,14 +6609,13 @@ static void ivas_masa_ext_rend_parambin_internal_fx( Copy( hMasaExtRend->hDiracDecBin[0]->ChCrossIm_e, hDiracDecBin->ChCrossIm_e, hSpatParamRendCom->num_freq_bands ); ivas_dirac_dec_binaural_formulate_target_covariance_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, Rmat_local, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, subFrameTotalEne_fx, subFrameTotalEne_e, IIReneLimiter_fx, NULL ); ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_local, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, 0, NULL ); - q_mat = hDiracDecBin->q_processMtx; move16(); q_mat = s_min( q_mat, hDiracDecBin->q_processMtxPrev ); @@ -6787,6 +6650,7 @@ static void ivas_masa_ext_rend_parambin_internal_fx( move16(); move16(); move16(); + /* re-use reverb and decorr from main direction for the sides */ ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, hMasaExtRend->cldfbSynRend, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, max_band_decorr, numInChannels, config_data.processReverb, subframe, q_mat, tmp_Cldfb_out_re, tmp_Cldfb_out_im, reverbRe_fx, reverbIm_fx, decorrRe_fx, decorrIm_fx, &Q_inp_mix, 0 ); 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 8bc3c037980dc68ea0f0efb65cd69a47a63d27bc..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 */ @@ -55,19 +54,17 @@ ivas_error ivas_HRTF_binary_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary!" ); } - set_c( (int8_t *) ( *hHrtfTD ), 0, (int32_t) sizeof( TDREND_HRFILT_FiltSet_t ) ); + set_c( (Word8 *) ( *hHrtfTD ), 0, (Word32) sizeof( TDREND_HRFILT_FiltSet_t ) ); 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 *-----------------------------------------------------------------------*/ @@ -246,14 +394,14 @@ ivas_error ivas_HRTF_parambin_binary_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for parametric binauralizer HRTF tables!" ); } - set_c( (int8_t *) ( *hHrtfParambin ), 0, (int32_t) sizeof( HRTFS_PARAMBIN ) ); + set_c( (Word8 *) ( *hHrtfParambin ), 0, (Word32) sizeof( HRTFS_PARAMBIN ) ); return IVAS_ERR_OK; } /*-----------------------------------------------------------------------* - * 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 144953e2672c93f199b87325e32c35ab7e9f3065..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,18 +30,15 @@ *******************************************************************************************************/ -#include #include "options.h" -#include "lib_rend.h" #include "ivas_prot_rend_fx.h" #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" -#ifdef NONBE_1344_REND_MASA_LOW_FS #include "ivas_rom_com.h" -#endif #include "ivas_prot_fx.h" + #define INV_UINT8_MAX 8421505 /* 1/UINT8_MAX in Q31 */ /*---------------------------------------------------------------------* @@ -490,9 +487,7 @@ ivas_error masaPrerendOpen_fx( { MASA_PREREND_HANDLE hMasaPrerend; Word16 i; -#ifdef NONBE_1344_REND_MASA_LOW_FS Word16 maxBin; -#endif ivas_error error; error = IVAS_ERR_OK; @@ -504,7 +499,6 @@ ivas_error masaPrerendOpen_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA prerenderer\n" ) ); } -#ifdef NONBE_1344_REND_MASA_LOW_FS /* Determine the number of bands and band grouping */ hMasaPrerend->nbands = MASA_FREQUENCY_BANDS; move16(); @@ -522,7 +516,6 @@ ivas_error masaPrerendOpen_fx( break; } } -#endif hMasaPrerend->num_Cldfb_instances = numTransports; move16(); @@ -577,7 +570,7 @@ void masaPrerendClose_fx( FOR( i = 0; i < ( *hMasaPrerendPtr )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); } free( ( *hMasaPrerendPtr )->hMasaOut ); diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index 2f607a7b33a956353a3d89d8ef82ede82edd84c7..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 */ /*------------------------------------------------------------------------- @@ -414,7 +411,7 @@ void ivas_mcmasa_ana_close( FOR( i = 0; i < ( *hMcMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); } /* intensity 3-dim */ @@ -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++ ) @@ -486,13 +492,11 @@ void ivas_mcmasa_ana_fx( /* Analysis */ ivas_mcmasa_param_est_ana_fx( hMcMasa, data, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, q_data, input_frame, nchan_inp ); -#ifdef NONBE_1344_REND_MASA_LOW_FS /* Add zeros to higher bands in case of lower sampling rates */ IF( LT_16( hMcMasa->nbands, MASA_FREQUENCY_BANDS ) ) { ivas_masa_zero_high_bands_fx( hMcMasa->nbands, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx ); } -#endif /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta_fx( hMcMasa->hMasaOut, hMcMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); @@ -1713,7 +1717,6 @@ void ivas_create_masa_out_meta_fx( } -#ifdef NONBE_1344_REND_MASA_LOW_FS /*------------------------------------------------------------------------- * ivas_masa_zero_high_bands() * @@ -1750,4 +1753,3 @@ void ivas_masa_zero_high_bands_fx( return; } -#endif diff --git a/lib_rend/ivas_objectRenderer_fx.c b/lib_rend/ivas_objectRenderer_fx.c index c2e6b73fc6ec8a2bb5d0e44e309f347fd6ae550e..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 ) @@ -631,16 +632,10 @@ ivas_error TDREND_Update_object_positions_fx( const ISM_METADATA_HANDLE *hIsmMetaData /* i : Input metadata for ISM objects */ ) { -#ifndef NONBE_1377_REND_DIRATT_CONF - TDREND_DirAtten_t *DirAtten_p; -#endif Word16 nS; Word32 Pos_fx[3]; // Q25 Word32 Dir_fx[3]; // Q30 ivas_error error; -#ifndef NONBE_1377_REND_DIRATT_CONF - DirAtten_p = hBinRendererTd->DirAtten_p; -#endif /* For each source, write the frame data to the source object*/ FOR( nS = 0; nS < num_src; nS++ ) @@ -665,12 +660,6 @@ ivas_error TDREND_Update_object_positions_fx( { return error; } -#ifndef NONBE_1377_REND_DIRATT_CONF - IF( NE_32( ( error = TDREND_MIX_SRC_SetDirAtten_fx( hBinRendererTd, nS, DirAtten_p ) ), IVAS_ERR_OK ) ) - { - return error; - } -#endif if ( ( error = TDREND_MIX_SRC_SetGain( hBinRendererTd, nS, hIsmMetaData[nS]->gain_fx ) ) != IVAS_ERR_OK ) // TODO: Check Gain has correct Q-value { return error; @@ -825,9 +814,7 @@ ivas_error ivas_td_binaural_open_ext_fx( RENDER_CONFIG_DATA *hRendCfg, /* i : Renderer configuration */ LSSETUP_CUSTOM_STRUCT *customLsInput, const Word32 outFs, -#ifdef NONBE_1377_REND_DIRATT_CONF const Word16 object_id, /* i: Object ID */ -#endif Word16 *SrcInd, Word16 *num_src ) { @@ -877,11 +864,7 @@ ivas_error ivas_td_binaural_open_ext_fx( if ( NULL != hRendCfg ) { -#ifdef NONBE_1377_REND_DIRATT_CONF directivity_fx = hRendCfg->directivity_fx + 3 * object_id; /* Address calculation -- no BASOPs */ -#else - directivity_fx = hRendCfg->directivity_fx; -#endif distAtt_fx = hRendCfg->distAtt_fx; } @@ -911,7 +894,7 @@ ivas_error ivas_td_binaural_renderer_ext_fx( { ISM_METADATA_FRAME hIsmMetaDataFrame; ISM_METADATA_HANDLE hIsmMetaData[1]; - Word16 lfe_idx, exp_tmp; + Word16 lfe_idx, tmp, exp_tmp; Word16 num_src; IVAS_FORMAT ivas_format; IVAS_REND_AudioConfigType inConfigType; @@ -986,11 +969,10 @@ ivas_error ivas_td_binaural_renderer_ext_fx( move16(); } - Word16 num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( output_frame, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs, &exp_tmp ); - IF( sub( 15, exp_tmp ) ) - { - num_subframes = shr( num_subframes, sub( 15, exp_tmp ) ); - } + tmp = extract_l( Mpy_32_16_1( output_Fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + tmp = BASOP_Util_Divide1616_Scale( output_frame, tmp, &exp_tmp ); + Word16 num_subframes = shr( tmp, sub( 15, exp_tmp ) ); /* Q0 */ + FOR( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { Word16 idx = subframe_idx; 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 7e73a0f605b4759938ed3c7ff8b892239a3d4497..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,13 +40,13 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" + /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ - static void ivas_omasa_dmx_fx( - Word32 data_in_f_fx[][L_FRAME48k], + Word32 data_in_fx[][L_FRAME48k], Word16 *data_in_q, const Word16 input_frame, const Word16 nchan_transport, @@ -57,7 +56,6 @@ static void ivas_omasa_dmx_fx( Word32 prev_gains_fx[][MASA_MAX_TRANSPORT_CHANNELS], const Word16 interpolator_fx[L_FRAME48k] ); - static void ivas_omasa_param_est_ana_fx( OMASA_ANA_HANDLE hOMasa, Word32 data_f_fx[][L_FRAME48k], @@ -73,6 +71,7 @@ static void ivas_omasa_param_est_ana_fx( const Word16 input_frame, const Word16 nchan_ism ); + /*--------------------------------------------------------------------------* * ivas_omasa_ana_open() * @@ -251,7 +250,7 @@ void ivas_omasa_ana_close( FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -292,20 +291,20 @@ void ivas_omasa_ana_close( return; } + /*--------------------------------------------------------------------------* * ivas_omasa_ana() * * OMASA analysis function *--------------------------------------------------------------------------*/ - void ivas_omasa_ana_fx( - OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ - Word32 data_in_f_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ - Word16 *data_in_q, - const Word16 input_frame, /* i : Input frame size */ - const Word16 nchan_transport, /* i : Number of transport channels */ - const Word16 nchan_ism /* i : Number of objects for parameter analysis */ + OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ + Word32 data_in_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ + Word16 *data_in_q, /* o : audio signals Q factor */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_transport, /* i : Number of transport channels */ + const Word16 nchan_ism /* i : Number of objects for parameter analysis */ ) { Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; @@ -316,21 +315,19 @@ void ivas_omasa_ana_fx( Word16 spreadCoherence_q, sorroundingCoherence_q, energyRatio_q; /* Estimate MASA parameters from the objects */ - ivas_omasa_param_est_ana_fx( hOMasa, data_in_f_fx, *data_in_q, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, &energyRatio_q, spreadCoherence_fx, &spreadCoherence_q, surroundingCoherence_fx, &sorroundingCoherence_q, input_frame, nchan_ism ); + ivas_omasa_param_est_ana_fx( hOMasa, data_in_fx, *data_in_q, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, &energyRatio_q, spreadCoherence_fx, &spreadCoherence_q, surroundingCoherence_fx, &sorroundingCoherence_q, input_frame, nchan_ism ); -#ifdef NONBE_1344_REND_MASA_LOW_FS /* Add zeros to higher bands in case of lower sampling rates */ IF( LT_16( hOMasa->nbands, MASA_FREQUENCY_BANDS ) ) { ivas_masa_zero_high_bands_fx( hOMasa->nbands, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx ); } -#endif /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta_fx( hOMasa->hMasaOut, hOMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); /* Downmix */ - ivas_omasa_dmx_fx( data_in_f_fx, data_in_q, input_frame, nchan_transport, nchan_ism, hOMasa->ism_azimuth_fx, hOMasa->ism_elevation_fx, hOMasa->prev_object_dm_gains_fx, hOMasa->interpolator_fx ); + ivas_omasa_dmx_fx( data_in_fx, data_in_q, input_frame, nchan_transport, nchan_ism, hOMasa->ism_azimuth_fx, hOMasa->ism_elevation_fx, hOMasa->prev_object_dm_gains_fx, hOMasa->interpolator_fx ); return; } @@ -341,8 +338,6 @@ void ivas_omasa_ana_fx( *--------------------------------------------------------------------------*/ /* Estimate MASA parameters from the objects */ - - static void ivas_omasa_param_est_ana_fx( OMASA_ANA_HANDLE hOMasa, Word32 data_f_fx[][L_FRAME48k], @@ -651,7 +646,7 @@ static void ivas_omasa_param_est_ana_fx( /* Compute downmix */ static void ivas_omasa_dmx_fx( - Word32 data_in_f_fx[][L_FRAME48k], + Word32 data_in_fx[][L_FRAME48k], Word16 *data_in_q, const Word16 input_frame, const Word16 nchan_transport, @@ -676,18 +671,15 @@ static void ivas_omasa_dmx_fx( } set16_fx( data_e, 0, 4 ); set16_fx( in_e, 0, 960 ); -#ifdef NONBE_1362_FIX_OMASA_TO_MASA1_RENDERING max_e = 0; -#endif FOR( i = 0; i < nchan_ism; i++ ) { -#ifdef NONBE_1362_FIX_OMASA_TO_MASA1_RENDERING IF( EQ_16( nchan_transport, 1 ) ) { FOR( j = 0; j < input_frame; j++ ) { - data_out_f_fx[0][j] = L_add_sat( data_out_f_fx[0][j], data_in_f_fx[i][j] ); + data_out_f_fx[0][j] = L_add_sat( data_out_f_fx[0][j], data_in_fx[i][j] ); move32(); } } @@ -714,7 +706,7 @@ static void ivas_omasa_dmx_fx( tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); // Q: ( ( ( 15 - scale ) + ( Q31 - Q16 ) ) - Q15 ) -> ( 15 - scale ) scale = BASOP_Util_Add_MantExp( tmp1, 0, tmp2, scale, &tmp1 ); - L_tmp = data_in_f_fx[i][k]; // data_in_q + L_tmp = data_in_fx[i][k]; // data_in_q move32(); tmp_e = sub( 31, *data_in_q ); move16(); @@ -727,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] ) ) { @@ -736,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(); @@ -749,66 +741,8 @@ static void ivas_omasa_dmx_fx( move32(); } } -#else - azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); // Q0 - elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); // Q0 - - ivas_ism_get_stereo_gains_fx( azimuth_fx, elevation_fx, &gains_fx[0], &gains_fx[1] ); - - /* Downmix using the panning gains */ - FOR( j = 0; j < nchan_transport; j++ ) - { - test(); - IF( abs_s( gains_fx[j] ) > 0 || L_abs( prev_gains_fx[i][j] ) > 0 ) - { - FOR( k = 0; k < input_frame; k++ ) - { - g1_fx = interpolator_fx[k]; // Q15 - move16(); - scale = BASOP_Util_Add_MantExp( 16384, 1, negate( g1_fx ), 0, &g2_fx ); - - tmp1 = mult( g1_fx, gains_fx[j] ); - tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); // Q: ( ( ( 15 - scale ) + ( Q31 - Q16 ) ) - Q15 ) -> ( 15 - scale ) - scale = BASOP_Util_Add_MantExp( tmp1, 0, tmp2, scale, &tmp1 ); - - L_tmp = data_in_f_fx[i][k]; // data_in_q - move32(); - tmp_e = sub( 31, *data_in_q ); - move16(); - - L_tmp = Mpy_32_16_1( L_tmp, tmp1 ); - scale = add( scale, tmp_e ); - - data_out_f_fx[j][k] = BASOP_Util_Add_Mant32Exp( data_out_f_fx[j][k], data_e[j], L_tmp, scale, &in_e[k] ); - move32(); - } - max_e = in_e[0]; - move16(); - FOR( l = 1; l < L_FRAME48k; l++ ) - { - IF( LT_16( max_e, in_e[l] ) ) - { - max_e = in_e[l]; - move16(); - } - } - - FOR( l = 0; l < L_FRAME48k; 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(); - } - data_e[j] = max_e; - move16(); - } - - prev_gains_fx[i][j] = L_deposit_h( gains_fx[j] ); // Q31 - move32(); - } -#endif } -#ifdef NONBE_1362_FIX_OMASA_TO_MASA1_RENDERING IF( NE_16( nchan_transport, 1 ) ) { max_e = data_e[0]; @@ -831,41 +765,15 @@ static void ivas_omasa_dmx_fx( } } } -#else - max_e = data_e[0]; - move16(); - FOR( i = 1; i < nchan_transport; i++ ) - { - IF( LT_16( max_e, data_e[i] ) ) - { - max_e = data_e[i]; - move16(); - } - } - - FOR( i = 0; i < nchan_transport; i++ ) - { - FOR( j = 0; j < input_frame; j++ ) - { - data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); // exponent: max_e, Q: ( 15 - max_e ) - move32(); - } - } -#endif FOR( i = 0; i < nchan_transport; i++ ) { - Copy32( data_out_f_fx[i], data_in_f_fx[i], input_frame ); -#ifdef NONBE_1362_FIX_OMASA_TO_MASA1_RENDERING + Copy32( data_out_f_fx[i], data_in_fx[i], input_frame ); IF( NE_16( nchan_transport, 1 ) ) { *data_in_q = sub( 31, max_e ); move16(); } -#else - *data_in_q = sub( 31, max_e ); - move16(); -#endif } return; diff --git a/lib_rend/ivas_orient_trk_fx.c b/lib_rend/ivas_orient_trk_fx.c index ee91e7060e252c6d06e9827ba3f2e5d353710038..00d7f7da8820c794a697261738aee027e42d0e55 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,13 @@ static Word32 VectorLength_fx( IVAS_VECTOR3 p, Word16 *q_fact ) { - 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 + 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 */ - *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); + result_fx = Sqrt32( result_fx, &sqrt_e ); + *q_fact = sub( 31, sqrt_e ); /* back to Q again */ move16(); return result_fx; } @@ -702,7 +704,10 @@ 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; + ELSE + { + pOTR->refRot = refRot; + } return IVAS_ERR_OK; } @@ -824,11 +829,8 @@ ivas_error ivas_orient_trk_SetReferenceVector_fx( return IVAS_ERR_WRONG_PARAMS; } - Word16 accoustic_q = acousticFrontVector.q_fact; - move16(); - acousticFrontVectorLength = VectorLength_fx( acousticFrontVector, &acousticFrontVector.q_fact ); - acousticFrontVector.q_fact = accoustic_q; - move16(); + Word16 tmp_q; + acousticFrontVectorLength = VectorLength_fx( acousticFrontVector, &tmp_q ); /* if the length is zero, the user has entered insensible listener and reference positions */ IF( LE_32( acousticFrontVectorLength, 0 ) ) { @@ -890,13 +892,15 @@ ivas_error ivas_orient_trk_Process_fx( pOTR->absAvgRot = absRot; Word16 scale_e; - Word32 div; - div = L_deposit_h( BASOP_Util_Divide3232_Scale( pOTR->centerAdaptationRate_fx, updateRate_fx, &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 */ - scale_e = sub( scale_e, 8 ); // e+e1-e2// - // here div value is less so we can use sandwitch rule of sine// - pOTR->alpha_fx = div; + /* sin(x) is approx x for small x */ + pOTR->alpha_fx = L_deposit_h( tmp ); move32(); + pOTR->Q_alpha = sub( Q31, scale_e ); + move16(); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse_fx( pOTR->refRot, &pOTR->trkRot ); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); @@ -950,6 +954,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 5969fac17a9c3759237d166a9b106069a66acc2b..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 @@ -318,11 +318,7 @@ Word16 ivas_get_nchan_buffers_dec_fx( output_config = st_ivas->hDecoderConfig->output_config; move16(); -#ifdef FIX_NCHAN_BUFFERS nchan_out_buff = st_ivas->nchan_transport; -#else - nchan_out_buff = MAX_OUTPUT_CHANNELS; -#endif move16(); IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) @@ -336,7 +332,6 @@ Word16 ivas_get_nchan_buffers_dec_fx( } ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { -#ifdef FIX_NCHAN_BUFFERS nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); test(); @@ -344,49 +339,16 @@ Word16 ivas_get_nchan_buffers_dec_fx( { nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); } -#else - nchan_out_buff = st_ivas->nchan_ism; - move16(); - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); - } - ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); - } -#endif } ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { -#ifdef FIX_NCHAN_BUFFERS Word16 nchan_internal; nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); nchan_out_buff = s_max( nchan_internal, st_ivas->hDecoderConfig->nchan_out ); -#else - Word16 nchan_internal; - nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); - nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; - move16(); - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); - } - ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); - } - nchan_out_buff = s_max( nchan_out_buff, nchan_internal ); -#endif } ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { -#ifdef FIX_NCHAN_BUFFERS nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); test(); @@ -395,64 +357,13 @@ Word16 ivas_get_nchan_buffers_dec_fx( nchan_out_buff = 2 * BINAURAL_CHANNELS; move16(); } -#else - nchan_out_buff = CPE_CHANNELS; - move16(); - - test(); - test(); - test(); - test(); - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); - } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || - EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - nchan_out_buff = shl( CPE_CHANNELS, 1 ); - } - ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); - } - test(); - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && GT_16( st_ivas->nchan_ism, 0 ) && LT_16( st_ivas->nchan_ism, 5 ) ) /* Last condition needed only in BASOP */ - { - nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS ); - } -#endif } ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { -#ifdef FIX_NCHAN_BUFFERS nchan_out_buff = s_max( st_ivas->hDecoderConfig->nchan_out, add( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); -#else - nchan_out_buff = add( st_ivas->nchan_ism, CPE_CHANNELS ); - - test(); - test(); - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); - } - ELSE 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 ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( BINAURAL_CHANNELS, st_ivas->nchan_ism ) ); - } - ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); - } -#endif } ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { -#ifdef FIX_NCHAN_BUFFERS Word16 nchan_internal; nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); @@ -473,52 +384,10 @@ Word16 ivas_get_nchan_buffers_dec_fx( { nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); } -#else - Word16 nchan_internal; - nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); - nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport ); - - IF( st_ivas->hMCT != NULL ) - { - nchan_out_buff = shl( shr( add( nchan_out_buff, 1 ), 1 ), 1 ); /* ensure odd number of channels in MCT */ - } - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); - } - ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); - - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) ) - { - nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */ - } - ELSE - { - nchan_out_buff = s_max( add( nchan_out_buff, st_ivas->nchan_ism ), audioCfg2channels( output_config ) ); /* needed for ivas_spar_dec_upmixer_sf() which is based on 'nchan_out' */ - } - } - ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*take into account sba_ch_idx' in ivas_dec() */ - } - - test(); - IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( nchan_internal, st_ivas->nchan_ism ) ); - } - nchan_out_buff = s_min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); -#endif } ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { -#ifdef FIX_NCHAN_BUFFERS - 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 ) { @@ -534,25 +403,12 @@ Word16 ivas_get_nchan_buffers_dec_fx( { nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); } -#else - nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; - - IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_out_buff = s_max( nchan_out_buff, add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ); - } - ELSE IF( NE_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) - { - nchan_out_buff = s_max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); - nchan_out_buff = s_max( nchan_out_buff, audioCfg2channels( output_config ) ); - } -#endif } 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; @@ -566,18 +422,12 @@ Word16 ivas_get_nchan_buffers_dec_fx( *-------------------------------------------------------------------*/ ivas_error ivas_output_buff_dec_fx( - Word32 *p_output_fx[], /* i/o: output audio buffers */ -#ifdef FIX_1330_JBM_MEMORY + Word32 *p_output_fx[], /* i/o: output audio buffers */ const Word16 nchan_out_buff, /* i : number of output channels */ const Word16 Opt_tsm, /* i : TSM option flag */ DECODER_TC_BUFFER_HANDLE hTcBuffer /* i : TSM buffer handle */ -#else - const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */ - const Word16 nchan_out_buff /* i : number of output channels */ -#endif ) { -#ifdef FIX_1330_JBM_MEMORY Word16 ch, nchan_tc_jbm, nsamp_to_allocate, n_samp_full, offset; FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ch++ ) @@ -596,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(); @@ -639,37 +489,6 @@ ivas_error ivas_output_buff_dec_fx( offset = add( offset, n_samp_full ); } } -#else - Word16 ch; - - IF( GT_16( nchan_out_buff, nchan_out_buff_old ) ) - { - FOR( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) - { -#ifdef FIX_NCHAN_BUFFERS -#ifdef DEBUGGING - if ( p_output_fx[ch] != NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Memory for floating-point output audio buffer is already allocated!\n" ) ); - } -#endif -#endif - /* note: these are intra-frame heap memories */ - IF( ( p_output_fx[ch] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for output audio buffer!\n" ) ); - } - } - } - ELSE - { - FOR( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ ) - { - free( p_output_fx[ch] ); - p_output_fx[ch] = NULL; - } - } -#endif return IVAS_ERR_OK; } @@ -796,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 86586520ea539a9b028d6f0873fa06af1d96e54c..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( - int16_t **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 int32_t 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 */ ); @@ -683,9 +696,7 @@ ivas_error ivas_td_binaural_open_ext_fx( RENDER_CONFIG_DATA *hRendCfg, /* i : Renderer configuration */ LSSETUP_CUSTOM_STRUCT *customLsInput, const Word32 output_Fs, -#ifdef NONBE_1377_REND_DIRATT_CONF const Word16 object_id, /* i : Object ID */ -#endif Word16 *SrcInd, Word16 *num_src ); @@ -891,7 +902,7 @@ ivas_error ivas_rend_openCrend_fx( HRTFS_CREND_HANDLE hHrtfCrend, HRTFS_STATISTICS_HANDLE hHrtfStatistics, const Word32 output_Fs, - const int16_t ext_rend_flag, + const Word16 ext_rend_flag, const Word16 num_poses ); @@ -916,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 */ @@ -955,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 */ @@ -1347,6 +1363,11 @@ ivas_error ivas_render_config_init_from_rom_fx( RENDER_CONFIG_HANDLE *hRenderConfig /* i/o: Renderer config handle */ ); +ivas_error ivas_render_config_change_defaults( + RENDER_CONFIG_HANDLE hRenderConfig, /* i/o: Renderer config handle */ + IVAS_DefaultReverbSize reverbDefault /* i : Reverb default size */ +); + /*----------------------------------------------------------------------------------* * Quaternion operations @@ -1444,8 +1465,8 @@ ivas_error ivas_omasa_ana_open( void ivas_omasa_ana_fx( OMASA_ANA_HANDLE hOMasa, /* i/o: OMASA analysis handle */ - Word32 data_in_f_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ - Word16 *q, + Word32 data_in_fx[][L_FRAME48k], /* i/o: Input / transport audio signals */ + Word16 *data_in_q, /* o : audio signals Q factor */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_ism /* i : Number of objects for parameter analysis*/ @@ -1489,7 +1510,6 @@ void ivas_create_masa_out_meta_fx( Word16 surroundingCoherence_q ); -#ifdef NONBE_1344_REND_MASA_LOW_FS void ivas_masa_zero_high_bands_fx( const Word16 nbands, /* i : Number of frequency bands with estimated values */ Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated elevation */ @@ -1498,7 +1518,6 @@ void ivas_masa_zero_high_bands_fx( Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated spread coherence */ Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i/o : Estimated surround coherence */ ); -#endif ivas_error ivas_dirac_ana_open_fx( DIRAC_ANA_HANDLE *hDirACPtr, /* i/o: DIRAC data handle pointer */ @@ -1554,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 */ @@ -1619,7 +1638,6 @@ void ivas_TD_RINGBUF_Close( TD_RINGBUF_HANDLE *ph /* i/o: Ring buffer handle */ ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP void ivas_TD_RINGBUF_PushInterleaved( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const Word32 *data, /* i : Input audio in interleaved channels layout */ @@ -1643,29 +1661,45 @@ void ivas_TD_RINGBUF_PopChannels( Word32 *p_channels[], /* i : Array of pointers to each output channel */ const Word16 num_samples_per_channel /* i : Number of samples per channel to pop */ ); -#else -void ivas_TD_RINGBUF_Push( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const Word32 *data, /* i : Input data */ - const Word16 num_samples_per_channel /* i : Number of samples per channel to store */ + +Word16 ivas_TD_RINGBUF_Size( + const TD_RINGBUF_HANDLE h /* i : Ring buffer handle */ ); -void ivas_TD_RINGBUF_PushZeros( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const Word16 num_samples_per_channel /* i : Number of zeros per channel to store */ +/*---------------------------------------------------------------------------------* + * Multi-pose ring buffer Prototypes +*-----------------------------------------------------------------------------------*/ + +ivas_error ivas_CLDFB_RINGBUF_Open( + ISAR_CLDFB_RINGBUF_HANDLE *ph, + const Word16 capacity_columns ); -void ivas_TD_RINGBUF_Pop( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - Word32 *data, /* i : Output data */ - const Word16 num_samples_per_channel /* i : Number of samples per channel to retrieve*/ +void ivas_CLDFB_RINGBUF_Close( + ISAR_CLDFB_RINGBUF_HANDLE *ph ); -#endif -Word16 ivas_TD_RINGBUF_Size( - const TD_RINGBUF_HANDLE h /* i : Ring buffer handle */ +void ivas_CLDFB_RINGBUF_Push( + ISAR_CLDFB_RINGBUF_HANDLE h, + const Word32 *real, + const Word32 *imag, + const Word16 num_bands ); -/* clang-format on */ +void ivas_CLDFB_RINGBUF_Pop( + ISAR_CLDFB_RINGBUF_HANDLE h, + Word32 *real, + Word32 *imag, + const Word16 num_bands +); -#endif /* IVAS_PROT_REND_H */ +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 3c43b59e1fa44312f199d2cd4af6d26c10e6229a..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 @@ -42,8 +42,14 @@ * Local constants *-----------------------------------------------------------------------*/ -#define IVAS_REVERB_DEFAULT_PRE_DELAY_FX 2147484 // 0.016 -#define IVAS_REVERB_DEFAULT_INPUT_DELAY_FX 13421773 // 0.1 +#define IVAS_REVERB_DEFAULT_L_PRE_DELAY_FX 2147484 // 0.016 +#define IVAS_REVERB_DEFAULT_L_INPUT_DELAY_FX 13421773 // 0.1 + +#define IVAS_REVERB_DEFAULT_S_PRE_DELAY_FX 1677722 // 0.0125f +#define IVAS_REVERB_DEFAULT_S_INPUT_DELAY_FX 0 // 0.0f + +#define IVAS_REVERB_DEFAULT_M_PRE_DELAY_FX 1677722 // 0.0125f +#define IVAS_REVERB_DEFAULT_M_INPUT_DELAY_FX 0 // 0.0f #define IVAS_REVERB_DEFAULT_USE_ER 0 @@ -107,11 +113,13 @@ ivas_error ivas_render_config_init_from_rom_fx( { return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Unexpected null pointer while attempting to fill renderer configuration from ROM" ); } - ( *hRenderConfig )->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_N_BANDS; + ( *hRenderConfig )->roomAcoustics.aeID = IVAS_DEFAULT_AEID; move16(); - ( *hRenderConfig )->roomAcoustics.acousticPreDelay_fx = IVAS_REVERB_DEFAULT_PRE_DELAY_FX; + ( *hRenderConfig )->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_L_N_BANDS; + move16(); + ( *hRenderConfig )->roomAcoustics.acousticPreDelay_fx = IVAS_REVERB_DEFAULT_L_PRE_DELAY_FX; move32(); - ( *hRenderConfig )->roomAcoustics.inputPreDelay_fx = IVAS_REVERB_DEFAULT_INPUT_DELAY_FX; + ( *hRenderConfig )->roomAcoustics.inputPreDelay_fx = IVAS_REVERB_DEFAULT_L_INPUT_DELAY_FX; move32(); ( *hRenderConfig )->roomAcoustics.use_er = IVAS_REVERB_DEFAULT_USE_ER; move16(); @@ -119,9 +127,9 @@ ivas_error ivas_render_config_init_from_rom_fx( set32_fx( &( *hRenderConfig )->roomAcoustics.pAcoustic_rt60_fx[0], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( &( *hRenderConfig )->roomAcoustics.pAcoustic_dsr_fx[0], 0, CLDFB_NO_CHANNELS_MAX ); - Copy32( ivas_reverb_default_fc_fx, ( *hRenderConfig )->roomAcoustics.pFc_input_fx, IVAS_REVERB_DEFAULT_N_BANDS ); - Copy32( ivas_reverb_default_RT60_fx, ( *hRenderConfig )->roomAcoustics.pAcoustic_rt60_fx, IVAS_REVERB_DEFAULT_N_BANDS ); - Copy32( ivas_reverb_default_DSR_fx, ( *hRenderConfig )->roomAcoustics.pAcoustic_dsr_fx, IVAS_REVERB_DEFAULT_N_BANDS ); + Copy32( ivas_reverb_default_large_fc_fx, ( *hRenderConfig )->roomAcoustics.pFc_input_fx, IVAS_REVERB_DEFAULT_L_N_BANDS ); + Copy32( ivas_reverb_default_large_RT60_fx, ( *hRenderConfig )->roomAcoustics.pAcoustic_rt60_fx, IVAS_REVERB_DEFAULT_L_N_BANDS ); + Copy32( ivas_reverb_default_large_DSR_fx, ( *hRenderConfig )->roomAcoustics.pAcoustic_dsr_fx, IVAS_REVERB_DEFAULT_L_N_BANDS ); FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { @@ -161,3 +169,75 @@ ivas_error ivas_render_config_init_from_rom_fx( return IVAS_ERR_OK; } + + +/*-------------------------------------------------------------------* + * ivas_render_config_change_defaults() + * + * Changes default values from ROM + *-------------------------------------------------------------------*/ + +ivas_error ivas_render_config_change_defaults( + RENDER_CONFIG_HANDLE hRenderConfig, /* i/o: Renderer config handle */ + IVAS_DefaultReverbSize defaultReverbSize /* i: Reverb default size */ +) +{ + SWITCH( defaultReverbSize ) + { + case DEFAULT_REVERB_SMALL: + hRenderConfig->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_S_N_BANDS; + move16(); + hRenderConfig->roomAcoustics.acousticPreDelay_fx = IVAS_REVERB_DEFAULT_S_PRE_DELAY_FX; + move32(); + hRenderConfig->roomAcoustics.inputPreDelay_fx = IVAS_REVERB_DEFAULT_S_INPUT_DELAY_FX; + move32(); + hRenderConfig->roomAcoustics.use_er = IVAS_REVERB_DEFAULT_USE_ER; + move16(); + set_zero_fx( &hRenderConfig->roomAcoustics.pFc_input_fx[0], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &hRenderConfig->roomAcoustics.pAcoustic_rt60_fx[0], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &hRenderConfig->roomAcoustics.pAcoustic_dsr_fx[0], CLDFB_NO_CHANNELS_MAX ); + + Copy32( ivas_reverb_default_small_fc_fx, hRenderConfig->roomAcoustics.pFc_input_fx, IVAS_REVERB_DEFAULT_S_N_BANDS ); + Copy32( ivas_reverb_default_small_RT60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, IVAS_REVERB_DEFAULT_S_N_BANDS ); + Copy32( ivas_reverb_default_small_DSR_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, IVAS_REVERB_DEFAULT_S_N_BANDS ); + BREAK; + case DEFAULT_REVERB_MEDIUM: + hRenderConfig->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_M_N_BANDS; + move16(); + hRenderConfig->roomAcoustics.acousticPreDelay_fx = IVAS_REVERB_DEFAULT_M_PRE_DELAY_FX; + move32(); + hRenderConfig->roomAcoustics.inputPreDelay_fx = IVAS_REVERB_DEFAULT_M_INPUT_DELAY_FX; + move32(); + hRenderConfig->roomAcoustics.use_er = IVAS_REVERB_DEFAULT_USE_ER; + move16(); + set_zero_fx( &hRenderConfig->roomAcoustics.pFc_input_fx[0], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &hRenderConfig->roomAcoustics.pAcoustic_rt60_fx[0], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &hRenderConfig->roomAcoustics.pAcoustic_dsr_fx[0], CLDFB_NO_CHANNELS_MAX ); + + Copy32( ivas_reverb_default_medium_fc_fx, hRenderConfig->roomAcoustics.pFc_input_fx, IVAS_REVERB_DEFAULT_M_N_BANDS ); + Copy32( ivas_reverb_default_medium_RT60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, IVAS_REVERB_DEFAULT_M_N_BANDS ); + Copy32( ivas_reverb_default_medium_DSR_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, IVAS_REVERB_DEFAULT_M_N_BANDS ); + BREAK; + case DEFAULT_REVERB_LARGE: + hRenderConfig->roomAcoustics.nBands = IVAS_REVERB_DEFAULT_L_N_BANDS; + move16(); + hRenderConfig->roomAcoustics.acousticPreDelay_fx = IVAS_REVERB_DEFAULT_L_PRE_DELAY_FX; + move32(); + hRenderConfig->roomAcoustics.inputPreDelay_fx = IVAS_REVERB_DEFAULT_L_INPUT_DELAY_FX; + move32(); + hRenderConfig->roomAcoustics.use_er = IVAS_REVERB_DEFAULT_USE_ER; + move16(); + set_zero_fx( &hRenderConfig->roomAcoustics.pFc_input_fx[0], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &hRenderConfig->roomAcoustics.pAcoustic_rt60_fx[0], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &hRenderConfig->roomAcoustics.pAcoustic_dsr_fx[0], CLDFB_NO_CHANNELS_MAX ); + + Copy32( ivas_reverb_default_large_fc_fx, hRenderConfig->roomAcoustics.pFc_input_fx, IVAS_REVERB_DEFAULT_L_N_BANDS ); + Copy32( ivas_reverb_default_large_RT60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, IVAS_REVERB_DEFAULT_L_N_BANDS ); + Copy32( ivas_reverb_default_large_DSR_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, IVAS_REVERB_DEFAULT_L_N_BANDS ); + BREAK; + default: + return IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING; + } + + return IVAS_ERR_OK; +} 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 09720d202d72eaceaa847453fc8af51939d97b97..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,18 +34,20 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" -#include #include "wmc_auto.h" +#ifdef DEBUGGING #include "debug.h" -#define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) -#define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) +#endif /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ + static void fft_wrapper_2ch_fx( Word32 *buffer_L, Word32 *buffer_R, const Word16 fft_size ); static void ifft_wrapper_2ch_fx( Word32 *buffer_L, Word32 *buffer_R, const Word16 fft_size ); + + /*-----------------------------------------------------------------------------------------* * Function int_log2() * 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 5b0f33864b00d441ae9cf83f227b09556f1be6f4..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 @@ -107,9 +107,17 @@ extern const Word32 t_design_11_elevation_int[70]; /*Q-22*/ * Reverberator ROM tables *-----------------------------------------------------------------------*/ -extern const Word32 ivas_reverb_default_fc_fx[]; /*Q-16*/ -extern const Word32 ivas_reverb_default_RT60_fx[]; /*Q-26*/ -extern const Word32 ivas_reverb_default_DSR_fx[]; /*Q-30*/ +extern const Word32 ivas_reverb_default_small_fc_fx[]; /*Q-16*/ +extern const Word32 ivas_reverb_default_small_RT60_fx[]; /*Q-26*/ +extern const Word32 ivas_reverb_default_small_DSR_fx[]; /*Q-30*/ + +extern const Word32 ivas_reverb_default_medium_fc_fx[]; /*Q-16*/ +extern const Word32 ivas_reverb_default_medium_RT60_fx[]; /*Q-26*/ +extern const Word32 ivas_reverb_default_medium_DSR_fx[]; /*Q-30*/ + +extern const Word32 ivas_reverb_default_large_fc_fx[]; /*Q-16*/ +extern const Word32 ivas_reverb_default_large_RT60_fx[]; /*Q-26*/ +extern const Word32 ivas_reverb_default_large_DSR_fx[]; /*Q-30*/ /*----------------------------------------------------------------------------------* * EFAP ROM tables diff --git a/lib_rend/ivas_rom_rend_fx.c b/lib_rend/ivas_rom_rend_fx.c index f3f034c4da5bec02aa566575979e8cc8309a7f87..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 @@ -81,15 +81,9 @@ const Word32 ap_lattice_coeffs_2_fx[132] /* Q31 */ = { 1360843264, 1462880896, const Word32 ap_lattice_coeffs_3_fx[66] /* Q31 */ = { 1360843264, 1462880896, -106124344, 615715776, 313579872, 290773568, -880779712, -444026592, -1410828032, -218497872, 936944960, 729753600, -282142848, -1661606912, -647739072, 703431872, 713452032, 442076704, 1541038592, -1186205568, -322414592, 117158120, 514363136, -1392593792, -1550156800, 406684000, 146426176, 13348758, 165409920, 83060376, 909276800, -233341280, 927820288, -890434752, 596656832, 898691840, 167097856, -607873152, -766668864, 9951439, -950562176, -799540352, 866157440, 521887904, 675097984, 954584384, 746287104, 1065244224, 232804400, 1007990144, -365686400, 700745408, 369704352, 945610048, 125449552, 729442240, -418684160, 1054884800, -604078592, -92599496, -1036132928, -719417728, -721895936, 421913952, -353525216, 950242176}; const Word32 * const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS] = { -#ifdef CODE_IMPROVEMENTS ap_lattice_coeffs_1_fx, ap_lattice_coeffs_2_fx, ap_lattice_coeffs_3_fx, -#else - &ap_lattice_coeffs_1_fx[0], - &ap_lattice_coeffs_2_fx[0], - &ap_lattice_coeffs_3_fx[0], -#endif }; const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]/*Q14*/ = { @@ -248,23 +242,91 @@ const Word32 t_design_11_elevation_int[70] = //Q22 32230182, -98862600, 97758528, 296363872, -40604592, -296967968, -111972608, 201383760, -32033360, 187339088, 110320048, -186468864, 39944096, -199750464 }; + + /*----------------------------------------------------------------------* * Reverberator ROM tables *-----------------------------------------------------------------------*/ -const Word32 ivas_reverb_default_fc_fx[IVAS_REVERB_DEFAULT_N_BANDS] /*Q16*/ = +const Word32 ivas_reverb_default_small_fc_fx[IVAS_REVERB_DEFAULT_S_N_BANDS] = +{ + 13107200, 39321600, 65536000, 91750400, 117964800, 144179200, 170393600, 196608000, 222822400, 249036800, + 275251200, 301465600, 327680000, 353894400, 380108800, 406323200, 432537600, 458752000, 484966400, 511180800, + 537395200, 563609600, 589824000, 616038400, 642252800, 668467200, 694681600, 720896000, 747110400, 773324800, + 799539200, 825753600, 851968000, 878182400, 904396800, 930611200, 956825600, 983040000, 1009254400, 1035468800, + 1061683200, 1087897600, 1114112000, 1140326400, 1166540800, 1192755200, 1218969600, 1245184000, 1271398400, 1297612800, + 1323827200, 1350041600, 1376256000, 1402470400, 1428684800, 1454899200, 1481113600, 1507328000, 1533542400, 1559756800 +}; + +const Word32 ivas_reverb_default_small_RT60_fx[IVAS_REVERB_DEFAULT_S_N_BANDS] = +{ + 20132660, 18371052, 17846998, 17702244, 17822236, 17568430, 16977738, 16495426, 15933590, 15312162, + 14732812, 14167755, 13640682, 13163001, 12694380, 12243073, 11827065, 11416157, 11022631, 10656284, + 10291077, 9953050, 9614419, 9287733, 8987823, 8690128, 8409345, 8176074, 7940388, 7726244, + 7560149, 7379157, 7211854, 7067302, 6912616, 6763433, 6618880, 6473925, 6330715, 6188578, + 6047516, 5909405, 5773644, 5641238, 5524872, 5405753, 5293279, 5208588, 5113897, 5027662, + 4972901, 4903511, 4842106, 4808954, 4762649, 4743657, 4712653, 4689433, 4693326, 4685541 +}; + +const Word32 ivas_reverb_default_small_DSR_fx[IVAS_REVERB_DEFAULT_S_N_BANDS] = +{ + 16773, 7628, 5046, 4620, 5666, 6853, 7771, 9876, 11530, 12337, + 11421, 10287, 8791, 7565, 6305, 5215, 4504, 3860, 3627, 4363, + 5246, 6739, 8151, 9611, 10088, 10416, 10154, 9187, 8628, 8012, + 7491, 6931, 6320, 6074, 5589, 5145, 4977, 4646, 4558, 4411, + 4331, 4253, 4147, 4018, 3821, 3629, 3428, 3361, 3361, 3361, + 3361, 3361, 3361, 3361, 3361, 3361, 3361, 3361, 3361, 3361 +}; + +const Word32 ivas_reverb_default_medium_fc_fx[IVAS_REVERB_DEFAULT_M_N_BANDS] = +{ + 1310720, 1638400, 2064384, 2621440, 3276800, + 4128768, 5242880, 6553600, 8192000, + 10485760, 13107200, 16384000, 20643840, + 26214400, 32768000, 41287680, 52428800, + 65536000, 81920000, 104857600, 131072000, + 163840000, 206438400, 262144000, 327680000, + 412876800, 524288000, 655360000, 819200000, + 1048576000, 1310720000 +}; + +const Word32 ivas_reverb_default_medium_RT60_fx[IVAS_REVERB_DEFAULT_M_N_BANDS] = +{ + 14763950, 15099494, 15535702, 16106127, + 16777216, 17649632, 18790482, 20132660, + 21810380, 24159192, 26843546, 26591888, + 26264732, 25836912, 25333596, 24785364, + 24530840, 24231400, 24127968, 24134494, + 24058024, 23406682, 22445968, 21003330, + 19424124, 17708016, 15804674, 13936498, + 12319828, 10826874, 9549390 +}; + +const Word32 ivas_reverb_default_medium_DSR_fx[IVAS_REVERB_DEFAULT_M_N_BANDS] = +{ + 15978, 16341, 16813, 17430, + 18156, 19101, 20335, 21788, + 23603, 26145, 29050, 27037, + 24421, 20999, 16973, 12614, + 10726, 8506, 8047, 8659, + 10526, 12575, 17260, 19074, + 13653, 7464, 6609, 12688, + 7607, 3835, 2373 +}; + +const Word32 ivas_reverb_default_large_fc_fx[IVAS_REVERB_DEFAULT_L_N_BANDS] /*Q16*/ = { - 1310720 , 1638400 , 2064384 , 2621440 , 3276800 , - 4128768 , 5242880 , 6553600 , 8192000 , - 10485760 , 13107200 , 16384000 , 20643840 , - 26214400 , 32768000 , 41287680 , 52428800 , - 65536000 , 81920000 , 104857600 , 131072000 , - 163840000 , 206438400 , 262144000 , 327680000 , - 412876800 , 524288000 , 655360000 , 819200000 , - 1048576000 , 1310720000 + 1310720, 1638400, 2064384, 2621440, 3276800, + 4128768, 5242880, 6553600, 8192000, + 10485760, 13107200, 16384000, 20643840, + 26214400, 32768000, 41287680, 52428800, + 65536000, 81920000, 104857600, 131072000, + 163840000, 206438400, 262144000, 327680000, + 412876800, 524288000, 655360000, 819200000, + 1048576000, 1310720000 }; -const Word32 ivas_reverb_default_RT60_fx[IVAS_REVERB_DEFAULT_N_BANDS] /*Q26*/ = +const Word32 ivas_reverb_default_large_RT60_fx[IVAS_REVERB_DEFAULT_L_N_BANDS] /*Q26*/ = { 91415696, 97213904, 88368952, 105944760, 99092952, 93643712, 86496616, 90341952, @@ -276,7 +338,7 @@ const Word32 ivas_reverb_default_RT60_fx[IVAS_REVERB_DEFAULT_N_BANDS] /*Q26*/ = 48281472, 41394088, 40286124 }; -const Word32 ivas_reverb_default_DSR_fx[IVAS_REVERB_DEFAULT_N_BANDS] /*Q30*/ = +const Word32 ivas_reverb_default_large_DSR_fx[IVAS_REVERB_DEFAULT_L_N_BANDS] /*Q30*/ = { 20, 23, 15, 16, 13, 20, 25, 42, @@ -517,6 +579,14 @@ const LS_CONVERSION_MATRIX_FX ls_conversion_cicp19_cicp16_fx[] = // Q30 }; /* Upmix matrices */ +const LS_CONVERSION_MATRIX_FX ls_conversion_mono_cicpX_fx[] = // Q30 +{ + /* First row indicates the number of non-zero elements and the number of matrix columns */ + {1, 12}, + /* Index of non-zero element, value of non-zero element*/ + {2, 1073741824}, +}; + const LS_CONVERSION_MATRIX_FX ls_conversion_cicp12_cicp14_fx[] = // Q30 { /* First row indicates the number of non-zero elements and the number of matrix columns */ @@ -602,6 +672,7 @@ const LS_CONVERSION_MATRIX_FX ls_conversion_cicp16_cicp19_fx[] = // Q30 const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[LS_SETUP_CONVERSION_NUM_MAPPINGS] = { /* Dowmix mappings - NULL is a special case for MONO / STEREO downmix */ + {IVAS_AUDIO_CONFIG_STEREO, IVAS_AUDIO_CONFIG_MONO, NULL}, {IVAS_AUDIO_CONFIG_5_1, IVAS_AUDIO_CONFIG_MONO, NULL}, {IVAS_AUDIO_CONFIG_7_1, IVAS_AUDIO_CONFIG_MONO, NULL}, {IVAS_AUDIO_CONFIG_5_1_2, IVAS_AUDIO_CONFIG_MONO, NULL}, @@ -629,6 +700,12 @@ const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[LS_SETUP_CONVERSION_NUM_ {IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_5_1_4, ls_conversion_cicp19_cicp16_fx}, /* Upmix mappings - NULL implies a 1:1 upmix */ + {IVAS_AUDIO_CONFIG_MONO, IVAS_AUDIO_CONFIG_5_1, ls_conversion_mono_cicpX_fx}, + {IVAS_AUDIO_CONFIG_MONO, IVAS_AUDIO_CONFIG_7_1, ls_conversion_mono_cicpX_fx}, + {IVAS_AUDIO_CONFIG_MONO, IVAS_AUDIO_CONFIG_5_1_2, ls_conversion_mono_cicpX_fx}, + {IVAS_AUDIO_CONFIG_MONO, IVAS_AUDIO_CONFIG_5_1_4, ls_conversion_mono_cicpX_fx}, + {IVAS_AUDIO_CONFIG_MONO, IVAS_AUDIO_CONFIG_7_1_4, ls_conversion_mono_cicpX_fx}, + {IVAS_AUDIO_CONFIG_STEREO, IVAS_AUDIO_CONFIG_5_1, NULL}, {IVAS_AUDIO_CONFIG_STEREO, IVAS_AUDIO_CONFIG_7_1, NULL}, {IVAS_AUDIO_CONFIG_STEREO, IVAS_AUDIO_CONFIG_5_1_2, NULL}, diff --git a/lib_rend/ivas_rotation_fx.c b/lib_rend/ivas_rotation_fx.c index b58294d06df3b29a334b8324eefc40cba3cc6c97..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" @@ -98,6 +97,27 @@ static void external_target_interpolation_fx( EXTERNAL_ORIENTATION_HANDLE hExtOr static bool are_orientations_same_fx( const IVAS_QUATERNION *orientation1, const IVAS_QUATERNION *orientation2 ); +/*-----------------------------------------------------------------------* + * function Q_factor_L_32() + * + * + *-----------------------------------------------------------------------*/ + +static Word16 Q_factor_L_32( + const Word32 x ) +{ + Word16 Q = 31; + + test(); + IF( GE_32( x, 1 ) || LE_32( x, -1 ) ) + { + Q = norm_l( L_abs( (Word32) x ) ); + } + + return Q; +} + + /*-----------------------------------------------------------------------* * ivas_headTrack_open() * @@ -200,7 +220,7 @@ void QuatToRotMat_fx( // Euler2Quat_fx( deg2rad( quat.x_fx ), deg2rad( quat.y_fx ), deg2rad( quat.z_fx ), &quat_local ); // QuatToRotMat_fx( quat_local, Rmat ); } - else + ELSE { Word32 w = quat.w_fx; // Qx move32(); @@ -699,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: @@ -836,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: @@ -1382,7 +1402,17 @@ ivas_error ivas_combined_orientation_open_fx( ( *hCombinedOrientationData )->isInterpolationOngoing = FALSE; move16(); ( *hCombinedOrientationData )->Quaternions_ext_interpolation_start = identity; + move32(); + move32(); + move32(); + move32(); + move16(); ( *hCombinedOrientationData )->Quaternions_ext_interpolation_target = identity; + move32(); + move32(); + move32(); + move32(); + move16(); /* Initialise orientations to identity */ FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) @@ -1390,7 +1420,17 @@ ivas_error ivas_combined_orientation_open_fx( ( *hCombinedOrientationData )->enableCombinedOrientation[i] = 0; move16(); ( *hCombinedOrientationData )->Quaternions[i] = identity; + move32(); + move32(); + move32(); + move32(); + move16(); ( *hCombinedOrientationData )->listenerPos[i] = origo; + move32(); + move32(); + move32(); + move32(); + move16(); FOR( j = 0; j < 3; j++ ) { @@ -1414,10 +1454,24 @@ ivas_error ivas_combined_orientation_open_fx( move32(); move16(); - ( *hCombinedOrientationData ) - ->Quaternion_prev_extOrientation = identity; + ( *hCombinedOrientationData )->Quaternion_prev_extOrientation = identity; + move32(); + move32(); + move32(); + move32(); + move16(); ( *hCombinedOrientationData )->Quaternion_frozen_ext = identity; + move32(); + move32(); + move32(); + move32(); + move16(); ( *hCombinedOrientationData )->Quaternion_frozen_head = identity; + move32(); + move32(); + move32(); + move32(); + move16(); set_zero_fx( ( *hCombinedOrientationData )->chEneIIR_fx[0], MASA_FREQUENCY_BANDS ); set_zero_fx( ( *hCombinedOrientationData )->chEneIIR_fx[1], MASA_FREQUENCY_BANDS ); set_zero_fx( ( *hCombinedOrientationData )->procChEneIIR_fx[0], MASA_FREQUENCY_BANDS ); @@ -1435,13 +1489,23 @@ ivas_error ivas_combined_orientation_open_fx( ( *hCombinedOrientationData )->subframe_idx = 0; move16(); /* ( *hCombinedOrientationData )->subframe_size = (int16_t) ( fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); */ - ( *hCombinedOrientationData )->subframe_size = extract_l( Mpy_32_32_r( fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); + ( *hCombinedOrientationData )->subframe_size = extract_l( Mpy_32_16_1( fs, ONE_BY_SUBFR_PER_SEC_Q15 ) ); move16(); ( *hCombinedOrientationData )->cur_subframe_samples_rendered = 0; move16(); + FOR( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) + { + ( *hCombinedOrientationData )->isDiegeticInputPI[i] = TRUE; + move16(); + } + ( *hCombinedOrientationData )->isDiegeticInputPISet = FALSE; + move16(); + return IVAS_ERR_OK; } + + /*-----------------------------------------------------------------------* * ivas_combined_orientation_close() * @@ -1486,10 +1550,12 @@ ivas_error combine_external_and_head_orientations_dec( pHeadRotQuaternion = hHeadTrackData->Quaternions; listenerPos = hHeadTrackData->Pos; sr_pose_pred_axis = hHeadTrackData->sr_pose_pred_axis; + move32(); } ELSE { sr_pose_pred_axis = DEFAULT_AXIS; + move32(); } return combine_external_and_head_orientations( pHeadRotQuaternion, listenerPos, sr_pose_pred_axis, hExtOrientationData, hCombinedOrientationData ); @@ -1514,22 +1580,14 @@ ivas_error combine_external_and_head_orientations_rend( Word16 i; sr_pose_pred_axis = DEFAULT_AXIS; + move32(); -#ifdef FIX_1383_HEAD_TRACK_SANITIZER IF( hHeadTrackData->headRotEnabled ) { headRotQuaternions = hHeadTrackData->headPositions; listenerPos = hHeadTrackData->Pos; -#else - IF( hHeadTrackData != NULL ) - { - IF( hHeadTrackData->headRotEnabled ) - { - headRotQuaternions = hHeadTrackData->headPositions; - listenerPos = hHeadTrackData->Pos; - } -#endif sr_pose_pred_axis = hHeadTrackData->sr_pose_pred_axis; + move32(); } ELSE IF( hExtOrientationData != NULL ) { @@ -1611,13 +1669,32 @@ ivas_error combine_external_and_head_orientations( hCombinedOrientationData->interpolationIncrement_fx = ONE_IN_Q30; move32(); hCombinedOrientationData->Quaternions_ext_interpolation_start = identity; + move32(); + move32(); + move32(); + move32(); + move16(); hCombinedOrientationData->Quaternions_ext_interpolation_target = identity; + move32(); + move32(); + move32(); + move32(); + move16(); FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { hCombinedOrientationData->enableCombinedOrientation[i] = 0; move16(); hCombinedOrientationData->Quaternions[i] = identity; + move32(); + move32(); + move32(); + move32(); + move16(); hCombinedOrientationData->listenerPos[i] = origo; + move32(); + move32(); + move32(); + move16(); FOR( j = 0; j < 3; j++ ) { @@ -1629,10 +1706,36 @@ ivas_error combine_external_and_head_orientations( } ELSE IF( hExtOrientationData == NULL && headRotQuaternions != NULL ) { - /* Head rotation only */ - FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) + /* Disable head rotation if diegetic PI data indicating non-diegetic audio is received */ + test(); + test(); + test(); + test(); + test(); + IF( hCombinedOrientationData->isDiegeticInputPISet && !hCombinedOrientationData->isDiegeticInputPI[0] && !hCombinedOrientationData->isDiegeticInputPI[1] && !hCombinedOrientationData->isDiegeticInputPI[2] && !hCombinedOrientationData->isDiegeticInputPI[3] && !hCombinedOrientationData->isDiegeticInputPI[4] ) { - hCombinedOrientationData->Quaternions[i] = headRotQuaternions[i]; + FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) + { + hCombinedOrientationData->Quaternions[i] = identity; + move32(); /* Copying full struct */ + move32(); + move32(); + move32(); + move16(); + } + } + ELSE + { + /* Head rotation only */ + FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) + { + hCombinedOrientationData->Quaternions[i] = headRotQuaternions[i]; + move32(); /* Copying full struct */ + move32(); + move32(); + move32(); + move16(); + } } } @@ -1647,6 +1750,11 @@ ivas_error combine_external_and_head_orientations( IF( NE_16( hCombinedOrientationData->isExtOrientationFrozen, 1 ) ) { hCombinedOrientationData->Quaternion_frozen_ext = hExtOrientationData->Quaternions[i]; + move32(); + move32(); + move32(); + move32(); + move16(); hCombinedOrientationData->isExtOrientationFrozen = 1; move16(); } @@ -1654,11 +1762,16 @@ ivas_error combine_external_and_head_orientations( ELSE { hCombinedOrientationData->Quaternion_frozen_ext = identity; + move32(); + move32(); + move32(); + move32(); + move16(); hCombinedOrientationData->isExtOrientationFrozen = 0; move16(); } test(); - IF( EQ_16( hExtOrientationData->enableRotationInterpolation[i], 1 ) && hExtOrientationData->enableExternalOrientation[i] > 0 ) + IF( EQ_16( hExtOrientationData->enableRotationInterpolation[i], 1 ) && GT_16( hExtOrientationData->enableExternalOrientation[i], 0 ) ) { test(); test(); @@ -1724,15 +1837,26 @@ ivas_error combine_external_and_head_orientations( IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 1 ) ) { hCombinedOrientationData->Quaternions[i] = hExtOrientationData->Quaternions[i]; + move32(); + move32(); + move32(); + move32(); + move16(); } /* Use the freezed external orientation */ ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 2 ) ) { hCombinedOrientationData->Quaternions[i] = hCombinedOrientationData->Quaternion_frozen_ext; + move32(); + move32(); + move32(); + move32(); + move16(); } } } } + test(); IF( hExtOrientationData != NULL && headRotQuaternions != NULL ) { @@ -1745,6 +1869,11 @@ ivas_error combine_external_and_head_orientations( IF( NE_16( hCombinedOrientationData->isHeadRotationFrozen, 1 ) ) { hCombinedOrientationData->Quaternion_frozen_head = headRotQuaternions[i]; + move32(); + move32(); + move32(); + move32(); + move16(); hCombinedOrientationData->isHeadRotationFrozen = 1; move16(); } @@ -1752,41 +1881,77 @@ ivas_error combine_external_and_head_orientations( ELSE { hCombinedOrientationData->Quaternion_frozen_head = identity; + move32(); + move32(); + move32(); + move32(); + move16(); hCombinedOrientationData->isHeadRotationFrozen = 0; move16(); } - /* Use the most recent head rotation */ - IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 1 ) ) + + /* Disable head rotation if diegetic PI data indicating non-diegetic audio is received */ + test(); + test(); + test(); + test(); + test(); + IF( hCombinedOrientationData->isDiegeticInputPISet && !hCombinedOrientationData->isDiegeticInputPI[0] && !hCombinedOrientationData->isDiegeticInputPI[1] && !hCombinedOrientationData->isDiegeticInputPI[2] && !hCombinedOrientationData->isDiegeticInputPI[3] && !hCombinedOrientationData->isDiegeticInputPI[4] ) { - IF( hExtOrientationData->enableExternalOrientation[i] > 0 ) - { - QuaternionProduct_fx( hCombinedOrientationData->Quaternions[i], headRotQuaternions[i], &hCombinedOrientationData->Quaternions[i] ); - } - ELSE - { - hCombinedOrientationData->Quaternions[i] = headRotQuaternions[i]; - } + CONTINUE; } - /* Use the freezed head rotation */ - ELSE IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 2 ) ) + ELSE { - IF( hExtOrientationData->enableExternalOrientation[i] > 0 ) + /* Use the most recent head rotation */ + IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 1 ) ) { - QuaternionProduct_fx( hCombinedOrientationData->Quaternions[i], hCombinedOrientationData->Quaternion_frozen_head, &hCombinedOrientationData->Quaternions[i] ); + IF( GT_16( hExtOrientationData->enableExternalOrientation[i], 0 ) ) + { + QuaternionProduct_fx( hCombinedOrientationData->Quaternions[i], headRotQuaternions[i], &hCombinedOrientationData->Quaternions[i] ); + } + ELSE + { + hCombinedOrientationData->Quaternions[i] = headRotQuaternions[i]; + move32(); /* Copying full struct */ + move32(); + move32(); + move32(); + move16(); + } } - ELSE + /* Use the freezed head rotation */ + ELSE IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 2 ) ) { - hCombinedOrientationData->Quaternions[i] = hCombinedOrientationData->Quaternion_frozen_head; + IF( hExtOrientationData->enableExternalOrientation[i] > 0 ) + { + QuaternionProduct_fx( hCombinedOrientationData->Quaternions[i], hCombinedOrientationData->Quaternion_frozen_head, &hCombinedOrientationData->Quaternions[i] ); + } + ELSE + { + hCombinedOrientationData->Quaternions[i] = hCombinedOrientationData->Quaternion_frozen_head; + move32(); /* Copying full struct */ + move32(); + move32(); + move32(); + move16(); + } } } + /* Reset the combined orientations to identity */ test(); - if ( hExtOrientationData->enableHeadRotation[i] == 0 && hExtOrientationData->enableExternalOrientation[i] == 0 ) + IF( hExtOrientationData->enableHeadRotation[i] == 0 && hExtOrientationData->enableExternalOrientation[i] == 0 ) { hCombinedOrientationData->Quaternions[i] = identity; + move32(); + move32(); + move32(); + move32(); + move16(); } } } + test(); IF( headRotQuaternions != NULL || hExtOrientationData != NULL ) { @@ -1800,22 +1965,38 @@ ivas_error combine_external_and_head_orientations( /* Save the current orientations */ IF( hExtOrientationData != NULL ) { - IF( hExtOrientationData->enableExternalOrientation[hExtOrientationData->num_subframes - 1] > 0 ) + IF( GT_16( hExtOrientationData->enableExternalOrientation[hExtOrientationData->num_subframes - 1], 0 ) ) { hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[hExtOrientationData->num_subframes - 1]; + move32(); + move32(); + move32(); + move32(); + move16(); } ELSE { hCombinedOrientationData->Quaternion_prev_extOrientation = identity; + move32(); + move32(); + move32(); + move32(); + move16(); } } + IF( headRotQuaternions != NULL ) { FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { hCombinedOrientationData->listenerPos[i] = listenerPos[i]; + move32(); + move32(); + move32(); + move16(); } } + /* Check if combined orientation is enabled */ test(); test(); @@ -1908,14 +2089,31 @@ ivas_error combine_external_and_head_orientations( } hCombinedOrientationData->sr_pose_pred_axis = sr_pose_pred_axis; + + /* Reset external orientations */ + IF( hExtOrientationData != NULL ) + { + FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) + { + hExtOrientationData->Quaternions[i] = identity; + move32(); + move32(); + move32(); + move32(); + move16(); + } + } + return IVAS_ERR_OK; } + /*------------------------------------------------------------------------- * external_target_interpolation() * * *------------------------------------------------------------------------*/ + static void external_target_interpolation_fx( EXTERNAL_ORIENTATION_HANDLE hExtOrientationData, /* i : external orientation handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ @@ -1937,42 +2135,68 @@ static void external_target_interpolation_fx( /* Set the received orientation as the target */ hCombinedOrientationData->Quaternions_ext_interpolation_target = hExtOrientationData->Quaternions[i]; + move32(); + move32(); + move32(); + move32(); + move16(); /* Use the most recent external orientation as the starting orientation */ IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 1 ) ) { - IF( i > 0 ) + IF( GT_16( i, 0 ) ) { IF( hExtOrientationData->enableExternalOrientation[i - 1] == 0 ) { - IVAS_QUATERNION identity; - identity.w_fx = ONE_IN_Q31; + /* Set to identity */ + hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx = ONE_IN_Q31; + hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx = 0; + hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx = 0; + hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx = 0; + hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact = 31; move32(); - identity.x_fx = identity.y_fx = identity.z_fx = 0; move32(); move32(); move32(); - identity.q_fact = 31; move16(); - hCombinedOrientationData->Quaternions_ext_interpolation_start = identity; } ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i - 1], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; + move32(); + move32(); + move32(); + move32(); + move16(); } ELSE { hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[i - 1]; + move32(); + move32(); + move32(); + move32(); + move16(); } } ELSE { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_prev_extOrientation; + move32(); + move32(); + move32(); + move32(); + move16(); } } ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; + move32(); + move32(); + move32(); + move32(); + move16(); } Word16 tmp_e = 0; move16(); 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 b0a1f27be03c5d34442683aed2879e5ce2003e6e..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" @@ -852,6 +850,8 @@ typedef struct ivas_combined_orientation_struct Word16 cur_subframe_samples_rendered; Word16 subframe_idx_start; Word16 cur_subframe_samples_rendered_start; + bool isDiegeticInputPI[1 + IVAS_MAX_NUM_OBJECTS]; + bool isDiegeticInputPISet; } COMBINED_ORIENTATION_DATA, *COMBINED_ORIENTATION_HANDLE; @@ -1163,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; @@ -1697,10 +1688,8 @@ typedef struct ivas_dirac_ana_data_structure typedef struct ivas_masa_prerend_data_structure { -#ifdef NONBE_1344_REND_MASA_LOW_FS Word16 nbands; Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; -#endif /* CLDFB analysis */ Word16 num_Cldfb_instances; 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 5866c31adc6b272694b7eefa339ba6030c8b09a8..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 @@ -78,7 +78,6 @@ static Word16 ivas_td_ringbuf_has_space_for_num_samples( } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP static void ivas_td_ringbuf_push_interleaved( TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ const Word32 *data, /* i : Input audio in interleaved channels layout */ @@ -118,7 +117,6 @@ static void ivas_td_ringbuf_push_interleaved( return; } -#endif /*-----------------------------------------------------------------------* @@ -211,7 +209,6 @@ void ivas_TD_RINGBUF_Close( } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PushInterleaved() * @@ -241,45 +238,24 @@ void ivas_TD_RINGBUF_PushChannels( const Word32 *p_channels[], /* i : Array of pointers to each input channel */ const Word16 num_samples_per_channel /* i : Number of samples per channel to push */ ) -#else -/*---------------------------------------------------------------------* - * ivas_TD_RINGBUF_Push() - * - * Push samples onto the back of the TD ring buffer. - * Returns total number of buffered samples (includes number of channels) - *---------------------------------------------------------------------*/ - -void ivas_TD_RINGBUF_Push( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const Word32 *data, /* i : Input data */ - const Word16 num_samples_per_channel /* i : Number of samples per channel to store */ -) -#endif { Word32 s; Word16 c; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP assert( h != NULL ); assert( p_channels != NULL ); for ( c = 0; c < h->num_channels; ++c ) /* Not using BASOP FOR because this loops only does assertions */ { assert( p_channels[c] != NULL ); } -#endif assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) ); FOR( s = 0; s < num_samples_per_channel; ++s ) { FOR( c = 0; c < h->num_channels; ++c ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP h->data[h->write_pos] = p_channels[c][s]; move32(); -#else - h->data[h->write_pos] = data[L_mac0( s, c, num_samples_per_channel )]; - move32(); -#endif h->write_pos = L_add( h->write_pos, 1 ); if ( EQ_32( h->write_pos, h->capacity ) ) @@ -300,7 +276,6 @@ void ivas_TD_RINGBUF_Push( } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PushConstant() * @@ -317,55 +292,8 @@ void ivas_TD_RINGBUF_PushConstant( return; } -#else -/*---------------------------------------------------------------------* - * ivas_TD_RINGBUF_PushZeros() - * - * Push zero samples onto the back of the TD ring buffer. - *---------------------------------------------------------------------*/ - -void ivas_TD_RINGBUF_PushZeros( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - const Word16 num_samples_per_channel /* i : Number of zeros per channel to store */ -) -{ - Word32 s; - Word16 c; - assert( ivas_td_ringbuf_has_space_for_num_samples( h, num_samples_per_channel * h->num_channels ) ); - IF( !num_samples_per_channel ) - { - return; - } - - FOR( s = 0; s < num_samples_per_channel; ++s ) - { - FOR( c = 0; c < h->num_channels; ++c ) - { - h->data[h->write_pos] = 0; - move32(); - h->write_pos = L_add( h->write_pos, 1 ); - IF( EQ_32( h->write_pos, h->capacity ) ) - { - h->write_pos = 0; - move32(); - } - } - } - - if ( EQ_32( h->read_pos, h->write_pos ) ) - { - h->is_full = 1; - move16(); - } - - return; -} -#endif - - -#ifdef FIX_1119_SPLIT_RENDERING_VOIP /*---------------------------------------------------------------------* * ivas_TD_RINGBUF_PopChannels() * @@ -377,44 +305,24 @@ void ivas_TD_RINGBUF_PopChannels( Word32 *p_channels[], /* i : Array of pointers to each output channel */ const Word16 num_samples_per_channel /* i : Number of samples per channel to pop */ ) -#else -/*---------------------------------------------------------------------* - * ivas_TD_RINGBUF_Pop() - * - * Pop samples from the front of the TD ring buffer. - *---------------------------------------------------------------------*/ - -void ivas_TD_RINGBUF_Pop( - TD_RINGBUF_HANDLE h, /* i/o: Ring buffer handle */ - Word32 *data, /* i : Output data */ - const Word16 num_samples_per_channel /* i : Number of samples per channel to retrieve */ -) -#endif { Word32 s; Word16 c; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP assert( h != NULL ); assert( p_channels != NULL ); for ( c = 0; c < h->num_channels; ++c ) /* Not using BASOP FOR because this loops only does assertions */ { assert( p_channels[c] != NULL ); } -#endif assert( ivas_td_ringbuf_total_size( h ) >= num_samples_per_channel * h->num_channels ); FOR( s = 0; s < num_samples_per_channel; ++s ) { FOR( c = 0; c < h->num_channels; ++c ) { -#ifdef FIX_1119_SPLIT_RENDERING_VOIP p_channels[c][s] = h->data[h->read_pos]; move32(); -#else - data[L_mac0( s, c, num_samples_per_channel )] = h->data[h->read_pos]; - move32(); -#endif ++h->read_pos; IF( EQ_32( h->read_pos, h->capacity ) ) @@ -425,19 +333,11 @@ void ivas_TD_RINGBUF_Pop( } } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP IF( NE_16( num_samples_per_channel, 0 ) ) { h->is_full = 0; move16(); } -#else - IF( h->is_full ) - { - h->is_full = 0; - move16(); - } -#endif return; } 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 f5f1d86cb1b094ec3825b8a4aee70ab36e224987..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 @@ -152,11 +151,9 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( const IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for input */ ); -#ifdef NONBE_1377_REND_DIRATT_CONF ivas_error IVAS_REND_SetObjectIDs( IVAS_REND_HANDLE hIvasRend /* i/o: Renderer handle */ ); -#endif ivas_error IVAS_REND_SetInputGain_fx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ @@ -271,6 +268,16 @@ ivas_error IVAS_REND_FeedRenderConfig( const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ ); +ivas_error IVAS_REND_GetReverbRoomSize( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + IVAS_ROOM_SIZE_T *reverbRoomSize /* o : Reverb room size */ +); + +ivas_error IVAS_REND_SetReverbRoomSize( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const IVAS_ROOM_SIZE_T reverbRoomSize /* i : Reverb room size */ +); + ivas_error IVAS_REND_FeedSplitBinauralBitstream( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -292,9 +299,10 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( ivas_error IVAS_REND_GetSplitRendBitstreamHeader( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ ISAR_SPLIT_REND_CODEC *pCodec, /* o : pointer to codec setting */ - ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o : pointer to pose correction mode */ + ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o : pointer to pose correction mode */ Word16 *pCodec_frame_size_ms, /* o : pointer to codec frame size setting */ - Word16 *pIsar_frame_size_ms /* o : pointer to ISAR frame size setting */ + Word16 *pIsar_frame_size_ms, /* o : pointer to ISAR frame size setting */ + Word16 *pLc3plusHighRes /* o : pointer to LC3plus High-Res setting */ ); ivas_error IVAS_REND_SetHeadRotation( @@ -336,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 b8e282d914658b815285586bea091ffa972bfe0d..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,9 +94,9 @@ 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; } rendering_context; /* Common base for input structs */ @@ -135,9 +130,7 @@ typedef struct Word32 nonDiegeticPanGain_fx; /* Q31 */ OMASA_ANA_HANDLE hOMasa; UWord16 total_num_objects; -#ifdef NONBE_1377_REND_DIRATT_CONF Word16 object_id; -#endif Word16 ism_metadata_delay_ms_fx; /* Q0 */ } input_ism; @@ -222,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; @@ -232,7 +224,7 @@ struct IVAS_REND Word8 rendererConfigEnabled; RENDER_CONFIG_DATA *hRendererConfig; /* Renderer config pointer */ - + IVAS_DefaultReverbSize selectedRoomReverbSize; #ifdef DEBUGGING Word32 numClipping; /* Counter of clipped output samples */ #endif @@ -1371,9 +1363,9 @@ 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; return ctx; } @@ -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; } @@ -1648,11 +1647,9 @@ static ivas_error alignInputDelay( input_ism *inputIsm; Word16 maxGlobalDelaySamples, numSamplesToPush, numSamplesToPop; UWord16 ringBufferSize, preDelay; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word16 i; const Word32 *p_read_channels[MAX_INPUT_CHANNELS]; Word32 *p_write_channels[MAX_INPUT_CHANNELS]; -#endif maxGlobalDelaySamples = latencyNsToSamples( sampleRateOut, maxGlobalDelayNs ); maxGlobalDelaySamples = shl( maxGlobalDelaySamples, cldfb2tdSampleShift ); @@ -1677,11 +1674,7 @@ static ivas_error alignInputDelay( /* for the first frame we need to push zeros to align the input delay to the global delay * and then push a frame of actual data */ -#ifdef FIX_1119_SPLIT_RENDERING_VOIP ivas_TD_RINGBUF_PushConstant( inputBase->delayBuffer, 0, preDelay ); -#else - ivas_TD_RINGBUF_PushZeros( inputBase->delayBuffer, preDelay ); -#endif /* for ISM inputs, ensure the metadata sync delay is updated */ IF( getAudioConfigType( inputBase->inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED ) @@ -1715,7 +1708,6 @@ static ivas_error alignInputDelay( move16(); } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP FOR( i = 0; i < inputAudio.config.numChannels; ++i ) { Word32 tmp; @@ -1733,10 +1725,6 @@ static ivas_error alignInputDelay( p_write_channels[i] = inputBase->inputBuffer.data_fx + tmp; } ivas_TD_RINGBUF_PopChannels( inputBase->delayBuffer, p_write_channels, numSamplesToPop ); -#else - ivas_TD_RINGBUF_Push( inputBase->delayBuffer, inputAudio.data_fx, numSamplesToPush ); - ivas_TD_RINGBUF_Pop( inputBase->delayBuffer, inputBase->inputBuffer.data_fx, numSamplesToPop ); -#endif } ELSE { @@ -1829,6 +1817,7 @@ static ivas_error setRendInputActiveIsm( FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) { + inputIsm->splitTdRendWrappers[i] = defaultTdRendWrapper(); inputIsm->splitTdRendWrappers[i].hHrtfTD = &hrtfs->hHrtfTD; } @@ -1844,11 +1833,7 @@ static ivas_error setRendInputActiveIsm( test(); IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { -#ifdef NONBE_1377_REND_DIRATT_CONF IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate, inputIsm->object_id, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -1881,11 +1866,7 @@ static ivas_error setRendInputActiveIsm( /* Open TD renderer wrappers */ FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) { -#ifdef NONBE_1377_REND_DIRATT_CONF IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->splitTdRendWrappers[i], inConfig, hRendCfg, NULL, *inputIsm->base.ctx.pOutSampleRate, inputIsm->object_id, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->splitTdRendWrappers[i], inConfig, hRendCfg, NULL, *inputIsm->base.ctx.pOutSampleRate, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -1919,11 +1900,7 @@ static ivas_error setRendInputActiveIsm( } ELSE { -#ifdef NONBE_1377_REND_DIRATT_CONF IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate, inputIsm->object_id, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -2590,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 ) ) { @@ -2709,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 ) @@ -2730,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: @@ -2788,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; @@ -2861,11 +2913,7 @@ static ivas_error initMcBinauralRendering( { Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; -#ifdef NONBE_1377_REND_DIRATT_CONF IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputMc->tdRendWrapper, inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate, 0, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputMc->tdRendWrapper, inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -2901,11 +2949,7 @@ static ivas_error initMcBinauralRendering( /* Open TD renderer wrappers */ FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) { -#ifdef NONBE_1377_REND_DIRATT_CONF IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputMc->splitTdRendWrappers[i], inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate, 0, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = ivas_td_binaural_open_ext_fx( &inputMc->splitTdRendWrappers[i], inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -3141,6 +3185,7 @@ static ivas_error setRendInputActiveMc( test(); FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) { + inputMc->splitTdRendWrappers[i] = defaultTdRendWrapper(); if ( hrtfs->hHrtfTD ) { inputMc->splitTdRendWrappers[i].binaural_latency_ns = L_shr_r( Mpy_32_32_r( hrtfs->hHrtfTD->latency_s_fx, 1000000000 ), hrtfs->hHrtfTD->latency_s_Q_fx ); @@ -3647,6 +3692,8 @@ ivas_error IVAS_REND_Open( move32(); hIvasRend->efapOutWrapper.pCustomLsSetup = NULL; move32(); + hIvasRend->selectedRoomReverbSize = DEFAULT_REVERB_UNSET; + move32(); hIvasRend->num_subframes = num_subframes; move16(); @@ -3818,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; } @@ -3842,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; } @@ -4184,7 +4238,6 @@ static ivas_error getConstInputById( return IVAS_ERR_OK; } -#ifdef CODE_IMPROVEMENTS static void *getInputByIndex_fx( void *inputsArray, const size_t index, @@ -4209,57 +4262,31 @@ static void *getInputByIndex_fx( /* include a final return to make the linter happy and avoid problems with wmc_tool (see #1355) */ return NULL; } -#endif static ivas_error findFreeInputSlot_fx( -#ifdef CODE_IMPROVEMENTS void *inputs, const IVAS_REND_AudioConfigType inputType, -#else - const void *inputs, - const int32_t inputStructSize, -#endif const Word32 maxInputs, Word32 *inputIndex ) { -#ifdef CODE_IMPROVEMENTS /* Using a void pointer and a separately provided type is a hack for this function to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). Assumptions: - input_base is always the first member in the input struct - memory alignments of original input type and input_base are the same */ -#else - /* Using a void pointer and a separately provided size is a hack for this function - to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). - Assumptions: - - input_base is always the first member in the input struct - - provided size is correct - */ -#endif Word32 i; bool canAddInput; -#ifndef CODE_IMPROVEMENTS - const UWord8 *pByte; -#endif const input_base *pInputBase; canAddInput = false; move16(); /* Find first unused input in array */ -#ifdef CODE_IMPROVEMENTS FOR( i = 0; i < maxInputs; ++i ) -#else - FOR( i = 0, pByte = inputs; i < maxInputs; ++i, pByte += inputStructSize ) -#endif { -#ifdef CODE_IMPROVEMENTS pInputBase = (const input_base *) getInputByIndex_fx( inputs, i, inputType ); -#else - pInputBase = (const input_base *) pByte; -#endif IF( EQ_32( pInputBase->inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) { @@ -4427,6 +4454,105 @@ static ivas_error isar_pre_rend_init( } +/*------------------------------------------------------------------------- + * Function getDefaultReverbSize() + * + * + *------------------------------------------------------------------------*/ + +static IVAS_ROOM_SIZE_T getDefaultReverbSize( + input_ism *ismInputs, + input_masa *masaInputs, + input_mc *mcInputs, + input_sba *sbaInputs ) +{ + bool combinedFormat; + Word16 i; + Word16 nActiveInputsIsm, nActiveInputsMasa, nActiveInputsSba, nActiveInputsMc; + IVAS_ROOM_SIZE_T selectedReverb; + selectedReverb = IVAS_ROOM_SIZE_MEDIUM; + move32(); + + combinedFormat = false; + nActiveInputsIsm = 0; + nActiveInputsMasa = 0; + nActiveInputsMc = 0; + nActiveInputsSba = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + + FOR( i = 0; i < RENDERER_MAX_ISM_INPUTS; i++ ) + { + IF( NE_32( ismInputs[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + nActiveInputsIsm = add( nActiveInputsIsm, 1 ); + } + } + FOR( i = 0; i < RENDERER_MAX_MASA_INPUTS; i++ ) + { + IF( NE_32( masaInputs[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + nActiveInputsMasa = add( nActiveInputsMasa, 1 ); + } + } + FOR( i = 0; i < RENDERER_MAX_MC_INPUTS; i++ ) + { + IF( NE_32( mcInputs[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + nActiveInputsMc = add( nActiveInputsMc, 1 ); + } + } + FOR( i = 0; i < RENDERER_MAX_SBA_INPUTS; i++ ) + { + IF( NE_32( sbaInputs[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + { + nActiveInputsSba = add( nActiveInputsSba, 1 ); + } + } + + /* ISM present with MASA/SBA inputs; treat as combined format */ + test(); + test(); + IF( nActiveInputsIsm && ( nActiveInputsMasa || nActiveInputsSba ) ) + { + combinedFormat = true; + move16(); + } + + IF( combinedFormat ) + { + selectedReverb = IVAS_ROOM_SIZE_MEDIUM; + move32(); + } + ELSE + { + /* Only set large if ISM is present alone */ + test(); + IF( nActiveInputsIsm && !nActiveInputsMc ) + { + selectedReverb = IVAS_ROOM_SIZE_LARGE; + move32(); + } + /* if only MC is present, set medium; Will not be overridden by the subsequent block */ + ELSE IF( nActiveInputsMc ) + { + selectedReverb = IVAS_ROOM_SIZE_MEDIUM; + move32(); + } + ELSE IF( nActiveInputsMasa || nActiveInputsSba ) + { + selectedReverb = IVAS_ROOM_SIZE_SMALL; + move32(); + } + } + + return selectedReverb; +} + + /*-------------------------------------------------------------------* * IVAS_REND_AddInput() * @@ -4442,11 +4568,7 @@ ivas_error IVAS_REND_AddInput_fx( ivas_error error; Word32 maxNumInputsOfType; void *inputsArray; -#ifdef CODE_IMPROVEMENTS IVAS_REND_AudioConfigType inputType; -#else - Word32 inputStructSize; -#endif ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA *, hrtf_handles *hrtfs ); void ( *setInputDelay )( void *, bool ); Word32 inputIndex; @@ -4481,19 +4603,12 @@ ivas_error IVAS_REND_AddInput_fx( } -#ifdef CODE_IMPROVEMENTS inputType = getAudioConfigType( inConfig ); SWITCH( inputType ) -#else - SWITCH( getAudioConfigType( inConfig ) ) -#endif { case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS; inputsArray = hIvasRend->inputsIsm; -#ifndef CODE_IMPROVEMENTS - inputStructSize = sizeof( *hIvasRend->inputsIsm ); -#endif activateInput = setRendInputActiveIsm; setInputDelay = setRendInputDelayIsm; move32(); @@ -4502,9 +4617,6 @@ ivas_error IVAS_REND_AddInput_fx( case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: maxNumInputsOfType = RENDERER_MAX_MC_INPUTS; inputsArray = hIvasRend->inputsMc; -#ifndef CODE_IMPROVEMENTS - inputStructSize = sizeof( *hIvasRend->inputsMc ); -#endif activateInput = setRendInputActiveMc; setInputDelay = setRendInputDelayMc; move32(); @@ -4513,9 +4625,6 @@ ivas_error IVAS_REND_AddInput_fx( case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS; inputsArray = hIvasRend->inputsSba; -#ifndef CODE_IMPROVEMENTS - inputStructSize = sizeof( *hIvasRend->inputsSba ); -#endif activateInput = setRendInputActiveSba; setInputDelay = setRendInputDelaySba; move32(); @@ -4524,9 +4633,6 @@ ivas_error IVAS_REND_AddInput_fx( case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS; inputsArray = hIvasRend->inputsMasa; -#ifndef CODE_IMPROVEMENTS - inputStructSize = sizeof( *hIvasRend->inputsMasa ); -#endif activateInput = setRendInputActiveMasa; setInputDelay = setRendInputDelayMasa; move32(); @@ -4536,36 +4642,34 @@ ivas_error IVAS_REND_AddInput_fx( return IVAS_ERR_INVALID_INPUT_FORMAT; } - /* Find first free input in array corresponding to input type */ -#ifdef CODE_IMPROVEMENTS + /* Find first free input in array corresponding to input type */ IF( NE_32( ( error = findFreeInputSlot_fx( inputsArray, inputType, maxNumInputsOfType, &inputIndex ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = findFreeInputSlot_fx( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ), IVAS_ERR_OK ) ) -#endif { return error; } *inputId = makeInputId( inConfig, inputIndex ); move16(); -#ifdef CODE_IMPROVEMENTS IF( NE_32( ( error = activateInput( getInputByIndex_fx( inputsArray, inputIndex, inputType ), inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ), IVAS_ERR_OK ) ) -#else - IF( NE_32( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ), IVAS_ERR_OK ) ) -#endif { return error; } -#ifdef CODE_IMPROVEMENTS setInputDelay( getInputByIndex_fx( inputsArray, inputIndex, inputType ), splitPreRendCldfb ); -#else - setInputDelay( (Word8 *) inputsArray + inputStructSize * inputIndex, splitPreRendCldfb ); -#endif /* set global maximum delay after adding an input */ setMaxGlobalDelayNs( hIvasRend ); + /* select default reverb size after adding an input */ + IF( EQ_32( hIvasRend->selectedRoomReverbSize, DEFAULT_REVERB_UNSET ) ) + { + IVAS_REND_SetReverbRoomSize( hIvasRend, + getDefaultReverbSize( hIvasRend->inputsIsm, + hIvasRend->inputsMasa, + hIvasRend->inputsMc, + hIvasRend->inputsSba ) ); + } + return IVAS_ERR_OK; } @@ -4635,7 +4739,6 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( return IVAS_ERR_OK; } -#ifdef NONBE_1377_REND_DIRATT_CONF /*-------------------------------------------------------------------* * IVAS_REND_SetObjectIDs() @@ -4663,7 +4766,6 @@ ivas_error IVAS_REND_SetObjectIDs( return IVAS_ERR_OK; } -#endif /*-------------------------------------------------------------------* * IVAS_REND_SetInputGain() @@ -4975,14 +5077,19 @@ ivas_error IVAS_REND_FeedInputAudio_fx( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - test(); - cldfb2tdShift = ( inputAudio.config.is_cldfb ) ? 1 : 0; + cldfb2tdShift = 0; + move16(); + if ( inputAudio.config.is_cldfb ) + { + cldfb2tdShift = 1; + move16(); + } test(); test(); test(); test(); - IF( inputAudio.config.numSamplesPerChannel <= 0 || ( L_FRAME_MAX < inputAudio.config.numSamplesPerChannel && inputAudio.config.is_cldfb == 0 ) || + IF( inputAudio.config.numSamplesPerChannel <= 0 || ( LT_16( L_FRAME_MAX, inputAudio.config.numSamplesPerChannel ) && inputAudio.config.is_cldfb == 0 ) || ( ( shl( L_FRAME_MAX, cldfb2tdShift ) ) < inputAudio.config.numSamplesPerChannel && inputAudio.config.is_cldfb == 1 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Buffer size outside of supported range" ); @@ -4994,6 +5101,8 @@ ivas_error IVAS_REND_FeedInputAudio_fx( return IVAS_ERR_WRONG_NUM_CHANNELS; } + test(); + test(); test(); move32(); // move added for typecasting IF( EQ_32( getAudioConfigType( hIvasRend->outputConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) && @@ -5226,6 +5335,8 @@ ivas_error IVAS_REND_GetRenderConfig( } hRCin = hIvasRend->hRendererConfig; + hRCout->roomAcoustics.aeID = hRCin->roomAcoustics.aeID; + move16(); hRCout->roomAcoustics.nBands = hRCin->roomAcoustics.nBands; hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx; hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx; @@ -5254,9 +5365,7 @@ ivas_error IVAS_REND_GetRenderConfig( move16(); move32(); -#ifdef FIX_1053_REVERB_RECONFIGURATION Copy32( hRCin->distAtt_fx, hRCout->distAtt_fx, 3 ); -#endif return IVAS_ERR_OK; } @@ -5289,6 +5398,8 @@ ivas_error IVAS_REND_FeedRenderConfig( hRenderConfig = hIvasRend->hRendererConfig; + hRenderConfig->roomAcoustics.aeID = renderConfig.roomAcoustics.aeID; + move16(); hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands; move16(); hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx; @@ -5299,9 +5410,7 @@ ivas_error IVAS_REND_FeedRenderConfig( Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); -#ifdef FIX_1053_REVERB_RECONFIGURATION Copy32( renderConfig.distAtt_fx, hRenderConfig->distAtt_fx, 3 ); -#endif hRenderConfig->roomAcoustics.use_er = 0; move16(); @@ -5612,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() * @@ -5783,11 +5875,90 @@ ivas_error IVAS_REND_CombineHeadAndExternalOrientation( /*---------------------------------------------------------------------* - * IVAS_REND_GetCombinedOrientation() + * IVAS_REND_GetReverbRoomSize() * * *---------------------------------------------------------------------*/ +ivas_error IVAS_REND_GetReverbRoomSize( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + IVAS_ROOM_SIZE_T *reverbRoomSize /* o : Reverb room size */ +) +{ + SWITCH( hIvasRend->selectedRoomReverbSize ) + { + case DEFAULT_REVERB_SMALL: + *reverbRoomSize = IVAS_ROOM_SIZE_SMALL; + move32(); + BREAK; + case DEFAULT_REVERB_MEDIUM: + *reverbRoomSize = IVAS_ROOM_SIZE_MEDIUM; + move32(); + BREAK; + case DEFAULT_REVERB_LARGE: + *reverbRoomSize = IVAS_ROOM_SIZE_LARGE; + move32(); + BREAK; + case DEFAULT_REVERB_UNSET: + default: + *reverbRoomSize = IVAS_ROOM_SIZE_AUTO; + move32(); + BREAK; + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * IVAS_REND_SetReverbRoomSize() + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_REND_SetReverbRoomSize( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_ROOM_SIZE_T reverbRoomSize /* i : Reverb room size */ +) +{ + ivas_error error; + + SWITCH( reverbRoomSize ) + { + case IVAS_ROOM_SIZE_SMALL: + hIvasRend->selectedRoomReverbSize = DEFAULT_REVERB_SMALL; + move32(); + BREAK; + case IVAS_ROOM_SIZE_MEDIUM: + hIvasRend->selectedRoomReverbSize = DEFAULT_REVERB_MEDIUM; + move32(); + BREAK; + case IVAS_ROOM_SIZE_LARGE: + hIvasRend->selectedRoomReverbSize = DEFAULT_REVERB_LARGE; + move32(); + BREAK; + case IVAS_ROOM_SIZE_AUTO: + default: + hIvasRend->selectedRoomReverbSize = DEFAULT_REVERB_UNSET; + move32(); + BREAK; /* will be setup in IVAS_REND_AddInput() */ + } + + IF( hIvasRend->hRendererConfig != NULL ) + { + IF( EQ_32( error = ivas_render_config_change_defaults( hIvasRend->hRendererConfig, hIvasRend->selectedRoomReverbSize ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + return IVAS_ERR_OK; +} + /*-------------------------------------------------------------------* * Local functions @@ -5802,6 +5973,17 @@ ivas_error IVAS_REND_CombineHeadAndExternalOrientation( 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, @@ -6148,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 ); } } @@ -6305,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, @@ -6317,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 ) @@ -6345,13 +6527,20 @@ static Word16 getNumSubframesInBuffer( const IVAS_REND_AudioBuffer *buffer, const Word32 sampleRate ) { - Word16 cldfb2tdShift; + Word16 cldfb2tdShift, temp, temp_e; - cldfb2tdShift = buffer->config.is_cldfb ? 1 : 0; + cldfb2tdShift = 0; + move16(); + if ( buffer->config.is_cldfb ) + { + cldfb2tdShift = 1; + move16(); + } - Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 /* 1 / FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES in Q31 */ ) ); - temp = BASOP_Util_Divide1616_Scale( buffer->config.numSamplesPerChannel, temp, &scale ); - temp = shr( temp, sub( 15, scale ) ); /* Q0 */ + // temp = ( buffer->config.numSamplesPerChannel / ( sampleRate / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES * cldfb2tdSampleFact ) ); + temp = extract_l( Mpy_32_16_1( sampleRate, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + temp = BASOP_Util_Divide1616_Scale( buffer->config.numSamplesPerChannel, temp, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); // Q0 temp = shr( temp, cldfb2tdShift ); return temp; @@ -6575,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 ) ) @@ -6585,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 ) @@ -6739,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 ); @@ -6886,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 */ @@ -6900,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 ) @@ -7138,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, @@ -7195,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 ) @@ -7282,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 ) ), @@ -7293,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 @@ -7405,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, @@ -7417,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 @@ -7762,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 ) @@ -7773,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 @@ -7891,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: @@ -8427,7 +8647,14 @@ static ivas_error renderInputSba( move32(); inAudio = sbaInput->base.inputBuffer; - cldfb2tdShift = outAudio.config.is_cldfb ? 1 : 0; + cldfb2tdShift = 0; + move16(); + if ( outAudio.config.is_cldfb ) + { + cldfb2tdShift = 1; + move16(); + } + test(); IF( NE_32( L_shl( sbaInput->base.numNewSamplesPerChannel, cldfb2tdShift ), outAudio.config.numSamplesPerChannel ) && NE_32( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { @@ -8649,23 +8876,13 @@ static void renderMasaToMasa( Word16 q_add = sub( 31, add( scale_factor, q_cldfb_out ) ); /* Compute channel energy for metadata processing */ -#ifdef NONBE_1344_REND_MASA_LOW_FS FOR( band_m_idx = 0; band_m_idx < masaInput->hMasaPrerend->nbands; band_m_idx++ ) -#else - FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) -#endif { -#ifdef NONBE_1344_REND_MASA_LOW_FS brange[0] = masaInput->hMasaPrerend->band_grouping[band_m_idx]; move16(); brange[1] = masaInput->hMasaPrerend->band_grouping[band_m_idx + 1]; move16(); -#else - brange[0] = MASA_band_grouping_24[band_m_idx]; - move16(); - brange[1] = MASA_band_grouping_24[band_m_idx + 1]; - move16(); -#endif + FOR( j = brange[0]; j < brange[1]; j++ ) { FOR( i = 0; i < numAnalysisChannels; i++ ) @@ -8798,7 +9015,15 @@ static ivas_error renderInputMasa( inAudio = masaInput->base.inputBuffer; - cldfb2tdShift = outAudio.config.is_cldfb ? 1 : 0; + cldfb2tdShift = 0; + move16(); + if ( outAudio.config.is_cldfb ) + { + cldfb2tdShift = 1; + move16(); + } + test(); + test(); IF( ( NE_32( L_shl( masaInput->base.numNewSamplesPerChannel, cldfb2tdShift ), outAudio.config.numSamplesPerChannel ) ) && NE_32( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { @@ -8827,15 +9052,18 @@ static ivas_error renderInputMasa( ELSE { /* MASA external renderer -> other formats */ - Word16 num_subframes, exp; + Word16 num_subframes, temp, temp_e; + FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { tmpBuffer_fx[ch] = tmpBuffer_buff_fx[ch]; } copyBufferTo2dArray_fx( masaInput->base.inputBuffer, tmpBuffer_buff_fx ); - num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( masaInput->base.inputBuffer.config.numSamplesPerChannel, IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), *masaInput->base.ctx.pOutSampleRate, &exp ); - num_subframes = shr( num_subframes, sub( 15, exp ) ); /* Q0 */ + /* num_subframes = (int16_t) ( masaInput->base.inputBuffer.config.numSamplesPerChannel / ( *masaInput->base.ctx.pOutSampleRate / ( IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) ); */ + temp = extract_l( Mpy_32_16_1( *masaInput->base.ctx.pOutSampleRate, ONE_BY_SUBFR_PER_SEC_Q15 ) ); + temp = BASOP_Util_Divide1616_Scale( masaInput->base.inputBuffer.config.numSamplesPerChannel, temp, &temp_e ); + num_subframes = shr( temp, sub( 15, temp_e ) ); /* Q0 */ IF( EQ_32( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || EQ_32( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) { @@ -8857,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 ); @@ -8882,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 */ @@ -8909,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 ) ); @@ -9374,7 +9606,6 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( Word16 max_bands; Word16 Q_out[2]; Word16 pcm_out_flag; -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word32 *p_Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; Word32 *p_Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX]; Word16 j; @@ -9387,7 +9618,6 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( p_Cldfb_ImagBuffer_Binaural[i][j] = Cldfb_ImagBuffer_Binaural[i][j]; } } -#endif max_bands = 0; move16(); @@ -9487,11 +9717,7 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( } } -#ifdef FIX_1119_SPLIT_RENDERING_VOIP Word16 q1 = 31, q2 = 31, Q_buff; -#else - Word16 q1 = 31, q2 = 31, Q_buff, j; -#endif Word16 num_poses = hIvasRend->splitRendWrapper->multiBinPoseData.num_poses; FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; i++ ) @@ -9532,7 +9758,7 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( } max_bands = extract_l( Mpy_32_32( imult3216( hIvasRend->sampleRateOut, BINAURAL_MAXBANDS ), 44740 /* 1/48000 in Q31 */ ) ); -#ifdef FIX_1119_SPLIT_RENDERING_VOIP + IF( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, hIvasRend->headRotData.headPositions[0], pSplitRendConfig->splitRendBitRate, @@ -9550,25 +9776,6 @@ ivas_error IVAS_REND_GetSplitBinauralBitstream( ro_md_flag, Q_buff, Q_out ) ) != IVAS_ERR_OK ) -#else - IF( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, - hIvasRend->headRotData.headPositions[0], - pSplitRendConfig->splitRendBitRate, - pSplitRendConfig->codec, - pSplitRendConfig->isar_frame_size_ms, - pSplitRendConfig->codec_frame_size_ms, - &bits, - Cldfb_RealBuffer_Binaural, - Cldfb_ImagBuffer_Binaural, - max_bands, - tmpBinaural, - 1, - cldfb_in_flag, - pcm_out_flag, - ro_md_flag, - Q_buff, - Q_out ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -9620,7 +9827,8 @@ ivas_error IVAS_REND_GetSplitRendBitstreamHeader( ISAR_SPLIT_REND_CODEC *pCodec, /* o : pointer to codec setting */ ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o : pointer to pose correction mode */ Word16 *pCodec_frame_size_ms, /* o : pointer to codec frame size setting */ - Word16 *pIsar_frame_size_ms /* o : pointer to ISAR frame size setting */ + Word16 *pIsar_frame_size_ms, /* o : pointer to ISAR frame size setting */ + Word16 *pLc3plusHighRes /* o : pointer to LC3plus High-Res setting */ ) { test(); @@ -9633,6 +9841,7 @@ ivas_error IVAS_REND_GetSplitRendBitstreamHeader( *pCodec_frame_size_ms = hIvasRend->hRendererConfig->split_rend_config.codec_frame_size_ms; *pIsar_frame_size_ms = hIvasRend->hRendererConfig->split_rend_config.isar_frame_size_ms; *poseCorrection = hIvasRend->hRendererConfig->split_rend_config.poseCorrectionMode; + *pLc3plusHighRes = hIvasRend->hRendererConfig->split_rend_config.lc3plus_highres; return IVAS_ERR_OK; } @@ -9701,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; @@ -9777,7 +9984,7 @@ void IVAS_REND_closeCldfb( { IF( cldfbAna[n] != NULL ) { - deleteCldfb_ivas_fx( &( cldfbAna[n] ) ); + deleteCldfb_fx( &( cldfbAna[n] ) ); cldfbAna[n] = NULL; } } @@ -9786,7 +9993,7 @@ void IVAS_REND_closeCldfb( { IF( cldfbSyn[n] != NULL ) { - deleteCldfb_ivas_fx( &( cldfbSyn[n] ) ); + deleteCldfb_fx( &( cldfbSyn[n] ) ); cldfbSyn[n] = NULL; } } @@ -10827,7 +11034,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbAnaRend[i] != NULL ) { - deleteCldfb_ivas_fx( &hMasaExtRend->cldfbAnaRend[i] ); + deleteCldfb_fx( &hMasaExtRend->cldfbAnaRend[i] ); } } @@ -10835,7 +11042,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbSynRend[i] != NULL ) { - deleteCldfb_ivas_fx( &hMasaExtRend->cldfbSynRend[i] ); + deleteCldfb_fx( &hMasaExtRend->cldfbSynRend[i] ); } } @@ -10902,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(); @@ -10941,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(); @@ -10955,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; @@ -11000,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 ) { @@ -11098,7 +11294,7 @@ static ivas_error printConfigInfo_rend( ) { ivas_error error; - Word8 config_str[50]; + Word8 config_str[200]; /*-----------------------------------------------------------------* * Print output audio configuration @@ -11132,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; @@ -11149,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 02ec5de808a8183f04d19a91b18b4620b4df05f5..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 @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include "aeid_file_reader.h" -#ifdef FIX_1053_REVERB_RECONFIGURATION #include "ivas_error_utils.h" #include #include @@ -184,4 +183,3 @@ const char *aeidFileReader_getFilePath( return aeidReader->file_path; } -#endif diff --git a/lib_util/aeid_file_reader.h b/lib_util/aeid_file_reader.h index 6049ecc6b54c75f49e8a12852752e2c0b40c0a03..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 @@ -36,7 +36,6 @@ #include "common_api_types.h" -#ifdef FIX_1053_REVERB_RECONFIGURATION struct aeidFileReader; typedef struct aeidFileReader aeidFileReader; @@ -85,6 +84,4 @@ const char *aeidFileReader_getFilePath( aeidFileReader *aeidReader /* i : aeidFileReader handle */ ); -#endif - #endif /* IVAS_AEID_FILE_READER_H */ 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 7ee96ba06d623a44f9d75cf25f2d9827d84632c3..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include diff --git a/lib_util/evs_rtp_payload.h b/lib_util/evs_rtp_payload.h index 9514677e3aed82f552adb816c6365916985adc79..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #pragma once diff --git a/lib_util/float_to_fix_ops.c b/lib_util/float_to_fix_ops.c new file mode 100644 index 0000000000000000000000000000000000000000..4bab0a6b1d9a7b8012257c039f374a6757ab5314 --- /dev/null +++ b/lib_util/float_to_fix_ops.c @@ -0,0 +1,129 @@ + +#include "common_api_types.h" +#include "float_to_fix_ops.h" +#include +#include + + +#define Q15 15 +#define Q31 31 +#define ONE_IN_Q31 0x7fffffff +#define MAX16B 32767 +#define MIN16B ( -32768 ) +#define MAXVAL_WORD32 ( (int32_t) 0x7FFFFFFF ) + + +Word32 float_to_fix( + float number, + const Word32 Q ) +{ + assert( Q >= 0 ); + if ( number == 1.0f && Q == Q31 ) + { + return ONE_IN_Q31; + } + if ( isnan( number ) ) + { + number = 0; + } + assert( fabs( number ) < pow( 2, 31 - Q ) ); + Word32 ret = (Word32) ( number * ( (UWord32) 1 << Q ) ); + + return ret; +} + + +Word16 float_to_fix16( + const float number, + const Word16 Q ) +{ + assert( Q >= 0 ); + if ( isnan( number ) ) + return 0; + if ( number == 1.0f && Q == Q15 ) + return MAX16B; + if ( number == -1.0f && Q == Q15 ) + return MIN16B; + assert( fabs( number ) < pow( 2, 15 - Q ) ); + Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) ); + + return ret; +} + + +Word32 floatToFixed( + const float f, + const Word16 Q ) +{ + Word64 result_32; + + if ( f == 1.0f && Q == Q15 ) + return MAX16B; + if ( f == 1.0f && Q == Q31 ) + return MAXVAL_WORD32; + if ( Q < 0 ) + result_32 = (Word64) ( (float) ( f ) / (double) ( (unsigned Word64) 1 << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); + else + result_32 = (Word64) ( f * (double) ( (unsigned Word64) 1 << Q ) + ( f >= 0 ? 0.5 : -0.5 ) ); + if ( result_32 > MAX_32 ) + return MAX_32; + if ( result_32 < MIN_32 ) + return MIN_32; + + return (Word32) result_32; +} + +float fixedToFloat( + const Word32 i, + const Word16 Q ) +{ + if ( Q < 0 ) + return ( i * (float) ( ( 1LL ) << ( -Q ) ) ); + else + return (float) ( i ) / (float) ( 1LL << Q ); +} + + +float fix16_to_float( + const Word16 number, + const Word16 Q ) +{ + assert( Q >= 0 ); + float ret = (float) number / ( (UWord16) 1 << Q ); + + return ret; +} + + +Word32 floatToFixed_32( + const float number, + const Word16 Q ) +{ + float val = 0.0f; + assert( abs_s( Q ) <= 63 ); + if ( abs_s( Q ) > 31 ) + { + if ( Q > 0 ) + { + val = ( number * ( (unsigned int) MAX_32 + 1 ) ) * ( 1 << ( Q - 31 ) ); + } + else + { + val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int) MIN_32; + } + if ( val >= 0.0f ) + { + assert( (Word32) val <= MAX_32 ); + } + else + { + assert( (Word32) val >= MIN_32 ); + } + } + else + { + return floatToFixed( number, Q ); + } + + return (Word32) val; +} diff --git a/lib_util/float_to_fix_ops.h b/lib_util/float_to_fix_ops.h new file mode 100644 index 0000000000000000000000000000000000000000..0cd23cbc687c24b8026a754c0acbd320a466c14f --- /dev/null +++ b/lib_util/float_to_fix_ops.h @@ -0,0 +1,19 @@ + +#include "common_api_types.h" + +#ifndef FLOAT_TO_FIX_OPS_H +#define FLOAT_TO_FIX_OPS_H + +Word32 float_to_fix( float number, const Word32 Q ); + +Word16 float_to_fix16( const float number, const Word16 Q ); + +Word32 floatToFixed( const float f, const Word16 Q ); + +Word32 floatToFixed_32( const float number, const Word16 Q ); + +float fixedToFloat( const Word32 i, const Word16 Q ); + +float fix16_to_float( const Word16 number, const Word16 Q ); + +#endif /* FLOAT_TO_FIX_OPS_H */ diff --git a/lib_util/g192.c b/lib_util/g192.c index 898e9753d6c4cf90605ff77fec5993afe68c2748..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include "g192.h" @@ -482,7 +482,7 @@ G192_ERROR G192_WriteVoipFrame_short( const uint16_t *serial, const int16_t numBits, uint16_t const rtpSequenceNumber, - uint16_t const rtpTimeStamp, + uint32_t const rtpTimeStamp, uint32_t const rcvTime_ms ) { int16_t G192_HEADER[2], G192_DATA[IVAS_MAX_BITS_PER_FRAME]; diff --git a/lib_util/g192.h b/lib_util/g192.h index 62eeaae8f1f042491341693c6949ea0ec9981e43..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #ifndef G192_H @@ -93,7 +93,7 @@ G192_ERROR G192_Writer_Open_filename( G192_HANDLE *phG192, const char *filename G192_ERROR G192_WriteFrame( G192_HANDLE const hG192, const uint16_t *serial, const int16_t numBits ); -G192_ERROR G192_WriteVoipFrame_short( G192_HANDLE const hG192, const uint16_t *serial, const int16_t num_bits, uint16_t const rtpSequenceNumber, uint16_t const rtpTimeStamp, uint32_t const rcvTime_ms ); +G192_ERROR G192_WriteVoipFrame_short( G192_HANDLE const hG192, const uint16_t *serial, const int16_t num_bits, uint16_t const rtpSequenceNumber, uint32_t const rtpTimeStamp, uint32_t const rcvTime_ms ); G192_ERROR G192_Writer_Close( G192_HANDLE *phG192 ); 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 aa9c62661687a10033b358f3f9eaaaa44743cb3c..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 @@ -34,12 +34,19 @@ #include "cmdl_tools.h" #include #include -#include "prot_fx.h" +#include "float_to_fix_ops.h" + #define META_LINE_LENGTH 200 /* max number of characters at one line of metadata input/output file */ #define NUM_ISM_METADATA_PER_LINE 8 /* Number of ISM metadata per line in a metadata file */ #define NUM_MIN_ISM_METADATA 1 /* Minimum number of metadata parameters (azimuth) */ +#define Q9 9 +#define Q22 22 +#define Q31 31 +#define DEG_360_IN_Q22 ( 360 << Q22 ) /* Q22 */ +#define DEG_180_IN_Q22 ( 180 << Q22 ) /* Q22 */ +#define DEG_90_IN_Q22 ( 90 << Q22 ) /* Q22 */ struct IsmFileReader { @@ -148,18 +155,7 @@ ivas_error IsmFileReader_readNextFrame( /* Invalid number of metadata parameters (2-7 supported) */ return IVAS_ERR_ISM_FILE_READER_INVALID_METADATA_FORMAT; } -#ifndef FIX_2084_FLOATING_POINT_LEFTOVERS - ismMetadata->azimuth = meta_prm[0]; - ismMetadata->elevation = meta_prm[1]; - ismMetadata->radius = meta_prm[2]; - ismMetadata->spread = meta_prm[3]; - ismMetadata->gainFactor = meta_prm[4]; - ismMetadata->yaw = meta_prm[5]; - ismMetadata->pitch = meta_prm[6]; - ismMetadata->non_diegetic_flag = (int16_t) meta_prm[7]; -#else ismMetadata->non_diegetic_flag = (Word16) meta_prm[7]; -#endif ismMetadata->azimuth_fx = floatToFixed( meta_prm[0], Q22 ); ismMetadata->elevation_fx = floatToFixed( meta_prm[1], Q22 ); ismMetadata->radius_fx = (Word16) floatToFixed( meta_prm[2], Q9 ); @@ -174,59 +170,37 @@ ivas_error IsmFileReader_readNextFrame( return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( GT_32( ismMetadata->azimuth_fx, DEG_180_IN_Q22 ) || LT_32( ismMetadata->azimuth_fx, -DEG_180_IN_Q22 ) ) -#else - if ( ismMetadata->azimuth > 180 || ismMetadata->azimuth < -180 ) -#endif + if ( ( ismMetadata->azimuth_fx > DEG_180_IN_Q22 ) || ( ismMetadata->azimuth_fx < -DEG_180_IN_Q22 ) ) { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( GT_32( ismMetadata->elevation_fx, DEG_90_IN_Q22 ) || LT_32( ismMetadata->elevation_fx, -DEG_90_IN_Q22 ) ) -#else - if ( ismMetadata->elevation > 90 || ismMetadata->elevation < -90 ) -#endif + + if ( ( ismMetadata->elevation_fx > DEG_90_IN_Q22 ) || ( ismMetadata->elevation_fx < -DEG_90_IN_Q22 ) ) { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( LT_32( ismMetadata->radius_fx, 0 ) ) /* Negative radius not supported. Max quantized radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */ -#else - if ( ismMetadata->radius < 0 ) /* Negative radius not supported. Max quantized radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */ -#endif + + if ( ismMetadata->radius_fx < 0 ) /* Negative radius not supported. Max quantized radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */ { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( GT_32( ismMetadata->spread_fx, DEG_360_IN_Q22 ) || LT_32( ismMetadata->spread_fx, 0 ) ) -#else - if ( ismMetadata->spread > 360 || ismMetadata->spread < 0 ) -#endif + + if ( ( ismMetadata->spread_fx > DEG_360_IN_Q22 ) || ( ismMetadata->spread_fx < 0 ) ) { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( /*GT_32( ismMetadata->gainFactor_fx, ONE_IN_Q31 ) ||*/ LT_32( ismMetadata->gainFactor_fx, 0 ) ) -#else - if ( ismMetadata->gainFactor > 1 || ismMetadata->gainFactor < 0 ) -#endif + + if ( /*( ismMetadata->gainFactor_fx > ONE_IN_Q31 ) ||*/ ( ismMetadata->gainFactor_fx < 0 ) ) { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( GT_32( ismMetadata->yaw_fx, DEG_180_IN_Q22 ) || LT_32( ismMetadata->yaw_fx, -DEG_180_IN_Q22 ) ) -#else - if ( ismMetadata->yaw > 180 || ismMetadata->yaw < -180 ) -#endif + + if ( ( ismMetadata->yaw_fx > DEG_180_IN_Q22 ) || ( ismMetadata->yaw_fx < -DEG_180_IN_Q22 ) ) { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS - if ( GT_32( ismMetadata->pitch_fx, DEG_90_IN_Q22 ) || LT_32( ismMetadata->pitch_fx, -DEG_90_IN_Q22 ) ) -#else - if ( ismMetadata->pitch > 90 || ismMetadata->pitch < -90 ) -#endif + + if ( ( ismMetadata->pitch_fx > DEG_90_IN_Q22 ) || ( ismMetadata->pitch_fx < -DEG_90_IN_Q22 ) ) { return IVAS_ERR_ISM_INVALID_METADATA_VALUE; } 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 8e55187c87caa7089da8f103533f738fdf6d601c..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 @@ -33,11 +33,14 @@ #include "ism_file_writer.h" #include #include +#include "float_to_fix_ops.h" -#include "prot_fx.h" #define META_LINE_LENGTH 200 /* max number of characters at one line of metadata input/output file */ +#define Q9 9 +#define Q22 22 +#define Q31 31 struct IsmFileWriter { @@ -113,7 +116,7 @@ ivas_error IsmFileWriter_writeFrame( } file = ismWriter->file; -#ifdef FIX_2084_FLOATING_POINT_LEFTOVERS + float azimuth = fixedToFloat( ismMetadata.azimuth_fx, Q22 ); float elevation = fixedToFloat( ismMetadata.elevation_fx, Q22 ); float radius = fix16_to_float( ismMetadata.radius_fx, Q9 ); @@ -123,17 +126,7 @@ ivas_error IsmFileWriter_writeFrame( float pitch = fixedToFloat( ismMetadata.pitch_fx, Q22 ); snprintf( char_buff, sizeof( char_buff ), "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f,%+07.2f,%+06.2f,%d\n", azimuth, elevation, radius, spread, gainFactor, yaw, pitch, ismMetadata.non_diegetic_flag ); -#else - ismMetadata.azimuth = fixedToFloat( ismMetadata.azimuth_fx, Q22 ); - ismMetadata.elevation = fixedToFloat( ismMetadata.elevation_fx, Q22 ); - ismMetadata.radius = fix16_to_float( ismMetadata.radius_fx, Q9 ); - ismMetadata.spread = fixedToFloat( ismMetadata.spread_fx, Q22 ); - ismMetadata.gainFactor = fixedToFloat( ismMetadata.gainFactor_fx, Q29 ); // TODO: Change to Q28 or Q12? - ismMetadata.yaw = fixedToFloat( ismMetadata.yaw_fx, Q22 ); - ismMetadata.pitch = fixedToFloat( ismMetadata.pitch_fx, Q22 ); - - snprintf( char_buff, sizeof( char_buff ), "%+07.2f,%+06.2f,%05.2f,%06.2f,%04.2f,%+07.2f,%+06.2f,%d\n", ismMetadata.azimuth, ismMetadata.elevation, ismMetadata.radius, ismMetadata.spread, ismMetadata.gainFactor, ismMetadata.yaw, ismMetadata.pitch, ismMetadata.non_diegetic_flag ); -#endif + if ( file ) { fputs( char_buff, file ); 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 new file mode 100644 index 0000000000000000000000000000000000000000..0ba94528f2830f2c6db3742f6326b49c242d3b78 --- /dev/null +++ b/lib_util/ivas_bpool.c @@ -0,0 +1,153 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 +#include "ivas_bpool.h" +#include "ivas_error_utils.h" +#include "mutex.h" + +struct BPOOL +{ + mtx_t lock; + uint32_t bufferSize; + uint32_t numBuffers; + uint32_t numFreeBuffers; + void **freeBuffers; +}; + +ivas_error BPOOL_Create( BPOOL_HANDLE *pHandle, size_t bufferSize, uint32_t numBuffers ) +{ + uint32_t n; + uint8_t *base = NULL; + BPOOL_HANDLE handle; + size_t allocSize = sizeof( struct BPOOL ); + + if ( pHandle == NULL ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer to Buffer Pool Handle" ); + } + + *pHandle = NULL; + + allocSize += bufferSize * numBuffers; /* pool memory */ + allocSize += sizeof( void * ) * numBuffers; /* free buffers stack */ + + base = calloc( allocSize, sizeof( uint8_t ) ); + if ( base == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Couldn't allocate Buffer pool" ); + } + + handle = (BPOOL_HANDLE) base; + base += sizeof( struct BPOOL ); + + mtx_init( &handle->lock, 0 ); + handle->bufferSize = bufferSize; + handle->numBuffers = numBuffers; + handle->numFreeBuffers = numBuffers; + handle->freeBuffers = (void **) base; + base += ( sizeof( void * ) * numBuffers ); + for ( n = 0; n < numBuffers; n++ ) + { + handle->freeBuffers[n] = base; + base += bufferSize; + } + + *pHandle = handle; + return IVAS_ERR_OK; +} + +void BPOOL_Destroy( BPOOL_HANDLE *pHandle ) +{ + if ( ( pHandle != NULL ) && ( *pHandle != NULL ) ) + { + mtx_destroy( &( *pHandle )->lock ); + free( *pHandle ); + *pHandle = NULL; + } +} + +ivas_error BPOOL_GetBuffer( BPOOL_HANDLE handle, void **dataPtr ) +{ + uint32_t idx = 0; + bool isFree = false; + + if ( handle == NULL || dataPtr == NULL ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer args in GetBuffer" ); + } + + mtx_lock( &handle->lock ); + isFree = ( handle->numFreeBuffers > 0 ); + if ( isFree ) + { + idx = --handle->numFreeBuffers; + } + mtx_unlock( &handle->lock ); + + if ( !isFree ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Underflow, no free buffers in pool" ); + } + + *dataPtr = handle->freeBuffers[idx]; + return IVAS_ERR_OK; +} + +/* return the buffer back to pool */ +ivas_error BPOOL_FreeBuffer( BPOOL_HANDLE handle, void *dataPtr ) +{ + uint32_t idx; + + if ( handle == NULL || dataPtr == NULL ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer args in GetBuffer" ); + } + + mtx_lock( &handle->lock ); + idx = handle->numFreeBuffers++; + mtx_unlock( &handle->lock ); + + handle->freeBuffers[idx] = dataPtr; + + return IVAS_ERR_OK; +} + +/* return the number of free buffers available atm in the pool */ +uint32_t BPOOL_AvailableBuffers( BPOOL_HANDLE handle ) +{ + uint32_t numFreeBuffers; + mtx_lock( &handle->lock ); + numFreeBuffers = handle->numFreeBuffers; + mtx_unlock( &handle->lock ); + return numFreeBuffers; +} diff --git a/lib_util/ivas_bpool.h b/lib_util/ivas_bpool.h new file mode 100644 index 0000000000000000000000000000000000000000..06281b453614a1929371064d6c4264a5c904f984 --- /dev/null +++ b/lib_util/ivas_bpool.h @@ -0,0 +1,57 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ + +#ifndef IVAS_BPOOL_H +#define IVAS_BPOOL_H + +#include +#include "common_api_types.h" + +/* Forward declaraiton of opaque buffer pool handle */ +typedef struct BPOOL *BPOOL_HANDLE; + +/* Create a buffer pool with given element size and max number of buffers */ +ivas_error BPOOL_Create( BPOOL_HANDLE *pHandle, size_t bufferSize, uint32_t numBuffers ); + +/* Destroy the buffer pool and all free-up all allocated memory */ +void BPOOL_Destroy( BPOOL_HANDLE *pHandle ); + +/* request a buffer from the pool */ +ivas_error BPOOL_GetBuffer( BPOOL_HANDLE handle, void **dataPtr ); + +/* return the buffer back to pool */ +ivas_error BPOOL_FreeBuffer( BPOOL_HANDLE handle, void *dataPtr ); + +/* return the number of free buffers available atm in the pool */ +uint32_t BPOOL_AvailableBuffers( BPOOL_HANDLE handle ); + +#endif /* IVAS_BPOOL_H */ diff --git a/lib_util/ivas_queue.c b/lib_util/ivas_queue.c new file mode 100644 index 0000000000000000000000000000000000000000..7c8be93af9f73d4434f9f59676e282860cbd8c33 --- /dev/null +++ b/lib_util/ivas_queue.c @@ -0,0 +1,137 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "ivas_queue.h" +#include "ivas_error_utils.h" +#include "mutex.h" + +struct QUEUE +{ + mtx_t lock; + NODE *front; + NODE *back; + uint32_t size; +}; + +ivas_error QUEUE_Create( QUEUE_HANDLE *pHandle ) +{ + QUEUE_HANDLE handle = NULL; + *pHandle = NULL; + + if ( pHandle == NULL ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid pointer to Buffer Pool Handle" ); + } + + handle = calloc( 1, sizeof( struct QUEUE ) ); + if ( handle != NULL ) + { + mtx_init( &handle->lock, 0 ); + } + + *pHandle = handle; + return IVAS_ERR_OK; +} + +/* Destroy the queue and free-up all allocated memory */ +void QUEUE_Destroy( QUEUE_HANDLE *pHandle ) +{ + if ( ( pHandle != NULL ) && ( *pHandle != NULL ) ) + { + mtx_destroy( &( *pHandle )->lock ); + free( *pHandle ); + *pHandle = NULL; + } +} + +void QUEUE_Push( QUEUE_HANDLE handle, NODE *node ) +{ + mtx_lock( &handle->lock ); + if ( handle->back == NULL ) + { + handle->front = node; + } + else + { + handle->back->next = node; + } + handle->back = node; + handle->size++; + mtx_unlock( &handle->lock ); +} + +/* return the buffer back to pool */ +NODE *QUEUE_Pop( QUEUE_HANDLE handle ) +{ + NODE *node; + mtx_lock( &handle->lock ); + node = handle->front; + handle->front = handle->front->next; + if ( NULL == handle->front ) + { + handle->back = NULL; + } + handle->size--; + mtx_unlock( &handle->lock ); + return node; +} + +/* returns the first element in the queue */ +NODE *QUEUE_Front( QUEUE_HANDLE handle ) +{ + NODE *node; + mtx_lock( &handle->lock ); + node = handle->front; + mtx_unlock( &handle->lock ); + return node; +} + +/* returns the last element in the queue */ +NODE *QUEUE_Back( QUEUE_HANDLE handle ) +{ + NODE *node; + mtx_lock( &handle->lock ); + node = handle->back; + mtx_unlock( &handle->lock ); + return node; +} + +/* return the number of elements in the queue */ +size_t QUEUE_Size( QUEUE_HANDLE handle ) +{ + uint32_t numNodes; + mtx_lock( &handle->lock ); + numNodes = handle->size; + mtx_unlock( &handle->lock ); + return numNodes; +} diff --git a/lib_util/ivas_queue.h b/lib_util/ivas_queue.h new file mode 100644 index 0000000000000000000000000000000000000000..a1df80035ee90a53d0b4c5f1b4890693c948ee50 --- /dev/null +++ b/lib_util/ivas_queue.h @@ -0,0 +1,68 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ + +#ifndef IVAS_QUEUE_H +#define IVAS_QUEUE_H + +#include +#include "common_api_types.h" + +typedef struct NODE +{ + struct NODE *next; +} NODE; + +/* Forward declaraiton of opaque queue handle */ +typedef struct QUEUE *QUEUE_HANDLE; + +/* Create a queue with given element size and max number of buffers */ +ivas_error QUEUE_Create( QUEUE_HANDLE *pHandle ); + +/* Destroy the queue and all free-up all allocated memory */ +void QUEUE_Destroy( QUEUE_HANDLE *pHandle ); + +/* push a buffer to a queue */ +void QUEUE_Push( QUEUE_HANDLE handle, NODE *data ); + +/* pop the buffer from the front */ +NODE *QUEUE_Pop( QUEUE_HANDLE handle ); + +/* returns the first element from the front */ +NODE *QUEUE_Front( QUEUE_HANDLE handle ); + +/* returns the last element from the back */ +NODE *QUEUE_Back( QUEUE_HANDLE handle ); + +/* return the number of elements in the queue */ +size_t QUEUE_Size( QUEUE_HANDLE handle ); + +#endif /* IVAS_QUEUE_H */ diff --git a/lib_util/ivas_rtp_api.h b/lib_util/ivas_rtp_api.h new file mode 100644 index 0000000000000000000000000000000000000000..f196539fbbb22c65adabdc2e3b609f89a60a7f7d --- /dev/null +++ b/lib_util/ivas_rtp_api.h @@ -0,0 +1,583 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ + +#ifndef IVAS_RTP_API_H +#define IVAS_RTP_API_H + +#include +#include "common_api_types.h" + +/* + * +-----------------------+---------------------+--------------------+----------+ + * | RTP Header (+ HDREXT) | payload header | frame data | PI data | + * +-----------------------+---------------------+--------------------+----------+ + * \--------------------\ /------------------------------/ + * IVAS payload + * + * This api provides a mechanism to generate/unpack the IVAS payload. The RTP Header + * and header extension fields must be handled by caller. + * + * IVAS General Payload structure + * =============================== + * + * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 + * H H H H F H + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |1| T | D |1| ET1 |x x x x|1| ET2 |x x x x|0|1|0 1| BR |1| ET3 |x x x x|… + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * \--------------/\--------------/\--------------/\--------------/\--------------/ + * Initial E byte Subsqnt Ebyte1 Subsqnt Ebyte2 ToC1 Subsqnt Ebyte3 + * + * H F + * +-+-+-+-+-+-+-+-+-------------------------- ---+-------------------- ---+-------+ + * …|0|0|0 1| BR | IVAS frame 1 ... | IVAS frame 2 ... |PI data| + * +-+-+-+-+-+-+-+-+-------------------------- ---+-------------------- ---+-------+ + * \--------------/ + * ToC2 + * + */ + +#define IVAS_MAX_FRAMES_PER_RTP_PACKET ( 8 ) /* Max supported frames per RTP packet */ + +/* It is difficult to decide the RTP Payload buffer's capacity intrinsically however computing + * using the maximum frame size and all currently supported PI data present gives a crude + * estimate or RTP packet size per frame. The additional PI data is assumed to add upto a 20% + * overhead in bitrate for the computation. + */ +#define NOMINAL_BUFFER_SIZE( numFramesPerPacket ) ( ( IVAS_MAX_BITS_PER_FRAME + ( IVAS_MAX_BITS_PER_FRAME / 5 ) ) * ( numFramesPerPacket ) / 8 ) + +#define DEFAULT_MAX_PACKET_BYTES ( 1400 ) /* Typical MTU size of 4G/5G Cellular Interfaces */ + +#define NO_BITRATE_REQ ( 0u ) /* If no bitrate is requested from remote */ + +/* IVAS Codec Types */ +typedef enum +{ + IVAS_RTP_EVS, /* EVS */ + IVAS_RTP_IVAS /* IVAS */ +} IVAS_RTP_CODEC; + +/* IVAS Bandwidth Requests */ +typedef enum +{ + IVAS_BANDWIDTH_NB, /* Narrowband */ + IVAS_BANDWIDTH_WB, /* Wideband*/ + IVAS_BANDWIDTH_SWB, /* SuperWideband*/ + IVAS_BANDWIDTH_FB, /* Fullband */ + IVAS_BANDWIDTH_NO_REQ, /* No Preference */ +} IVAS_RTP_BANDWIDTH; + +/* Channel Aware Coding */ +typedef enum +{ + IVAS_RTP_CA_LO_O2, /* FER=LO, OFFSET=2 */ + IVAS_RTP_CA_LO_O3, /* FER=LO, OFFSET=3 */ + IVAS_RTP_CA_LO_O5, /* FER=LO, OFFSET=5 */ + IVAS_RTP_CA_LO_O7, /* FER=LO, OFFSET=7 */ + IVAS_RTP_CA_HI_O2, /* FER=HI, OFFSET=2 */ + IVAS_RTP_CA_HI_O3, /* FER=HI, OFFSET=3 */ + IVAS_RTP_CA_HI_O5, /* FER=HI, OFFSET=5 */ + IVAS_RTP_CA_HI_O7, /* FER=HI, OFFSET=7 */ + IVAS_RTP_CA_NO_REQ /* No request */ +} IVAS_RTP_CA_MODE; + +/* Coded Format Requests */ +typedef enum +{ + IVAS_FMT_STEREO, /* Stereo */ + IVAS_FMT_SBA, /* Scene Based Audio */ + IVAS_FMT_MASA, /* Metadata Assisted Spatial Audio */ + IVAS_FMT_ISM, /* Object Based Audio */ + IVAS_FMT_MC, /* Multichannel Audio */ + IVAS_FMT_OMASA, /* Object + MASA */ + IVAS_FMT_OSBA, /* Object + SBA */ + IVAS_FMT_NO_REQ, /* No preference */ +} IVAS_RTP_FORMAT; + +/* Coded Subformat Requests */ +typedef enum +{ + IVAS_SUBFMT_FOA_PLANAR, + IVAS_SUBFMT_HOA2_PLANAR, + IVAS_SUBFMT_HOA3_PLANAR, + IVAS_SUBFMT_FOA, + IVAS_SUBFMT_HOA2, + IVAS_SUBFMT_HOA3, + IVAS_SUBFMT_MASA1, + IVAS_SUBFMT_MASA2, + IVAS_SUBFMT_ISM1, + IVAS_SUBFMT_ISM2, + IVAS_SUBFMT_ISM3, + IVAS_SUBFMT_ISM4, + IVAS_SUBFMT_ISM1_EXTENDED_METADATA, + IVAS_SUBFMT_ISM2_EXTENDED_METADATA, + IVAS_SUBFMT_ISM3_EXTENDED_METADATA, + IVAS_SUBFMT_ISM4_EXTENDED_METADATA, + IVAS_SUBFMT_MC_5_1, + IVAS_SUBFMT_MC_7_1, + IVAS_SUBFMT_MC_5_1_2, + IVAS_SUBFMT_MC_5_1_4, + IVAS_SUBFMT_MC_7_1_4, + IVAS_SUBFMT_RESERVED_21, + IVAS_SUBFMT_RESERVED_22, + IVAS_SUBFMT_RESERVED_23, + IVAS_SUBFMT_RESERVED_24, + IVAS_SUBFMT_RESERVED_25, + IVAS_SUBFMT_RESERVED_26, + IVAS_SUBFMT_RESERVED_27, + IVAS_SUBFMT_RESERVED_28, + IVAS_SUBFMT_RESERVED_29, + IVAS_SUBFMT_RESERVED_30, + IVAS_SUBFMT_RESERVED_31, + IVAS_SUBFMT_OMASA_ISM1_1TC, + IVAS_SUBFMT_OMASA_ISM2_1TC, + IVAS_SUBFMT_OMASA_ISM3_1TC, + IVAS_SUBFMT_OMASA_ISM4_1TC, + IVAS_SUBFMT_OMASA_ISM1_2TC, + IVAS_SUBFMT_OMASA_ISM2_2TC, + IVAS_SUBFMT_OMASA_ISM3_2TC, + IVAS_SUBFMT_OMASA_ISM4_2TC, + IVAS_SUBFMT_OSBA_ISM1_FOA_PLANAR, + IVAS_SUBFMT_OSBA_ISM2_FOA_PLANAR, + IVAS_SUBFMT_OSBA_ISM3_FOA_PLANAR, + IVAS_SUBFMT_OSBA_ISM4_FOA_PLANAR, + IVAS_SUBFMT_OSBA_ISM1_FOA, + IVAS_SUBFMT_OSBA_ISM2_FOA, + IVAS_SUBFMT_OSBA_ISM3_FOA, + IVAS_SUBFMT_OSBA_ISM4_FOA, + IVAS_SUBFMT_OSBA_ISM1_HOA2_PLANAR, + IVAS_SUBFMT_OSBA_ISM2_HOA2_PLANAR, + IVAS_SUBFMT_OSBA_ISM3_HOA2_PLANAR, + IVAS_SUBFMT_OSBA_ISM4_HOA2_PLANAR, + IVAS_SUBFMT_OSBA_ISM1_HOA2, + IVAS_SUBFMT_OSBA_ISM2_HOA2, + IVAS_SUBFMT_OSBA_ISM3_HOA2, + IVAS_SUBFMT_OSBA_ISM4_HOA2, + IVAS_SUBFMT_OSBA_ISM1_HOA3_PLANAR, + IVAS_SUBFMT_OSBA_ISM2_HOA3_PLANAR, + IVAS_SUBFMT_OSBA_ISM3_HOA3_PLANAR, + IVAS_SUBFMT_OSBA_ISM4_HOA3_PLANAR, + IVAS_SUBFMT_OSBA_ISM1_HOA3, + IVAS_SUBFMT_OSBA_ISM2_HOA3, + IVAS_SUBFMT_OSBA_ISM3_HOA3, + IVAS_SUBFMT_OSBA_ISM4_HOA3, + IVAS_SUBFMT_NO_REQ +} IVAS_RTP_SUBFORMAT; + +/* Split Rendering Requests */ +typedef struct +{ + uint32_t valid : 1; /* is split rendering request valid */ + uint32_t diegetic : 1; /* enabling diegetic support for Split Rendering */ + uint32_t yaw : 1; /* transmission metadata for correction around yaw axis */ + uint32_t pitch : 1; /* transmission metadata for correction around pitch axis */ + uint32_t roll : 1; /* transmission metadata for correction around roll axis */ + uint32_t reserved : 27; /* reserved */ +} IVAS_RTP_SPLITRENDER; + +/* Remote Requests Types (Keys) */ +typedef enum +{ + IVAS_REQUEST_CODEC, /* Request codec type, value of type IVAS_RTP_CODEC */ + IVAS_REQUEST_BITRATE, /* Request bitrate, value of type uint32_t in kbps */ + IVAS_REQUEST_BANDWIDTH, /* Request bandwidth, value of type IVAS_RTP_BANDWIDTH */ + IVAS_REQUEST_FORMAT, /* Request format, value of type IVAS_RTP_FORMAT */ + IVAS_REQUEST_CA_MODE, /* Request channel awareness, value of type IVAS_RTP_CA_MODE */ + IVAS_REQUEST_SUBFORMAT, /* Request subFormat, value of type IVAS_RTP_SUBFORMAT */ + IVAS_REQUEST_SR_CONFIG, /* Request spit rendering, value of type IVAS_RTP_SPLITRENDER */ + IVAS_REQUEST_MAX /* Max number of requests */ +} IVAS_RTP_REQUEST_TYPE; + +/* Remote Request Values */ +typedef union +{ + uint32_t bitrate; /* bitrate in kbps when request type is IVAS_REQUEST_BITRATE */ + IVAS_RTP_CODEC codec; /* codec id when request type is IVAS_REQUEST_CODEC */ + IVAS_RTP_BANDWIDTH bandwidth; /* badwidth when request type is IVAS_REQUEST_BANDWIDTH */ + IVAS_RTP_FORMAT formatType; /* format type when request type is IVAS_REQUEST_FORMAT */ + IVAS_RTP_CA_MODE caMode; /* channel aware mode when request type is IVAS_REQUEST_CA_MODE */ + IVAS_RTP_SUBFORMAT subFormatType; /* sub-format type when request type is IVAS_REQUEST_SUBFORMAT */ + IVAS_RTP_SPLITRENDER srConfig; /* split rendering config when request type is IVAS_REQUEST_SR_CONFIG */ +} IVAS_RTP_REQUEST_VALUE; + +/* Template for pi data types, all defined pi data follow this template + * for example scene orientation pi data can be represented as :- + * + * typedef struct { + * size_t size; // sizeof(IVAS_PIDATA_SCENE_ORIENTATION) + * uint32_t piDataType; // IVAS_PI_SCENE_ORIENTATION + * float w, x, y, z; // pi data of scene orientation in quaternions + * } IVAS_PIDATA_SCENE_ORIENTATION; + * + */ +typedef struct +{ + size_t size; /* size of this structure */ + uint32_t piDataType; /* IVAS PI data type */ + uint8_t data[1]; /* Variable length array */ +} IVAS_PIDATA_GENERIC; + +/* Generic data buffer for sending/receiving coded frames / rtp payloads + * data buffer is owned and initialized by caller, rtp api will ensure + * buffer write does not exceed capacity. + */ +typedef struct +{ + size_t capacity; /* allocated size of the data buffer */ + size_t length; /* length of the initialized data in the buffer */ + uint8_t *buffer; /* pointer to the payload buffer */ +} IVAS_DATA_BUFFER; + +typedef enum +{ + IVAS_SR_TRANSPORT_LCLD, + IVAS_SR_TRANSPORT_LC3PLUS +} IVAS_RTP_SR_TRANSPORT; + +typedef struct +{ + bool valid; /* Valid Split Rendering Info for/in the ToC */ + bool diegetic; /* SR content digetic */ + uint32_t bitrateKbps; /* SR bitrate in kbps */ + uint32_t codecFrameSizeMs; /* SR transport codec framesize in ms (5/10/20) */ + IVAS_RTP_SR_TRANSPORT codec; /* SR Transport Codec used*/ +} IVAS_RTP_SR_INFO; + + +/**********************************************/ +/* IVAS RTP PACKER API */ +/**********************************************/ + +/* Forward declaration of rtp pack/unpack handle types */ +typedef struct IVAS_RTP_PACK *IVAS_RTP_PACK_HANDLE; /* rtp packer handle type */ + +/* Initial configuration for rtp packer + * - maxFramesPerPacket is used to define if more than one frame should be packed + * in the same rtp packet. If zero, will use IVAS_MAX_FRAMES_PER_RTP_PACKET. + */ +typedef struct +{ + uint32_t maxFramesPerPacket; /* maximum no of frame per packet desired during the session */ +} IVAS_RTP_PACK_CONFIG; + +/* Open an instance of the RTP packer and return a handle to rtp packer on success + * error code is retured on failure and handle is set to NULL + */ +ivas_error IVAS_RTP_PACK_Open( + IVAS_RTP_PACK_HANDLE *phIvasPack, /* i/o: pointer to an IVAS rtp packer handle to be opened */ + const IVAS_RTP_PACK_CONFIG *config /* i : pointer to initial config for RTP Packer */ +); + +/* Close and free an existing instance of rtp packer */ +void IVAS_RTP_PACK_Close( + IVAS_RTP_PACK_HANDLE *phIvasPack /* i/o : pointer to an IVAS rtp packer handle to be closed */ +); + +/* Update the RTP Header structure */ +ivas_error IVAS_RTP_PACK_UpdateHeader( + IVAS_RTP_PACK_HANDLE hIvasPack, /* i/o: pointer to an IVAS rtp packer handle to be opened */ + uint16_t seqNumInitVal, /* i : Initial sequence number to be used for 1st packet */ + uint32_t ssrc, /* i : Unique 32-bit Source ID as negotiated during SDP */ + uint8_t numCC, /* i : numCC indicates no. of contributing sources */ + uint32_t *csrc, /* i : SSRCs of contributing Sources for a mixed stream */ + uint16_t extHeaderId, /* i : extension header ID */ + uint16_t numExtensionBytes, /* i : length of the extension data */ + uint8_t *extData /* i : extension data pointer */ +); + +/* Add requests for remote sender using a key value pair api + * each key must be provided with a corresponding value type + * + * Cross validation of some key,value pairs will not be done + * in this API. E.g. Codec ID and supported bitrates/bandwidths + * will not be performed at this level. + */ +ivas_error IVAS_RTP_PACK_PushRemoteRequest( + IVAS_RTP_PACK_HANDLE hIvasPack, /* i/o : IVAS rtp packer handle */ + IVAS_RTP_REQUEST_TYPE reqType, /* i : remote request type */ + IVAS_RTP_REQUEST_VALUE reqValue /* i : value of the requested type */ +); + +/* Push a single IVAS/EVS frame to rtp packer + * + * If multiple frames per RTP packet are desired, multiple frames must be explicitly + * pushed before a call to IVAS_RTP_PACK_GetPayload to generate a rtp payload. + * + * It is possible to have variable frames per packet until maxFramesPerPacket frames + * if IVAS_RTP_PACK_GetPayload is invoked asyncronously w.r.t this api. + * + */ +ivas_error IVAS_RTP_PACK_PushFrame( + IVAS_RTP_PACK_HANDLE hIvasPack, /* i/o : IVAS rtp packer handle */ + IVAS_RTP_CODEC codecId, /* i : Codec type (IVAS/EVS) */ + const IVAS_RTP_SR_INFO *srInfo, /* i : Split Rendering Info (NULL if absent) */ + const IVAS_DATA_BUFFER *frameBuffer /* i : packed frame bitstream for IVAS/EVS */ +); + +/* Get the number of frames in the FiFo currently */ +uint32_t IVAS_RTP_PACK_GetNumFrames( + IVAS_RTP_PACK_HANDLE hIvasPack /* i/o : IVAS rtp packer handle */ +); + +/* Push single PI data to rtp packer + * + * Provide PI data for a current RTP packet. All PI data is locally cached in the packer + * and set to the rtp payload with policy defined in initial configuration during call to + * IVAS_RTP_PACK_GetPayload. + * + */ +ivas_error IVAS_RTP_PACK_PushPiData( + IVAS_RTP_PACK_HANDLE hIvasPack, /* i/o : IVAS rtp packer handle */ + const IVAS_PIDATA_GENERIC *data /* i : pointer to the PIData stucture */ +); + +/* Generate a rtp payload using available pushed frames + * + * Available remote requests, pi data and frames will be packed into a rtp payload. The + * capacity field of payload is used to limits the maximum RTP packet size. + * + */ +ivas_error IVAS_RTP_PACK_GetPayload( + IVAS_RTP_PACK_HANDLE hIvasPack, /* i/o : IVAS rtp packer handle */ + IVAS_DATA_BUFFER *payload, /* o : encapsulated rtp payload */ + uint32_t *numFramesInPayload /* o : no. of frames in payload */ +); + +/* Generate a rtp packet using available pushed frames + * + * Available remote requests, pi data and frames will be packed into a rtp packet. If no + * frame is pushed before call to this api, NO_DATA_FRAME will be generated + * Takes care of updates to the RTP Header + * + */ +ivas_error IVAS_RTP_PACK_GetPacket( + IVAS_RTP_PACK_HANDLE hIvasPack, /* i/o : IVAS rtp packer handle */ + IVAS_DATA_BUFFER *packet, /* o : encapsulated rtp packet */ + uint32_t *numFramesInPacket /* o : no. of frames in packet */ +); + +/**********************************************/ +/* IVAS RTP UNPACKER API */ +/**********************************************/ + +/* Forward declaration of rtp unpack handle types */ +typedef struct IVAS_RTP_UNPACK *IVAS_RTP_UNPACK_HANDLE; /* rtp unpacker handle type */ + +/* Initial configuration for rtp unpacker + * - maxFramesPerPacket is used to define maximum supported frames per rtp packet + * to allow for internal memory allocaton, if zero, will use IVAS_MAX_FRAMES_PER_RTP_PACKET + */ + +typedef struct +{ + uint32_t maxFramesPerPacket; /* maximum no of frame per packet expected during the session */ + uint32_t srCodecFrameSizeMs; /* split rendering transport codec frame size in ms (5/10/20) set by sdp negotiation */ +} IVAS_RTP_UNPACK_CONFIG; + +/* Open an instance of the RTP unpacker and return a handle to rtp unpacker on success + * error code is retured on failure and handle is set to NULL + */ +ivas_error IVAS_RTP_UNPACK_Open( + IVAS_RTP_UNPACK_HANDLE *phIvasUnpack, /* i/o : rtp unpacker handle */ + const IVAS_RTP_UNPACK_CONFIG *config /* i : initial configuration for rtp unpacker */ +); + +/* Close and free an existing instance of rtp unpacker */ +void IVAS_RTP_UNPACK_Close( + IVAS_RTP_UNPACK_HANDLE *phIvasUnpack /* i/o : IVAS rtp unpacker handle */ +); + +/* Push a received rtp Ivas Payload to unpacker to extract number of frames, pi data and + * any remote request present in the payload. Caller must extract RTP header and header + * extension and feed Ivas Payload alongwith RTP Timestamp and sequence number. + * + * In case of DTX transmission modes, the number of frames in packet will be reduced by + * the number of NO_DATA frame received. All PullFrame calls for non NO_DATA frames shall + * be reported with timestamp jump indicating missing/NO_DATA IVAS frames. + * + * It is important to ensure IVAS_RTP_UNPACK_PushPayload, IVAS_RTP_UNPACK_PullFrame and + * IVAS_RTP_UNPACK_PullNextPiData API are invoked in same thread context or in a thread + * safe manner else a race condition can arise if new packet is pushed while frames/pidata + * are still being pulled out. The IVAS_RTP_UNPACK_PushPayload will gererate an error if + * new paylod is pushed before all frames/pidata are pulled out. + * + * Example usage : - + * ================== + * err = IVAS_RTP_UNPACK_PushPayload(hIvasUnpack, payload, rtpTs, seqNum, + * &nFrames, &nPiData, &reqBitmap); + * if (err != IVAS_ERR_OK) { return err; } + * + * // Read the frames in payload and feed to decoder + * while (nFrames-- > 0) { + * err = IVAS_RTP_UNPACK_PullFrame(hIvasUnpack, &recCodecId, &srInfo, &frame, &frameTs, &seqNum, &SpeechLostIndicated); + * if (err != IVAS_ERR_OK) { return err; } + * err = IVAS_DEC_VoIP_FeedFrame(hIvasDec, frame.buffer, frame.length, seqNum, frameTs, rcvTime, isGoodFrame); + * if (err != IVAS_ERR_OK) { return err; } + * } + * + * // Read PI Data + * while (nPiData-- > 0) { + * err = IVAS_RTP_UNPACK_PullNextPiData(hIvasUnpack, &piData, &piTs); + * if (err != IVAS_ERR_OK) { return err; } + * // handle pi data based on fwd/rev pi data types + * handlePIData(&piData, piTs) + * } + * + * // Read remote requests + * for (req = 0; req < IVAS_REQUEST_MAX; req++) { + * if (reqBitmap & (1u << req)) { + * err = IVAS_RTP_UNPACK_GetRequest(hIvasUnpack, req, &value); + * if (err != IVAS_ERR_OK) { return err; } + * switch(req) { + * case IVAS_REQUEST_CODEC : handleCodec(value.codec); break; + * case IVAS_REQUEST_BITRATE : handleBitrate(value.bitrate); break; + * case IVAS_REQUEST_BANDWIDTH : handleBandwidth(value.bandwidth); break; + * case IVAS_REQUEST_FORMAT : handleFormat(value.formatType); break; + * case IVAS_REQUEST_SUBFORMAT : handleSubFormat(value.subFormatType); break; + * case IVAS_REQUEST_CA_MODE : handleCAModevalue.caMode); break; + * case IVAS_REQUEST_SR_CONFIG : handleSRConfig(value.srConfig); break; + * } + * } + * } + * + */ +ivas_error IVAS_RTP_UNPACK_PushPayload( + IVAS_RTP_UNPACK_HANDLE hIvasUnpack, /* i/o : IVAS rtp unpacker handle */ + const IVAS_DATA_BUFFER *payload, /* i : received rtp payload */ + uint32_t timestamp, /* i : timestamp in RTP Clock @ 16KHz from rtp header */ + uint16_t sequenceNumber, /* i : sequence number from rtp header */ + uint32_t *numFramesInPacket, /* o : number of IVAS/EVS frames in rtp packet */ + uint32_t *numPiDataInPacket, /* o : number of PI data received in rtp packet */ + uint32_t *remoteRequestBitmap /* o : bitmap of available request in this packet */ +); + +/* Push a received rtp Ivas Packet to unpacker to extract number of frames, pi data and + * any remote request present in the Packet. + * + * In case of DTX transmission modes, the number of frames in packet will be reduced by + * the number of NO_DATA frame received. All PullFrame calls for non NO_DATA frames shall + * be reported with timestamp jump indicating missing/NO_DATA IVAS frames. + * + * It is important to ensure IVAS_RTP_UNPACK_PushPacket, IVAS_RTP_UNPACK_PullFrame and + * IVAS_RTP_UNPACK_PullNextPiData API are invoked in same thread context or in a thread + * safe manner else a race condition can arise if new packet is pushed while frames/pidata + * are still being pulled out. The IVAS_RTP_UNPACK_PushPacket will gererate an error if + * new packet is pushed before all frames/pidata are pulled out. + * + * Example usage : - + * ================== + * err = IVAS_RTP_UNPACK_PushPacket(hIvasUnpack, packet, &nFrames, &nPiData, &reqBitmap); + * if (err != IVAS_ERR_OK) { return err; } + * + * // Read the frames in packet and feed to decoder + * while (nFrames-- > 0) { + * err = IVAS_RTP_UNPACK_PullFrame(hIvasUnpack, &recCodecId, &srInfo, &frame, &frameTs, &seqNum, &SpeechLostIndicated); + * if (err != IVAS_ERR_OK) { return err; } + * err = IVAS_DEC_VoIP_FeedFrame(hIvasDec, frame.buffer, frame.length, seqNum, frameTs, rcvTime, isGoodFrame); + * if (err != IVAS_ERR_OK) { return err; } + * } + * + * // Read PI Data + * while (nPiData-- > 0) { + * err = IVAS_RTP_UNPACK_PullNextPiData(hIvasUnpack, &piData, &piTs); + * if (err != IVAS_ERR_OK) { return err; } + * // handle pi data based on fwd/rev pi data types + * handlePIData(&piData, piTs) + * } + * + * // Read remote requests + * for (req = 0; req < IVAS_REQUEST_MAX; req++) { + * if (reqBitmap & (1u << req)) { + * err = IVAS_RTP_UNPACK_GetRequest(hIvasUnpack, req, &value); + * if (err != IVAS_ERR_OK) { return err; } + * switch(req) { + * case IVAS_REQUEST_CODEC : handleCodec(value.codec); break; + * case IVAS_REQUEST_BITRATE : handleBitrate(value.bitrate); break; + * case IVAS_REQUEST_BANDWIDTH : handleBandwidth(value.bandwidth); break; + * case IVAS_REQUEST_FORMAT : handleFormat(value.formatType); break; + * case IVAS_REQUEST_SUBFORMAT : handleSubFormat(value.subFormatType); break; + * case IVAS_REQUEST_CA_MODE : handleCAModevalue.caMode); break; + * case IVAS_REQUEST_SR_CONFIG : handleSRConfig(value.srConfig); break; + * } + * } + * } + */ +ivas_error IVAS_RTP_UNPACK_PushPacket( + IVAS_RTP_UNPACK_HANDLE hIvasUnpack, /* i/o : IVAS rtp unpacker handle */ + const IVAS_DATA_BUFFER *packet, /* i : received rtp Packet */ + uint32_t *numFramesInPacket, /* o : number of IVAS/EVS frames in rtp packet */ + uint32_t *numPiDataInPacket, /* o : number of PI data received in rtp packet */ + uint32_t *remoteRequestBitmap /* o : bitmap of available request in this packet */ +); + +/* Fetch requests from sender using a key value pair api + * each key must be provided with a corresponding value storage type + * + * On call to IVAS_RTP_UNPACK_PushPayload(), remoteRequestBitmap can be used + * an indicator of new request available this frame + * + */ +ivas_error IVAS_RTP_UNPACK_GetRequest( + IVAS_RTP_UNPACK_HANDLE hIvasUnpack, /* i/o : IVAS rtp packer handle */ + IVAS_RTP_REQUEST_TYPE type, /* i : remote request type */ + IVAS_RTP_REQUEST_VALUE *value /* o : pointer of the requested type */ +); + +/* Extract a single IVAS/EVS frame from provided rtp payload alongwith rtp timestamp + * and sequence number + * + * If multiple frames per RTP packet are available, multiple calls to IVAS_RTP_UNPACK_PullFrame + * are needed. + */ +ivas_error IVAS_RTP_UNPACK_PullFrame( + IVAS_RTP_UNPACK_HANDLE hIvasUnpack, /* i/o : IVAS rtp unpacker handle */ + IVAS_RTP_CODEC *receivedCodecId, /* o : Codec type (IVAS/EVS) */ + IVAS_RTP_SR_INFO *srInfo, /* o : Split Rendering Info */ + IVAS_DATA_BUFFER *frameBuffer, /* o : packed frame bitstream for IVAS/EVS */ + int16_t *frameSizeInBits, /* o : exact frame size in bits (AMRWB IO) */ + uint32_t *timestamp, /* o : timestamp in RTP Clock @ 16KHz */ + uint16_t *sequenceNumber, /* o : sequence number from rtp header */ + bool *speechLostIndicated, /* o : Is current frame indicated as Lost */ + bool *isAMRWB_IOmode /* o : Is AMRWB_IO mode EVS frame */ +); + +/* Pull a single PI data from rtp unpacker instance for current packet + * Each Pi data is accompanied with a corresponding timestamp + */ +ivas_error IVAS_RTP_UNPACK_PullNextPiData( + IVAS_RTP_UNPACK_HANDLE hIvasUnpack, /* i/o : IVAS rtp unpacker handle */ + IVAS_PIDATA_GENERIC *data, /* o : output data buffer for the Pi data */ + size_t capacity, /* i : capacity of pi data buffer in bytes */ + uint32_t *timestamp /* o : timestamp in RTP Clock @ 16KHz */ +); + +#endif /* IVAS_RTP_API_H */ diff --git a/lib_util/ivas_rtp_file.c b/lib_util/ivas_rtp_file.c new file mode 100644 index 0000000000000000000000000000000000000000..37d03a385e2474a9d169c638609fb80b2ce63c2e --- /dev/null +++ b/lib_util/ivas_rtp_file.c @@ -0,0 +1,1124 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 +#include +#include "ivas_rtp_file.h" +#include "ivas_error_utils.h" +#include "float_to_fix_ops.h" + + +#define Q15 15 + +struct IVAS_RTP_FILE +{ + bool isFileWriter; + FILE *f_rtpstream; +}; + +static ivas_error IvasRtpFile_Open( + const char *filePath, /* i : path to CA config file */ + bool isFileWriter, /* i : instance is a file writer else reader */ + IVAS_RTP_FILE_HANDLE *phRtpFile /* o : pointer to an IVAS file reader handle */ +) +{ + const char *mode = isFileWriter ? "wb" : "rb"; + FILE *f_rtpstream = fopen( filePath, mode ); + if ( f_rtpstream == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "could not open: %s\n", filePath ); + } + + *phRtpFile = calloc( 1, sizeof( struct IVAS_RTP_FILE ) ); + if ( *phRtpFile != NULL ) + { + ( *phRtpFile )->isFileWriter = isFileWriter; + ( *phRtpFile )->f_rtpstream = f_rtpstream; + } + + return IVAS_ERR_OK; +} + +static ivas_error IvasRtpFile_Close( + IVAS_RTP_FILE_HANDLE *phReader /* i : pointer to an IVAS file reader handle */ +) +{ + if ( phReader != NULL && *phReader != NULL ) + { + if ( ( *phReader )->f_rtpstream != NULL ) + { + fclose( ( *phReader )->f_rtpstream ); + ( *phReader )->f_rtpstream = NULL; + } + free( *phReader ); + *phReader = NULL; + } + + return IVAS_ERR_OK; +} + +static ivas_error IvasRtpFile_Write( + IVAS_RTP_FILE_HANDLE hRtpFile, /* i : pointer to an IVAS file writer handle */ + const uint8_t *packet, /* i : rtp packet to be written to rtpdump file */ + size_t numBytes ) /* i : size in bytes of the rtp packet */ +{ + ivas_error error = IVAS_ERR_OK; + if ( hRtpFile->isFileWriter ) + { + uint32_t length = (uint32_t) numBytes; /* Max packet length is < 32 bits*/ + fwrite( &length, sizeof( uint32_t ), 1, hRtpFile->f_rtpstream ); + fwrite( packet, sizeof( uint8_t ), numBytes, hRtpFile->f_rtpstream ); + } + else + { + error = IVAS_ERR_WRONG_PARAMS; + } + return error; +} + +static ivas_error IvasRtpFile_Read( + IVAS_RTP_FILE_HANDLE hRtpFile, /* i : pointer to an IVAS file reader handle */ + uint8_t *packet, /* o : read rtp packet */ + size_t *numBytes, /* o : no of bytes in packet */ + size_t capacity /* i : max capacity of the packet buffer */ +) +{ + size_t nread = 0; + uint32_t length = 0; + if ( hRtpFile->isFileWriter ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "File open for writing cannot be read" ); + } + + nread = fread( &length, sizeof( uint32_t ), 1, hRtpFile->f_rtpstream ); /* Read Packet Length */ + if ( nread == 0 ) + { + return IVAS_ERR_END_OF_FILE; + } + + *numBytes = length; + if ( ( *numBytes ) > capacity ) + { + fprintf( stderr, "RTP packet > buffer capacity %lu bytes\n", capacity ); + return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE; + } + + nread = fread( packet, sizeof( uint8_t ), ( *numBytes ), hRtpFile->f_rtpstream ); /* Read Packet */ + if ( nread < ( *numBytes ) ) + { + return IVAS_ERR_END_OF_FILE; + } + + return IVAS_ERR_OK; +} + +static const char *const PiDataNames[IVAS_PI_MAX_ID] = { + "SCENE_ORIENTATION", "DEVICE_ORIENTATION_COMPENSATED", "DEVICE_ORIENTATION_UNCOMPENSATED", + "ACOUSTIC_ENVIRONMENT", "AUDIO_DESCRIPTION", "ISM_NUM", "ISM_ID", "ISM_GAIN", "ISM_ORIENTATION", + "ISM_POSITION", "ISM_POSITION_COMPACT", "ISM_DISTANCE_ATTENUATION", "ISM_DIRECTIVITY", "DIEGETIC_TYPE", "DYNAMIC_AUDIO_SUPPRESSION_INDICATION", + "AUDIO_FOCUS_INDICATION", "PLAYBACK_DEVICE_ORIENTATION", "HEAD_ORIENTATION", "LISTENER_POSITION", + "DYNAMIC_AUDIO_SUPPRESSION_REQUEST", "AUDIO_FOCUS_REQUEST", "PI_LATENCY", "R_ISM_ID", "R_ISM_GAIN", + "R_ISM_ORIENTATION", "R_ISM_POSITION", "R_ISM_POSITION_COMPACT", "R_ISM_DIRECTION", "RESERVED27", "RESERVED28", "RESERVED29", "NO_DATA" +}; + +void IVAS_RTP_LogPiData( + 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; + uint32_t timestamp = ~0u; + if ( f_piDataOut == NULL || piData == NULL || nPiDataPresent == 0 ) + { + return; + } + +#ifdef _WIN32 + if ( ftell( f_piDataOut ) > 3 ) +#else + if ( ftell( f_piDataOut ) > 2 ) +#endif + { + fprintf( f_piDataOut, ",\n" ); + } + + while ( nPiDataPresent-- > 0 ) + { + const IVAS_PIDATA_TS *cur = piData++; + + if ( timestamp != ( ~0u ) && timestamp != cur->timestamp ) + { + fprintf( f_piDataOut, "\n\t},\n\t\"%d\": {\n", cur->timestamp ); + } + else if ( timestamp != cur->timestamp ) + { + fprintf( f_piDataOut, "\t\"%d\": {\n", cur->timestamp ); + } + else + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\"%s\" : ", PiDataNames[cur->data.noPiData.piDataType] ); + switch ( cur->data.noPiData.piDataType ) + { + case IVAS_PI_SCENE_ORIENTATION: + case IVAS_PI_DEVICE_ORIENTATION_COMPENSATED: + case IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED: + case IVAS_PI_PLAYBACK_DEVICE_ORIENTATION: + case IVAS_PI_HEAD_ORIENTATION: + { + fprintf( f_piDataOut, "{\n\t\t\t\"w\": %f,\n\t\t\t\"x\": %f,\n\t\t\t\"y\": %f,\n\t\t\t\"z\": %f \n\t\t}", + fixedToFloat( cur->data.scene.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.scene.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.scene.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.scene.orientation.z_fx, Q15 ) ); + } + break; + + case IVAS_PI_ACOUSTIC_ENVIRONMENT: + { + fprintf( f_piDataOut, "{\n\t\t\t\"aeid\": %d", cur->data.acousticEnv.aeid ); + if ( cur->data.acousticEnv.availLateReverb ) + { + fprintf( f_piDataOut, ",\n\t\t\t\"rt60\": [ %f, %f, %f ],\n", cur->data.acousticEnv.rt60[0], cur->data.acousticEnv.rt60[1], cur->data.acousticEnv.rt60[2] ); + fprintf( f_piDataOut, "\t\t\t\"dsr\": [ %f, %f, %f ]", cur->data.acousticEnv.dsr[0], cur->data.acousticEnv.dsr[1], cur->data.acousticEnv.dsr[2] ); + } + if ( cur->data.acousticEnv.availEarlyReflections ) + { + fprintf( f_piDataOut, ",\n\t\t\t\"dim\": [ %f, %f, %f ],\n", cur->data.acousticEnv.roomDimensions.x, cur->data.acousticEnv.roomDimensions.y, cur->data.acousticEnv.roomDimensions.z ); + fprintf( f_piDataOut, "\t\t\t\"abscoeff\": [ %f, %f, %f, %f, %f, %f ]", cur->data.acousticEnv.absorbCoeffs[0], cur->data.acousticEnv.absorbCoeffs[1], cur->data.acousticEnv.absorbCoeffs[2], cur->data.acousticEnv.absorbCoeffs[3], cur->data.acousticEnv.absorbCoeffs[4], cur->data.acousticEnv.absorbCoeffs[5] ); + } + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_LISTENER_POSITION: + { + fprintf( f_piDataOut, "{\n\t\t\t\"x\": %f,\n\t\t\t\"y\": %f,\n\t\t\t\"z\": %f \n\t\t}", + cur->data.listnerPosition.position.x, cur->data.listnerPosition.position.y, cur->data.listnerPosition.position.z ); + } + break; + case IVAS_PI_AUDIO_DESCRIPTION: + { + uint32_t nEntries = cur->data.audioDesc.nValidEntries; + const IVAS_AUDIO_ID *audioId = cur->data.audioDesc.audioId; + + fprintf( f_piDataOut, "[\n" ); + while ( nEntries-- > 0 ) + { + fprintf( f_piDataOut, "\t\t\t{\n" ); + fprintf( f_piDataOut, "\t\t\t\t\"isSpeech\": %s,\n", audioId->speech ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t\"isMusic\": %s,\n", audioId->music ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t\"isAmbiance\": %s,\n", audioId->ambiance ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t\"isEditable\": %s,\n", audioId->editable ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t\"isBinaural\": %s\n", audioId->binaural ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t}%c\n", ( nEntries == 0 ) ? ' ' : ',' ); + audioId++; + } + fprintf( f_piDataOut, "\t\t]" ); + } + break; + case IVAS_PI_DIEGETIC_TYPE: + { + const bool *isDiegetic = cur->data.digeticIndicator.isDiegetic; + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"isDigetic\": [\n" ); + fprintf( f_piDataOut, "\t\t\t\t%s,\n", isDiegetic[0] ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t%s,\n", isDiegetic[1] ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t%s,\n", isDiegetic[2] ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t%s,\n", isDiegetic[3] ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\t%s\n", isDiegetic[4] ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t]\n\t\t}" ); + } + break; + case IVAS_PI_AUDIO_FOCUS_INDICATION: + { + fprintf( f_piDataOut, "{" ); + if ( cur->data.focusIndication.availDirection ) + { + fprintf( f_piDataOut, "\n\t\t\t\"direction\": {\n" ); + fprintf( f_piDataOut, "\t\t\t\t\t\t\"w\": %f,\n\t\t\t\t\t\t\"x\": %f,\n\t\t\t\t\t\t\"y\": %f,\n\t\t\t\t\t\t\"z\": %f \n\t\t\t}", + fixedToFloat( cur->data.focusIndication.direction.w_fx, Q15 ), + fixedToFloat( cur->data.focusIndication.direction.x_fx, Q15 ), + fixedToFloat( cur->data.focusIndication.direction.y_fx, Q15 ), + fixedToFloat( cur->data.focusIndication.direction.z_fx, Q15 ) ); + if ( cur->data.focusIndication.availLevel ) + { + fprintf( f_piDataOut, "," ); + } + } + if ( cur->data.focusIndication.availLevel ) + { + fprintf( f_piDataOut, "\n\t\t\t\"level\": %d", cur->data.focusIndication.flvl ); + } + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_REQUEST: + { + const IVAS_PIDATA_DYNAMIC_SUPPRESSION *das = &cur->data.dynSuppressionRequest; + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"preferSpeech\": %s,\n", das->speech ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\"preferMusic\": %s,\n", das->music ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\"preferAmbiance\": %s,\n", das->ambiance ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\"level\": %d", das->sli ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION: + { + const IVAS_PIDATA_DYNAMIC_SUPPRESSION *das = &cur->data.dynSuppressionIndication; + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"preferSpeech\": %s,\n", das->speech ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\"preferMusic\": %s,\n", das->music ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\"preferAmbiance\": %s,\n", das->ambiance ? "true" : "false" ); + fprintf( f_piDataOut, "\t\t\t\"level\": %d", das->sli ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_AUDIO_FOCUS_REQUEST: + { + fprintf( f_piDataOut, "{" ); + if ( cur->data.focusRequest.availDirection ) + { + fprintf( f_piDataOut, "\n\t\t\t\"direction\": {\n" ); + fprintf( f_piDataOut, "\t\t\t\t\t\t\"w\": %f,\n\t\t\t\t\t\t\"x\": %f,\n\t\t\t\t\t\t\"y\": %f,\n\t\t\t\t\t\t\"z\": %f \n\t\t\t}", + fixedToFloat( cur->data.focusRequest.direction.w_fx, Q15 ), + fixedToFloat( cur->data.focusRequest.direction.x_fx, Q15 ), + fixedToFloat( cur->data.focusRequest.direction.y_fx, Q15 ), + fixedToFloat( cur->data.focusRequest.direction.z_fx, Q15 ) ); + if ( cur->data.focusRequest.availLevel ) + { + fprintf( f_piDataOut, "," ); + } + } + if ( cur->data.focusRequest.availLevel ) + { + fprintf( f_piDataOut, "\n\t\t\t\"level\": %d", cur->data.focusRequest.flvl ); + } + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_RESERVED27: + case IVAS_PI_RESERVED28: + case IVAS_PI_RESERVED29: + { + fprintf( f_piDataOut, "{}" ); + } + break; + case IVAS_PI_ISM_ORIENTATION: + { + fprintf( f_piDataOut, "[\n" ); + for ( n = 0; n < cur->data.ismOrientation.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t{\n\t\t\t\t\"w\": %f,\n\t\t\t\t\"x\": %f,\n\t\t\t\t\"y\": %f,\n\t\t\t\t\"z\": %f \n\t\t\t}", + fixedToFloat( cur->data.ismOrientation.orientation[n].w_fx, Q15 ), + fixedToFloat( cur->data.ismOrientation.orientation[n].x_fx, Q15 ), + fixedToFloat( cur->data.ismOrientation.orientation[n].y_fx, Q15 ), + fixedToFloat( cur->data.ismOrientation.orientation[n].z_fx, Q15 ) ); + } + fprintf( f_piDataOut, "\n\t\t]" ); + } + break; + case IVAS_PI_ISM_NUM: + { + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"num\": %d", cur->data.ismNum.numObjects ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_ISM_ID: + { + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"ids\": [\n" ); + for ( n = 0; n < cur->data.ismId.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t\t%d", cur->data.ismId.id[n] ); + } + fprintf( f_piDataOut, "\n\t\t\t]" ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_ISM_GAIN: + { + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"gains\": [\n" ); + for ( n = 0; n < cur->data.ismGain.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t\t%d", cur->data.ismGain.dB[n] ); + } + fprintf( f_piDataOut, "\n\t\t\t]" ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_ISM_POSITION: + { + fprintf( f_piDataOut, "[\n" ); + for ( n = 0; n < cur->data.ismPosition.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t{\n\t\t\t\t\"x\": %f,\n\t\t\t\t\"y\": %f,\n\t\t\t\t\"z\": %f \n\t\t\t}", cur->data.ismPosition.position[n].x, cur->data.ismPosition.position[n].y, cur->data.ismPosition.position[n].z ); + } + fprintf( f_piDataOut, "\n\t\t]" ); + } + break; + case IVAS_PI_ISM_POSITION_COMPACT: + { + fprintf( f_piDataOut, "[\n" ); + for ( n = 0; n < cur->data.ismPositionCompact.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t{\n\t\t\t\t\"x\": %f,\n\t\t\t\t\"y\": %f,\n\t\t\t\t\"z\": %f \n\t\t\t}", cur->data.ismPositionCompact.position[n].x, cur->data.ismPositionCompact.position[n].y, cur->data.ismPositionCompact.position[n].z ); + } + fprintf( f_piDataOut, "\n\t\t]" ); + } + break; + case IVAS_PI_ISM_DISTANCE_ATTENUATION: + { + fprintf( f_piDataOut, "[\n" ); + for ( n = 0; n < cur->data.ismAttenuation.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t{\n\t\t\t\t\"ref_dist\": %f,\n\t\t\t\t\"max_dist\": %f,\n\t\t\t\t\"roll_off\": %f \n\t\t\t}", cur->data.ismAttenuation.distAtten[n].ref_dist, cur->data.ismAttenuation.distAtten[n].max_dist, cur->data.ismAttenuation.distAtten[n].roll ); + } + fprintf( f_piDataOut, "\n\t\t]" ); + } + break; + case IVAS_PI_ISM_DIRECTIVITY: + { + fprintf( f_piDataOut, "[\n" ); + for ( n = 0; n < cur->data.ismDirectivity.numObjects; n++ ) + { + if ( n != 0 ) + { + fprintf( f_piDataOut, ",\n" ); + } + fprintf( f_piDataOut, "\t\t\t{\n\t\t\t\t\"inner_ang\": %d,\n\t\t\t\t\"outer_ang\": %d,\n\t\t\t\t\"outer_att\": %f \n\t\t\t}", cur->data.ismDirectivity.directivity[n].innerConeAngle, cur->data.ismDirectivity.directivity[n].outerConeAngle, cur->data.ismDirectivity.directivity[n].outerAttenuationdB ); + } + fprintf( f_piDataOut, "\n\t\t]" ); + } + break; + case IVAS_PI_PI_LATENCY: + { + fprintf( f_piDataOut, "{" ); + fprintf( f_piDataOut, "\n\t\t\t\"reverseType\": \"%s\",", PiDataNames[cur->data.piLatency.type] ); + fprintf( f_piDataOut, "\n\t\t\t\"latency\": %d", cur->data.piLatency.latency ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_R_ISM_ID: + { + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"id\": %d", cur->data.ismEditId.id ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_R_ISM_GAIN: + { + fprintf( f_piDataOut, "{\n" ); + fprintf( f_piDataOut, "\t\t\t\"gain\": %d", cur->data.ismEditGain.dB ); + fprintf( f_piDataOut, "\n\t\t}" ); + } + break; + case IVAS_PI_R_ISM_ORIENTATION: + { + fprintf( f_piDataOut, "{\n\t\t\t\"w\": %f,\n\t\t\t\"x\": %f,\n\t\t\t\"y\": %f,\n\t\t\t\"z\": %f \n\t\t}", + fixedToFloat( cur->data.ismEditOrientation.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.ismEditOrientation.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.ismEditOrientation.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.ismEditOrientation.orientation.z_fx, Q15 ) ); + } + break; + case IVAS_PI_R_ISM_POSITION: + { + fprintf( f_piDataOut, "{\n\t\t\t\"x\": %f,\n\t\t\t\"y\": %f,\n\t\t\t\"z\": %f \n\t\t}", + cur->data.ismEditPosition.position.x, cur->data.ismEditPosition.position.y, cur->data.ismEditPosition.position.z ); + } + break; + case IVAS_PI_R_ISM_POSITION_COMPACT: + { + fprintf( f_piDataOut, "{\n\t\t\t\"x\": %f,\n\t\t\t\"y\": %f,\n\t\t\t\"z\": %f \n\t\t}", + cur->data.ismEditPositionCompact.position.x, cur->data.ismEditPositionCompact.position.y, cur->data.ismEditPositionCompact.position.z ); + } + break; + case IVAS_PI_R_ISM_DIRECTION: + { + fprintf( f_piDataOut, "{\n\t\t\t\"azi\": %f,\n\t\t\t\"elev\": %f \n\t\t}", + cur->data.ismEditDirection.azimuth, cur->data.ismEditDirection.elevation ); + } + break; + case IVAS_PI_NO_DATA: + { + fprintf( f_piDataOut, "{}" ); + } + break; + } + timestamp = cur->timestamp; + } + fprintf( f_piDataOut, "\n\t}" ); +} + +void IVAS_RTP_WriteExtPiData( + 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 ) + { + return; + } + + int i = 0; + + while ( nPiDataPresent-- > 0 ) + { + const IVAS_PIDATA_TS *cur = piData++; + + /* The writing follows the pattern of: timestamp, PI DATA TYPE, PI DATA */ + + fprintf( f_piDataOut, "%d,%s,", cur->timestamp, PiDataNames[cur->data.noPiData.piDataType] ); + switch ( cur->data.noPiData.piDataType ) + { + case IVAS_PI_SCENE_ORIENTATION: + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.scene.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.scene.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.scene.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.scene.orientation.z_fx, Q15 ) ); + } + break; + case IVAS_PI_DEVICE_ORIENTATION_COMPENSATED: + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.deviceCompensated.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.deviceCompensated.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.deviceCompensated.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.deviceCompensated.orientation.z_fx, Q15 ) ); + } + break; + case IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED: + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.deviceUnCompensated.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.deviceUnCompensated.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.deviceUnCompensated.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.deviceUnCompensated.orientation.z_fx, Q15 ) ); + } + break; + case IVAS_PI_ACOUSTIC_ENVIRONMENT: + { + fprintf( f_piDataOut, "%d", cur->data.acousticEnv.aeid ); + if ( cur->data.acousticEnv.availLateReverb ) + { + fprintf( f_piDataOut, ",%f,%f,%f", cur->data.acousticEnv.rt60[0], cur->data.acousticEnv.rt60[1], cur->data.acousticEnv.rt60[2] ); + fprintf( f_piDataOut, ",%f,%f,%f", cur->data.acousticEnv.dsr[0], cur->data.acousticEnv.dsr[1], cur->data.acousticEnv.dsr[2] ); + } + if ( cur->data.acousticEnv.availEarlyReflections ) + { + fprintf( f_piDataOut, ",%f,%f,%f", cur->data.acousticEnv.roomDimensions.x, cur->data.acousticEnv.roomDimensions.y, cur->data.acousticEnv.roomDimensions.z ); + fprintf( f_piDataOut, ",%f,%f,%f,%f,%f,%f", cur->data.acousticEnv.absorbCoeffs[0], cur->data.acousticEnv.absorbCoeffs[1], cur->data.acousticEnv.absorbCoeffs[2], cur->data.acousticEnv.absorbCoeffs[3], cur->data.acousticEnv.absorbCoeffs[4], cur->data.acousticEnv.absorbCoeffs[5] ); + } + } + break; + case IVAS_PI_AUDIO_DESCRIPTION: + { + uint32_t nEntries = cur->data.audioDesc.nValidEntries; + const IVAS_AUDIO_ID *audioId = cur->data.audioDesc.audioId; + + while ( nEntries-- > 0 ) + { + fprintf( f_piDataOut, "%d,%d,%d,%d,%d", audioId->speech, audioId->music, audioId->ambiance, audioId->editable, audioId->binaural ); + audioId++; + } + } + break; + case IVAS_PI_ISM_NUM: + { + fprintf( f_piDataOut, "%d", cur->data.ismNum.numObjects ); + } + break; + case IVAS_PI_ISM_ID: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%d", cur->data.ismId.id[i] ); + } + } + break; + case IVAS_PI_ISM_GAIN: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%d", cur->data.ismGain.dB[i] ); + } + } + break; + case IVAS_PI_ISM_ORIENTATION: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.ismOrientation.orientation[i].w_fx, Q15 ), + fixedToFloat( cur->data.ismOrientation.orientation[i].x_fx, Q15 ), + fixedToFloat( cur->data.ismOrientation.orientation[i].y_fx, Q15 ), + fixedToFloat( cur->data.ismOrientation.orientation[i].z_fx, Q15 ) ); + } + } + break; + case IVAS_PI_ISM_POSITION: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%f,%f,%f", cur->data.ismPosition.position[i].x, cur->data.ismPosition.position[i].y, cur->data.ismPosition.position[i].z ); + } + } + break; + case IVAS_PI_ISM_POSITION_COMPACT: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%f,%f,%f", cur->data.ismPositionCompact.position[i].x, cur->data.ismPositionCompact.position[i].y, cur->data.ismPositionCompact.position[i].z ); + } + } + break; + case IVAS_PI_ISM_DISTANCE_ATTENUATION: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%f,%f,%f", cur->data.ismAttenuation.distAtten[i].ref_dist, cur->data.ismAttenuation.distAtten[i].max_dist, cur->data.ismAttenuation.distAtten[i].roll ); + } + } + break; + case IVAS_PI_ISM_DIRECTIVITY: + { + for ( i = 0; i < numObj; ++i ) + { + if ( i != 0 ) + { + fprintf( f_piDataOut, "," ); + } + fprintf( f_piDataOut, "%d,%d,%f", cur->data.ismDirectivity.directivity[i].innerConeAngle, cur->data.ismDirectivity.directivity[i].outerConeAngle, cur->data.ismDirectivity.directivity[i].outerAttenuationdB ); + } + } + break; + case IVAS_PI_DIEGETIC_TYPE: + { + const bool *isDiegetic = cur->data.digeticIndicator.isDiegetic; + fprintf( f_piDataOut, "%d,%d,%d,%d,%d", isDiegetic[0], isDiegetic[1], isDiegetic[2], isDiegetic[3], isDiegetic[4] ); + } + break; + case IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION: + { + const IVAS_PIDATA_DYNAMIC_SUPPRESSION *das = &cur->data.dynSuppressionIndication; + fprintf( f_piDataOut, "%d,%d,%d,%d", das->speech, das->music, das->ambiance, das->sli ); + } + break; + case IVAS_PI_AUDIO_FOCUS_INDICATION: + { + if ( cur->data.focusIndication.availDirection ) + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.focusIndication.direction.w_fx, Q15 ), + fixedToFloat( cur->data.focusIndication.direction.x_fx, Q15 ), + fixedToFloat( cur->data.focusIndication.direction.y_fx, Q15 ), + fixedToFloat( cur->data.focusIndication.direction.z_fx, Q15 ) ); + if ( cur->data.focusIndication.availLevel ) + { + fprintf( f_piDataOut, "," ); + } + } + if ( cur->data.focusIndication.availLevel ) + { + fprintf( f_piDataOut, "%d", cur->data.focusIndication.flvl ); + } + } + break; + case IVAS_PI_PLAYBACK_DEVICE_ORIENTATION: + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.playbackOrientation.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.playbackOrientation.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.playbackOrientation.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.playbackOrientation.orientation.z_fx, Q15 ) ); + } + break; + case IVAS_PI_HEAD_ORIENTATION: + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.headOrientation.orientation.w_fx, Q15 ), + fixedToFloat( cur->data.headOrientation.orientation.x_fx, Q15 ), + fixedToFloat( cur->data.headOrientation.orientation.y_fx, Q15 ), + fixedToFloat( cur->data.headOrientation.orientation.z_fx, Q15 ) ); + } + break; + case IVAS_PI_LISTENER_POSITION: + { + fprintf( f_piDataOut, "%f,%f,%f", cur->data.listnerPosition.position.x, cur->data.listnerPosition.position.y, cur->data.listnerPosition.position.z ); + } + break; + case IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_REQUEST: + { + const IVAS_PIDATA_DYNAMIC_SUPPRESSION *das = &cur->data.dynSuppressionRequest; + fprintf( f_piDataOut, "%d,%d,%d,%d", das->speech, das->music, das->ambiance, das->sli ); + } + break; + case IVAS_PI_AUDIO_FOCUS_REQUEST: + { + + if ( cur->data.focusRequest.availDirection ) + { + fprintf( f_piDataOut, "%f,%f,%f,%f", + fixedToFloat( cur->data.focusRequest.direction.w_fx, Q15 ), + fixedToFloat( cur->data.focusRequest.direction.x_fx, Q15 ), + fixedToFloat( cur->data.focusRequest.direction.y_fx, Q15 ), + fixedToFloat( cur->data.focusRequest.direction.z_fx, Q15 ) ); + if ( cur->data.focusRequest.availLevel ) + { + fprintf( f_piDataOut, "," ); + } + } + if ( cur->data.focusRequest.availLevel ) + { + fprintf( f_piDataOut, "%d", cur->data.focusRequest.flvl ); + } + } + break; + case IVAS_PI_PI_LATENCY: + { + fprintf( f_piDataOut, "%s,%d", PiDataNames[cur->data.piLatency.type], cur->data.piLatency.latency ); + } + break; + case IVAS_PI_R_ISM_ID: + { + fprintf( f_piDataOut, "%d", cur->data.ismEditId.id ); + } + break; + case IVAS_PI_R_ISM_GAIN: + { + fprintf( f_piDataOut, "%d", cur->data.ismEditGain.piDataType ); + } + break; + case IVAS_PI_R_ISM_ORIENTATION: + { + fprintf( f_piDataOut, "%d,%d,%d,%d", cur->data.ismEditOrientation.orientation.w_fx, cur->data.ismEditOrientation.orientation.x_fx, cur->data.ismEditOrientation.orientation.y_fx, cur->data.ismEditOrientation.orientation.z_fx ); + } + break; + case IVAS_PI_R_ISM_POSITION: + { + fprintf( f_piDataOut, "%f,%f,%f", cur->data.ismEditPosition.position.x, cur->data.ismEditPosition.position.y, cur->data.ismEditPosition.position.z ); + } + break; + case IVAS_PI_R_ISM_POSITION_COMPACT: + { + fprintf( f_piDataOut, "%f,%f,%f", cur->data.ismEditPositionCompact.position.x, cur->data.ismEditPositionCompact.position.y, cur->data.ismEditPositionCompact.position.z ); + } + break; + case IVAS_PI_R_ISM_DIRECTION: + { + fprintf( f_piDataOut, "%f,%f", cur->data.ismEditDirection.azimuth, cur->data.ismEditDirection.elevation ); + } + break; + case IVAS_PI_RESERVED27: + case IVAS_PI_RESERVED28: + case IVAS_PI_RESERVED29: + break; + } + fprintf( f_piDataOut, "\n" ); + } +} + +const char *IVAS_RTP_GetExtPiFilePath( IVAS_RTP *rtp ) +{ + return rtp->piExtFilename; +} + +void IVAS_RTP_Term( + IVAS_RTP *rtp /* i/o : IVAS RTP File reader/writer handle */ +) +{ + if ( NULL != rtp ) + { + if ( rtp->hPack != NULL ) + { + /* Complete the last packet */ + if ( IVAS_RTP_PACK_GetNumFrames( rtp->hPack ) != 0 ) + { + ivas_error error = IVAS_ERR_OK; + uint32_t numFramesInPayload = 0; + + if ( ( error = IVAS_RTP_PACK_GetPacket( rtp->hPack, &rtp->rtpPacket, &numFramesInPayload ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while packing RTP Packet\n", ivas_error_to_string( error ) ); + } + else if ( numFramesInPayload > 0 ) + { + if ( ( error = IvasRtpFile_Write( rtp->hRtpFile, rtp->rtpPacket.buffer, rtp->rtpPacket.length ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while writing RTP packet\n", ivas_error_to_string( error ) ); + } + } + } + IVAS_RTP_PACK_Close( &rtp->hPack ); + } + + if ( rtp->hUnpack != NULL ) + { + IVAS_RTP_UNPACK_Close( &rtp->hUnpack ); + } + + if ( rtp->f_piDataOut != NULL ) + { + fprintf( rtp->f_piDataOut, "\n}\n" ); + fclose( rtp->f_piDataOut ); + rtp->f_piDataOut = NULL; + } + + if ( rtp->f_piExtOut != NULL ) + { + fclose( rtp->f_piExtOut ); + rtp->f_piExtOut = NULL; + } + + if ( rtp->hRtpFile != NULL ) + { + IvasRtpFile_Close( &rtp->hRtpFile ); + } + } +} + +ivas_error IVAS_RTP_WRITER_Init( + IVAS_RTP *rtp, /* i/o : IVAS RTP File writer handle */ + const char *outputBitstreamFilename, /* i : RTP Dump filename */ + uint32_t numFramesPerPacket, /* i : No. of frames per packet desired */ + uint32_t SSRC, /* i : SSRC for RTP Header */ + uint16_t seqNumInitVal /* i : Initial seq number in rtp header */ +) +{ + + ivas_error error = IVAS_ERR_OK; + + memset( rtp, 0, sizeof( IVAS_RTP ) ); + + rtp->packCfg.maxFramesPerPacket = numFramesPerPacket; + rtp->rtpPacket.buffer = rtp->packet; + rtp->rtpPacket.capacity = sizeof( rtp->packet ); + + error = IVAS_RTP_PACK_Open( &rtp->hPack, &rtp->packCfg ); + if ( error == IVAS_ERR_OK ) + { + /* Open the output file for RTPDump writing */ + error = IvasRtpFile_Open( outputBitstreamFilename, true, &rtp->hRtpFile ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + + error = IVAS_RTP_PACK_UpdateHeader( rtp->hPack, seqNumInitVal, SSRC, 0, NULL, 0, 0, NULL ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "error in IVAS_RTP_PACK_UpdateHeader(): %d\n", error ); + } + } + + return error; +} + +ivas_error IVAS_RTP_READER_Init( + IVAS_RTP *rtp, /* i/o : IVAS RTP File reader handle */ + const char *inputBitstreamFilename, /* i : Input rtpdump filename */ + const char *piOutputFilename, /* i : Output PI data json filename */ + bool isExtOutput, /* i : External output mode */ + const char *outputWavFilename /* i : name of the output audio file */ +) +{ + ivas_error error = IVAS_ERR_OK; + + memset( rtp, 0, sizeof( IVAS_RTP ) ); + + rtp->unpackCfg.maxFramesPerPacket = IVAS_MAX_FRAMES_PER_RTP_PACKET; + rtp->rtpPacket.buffer = rtp->packet; + rtp->rtpPacket.capacity = sizeof( rtp->packet ); + + error = IVAS_RTP_UNPACK_Open( &rtp->hUnpack, &rtp->unpackCfg ); + if ( error == IVAS_ERR_OK ) + { + error = IvasRtpFile_Open( inputBitstreamFilename, false, &rtp->hRtpFile ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + + if ( piOutputFilename != NULL ) + { + rtp->f_piDataOut = fopen( piOutputFilename, "w" ); + if ( rtp->f_piDataOut == NULL ) + { + fprintf( stderr, "could not open: %s\n", piOutputFilename ); + return IVAS_ERR_FAILED_FILE_OPEN; + } + fprintf( rtp->f_piDataOut, "{\n" ); + } + } + + if ( isExtOutput ) + { + char ext_pi[12]; + + /* sizeof( ext_pi ) accounts for terminating NULL, don't subtract extra 1 */ + const int32_t maxNameLenWithoutExt = FILENAME_MAX - (int32_t) sizeof( ext_pi ); + strncpy( rtp->piExtFilename, outputWavFilename, maxNameLenWithoutExt ); + snprintf( ext_pi, sizeof( ext_pi ), ".pidata.csv" ); + + /* strlen( metadata_filename[0] ) doesn't account for terminating NULL, subtract extra 1 */ + const int32_t maxNumCharactersToAppend = FILENAME_MAX - (int32_t) strlen( rtp->piExtFilename ) - 1; + strncat( rtp->piExtFilename, ext_pi, maxNumCharactersToAppend ); + + rtp->f_piExtOut = fopen( rtp->piExtFilename, "w" ); + if ( rtp->f_piExtOut == NULL ) + { + fprintf( stderr, "could not open: %s\n", rtp->piExtFilename ); + return IVAS_ERR_FAILED_FILE_OPEN; + } + } + + return error; +} + +ivas_error IVAS_RTP_WriteNextFrame( + IVAS_RTP *rtp, /* i/o : IVAS RTP File writer handle */ + uint8_t *au, /* i : IVAS Compressed AU (Packed frame) */ + const IVAS_RTP_SR_INFO *srInfo, /* i : Split rendering info in present, else NULL */ + int16_t auSizeBits, /* i : Frame size in bits */ + bool isMono, /* i : input was evs(true) or ivas(false) */ + bool forcePacket /* i : force packets with whatever frames pushed so far */ +) +{ + ivas_error error = IVAS_ERR_OK; + uint32_t nProcPiData = 0; + IVAS_DATA_BUFFER packedFrame = { 0, 0, NULL }; + + packedFrame.capacity = ( auSizeBits + 7 ) / 8; + packedFrame.length = ( auSizeBits + 7 ) / 8; + packedFrame.buffer = (uint8_t *) au; + rtp->rtpPacket.length = 0; + + /* Push Encoded Stream to */ + error = IVAS_RTP_PACK_PushFrame( rtp->hPack, + isMono ? IVAS_RTP_EVS : IVAS_RTP_IVAS, + srInfo, + &packedFrame ); + if ( error != IVAS_ERR_OK ) + { + return error; + } + + while ( rtp->nWrittenPiData > 0 ) + { + 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 ) ); + return error; + } + rtp->nWrittenPiData--; + } + + if ( forcePacket || IVAS_RTP_PACK_GetNumFrames( rtp->hPack ) == rtp->packCfg.maxFramesPerPacket ) + { + uint32_t numFramesInPayload = 0; + + /* Generate RTP Packet */ + if ( ( error = IVAS_RTP_PACK_GetPacket( rtp->hPack, &rtp->rtpPacket, &numFramesInPayload ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while packing RTP Header\n", ivas_error_to_string( error ) ); + return error; + } + + if ( ( error = IvasRtpFile_Write( rtp->hRtpFile, rtp->rtpPacket.buffer, rtp->rtpPacket.length ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while writing RTP packet\n", ivas_error_to_string( error ) ); + return error; + } + } + + return error; +} + +ivas_error IVAS_RTP_ReadNextFrame( + IVAS_RTP *rtp, /* i/o : IVAS RTP File reader handle */ + uint8_t *au, /* o : Read next IVAS Compressed AU (Packed frame) */ + int16_t *auSizeBits, /* o : Reported Frame size in bits */ + uint32_t *rtpTimeStamp, /* o : RTP Timestamp for this frame */ + uint16_t *rtpSequenceNumber, /* o : RTP sequence number for this packet */ + uint32_t *nextPacketRcvTime_ms, /* i/o : Clock indicating packet receive times need in JBM */ + IVAS_RTP_SR_INFO *srInfo, /* o : Split Rendering info if SR RTP frame unpacked */ + bool *qBit /* o : AMRWB Q bite as indicated in the RTP packet */ +) +{ + ivas_error error = IVAS_ERR_OK; + IVAS_DATA_BUFFER packedFrame; + IVAS_RTP_CODEC codecId = IVAS_RTP_IVAS; + bool isAMRWB_IOmode = false; + + packedFrame.length = 0; + packedFrame.buffer = au; + packedFrame.capacity = ( IVAS_MAX_BITS_PER_FRAME / 8 ); + if ( rtp->numFramesInPacket == 0 ) + { + rtp->rtpPacket.length = 0; + if ( ( error = IvasRtpFile_Read( rtp->hRtpFile, rtp->rtpPacket.buffer, &rtp->rtpPacket.length, rtp->rtpPacket.capacity ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = IVAS_RTP_UNPACK_PushPacket( rtp->hUnpack, &rtp->rtpPacket, + &rtp->numFramesInPacket, &rtp->numPiDataInPacket, + &rtp->remoteRequestBitmap ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "failed to unpack RTP packet error = %s\n", ivas_error_to_string( error ) ); + return error; + } + + rtp->nReadPiData = 0; + rtp->nProcPiData = 0; + + /* Pre-read all PI data */ + while ( rtp->numPiDataInPacket != 0 ) + { + 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 ) ); + return error; + } + rtp->nReadPiData++; + rtp->numPiDataInPacket--; + } + IVAS_RTP_LogPiData( rtp->f_piDataOut, rtp->piData, rtp->nReadPiData ); + } + + error = IVAS_RTP_UNPACK_PullFrame( rtp->hUnpack, &codecId, &rtp->srInfo, &packedFrame, auSizeBits, rtpTimeStamp, rtpSequenceNumber, &rtp->speechLostIndicated, &isAMRWB_IOmode ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "failed to pull frame after unpack\n" ); + return error; + } + + rtp->restartNeeded = false; + if ( *auSizeBits == 0 ) + { + /* NO_DATA_FRAME/SPEECH_LOST for IVAS and EVS is indicated by same bits + Do not restart decoder on codec/amrwb mode change in this case */ + } + else + { + rtp->restartNeeded = ( rtp->codecId != codecId ) || + ( codecId == IVAS_RTP_EVS && ( rtp->isAMRWB_IOmode != isAMRWB_IOmode ) ); + + if ( rtp->restartNeeded ) + { + fprintf( stdout, "\nRTP packet codec changed %s -> %s\n", + ( rtp->codecId == IVAS_RTP_EVS ) ? ( rtp->isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS", + ( codecId == IVAS_RTP_EVS ) ? ( isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS" ); + } + + rtp->codecId = codecId; + rtp->isAMRWB_IOmode = isAMRWB_IOmode; + } + + if ( srInfo != NULL ) + { + *srInfo = rtp->srInfo; + } + *qBit = !rtp->speechLostIndicated; + rtp->numFramesInPacket--; + rtp->numFramesProduced++; + *nextPacketRcvTime_ms += 20; + + return IVAS_ERR_OK; +} + +uint16_t IVAS_RTP_OwnRandom( uint16_t *seed ) +{ + *seed = (uint16_t) ( *seed * 31821L + 13849L ); + + return ( *seed ); +} diff --git a/lib_util/ivas_rtp_file.h b/lib_util/ivas_rtp_file.h new file mode 100644 index 0000000000000000000000000000000000000000..a3742c6c81ad277a5d96f851a7bf6e660279f017 --- /dev/null +++ b/lib_util/ivas_rtp_file.h @@ -0,0 +1,81 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ + +#ifndef IVAS_RTP_FILE_H +#define IVAS_RTP_FILE_H + +#include "common_api_types.h" +#include "ivas_rtp_api.h" +#include "ivas_rtp_pi_data.h" + +typedef struct IVAS_RTP_FILE *IVAS_RTP_FILE_HANDLE; + +typedef struct +{ + uint8_t packet[NOMINAL_BUFFER_SIZE( 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; + FILE *f_piExtOut; + char piExtFilename[FILENAME_MAX]; + IVAS_RTP_CODEC codecId; + uint32_t nWrittenPiData; + uint32_t nReadPiData; + uint32_t nProcPiData; + uint32_t numFramesInPacket; + uint32_t numPiDataInPacket; + uint32_t remoteRequestBitmap; + bool speechLostIndicated; + bool restartNeeded; + bool isAMRWB_IOmode; + size_t numFramesProduced; + + IVAS_DATA_BUFFER rtpPacket; + IVAS_RTP_PACK_HANDLE hPack; + IVAS_RTP_UNPACK_HANDLE hUnpack; + IVAS_RTP_PACK_CONFIG packCfg; + IVAS_RTP_UNPACK_CONFIG unpackCfg; + IVAS_RTP_SR_INFO srInfo; +} IVAS_RTP; + +ivas_error IVAS_RTP_WRITER_Init( IVAS_RTP *rtp, const char *outputBitstreamFilename, uint32_t numFramesPerPacket, uint32_t SSRC, uint16_t seqNumInitVal ); +ivas_error IVAS_RTP_READER_Init( IVAS_RTP *rtp, const char *inputBitstreamFilename, const char *piOutputFilename, bool isExtOutput, const char *outputWavFilename ); +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 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 ); + +#endif /* IVAS_RTP_FILE_H */ diff --git a/lib_util/ivas_rtp_internal.h b/lib_util/ivas_rtp_internal.h new file mode 100644 index 0000000000000000000000000000000000000000..afa4c3c6010ecbe95c9641949cf9ec6b601df2b7 --- /dev/null +++ b/lib_util/ivas_rtp_internal.h @@ -0,0 +1,143 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ + +#ifndef IVAS_RTP_INTERNAL_H +#define IVAS_RTP_INTERNAL_H + +#include "ivas_rtp_api.h" +#include "ivas_rtp_pi_data.h" + + +enum MASK_BITS +{ + MASK_1BIT = 0x1, + MASK_2BIT = 0x3, + MASK_3BIT = 0x7, + MASK_4BIT = 0xF, + MASK_5BIT = 0x1F, + MASK_6BIT = 0x3F, + MASK_7BIT = 0x7F, + MASK_8BIT = 0xFF, + MASK_9BIT = 0x1FF, + MASK_10BIT = 0x3FF, + MASK_11BIT = 0x7FF, + +}; + +/* tables */ +#define NBITS_AEID ( 7 ) +#define NBITS_RT60 ( 5 ) +#define NBITS_DSR ( 6 ) +#define NBITS_DIM ( 4 ) +#define NBITS_ABS ( 2 ) + +#define MASK_AEID ( ( 1u << NBITS_AEID ) - 1 ) +#define MASK_RT60 ( ( 1u << NBITS_RT60 ) - 1 ) +#define MASK_DSR ( ( 1u << NBITS_DSR ) - 1 ) +#define MASK_DIM ( ( 1u << NBITS_DIM ) - 1 ) +#define MASK_ABS ( ( 1u << NBITS_ABS ) - 1 ) + +#define MAX_PI_POSITION_METERS ( 327.68f ) +#define FLOAT_FROM_Q15( q15Val ) ( (float) ( q15Val ) / 32768.0f ) +#define MAX_PI_COMPACT_POSITION_XY_METERS ( 10.24f ) +#define MAX_PI_COMPACT_POSITION_Z_METERS ( 5.12f ) +#define FLOAT_FROM_Q10( q10Val ) ( (float) ( q10Val ) / 1024.0f ) +#define FLOAT_FROM_Q9( q9Val ) ( (float) ( q9Val ) / 512.0f ) +#define FLOAT_FROM_Q7( q7Val ) ( (float) ( q7Val ) / 128.0f ) + +extern const float mapDSR[1u << NBITS_DSR]; +extern const float mapRT60[1u << NBITS_RT60]; +extern const float mapRoomDims[1u << NBITS_DIM]; +extern const float mapAbsorbtion[1u << NBITS_ABS]; + +enum IVAS_RTP_HEADER_BITS +{ + + EBYTE_TOC_HEADER_BIT = 0x80, /* Ebyte/ToC indicator H bit, 1 = EByte, 0 = ToC */ + + TOC_HEADER_FOLLOWS = 0x40, /* ToC header byte is followed by another header byte */ + TOC_INDICATE_NO_DATA_AMRWB = 0x3F, /* ToC byte indicates NO_DATA in DTX mode for AMRWB */ + TOC_INDICATE_NO_DATA = 0x0F, /* ToC header byte indicates NO_DATA in DTX mode */ + TOC_INDICATE_IVAS = 0x10, /* ToC header byte indicates IVAS data */ + TOC_INDICATE_EVS = 0x00, /* ToC header byte indicates EVS data */ + TOC_INDICATE_AMRWB = 0x30, /* ToC header byte indicates AMR-WB IO data */ + TOC_INDICATE_ARMWB_Q = 0x20, /* ToC header byte indicates AMR-WB IO lost frame */ + TOC_INDICATE_SR = 0x1E, /* Indicate Split Rendering in ToC bytes */ + + EBYTE_CMR_T_EVS_NB = 0x80, /* Initial E-byte indicating EVS NarrowBand modes */ + EBYTE_CMR_T_EVS_IO = 0x90, /* Initial E-byte indicating EVS AMRWB IO modes */ + EBYTE_CMR_T_EVS_WB = 0xA0, /* Initial E-byte indicating EVS WideBand modes */ + EBYTE_CMR_T_EVS_SWB = 0xB0, /* Initial E-byte indicating EVS SuperWideBand modes */ + EBYTE_CMR_T_EVS_FB = 0xC0, /* Initial E-byte indicating EVS FullBand modes */ + EBYTE_CMR_T_EVS_CA_WB = 0xD0, /* Initial E-byte indicating EVS CA WideBand modes */ + EBYTE_CMR_T_EVS_CA_SWB = 0xE0, /* Initial E-byte indicating EVS CA SuperWideBand modes */ + EBYTE_CMR_T_IVAS = 0xF0, /* Initial E-byte indicating IVAS modes */ + EBYTE_CMR_T_NO_REQ = 0xFF, /* If no bitrate and no CA mode requested for IVAS/EVS */ + + EBYTE_BANDWIDTH_REQUEST = 0x80, /* Subsequent E-byte for Bandwidth Request */ + EBYTE_FORMAT_REQUEST = 0x90, /* Subsequent E-byte for Format Request */ + EBYTE_SUBFORMAT_REQUEST = 0x9F, /* Subsequent E-byte for SubFormat Request */ + EBYTE_PI_INDICATOR = 0xA0, /* Subsequent E-byte for PI Indicator */ + EBYTE_SR_REQUEST = 0xB0, /* Subsequent E-byte for Split Rendering Request */ + + PI_HEADER_PF_LAST = 0x00, /* Last PI header of the Payload in PI Header */ + PI_HEADER_PF_NOT_LAST = 0x80, /* Another PI header follows after this in PI Header */ + PI_HEADER_PM_NOT_LAST = 0x20, /* PI Frame Marker, not the last PI Header in current frame */ + PI_HEADER_PM_LAST = 0x40, /* PI Frame Marker, the last PI Header in current frame */ + PI_HEADER_PM_GENERIC = 0x60, /* PI Frame Marker, Generic applied to all frames */ + + PI_AD_SPEECH_INDICATED = 0x80, /* Audio Description indicate Speech in Audio data */ + PI_AD_MUSIC_INDICATED = 0x40, /* Audio Description indicate Misuc in Audio data */ + PI_AD_AMBIANCE_INDICATED = 0x20, /* Audio Description indicate Ambiance in Audio data */ + PI_AD_EDITABLE_INDICATED = 0x10, /* Audio Description indicate metadata is editable */ + PI_AD_BINAURAL_INDICATED = 0x8, /* Audio Description indicate Stereo stream in Binaural */ + +}; + +#define ERR_CHECK_RETURN( err ) \ + { \ + if ( ( err ) != IVAS_ERR_OK ) \ + { \ + return ( err ); \ + } \ + } + +typedef struct +{ + uint32_t size; + uint8_t data[IVAS_PI_MAX_DATA_SIZE]; +} PIDATA_PACKED; + +ivas_error PI_PackData( const IVAS_PIDATA_GENERIC *piData, PIDATA_PACKED *packed, uint8_t pmBits ); +ivas_error PI_UnPackData( uint8_t piDataType, uint32_t piSize, const uint8_t *piDataBuffer, IVAS_PIDATA_GENERIC *piData ); + +#endif /* IVAS_RTP_INTERNAL_H */ diff --git a/lib_util/ivas_rtp_payload.c b/lib_util/ivas_rtp_payload.c new file mode 100644 index 0000000000000000000000000000000000000000..137c44119e9caeb85127be5bc74a75ab9124051c --- /dev/null +++ b/lib_util/ivas_rtp_payload.c @@ -0,0 +1,1835 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 +#include +#include "common_api_types.h" +#include "ivas_rtp_internal.h" +#include "ivas_bpool.h" +#include "ivas_queue.h" +#include "ivas_error_utils.h" +#include "mutex.h" + +#define IVAS_MAX_BYTES_PER_FRAME ( ( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3 ) +#define MAX_TOC_PER_FRAME ( 2u ) /* Main ToC Byte + SR-ToC byte */ + +/* Generic RTP Header + Header Extension data structure */ +typedef struct +{ + uint32_t ssrc; /* synchronization source id as negotiated in SDP */ + uint8_t version; /* version of RTP protocol, currently 2 */ + bool padding; /* false = no padding, true = zeoo padded payload (last byte = padding count) */ + bool extension; /* true = extension header is present before payload */ + uint8_t CC; /* if some streams mixed together, CC indicates no. of contributing sources (4 bits) */ + bool marker; /* Marker bit field */ + uint8_t payloadType; /* 7-bit payload type field indicating IVAS */ + uint16_t seqNumber; /* 16-bit sequence number for RTP packets */ + uint32_t timestamp; /* timer ticks @ 16KHz clock corrsponding to 1st frame in the Payload */ + uint32_t CSRC[15]; /* SSRC of contributing Sources for a mixed stream */ + uint16_t extHeaderId; /* extension header ID */ + uint16_t numExtUnits; /* length of the extension data in 32-bit words */ + uint8_t *extData; /* Extension data pointer */ +} RTP_HEADER; + +typedef struct +{ + PIDATA_PACKED piData[IVAS_PI_MAX_ID]; /* pi data per frame */ + uint32_t piDataBitmap; /* bitmap showing available pi */ + uint32_t numPiDataAvailable; /* number of pi data available */ +} PIDATA_FRAME; + +static void initRequests( IVAS_RTP_REQUEST_VALUE *requests ) +{ + requests[IVAS_REQUEST_CODEC].codec = IVAS_RTP_IVAS; + requests[IVAS_REQUEST_BITRATE].bitrate = 0; + requests[IVAS_REQUEST_BANDWIDTH].bandwidth = IVAS_BANDWIDTH_NO_REQ; + requests[IVAS_REQUEST_FORMAT].formatType = IVAS_FMT_NO_REQ; + requests[IVAS_REQUEST_CA_MODE].caMode = IVAS_RTP_CA_NO_REQ; + requests[IVAS_REQUEST_SUBFORMAT].subFormatType = IVAS_SUBFMT_NO_REQ; + requests[IVAS_REQUEST_SR_CONFIG].srConfig.valid = false; +} + +static void initPiDataFrame( PIDATA_FRAME *piDataFrm ) +{ + /* Add NO_PI_DATA by default */ + piDataFrm->numPiDataAvailable = 1; + piDataFrm->piDataBitmap = ( 1u << IVAS_PI_NO_DATA ); + piDataFrm->piData[IVAS_PI_NO_DATA].size = 2; + piDataFrm->piData[IVAS_PI_NO_DATA].data[0] = ( IVAS_PI_NO_DATA ); /* PF/PM populated during final packing */ + piDataFrm->piData[IVAS_PI_NO_DATA].data[1] = 0; /* NO_PI_DATA is 0 bytes */ +} + +typedef struct FRAME_NODE +{ + struct FRAME_NODE *next; /* next node */ + PIDATA_FRAME piDataFrame; /* PI data for this frame */ + uint8_t au[IVAS_MAX_BYTES_PER_FRAME]; /* ivas/evs packed frame (AU) */ + uint8_t toc[MAX_TOC_PER_FRAME]; /* ToC bytes for this frame */ + uint32_t auNumBits; /* Actual frame size in bits */ + uint32_t tocNumBytes; /* valid ToC bytes (1 or 2) */ +} FRAME_NODE; + +static void initFrameNode( FRAME_NODE *node ) +{ + node->next = NULL; + initPiDataFrame( &node->piDataFrame ); + node->auNumBits = 0; + node->tocNumBytes = 0; +} + +struct IVAS_RTP_PACK +{ + mtx_t apilock; /* Lock to handle concurrent API invocation */ + bool amrwbIOMode; /* If EVS is an AMRWB-IO mode frame */ + RTP_HEADER header; /* RTP Header Params */ + BPOOL_HANDLE packNodePool; /* Buffer pool to allocate FRAME_NODEs */ + PIDATA_FRAME piDataCache; /* temporary cache for PI data pushed before any frame is available in Queue */ + IVAS_RTP_PACK_CONFIG initConfig; /* Initial Configuration for Unpacker */ + IVAS_RTP_REQUEST_VALUE requests[IVAS_REQUEST_MAX]; /* Requests Storage */ + QUEUE_HANDLE frameQ; /* frames queue for FRAME_NODEs */ +}; + +typedef struct +{ + IVAS_RTP_CODEC codecId; /* Coded frame type (IVAS/EVS) */ + uint32_t auNumBits; /* Actual frame size in bits */ + bool speechLostIndicated; /* Speech Lost indicated */ + bool isAMRWB_IOmode; /* EVS frame is AMRWB_IO */ + IVAS_RTP_SR_INFO srInfo; /* Split Rendering Info */ +} TOC_INFO; + +typedef struct PIDATA_NODE +{ + struct PIDATA_NODE *next; /* next node is first element */ + IVAS_PIDATA data; /* unpacked pi data per frame */ + uint32_t timestamp; /* rtp timestamp of this frame */ +} PIDATA_NODE; + +typedef struct UNPACK_NODE +{ + struct UNPACK_NODE *next; /* next node is first element */ + uint8_t au[IVAS_MAX_BYTES_PER_FRAME]; /* ivas/evs packed frame (AU) */ + TOC_INFO toc; /* unpacked ToC information */ + uint32_t timestamp; /* timestamp of this frame */ + uint16_t seqNumber; /* sequence number of the packet */ +} UNPACK_NODE; + +struct IVAS_RTP_UNPACK +{ + mtx_t apilock; /* Lock to handle concurrent API invocation */ + size_t maxNumberOfFrames; + size_t maxNumberOfPiData; + RTP_HEADER header; + BPOOL_HANDLE unpackNodePool; + BPOOL_HANDLE piDataPool; + IVAS_RTP_UNPACK_CONFIG initConfig; + IVAS_RTP_REQUEST_VALUE requests[IVAS_REQUEST_MAX]; + uint32_t numPiDataAvailable; /* number of pi data available */ + QUEUE_HANDLE frameQ; /* frame queue */ + QUEUE_HANDLE piDataQ; /* pi data queue */ +}; + +static const uint32_t ivasFrameSizeInBits[] = { + 264, 328, 488, 640, 960, 1280, 1600, 1920, 2560, 3200, 3840, 5120, 7680, 10240, 0, 104 +}; + +static const uint32_t evsFrameSizeInBits[] = { + 56, 144, 160, 192, 264, 328, 488, 640, 960, 1280, 1920, 2560, 48 +}; + +static const uint32_t amrWBIOFrameSizeInBits[] = { + 132, 177, 253, 285, 317, 365, 397, 461, 477, 35 +}; + + +/* Update the RTP Header structure */ +ivas_error IVAS_RTP_PACK_UpdateHeader( + IVAS_RTP_PACK_HANDLE hPack, /* i/o: pointer to an IVAS rtp packer handle to be opened */ + uint16_t seqNumInitVal, /* i : Initial sequence number to be used for 1st packet */ + uint32_t ssrc, /* i : Unique 32-bit Source ID as negotiated during SDP */ + uint8_t numCC, /* i : numCC indicates no. of contributing sources */ + uint32_t *csrc, /* i : SSRCs of contributing Sources for a mixed stream */ + uint16_t extHeaderId, /* i : extension header ID */ + uint16_t numExtensionBytes, /* i : length of the extension data */ + uint8_t *extData /* i : extension data pointer */ +) +{ + RTP_HEADER *header = &hPack->header; + + if ( numCC > 15 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "CC must be less than 16" ); + } + + header->seqNumber = seqNumInitVal; + header->ssrc = ssrc; + header->CC = numCC; + if ( csrc != NULL ) + { + memcpy( header->CSRC, csrc, numCC & 0xF ); + } + + if ( ( numExtensionBytes > 0 ) && ( extData != NULL ) ) + { + header->extHeaderId = extHeaderId; + header->extData = realloc( header->extData, numExtensionBytes ); + if ( header->extData == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "failed to allocate extdata" ); + } + memcpy( header->extData, extData, numExtensionBytes ); + header->extension = true; + header->numExtUnits = numExtensionBytes / sizeof( uint32_t ); + } + else + { + header->numExtUnits = 0; + header->extension = false; + } + + return IVAS_ERR_OK; +} + +static void InitRtpHeader( + RTP_HEADER *header /* RTP header structure */ +) +{ + memset( header, 0, sizeof( *header ) ); + header->version = 2; + + return; +} + +static ivas_error PackRtpHeader( + RTP_HEADER *header, + IVAS_DATA_BUFFER *buf ) +{ + uint32_t nBytes = 0; + uint8_t CC = header->CC & MASK_4BIT; + uint32_t *CSRC = header->CSRC; + bool extension = header->extension && ( NULL != header->extData ); + uint32_t extensionLength = header->extension ? ( 1 + header->numExtUnits ) : 0; /* in u32 words */ + uint32_t packedLength = 12 + ( 4 * CC ) + ( 4 * extensionLength ); + + buf->length = 0; + if ( packedLength > buf->capacity ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient output buffer for RTP header packing" ); + } + + /* + +---+---+---+---+---+---+---+---+ + | V | V | P | X | CC (4 - bits) | + +---+---+---+---+---+---+---+---+ + */ + buf->buffer[nBytes++] = ( header->version << 6 ) | + ( (uint8_t) header->padding << 5 ) | + ( (uint8_t) extension << 4 ) | + CC; + /* + +---+---+---+---+---+---+---+---+ + | M | PT (7 - bits) | + +---+---+---+---+---+---+---+---+ + */ + buf->buffer[nBytes++] = ( (uint8_t) header->marker << 7 ) | + ( header->payloadType & MASK_7BIT ); + /* + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + | SEQUENCE NUMBER (16 bit) | + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + */ + buf->buffer[nBytes++] = (uint8_t) ( header->seqNumber >> 8 ); + buf->buffer[nBytes++] = (uint8_t) ( header->seqNumber ); + + /* Timestamp (32-bit) */ + buf->buffer[nBytes++] = (uint8_t) ( header->timestamp >> 24 ); + buf->buffer[nBytes++] = (uint8_t) ( header->timestamp >> 16 ); + buf->buffer[nBytes++] = (uint8_t) ( header->timestamp >> 8 ); + buf->buffer[nBytes++] = (uint8_t) ( header->timestamp >> 0 ); + + /* SSRC (32-bit) */ + buf->buffer[nBytes++] = (uint8_t) ( header->ssrc >> 24 ); + buf->buffer[nBytes++] = (uint8_t) ( header->ssrc >> 16 ); + buf->buffer[nBytes++] = (uint8_t) ( header->ssrc >> 8 ); + buf->buffer[nBytes++] = (uint8_t) ( header->ssrc >> 0 ); + + /* CSRC Identifiers */ + while ( CC ) + { + /* CSRC[n] (32-bit) */ + uint32_t id = *CSRC++; + buf->buffer[nBytes++] = (uint8_t) ( id >> 24 ); + buf->buffer[nBytes++] = (uint8_t) ( id >> 16 ); + buf->buffer[nBytes++] = (uint8_t) ( id >> 8 ); + buf->buffer[nBytes++] = (uint8_t) ( id >> 0 ); + CC--; + } + + if ( extension ) + { + buf->buffer[nBytes++] = (uint8_t) ( header->extHeaderId >> 8 ); + buf->buffer[nBytes++] = (uint8_t) ( header->extHeaderId >> 0 ); + buf->buffer[nBytes++] = (uint8_t) ( header->numExtUnits >> 8 ); + buf->buffer[nBytes++] = (uint8_t) ( header->numExtUnits >> 0 ); + + memcpy( &buf->buffer[nBytes], header->extData, header->numExtUnits * 4 ); + nBytes += header->numExtUnits; + } + + buf->length = nBytes; + return IVAS_ERR_OK; +} + +static void UpdateRtpHeader( + RTP_HEADER *header, /* RTP header structure */ + uint32_t timestampOffset /* Timestamp offset @ 16KHz clock for next frame */ +) +{ + header->seqNumber++; + header->timestamp += timestampOffset; +} + +static ivas_error UnpackRtpPacket( + const IVAS_DATA_BUFFER *packet, /* Input buffer with RTP Packet */ + RTP_HEADER *header, /* RTP header structure */ + uint32_t *numHeaderBytes /* No. of rtp header bytes */ +) +{ + uint32_t n = 0, nByte = 0, expectedSize = 12; + uint8_t byte; + + if ( packet->length < expectedSize ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Insufficient input buffer for RTP header unpacking" ); + } + + /* + +---+---+---+---+---+---+---+---+ + | V | V | P | X | CC (4 - bits) | + +---+---+---+---+---+---+---+---+ + */ + byte = packet->buffer[nByte++]; + header->version = ( byte >> 6 ) & MASK_2BIT; + header->padding = ( byte >> 5 ) & MASK_1BIT; + header->extension = ( byte >> 4 ) & MASK_1BIT; + header->CC = ( byte & MASK_4BIT ); + + /* + +---+---+---+---+---+---+---+---+ + | M | PT (7 - bits) | + +---+---+---+---+---+---+---+---+ + */ + byte = packet->buffer[nByte++]; + header->marker = ( byte >> 7 ) & MASK_1BIT; + header->payloadType = byte & MASK_7BIT; + + /* + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + | SEQUENCE NUMBER (16 bit) | + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + */ + header->seqNumber = (uint16_t) packet->buffer[nByte++] << 8; + header->seqNumber |= (uint16_t) packet->buffer[nByte++] << 8; + + /* Timestamp (32-bit) */ + header->timestamp = ( (uint32_t) packet->buffer[nByte++] << 24 ); + header->timestamp |= ( (uint32_t) packet->buffer[nByte++] << 16 ); + header->timestamp |= ( (uint32_t) packet->buffer[nByte++] << 8 ); + header->timestamp |= ( (uint32_t) packet->buffer[nByte++] ); + + /* SSRC (32-bit) */ + header->ssrc = ( (uint32_t) packet->buffer[nByte++] << 24 ); + header->ssrc |= ( (uint32_t) packet->buffer[nByte++] << 16 ); + header->ssrc |= ( (uint32_t) packet->buffer[nByte++] << 8 ); + header->ssrc |= ( (uint32_t) packet->buffer[nByte++] ); + + expectedSize += ( header->CC ) * 4 + ( header->extension ? 4 : 0 ); + if ( packet->length < expectedSize ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "CC indicated but insufficient input buffer" ); + } + + /* CSRC Identifiers */ + for ( n = 0; n < header->CC; n++ ) + { + /* CSRC[n] (32-bit) */ + header->CSRC[n] = ( (uint32_t) packet->buffer[nByte++] << 24 ); + header->CSRC[n] |= ( (uint32_t) packet->buffer[nByte++] << 16 ); + header->CSRC[n] |= ( (uint32_t) packet->buffer[nByte++] << 8 ); + header->CSRC[n] |= ( (uint32_t) packet->buffer[nByte++] ); + } + + if ( header->extension ) + { + header->extHeaderId = ( (uint32_t) packet->buffer[nByte++] << 8 ); + header->extHeaderId |= ( (uint32_t) packet->buffer[nByte++] ); + header->numExtUnits = ( (uint32_t) packet->buffer[nByte++] << 8 ); + header->numExtUnits |= ( (uint32_t) packet->buffer[nByte++] ); + + expectedSize += header->numExtUnits * 4; + if ( packet->length < expectedSize ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Extension Header indicated but insufficient input buffer" ); + } + + header->extData = realloc( header->extData, header->numExtUnits * 4 ); + if ( header->extData == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "failed to allocate extdata" ); + } + memcpy( header->extData, &packet->buffer[nByte], header->numExtUnits * 4 ); + nByte += header->numExtUnits * 4; + } + + *numHeaderBytes = nByte; + return IVAS_ERR_OK; +} + +static ivas_error getBitrateFromCodecAndFrameSize( + IVAS_RTP_CODEC codecId, + uint32_t frameLengthBytes, + uint32_t *bitrateKbps, + uint32_t *frameLenInBits, + uint8_t *tocByte, + bool *isAmrwbIOMode ) +{ + size_t n; + *bitrateKbps = 0; + *frameLenInBits = 0; + if ( codecId == IVAS_RTP_IVAS ) + { + /* Validate the framelength is supported for ivas frame */ + for ( n = 0; n < sizeof( ivasFrameSizeInBits ) / sizeof( ivasFrameSizeInBits[0] ); n++ ) + { + if ( ivasFrameSizeInBits[n] == frameLengthBytes * 8 ) + { + *bitrateKbps = ( frameLengthBytes * IVAS_NUM_FRAMES_PER_SEC * 8 ); /* bitrate in kbps */ + *frameLenInBits = frameLengthBytes * 8; /* frame length in bits */ + *tocByte = TOC_INDICATE_IVAS | ( n & MASK_4BIT ); /* bitrate index */ + return IVAS_ERR_OK; + } + } + return IVAS_ERR_INVALID_BITRATE; + } + else + { + /* Try if frameLength is a supported EVS frame length */ + for ( n = 0; n < sizeof( evsFrameSizeInBits ) / sizeof( evsFrameSizeInBits[0] ); n++ ) + { + if ( evsFrameSizeInBits[n] == frameLengthBytes * 8 ) + { + *bitrateKbps = ( frameLengthBytes * IVAS_NUM_FRAMES_PER_SEC * 8 ); /* bitrate in kbps */ + *frameLenInBits = frameLengthBytes * 8; /* frame length in bits */ + *tocByte = TOC_INDICATE_EVS | ( n & MASK_4BIT ); /* bitrate index */ + return IVAS_ERR_OK; + } + } + /* Try if frameLength is a supported AMRWB-IO frame length */ + for ( n = 0; n < sizeof( amrWBIOFrameSizeInBits ) / sizeof( amrWBIOFrameSizeInBits[0] ); n++ ) + { + uint32_t lengthInBits = amrWBIOFrameSizeInBits[n]; + if ( ( ( lengthInBits + 7 ) / 8 ) == frameLengthBytes ) + { + *isAmrwbIOMode = true; + *bitrateKbps = ( lengthInBits * IVAS_NUM_FRAMES_PER_SEC ); /* bitrate in kbps */ + *frameLenInBits = lengthInBits; /* frame length in bits */ + *tocByte = TOC_INDICATE_AMRWB | ( n & MASK_4BIT ); /* bitrate index */ + return IVAS_ERR_OK; + } + } + return IVAS_ERR_INVALID_BITRATE; + } +} + +ivas_error IVAS_RTP_PACK_Open( + IVAS_RTP_PACK_HANDLE *phPack, /* i/o: pointer to an IVAS rtp packer handle to be opened */ + const IVAS_RTP_PACK_CONFIG *config /* i : pointer to initial config for RTP Packer */ +) +{ + ivas_error error; + IVAS_RTP_PACK_HANDLE hPack; + uint32_t numFramesPerPacket = ( config->maxFramesPerPacket == 0 ) ? IVAS_MAX_FRAMES_PER_RTP_PACKET : config->maxFramesPerPacket; + + if ( phPack == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( numFramesPerPacket > IVAS_MAX_FRAMES_PER_RTP_PACKET ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Max frame per packet exeeds %d", IVAS_MAX_FRAMES_PER_RTP_PACKET ); + } + + *phPack = NULL; + if ( ( hPack = (IVAS_RTP_PACK_HANDLE) calloc( 1, sizeof( struct IVAS_RTP_PACK ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS rtppack handle" ); + } + + error = BPOOL_Create( &hPack->packNodePool, sizeof( FRAME_NODE ), numFramesPerPacket * 4 ); + ERR_CHECK_RETURN( error ); + + error = QUEUE_Create( &hPack->frameQ ); + ERR_CHECK_RETURN( error ); + + mtx_init( &hPack->apilock, 0 ); + hPack->initConfig = *config; + initRequests( hPack->requests ); + InitRtpHeader( &hPack->header ); + initPiDataFrame( &hPack->piDataCache ); + *phPack = hPack; + return IVAS_ERR_OK; +} + +/* Close and free an existing instance of rtp packer */ +void IVAS_RTP_PACK_Close( + IVAS_RTP_PACK_HANDLE *phPack /* i/o : pointer to an IVAS rtp packer handle to be closed */ +) +{ + IVAS_RTP_PACK_HANDLE hPack; + + /* Free all memory */ + if ( phPack == NULL || *phPack == NULL ) + { + return; + } + + hPack = *phPack; + QUEUE_Destroy( &hPack->frameQ ); + mtx_destroy( &hPack->apilock ); + BPOOL_Destroy( &hPack->packNodePool ); + free( hPack->header.extData ); + free( hPack ); + *phPack = NULL; +} + +ivas_error IVAS_RTP_PACK_PushRemoteRequest( + IVAS_RTP_PACK_HANDLE hPack, /* i/o : IVAS rtp packer handle */ + IVAS_RTP_REQUEST_TYPE reqType, /* i : remote request type */ + IVAS_RTP_REQUEST_VALUE reqValue /* i : value of the requested type */ +) +{ + if ( reqType < 0 || reqType >= IVAS_REQUEST_MAX ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid request key provided" ); + } + + /* Sanity on API */ + switch ( reqType ) + { + case IVAS_REQUEST_CODEC: + { + uint32_t codec = reqValue.codec; + if ( codec != IVAS_RTP_IVAS && codec != IVAS_RTP_EVS ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported codec id provided" ); + } + } + break; + case IVAS_REQUEST_BITRATE: + { + uint32_t bitrate = reqValue.bitrate; + if ( bitrate < 5900 || bitrate > 512000 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported bitrate provided" ); + } + } + break; + case IVAS_REQUEST_BANDWIDTH: + { + uint32_t bandwidth = reqValue.bandwidth; + if ( bandwidth > IVAS_BANDWIDTH_NO_REQ ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported bandwidth provided" ); + } + } + break; + case IVAS_REQUEST_FORMAT: + { + uint32_t format = reqValue.formatType; + if ( format > IVAS_FMT_NO_REQ ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported format provided" ); + } + } + break; + case IVAS_REQUEST_CA_MODE: + { + uint32_t caMode = reqValue.caMode; + if ( caMode > IVAS_RTP_CA_NO_REQ ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported channel aware mode provided" ); + } + } + break; + case IVAS_REQUEST_SUBFORMAT: + { + uint32_t subFormat = reqValue.subFormatType; + if ( subFormat > IVAS_SUBFMT_NO_REQ ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported subformat provided" ); + } + } + break; + case IVAS_REQUEST_SR_CONFIG: + { + IVAS_RTP_SPLITRENDER srConfig = reqValue.srConfig; + if ( srConfig.reserved != 0 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported reserved bits in SR config provided" ); + } + } + break; + default: + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported request type" ); + } + + hPack->requests[reqType] = reqValue; + + return IVAS_ERR_OK; +} + +static bool isAmrWBIOMode( uint32_t bitrate, uint32_t *idx ) +{ + size_t n; + *idx = 0; + for ( n = 0; n < sizeof( amrWBIOFrameSizeInBits ) / sizeof( amrWBIOFrameSizeInBits[0] ); n++ ) + { + if ( bitrate == ( amrWBIOFrameSizeInBits[n] * IVAS_NUM_FRAMES_PER_SEC ) ) + { + *idx = n; + return true; + } + } + return false; +} + +static uint32_t getBitrateIdx( const uint32_t *table, uint32_t tableLen, uint32_t bitrate ) +{ + size_t n, idx = 0; + + for ( n = 0; n < tableLen; n++ ) + { + if ( bitrate > ( table[n] * IVAS_NUM_FRAMES_PER_SEC ) ) + { + idx = n; + } + else + { + return idx; + } + } + return idx; +} + +static void packEBytes( + IVAS_RTP_PACK_HANDLE hPack, /* i/o : IVAS rtp packer handle */ + bool piDataPresent, /* i : Signals if PI data present */ + size_t maxNumEBytes, /* i : max capacity of eByte buffer */ + uint8_t *eByte, /* o : output buffer for E-Bytes */ + size_t *nBytesWritten /* o : max capacity of eByte buffer */ +) +{ + /* Initial E-byte structure + * 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+ + * |H|T|T|T| BR | + * +-+-+-+-+-+-+-+-+ + */ + uint32_t nByte = 0; + uint8_t T = EBYTE_CMR_T_IVAS; /* IVAS */ + uint8_t BR = 0; + + IVAS_RTP_CODEC codec = hPack->requests[IVAS_REQUEST_CODEC].codec; + IVAS_RTP_BANDWIDTH bandwidth = hPack->requests[IVAS_REQUEST_BANDWIDTH].bandwidth; + uint32_t bitrate = hPack->requests[IVAS_REQUEST_BITRATE].bitrate; + uint32_t bitrateIdx = 0; + + *nBytesWritten = 0; + + if ( codec == IVAS_RTP_EVS ) + { + /* If requesting EVS/AMRWB IO from farend, only Initial E-byte present */ + IVAS_RTP_CA_MODE caMode = hPack->requests[IVAS_REQUEST_CA_MODE].caMode; + + if ( caMode != IVAS_RTP_CA_NO_REQ ) + { + T = ( bandwidth == IVAS_BANDWIDTH_SWB ) ? EBYTE_CMR_T_EVS_CA_SWB : EBYTE_CMR_T_EVS_CA_WB; + BR = caMode & MASK_3BIT; /* only 8 valid values */ + if ( nByte < maxNumEBytes ) + { + eByte[nByte++] = ( T | BR ); + } + } + else if ( bitrate > 0 && isAmrWBIOMode( bitrate, &bitrateIdx ) ) + { + /* AMR WB IO Mode */ + T = EBYTE_CMR_T_EVS_IO; + BR = (uint8_t) bitrateIdx & MASK_4BIT; + if ( nByte < maxNumEBytes ) + { + eByte[nByte++] = ( T | BR ); + } + } + else if ( bitrate > 0 ) + { + /* EVS Modes */ + bitrate = ( bitrate > 128000 ) ? 128000 : bitrate; + bitrate = ( bitrate < 5900 ) ? 5900 : bitrate; + bitrateIdx = getBitrateIdx( evsFrameSizeInBits, sizeof( evsFrameSizeInBits ) / sizeof( evsFrameSizeInBits[0] ), bitrate ); + BR = (uint8_t) bitrateIdx & MASK_4BIT; + + /* If a bandwidth choice cannot be signalled for a given bitrate + preference is given to bitrate choice, bandwidth req is modified */ + switch ( bandwidth ) + { + case IVAS_BANDWIDTH_NB: + T = ( bitrate <= 24400u ) ? EBYTE_CMR_T_EVS_NB : EBYTE_CMR_T_EVS_SWB; + break; + case IVAS_BANDWIDTH_WB: + T = EBYTE_CMR_T_EVS_WB; + break; + case IVAS_BANDWIDTH_SWB: + T = ( bitrate >= 9600u ) ? EBYTE_CMR_T_EVS_SWB : EBYTE_CMR_T_EVS_WB; + break; + case IVAS_BANDWIDTH_FB: + T = ( bitrate >= 16400u ) ? EBYTE_CMR_T_EVS_FB : EBYTE_CMR_T_EVS_WB; + break; + default: /*IVAS_BANDWIDTH_NO_REQ */ + T = ( bitrate >= 9600u ) ? EBYTE_CMR_T_EVS_SWB : EBYTE_CMR_T_EVS_WB; + break; + } + if ( nByte < maxNumEBytes ) + { + eByte[nByte++] = ( T | BR ); + } + } + else if ( piDataPresent ) + { + /* Send an initial E-byte to allow for subsequent PI indication E-byte */ + if ( nByte < maxNumEBytes ) + { + eByte[nByte++] = EBYTE_CMR_T_NO_REQ; + } + } + } + else + { + /* Requesting IVAS from farend, Subsequent E-byte indicate BW, CFR, SR */ + IVAS_RTP_FORMAT format = hPack->requests[IVAS_REQUEST_FORMAT].formatType; + bool isBandwidthProvided = ( bandwidth != IVAS_BANDWIDTH_NO_REQ && bandwidth != IVAS_BANDWIDTH_NB ); + bool isFormatProvided = ( format != IVAS_FMT_NO_REQ ); + bool isSubFormatProvided = false; + bool isSRConfigProvided = false; + + IVAS_RTP_SUBFORMAT subFormat = hPack->requests[IVAS_REQUEST_SUBFORMAT].subFormatType; + IVAS_RTP_SPLITRENDER srConfig = hPack->requests[IVAS_REQUEST_SR_CONFIG].srConfig; + + isSubFormatProvided = ( subFormat != IVAS_SUBFMT_NO_REQ ); + isSRConfigProvided = srConfig.valid; + + /* Initial E-Byte only sent if either bitrate requested or subsequent E-byte is requested */ + if ( !( ( bitrate > 0 ) || isBandwidthProvided || isFormatProvided || + isSubFormatProvided || isSRConfigProvided || piDataPresent ) ) + { + return; + } + + if ( bitrate > 0 ) + { + /* Initial E-Byte */ + bitrate = ( bitrate > 512000 ) ? 512000 : bitrate; + bitrate = ( bitrate < 13200 ) ? 13200 : bitrate; + bitrateIdx = getBitrateIdx( ivasFrameSizeInBits, sizeof( ivasFrameSizeInBits ) / sizeof( ivasFrameSizeInBits[0] ), bitrate ); + BR = (uint8_t) bitrateIdx & MASK_4BIT; + if ( nByte < maxNumEBytes ) + { + eByte[nByte++] = ( EBYTE_CMR_T_IVAS | BR ); + } + } + else + { + if ( nByte < maxNumEBytes ) + { + eByte[nByte++] = EBYTE_CMR_T_NO_REQ; + } + } + + /* Subsequent E-bytes - Bandwidth Request */ + if ( isBandwidthProvided && nByte < maxNumEBytes ) + { + uint8_t bw = ( bandwidth - IVAS_BANDWIDTH_WB ) & MASK_2BIT; + eByte[nByte++] = ( EBYTE_BANDWIDTH_REQUEST | bw ); + } + + /* Subsequent E-bytes - Coded Format Request */ + if ( ( isFormatProvided || isSubFormatProvided ) && nByte < maxNumEBytes ) + { + uint8_t fmtEByte = ( EBYTE_FORMAT_REQUEST | ( (uint8_t) format & MASK_3BIT ) ); + eByte[nByte++] = isSubFormatProvided ? EBYTE_SUBFORMAT_REQUEST : fmtEByte; + } + + if ( isSubFormatProvided && nByte < maxNumEBytes ) + { + eByte[nByte++] = ( (uint8_t) subFormat & MASK_6BIT ); /* Requested Coded subFormat */ + } + + /* Subsequent E-bytes - Split Renderer Configuration Request */ + if ( isSRConfigProvided && nByte < maxNumEBytes ) + { + eByte[nByte++] = EBYTE_SR_REQUEST | + ( (uint8_t) srConfig.diegetic << 3 ) | ( (uint8_t) srConfig.yaw << 2 ) | + ( (uint8_t) srConfig.pitch << 1 ) | ( (uint8_t) srConfig.roll << 0 ); + } + } + + /* Final E-byte is the PI Indicator E-Byte */ + if ( piDataPresent && ( nByte < maxNumEBytes ) ) + { + eByte[nByte++] = EBYTE_PI_INDICATOR; /* PI Indication */ + } + + *nBytesWritten = nByte; +} + + +static ivas_error getSRToCByte( + const IVAS_RTP_SR_INFO *srInfo, /* i : Split Rendering Info */ + uint8_t *tocByte /* o : toc byte 2 */ +) +{ + uint8_t bitIdx, codecId, digetic, codecFrameSize; + + if ( srInfo->codecFrameSizeMs != 5 && srInfo->codecFrameSizeMs != 10 && srInfo->codecFrameSizeMs != 20 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported codec framesize for SR provided" ); + } + + if ( srInfo->bitrateKbps < 256000 || srInfo->bitrateKbps > 512000 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Unsupported bitrate for SR" ); + } + + bitIdx = ( ( srInfo->bitrateKbps / 128000u ) - 1 ) & MASK_2BIT; + codecId = (uint8_t) srInfo->codec; + digetic = srInfo->diegetic ? 1 : 0; + + codecFrameSize = ( srInfo->codecFrameSizeMs == 20 ) ? 3 : (uint8_t) ( srInfo->codecFrameSizeMs / 5 ); + *tocByte = ( digetic << 6 ) | ( codecId << 5 ) | ( bitIdx << 3 ) | ( codecFrameSize << 1 ); + + return IVAS_ERR_OK; +} + + +static void addPackedPiDataToFrame( PIDATA_FRAME *piDataFrm, const PIDATA_PACKED *packedPiData, uint32_t piDataType ) +{ + piDataFrm->piData[piDataType].size = packedPiData->size; + memcpy( piDataFrm->piData[piDataType].data, packedPiData->data, packedPiData->size ); + + /* Indicate th PI data type presense in bitmap, If the same pi data type is + already pushed for this frame, it is overwritten with the newer data */ + if ( !( piDataFrm->piDataBitmap & ( 1u << piDataType ) ) ) + { + piDataFrm->piDataBitmap |= ( 1u << piDataType ); + piDataFrm->numPiDataAvailable++; + } + + /* Atleast one valid PI data is now pushed for this frame, clear No PI data + for this frame */ + if ( piDataFrm->piDataBitmap & ( 1u << IVAS_PI_NO_DATA ) ) + { + piDataFrm->piDataBitmap &= ~( 1u << IVAS_PI_NO_DATA ); + piDataFrm->numPiDataAvailable--; + } +} + +ivas_error IVAS_RTP_PACK_PushFrame( + IVAS_RTP_PACK_HANDLE hPack, /* i/o : IVAS rtp packer handle */ + IVAS_RTP_CODEC codecId, /* i : Codec type (IVAS/EVS) */ + const IVAS_RTP_SR_INFO *srInfo, /* i : Split Rendering Info */ + const IVAS_DATA_BUFFER *frameBuffer /* i : packed frame bitstream for IVAS/EVS */ +) +{ + ivas_error error = IVAS_ERR_OK; + uint32_t bitrate = 0; + uint32_t frameLengthInBits = 0; + uint8_t tocByte = 0; + uint8_t tocByte1 = 0; + FRAME_NODE *node = NULL; + PIDATA_FRAME *piDataFrame = &hPack->piDataCache; + uint32_t piDataType = 0; + + if ( frameBuffer == NULL || frameBuffer->length == 0 ) + { + /* Indicates a NO_DATA_FRAME in case of DTX mode */ + tocByte = ( hPack->amrwbIOMode ) ? TOC_INDICATE_NO_DATA_AMRWB : TOC_INDICATE_NO_DATA; + } + else if ( srInfo != NULL && srInfo->valid ) + { + tocByte = TOC_INDICATE_SR; + frameLengthInBits = frameBuffer->length * 8; + error = getSRToCByte( srInfo, &tocByte1 ); + ERR_CHECK_RETURN( error ); + } + else + { + error = getBitrateFromCodecAndFrameSize( codecId, frameBuffer->length, &bitrate, &frameLengthInBits, &tocByte, &hPack->amrwbIOMode ); + ERR_CHECK_RETURN( error ); + } + + /* Allocate a new frame node for this frame */ + error = BPOOL_GetBuffer( hPack->packNodePool, (void **) &node ); + ERR_CHECK_RETURN( error ); + + initFrameNode( node ); + + /* Set ToC byte & frame */ + node->toc[node->tocNumBytes++] = tocByte; + if ( srInfo != NULL && srInfo->valid ) + { + node->toc[node->tocNumBytes++] = tocByte1; + } + + node->auNumBits = frameLengthInBits; + if ( frameBuffer != NULL ) + { + memcpy( node->au, frameBuffer->buffer, frameBuffer->length ); + } + + /* If some Pi data is is Cache add to Frame Node's associated Pi Data */ + mtx_lock( &hPack->apilock ); /* Lock to prevent access to shared cache */ + if ( piDataFrame->numPiDataAvailable ) + { + uint32_t bitmap = piDataFrame->piDataBitmap; + for ( piDataType = 0; piDataType < 32 && ( bitmap != 0 ); piDataType++ ) + { + uint32_t mask = ( 1u << piDataType ); + if ( bitmap & mask ) + { + bitmap &= ~mask; /* Mask out this pi type to indicate processed */ + addPackedPiDataToFrame( &node->piDataFrame, &piDataFrame->piData[piDataType], piDataType ); + } + } + initPiDataFrame( piDataFrame ); /* Reset Cache */ + } + mtx_unlock( &hPack->apilock ); + + /* Add to frames FiFo */ + QUEUE_Push( hPack->frameQ, (NODE *) node ); + + return IVAS_ERR_OK; +} + +uint32_t IVAS_RTP_PACK_GetNumFrames( + IVAS_RTP_PACK_HANDLE hPack /* i/o : IVAS rtp packer handle */ +) +{ + uint32_t nFrames = 0; + if ( hPack ) + { + nFrames = QUEUE_Size( hPack->frameQ ); + } + return nFrames; +} + +/* Push single PI data to rtp packer + * + * Provide PI data for a current RTP Payload. All PI data is locally cached in the packer + * and set to the rtp packet with policy defined in initial configuration during call to + * IVAS_RTP_PACK_GetPacket. + * + */ +ivas_error IVAS_RTP_PACK_PushPiData( + IVAS_RTP_PACK_HANDLE hPack, /* i/o : IVAS rtp packer handle */ + const IVAS_PIDATA_GENERIC *data /* i : pointer to the PIData stucture */ +) +{ + ivas_error error = IVAS_ERR_OK; + PIDATA_PACKED packedPiData; + + 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( IVAS_PIDATA ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Wrong PI Data provided" ); + } + + error = PI_PackData( data, &packedPiData, 0 ); + ERR_CHECK_RETURN( error ); + + mtx_lock( &hPack->apilock ); /* Lock to prevent access to shared cache */ + { + FRAME_NODE *node = (FRAME_NODE *) QUEUE_Back( hPack->frameQ ); + /* use cache if no frame in Queue to associate PI data */ + PIDATA_FRAME *piDataFrm = ( node != NULL ) ? &node->piDataFrame : &hPack->piDataCache; + addPackedPiDataToFrame( piDataFrm, &packedPiData, data->piDataType ); + } + mtx_unlock( &hPack->apilock ); + + return IVAS_ERR_OK; +} + +#define WRITE_BYTE_PAYLOAD_OR_EXIT( payload, byte ) \ + if ( payload->length < payload->capacity ) \ + { \ + uint8_t _byte = ( byte ); \ + payload->buffer[payload->length++] = _byte; \ + } \ + else \ + { \ + error = IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient memory to write RTP Payload" ); \ + goto err_exit; \ + } + +ivas_error IVAS_RTP_PACK_GetPayload( + IVAS_RTP_PACK_HANDLE hPack, /* i/o : IVAS rtp packer handle */ + IVAS_DATA_BUFFER *payload, /* o : encapsulated rtp payload */ + uint32_t *numFramesInPayload /* o : no. of frames in payload */ +) +{ + uint32_t n = 0, numFrame = 0; + ivas_error error = IVAS_ERR_OK; + uint32_t numPiDataPresent = 0; + FRAME_NODE *availableFrameNodes[IVAS_MAX_FRAMES_PER_RTP_PACKET]; + size_t numEBytes = 0; + + if ( payload == NULL ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Output data buffer is NULL" ); + } + + /* Calculate number of frames to pack in this payload */ + numFrame = QUEUE_Size( hPack->frameQ ); + numFrame = ( numFrame > hPack->initConfig.maxFramesPerPacket ) ? hPack->initConfig.maxFramesPerPacket : numFrame; + *numFramesInPayload = numFrame; /* numFrames in Packet */ + + /* Collect all the frame nodes from FiFo */ + for ( n = 0; n < numFrame; n++ ) + { + FRAME_NODE *node = (FRAME_NODE *) QUEUE_Pop( hPack->frameQ ); + if ( node == NULL ) + { + assert( 0 ); /* catastrophic error, implementation issue somewhere */ + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "NULL found in frame nodes" ); + } + /* Calculate number of PI data present in total */ + numPiDataPresent += node->piDataFrame.numPiDataAvailable; + availableFrameNodes[n] = node; + } + + /* IVAS Payload starts with E-Bytes */ + packEBytes( hPack, ( numPiDataPresent > 0 ), payload->capacity, &payload->buffer[payload->length], &numEBytes ); + payload->length += numEBytes; + + /* ToC bytes (atleast 1 byte per frame, 2 if SR )*/ + for ( n = 0; n < numFrame; n++ ) + { + FRAME_NODE *node = availableFrameNodes[n]; + uint8_t fBit = ( n != ( numFrame - 1 ) ) ? TOC_HEADER_FOLLOWS : 0; /* Next ToC present */ + + WRITE_BYTE_PAYLOAD_OR_EXIT( payload, ( node->toc[0] | fBit ) ); + if ( node->tocNumBytes == 2 ) + { + WRITE_BYTE_PAYLOAD_OR_EXIT( payload, node->toc[1] ); + } + } + + /* Frame Data */ + for ( n = 0; n < numFrame; n++ ) + { + FRAME_NODE *node = availableFrameNodes[n]; + size_t frameLength = ( node->auNumBits + 7 ) >> 3; /* zero padded length in bytes */ + if ( payload->length + frameLength <= payload->capacity ) + { + memcpy( &payload->buffer[payload->length], node->au, frameLength ); + } + else + { + error = IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient memory to write RTP Payload" ); + goto err_exit; + } + payload->length += frameLength; + } + + /* PI Data */ + if ( numPiDataPresent > 0 ) + { + bool skipPiData = false; + size_t nBytes = payload->length; + uint32_t numPiDataWritten = 0; + + for ( n = 0; n < numFrame; n++ ) + { + uint32_t piDataType = 0; + FRAME_NODE *node = availableFrameNodes[n]; + PIDATA_FRAME *piDataFrame = &node->piDataFrame; + uint32_t bitmap = piDataFrame->piDataBitmap; + uint8_t PM = 0, PF = 0; + + for ( piDataType = 0; piDataType < 32 && ( bitmap != 0 ); piDataType++ ) + { + uint32_t mask = ( 1u << piDataType ); + if ( bitmap & mask ) + { + bitmap &= ~mask; /* Mask out this pi type to indicate processing */ + /* Check if last PI data this frame */ + PM = piDataFrame->piData[piDataType].data[0] & 0x60; + PM = (uint8_t) ( ( bitmap == 0 && PM != PI_HEADER_PM_GENERIC ) ? PI_HEADER_PM_LAST : PM ); + /* Check if last PI data all frames */ + PF = (uint8_t) ( ( bitmap == 0 && ( numPiDataWritten + 1 == numPiDataPresent ) ) ? PI_HEADER_PF_LAST : PI_HEADER_PF_NOT_LAST ); /* Last PI in Payload */ + /* Update the first byte of PI Header with PF/PM */ + piDataFrame->piData[piDataType].data[0] |= ( PF | PM ); + if ( nBytes + piDataFrame->piData[piDataType].size < payload->capacity ) + { + memcpy( &payload->buffer[nBytes], piDataFrame->piData[piDataType].data, piDataFrame->piData[piDataType].size ); + nBytes += piDataFrame->piData[piDataType].size; + } + else + { + skipPiData = true; /* Not enough bytes in output for PI data */ + } + numPiDataWritten++; + } + } + } + if ( !skipPiData ) + { + payload->length = nBytes; /* update payload length after PI packing */ + } + } + +err_exit: + /* Pop frames from Queue */ + for ( n = 0; n < numFrame; n++ ) + { + if ( BPOOL_FreeBuffer( hPack->packNodePool, availableFrameNodes[n] ) != IVAS_ERR_OK ) + { + assert( 0 ); /* catastrophic error if this fails */ + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "frame node could not be freed" ); + } + availableFrameNodes[n] = NULL; + } + + return error; +} + +ivas_error IVAS_RTP_PACK_GetPacket( + IVAS_RTP_PACK_HANDLE hPack, /* i/o : IVAS rtp packer handle */ + IVAS_DATA_BUFFER *packet, /* o : encapsulated rtp packet */ + uint32_t *numFramesInPacket /* o : no. of frames in packet */ +) +{ + ivas_error error = PackRtpHeader( &hPack->header, packet ); + ERR_CHECK_RETURN( error ); + + error = IVAS_RTP_PACK_GetPayload( hPack, packet, numFramesInPacket ); + ERR_CHECK_RETURN( error ); + + UpdateRtpHeader( &hPack->header, ( *numFramesInPacket ) * 320 ); + + return IVAS_ERR_OK; +} + +ivas_error IVAS_RTP_UNPACK_Open( + IVAS_RTP_UNPACK_HANDLE *phUnpack, /* i/o : rtp unpacker handle */ + const IVAS_RTP_UNPACK_CONFIG *config /* i : initial configuration for rtp unpacker */ +) +{ + ivas_error error = IVAS_ERR_OK; + IVAS_RTP_UNPACK_HANDLE hUnpack; + + if ( phUnpack == NULL || config == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *phUnpack = NULL; + if ( ( hUnpack = (IVAS_RTP_UNPACK_HANDLE) calloc( 1, sizeof( struct IVAS_RTP_UNPACK ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS rtp unpack handle" ); + } + + if ( config->maxFramesPerPacket > IVAS_MAX_FRAMES_PER_RTP_PACKET ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Max frame per packet exeeds %d", IVAS_MAX_FRAMES_PER_RTP_PACKET ); + } + + hUnpack->maxNumberOfFrames = ( config->maxFramesPerPacket == 0 ) ? IVAS_MAX_FRAMES_PER_RTP_PACKET : config->maxFramesPerPacket; + hUnpack->maxNumberOfPiData = hUnpack->maxNumberOfFrames * IVAS_PI_MAX_ID; + + error = BPOOL_Create( &hUnpack->unpackNodePool, sizeof( UNPACK_NODE ), hUnpack->maxNumberOfFrames ); + ERR_CHECK_RETURN( error ); + + error = BPOOL_Create( &hUnpack->piDataPool, sizeof( PIDATA_NODE ), hUnpack->maxNumberOfPiData ); + ERR_CHECK_RETURN( error ); + + error = QUEUE_Create( &hUnpack->frameQ ); + ERR_CHECK_RETURN( error ); + + error = QUEUE_Create( &hUnpack->piDataQ ); + ERR_CHECK_RETURN( error ); + + hUnpack->initConfig = *config; + mtx_init( &hUnpack->apilock, 0 ); + + initRequests( hUnpack->requests ); + + *phUnpack = hUnpack; + return IVAS_ERR_OK; +} + +/* Close and free an existing instance of rtp unpacker */ +void IVAS_RTP_UNPACK_Close( + IVAS_RTP_UNPACK_HANDLE *phUnpack /* i/o : IVAS rtp unpacker handle */ +) +{ + IVAS_RTP_UNPACK_HANDLE hUnpack; + + /* Free all memory */ + if ( phUnpack == NULL || *phUnpack == NULL ) + { + return; + } + + hUnpack = *phUnpack; + mtx_destroy( &hUnpack->apilock ); + QUEUE_Destroy( &hUnpack->frameQ ); + QUEUE_Destroy( &hUnpack->piDataQ ); + BPOOL_Destroy( &hUnpack->piDataPool ); + BPOOL_Destroy( &hUnpack->unpackNodePool ); + free( hUnpack->header.extData ); + free( hUnpack ); + *phUnpack = NULL; +} + +static void setEVSRequests( IVAS_RTP_BANDWIDTH bandwidth, uint32_t bitrate, IVAS_RTP_CA_MODE caMode, IVAS_RTP_REQUEST_VALUE *requests ) +{ + requests[IVAS_REQUEST_CODEC].codec = IVAS_RTP_EVS; + requests[IVAS_REQUEST_CA_MODE].caMode = caMode; + requests[IVAS_REQUEST_BITRATE].bitrate = bitrate; + requests[IVAS_REQUEST_BANDWIDTH].bandwidth = bandwidth; +} + +static uint32_t parseInitialEByte( const IVAS_DATA_BUFFER *payload, uint32_t nBytes, IVAS_RTP_REQUEST_VALUE *requests ) +{ + if ( nBytes < payload->length ) + { + uint8_t byte = payload->buffer[nBytes]; + uint8_t EvsIvasIndicator = ( byte & ( ~MASK_4BIT ) ); + uint8_t BR = ( byte & MASK_4BIT ); + + if ( ( byte & EBYTE_TOC_HEADER_BIT ) == 0 ) + { + return nBytes; + } + + nBytes++; /* Consume this e-byte */ + + switch ( EvsIvasIndicator ) + { + case EBYTE_CMR_T_EVS_NB: + if ( BR < 7 ) + { + uint32_t bitrate = evsFrameSizeInBits[BR] * IVAS_NUM_FRAMES_PER_SEC; + setEVSRequests( IVAS_BANDWIDTH_NB, bitrate, IVAS_RTP_CA_NO_REQ, requests ); + } + break; + case EBYTE_CMR_T_EVS_IO: /* AMRWB-IO */ + if ( BR < 9 ) + { + uint32_t bitrate = amrWBIOFrameSizeInBits[BR] * IVAS_NUM_FRAMES_PER_SEC; + setEVSRequests( IVAS_BANDWIDTH_NO_REQ, bitrate, IVAS_RTP_CA_NO_REQ, requests ); + } + break; + case EBYTE_CMR_T_EVS_CA_WB: + if ( BR < 8 ) + { + uint32_t bitrate = 13200; /* Fixed in CA Mode */ + setEVSRequests( IVAS_BANDWIDTH_WB, bitrate, BR, requests ); + } + break; + case EBYTE_CMR_T_EVS_CA_SWB: + if ( BR < 8 ) + { + uint32_t bitrate = 13200; /* Fixed in CA Mode */ + setEVSRequests( IVAS_BANDWIDTH_SWB, bitrate, BR, requests ); + } + break; + case EBYTE_CMR_T_EVS_WB: + if ( BR < 12 ) + { + uint32_t bitrate = evsFrameSizeInBits[BR] * IVAS_NUM_FRAMES_PER_SEC; + setEVSRequests( IVAS_BANDWIDTH_WB, bitrate, IVAS_RTP_CA_NO_REQ, requests ); + } + break; + case EBYTE_CMR_T_EVS_SWB: /* Intentional fall through */ + if ( BR < 12 && BR > 2 ) + { + uint32_t bitrate = evsFrameSizeInBits[BR] * IVAS_NUM_FRAMES_PER_SEC; + setEVSRequests( IVAS_BANDWIDTH_SWB, bitrate, IVAS_RTP_CA_NO_REQ, requests ); + } + break; + case EBYTE_CMR_T_EVS_FB: + if ( BR < 12 && BR > 4 ) + { + uint32_t bitrate = evsFrameSizeInBits[BR] * IVAS_NUM_FRAMES_PER_SEC; + setEVSRequests( IVAS_BANDWIDTH_FB, bitrate, IVAS_RTP_CA_NO_REQ, requests ); + } + break; + case EBYTE_CMR_T_IVAS: /* IVAS */ + if ( BR != 14 ) + { + requests[IVAS_REQUEST_CODEC].codec = IVAS_RTP_IVAS; + requests[IVAS_REQUEST_BITRATE].bitrate = ( BR == 0xF ) ? 0 : ivasFrameSizeInBits[BR] * IVAS_NUM_FRAMES_PER_SEC; + requests[IVAS_REQUEST_CA_MODE].caMode = IVAS_RTP_CA_NO_REQ; + } + break; + } + } + + return nBytes; +} + +static uint32_t parseSubsequentEByte( const IVAS_DATA_BUFFER *payload, uint32_t nBytes, IVAS_RTP_REQUEST_VALUE *requests, bool *piDataIndicated ) +{ + while ( nBytes < payload->length ) + { + uint8_t byte = payload->buffer[nBytes]; + uint8_t ET = ( byte & ( ~MASK_4BIT ) ); + + if ( ( byte & EBYTE_TOC_HEADER_BIT ) == 0 ) + { + return nBytes; + } + + nBytes++; /* Consume this e-byte */ + + switch ( ET ) + { + case EBYTE_BANDWIDTH_REQUEST: /* Bandwidth Request */ + { + requests[IVAS_REQUEST_BANDWIDTH].bandwidth = IVAS_BANDWIDTH_WB + ( byte & MASK_2BIT ); + } + break; + case EBYTE_FORMAT_REQUEST: /* Format Request */ + { + bool S = ( byte >> 3 ) & MASK_1BIT; + if ( S ) + { + /* Use the next byte to extract SubFormat */ + if ( nBytes < payload->length ) + { + byte = payload->buffer[nBytes++]; + requests[IVAS_REQUEST_SUBFORMAT].subFormatType = byte & MASK_6BIT; + } + } + + requests[IVAS_REQUEST_FORMAT].formatType = byte & MASK_3BIT; + } + break; + case EBYTE_PI_INDICATOR: /* PI Indication */ + *piDataIndicated = true; + break; + case EBYTE_SR_REQUEST: /* Split Rendering Request */ + { + IVAS_RTP_SPLITRENDER *srConfig = &requests[IVAS_REQUEST_SR_CONFIG].srConfig; + srConfig->diegetic = ( byte >> 3 ) & MASK_1BIT; + srConfig->yaw = ( byte >> 2 ) & MASK_1BIT; + srConfig->pitch = ( byte >> 1 ) & MASK_1BIT; + srConfig->roll = byte & MASK_1BIT; + srConfig->valid = true; + } + break; + default: /* Reserved for future use - unhandled atm */ + break; + } + } + + return nBytes; +} + +static ivas_error parseToCByte( const IVAS_DATA_BUFFER *payload, uint32_t *numBytes, uint32_t *numFrames, TOC_INFO *toc, uint32_t maxNumberOfToCBytes ) +{ + bool headerFollows = true; + uint32_t nBytes = *numBytes; + + *numFrames = 0; + while ( nBytes < payload->length && headerFollows ) + { + uint8_t byte = payload->buffer[nBytes]; + uint8_t BR = byte & MASK_4BIT; + uint8_t FT = byte & ( ( ~MASK_4BIT ) & MASK_6BIT ); + + headerFollows = ( byte & ( ~MASK_6BIT ) ) == TOC_HEADER_FOLLOWS; + + if ( ( byte & EBYTE_TOC_HEADER_BIT ) != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNSUPPORTED_FRAME, "Expected ToC byte missing" ); + } + + nBytes++; /* Consume this e-byte */ + + if ( *numFrames == maxNumberOfToCBytes ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "No of frames in packet exceed max defined" ); + } + + *numFrames += 1; + memset( toc, 0, sizeof( *toc ) ); + + if ( FT == TOC_INDICATE_ARMWB_Q || FT == TOC_INDICATE_AMRWB ) + { + toc->codecId = IVAS_RTP_EVS; + toc->isAMRWB_IOmode = true; + toc->speechLostIndicated = ( FT == TOC_INDICATE_ARMWB_Q ) ? true : false; /* Q bit = 0 for AMRWB, BR is valid */ + if ( BR <= 9 ) + { + toc->auNumBits = amrWBIOFrameSizeInBits[BR]; + } + else if ( BR < 14 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNSUPPORTED_FRAME, "Reserved bitrate provided in AMRWB ToC" ); + } + else + { + toc->speechLostIndicated = ( BR == 14 ); /* SPEECH_LOST */ + toc->auNumBits = 0; + } + } + else if ( FT == TOC_INDICATE_IVAS ) + { + toc->codecId = IVAS_RTP_IVAS; + if ( BR == 14 ) + { + /* Read Unconditional SR-ToC byte */ + if ( nBytes < payload->length ) + { + uint8_t SR_BR; + static const uint8_t codecFrameSizeMap[4] = { 0, 5, 10, 20 }; + + byte = payload->buffer[nBytes++]; + SR_BR = ( byte >> 3 ) & MASK_2BIT; + if ( SR_BR == 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNSUPPORTED_FRAME, "Reserved bitrate provided in SR ToC" ); + } + toc->srInfo.valid = true; + toc->srInfo.diegetic = ( byte >> 6 ) & MASK_1BIT; + toc->srInfo.codec = IVAS_SR_TRANSPORT_LCLD + ( ( byte >> 5 ) & MASK_1BIT ); + toc->srInfo.bitrateKbps = ( SR_BR + 1 ) * 128000u; + toc->srInfo.codecFrameSizeMs = codecFrameSizeMap[( byte >> 1 ) & MASK_2BIT]; + toc->auNumBits = toc->srInfo.bitrateKbps * toc->srInfo.codecFrameSizeMs / 1000; + } + else + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Underflow during ToC SR byte" ); + } + } + else + { + toc->auNumBits = ivasFrameSizeInBits[BR]; + } + } + else /* EVS */ + { + toc->codecId = IVAS_RTP_EVS; + toc->speechLostIndicated = ( FT == TOC_INDICATE_ARMWB_Q ) ? true : false; /* Q bit = 0 for AMRWB, BR is valid */ + if ( BR < 13 ) + { + toc->auNumBits = evsFrameSizeInBits[BR]; + } + else if ( BR == 13 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNSUPPORTED_FRAME, "Reserved bitrate provided in EVS ToC" ); + } + else + { + toc->speechLostIndicated = ( BR == 14 ); /* SPEECH_LOST */ + toc->auNumBits = 0; + } + } + + toc++; + + /* Handle any frame specific E-Bytes here currently there are none, so we skip any E-Bytes here after */ + if ( headerFollows ) + { + while ( nBytes < payload->length ) + { + byte = payload->buffer[nBytes]; + if ( ( byte & EBYTE_TOC_HEADER_BIT ) == 0 ) + { + break; + } + nBytes++; + } + } + } + + *numBytes = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error parsePIData( IVAS_RTP_UNPACK_HANDLE hUnpack, uint32_t rtpTimestamp, const IVAS_DATA_BUFFER *payload, uint32_t *numBytes, uint32_t *numPiDataInPacket ) +{ + bool PF = true; + uint32_t nBytes = *numBytes; + bool isFirstPiSize = true; + + while ( PF ) + { + uint8_t piHeader0, PM, piDataType, byte = 0; + uint32_t piSize = 0; + + if ( nBytes + 1 >= payload->length ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Underflow during expected PI Header read" ); + } + + piHeader0 = payload->buffer[nBytes++]; + + PF = ( piHeader0 >> 7 ) & MASK_1BIT; /* New PI header follows this PI Data Frame */ + PM = ( piHeader0 & ( ~MASK_5BIT ) ) & MASK_7BIT; /* PI Marker Bits */ + piDataType = ( piHeader0 & MASK_5BIT ); + + do + { + byte = payload->buffer[nBytes++]; + piSize += isFirstPiSize ? ( byte & MASK_5BIT ) : byte; + if ( nBytes >= payload->length ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Underflow during reading piSize" ); + } + isFirstPiSize = false; + } while ( byte == 255 || piSize == 32 ); + + if ( piDataType == IVAS_PI_NO_DATA ) + { + if ( piSize > 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "NO_PI_DATA should be 0 sized" ); + } + + /* Do not add a node for NO_DATA */ + } + else if ( nBytes + piSize <= payload->length ) + { + PIDATA_NODE *node = NULL; + ivas_error error = BPOOL_GetBuffer( hUnpack->piDataPool, (void **) &node ); + ERR_CHECK_RETURN( error ); + + node->next = NULL; + + error = PI_UnPackData( piDataType, piSize, &payload->buffer[nBytes], (IVAS_PIDATA_GENERIC *) &node->data ); + ERR_CHECK_RETURN( error ); + + node->timestamp = rtpTimestamp; + + nBytes += piSize; + *numPiDataInPacket += 1; + + QUEUE_Push( hUnpack->piDataQ, (NODE *) node ); + } + else + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Underflow during reading pi data" ); + } + + if ( PM == PI_HEADER_PM_LAST ) + { + rtpTimestamp += 16000 / IVAS_NUM_FRAMES_PER_SEC; + } + } + + *numBytes = nBytes; + return IVAS_ERR_OK; +} + +ivas_error IVAS_RTP_UNPACK_PushPayload( + IVAS_RTP_UNPACK_HANDLE hUnpack, /* i/o : IVAS rtp unpacker handle */ + const IVAS_DATA_BUFFER *payload, /* i : received rtp payload */ + uint32_t timestamp, /* i : timestamp in RTP Clock @ 16KHz from rtp header */ + uint16_t sequenceNumber, /* i : sequence number from rtp header */ + uint32_t *numFramesInPacket, /* o : number of IVAS/EVS frames in rtp packet */ + uint32_t *numPiDataInPacket, /* o : number of PI data received in rtp packet */ + uint32_t *remoteRequestBitmap /* o : bitmap of available request in this packet */ +) +{ + ivas_error error = IVAS_ERR_OK; + uint32_t nBytes = 0, numFrames = 0, numPiData = 0, n; + bool piDataIndicated = false; + TOC_INFO toc[IVAS_MAX_FRAMES_PER_RTP_PACKET]; + + IVAS_RTP_REQUEST_VALUE oldRequests[IVAS_REQUEST_MAX]; + + if ( hUnpack == NULL || payload == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( remoteRequestBitmap != NULL ) + { + *remoteRequestBitmap = 0; + } + + if ( numFramesInPacket != NULL ) + { + *numFramesInPacket = 0; + } + + if ( numPiDataInPacket != NULL ) + { + *numPiDataInPacket = 0; + } + + /* Sanity check if any frame or PI data from last packet is still not pulled */ + if ( QUEUE_Size( hUnpack->frameQ ) > 0 || QUEUE_Size( hUnpack->piDataQ ) > 0 ) + { + assert( 0 ); + return IVAS_ERROR( IVAS_ERR_INTERNAL, "Previous packet data should be consumed before next packet is pushed" ); + } + + memcpy( oldRequests, hUnpack->requests, sizeof( oldRequests ) ); + + /* Unpack IVAS Payload, starting with the E-Bytes */ + nBytes = parseInitialEByte( payload, nBytes, hUnpack->requests ); + + /* Unpack any subsequent E-bytes */ + nBytes = parseSubsequentEByte( payload, nBytes, hUnpack->requests, &piDataIndicated ); + + /* Unpack the ToC Bytes => Extract number of frames in packet */ + error = parseToCByte( payload, &nBytes, &numFrames, toc, sizeof( toc ) / sizeof( toc[0] ) ); + ERR_CHECK_RETURN( error ); + + /* Read frame bits */ + for ( n = 0; n < numFrames; n++ ) + { + uint32_t frameSizeBytes; + UNPACK_NODE *node = NULL; + + /* Get a new node */ + error = BPOOL_GetBuffer( hUnpack->unpackNodePool, (void **) &node ); + ERR_CHECK_RETURN( error ); + + node->next = NULL; + node->timestamp = timestamp + ( n * 320 ); + node->seqNumber = sequenceNumber; + node->toc = toc[n]; + + frameSizeBytes = ( node->toc.auNumBits + 7 ) / 8; + if ( nBytes + frameSizeBytes <= payload->length ) + { + memcpy( node->au, &payload->buffer[nBytes], frameSizeBytes ); + nBytes += frameSizeBytes; + } + else + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "Underflow during expected frame bits" ); + } + + /* Add to frames FiFo */ + QUEUE_Push( hUnpack->frameQ, (NODE *) node ); + } + + if ( piDataIndicated ) + { + error = parsePIData( hUnpack, timestamp, payload, &nBytes, &numPiData ); + if ( error != IVAS_ERR_OK ) + { + /* PI Parsing errors are not fatal => indicate no PI data in packet as workaround */ + numPiData = 0; + } + } + + if ( numFramesInPacket != NULL ) + { + *numFramesInPacket = numFrames; + } + + if ( numPiDataInPacket ) + { + *numPiDataInPacket = numPiData; + } + + if ( remoteRequestBitmap ) + { + for ( n = 0; n < IVAS_REQUEST_MAX; n++ ) + { + bool changed = ( memcmp( &hUnpack->requests[n], &oldRequests[n], sizeof( IVAS_RTP_REQUEST_VALUE ) ) != 0 ); + *remoteRequestBitmap |= changed ? ( 1u << n ) : 0; + } + } + + return IVAS_ERR_OK; +} + +ivas_error IVAS_RTP_UNPACK_PushPacket( + IVAS_RTP_UNPACK_HANDLE hUnpack, /* i/o : IVAS rtp unpacker handle */ + const IVAS_DATA_BUFFER *packet, /* i : received rtp Packet */ + uint32_t *numFramesInPacket, /* o : number of IVAS/EVS frames in rtp packet */ + uint32_t *numPiDataInPacket, /* o : number of PI data received in rtp packet */ + uint32_t *remoteRequestBitmap /* o : bitmap of available request in this packet */ +) +{ + ivas_error error = IVAS_ERR_OK; + uint32_t numHeaderBytes = 0; + IVAS_DATA_BUFFER payload; + + error = UnpackRtpPacket( packet, &hUnpack->header, &numHeaderBytes ); + ERR_CHECK_RETURN( error ); + + /* Offset to RTP Payload */ + payload.capacity = packet->capacity; + payload.buffer = packet->buffer + numHeaderBytes; + payload.length = packet->length - numHeaderBytes; + + return IVAS_RTP_UNPACK_PushPayload( + hUnpack, + &payload, + hUnpack->header.timestamp, + hUnpack->header.seqNumber, + numFramesInPacket, + numPiDataInPacket, + remoteRequestBitmap ); +} + +ivas_error IVAS_RTP_UNPACK_GetRequest( + IVAS_RTP_UNPACK_HANDLE hUnpack, /* i/o : IVAS rtp packer handle */ + IVAS_RTP_REQUEST_TYPE type, /* i : remote request type */ + IVAS_RTP_REQUEST_VALUE *value /* o : pointer of the requested type */ +) +{ + if ( type < 0 || type >= IVAS_REQUEST_MAX ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Invalid request key provided" ); + } + *value = hUnpack->requests[type]; + return IVAS_ERR_OK; +} + +ivas_error IVAS_RTP_UNPACK_PullFrame( + IVAS_RTP_UNPACK_HANDLE hUnpack, /* i/o : IVAS rtp unpacker handle */ + IVAS_RTP_CODEC *receivedCodecId, /* o : Codec type (IVAS/EVS) */ + IVAS_RTP_SR_INFO *srInfo, /* o : Split Rendering Info */ + IVAS_DATA_BUFFER *frameBuffer, /* o : packed frame bitstream for IVAS/EVS */ + int16_t *frameSizeInBits, /* o : exact frame size in bits (AMRWB IO) */ + uint32_t *timestamp, /* o : timestamp in RTP Clock @ 16KHz */ + uint16_t *sequenceNumber, /* o : sequence number from rtp header */ + bool *speechLostIndicated, /* o : Is current frame indicated as Lost */ + bool *isAMRWB_IOmode /* o : Is AMRWB_IO mode EVS frame */ +) +{ + size_t length = 0; + UNPACK_NODE *node = (UNPACK_NODE *) QUEUE_Pop( hUnpack->frameQ ); + + /* Check if a node is available in FiFo */ + if ( node == NULL ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "No more frames in unpack fifo" ); + } + + length = ( node->toc.auNumBits + 7 ) / 8; + if ( frameBuffer != NULL && ( length <= frameBuffer->capacity ) ) + { + memcpy( frameBuffer->buffer, node->au, length ); + frameBuffer->length = length; + } + + if ( frameSizeInBits != NULL ) + { + *frameSizeInBits = (int16_t) node->toc.auNumBits; + } + + if ( receivedCodecId != NULL ) + { + *receivedCodecId = node->toc.codecId; + } + + if ( srInfo != NULL ) + { + *srInfo = node->toc.srInfo; + } + + if ( timestamp != NULL ) + { + *timestamp = node->timestamp; + } + + if ( sequenceNumber != NULL ) + { + *sequenceNumber = node->seqNumber; + } + + if ( speechLostIndicated != NULL ) + { + *speechLostIndicated = node->toc.speechLostIndicated; + } + + if ( isAMRWB_IOmode != NULL ) + { + *isAMRWB_IOmode = node->toc.isAMRWB_IOmode; + } + + return BPOOL_FreeBuffer( hUnpack->unpackNodePool, node ); +} + +ivas_error IVAS_RTP_UNPACK_PullNextPiData( + IVAS_RTP_UNPACK_HANDLE hUnpack, /* i/o : IVAS rtp unpacker handle */ + IVAS_PIDATA_GENERIC *data, /* o : output data buffer for the Pi data */ + size_t capacity, /* i : capacity of pi data buffer in bytes */ + uint32_t *timestamp /* o : timestamp in RTP Clock @ 16KHz */ +) +{ + IVAS_PIDATA_GENERIC *pi = NULL; + PIDATA_NODE *node = (PIDATA_NODE *) QUEUE_Pop( hUnpack->piDataQ ); + + /* Check if a node is available in FiFo */ + if ( node == NULL ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNDERFLOW, "No more pi data in unpack fifo" ); + } + + pi = (IVAS_PIDATA_GENERIC *) &node->data; + + if ( data != NULL && ( pi->size <= capacity ) ) + { + memcpy( data, pi, pi->size ); + } + + if ( timestamp != NULL ) + { + *timestamp = node->timestamp; + } + + return BPOOL_FreeBuffer( hUnpack->piDataPool, node ); +} diff --git a/lib_util/ivas_rtp_pi_data.c b/lib_util/ivas_rtp_pi_data.c new file mode 100644 index 0000000000000000000000000000000000000000..b533d07c284194e88202dce64512ac06c86575af --- /dev/null +++ b/lib_util/ivas_rtp_pi_data.c @@ -0,0 +1,1789 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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 "ivas_error_utils.h" +#include "ivas_rtp_internal.h" +#include +#include +#include "cnst.h" + + +#ifndef min +#define min( 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 ); + +static __inline uint32_t writeInt16( uint8_t *buffer, uint32_t idx, int16_t val ) +{ + buffer[idx++] = (uint8_t) ( val >> 8 ); + buffer[idx++] = (uint8_t) ( val & 0x00FF ); + return idx; +} + +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() + * + * Convert a float value into a Q15 encoded value. + *-----------------------------------------------------------------------*/ +static int16_t ivasPayload_convertToQ15( float value ) +{ + value = ( value * 32768.0f ); + value = value > +32767.0f ? +32767.0f : value; + value = value < -32768.0f ? -32768.0f : value; + return (int16_t) ( value ); +} + +/*-----------------------------------------------------------------------* + * ivasPayload_convertToQ10() + * + * Convert a float value into a Q10 encoded value. + *-----------------------------------------------------------------------*/ +static int16_t ivasPayload_convertToQ10( float value ) +{ + value = ( value * 1024.0f ); + value = value > +1024.0f ? +1024.0f : value; + value = value < -1024.0f ? -1024.0f : value; + return (int16_t) ( value ); +} + +/*-----------------------------------------------------------------------* + * ivasPayload_convertToQ9() + * + * Convert a float value into a Q9 encoded value. + *-----------------------------------------------------------------------*/ +static int16_t ivasPayload_convertToQ9( float value ) +{ + value = ( value * 512.0f ); + value = value > +512.0f ? +512.0f : value; + value = value < -512.0f ? -512.0f : value; + return (int16_t) ( value ); +} + +static uint32_t packQuaternion( IVAS_QUATERNION orientation, uint8_t *buffer ) +{ + uint32_t nBytes = 0; + float q[4], q_max; + uint16_t max_q_idx, n, k; + uint32_t lWord; + + q[0] = FLOAT_FROM_Q15( orientation.w_fx >> 16 ); + q[1] = FLOAT_FROM_Q15( orientation.x_fx >> 16 ); + q[2] = FLOAT_FROM_Q15( orientation.y_fx >> 16 ); + q[3] = FLOAT_FROM_Q15( orientation.z_fx >> 16 ); + + max_q_idx = 0; + q_max = (float) fabs( q[0] ); + for ( n = 1; n < 4; n++ ) + { + if ( (float) fabs( q[n] ) > q_max ) + { + q_max = (float) fabs( q[n] ); + max_q_idx = n; + } + } + + if ( q[max_q_idx] < 0 ) + { + for ( n = 0; n < 4; n++ ) + { + q[n] = -q[n]; + } + } + lWord = ( (uint32_t) max_q_idx ) << 30; + + k = 1; + for ( n = 0; n < 4; n++ ) + { + if ( n == max_q_idx ) + { + continue; + } + lWord |= ( ( (int16_t) ( ( q[n] + 1 / sqrt( 2.0f ) ) * 1023 / sqrt( 2.0f ) ) & MASK_10BIT ) << ( 30 - k * 10 ) ); + k++; + } + + buffer[nBytes++] = ( lWord >> 24 ) & MASK_8BIT; + buffer[nBytes++] = ( lWord >> 16 ) & MASK_8BIT; + buffer[nBytes++] = ( lWord >> 8 ) & MASK_8BIT; + buffer[nBytes++] = (lWord) &MASK_8BIT; + + return nBytes; +} + + +static ivas_error unpackQuaternion( const uint8_t *buffer, IVAS_QUATERNION *orientation ) +{ + uint32_t i, k, lWord; + uint16_t max_q_idx, tmp; + float q[4], qs; + + lWord = ( (uint32_t) buffer[0] ) << 24; + lWord |= ( (uint32_t) buffer[1] ) << 16; + lWord |= ( (uint32_t) buffer[2] ) << 8; + lWord |= (uint32_t) buffer[3]; + + max_q_idx = ( lWord >> 30 ) & MASK_2BIT; + k = 1; + qs = 0.0f; + for ( i = 0; i < 4; i++ ) + { + if ( i == max_q_idx ) + { + continue; + } + tmp = ( lWord >> ( 30 - k * 10 ) ) & MASK_10BIT; + q[i] = tmp / 1023.0f * sqrtf( 2.0f ) - 1 / sqrtf( 2.0f ); + qs += q[i] * q[i]; + k++; + } + q[max_q_idx] = sqrtf( 1 - qs ); + orientation->w_fx = ivasPayload_convertToQ15( q[0] ); + orientation->x_fx = ivasPayload_convertToQ15( q[1] ); + orientation->y_fx = ivasPayload_convertToQ15( q[2] ); + orientation->z_fx = ivasPayload_convertToQ15( q[3] ); + + return IVAS_ERR_OK; +} + +static ivas_error packUnsupportedData( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + (void) piData; + (void) buffer; + (void) maxDataBytes; + /* Skip packing */ + *nBytesWritten = 0; + return IVAS_ERR_OK; +} + +static ivas_error unpackUnsupportedData( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + (void) piData; + (void) buffer; + (void) numDataBytes; + /* Skip unpacking */ + return IVAS_ERR_OK; +} + +static ivas_error packNoPiData( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + (void) piData; + + *nBytesWritten = 0; + + /* NO_PI_DATA is just PI header with no data */ + if ( maxDataBytes < 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space in PI data buffer for NO_PI_DATA" ); + } + + buffer[nBytes++] = ( IVAS_PI_NO_DATA ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 0; /* NO_PI_DATA is 0 bytes */ + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackNoPiData( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + (void) buffer; + + if ( numDataBytes != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "NO_PI_DATA must be 0 byte" ); + } + + piData->size = sizeof( IVAS_PIDATA_NO_DATA ); + return IVAS_ERR_OK; +} + +static ivas_error packOrientation( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_ORIENTATION *orientation = (const IVAS_PIDATA_ORIENTATION *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_ORIENTATION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in Orientation PI data" ); + } + + if ( ( piData->piDataType != IVAS_PI_SCENE_ORIENTATION ) && ( piData->piDataType != IVAS_PI_DEVICE_ORIENTATION_COMPENSATED ) && ( piData->piDataType != IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED ) && ( piData->piDataType != IVAS_PI_PLAYBACK_DEVICE_ORIENTATION ) && ( piData->piDataType != IVAS_PI_HEAD_ORIENTATION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in Orientation PI data" ); + } + + /* Orientation data is 4 bytes, header is 2 bytes */ + if ( maxDataBytes < 4 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack Orientation PI data" ); + } + + buffer[nBytes++] = ( orientation->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 4; + nBytes += packQuaternion( orientation->orientation, &buffer[nBytes] ); + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error packISMOrientation( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_ISM_ORIENTATION *orientation = (const IVAS_PIDATA_ISM_ORIENTATION *) piData; + uint16_t n; + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_ISM_ORIENTATION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in Orientation PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_ORIENTATION ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in Orientation PI data" ); + } + + /* Orientation data is 4 bytes, header is 2 bytes */ + if ( maxDataBytes < 4 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack Orientation PI data" ); + } + + buffer[nBytes++] = ( orientation->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) orientation->numObjects * 4; + for ( n = 0; n < orientation->numObjects; n++ ) + { + nBytes += packQuaternion( orientation->orientation[n], &buffer[nBytes] ); + } + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackOrientation( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_ORIENTATION *orientation = (IVAS_PIDATA_ORIENTATION *) piData; + + /* Orientation data is 4 bytes */ + if ( numDataBytes != 4 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack Orientation PI data" ); + } + + piData->size = sizeof( IVAS_PIDATA_ORIENTATION ); + unpackQuaternion( buffer, &( orientation->orientation ) ); + + return IVAS_ERR_OK; +} + +static ivas_error unpackISMOrientation( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_ISM_ORIENTATION *ism_orientation = (IVAS_PIDATA_ISM_ORIENTATION *) piData; + + /* Orientation data is 4 bytes */ + uint16_t n; + if ( numDataBytes % 4 != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack Orientation PI data" ); + } + + ism_orientation->size = sizeof( IVAS_PIDATA_ISM_ORIENTATION ); + ism_orientation->numObjects = (uint16_t) numDataBytes / 4; + + for ( n = 0; n < ism_orientation->numObjects; n++ ) + { + unpackQuaternion( &buffer[4 * n], &( ism_orientation->orientation[n] ) ); + } + + for ( ; n < IVAS_MAX_NUM_OBJECTS; n++ ) + { + ism_orientation->orientation[n].w_fx = 0; + ism_orientation->orientation[n].x_fx = 0; + ism_orientation->orientation[n].y_fx = 0; + ism_orientation->orientation[n].z_fx = 0; + } + + return IVAS_ERR_OK; +} + +static uint32_t getIndexTable( const float *table, uint32_t tableLength, float value ) +{ + uint32_t idx = 0; + if ( value <= table[0] ) + { + return 0; + } + + for ( idx = 1; idx < tableLength; idx++ ) + { + if ( value < table[idx] ) + { + break; + } + } + return idx - 1; +} + +#define GET_IDX( table, nBits, value ) getIndexTable( table, ( 1u << ( nBits ) ), ( value ) ) + +static ivas_error packAcousticEnvironment( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + uint8_t packedSize = 1; + const IVAS_PIDATA_ACOUSTIC_ENV *aeEnv = (const IVAS_PIDATA_ACOUSTIC_ENV *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_ACOUSTIC_ENV ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in PI data of type Acoustic Environment" ); + } + + if ( aeEnv->availEarlyReflections ) + { + packedSize = 8; + } + else if ( aeEnv->availLateReverb ) + { + packedSize = 5; + } + + /* Acoustic Env data is packedSize bytes, header is 2 bytes */ + if ( maxDataBytes < (uint32_t) packedSize + 2 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Insufficient space to pack Orientation PI data" ); + } + + buffer[nBytes++] = ( IVAS_PI_ACOUSTIC_ENVIRONMENT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = packedSize; + + if ( packedSize == 1 ) + { + buffer[nBytes++] = aeEnv->aeid & 0x7F; + } + else + { + uint64_t dWord = (uint64_t) aeEnv->aeid << 57; + + dWord |= (uint64_t) GET_IDX( mapRT60, NBITS_RT60, aeEnv->rt60[IVAS_PI_AE_LOW] ) << 52; + dWord |= (uint64_t) GET_IDX( mapDSR, NBITS_DSR, aeEnv->dsr[IVAS_PI_AE_LOW] ) << 46; + dWord |= (uint64_t) GET_IDX( mapRT60, NBITS_RT60, aeEnv->rt60[IVAS_PI_AE_MID] ) << 41; + dWord |= (uint64_t) GET_IDX( mapDSR, NBITS_DSR, aeEnv->dsr[IVAS_PI_AE_MID] ) << 35; + dWord |= (uint64_t) GET_IDX( mapRT60, NBITS_RT60, aeEnv->rt60[IVAS_PI_AE_HIGH] ) << 30; + dWord |= (uint64_t) GET_IDX( mapDSR, NBITS_DSR, aeEnv->dsr[IVAS_PI_AE_HIGH] ) << 24; + + buffer[nBytes++] = (uint8_t) ( dWord >> 56 ); + buffer[nBytes++] = (uint8_t) ( dWord >> 48 ); + buffer[nBytes++] = (uint8_t) ( dWord >> 40 ); + buffer[nBytes++] = (uint8_t) ( dWord >> 32 ); + buffer[nBytes++] = (uint8_t) ( dWord >> 24 ); + + if ( packedSize > 5 ) + { + dWord |= (uint64_t) GET_IDX( mapRoomDims, NBITS_DIM, aeEnv->roomDimensions.x ) << 20; + dWord |= (uint64_t) GET_IDX( mapRoomDims, NBITS_DIM, aeEnv->roomDimensions.y ) << 16; + dWord |= (uint64_t) GET_IDX( mapRoomDims, NBITS_DIM, aeEnv->roomDimensions.z ) << 12; + dWord |= (uint64_t) GET_IDX( mapAbsorbtion, NBITS_ABS, aeEnv->absorbCoeffs[IVAS_PI_AE_FRONT] ) << 10; + dWord |= (uint64_t) GET_IDX( mapAbsorbtion, NBITS_ABS, aeEnv->absorbCoeffs[IVAS_PI_AE_BACK] ) << 8; + dWord |= (uint64_t) GET_IDX( mapAbsorbtion, NBITS_ABS, aeEnv->absorbCoeffs[IVAS_PI_AE_LEFT] ) << 6; + dWord |= (uint64_t) GET_IDX( mapAbsorbtion, NBITS_ABS, aeEnv->absorbCoeffs[IVAS_PI_AE_RIGHT] ) << 4; + dWord |= (uint64_t) GET_IDX( mapAbsorbtion, NBITS_ABS, aeEnv->absorbCoeffs[IVAS_PI_AE_CEILING] ) << 2; + dWord |= (uint64_t) GET_IDX( mapAbsorbtion, NBITS_ABS, aeEnv->absorbCoeffs[IVAS_PI_AE_FLOOR] ); + + buffer[nBytes++] = (uint8_t) ( dWord >> 16 ); + buffer[nBytes++] = (uint8_t) ( dWord >> 8 ); + buffer[nBytes++] = (uint8_t) ( dWord ); + } + } + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackAcousticEnvironment( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_ACOUSTIC_ENV *aeEnv = (IVAS_PIDATA_ACOUSTIC_ENV *) piData; + + /* Acooustic Env data is either 1, 5 or 8 bytes */ + if ( numDataBytes != 1 && numDataBytes != 5 && numDataBytes != 8 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack PI data of type Acoustic Environment" ); + } + + piData->size = sizeof( IVAS_PIDATA_ACOUSTIC_ENV ); + aeEnv->availLateReverb = ( numDataBytes >= 5 ); + aeEnv->availEarlyReflections = ( numDataBytes == 8 ); + + if ( numDataBytes == 1 ) + { + aeEnv->aeid = buffer[0]; + } + else + { + uint64_t dWord = 0ull; + uint32_t n; + for ( n = 0; n < numDataBytes; n++ ) + { + dWord <<= 8; + dWord |= buffer[n]; + } + dWord <<= ( 8 - numDataBytes ) * 8; + + aeEnv->aeid = (uint8_t) ( ( dWord >> 57 ) & MASK_AEID ); + aeEnv->rt60[IVAS_PI_AE_LOW] = mapRT60[( dWord >> 52 ) & MASK_RT60]; + aeEnv->dsr[IVAS_PI_AE_LOW] = mapDSR[( dWord >> 46 ) & MASK_DSR]; + aeEnv->rt60[IVAS_PI_AE_MID] = mapRT60[( dWord >> 41 ) & MASK_RT60]; + aeEnv->dsr[IVAS_PI_AE_MID] = mapDSR[( dWord >> 35 ) & MASK_DSR]; + aeEnv->rt60[IVAS_PI_AE_HIGH] = mapRT60[( dWord >> 30 ) & MASK_RT60]; + aeEnv->dsr[IVAS_PI_AE_HIGH] = mapDSR[( dWord >> 24 ) & MASK_DSR]; + + aeEnv->roomDimensions.x = mapRoomDims[( dWord >> 20 ) & MASK_DIM]; + aeEnv->roomDimensions.y = mapRoomDims[( dWord >> 16 ) & MASK_DIM]; + aeEnv->roomDimensions.z = mapRoomDims[( dWord >> 12 ) & MASK_DIM]; + + aeEnv->absorbCoeffs[IVAS_PI_AE_FRONT] = mapAbsorbtion[( dWord >> 10 ) & MASK_ABS]; + aeEnv->absorbCoeffs[IVAS_PI_AE_BACK] = mapAbsorbtion[( dWord >> 8 ) & MASK_ABS]; + aeEnv->absorbCoeffs[IVAS_PI_AE_LEFT] = mapAbsorbtion[( dWord >> 6 ) & MASK_ABS]; + aeEnv->absorbCoeffs[IVAS_PI_AE_RIGHT] = mapAbsorbtion[( dWord >> 4 ) & MASK_ABS]; + aeEnv->absorbCoeffs[IVAS_PI_AE_CEILING] = mapAbsorbtion[( dWord >> 2 ) & MASK_ABS]; + aeEnv->absorbCoeffs[IVAS_PI_AE_FLOOR] = mapAbsorbtion[( dWord >> 0 ) & MASK_ABS]; + + aeEnv->rt60_fx[IVAS_PI_AE_LOW] = (Word32) ( aeEnv->rt60[IVAS_PI_AE_LOW] * ONE_IN_Q26 ); /* Q26 */ + aeEnv->rt60_fx[IVAS_PI_AE_MID] = (Word32) ( aeEnv->rt60[IVAS_PI_AE_MID] * ONE_IN_Q26 ); + aeEnv->rt60_fx[IVAS_PI_AE_HIGH] = (Word32) ( aeEnv->rt60[IVAS_PI_AE_HIGH] * ONE_IN_Q26 ); + aeEnv->dsr_fx[IVAS_PI_AE_LOW] = (Word32) ( powf( 10.0f, aeEnv->dsr[IVAS_PI_AE_LOW] / 10.0f ) * ONE_IN_Q30 ); /* Q30 */ + aeEnv->dsr_fx[IVAS_PI_AE_MID] = (Word32) ( powf( 10.0f, aeEnv->dsr[IVAS_PI_AE_MID] / 10.0f ) * ONE_IN_Q30 ); + aeEnv->dsr_fx[IVAS_PI_AE_HIGH] = (Word32) ( powf( 10.0f, aeEnv->dsr[IVAS_PI_AE_HIGH] / 10.0f ) * ONE_IN_Q30 ); + + 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 = 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 ); + aeEnv->absorbCoeffs_fx[IVAS_PI_AE_LEFT] = (Word32) ( aeEnv->absorbCoeffs[IVAS_PI_AE_LEFT] * ONE_IN_Q30 ); + aeEnv->absorbCoeffs_fx[IVAS_PI_AE_RIGHT] = (Word32) ( aeEnv->absorbCoeffs[IVAS_PI_AE_RIGHT] * ONE_IN_Q30 ); + aeEnv->absorbCoeffs_fx[IVAS_PI_AE_CEILING] = (Word32) ( aeEnv->absorbCoeffs[IVAS_PI_AE_CEILING] * ONE_IN_Q30 ); + aeEnv->absorbCoeffs_fx[IVAS_PI_AE_FLOOR] = (Word32) ( aeEnv->absorbCoeffs[IVAS_PI_AE_FLOOR] * ONE_IN_Q30 ); + } + + return IVAS_ERR_OK; +} + +static ivas_error packAudioDescription( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t n; + uint32_t nBytes = 0; + const IVAS_PIDATA_AUDIO_DESC *audioDesc = (const IVAS_PIDATA_AUDIO_DESC *) piData; + uint32_t packedSize = audioDesc->nValidEntries; /* Each Entry is 1 byte */ + + *nBytesWritten = 0; + + if ( audioDesc->nValidEntries > ( IVAS_MAX_NUM_OBJECTS + 1 ) ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNSUPPORTED_FRAME, "Audio Description cannot have more than 5 entries" ); + } + + /* Audio Description data is max 5 bytes, 2 bytes header */ + if ( maxDataBytes < packedSize + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space in Audio Description PI data buffer" ); + } + + buffer[nBytes++] = ( IVAS_PI_AUDIO_DESCRIPTION ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) packedSize; + + for ( n = 0; n < audioDesc->nValidEntries; n++ ) + { + buffer[nBytes++] = ( audioDesc->audioId[n].speech ? PI_AD_SPEECH_INDICATED : 0 ) | + ( audioDesc->audioId[n].music ? PI_AD_MUSIC_INDICATED : 0 ) | + ( audioDesc->audioId[n].ambiance ? PI_AD_AMBIANCE_INDICATED : 0 ) | + ( audioDesc->audioId[n].editable ? PI_AD_EDITABLE_INDICATED : 0 ) | + ( audioDesc->audioId[n].binaural ? PI_AD_BINAURAL_INDICATED : 0 ); + } + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackAudioDescription( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t n; + IVAS_PIDATA_AUDIO_DESC *audioDesc = (IVAS_PIDATA_AUDIO_DESC *) piData; + + /* Audio Description data is max 5 bytes */ + if ( numDataBytes > ( IVAS_MAX_NUM_OBJECTS + 1 ) ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack Orientation PI data" ); + } + + audioDesc->size = sizeof( IVAS_PIDATA_AUDIO_DESC ); + audioDesc->nValidEntries = numDataBytes; + audioDesc->piDataType = IVAS_PI_AUDIO_DESCRIPTION; + + for ( n = 0; n < audioDesc->nValidEntries; n++ ) + { + audioDesc->audioId[n].speech = ( buffer[n] & PI_AD_SPEECH_INDICATED ) != 0; + audioDesc->audioId[n].music = ( buffer[n] & PI_AD_MUSIC_INDICATED ) != 0; + audioDesc->audioId[n].ambiance = ( buffer[n] & PI_AD_AMBIANCE_INDICATED ) != 0; + audioDesc->audioId[n].editable = ( buffer[n] & PI_AD_EDITABLE_INDICATED ) != 0; + audioDesc->audioId[n].binaural = ( buffer[n] & PI_AD_BINAURAL_INDICATED ) != 0; + } + + return IVAS_ERR_OK; +} + +static ivas_error packDynamicSuppression( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_DYNAMIC_SUPPRESSION *das = (const IVAS_PIDATA_DYNAMIC_SUPPRESSION *) piData; + + *nBytesWritten = 0; + + /* Dynamic Audio Suppression data is 2 bytes, 2 bytes header */ + if ( maxDataBytes < 2 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space in DAS PI data buffer" ); + } + + buffer[nBytes++] = ( das->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 2u; + + buffer[nBytes++] = ( das->speech ? PI_AD_SPEECH_INDICATED : 0 ) | + ( das->music ? PI_AD_MUSIC_INDICATED : 0 ) | + ( das->ambiance ? PI_AD_AMBIANCE_INDICATED : 0 ); + buffer[nBytes++] = ( (uint8_t) das->sli & MASK_4BIT ) << 4; + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackDynamicSuppression( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_DYNAMIC_SUPPRESSION *das = (IVAS_PIDATA_DYNAMIC_SUPPRESSION *) piData; + + /* Dynamic Suppression data is 2 bytes */ + if ( numDataBytes != 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack DAS PI data" ); + } + + das->size = sizeof( IVAS_PIDATA_AUDIO_DESC ); + das->speech = ( buffer[0] & PI_AD_SPEECH_INDICATED ) != 0; + das->music = ( buffer[0] & PI_AD_MUSIC_INDICATED ) != 0; + das->ambiance = ( buffer[0] & PI_AD_AMBIANCE_INDICATED ) != 0; + das->sli = ( buffer[1] >> 4 ); + + return IVAS_ERR_OK; +} + +static ivas_error packPosition( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_POSITION *position = (const IVAS_PIDATA_POSITION *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_POSITION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in position PI data" ); + } + + if ( piData->piDataType != IVAS_PI_LISTENER_POSITION && piData->piDataType != IVAS_PI_R_ISM_POSITION ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in position PI data" ); + } + + /* Position data is 6 bytes, header is 2 bytes */ + if ( maxDataBytes < 6 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack position PI data" ); + } + + buffer[nBytes++] = ( position->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 6; + nBytes = writeInt16( buffer, nBytes, ivasPayload_convertToQ15( position->position.x / MAX_PI_POSITION_METERS ) ); + nBytes = writeInt16( buffer, nBytes, ivasPayload_convertToQ15( position->position.y / MAX_PI_POSITION_METERS ) ); + nBytes = writeInt16( buffer, nBytes, ivasPayload_convertToQ15( position->position.z / MAX_PI_POSITION_METERS ) ); + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackPosition( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_POSITION *position = (IVAS_PIDATA_POSITION *) piData; + + /* Position data is 6 bytes */ + if ( numDataBytes != 6 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack position PI data" ); + } + + position->size = sizeof( IVAS_PIDATA_POSITION ); + position->position.x = FLOAT_FROM_Q15( readInt16( &buffer[0] ) ) * MAX_PI_POSITION_METERS; + position->position.y = FLOAT_FROM_Q15( readInt16( &buffer[2] ) ) * MAX_PI_POSITION_METERS; + position->position.z = FLOAT_FROM_Q15( readInt16( &buffer[4] ) ) * MAX_PI_POSITION_METERS; + return IVAS_ERR_OK; +} + +static ivas_error packPositionCompact( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + uint16_t posX, posY, posZ = 0; + const IVAS_PIDATA_POSITION *position = (const IVAS_PIDATA_POSITION *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_POSITION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in compact position PI data" ); + } + + if ( piData->piDataType != IVAS_PI_R_ISM_POSITION ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in compact position PI data" ); + } + + /* Compact position data is 4 bytes, header is 2 bytes */ + if ( maxDataBytes < 4 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack compact position PI data" ); + } + + buffer[nBytes++] = ( position->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 4; + posX = (uint16_t) ivasPayload_convertToQ10( position->position.x / MAX_PI_COMPACT_POSITION_XY_METERS ); + posY = (uint16_t) ivasPayload_convertToQ10( position->position.y / MAX_PI_COMPACT_POSITION_XY_METERS ); + posZ = (uint16_t) ivasPayload_convertToQ9( position->position.z / MAX_PI_COMPACT_POSITION_Z_METERS ); + buffer[nBytes++] = (uint8_t) ( posX >> 8 ); + buffer[nBytes++] = (uint8_t) ( ( ( posX & MASK_3BIT ) << 5 ) | posY >> 6 ); + buffer[nBytes++] = (uint8_t) ( ( ( posY & MASK_6BIT ) << 2 ) | posZ >> 8 ); + buffer[nBytes++] = (uint8_t) ( posZ >> 2 ); + + *nBytesWritten = nBytes; + + return IVAS_ERR_OK; +} + +static ivas_error unpackPositionCompact( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_POSITION *position = (IVAS_PIDATA_POSITION *) piData; + int32_t compactRead = 0; + + /* Compact position data is 4 bytes */ + if ( numDataBytes != 4 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack compact position PI data" ); + } + + position->size = sizeof( IVAS_PIDATA_POSITION ); + + compactRead = ( (int32_t) buffer[0] << 24 ) | ( (int32_t) buffer[1] << 16 ) | ( (int32_t) buffer[2] << 8 ) | ( (int32_t) buffer[3] ); + position->position.x = FLOAT_FROM_Q10( (int16_t) ( compactRead >> 21 ) ) * MAX_PI_COMPACT_POSITION_XY_METERS; /* Shift preserves sign bit */ + compactRead = compactRead << 11; /* Discard read bits */ + position->position.y = FLOAT_FROM_Q10( (int16_t) ( compactRead >> 21 ) ) * MAX_PI_COMPACT_POSITION_XY_METERS; /* Shift preserves sign bit */ + compactRead = compactRead << 11; /* Discard read bits */ + position->position.z = FLOAT_FROM_Q9( (int16_t) ( compactRead >> 22 ) ) * MAX_PI_COMPACT_POSITION_Z_METERS; /* Shift preserves sign bit */ + + return IVAS_ERR_OK; +} + +static ivas_error packISMPosition( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n; + const IVAS_PIDATA_ISM_POSITION *ism_position = (const IVAS_PIDATA_ISM_POSITION *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_ISM_POSITION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM POSITION PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_POSITION ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM POSITION PI data" ); + } + + /* Position data is 6 bytes, header is 2 bytes */ + if ( maxDataBytes < 6 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM POSITION PI data" ); + } + + buffer[nBytes++] = ( ism_position->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) ism_position->numObjects * 6; + for ( n = 0; n < ism_position->numObjects; n++ ) + { + nBytes = writeInt16( buffer, nBytes, ivasPayload_convertToQ15( ism_position->position[n].x / MAX_PI_POSITION_METERS ) ); + nBytes = writeInt16( buffer, nBytes, ivasPayload_convertToQ15( ism_position->position[n].y / MAX_PI_POSITION_METERS ) ); + nBytes = writeInt16( buffer, nBytes, ivasPayload_convertToQ15( ism_position->position[n].z / MAX_PI_POSITION_METERS ) ); + } + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMPosition( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint16_t n; + IVAS_PIDATA_ISM_POSITION *ism_position = (IVAS_PIDATA_ISM_POSITION *) piData; + + /* Position data is 6 bytes */ + if ( numDataBytes % 6 != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack LISTENER POSITION PI data" ); + } + + ism_position->size = sizeof( IVAS_PIDATA_ISM_POSITION ); + ism_position->piDataType = IVAS_PI_ISM_POSITION; + ism_position->numObjects = (uint16_t) numDataBytes / 6; + + for ( n = 0; n < ism_position->numObjects; n++ ) + { + ism_position->position[n].x = FLOAT_FROM_Q15( readInt16( &buffer[6 * n] ) ) * MAX_PI_POSITION_METERS; + ism_position->position[n].y = FLOAT_FROM_Q15( readInt16( &buffer[6 * n + 2] ) ) * MAX_PI_POSITION_METERS; + ism_position->position[n].z = FLOAT_FROM_Q15( readInt16( &buffer[6 * n + 4] ) ) * MAX_PI_POSITION_METERS; + } + return IVAS_ERR_OK; +} + +static ivas_error packISMPositionCompact( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n; + uint16_t posX, posY, posZ = 0; + const IVAS_PIDATA_ISM_POSITION *ism_position = (const IVAS_PIDATA_ISM_POSITION *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_ISM_POSITION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM POSITION COMPACT PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_POSITION_COMPACT ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM POSITION COMPACT PI data" ); + } + + /* Compact position data is 4 bytes, header is 2 bytes */ + if ( maxDataBytes < 4 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM POSITION COMPACT PI data" ); + } + + buffer[nBytes++] = ( ism_position->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) ism_position->numObjects * 4; + for ( n = 0; n < ism_position->numObjects; n++ ) + { + posX = (uint16_t) ivasPayload_convertToQ10( ism_position->position[n].x / MAX_PI_COMPACT_POSITION_XY_METERS ); + posY = (uint16_t) ivasPayload_convertToQ10( ism_position->position[n].y / MAX_PI_COMPACT_POSITION_XY_METERS ); + posZ = (uint16_t) ivasPayload_convertToQ9( ism_position->position[n].z / MAX_PI_COMPACT_POSITION_Z_METERS ); + buffer[nBytes++] = (uint8_t) ( posX >> 8 ); + buffer[nBytes++] = (uint8_t) ( ( ( posX & MASK_3BIT ) << 5 ) | posY >> 6 ); + buffer[nBytes++] = (uint8_t) ( ( ( posY & MASK_6BIT ) << 2 ) | posZ >> 8 ); + buffer[nBytes++] = (uint8_t) ( posZ >> 2 ); + } + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMPositionCompact( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint16_t n; + int32_t compactRead = 0; + IVAS_PIDATA_ISM_POSITION *ism_position = (IVAS_PIDATA_ISM_POSITION *) piData; + + /* Compact position data is 4 bytes */ + if ( numDataBytes % 4 != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack ISM POSITION COMPACT PI data" ); + } + + ism_position->size = sizeof( IVAS_PIDATA_ISM_POSITION ); + ism_position->piDataType = IVAS_PI_ISM_POSITION_COMPACT; + ism_position->numObjects = (uint16_t) numDataBytes / 4; + + for ( n = 0; n < ism_position->numObjects; n++ ) + { + compactRead = ( (int32_t) buffer[n * 4] << 24 ) | ( (int32_t) buffer[n * 4 + 1] << 16 ) | ( (int32_t) buffer[n * 4 + 2] << 8 ) | ( (int32_t) buffer[n * 4 + 3] ); + ism_position->position[n].x = FLOAT_FROM_Q10( (int16_t) ( compactRead >> 21 ) ) * MAX_PI_COMPACT_POSITION_XY_METERS; /* Shift preserves sign bit */ + compactRead = compactRead << 11; /* Discard read bits */ + ism_position->position[n].y = FLOAT_FROM_Q10( (int16_t) ( compactRead >> 21 ) ) * MAX_PI_COMPACT_POSITION_XY_METERS; /* Shift preserves sign bit */ + compactRead = compactRead << 11; /* Discard read bits */ + ism_position->position[n].z = FLOAT_FROM_Q9( (int16_t) ( compactRead >> 22 ) ) * MAX_PI_COMPACT_POSITION_Z_METERS; /* Shift preserves sign bit */ + } + return IVAS_ERR_OK; +} + +static ivas_error packDiegetic( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n; + uint8_t byte = 0; + const IVAS_PIDATA_DIEGETIC *diegetic = (const IVAS_PIDATA_DIEGETIC *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_DIEGETIC ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in Diegetic Type PI data" ); + } + + if ( piData->piDataType != IVAS_PI_DIEGETIC_TYPE ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in Diegetic Type PI data" ); + } + + /* Diegetic data is 1 bytes, header is 2 bytes */ + if ( maxDataBytes < 1 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack Diegetic Type PI data" ); + } + + /* Valid bits must be based on active bits defined for the input format */ + for ( n = 0; n < ( IVAS_MAX_NUM_OBJECTS + 1 ); n++ ) + { + byte <<= 1; + byte |= ( diegetic->isDiegetic[n] ); + } + byte <<= 3; + + buffer[nBytes++] = ( diegetic->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 1; + buffer[nBytes++] = byte; + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackDiegetic( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t n; + IVAS_PIDATA_DIEGETIC *diegetic = (IVAS_PIDATA_DIEGETIC *) piData; + uint8_t byte; + + /* Diegetic data is 1 bytes */ + if ( numDataBytes != 1 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack Diegetic PI data" ); + } + + diegetic->size = sizeof( IVAS_PIDATA_DIEGETIC ); + diegetic->piDataType = IVAS_PI_DIEGETIC_TYPE; + + byte = buffer[0]; + /* Valid bits must be based on active bits defined for the input format */ + for ( n = 0; n < ( IVAS_MAX_NUM_OBJECTS + 1 ); n++ ) + { + diegetic->isDiegetic[n] = ( ( byte >> ( 7 - n ) ) & 1 ) != 0; + } + + return IVAS_ERR_OK; +} + +static ivas_error packAudioFocusCommon( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + uint8_t packedSize = 1; + const IVAS_PIDATA_AUDIO_FOCUS *audioFocus = (const IVAS_PIDATA_AUDIO_FOCUS *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_AUDIO_FOCUS ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in PI data of type Audio Focus" ); + } + + if ( audioFocus->availDirection && audioFocus->availLevel ) + { + packedSize = 5; + } + else if ( audioFocus->availDirection ) + { + packedSize = 4; + } + else if ( audioFocus->availLevel ) + { + packedSize = 1; + } + else + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Neither direction or level is available for packing Audio Focus" ); + } + + /* Audio Focus data is packedSize bytes, header is 2 bytes */ + if ( maxDataBytes < (uint32_t) packedSize + 2 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Insufficient space to pack Audio Focus PI data" ); + } + + buffer[nBytes++] = ( audioFocus->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = packedSize; + if ( packedSize == 5 || packedSize == 4 ) + { + nBytes += packQuaternion( audioFocus->direction, &buffer[nBytes] ); + } + if ( packedSize == 5 || packedSize == 1 ) + { + buffer[nBytes++] = ( (uint8_t) audioFocus->flvl & MASK_4BIT ) << 4; + } + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackAudioFocusCommon( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_AUDIO_FOCUS *audioFocus = (IVAS_PIDATA_AUDIO_FOCUS *) piData; + + /* Audio Focus data is either 1, 4 or 5 bytes */ + if ( numDataBytes != 1 && numDataBytes != 4 && numDataBytes != 5 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack PI data of type Audio Focus" ); + } + + piData->size = sizeof( IVAS_PIDATA_AUDIO_FOCUS ); + audioFocus->availDirection = ( numDataBytes >= 4 ); + audioFocus->availLevel = ( numDataBytes == 1 || numDataBytes == 5 ); + + if ( numDataBytes == 1 ) + { + audioFocus->flvl = ( buffer[0] >> 4 ); + } + else + { + unpackQuaternion( buffer, &( audioFocus->direction ) ); + + if ( numDataBytes == 5 ) + { + audioFocus->flvl = ( buffer[4] >> 4 ); + } + } + + return IVAS_ERR_OK; +} + +static ivas_error packISMNum( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_ISM_NUM *ism_num = (const IVAS_PIDATA_ISM_NUM *) piData; + + *nBytesWritten = 0; + + if ( piData->size != sizeof( IVAS_PIDATA_ISM_NUM ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM_NUM PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_NUM ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM_NUM PI data" ); + } + + /* ISM_NUM data is 1 bytes, header is 2 bytes */ + if ( maxDataBytes < 1 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM_NUM PI data" ); + } + + buffer[nBytes++] = ( ism_num->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = 1; + buffer[nBytes++] = ( ( ism_num->numObjects - 1 ) & MASK_2BIT ) << 6; + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMNum( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_ISM_NUM *ism_num = (IVAS_PIDATA_ISM_NUM *) piData; + uint8_t byte; + + /* ISM_NUM data is 1 bytes */ + if ( numDataBytes != 1 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack ISM_NUM PI data" ); + } + + ism_num->size = sizeof( IVAS_PIDATA_ISM_NUM ); + ism_num->piDataType = IVAS_PI_ISM_NUM; + + byte = buffer[0]; + ism_num->numObjects = ( ( byte >> 6 ) & MASK_2BIT ) + 1; + + return IVAS_ERR_OK; +} + +static ivas_error packISMID( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n; + const IVAS_PIDATA_ISM_ID *ism_id = (const IVAS_PIDATA_ISM_ID *) piData; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_ID ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM_ID PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_ID ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM_ID PI data" ); + } + + /* ISM_ID data is 1 byte per object, header is 2 bytes */ + if ( maxDataBytes < 1 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM_NUM PI data" ); + } + + buffer[nBytes++] = ( ism_id->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) ism_id->numObjects; + /* Pack ID for each object */ + for ( n = 0; n < ism_id->numObjects; n++ ) + { + buffer[nBytes++] = ( ism_id->id[n] & MASK_8BIT ); + } + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMID( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t n; + IVAS_PIDATA_ISM_ID *ism_id = (IVAS_PIDATA_ISM_ID *) piData; + + /* ISM_ID data is 1 byte per object */ + if ( numDataBytes > IVAS_MAX_NUM_OBJECTS ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack ISM_ID PI data" ); + } + + ism_id->size = sizeof( IVAS_PIDATA_ISM_ID ); + ism_id->piDataType = IVAS_PI_ISM_ID; + ism_id->numObjects = (uint16_t) numDataBytes; + + /* Unpack ID for each object (1 byte each) */ + for ( n = 0; n < ism_id->numObjects; n++ ) + { + ism_id->id[n] = buffer[n]; + } + for ( ; n < IVAS_MAX_NUM_OBJECTS; n++ ) + { + ism_id->id[n] = 0; /* Initializing to 0, although there might be another object with this ID */ + } + + return IVAS_ERR_OK; +} + +static ivas_error packISMGain( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n, idx; + int16_t gain; + const IVAS_PIDATA_ISM_GAIN *ism_gain = (const IVAS_PIDATA_ISM_GAIN *) piData; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_GAIN ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM_GAIN PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_GAIN ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM_GAIN PI data" ); + } + + /* ISM_GAIN data is 1 byte per object, header is 2 bytes */ + if ( maxDataBytes < 1 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM_GAIN PI data" ); + } + + buffer[nBytes++] = ( ism_gain->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) ism_gain->numObjects; + /* Pack ID for each object */ + for ( n = 0; n < ism_gain->numObjects; n++ ) + { + gain = (int16_t) ism_gain->dB[n]; + idx = min( -gain, 25 ); + if ( gain > 0 ) + { + idx += 25; + } + + buffer[nBytes++] = ( idx & MASK_6BIT ) << 2; + } + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMGain( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t n, idx; + IVAS_PIDATA_ISM_GAIN *ism_gain = (IVAS_PIDATA_ISM_GAIN *) piData; + + /* ISM_GAIN data is 1 byte per object */ + if ( numDataBytes > IVAS_MAX_NUM_OBJECTS ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack ISM_GAIN PI data" ); + } + + ism_gain->size = sizeof( IVAS_PIDATA_ISM_GAIN ); + ism_gain->piDataType = IVAS_PI_ISM_GAIN; + ism_gain->numObjects = (uint16_t) numDataBytes; + + /* Unpack ID for each object (1 byte each) */ + for ( n = 0; n < ism_gain->numObjects; n++ ) + { + idx = ( buffer[n] ) >> 2; + /* negative gains*/ + if ( idx < 25 ) + { + ism_gain->dB[n] = -(int8_t) ( idx ); + } + /* Set to min for muting, to be interpreted as -Inf */ + else if ( idx == 25 ) + { + ism_gain->dB[n] = -128; + } + /* postive gains */ + else if ( idx < 38 ) + { + ism_gain->dB[n] = (int8_t) idx - 25; + } + else + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect index for ISM_GAIN PI data" ); + } + } + for ( ; n < IVAS_MAX_NUM_OBJECTS; n++ ) + { + ism_gain->dB[n] = 0; /* Set to default */ + } + return IVAS_ERR_OK; +} + +static ivas_error packISMDistanceAttenuation( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n; + const IVAS_PIDATA_ISM_ATTENUATION *ism_att = (const IVAS_PIDATA_ISM_ATTENUATION *) piData; + uint32_t lWord; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_ATTENUATION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM_DISTANCE_ATTENUATION PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_DISTANCE_ATTENUATION ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM_DISTANCE_ATTENUATION PI data" ); + } + + /* ISM_DISTANCE_ATTENUATION data is 3 bytes per object, header is 2 bytes */ + if ( maxDataBytes > 3 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM_DISTANCE_ATTENUATION PI data" ); + } + + buffer[nBytes++] = ( ism_att->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) ism_att->numObjects * 3; + /* Pack ID for each object */ + for ( n = 0; n < ism_att->numObjects; n++ ) + { + if ( ism_att->distAtten[n].ref_dist < 0 || ism_att->distAtten[n].max_dist < 0 || ism_att->distAtten[n].roll < 0 ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect DISTANCE ATTENUATION data" ); + } + lWord = (uint32_t) ( min( (uint16_t) ( ism_att->distAtten[n].ref_dist * 10.0f + 0.5f ) - 1, 63 ) << 18 ); + lWord |= (uint32_t) ( min( (uint16_t) ( ism_att->distAtten[n].max_dist + 0.5f ) - 1, 63 ) << 12 ); + lWord |= (uint32_t) ( min( (uint16_t) ( ism_att->distAtten[n].roll * 10.0f + 0.5f ), 40 ) << 6 ); + + buffer[nBytes++] = ( lWord >> 16 ) & MASK_8BIT; + buffer[nBytes++] = ( lWord >> 8 ) & MASK_8BIT; + buffer[nBytes++] = lWord & MASK_8BIT; + } + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMDistanceAttenuation( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t n, lWord; + IVAS_PIDATA_ISM_ATTENUATION *ism_att = (IVAS_PIDATA_ISM_ATTENUATION *) piData; + + /* ISM_DISTANCE_ATTENUATION data is 3 bytes per object */ + if ( numDataBytes % 3 != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack ISM_DISTANCE_ATTENUATION PI data" ); + } + + ism_att->size = sizeof( IVAS_PIDATA_ISM_ATTENUATION ); + ism_att->piDataType = IVAS_PI_ISM_DISTANCE_ATTENUATION; + ism_att->numObjects = (uint16_t) numDataBytes / 3; + + /* Unpack attenuation for each object (3 bytes each) */ + for ( n = 0; n < ism_att->numObjects; n++ ) + { + lWord = ( buffer[3 * n] ) << 16; + lWord |= ( buffer[3 * n + 1] ) << 8; + lWord |= buffer[3 * n + 2]; + + ism_att->distAtten[n].ref_dist = ( ( ( lWord >> 18 ) & MASK_6BIT ) + 1 ) / 10.0f; + ism_att->distAtten[n].max_dist = (float) ( ( lWord >> 12 ) & MASK_6BIT ) + 1; + ism_att->distAtten[n].roll = ( ( lWord >> 6 ) & MASK_6BIT ) / 10.0f; + } + for ( ; n < IVAS_MAX_NUM_OBJECTS; n++ ) + { + ism_att->distAtten[n].ref_dist = 1.0f; /* Set to default */ + ism_att->distAtten[n].max_dist = 16.0f; /* Set to default */ + ism_att->distAtten[n].roll = 1.0f; /* Set to default */ + } + return IVAS_ERR_OK; +} + +static ivas_error packISMDirectivity( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, n; + const IVAS_PIDATA_ISM_DIRECTIVITY *ism_directivity = (const IVAS_PIDATA_ISM_DIRECTIVITY *) piData; + uint16_t word, idx; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_DIRECTIVITY ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in ISM_DIRECTIVITY PI data" ); + } + + if ( piData->piDataType != IVAS_PI_ISM_DIRECTIVITY ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM_DIRECTIVITY PI data" ); + } + + /* ISM_DIRECTIVITY data is 2 bytes per object, header is 2 bytes */ + if ( maxDataBytes > 2 * IVAS_MAX_NUM_OBJECTS + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack ISM_DIRECTIVITY PI data" ); + } + + buffer[nBytes++] = ( ism_directivity->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = (uint8_t) ism_directivity->numObjects * 2; + /* Pack directivity for each object */ + for ( n = 0; n < ism_directivity->numObjects; n++ ) + { + word = (uint16_t) ( min( ism_directivity->directivity[n].innerConeAngle / 15, 24 ) << 11 ); + word |= (uint16_t) ( min( ism_directivity->directivity[n].outerConeAngle / 15, 24 ) << 6 ); + + idx = 0; + /* For outer attenuation < -90 dB, idx = 0, which corresponds to -Inf (muting) */ + if ( ism_directivity->directivity[n].outerAttenuationdB >= -90.0f ) + { + idx = 32 - (uint16_t) ( -ism_directivity->directivity[n].outerAttenuationdB / 3.0f + 0.5f ); + } + word |= (uint16_t) ( min( idx, 31 ) << 1 ); + + buffer[nBytes++] = ( word >> 8 ) & MASK_8BIT; + buffer[nBytes++] = word & MASK_8BIT; + } + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackISMDirectivity( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t n; + uint16_t word, idx; + IVAS_PIDATA_ISM_DIRECTIVITY *ism_directivity = (IVAS_PIDATA_ISM_DIRECTIVITY *) piData; + + /* ISM_DIRECTIVITY data is 2 bytes per object */ + if ( numDataBytes % 2 != 0 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack ISM_DIRECTIVITY PI data" ); + } + + ism_directivity->size = sizeof( IVAS_PIDATA_ISM_DIRECTIVITY ); + ism_directivity->piDataType = IVAS_PI_ISM_DIRECTIVITY; + ism_directivity->numObjects = (uint16_t) numDataBytes / 2; + + /* Unpack directivity for each object (2 bytes each) */ + for ( n = 0; n < ism_directivity->numObjects; n++ ) + { + word = ( buffer[2 * n] ) << 8; + word |= ( buffer[2 * n + 1] ); + + ism_directivity->directivity[n].innerConeAngle = ( ( word >> 11 ) & MASK_5BIT ) * 15; + ism_directivity->directivity[n].outerConeAngle = ( ( word >> 6 ) & MASK_5BIT ) * 15; + idx = ( word >> 1 ) & MASK_5BIT; + + if ( idx == 0 ) + { + ism_directivity->directivity[n].outerAttenuationdB = -128.0f; /* corresponds to muting */ + } + else + { + ism_directivity->directivity[n].outerAttenuationdB = -3.0f * ( 31 - ( ( word >> 1 ) & MASK_5BIT ) ); + } + } + for ( ; n < IVAS_MAX_NUM_OBJECTS; n++ ) + { + ism_directivity->directivity[n].innerConeAngle = 360; /* Set to default */ + ism_directivity->directivity[n].outerConeAngle = 360; /* Set to default */ + ism_directivity->directivity[n].outerAttenuationdB = 0; /* Set to default */ + } + return IVAS_ERR_OK; +} + +static ivas_error packReverseISMID( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_ISM_EDIT_ID *r_ism_id = (const IVAS_PIDATA_ISM_EDIT_ID *) piData; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_EDIT_ID ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in R_ISM_ID PI data" ); + } + + if ( piData->piDataType != IVAS_PI_R_ISM_ID ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in R_ISM_ID PI data" ); + } + + /* R_ISM_ID data is 1 byte, header is 2 bytes */ + if ( maxDataBytes < 1 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack R_ISM_NUM PI data" ); + } + + buffer[nBytes++] = ( r_ism_id->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + buffer[nBytes++] = ( r_ism_id->id & MASK_8BIT ); + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackReverseISMID( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + IVAS_PIDATA_ISM_EDIT_ID *r_ism_id = (IVAS_PIDATA_ISM_EDIT_ID *) piData; + + /* ISM_ID data is 1 byte*/ + if ( numDataBytes > 1 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack R_ISM_ID PI data" ); + } + + r_ism_id->size = sizeof( IVAS_PIDATA_ISM_EDIT_ID ); + r_ism_id->piDataType = IVAS_PI_R_ISM_ID; + r_ism_id->id = *buffer; + + return IVAS_ERR_OK; +} + +static ivas_error packReverseISMGain( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0, idx; + int16_t gain; + const IVAS_PIDATA_ISM_EDIT_GAIN *r_ism_gain = (const IVAS_PIDATA_ISM_EDIT_GAIN *) piData; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_EDIT_GAIN ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in R_ISM_GAIN PI data" ); + } + + if ( piData->piDataType != IVAS_PI_R_ISM_GAIN ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in R_ISM_GAIN PI data" ); + } + + /* R_ISM_GAIN data is 1 byte, header is 2 bytes */ + if ( maxDataBytes < 1 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack R_ISM_GAIN PI data" ); + } + + buffer[nBytes++] = ( r_ism_gain->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + gain = (int16_t) r_ism_gain->dB; + idx = min( -gain, 25 ); + if ( gain > 0 ) + { + idx += 25; + } + + buffer[nBytes++] = ( idx & MASK_6BIT ) << 2; + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackReverseISMGain( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t idx; + IVAS_PIDATA_ISM_EDIT_GAIN *r_ism_gain = (IVAS_PIDATA_ISM_EDIT_GAIN *) piData; + + /* R_ISM_GAIN data is 1 byte */ + if ( numDataBytes > 1 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack R_ISM_GAIN PI data" ); + } + + r_ism_gain->size = sizeof( IVAS_PIDATA_ISM_EDIT_GAIN ); + r_ism_gain->piDataType = IVAS_PI_R_ISM_GAIN; + + /* Unpack gain */ + idx = ( *buffer ) >> 2; + /* negative gains*/ + if ( idx < 25 ) + { + r_ism_gain->dB = -(int8_t) ( idx ); + } + /* Set to min for muting, to be interpreted as -Inf */ + else if ( idx == 25 ) + { + r_ism_gain->dB = -128; + } + /* postive gains */ + else if ( idx < 38 ) + { + r_ism_gain->dB = (int8_t) idx - 25; + } + else + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect index for R_ISM_GAIN PI data" ); + } + + return IVAS_ERR_OK; +} + +static ivas_error packReverseISMDirection( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t nBytes = 0; + const IVAS_PIDATA_ISM_EDIT_DIRECTION *r_ism_direction = (const IVAS_PIDATA_ISM_EDIT_DIRECTION *) piData; + uint16_t word; + + *nBytesWritten = 0; + + if ( piData->size > sizeof( IVAS_PIDATA_ISM_EDIT_DIRECTION ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size in R_ISM_DIRECTION PI data" ); + } + + if ( piData->piDataType != IVAS_PI_R_ISM_DIRECTION ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID in ISM_DIRECTION PI data" ); + } + + /* R_ISM_DIRECTION data is 2 bytes, header is 2 bytes */ + if ( maxDataBytes > 2 + 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack R_ISM_DIRECTION PI data" ); + } + + buffer[nBytes++] = ( r_ism_direction->piDataType & MASK_5BIT ); /* PF/PM populated during final packing */ + + word = (uint16_t) ( min( (uint16_t) ceilf( r_ism_direction->azimuth * REVERSE_ISM_DIRECTION_AZIMUTH_STEP_INV ) + 256, 511 ) << 7 ); + word |= (uint16_t) ( min( (uint16_t) ceilf( r_ism_direction->elevation * REVERSE_ISM_DIRECTION_ELEVATION_STEP_INV ) + 64, 127 ) << 6 ); + + buffer[nBytes++] = ( word >> 8 ) & MASK_8BIT; + buffer[nBytes++] = word & MASK_8BIT; + + *nBytesWritten = nBytes; + return IVAS_ERR_OK; +} + +static ivas_error unpackReverseISMDirection( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint16_t word; + IVAS_PIDATA_ISM_EDIT_DIRECTION *r_ism_direction = (IVAS_PIDATA_ISM_EDIT_DIRECTION *) piData; + + /* R_ISM_DIRECTION data is 2 bytes */ + if ( numDataBytes > 2 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack R_ISM_DIRECTION PI data" ); + } + + r_ism_direction->size = sizeof( IVAS_PIDATA_ISM_EDIT_DIRECTION ); + r_ism_direction->piDataType = IVAS_PI_R_ISM_DIRECTION; + + word = ( buffer[0] ) << 8; + word |= ( buffer[1] ); + + r_ism_direction->azimuth = (float) ( ( ( word >> 7 ) & MASK_9BIT ) + 1 ) * REVERSE_ISM_DIRECTION_AZIMUTH_STEP - 180.0f; + r_ism_direction->elevation = (float) ( word & MASK_7BIT ) * REVERSE_ISM_DIRECTION_ELEVATION_STEP - 90.0f; + + return IVAS_ERR_OK; +} + +static ivas_error packPiLatency( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten ) +{ + uint32_t typeBits; + uint32_t latencyBits; + uint32_t word; + uint32_t nBytes = 0; + const IVAS_PIDATA_REVERSE_PI_LATENCY *p = (const IVAS_PIDATA_REVERSE_PI_LATENCY *) piData; + + *nBytesWritten = 0; + if ( piData->size != sizeof( IVAS_PIDATA_REVERSE_PI_LATENCY ) ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size for PI_LATENCY data" ); + } + if ( piData->piDataType != IVAS_PI_PI_LATENCY ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID for PI_LATENCY data" ); + } + if ( maxDataBytes < 2 + 4 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack PI_LATENCY data" ); + } + + buffer[nBytes++] = ( p->piDataType & MASK_5BIT ); + buffer[nBytes++] = 4; + + typeBits = (uint32_t) ( p->type & MASK_5BIT ); + latencyBits = (uint32_t) ( p->latency & 0x07FFFFFF ); + word = ( typeBits << 27 ) | latencyBits; + + buffer[nBytes++] = (uint8_t) ( word >> 24 ); + buffer[nBytes++] = (uint8_t) ( word >> 16 ); + buffer[nBytes++] = (uint8_t) ( word >> 8 ); + buffer[nBytes++] = (uint8_t) ( word ); + *nBytesWritten = nBytes; + + return IVAS_ERR_OK; +} + +static ivas_error unpackPiLatency( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData ) +{ + uint32_t word; + uint32_t lat; + IVAS_PIDATA_REVERSE_PI_LATENCY *p = (IVAS_PIDATA_REVERSE_PI_LATENCY *) piData; + + if ( numDataBytes != 4 ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack PI_LATENCY data" ); + } + + p->size = sizeof( IVAS_PIDATA_REVERSE_PI_LATENCY ); + p->piDataType = IVAS_PI_PI_LATENCY; + + word = ( (uint32_t) buffer[0] << 24 ) | ( (uint32_t) buffer[1] << 16 ) | + ( (uint32_t) buffer[2] << 8 ) | (uint32_t) buffer[3]; + p->type = (IVAS_PI_TYPE) ( ( word >> 27 ) & MASK_5BIT ); + lat = word & 0x07FFFFFF; + + /* Sign-extend 27-bit value */ + if ( lat & ( 1u << 26 ) ) + p->latency = (int32_t) ( lat | ~0x07FFFFFF ); + else + p->latency = (int32_t) lat; + + return IVAS_ERR_OK; +} + + +static const PACK_PI_FN packPiDataFuntions[IVAS_PI_MAX_ID] = { + packOrientation, /* SCENE_ORIENTATION */ + packOrientation, /* DEVICE_ORIENTATION_COMPENSATED */ + packOrientation, /* DEVICE_ORIENTATION_UNCOMPENSATED */ + packAcousticEnvironment, /* ACOUSTIC_ENVIRONMENT */ + packAudioDescription, /* AUDIO_DESCRIPTION */ + packISMNum, /* ISM_NUM */ + packISMID, /* ISM_ID */ + packISMGain, /* ISM_GAIN */ + packISMOrientation, /* ISM_ORIENTATION */ + packISMPosition, /* ISM_POSITION */ + packISMPositionCompact, /* ISM_POSITION_COMPACT */ + packISMDistanceAttenuation, /* ISM_DISTANCE_ATTENUATION */ + packISMDirectivity, /* ISM_DIRECTIVITY */ + packDiegetic, /* DIEGETIC_TYPE */ + packDynamicSuppression, /* DYNAMIC_AUDIO_SUPPRESSION_INDICATION */ + packAudioFocusCommon, /* AUDIO_FOCUS_INDICATION */ + packOrientation, /* PLAYBACK_DEVICE_ORIENTATION */ + packOrientation, /* HEAD_ORIENTATION */ + packPosition, /* LISTENER_POSITION */ + packDynamicSuppression, /* DYNAMIC_AUDIO_SUPPRESSION_REQUEST */ + packAudioFocusCommon, /* AUDIO_FOCUS_REQUEST */ + packPiLatency, /* PI_LATENCY */ + packReverseISMID, /* R_ISM_ID */ + packReverseISMGain, /* R_ISM_GAIN */ + packOrientation, /* R_ISM_ORIENTATION */ + packPosition, /* R_ISM_POSITION */ + packPositionCompact, /* R_ISM_POSITION_COMPACT */ + packReverseISMDirection, /* R_ISM_DIRECTION */ + packUnsupportedData, /* RESERVED27 */ + packUnsupportedData, /* RESERVED28 */ + packUnsupportedData, /* RESERVED29 */ + packNoPiData /* NO_DATA */ +}; + +static const UNPACK_PI_FN unpackPiDataFuntions[IVAS_PI_MAX_ID] = { + unpackOrientation, /* SCENE_ORIENTATION */ + unpackOrientation, /* DEVICE_ORIENTATION_COMPENSATED */ + unpackOrientation, /* DEVICE_ORIENTATION_UNCOMPENSATED */ + unpackAcousticEnvironment, /* ACOUSTIC_ENVIRONMENT */ + unpackAudioDescription, /* AUDIO_DESCRIPTION */ + unpackISMNum, /* ISM_NUM */ + unpackISMID, /* ISM_ID */ + unpackISMGain, /* ISM_GAIN */ + unpackISMOrientation, /* ISM_ORIENTATION */ + unpackISMPosition, /* ISM_POSITION */ + unpackISMPositionCompact, /* ISM_POSITION_COMPACT */ + unpackISMDistanceAttenuation, /* ISM_DISTANCE_ATTENUATION */ + unpackISMDirectivity, /* ISM_DIRECTIVITY */ + unpackDiegetic, /* DIEGETIC_TYPE */ + unpackDynamicSuppression, /* DYNAMIC_AUDIO_SUPPRESSION_INDICATION */ + unpackAudioFocusCommon, /* AUDIO_FOCUS_INDICATION */ + unpackOrientation, /* PLAYBACK_DEVICE_ORIENTATION */ + unpackOrientation, /* HEAD_ORIENTATION */ + unpackPosition, /* LISTENER_POSITION */ + unpackDynamicSuppression, /* DYNAMIC_AUDIO_SUPPRESSION_REQUEST */ + unpackAudioFocusCommon, /* AUDIO_FOCUS_REQUEST */ + unpackPiLatency, /* PI_LATENCY */ + unpackReverseISMID, /* R_ISM_ID */ + unpackReverseISMGain, /* R_ISM_GAIN */ + unpackOrientation, /* R_ISM_ORIENTATION */ + unpackPosition, /* R_ISM_POSITION */ + unpackPositionCompact, /* R_ISM_POSITION_COMPACT */ + unpackReverseISMDirection, /* R_ISM_DIRECTION */ + unpackUnsupportedData, /* RESERVED27 */ + unpackUnsupportedData, /* RESERVED28 */ + unpackUnsupportedData, /* RESERVED29 */ + unpackNoPiData /* NO_DATA */ +}; + +static const uint32_t maxPiDataSize[IVAS_PI_MAX_ID] = { + 4, /* IVAS_PI_SCENE_ORIENTATION */ + 4, /* IVAS_PI_DEVICE_ORIENTATION_COMPENSATED */ + 4, /* IVAS_PI_DEVICE_ORIENTATION_UNCOMPENSATED */ + 8, /* IVAS_PI_ACOUSTIC_ENVIRONMENT */ + 5, /* IVAS_PI_AUDIO_DESCRIPTION */ + 1, /* IVAS_PI_ISM_NUM */ + 4, /* IVAS_PI_ISM_ID */ + 4, /* IVAS_PI_ISM_GAIN */ + 16, /* IVAS_PI_ISM_ORIENTATION */ + 24, /* IVAS_PI_ISM_POSITION */ + 16, /* IVAS_PI_ISM_POSITION_COMPACT */ + 12, /* IVAS_PI_ISM_DISTANCE_ATTENUATION */ + 8, /* IVAS_PI_ISM_DIRECTIVITY */ + 1, /* IVAS_PI_DIEGETIC_TYPE */ + 2, /* IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION_INDICATION */ + 5, /* IVAS_PI_AUDIO_FOCUS_INDICATION */ + 4, /* IVAS_PI_PLAYBACK_DEVICE_ORIENTATION */ + 4, /* IVAS_PI_HEAD_ORIENTATION */ + 6, /* IVAS_PI_LISTENER_POSITION */ + 2, /* IVAS_PI_DYNAMIC_AUDIO_SUPPRESSION */ + 5, /* IVAS_PI_AUDIO_FOCUS_REQUEST */ + 4, /* IVAS_PI_PI_LATENCY */ + 1, /* IVAS_PI_R_ISM_ID */ + 1, /* IVAS_PI_R_ISM_GAIN */ + 4, /* IVAS_PI_R_ISM_ORIENTATION */ + 6, /* IVAS_PI_R_ISM_POSITION */ + 4, /* IVAS_PI_R_ISM_POSITION_COMPACT */ + 2, /* IVAS_PI_R_ISM_DIRECTION */ + 0, /* IVAS_PI_RESERVED27 */ + 0, /* IVAS_PI_RESERVED28 */ + 0, /* IVAS_PI_RESERVED29 */ + 0, /* NO_DATA */ +}; + +ivas_error PI_PackData( const IVAS_PIDATA_GENERIC *piData, PIDATA_PACKED *packed, uint8_t pmBits ) +{ + uint32_t type = (IVAS_PI_TYPE) ( piData->piDataType & MASK_5BIT ); + ivas_error error = packPiDataFuntions[type]( piData, packed->data, sizeof( packed->data ), &packed->size ); + if ( error == IVAS_ERR_OK ) + { + packed->data[0] |= pmBits; /* Update the PM bits */ + } + assert( packed->size != 0 ); + return error; +} + +ivas_error PI_UnPackData( uint8_t piDataType, uint32_t piSize, const uint8_t *piDataBuffer, IVAS_PIDATA_GENERIC *piData ) +{ + ivas_error error; + + /* Sanitize maximum sizes for each PI Type */ + if ( piSize > maxPiDataSize[piDataType] ) + { + return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Max size for PI Data type exceeded" ); + } + + error = unpackPiDataFuntions[piDataType]( piDataBuffer, piSize, piData ); + ERR_CHECK_RETURN( error ); + + /* since some pi data share piData structure, pi id are re-filled after unpacking */ + piData->piDataType = piDataType; + + return IVAS_ERR_OK; +} + +/* 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, + 0.4032f, 0.5080f, 0.64f, 0.8063f, 1.0159f, 1.28f, 1.6127f, 2.0319f, + 2.56f, 3.2254f, 4.0637f, 5.12f, 6.4508f, 8.1275f, 10.24f, 12.9016f +}; + +const float mapDSR[1u << NBITS_DSR] = { + -20.f, -21.f, -22.f, -23.f, -24.f, -25.f, -26.f, -27.f, + -28.f, -29.f, -30.f, -31.f, -32.f, -33.f, -34.f, -35.f, + -36.f, -37.f, -38.f, -39.f, -40.f, -41.f, -42.f, -43.f, + -44.f, -45.f, -46.f, -47.f, -48.f, -49.f, -50.f, -51.f, + -52.f, -53.f, -54.f, -55.f, -56.f, -57.f, -58.f, -59.f, + -60.f, -61.f, -62.f, -63.f, -64.f, -65.f, -66.f, -67.f, + -68.f, -69.f, -70.f, -71.f, -72.f, -73.f, -74.f, -75.f, + -76.f, -77.f, -78.f, -79.f, -80.f, -81.f, -82.f, -83.f +}; + +const float mapRoomDims[1u << NBITS_DIM] = { + 0.5f, 0.707f, 1.f, 1.4141f, 2, 2.8282f, 4.f, 5.6568f, + 8.f, 11.314f, 16.f, 22.627f, 32.f, 45.255f, 64.f, 90.51f +}; + +const float mapAbsorbtion[1u << NBITS_ABS] = { + 0.0800f, 0.1656f, 0.3430f, 0.7101f +}; diff --git a/lib_isar/isar_NoiseGen.c b/lib_util/ivas_rtp_pi_data.h similarity index 79% rename from lib_isar/isar_NoiseGen.c rename to lib_util/ivas_rtp_pi_data.h index 363e758fffbdd642dc3aa4061bd3ee6ac13e2853..4f156a9defe729157620134f738e1c7ec0649d3c 100644 --- a/lib_isar/isar_NoiseGen.c +++ 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 @@ -30,26 +30,18 @@ *******************************************************************************************************/ -#include -#include "options.h" -#include -#include "prot_fx.h" -#include "isar_lcld_prot.h" -#include "wmc_auto.h" +#ifndef IVAS_RTP_PI_DATA_H +#define IVAS_RTP_PI_DATA_H +#include "common_api_types.h" -/*------------------------------------------------------------------------------------------* - * Function DeleteNoiseGen() - * - * - *------------------------------------------------------------------------------------------*/ -void DeleteNoiseGen( NoiseGen *psNoiseGen ) -{ - free( psNoiseGen->pfNoiseBuffer ); - free( psNoiseGen ); +#define IVAS_PI_MAX_DATA_SIZE ( 32 + 2 ) /* max packed PI data bytes + pi header bytes */ - return; -} +#define REVERSE_ISM_DIRECTION_AZIMUTH_STEP 0.703125f +#define REVERSE_ISM_DIRECTION_ELEVATION_STEP 1.417322835f +#define REVERSE_ISM_DIRECTION_AZIMUTH_STEP_INV 1.4222222222f +#define REVERSE_ISM_DIRECTION_ELEVATION_STEP_INV 0.7055555556f -extern Word32 GetNoise_fx( NoiseGen *psNoiseGen ); + +#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 37784a6305c237882477fd37292abdf89e78c79d..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 @@ -33,7 +33,7 @@ #include "ls_custom_file_reader.h" #include #include -#include "ivas_prot_fx.h" +#include struct LsCustomFileReader @@ -105,6 +105,96 @@ void CustomLsReader_close( } +/*-------------------------------------------------------------------* + * panning_wrap_angles() + * + * Wrap angles for amplitude panning to the range: + * azimuth = (-180, 180] + * elevation = [-90, 90] + * Considers direction changes from large elevation values + *-------------------------------------------------------------------*/ + +/* helper function for panning_wrap_angles */ +static float wrap_azi( + const float azi_deg ) +{ + float azi = azi_deg; + + /* Wrap azimuth value */ + while ( azi > 180 ) + { + azi -= 360.0f; + } + + while ( azi <= -180 ) + { + azi += 360; + } + + return azi; +} + +static void panning_wrap_angles( + const float azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ + const float ele_deg, /* i : elevation in degrees for panning direction (positive up) */ + float *azi_wrapped, /* o : wrapped azimuth component */ + float *ele_wrapped /* o : wrapped elevation component */ +) +{ + float azi, ele; + + azi = azi_deg; + ele = ele_deg; + + if ( fabsf( ele ) < 90 ) + { + *ele_wrapped = ele; + *azi_wrapped = wrap_azi( azi ); + return; + } + else + { + /* Special case when elevation is a multiple of 90; azimuth is irrelevant */ + if ( ( fmodf( ele, 90 ) == 0 ) && ( fmodf( ele, 180 ) != 0 ) ) + { + *azi_wrapped = 0; + while ( ele > 90 ) + { + ele -= 360; + } + while ( ele < -90 ) + { + ele += 360; + } + *ele_wrapped = ele; + } + else + { + /* Wrap elevation and adjust azimuth accordingly */ + while ( fabsf( ele ) > 90 ) + { + /* Flip to other hemisphere */ + azi += 180; + + /* Compensate elevation accordingly */ + if ( ele > 90 ) + { + ele = 180 - ele; + } + else if ( ele < -90 ) + { + ele = -180 - ele; + } + } + *azi_wrapped = wrap_azi( azi ); + *ele_wrapped = ele; + } + + return; + } +} + + /*-------------------------------------------------------------------------* * CustomLoudspeakerLayout_validate() * 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 87ce9d13143af4edd5c3ef7e8c1e34f1d8147eab..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 @@ -317,11 +317,7 @@ static bool readByte( FILE *file, uint8_t *value ) static bool readLong( FILE *file, uint16_t *value ) { char buffer[4] = { 0 }; -#ifdef CODE_IMPROVEMENTS if ( fread( buffer, 1, 4, file ) != 1U ) -#else - if ( fread( buffer, 4, 1, file ) != 1U ) -#endif { return false; } 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 new file mode 100644 index 0000000000000000000000000000000000000000..64f5d2c58397152ef66437b7955410ac00679070 --- /dev/null +++ b/lib_util/mutex.h @@ -0,0 +1,104 @@ +/****************************************************************************************************** + + (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. 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. + +*******************************************************************************************************/ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 + ====================================================================================*/ + +#ifndef _MUTEX_H +#define _MUTEX_H + +#if defined( __unix__ ) || defined( __linux__ ) || ( defined( __MACH__ ) && defined( __APPLE__ ) ) +#include +typedef pthread_mutex_t mtx_t; +#define _USE_POSIX ( 1 ) +#elif defined( _WIN32 ) || defined( _WIN64 ) +#include +typedef CRITICAL_SECTION mtx_t; +#define _USE_WIN ( 1 ) +#else +typedef int mtx_t; +#warning Mutex implementation to be defined for this platform here. +#endif + +static __inline int mtx_init( mtx_t *mutex, int type ) +{ + int err = 0; + (void) type; +#ifdef _USE_POSIX + err = pthread_mutex_init( mutex, NULL ); +#elif defined( _USE_WIN ) + InitializeCriticalSection( mutex ); +#else + (void) mutex; +#endif + return err; +} + +static __inline void mtx_destroy( mtx_t *mutex ) +{ +#if _USE_POSIX + pthread_mutex_destroy( mutex ); +#elif defined( _USE_WIN ) + DeleteCriticalSection( mutex ); +#else + (void) mutex; +#endif +} + +static __inline int mtx_lock( mtx_t *mutex ) +{ + int err = 0; +#if _USE_POSIX + err = pthread_mutex_lock( mutex ); +#elif defined( _USE_WIN ) + EnterCriticalSection( mutex ); +#else + (void) mutex; +#endif + return err; +} + +static __inline int mtx_unlock( mtx_t *mutex ) +{ + int err = 0; +#if _USE_POSIX + err = pthread_mutex_unlock( mutex ); +#elif defined( _USE_WIN ) + LeaveCriticalSection( mutex ); +#else + (void) mutex; +#endif + return err; +} + +#endif /* _MUTEX_H */ diff --git a/lib_util/obj_edit_file_reader.c b/lib_util/obj_edit_file_reader.c index 63a5420943e6337098ed2b9b92dbe4175185258b..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() * @@ -70,8 +77,7 @@ ivas_error ObjectEditFileReader_open( } self = (ObjectEditFileReader *) calloc( 1, sizeof( ObjectEditFileReader ) ); - - self->maxLineLen = 256; + self->maxLineLen = 1024; self->editFileHandle = fileHandle; self->inLine = (char *) calloc( self->maxLineLen, sizeof( char ) ); @@ -90,6 +96,15 @@ ivas_error ObjectEditFileReader_open( self->readInfo->obj_ele[obj_idx] = 0.0f; self->readInfo->obj_ele_edited[obj_idx] = false; self->readInfo->obj_ele_relative[obj_idx] = false; + self->readInfo->obj_radius[obj_idx] = 0.0f; + self->readInfo->obj_radius_edited[obj_idx] = false; + self->readInfo->obj_radius_relative[obj_idx] = false; + self->readInfo->obj_yaw[obj_idx] = 0.0f; + self->readInfo->obj_yaw_edited[obj_idx] = false; + self->readInfo->obj_yaw_relative[obj_idx] = false; + self->readInfo->obj_pitch[obj_idx] = 0.0f; + self->readInfo->obj_pitch_edited[obj_idx] = false; + self->readInfo->obj_pitch_relative[obj_idx] = false; } self->rewound = false; @@ -136,6 +151,12 @@ ivas_error ObjectEditFileReader_readNextFrame( readEdits->obj_azi_relative[obj_idx] = false; readEdits->obj_ele_edited[obj_idx] = false; readEdits->obj_ele_relative[obj_idx] = false; + readEdits->obj_radius_edited[obj_idx] = false; + readEdits->obj_radius_relative[obj_idx] = false; + readEdits->obj_yaw_edited[obj_idx] = false; + readEdits->obj_yaw_relative[obj_idx] = false; + readEdits->obj_pitch_edited[obj_idx] = false; + readEdits->obj_pitch_relative[obj_idx] = false; } /* tokenize the line by comma */ @@ -207,6 +228,33 @@ ivas_error ObjectEditFileReader_readNextFrame( { readEdits->obj_ele_relative[obj_idx] = ( strcmp( paramValue, "1" ) == 0 ); } + else if ( strcmp( param, "radius" ) == 0 ) + { + readEdits->obj_radius[obj_idx] = strtof( paramValue, NULL ); + readEdits->obj_radius_edited[obj_idx] = true; + } + else if ( strcmp( param, "yaw" ) == 0 ) + { + readEdits->obj_yaw[obj_idx] = strtof( paramValue, NULL ); + readEdits->obj_yaw_edited[obj_idx] = true; + } + else if ( strcmp( param, "pitch" ) == 0 ) + { + readEdits->obj_pitch[obj_idx] = strtof( paramValue, NULL ); + readEdits->obj_pitch_edited[obj_idx] = true; + } + else if ( strcmp( param, "relradius" ) == 0 ) + { + readEdits->obj_radius_relative[obj_idx] = ( strcmp( paramValue, "1" ) == 0 ); + } + else if ( strcmp( param, "relyaw" ) == 0 ) + { + readEdits->obj_yaw_relative[obj_idx] = ( strcmp( paramValue, "1" ) == 0 ); + } + else if ( strcmp( param, "relpitch" ) == 0 ) + { + readEdits->obj_pitch_relative[obj_idx] = ( strcmp( paramValue, "1" ) == 0 ); + } } } } @@ -230,6 +278,18 @@ ivas_error ObjectEditFileReader_readNextFrame( { readEdits->obj_ele[obj_idx] = max( min( readEdits->obj_ele[obj_idx], 90.f ), -90.f ); } + if ( readEdits->obj_radius_edited[obj_idx] && !readEdits->obj_radius_relative[obj_idx] ) + { + readEdits->obj_radius[obj_idx] = max( min( readEdits->obj_radius[obj_idx], OBJ_EDIT_RADIUS_MAX ), 0.0f ); + } + if ( readEdits->obj_yaw_edited[obj_idx] && !readEdits->obj_yaw_relative[obj_idx] ) + { + readEdits->obj_yaw[obj_idx] = max( min( readEdits->obj_yaw[obj_idx], 180.f ), -180.f ); + } + if ( readEdits->obj_pitch_edited[obj_idx] && !readEdits->obj_pitch_relative[obj_idx] ) + { + readEdits->obj_pitch[obj_idx] = max( min( readEdits->obj_pitch[obj_idx], 90.f ), -90.f ); + } } } else diff --git a/lib_util/obj_edit_file_reader.h b/lib_util/obj_edit_file_reader.h index 4c3e4435f7864dfda5dd04aac759a92c8ada7161..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 @@ -41,10 +41,14 @@ the United Nations Convention on Contracts on the International Sales of Goods. * Constants ans structures *---------------------------------------------------------------------*/ -#define OBJ_EDIT_GAIN_MIN_FX 33874262 /* Q29, 0.06309573f, -24 dB */ -#define OBJ_EDIT_GAIN_MAX_FX 2127207375 /* Q29, 3.9622325f, +12 dB, TODO: align with float */ -#define OBJ_EDIT_GAIN_MIN 0.06309573f /* -24 dB */ -#define OBJ_EDIT_GAIN_MAX 3.9622325f /* +12 dB */ +#define OBJ_EDIT_GAIN_MIN_FX 0 /* Q29, 0.0f, -inf dB */ +#define OBJ_EDIT_GAIN_MAX_FX 2137321728 /* Q29, 3.9810719f, +12 dB */ +#define OBJ_EDIT_GAIN_MIN 0.0f /* -inf dB */ +#define OBJ_EDIT_GAIN_MAX 3.9810719f /* +12 dB */ + +#define OBJ_EDIT_RADIUS_MAX 15.75f /* Max radius = (2^ISM_RADIUS_NBITS-1)*0.25 = 15.75 */ +#define OBJ_EDIT_RADIUS_MAX_FX 8064 /* Q9, 15.75f (15.75 * 512 = 8064) */ +#define OBJ_EDIT_RADIUS_MIN_FX 0 typedef struct ObjectEditFileReader ObjectEditFileReader; typedef struct ReadObjectEditInfo ReadObjectEditInfo; @@ -65,6 +69,18 @@ struct ReadObjectEditInfo float obj_ele[IVAS_MAX_NUM_OBJECTS]; bool obj_ele_edited[IVAS_MAX_NUM_OBJECTS]; bool obj_ele_relative[IVAS_MAX_NUM_OBJECTS]; + + float obj_radius[IVAS_MAX_NUM_OBJECTS]; + bool obj_radius_edited[IVAS_MAX_NUM_OBJECTS]; + bool obj_radius_relative[IVAS_MAX_NUM_OBJECTS]; + + float obj_yaw[IVAS_MAX_NUM_OBJECTS]; + bool obj_yaw_edited[IVAS_MAX_NUM_OBJECTS]; + bool obj_yaw_relative[IVAS_MAX_NUM_OBJECTS]; + + float obj_pitch[IVAS_MAX_NUM_OBJECTS]; + bool obj_pitch_edited[IVAS_MAX_NUM_OBJECTS]; + bool obj_pitch_relative[IVAS_MAX_NUM_OBJECTS]; }; struct ObjectEditFileReader diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index 14538b5ee9bb3fa4f251e0acdcf74df79798019a..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 @@ -38,6 +38,7 @@ #include #include "cmdl_tools.h" #include "prot_fx.h" +#include "ivas_cnst.h" /*------------------------------------------------------------------------------------------* @@ -86,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 @@ -660,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++ ) { @@ -1265,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 ) ) @@ -1303,66 +1299,43 @@ ivas_error RenderConfigReader_checkValues( if ( pRoom_acoustics->use_er == 1 ) { /* Room dimensions */ - if ( pRoom_acoustics->dimensions.x < ER_MIN_ROOM_DIMENSION ) + if ( pRoom_acoustics->dimensions.x_fx < ER_MIN_ROOM_DIMENSION_FX ) { - pRoom_acoustics->dimensions.x = ER_MIN_ROOM_DIMENSION; pRoom_acoustics->dimensions.x_fx = ER_MIN_ROOM_DIMENSION_FX; } - if ( pRoom_acoustics->dimensions.x > ER_MAX_ROOM_DIMENSION ) + if ( pRoom_acoustics->dimensions.x_fx > ER_MAX_ROOM_DIMENSION_FX ) { - pRoom_acoustics->dimensions.x = ER_MAX_ROOM_DIMENSION; pRoom_acoustics->dimensions.x_fx = ER_MAX_ROOM_DIMENSION_FX; } - if ( pRoom_acoustics->dimensions.y < ER_MIN_ROOM_DIMENSION ) + if ( pRoom_acoustics->dimensions.y_fx < ER_MIN_ROOM_DIMENSION_FX ) { - pRoom_acoustics->dimensions.y = ER_MIN_ROOM_DIMENSION; pRoom_acoustics->dimensions.y_fx = ER_MIN_ROOM_DIMENSION_FX; } - if ( pRoom_acoustics->dimensions.y > ER_MAX_ROOM_DIMENSION ) + if ( pRoom_acoustics->dimensions.y_fx > ER_MAX_ROOM_DIMENSION_FX ) { - pRoom_acoustics->dimensions.y = ER_MAX_ROOM_DIMENSION; pRoom_acoustics->dimensions.y_fx = ER_MAX_ROOM_DIMENSION_FX; } - if ( pRoom_acoustics->dimensions.z < ER_MIN_ROOM_DIMENSION ) + if ( pRoom_acoustics->dimensions.z_fx < ER_MIN_ROOM_DIMENSION_FX ) { - pRoom_acoustics->dimensions.z = ER_MIN_ROOM_DIMENSION; pRoom_acoustics->dimensions.z_fx = ER_MIN_ROOM_DIMENSION_FX; } - if ( pRoom_acoustics->dimensions.z > ER_MAX_ROOM_DIMENSION ) + if ( pRoom_acoustics->dimensions.z_fx > ER_MAX_ROOM_DIMENSION_FX ) { - pRoom_acoustics->dimensions.z = ER_MAX_ROOM_DIMENSION; pRoom_acoustics->dimensions.z_fx = ER_MAX_ROOM_DIMENSION_FX; } /* Abs Coeff */ for ( wall_idx = 0; wall_idx < IVAS_ROOM_ABS_COEFF; wall_idx++ ) { - if ( pRoom_acoustics->AbsCoeff[wall_idx] < ER_MIN_ABS_COEFF ) + if ( pRoom_acoustics->AbsCoeff_fx[wall_idx] < ER_MIN_ABS_COEFF_FX ) { - pRoom_acoustics->AbsCoeff[wall_idx] = ER_MIN_ABS_COEFF; pRoom_acoustics->AbsCoeff_fx[wall_idx] = ER_MIN_ABS_COEFF_FX; } - if ( pRoom_acoustics->AbsCoeff[wall_idx] > ER_MAX_ABS_COEFF ) + if ( pRoom_acoustics->AbsCoeff_fx[wall_idx] > ER_MAX_ABS_COEFF_FX ) { - pRoom_acoustics->AbsCoeff[wall_idx] = ER_MAX_ABS_COEFF; 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 } @@ -2006,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 ) @@ -2832,6 +2807,116 @@ ivas_error RenderConfigReader_read( } return IVAS_ERR_OK; } + + +/*------------------------------------------------------------------------------------------* + * RenderConfigReader_getAcousticEnvironmentCount() + * + * Gets number of acoustic environments available + *------------------------------------------------------------------------------------------*/ + +uint32_t RenderConfigReader_getAcousticEnvironmentCount( + RenderConfigReader *pRenderConfigReader /* i : RenderConfigReader handle */ +) +{ + return pRenderConfigReader->nAE; +} + + +/*------------------------------------------------------------------------------------------* + * RenderConfigReader_getAcousticEnvironments() + * + * Gets all acoustic environments + *------------------------------------------------------------------------------------------*/ + +ivas_error RenderConfigReader_getAcousticEnvironments( + RenderConfigReader *pRenderConfigReader, /* i : RenderConfigReader handle */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA **ppAcEnv /* o : Acoustic environment array pointer */ +) +{ + uint16_t n, m, j; + + if ( pRenderConfigReader == NULL || ppAcEnv == NULL || pRenderConfigReader->nAE == 0 || pRenderConfigReader->pAE == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + for ( n = 0; n < pRenderConfigReader->nAE; n++ ) + { + AcousticEnv pIn = pRenderConfigReader->pAE[n]; + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pOut = ppAcEnv[n]; + + pOut->aeID = (Word16) pIn.id; + pOut->nBands = (Word16) pIn.pFG->nrBands; + if ( pRenderConfigReader->pAE[n].preDelay > INPUTPREDELAY_MAX || + pRenderConfigReader->pAE[n].preDelay < INPUTPREDELAY_MIN ) + { + return IVAS_ERR_INVALID_RENDER_CONFIG; + } + pOut->inputPreDelay_fx = (Word32) ( pIn.preDelay * ONE_IN_Q27 ); + + for ( m = 0; m < pOut->nBands; m++ ) + { + pOut->pFc_input_fx[m] = (Word32) ( pIn.pFG->pFc[m] * ONE_IN_Q16 ); + pOut->pAcoustic_rt60_fx[m] = (Word32) ( pIn.pRT60[m] * ONE_IN_Q26 ); + pOut->pAcoustic_dsr_fx[m] = (Word32) ( pIn.pDSR[m] * ONE_IN_Q30 ); + } + + /* If ER are allocated then propagate parameters */ + if ( pIn.pEarlyReflections != 0 ) + { + pOut->use_er = pIn.pEarlyReflections->use_er; /* ER activation flag */ + pOut->lowComplexity = pIn.pEarlyReflections->lowComplexity; /* Low complexity flag */ + pOut->dimensions = pIn.pEarlyReflections->dimensions; + pOut->dimensions.x_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.x * ONE_IN_Q22 ); + pOut->dimensions.y_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.y * ONE_IN_Q22 ); + pOut->dimensions.z_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->dimensions.z * ONE_IN_Q22 ); + + /* Use default listener origin position if non provided */ + if ( pIn.pEarlyReflections->pListenerOrigin == NULL ) + { + pOut->ListenerOrigin.x = IVAS_ER_LIST_ORIGIN_X; + pOut->ListenerOrigin.y = IVAS_ER_LIST_ORIGIN_Y; + pOut->ListenerOrigin.z = IVAS_ER_LIST_HEIGHT; + + pOut->ListenerOrigin.x_fx = IVAS_ER_LIST_ORIGIN_X_FX; + pOut->ListenerOrigin.y_fx = IVAS_ER_LIST_ORIGIN_Y_FX; + pOut->ListenerOrigin.z_fx = IVAS_ER_LIST_HEIGHT_FX; + pOut->ListenerOrigin.q_fact = Q22; + } + else + { + pOut->ListenerOrigin.x = pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin->x; + pOut->ListenerOrigin.y = pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin->y; + pOut->ListenerOrigin.z = pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin->z; + + pOut->ListenerOrigin.x_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin->x * ONE_IN_Q22 ); + pOut->ListenerOrigin.y_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin->y * ONE_IN_Q22 ); + pOut->ListenerOrigin.z_fx = (Word32) ( pRenderConfigReader->pAE[n].pEarlyReflections->pListenerOrigin->z * ONE_IN_Q22 ); + } + + for ( j = 0; j < IVAS_ROOM_ABS_COEFF; j++ ) + { + pOut->AbsCoeff[j] = pIn.pEarlyReflections->pAbsCoeff[j]; + pOut->AbsCoeff_fx[j] = (Word32) ( pIn.pEarlyReflections->pAbsCoeff[j] * ONE_IN_Q30 ); + } + } + else + { + pOut->use_er = false; + } + } + + return IVAS_ERR_OK; +} + + +/*------------------------------------------------------------------------------------------* + * RenderConfigReader_getAcousticEnvironment() + * + * Gets Acoustic environment with a given ID + *------------------------------------------------------------------------------------------*/ + ivas_error RenderConfigReader_getAcousticEnvironment( RenderConfigReader *pRenderConfigReader, /* i : RenderConfigReader handle */ uint16_t id, /* i : Acoustic environment ID */ @@ -2847,7 +2932,7 @@ ivas_error RenderConfigReader_getAcousticEnvironment( } /* case when -aeid is not specified, select first ID from config file */ - if ( id == 65535 && pRenderConfigReader->nAE > 0 ) + if ( id == (UWord16) IVAS_DEFAULT_AEID && pRenderConfigReader->nAE > 0 ) { id = (uint16_t) pRenderConfigReader->pAE[0].id; } diff --git a/lib_util/render_config_reader.h b/lib_util/render_config_reader.h index 58946eca6bd690c3fd887db079e24f1bcbef6d97..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 @@ -51,6 +51,17 @@ ivas_error RenderConfigReader_open( RenderConfigReader **ppRenderConfigReader /* o : RenderConfigReader handle */ ); +/* Get number of acoustic environments */ +uint32_t RenderConfigReader_getAcousticEnvironmentCount( + RenderConfigReader *pRenderConfigReader /* i : RenderConfigReader handle */ +); + +/* Get all acoustic environments */ +ivas_error RenderConfigReader_getAcousticEnvironments( + RenderConfigReader *pRenderConfigReader, /* i : RenderConfigReader handle */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA **ppAcEnv /* o : Acoustic environment array pointer */ +); + /* Get an acoustic environment */ ivas_error RenderConfigReader_getAcousticEnvironment( RenderConfigReader *pRenderConfigReader, /* i : RenderConfigReader handle */ diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index 2f32ea858de8a066ba9e09cd6968e626599d6f08..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 @@ -33,10 +33,14 @@ #include "rotation_file_reader.h" #include #include -#include -#include "prot_fx.h" +#include "float_to_fix_ops.h" +#define Q22 22 +#define Q25 25 +#define Q29 29 +#define Q31 31 + struct RotFileReader { FILE *trajFile; @@ -193,23 +197,18 @@ ivas_error ExternalOrientationFileReading( } ( externalOrientationReader->frameCounter )++; -#ifdef FIX_1370_EXTERNAL_ORIENTATION_CHECK /* Only Quaternion orientations are supported, raise an error if Euler angles are detected in the input */ if ( w == -3.0f ) { return IVAS_ERR_EXTERNAL_ORIENTATION_INVALID_FORMAT; } -#endif pQuaternion->w_fx = float_to_fix( w, Q29 ); pQuaternion->x_fx = float_to_fix( x, Q29 ); pQuaternion->y_fx = float_to_fix( y, Q29 ); pQuaternion->z_fx = float_to_fix( z, Q29 ); - move32(); - move32(); - move32(); - move32(); + *enableHeadRotation = (int8_t) headRotFlag; *enableExternalOrientation = (int8_t) extOrientationFlag; *enableRotationInterpolation = (int8_t) rotInterpolationFlag; 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 d2f13f6bcf6f9fb37ce59e111ff8e6452397bcc4..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 @@ -31,13 +31,14 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include #include #include #include "rtpdump.h" +#include "options.h" struct RTPDUMP { @@ -80,11 +81,7 @@ static unsigned char *parseByte( unsigned char *buffer, unsigned char *value ) static int readLong( FILE *file, unsigned int *value ) { char buffer[4] = { 0 }; -#ifdef CODE_IMPROVEMENTS if ( fread( buffer, 1, 4, file ) != 1U ) -#else - if ( fread( buffer, 4, 1, file ) != 1U ) -#endif { return -1; } @@ -100,11 +97,7 @@ static int readLong( FILE *file, unsigned int *value ) static int readShort( FILE *file, unsigned short *value ) { char buffer[2] = { 0 }; -#ifdef CODE_IMPROVEMENTS if ( fread( buffer, 1, 2, file ) != 1U ) -#else - if ( fread( buffer, 2, 1, file ) != 1U ) -#endif { return -1; } @@ -118,10 +111,10 @@ static int readShort( FILE *file, unsigned short *value ) static int writeLong( FILE *file, unsigned int value ) { char buffer[4] = { 0 }; - buffer[3] = value & 0xff; - buffer[2] = ( value >> 8 ) & 0xff; - buffer[1] = ( value >> 16 ) & 0xff; - buffer[0] = ( value >> 24 ) & 0xff; + buffer[3] = (char) ( value & 0xff ); + buffer[2] = (char) ( ( value >> 8 ) & 0xff ); + buffer[1] = (char) ( ( value >> 16 ) & 0xff ); + buffer[0] = (char) ( ( value >> 24 ) & 0xff ); if ( fwrite( buffer, 4, 1, file ) != 1U ) { return -1; @@ -133,8 +126,8 @@ static int writeLong( FILE *file, unsigned int value ) static int writeShort( FILE *file, unsigned short value ) { char buffer[2] = { 0 }; - buffer[1] = value & 0xff; - buffer[0] = ( value >> 8 ) & 0xff; + buffer[1] = (char) ( value & 0xff ); + buffer[0] = (char) ( ( value >> 8 ) & 0xff ); if ( fwrite( buffer, 2, 1, file ) != 1U ) { return -1; diff --git a/lib_util/rtpdump.h b/lib_util/rtpdump.h index 8fe2323f66f119fa6f6bdf86490f2c1754171cc7..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 @@ -31,7 +31,7 @@ *******************************************************************************************************/ /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #pragma once 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 179c676a81b274098fabbe5050c2c977572c82ec..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 @@ -54,22 +54,14 @@ #define __TWI_SUCCESS ( 0 ) #define __TWI_ERROR ( -1 ) -#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveInHandle -#else -typedef struct __tinyWaveInHandle -#endif { FILE *theFile; fpos_t dataChunkPos; uint32_t position; uint32_t length; uint32_t bps; -#ifdef CODE_IMPROVEMENTS } tinyWaveInHandle, WAVEFILEIN; -#else -} __tinyWaveInHandle, WAVEFILEIN; -#endif typedef struct { diff --git a/lib_util/tinywaveout_c.h b/lib_util/tinywaveout_c.h index 70373e3cca0850aacd3849376765690d3980927a..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 @@ -70,27 +70,15 @@ #endif #endif -#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutHeader -#else -typedef struct __tinyWaveOutHeader -#endif { uint32_t riffType; /* 'RIFF' */ uint32_t riffSize; /* file size */ uint32_t waveType; /* 'WAVE' */ -#ifdef CODE_IMPROVEMENTS } tinyWaveOutHeader; -#else -} __tinyWaveOutHeader; -#endif -#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutFmtChunk -#else -typedef struct __tinyWaveOutFmtChunk -#endif { uint32_t formatType; uint32_t formatSize; @@ -103,32 +91,16 @@ typedef struct __tinyWaveOutFmtChunk uint16_t bitsPerSample; /* wav fmt ext hdr here */ -#ifdef CODE_IMPROVEMENTS } tinyWaveOutFmtChunk; -#else -} __tinyWaveOutFmtChunk; -#endif -#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutDataChunk -#else -typedef struct __tinyWaveOutDataChunk -#endif { uint32_t dataType; uint32_t dataSize; -#ifdef CODE_IMPROVEMENTS } tinyWaveOutDataChunk; -#else -} __tinyWaveOutDataChunk; -#endif -#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutHandle -#else -typedef struct __tinyWaveOutHandle -#endif { FILE *theFile; uint32_t dataSize; @@ -137,11 +109,7 @@ typedef struct __tinyWaveOutHandle uint32_t dataChunkOffset; uint32_t bps; uint32_t clipCount; -#ifdef CODE_IMPROVEMENTS } tinyWaveOutHandle, WAVEFILEOUT; -#else -} __tinyWaveOutHandle, WAVEFILEOUT; -#endif /*--- local protos --------------------------------------------------*/ static __inline uint32_t BigEndian32( char, char, char, char ); @@ -164,15 +132,9 @@ static WAVEFILEOUT *CreateBWF( /* ,const uint32_t writeWaveExt */ ) { WAVEFILEOUT *self; -#ifdef CODE_IMPROVEMENTS tinyWaveOutHeader whdr; tinyWaveOutFmtChunk wfch; tinyWaveOutDataChunk wdch; -#else - __tinyWaveOutHeader whdr; - __tinyWaveOutFmtChunk wfch; - __tinyWaveOutDataChunk wdch; -#endif uint32_t blockAlignment = 0; uint32_t ByteCnt = 0; /* Byte counter for fwrite */ diff --git a/lib_util/vector3_pair_file_reader.c b/lib_util/vector3_pair_file_reader.c index a4b8cc450bdb26b6f204a3cce6935cf906a19c33..d2225b7f5e7c8524254fa446cd094842cacba599 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 @@ -33,8 +33,7 @@ #include "vector3_pair_file_reader.h" #include #include -#include "prot_fx.h" // needed for floatToFixed_32 -//#include "ivas_prot_fx.h" // needed for floatToFixed_32 +#include "float_to_fix_ops.h" // needed for floatToFixed_32 struct Vector3PairFileReader @@ -115,8 +114,8 @@ ivas_error Vector3PairFileReader_read( pSecond->y = y2; pSecond->z = z2; - pFirst->q_fact = Q29; - pSecond->q_fact = Q29; + pFirst->q_fact = 27; // Q27 + pSecond->q_fact = 27; // Q27 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 d272f7a8c3eceb52328046d6e43b843d6784ddf5..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 @@ -33,13 +33,14 @@ These files represent the 3GPP EVS Codec Extension for Immersive Voice and Audio Services (IVAS) BASOP C simulation. All code is writtten -in ISO/IEC C99. The system is implemented as five separate programs: +in ISO/IEC C99. The system is implemented as six separate programs: - IVAS_cod IVAS Encoder - IVAS_dec IVAS Decoder - IVAS_rend IVAS External Renderer + IVAS_cod IVAS Encoder + IVAS_dec IVAS Decoder + IVAS_rend IVAS External Renderer ISAR_post_rend ISAR Post Renderer - ambi_converter Ambisonics format converter + IVAS_cod_fmtsw IVAS Encoder with support for format switching + ambi_converter example program for Ambisonics format conversion For encoding using the coder program, the input is a binary audio file (*.8k, *.16k, *.32k, *.48k) and the output is a binary @@ -123,32 +124,39 @@ should have the following structure: . `-- c-code + |-- readme.txt |-- Makefile |-- Workspace_msvc |-- apps + |-- lib_basop |-- lib_com |-- lib_debug |-- lib_dec |-- lib_enc |-- lib_isar |-- lib_lc3plus - |-- lib_rend + |-- lib_rend |-- lib_util - |-- readme.txt - |-- .clang-format + |-- scripts The package includes a Makefile for gcc, which has been verified on 32-bit Linux systems. The code can be compiled by entering the directory "c-code" and typing the command: make. The resulting encoder/decoder/renderer/ ISAR_post_renderer executables are named "IVAS_cod", "IVAS_dec", "IVAS_rend", -and "ISAR_post_rend". All reside in the c-code directory. +and "ISAR_post_rend". All reside in the c-code directory. In addition, this +directory will contain a version of the encoder with support for format switching +(named "IVAS_cod_fmtsw") and an example program for Ambisonics format conversion +(named "ambi_converter"). The package also includes a solution-file for Microsoft Visual Studio 2017 (x86). To compile the code, please open "Workspace_msvc\Workspace_msvc.sln" and build "encoder" for the encoder, "decoder" for the decoder, and "renderer" for the renderer executable. The resulting encoder/decoder/renderer/ISAR_post_renderer executables are "IVAS_cod.exe", "IVAS_dec.exe", "IVAS_rend.exe", and -"ISAR_post_rend.exe". All reside in the c-code main directory. +"ISAR_post_rend.exe". All reside in the c-code main directory. In addition, this +directory will contain a version of the encoder with support for format switching +(named "IVAS_cod_fmtsw.exe") and an example program for Ambisonics format conversion +(named "ambi_converter.exe"). @@ -176,7 +184,7 @@ some potential race conditions. The usage of the "IVAS_cod" program is as follows: -------------------------------------------------- -Usage: IVAS_cod.exe [Options] R Fs input_file bitstream_file +Usage: IVAS_cod [Options] R Fs input_file bitstream_file Mandatory parameters: --------------------- @@ -234,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 @@ -251,19 +259,26 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. Currently, all values default to level 3 (full functionality). -q : Quiet mode, limit printouts to terminal, default is deactivated +-rtpdump : RTPDump output, hf_only=1 by default. The encoder will packetize the + bitstream frames into TS26.253 Annex A IVAS RTP Payload Format packets and + writes those to the output file. In EVS mono operating mode, TS26.445 Annex A.2.2 + EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet +-scene_orientation : Scene orientation trajectory file. Only used with rtpdump output. +-device_orientation : Device orientation trajectory file. Only used with rtpdump output. The usage of the "IVAS_dec" program is as follows: -------------------------------------------------- -Usage for EVS: IVAS_dec.exe [Options] Fs bitstream_file output_file -Usage for IVAS: IVAS_dec.exe [Options] OutputConf Fs bitstream_file output_file +Usage for EVS: IVAS_dec [Options] Fs bitstream_file output_file + OR usage for IVAS (below) with -evs option and OutputConf +Usage for IVAS: IVAS_dec [Options] OutputConf Fs bitstream_file output_file Mandatory parameters: --------------------- OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA, - HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, - BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM, EXT + HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, + BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM, EXT By default, channel order and loudspeaker positions are equal to the encoder. For loudspeaker outputs, OutputConf can be a custom loudspeaker layout file. See below for details. @@ -274,11 +289,13 @@ output_file : Output audio filename Options: -------- +-evs : Specify that the supplied bitstream is an EVS bitstream -VOIP : VoIP mode: RTP in G192 -VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump --VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump +-VOIP_hf_only=1 : VoIP mode: EVS or IVAS RTP Payload Format hf_only=1 in rtpdump The decoder may read rtpdump files containing TS26.445 Annex A.2.2 - EVS RTP Payload Format. The SDP parameter hf_only is required. + EVS RTP Payload Format or rtpdump files containing TS26.253 Annex A + IVAS RTP Payload Format. The SDP parameter hf_only is required. Reading RFC4867 AMR/AMR-WB RTP payload format is not supported. -Tracefile TF : VoIP mode: Generate trace file named TF. Requires -no_delay_cmp to be enabled so that trace contents remain in sync with audio output. @@ -302,16 +319,19 @@ Options: -rvf File : Reference vector specified by external trajectory File works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes -render_config File : Binaural renderer configuration parameters in File (only for binaural outputs) +-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large) + for BINAURAL_ROOM_REVERB output configuration -non_diegetic_pan P : panning mono non-diegetic sound to stereo -90<= P <=90, left or l or 90->left, right or r or -90->right, center or c or 0->middle -exof File : External orientation trajectory File for simulation of external orientations -dpid ID : Directivity pattern ID(s) (space-separated list of up to 4 numbers can be - specified) for binaural output configuration --aeid ID : Acoustic environment ID (number >= 0) for BINAURAL_ROOM_REVERB output config. + specified) for binaural output configurations +-aeid ID | File : Acoustic environment ID (number > 0) or a text file where each line + contains "ID duration" for BINAURAL_ROOM_REVERB output configuration -obj_edit File : Object editing instructions file or NULL for built-in example --level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. --om File : Coded metadata File for BINAURAL_SPLIT_PCM OutputConf - Currently, all values default to level 3 (full functionality). +-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation + Currently, all values default to level 3 (full functionality) +-om File : Coded metadata File for BINAURAL_SPLIT_PCM output configuration -q : Quiet mode, limit printouts to terminal, default is deactivated @@ -324,7 +344,9 @@ Options: -------- -i File : Input audio File (WAV, raw PCM or scene description file) -if Format : Audio Format of input file (e.g. 5_1 or HOA3 or META, use -l for a list) --im Files : Metadata files for ISM (one file per object) or MASA inputs + META is related to the Scene description file, see scripts/testv/renderer_config_format_readme.txt +-im Files : Metadata files for ISM/MASA/OMASA/OSBA/BINAURAL_SPLIT_PCM (one file per object). + For OMASA input, ISM files must be specified first. -o File : Output audio File -of Format : Audio Format of output file Alternatively, it can be a custom loudspeaker layout File @@ -336,49 +358,57 @@ Options: -rf File : Reference rotation trajectory File for simulation of head tracking (only for binaural outputs) -rvf File : Reference vector trajectory File for simulation of head tracking (only for binaural outputs) -render_config File : Binaural renderer configuration parameters in File (only for binaural outputs) +-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large) -non_diegetic_pan P : Panning mono non-diegetic sound to stereo -90<= P <= 90 - left or l or 90->left, right or r or -90->right, center or c or 0 ->middle + left or l or 90->left, right or r or -90->right, center or c or 0 ->middle -exof File : External orientation trajectory File for simulation of external orientations -dpid ID : Directivity pattern ID(s) (space-separated list of up to 4 numbers can be - specified) for binaural output configuration --aeid ID : Acoustic environment ID (number > 0) or - a sequence thereof in the format [ID1:duration1,ID2:duration2...] - without braces and spaces, with ':' character separating ID from duration and ',' separating - ID and duration pairs, where duration is specified in frames - for BINAURAL_ROOM_REVERB output configuration. + specified) for binaural output configurations +-aeid ID | File : Acoustic environment ID (number > 0) or a text file where each line + contains "ID duration" for BINAURAL_ROOM_REVERB output configuration -lp Position : Output LFE position. Comma-delimited triplet of [gain, azimuth, elevation] where gain is linear - (like --gain, -g) and azimuth, elevation are in degrees. - If specified, overrides the default behavior which attempts to map input to output LFE channel(s) + (like --gain, -g) and azimuth, elevation are in degrees + If specified, overrides the default behavior which attempts to map input to output LFE channel(s) -lm File : LFE panning matrix File (CSV table) containing a matrix of dimensions [ num_input_lfe x num_output_channels ] with elements specifying linear routing gain (like --gain, -g). - If specified, overrides the output LFE position option and the default behavior which attempts to map input to output LFE channel(s) + If specified, overrides the output LFE position option and the default behavior which attempts to map input to output LFE channel(s) -no_delay_cmp : Turn off delay compensation -g : Input gain (linear, not in dB) to be applied to input audio file -l : List supported audio formats -smd : Metadata Synchronization Delay in ms, Default is 0. Quantized by 5ms subframes. --om File : Coded metadata File for BINAURAL_SPLIT_PCM output format --level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. +-om File : Coded metadata File for BINAURAL_SPLIT_PCM output configuration +-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation Currently, all values default to level 3 (full functionality). -q : Quiet mode, limit printouts to terminal, default is deactivated -The usage of the "ISAR_post_rend" program: ------------------------------------------- +The usage of the "ISAR_post_rend" program is as follows: +-------------------------------------------------------- -Usage: ISAR_post_rend [options] +Usage: ISAR_post_rend [options] -i -if -o -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 +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: ------------------------------------------- + +The usage of the "ambi_converter" program is as follows: +-------------------------------------------------------- Usage: ambi_converter input_file output_file input_convention output_convention @@ -391,7 +421,18 @@ the following conventions are supported: 4 : SID-SN3D 5 : SID-N3D -Either the input or the output convention must always be ACN-SN3D! +Either the input or the output convention must always be ACN-SN3D. + + +The usage of the "IVAS_cod_fmtsw" program is as follows: +-------------------------------------------------------- + +Usage: IVAS_cod_fmtsw format_switching_file + +Mandatory parameters: +--------------------- +format_switching_file: Text file containing a valid encoder command line in each line + MULTICHANNEL LOUDSPEAKER INPUT / OUTPUT CONFIGURATIONS @@ -421,7 +462,6 @@ omitted, the LFE input is downmixed to all channels with a factor of 1/N. Positi the LFE channel. Maximum number of supported loudskpeakers N is 16. An example custom loudspeaker layout file is available: ls_setup_16ch_8+4+4.txt - RUNNING THE SELF TEST ===================== @@ -665,14 +705,32 @@ The parameters for the object editing in decoder for the supported formats can b parameter file. Each row of the file corresponds to one 20 ms IVAS frame. The row contains one or more of the following parameters separated by a comma: -bg_gain= linear gain to be applied on the SBA/MASA component in OSBA/OMASA, no effect for ISM -obj__gain= linear gain to be applied on object , 0-based indexing -obj__relgain=0|1 if 1, obj__gain is interpreted as a relative modification. default is absolute modification -obj__azi= azimuth angle in degrees to be applied on object , 0-based indexing -obj__relazi=0|1 if 1, obj__azi is interpreted as a relative modification. default is absolute modification -obj__ele= elevation angle in degrees to be applied on object , 0-based indexing -obj__relele=0|1 if 1, obj__ele is interpreted as a relative modification. default is absolute modification +bg_gain= linear gain to be applied on the SBA/MASA component in OSBA/OMASA, no effect for ISM +obj__gain= linear gain to be applied on object , 0-based indexing +obj__relgain=0|1 if 1, obj__gain is interpreted as a relative modification. default is absolute modification +obj__azi= azimuth angle in degrees to be applied on object , 0-based indexing +obj__relazi=0|1 if 1, obj__azi is interpreted as a relative modification. default is absolute modification +obj__ele= elevation angle in degrees to be applied on object , 0-based indexing +obj__relele=0|1 if 1, obj__ele is interpreted as a relative modification. default is absolute modification +obj__radius= linear radius to be applied on object , 0-based indexing +obj__relradius=0|1 if 1, obj__radius is interpreted as a relative modification. default is absolute modification +obj__yaw= yaw angle in degrees to be applied on object , 0-based indexing +obj__relyaw=0|1 if 1, obj__yaw is interpreted as a relative modification. default is absolute modification +obj__pitch= pitch angle in degrees to be applied on object , 0-based indexing +obj__relpitch=0|1 if 1, obj__pitch is interpreted as a relative modification. default is absolute modification If a parameter is not specified, that parameter is not edited. An empty line in the file corresponds to not editing any parameter in the item. Example files are available in folder /scripts/object_edit. + + +RTP streaming file +------------------- +IVAS supports a simple packing and unpacking for streaming file for the RTP. In this format a single RTP_streaming_packet +contains the length of an RTP packet followed by the actual RTP packet which is recorded as-is. This format is produced +by the encoder when using the -rtpdump switch and the decoder assumes this format in the input when -VOIP_hf_only=1 is set. + +typedef struct { + u_int32 length; /* size of the RTP packet in bytes */ + (u_int8 * length) RTP_packet; /* RTP packet (sized length * byte) */ +} RTP_streaming_packet;